1 From a3310d64d7cb1ba0f9279e77d21f13a75fa66ab5 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Wed, 17 Jan 2018 15:29:23 +0800
4 Subject: [PATCH 16/30] crypto: support layerscape
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This is an integrated patch for layerscape sec support.
11 Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
12 Signed-off-by: Fabio Estevam <festevam@gmail.com>
13 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
14 Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
15 Signed-off-by: Tudor Ambarus <tudor-dan.ambarus@nxp.com>
16 Signed-off-by: Eric Biggers <ebiggers@google.com>
17 Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
18 Signed-off-by: Xulin Sun <xulin.sun@windriver.com>
19 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
20 Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
21 Signed-off-by: Tudor Ambarus <tudor-dan.ambarus@nxp.com>
22 Signed-off-by: Andrew Lutomirski <luto@kernel.org>
23 Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
24 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
25 Signed-off-by: Marcelo Cerri <marcelo.cerri@canonical.com>
26 Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
27 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
28 Signed-off-by: Laura Abbott <labbott@redhat.com>
29 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
30 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
34 crypto/acompress.c | 169 +
35 crypto/algboss.c | 12 +-
36 crypto/crypto_user.c | 19 +
37 crypto/scompress.c | 356 ++
38 crypto/tcrypt.c | 17 +-
39 crypto/testmgr.c | 1708 +++---
40 crypto/testmgr.h | 1125 ++--
41 crypto/tls.c | 607 +++
42 drivers/crypto/caam/Kconfig | 77 +-
43 drivers/crypto/caam/Makefile | 16 +-
44 drivers/crypto/caam/caamalg.c | 2171 ++------
45 drivers/crypto/caam/caamalg_desc.c | 1961 +++++++
46 drivers/crypto/caam/caamalg_desc.h | 127 +
47 drivers/crypto/caam/caamalg_qi.c | 2929 ++++++++++
48 drivers/crypto/caam/caamalg_qi2.c | 5920 +++++++++++++++++++++
49 drivers/crypto/caam/caamalg_qi2.h | 281 +
50 drivers/crypto/caam/caamhash.c | 550 +-
51 drivers/crypto/caam/caamhash_desc.c | 108 +
52 drivers/crypto/caam/caamhash_desc.h | 49 +
53 drivers/crypto/caam/caampkc.c | 471 +-
54 drivers/crypto/caam/caampkc.h | 58 +
55 drivers/crypto/caam/caamrng.c | 16 +-
56 drivers/crypto/caam/compat.h | 1 +
57 drivers/crypto/caam/ctrl.c | 358 +-
58 drivers/crypto/caam/ctrl.h | 2 +
59 drivers/crypto/caam/desc.h | 84 +-
60 drivers/crypto/caam/desc_constr.h | 180 +-
61 drivers/crypto/caam/dpseci.c | 859 +++
62 drivers/crypto/caam/dpseci.h | 395 ++
63 drivers/crypto/caam/dpseci_cmd.h | 261 +
64 drivers/crypto/caam/error.c | 127 +-
65 drivers/crypto/caam/error.h | 10 +-
66 drivers/crypto/caam/intern.h | 31 +-
67 drivers/crypto/caam/jr.c | 72 +-
68 drivers/crypto/caam/jr.h | 2 +
69 drivers/crypto/caam/key_gen.c | 32 +-
70 drivers/crypto/caam/key_gen.h | 36 +-
71 drivers/crypto/caam/pdb.h | 62 +
72 drivers/crypto/caam/pkc_desc.c | 36 +
73 drivers/crypto/caam/qi.c | 797 +++
74 drivers/crypto/caam/qi.h | 204 +
75 drivers/crypto/caam/regs.h | 63 +-
76 drivers/crypto/caam/sg_sw_qm.h | 126 +
77 drivers/crypto/caam/sg_sw_qm2.h | 81 +
78 drivers/crypto/caam/sg_sw_sec4.h | 60 +-
79 drivers/net/wireless/rsi/rsi_91x_usb.c | 2 +-
80 drivers/staging/wilc1000/linux_wlan.c | 2 +-
81 drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 2 +-
82 include/crypto/acompress.h | 269 +
83 include/crypto/internal/acompress.h | 81 +
84 include/crypto/internal/scompress.h | 136 +
85 include/linux/crypto.h | 3 +
86 include/uapi/linux/cryptouser.h | 5 +
87 scripts/spelling.txt | 3 +
88 sound/soc/amd/acp-pcm-dma.c | 2 +-
89 57 files changed, 19177 insertions(+), 3988 deletions(-)
90 create mode 100644 crypto/acompress.c
91 create mode 100644 crypto/scompress.c
92 create mode 100644 crypto/tls.c
93 create mode 100644 drivers/crypto/caam/caamalg_desc.c
94 create mode 100644 drivers/crypto/caam/caamalg_desc.h
95 create mode 100644 drivers/crypto/caam/caamalg_qi.c
96 create mode 100644 drivers/crypto/caam/caamalg_qi2.c
97 create mode 100644 drivers/crypto/caam/caamalg_qi2.h
98 create mode 100644 drivers/crypto/caam/caamhash_desc.c
99 create mode 100644 drivers/crypto/caam/caamhash_desc.h
100 create mode 100644 drivers/crypto/caam/dpseci.c
101 create mode 100644 drivers/crypto/caam/dpseci.h
102 create mode 100644 drivers/crypto/caam/dpseci_cmd.h
103 create mode 100644 drivers/crypto/caam/qi.c
104 create mode 100644 drivers/crypto/caam/qi.h
105 create mode 100644 drivers/crypto/caam/sg_sw_qm.h
106 create mode 100644 drivers/crypto/caam/sg_sw_qm2.h
107 create mode 100644 include/crypto/acompress.h
108 create mode 100644 include/crypto/internal/acompress.h
109 create mode 100644 include/crypto/internal/scompress.h
113 @@ -102,6 +102,15 @@ config CRYPTO_KPP
117 +config CRYPTO_ACOMP2
119 + select CRYPTO_ALGAPI2
123 + select CRYPTO_ALGAPI
124 + select CRYPTO_ACOMP2
127 tristate "RSA algorithm"
128 select CRYPTO_AKCIPHER
129 @@ -138,6 +147,7 @@ config CRYPTO_MANAGER2
130 select CRYPTO_BLKCIPHER2 if !CRYPTO_MANAGER_DISABLE_TESTS
131 select CRYPTO_AKCIPHER2 if !CRYPTO_MANAGER_DISABLE_TESTS
132 select CRYPTO_KPP2 if !CRYPTO_MANAGER_DISABLE_TESTS
133 + select CRYPTO_ACOMP2 if !CRYPTO_MANAGER_DISABLE_TESTS
136 tristate "Userspace cryptographic algorithm configuration"
137 @@ -295,6 +305,26 @@ config CRYPTO_ECHAINIV
138 a sequence number xored with a salt. This is the default
142 + tristate "TLS support"
144 + select CRYPTO_BLKCIPHER
145 + select CRYPTO_MANAGER
148 + select CRYPTO_AUTHENC
150 + Support for TLS 1.0 record encryption and decryption
152 + This module adds support for encryption/decryption of TLS 1.0 frames
153 + using blockcipher algorithms. The name of the resulting algorithm is
154 + "tls10(hmac(<digest>),cbc(<cipher>))". By default, the generic base
155 + algorithms are used (e.g. aes-generic, sha1-generic), but hardware
156 + accelerated versions will be used automatically if available.
158 + User-space applications (OpenSSL, GnuTLS) can offload TLS 1.0
159 + operations through AF_ALG or cryptodev interfaces
161 comment "Block modes"
164 --- a/crypto/Makefile
165 +++ b/crypto/Makefile
166 @@ -51,6 +51,9 @@ rsa_generic-y += rsa_helper.o
167 rsa_generic-y += rsa-pkcs1pad.o
168 obj-$(CONFIG_CRYPTO_RSA) += rsa_generic.o
170 +obj-$(CONFIG_CRYPTO_ACOMP2) += acompress.o
171 +obj-$(CONFIG_CRYPTO_ACOMP2) += scompress.o
173 cryptomgr-y := algboss.o testmgr.o
175 obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o
176 @@ -115,6 +118,7 @@ obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_ge
177 obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o
178 obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o
179 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
180 +obj-$(CONFIG_CRYPTO_TLS) += tls.o
181 obj-$(CONFIG_CRYPTO_LZO) += lzo.o
182 obj-$(CONFIG_CRYPTO_LZ4) += lz4.o
183 obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o
185 +++ b/crypto/acompress.c
188 + * Asynchronous Compression operations
190 + * Copyright (c) 2016, Intel Corporation
191 + * Authors: Weigang Li <weigang.li@intel.com>
192 + * Giovanni Cabiddu <giovanni.cabiddu@intel.com>
194 + * This program is free software; you can redistribute it and/or modify it
195 + * under the terms of the GNU General Public License as published by the Free
196 + * Software Foundation; either version 2 of the License, or (at your option)
197 + * any later version.
200 +#include <linux/errno.h>
201 +#include <linux/kernel.h>
202 +#include <linux/module.h>
203 +#include <linux/seq_file.h>
204 +#include <linux/slab.h>
205 +#include <linux/string.h>
206 +#include <linux/crypto.h>
207 +#include <crypto/algapi.h>
208 +#include <linux/cryptouser.h>
209 +#include <net/netlink.h>
210 +#include <crypto/internal/acompress.h>
211 +#include <crypto/internal/scompress.h>
212 +#include "internal.h"
214 +static const struct crypto_type crypto_acomp_type;
217 +static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
219 + struct crypto_report_acomp racomp;
221 + strncpy(racomp.type, "acomp", sizeof(racomp.type));
223 + if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP,
224 + sizeof(struct crypto_report_acomp), &racomp))
225 + goto nla_put_failure;
232 +static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
238 +static void crypto_acomp_show(struct seq_file *m, struct crypto_alg *alg)
239 + __attribute__ ((unused));
241 +static void crypto_acomp_show(struct seq_file *m, struct crypto_alg *alg)
243 + seq_puts(m, "type : acomp\n");
246 +static void crypto_acomp_exit_tfm(struct crypto_tfm *tfm)
248 + struct crypto_acomp *acomp = __crypto_acomp_tfm(tfm);
249 + struct acomp_alg *alg = crypto_acomp_alg(acomp);
254 +static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
256 + struct crypto_acomp *acomp = __crypto_acomp_tfm(tfm);
257 + struct acomp_alg *alg = crypto_acomp_alg(acomp);
259 + if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
260 + return crypto_init_scomp_ops_async(tfm);
262 + acomp->compress = alg->compress;
263 + acomp->decompress = alg->decompress;
264 + acomp->dst_free = alg->dst_free;
265 + acomp->reqsize = alg->reqsize;
268 + acomp->base.exit = crypto_acomp_exit_tfm;
271 + return alg->init(acomp);
276 +static unsigned int crypto_acomp_extsize(struct crypto_alg *alg)
278 + int extsize = crypto_alg_extsize(alg);
280 + if (alg->cra_type != &crypto_acomp_type)
281 + extsize += sizeof(struct crypto_scomp *);
286 +static const struct crypto_type crypto_acomp_type = {
287 + .extsize = crypto_acomp_extsize,
288 + .init_tfm = crypto_acomp_init_tfm,
289 +#ifdef CONFIG_PROC_FS
290 + .show = crypto_acomp_show,
292 + .report = crypto_acomp_report,
293 + .maskclear = ~CRYPTO_ALG_TYPE_MASK,
294 + .maskset = CRYPTO_ALG_TYPE_ACOMPRESS_MASK,
295 + .type = CRYPTO_ALG_TYPE_ACOMPRESS,
296 + .tfmsize = offsetof(struct crypto_acomp, base),
299 +struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
302 + return crypto_alloc_tfm(alg_name, &crypto_acomp_type, type, mask);
304 +EXPORT_SYMBOL_GPL(crypto_alloc_acomp);
306 +struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp)
308 + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
309 + struct acomp_req *req;
311 + req = __acomp_request_alloc(acomp);
312 + if (req && (tfm->__crt_alg->cra_type != &crypto_acomp_type))
313 + return crypto_acomp_scomp_alloc_ctx(req);
317 +EXPORT_SYMBOL_GPL(acomp_request_alloc);
319 +void acomp_request_free(struct acomp_req *req)
321 + struct crypto_acomp *acomp = crypto_acomp_reqtfm(req);
322 + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
324 + if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
325 + crypto_acomp_scomp_free_ctx(req);
327 + if (req->flags & CRYPTO_ACOMP_ALLOC_OUTPUT) {
328 + acomp->dst_free(req->dst);
332 + __acomp_request_free(req);
334 +EXPORT_SYMBOL_GPL(acomp_request_free);
336 +int crypto_register_acomp(struct acomp_alg *alg)
338 + struct crypto_alg *base = &alg->base;
340 + base->cra_type = &crypto_acomp_type;
341 + base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
342 + base->cra_flags |= CRYPTO_ALG_TYPE_ACOMPRESS;
344 + return crypto_register_alg(base);
346 +EXPORT_SYMBOL_GPL(crypto_register_acomp);
348 +int crypto_unregister_acomp(struct acomp_alg *alg)
350 + return crypto_unregister_alg(&alg->base);
352 +EXPORT_SYMBOL_GPL(crypto_unregister_acomp);
354 +MODULE_LICENSE("GPL");
355 +MODULE_DESCRIPTION("Asynchronous compression type");
356 --- a/crypto/algboss.c
357 +++ b/crypto/algboss.c
358 @@ -247,17 +247,9 @@ static int cryptomgr_schedule_test(struc
359 memcpy(param->alg, alg->cra_name, sizeof(param->alg));
360 type = alg->cra_flags;
362 - /* This piece of crap needs to disappear into per-type test hooks. */
363 -#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
364 - type |= CRYPTO_ALG_TESTED;
366 - if (!((type ^ CRYPTO_ALG_TYPE_BLKCIPHER) &
367 - CRYPTO_ALG_TYPE_BLKCIPHER_MASK) && !(type & CRYPTO_ALG_GENIV) &&
368 - ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
369 - CRYPTO_ALG_TYPE_BLKCIPHER ? alg->cra_blkcipher.ivsize :
370 - alg->cra_ablkcipher.ivsize))
371 + /* Do not test internal algorithms. */
372 + if (type & CRYPTO_ALG_INTERNAL)
373 type |= CRYPTO_ALG_TESTED;
378 --- a/crypto/crypto_user.c
379 +++ b/crypto/crypto_user.c
380 @@ -112,6 +112,21 @@ nla_put_failure:
384 +static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
386 + struct crypto_report_acomp racomp;
388 + strncpy(racomp.type, "acomp", sizeof(racomp.type));
390 + if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP,
391 + sizeof(struct crypto_report_acomp), &racomp))
392 + goto nla_put_failure;
399 static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
401 struct crypto_report_akcipher rakcipher;
402 @@ -186,7 +201,11 @@ static int crypto_report_one(struct cryp
403 goto nla_put_failure;
406 + case CRYPTO_ALG_TYPE_ACOMPRESS:
407 + if (crypto_report_acomp(skb, alg))
408 + goto nla_put_failure;
411 case CRYPTO_ALG_TYPE_AKCIPHER:
412 if (crypto_report_akcipher(skb, alg))
413 goto nla_put_failure;
415 +++ b/crypto/scompress.c
418 + * Synchronous Compression operations
420 + * Copyright 2015 LG Electronics Inc.
421 + * Copyright (c) 2016, Intel Corporation
422 + * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
424 + * This program is free software; you can redistribute it and/or modify it
425 + * under the terms of the GNU General Public License as published by the Free
426 + * Software Foundation; either version 2 of the License, or (at your option)
427 + * any later version.
430 +#include <linux/errno.h>
431 +#include <linux/kernel.h>
432 +#include <linux/module.h>
433 +#include <linux/seq_file.h>
434 +#include <linux/slab.h>
435 +#include <linux/string.h>
436 +#include <linux/crypto.h>
437 +#include <linux/vmalloc.h>
438 +#include <crypto/algapi.h>
439 +#include <linux/cryptouser.h>
440 +#include <net/netlink.h>
441 +#include <linux/scatterlist.h>
442 +#include <crypto/scatterwalk.h>
443 +#include <crypto/internal/acompress.h>
444 +#include <crypto/internal/scompress.h>
445 +#include "internal.h"
447 +static const struct crypto_type crypto_scomp_type;
448 +static void * __percpu *scomp_src_scratches;
449 +static void * __percpu *scomp_dst_scratches;
450 +static int scomp_scratch_users;
451 +static DEFINE_MUTEX(scomp_lock);
454 +static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
456 + struct crypto_report_comp rscomp;
458 + strncpy(rscomp.type, "scomp", sizeof(rscomp.type));
460 + if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
461 + sizeof(struct crypto_report_comp), &rscomp))
462 + goto nla_put_failure;
469 +static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
475 +static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
476 + __attribute__ ((unused));
478 +static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
480 + seq_puts(m, "type : scomp\n");
483 +static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
488 +static void crypto_scomp_free_scratches(void * __percpu *scratches)
495 + for_each_possible_cpu(i)
496 + vfree(*per_cpu_ptr(scratches, i));
498 + free_percpu(scratches);
501 +static void * __percpu *crypto_scomp_alloc_scratches(void)
503 + void * __percpu *scratches;
506 + scratches = alloc_percpu(void *);
510 + for_each_possible_cpu(i) {
513 + scratch = vmalloc_node(SCOMP_SCRATCH_SIZE, cpu_to_node(i));
516 + *per_cpu_ptr(scratches, i) = scratch;
522 + crypto_scomp_free_scratches(scratches);
526 +static void crypto_scomp_free_all_scratches(void)
528 + if (!--scomp_scratch_users) {
529 + crypto_scomp_free_scratches(scomp_src_scratches);
530 + crypto_scomp_free_scratches(scomp_dst_scratches);
531 + scomp_src_scratches = NULL;
532 + scomp_dst_scratches = NULL;
536 +static int crypto_scomp_alloc_all_scratches(void)
538 + if (!scomp_scratch_users++) {
539 + scomp_src_scratches = crypto_scomp_alloc_scratches();
540 + if (!scomp_src_scratches)
542 + scomp_dst_scratches = crypto_scomp_alloc_scratches();
543 + if (!scomp_dst_scratches)
549 +static void crypto_scomp_sg_free(struct scatterlist *sgl)
558 + for_each_sg(sgl, sgl, n, i) {
559 + page = sg_page(sgl);
567 +static struct scatterlist *crypto_scomp_sg_alloc(size_t size, gfp_t gfp)
569 + struct scatterlist *sgl;
573 + n = ((size - 1) >> PAGE_SHIFT) + 1;
575 + sgl = kmalloc_array(n, sizeof(struct scatterlist), gfp);
579 + sg_init_table(sgl, n);
581 + for (i = 0; i < n; i++) {
582 + page = alloc_page(gfp);
585 + sg_set_page(sgl + i, page, PAGE_SIZE, 0);
591 + sg_mark_end(sgl + i);
592 + crypto_scomp_sg_free(sgl);
596 +static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
598 + struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
599 + void **tfm_ctx = acomp_tfm_ctx(tfm);
600 + struct crypto_scomp *scomp = *tfm_ctx;
601 + void **ctx = acomp_request_ctx(req);
602 + const int cpu = get_cpu();
603 + u8 *scratch_src = *per_cpu_ptr(scomp_src_scratches, cpu);
604 + u8 *scratch_dst = *per_cpu_ptr(scomp_dst_scratches, cpu);
607 + if (!req->src || !req->slen || req->slen > SCOMP_SCRATCH_SIZE) {
612 + if (req->dst && !req->dlen) {
617 + if (!req->dlen || req->dlen > SCOMP_SCRATCH_SIZE)
618 + req->dlen = SCOMP_SCRATCH_SIZE;
620 + scatterwalk_map_and_copy(scratch_src, req->src, 0, req->slen, 0);
622 + ret = crypto_scomp_compress(scomp, scratch_src, req->slen,
623 + scratch_dst, &req->dlen, *ctx);
625 + ret = crypto_scomp_decompress(scomp, scratch_src, req->slen,
626 + scratch_dst, &req->dlen, *ctx);
629 + req->dst = crypto_scomp_sg_alloc(req->dlen,
630 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
631 + GFP_KERNEL : GFP_ATOMIC);
635 + scatterwalk_map_and_copy(scratch_dst, req->dst, 0, req->dlen,
643 +static int scomp_acomp_compress(struct acomp_req *req)
645 + return scomp_acomp_comp_decomp(req, 1);
648 +static int scomp_acomp_decompress(struct acomp_req *req)
650 + return scomp_acomp_comp_decomp(req, 0);
653 +static void crypto_exit_scomp_ops_async(struct crypto_tfm *tfm)
655 + struct crypto_scomp **ctx = crypto_tfm_ctx(tfm);
657 + crypto_free_scomp(*ctx);
660 +int crypto_init_scomp_ops_async(struct crypto_tfm *tfm)
662 + struct crypto_alg *calg = tfm->__crt_alg;
663 + struct crypto_acomp *crt = __crypto_acomp_tfm(tfm);
664 + struct crypto_scomp **ctx = crypto_tfm_ctx(tfm);
665 + struct crypto_scomp *scomp;
667 + if (!crypto_mod_get(calg))
670 + scomp = crypto_create_tfm(calg, &crypto_scomp_type);
671 + if (IS_ERR(scomp)) {
672 + crypto_mod_put(calg);
673 + return PTR_ERR(scomp);
677 + tfm->exit = crypto_exit_scomp_ops_async;
679 + crt->compress = scomp_acomp_compress;
680 + crt->decompress = scomp_acomp_decompress;
681 + crt->dst_free = crypto_scomp_sg_free;
682 + crt->reqsize = sizeof(void *);
687 +struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req)
689 + struct crypto_acomp *acomp = crypto_acomp_reqtfm(req);
690 + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
691 + struct crypto_scomp **tfm_ctx = crypto_tfm_ctx(tfm);
692 + struct crypto_scomp *scomp = *tfm_ctx;
695 + ctx = crypto_scomp_alloc_ctx(scomp);
706 +void crypto_acomp_scomp_free_ctx(struct acomp_req *req)
708 + struct crypto_acomp *acomp = crypto_acomp_reqtfm(req);
709 + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
710 + struct crypto_scomp **tfm_ctx = crypto_tfm_ctx(tfm);
711 + struct crypto_scomp *scomp = *tfm_ctx;
712 + void *ctx = *req->__ctx;
715 + crypto_scomp_free_ctx(scomp, ctx);
718 +static const struct crypto_type crypto_scomp_type = {
719 + .extsize = crypto_alg_extsize,
720 + .init_tfm = crypto_scomp_init_tfm,
721 +#ifdef CONFIG_PROC_FS
722 + .show = crypto_scomp_show,
724 + .report = crypto_scomp_report,
725 + .maskclear = ~CRYPTO_ALG_TYPE_MASK,
726 + .maskset = CRYPTO_ALG_TYPE_MASK,
727 + .type = CRYPTO_ALG_TYPE_SCOMPRESS,
728 + .tfmsize = offsetof(struct crypto_scomp, base),
731 +int crypto_register_scomp(struct scomp_alg *alg)
733 + struct crypto_alg *base = &alg->base;
736 + mutex_lock(&scomp_lock);
737 + if (crypto_scomp_alloc_all_scratches())
740 + base->cra_type = &crypto_scomp_type;
741 + base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
742 + base->cra_flags |= CRYPTO_ALG_TYPE_SCOMPRESS;
744 + ret = crypto_register_alg(base);
748 + mutex_unlock(&scomp_lock);
752 + crypto_scomp_free_all_scratches();
753 + mutex_unlock(&scomp_lock);
756 +EXPORT_SYMBOL_GPL(crypto_register_scomp);
758 +int crypto_unregister_scomp(struct scomp_alg *alg)
762 + mutex_lock(&scomp_lock);
763 + ret = crypto_unregister_alg(&alg->base);
764 + crypto_scomp_free_all_scratches();
765 + mutex_unlock(&scomp_lock);
769 +EXPORT_SYMBOL_GPL(crypto_unregister_scomp);
771 +MODULE_LICENSE("GPL");
772 +MODULE_DESCRIPTION("Synchronous compression type");
773 --- a/crypto/tcrypt.c
774 +++ b/crypto/tcrypt.c
775 @@ -74,7 +74,7 @@ static char *check[] = {
776 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
777 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
778 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
783 struct tcrypt_result {
784 @@ -1333,6 +1333,10 @@ static int do_test(const char *alg, u32
785 ret += tcrypt_test("hmac(sha3-512)");
789 + ret += tcrypt_test("rsa");
793 ret += tcrypt_test("ansi_cprng");
795 @@ -1394,6 +1398,9 @@ static int do_test(const char *alg, u32
797 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
800 + ret += tcrypt_test("tls10(hmac(sha1),cbc(aes))");
803 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
804 speed_template_16_24_32);
805 @@ -1408,9 +1415,9 @@ static int do_test(const char *alg, u32
806 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
807 speed_template_32_40_48);
808 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
809 - speed_template_32_48_64);
810 + speed_template_32_64);
811 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
812 - speed_template_32_48_64);
813 + speed_template_32_64);
814 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
815 speed_template_16_24_32);
816 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
817 @@ -1841,9 +1848,9 @@ static int do_test(const char *alg, u32
818 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
819 speed_template_32_40_48);
820 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
821 - speed_template_32_48_64);
822 + speed_template_32_64);
823 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
824 - speed_template_32_48_64);
825 + speed_template_32_64);
826 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
827 speed_template_16_24_32);
828 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
829 --- a/crypto/testmgr.c
830 +++ b/crypto/testmgr.c
832 #include <crypto/drbg.h>
833 #include <crypto/akcipher.h>
834 #include <crypto/kpp.h>
835 +#include <crypto/acompress.h>
837 #include "internal.h"
839 @@ -62,7 +63,7 @@ int alg_test(const char *driver, const c
848 @@ -82,47 +83,54 @@ struct tcrypt_result {
850 struct aead_test_suite {
852 - struct aead_testvec *vecs;
853 + const struct aead_testvec *vecs;
858 struct cipher_test_suite {
860 - struct cipher_testvec *vecs;
861 + const struct cipher_testvec *vecs;
866 struct comp_test_suite {
868 - struct comp_testvec *vecs;
869 + const struct comp_testvec *vecs;
874 struct hash_test_suite {
875 - struct hash_testvec *vecs;
876 + const struct hash_testvec *vecs;
880 struct cprng_test_suite {
881 - struct cprng_testvec *vecs;
882 + const struct cprng_testvec *vecs;
886 struct drbg_test_suite {
887 - struct drbg_testvec *vecs;
888 + const struct drbg_testvec *vecs;
892 +struct tls_test_suite {
894 + struct tls_testvec *vecs;
895 + unsigned int count;
899 struct akcipher_test_suite {
900 - struct akcipher_testvec *vecs;
901 + const struct akcipher_testvec *vecs;
905 struct kpp_test_suite {
906 - struct kpp_testvec *vecs;
907 + const struct kpp_testvec *vecs;
911 @@ -139,12 +147,14 @@ struct alg_test_desc {
912 struct hash_test_suite hash;
913 struct cprng_test_suite cprng;
914 struct drbg_test_suite drbg;
915 + struct tls_test_suite tls;
916 struct akcipher_test_suite akcipher;
917 struct kpp_test_suite kpp;
921 -static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
922 +static const unsigned int IDX[8] = {
923 + IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
925 static void hexdump(unsigned char *buf, unsigned int len)
927 @@ -202,7 +212,7 @@ static int wait_async_op(struct tcrypt_r
930 static int ahash_partial_update(struct ahash_request **preq,
931 - struct crypto_ahash *tfm, struct hash_testvec *template,
932 + struct crypto_ahash *tfm, const struct hash_testvec *template,
933 void *hash_buff, int k, int temp, struct scatterlist *sg,
934 const char *algo, char *result, struct tcrypt_result *tresult)
936 @@ -259,11 +269,12 @@ out_nostate:
940 -static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
941 - unsigned int tcount, bool use_digest,
942 - const int align_offset)
943 +static int __test_hash(struct crypto_ahash *tfm,
944 + const struct hash_testvec *template, unsigned int tcount,
945 + bool use_digest, const int align_offset)
947 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
948 + size_t digest_size = crypto_ahash_digestsize(tfm);
949 unsigned int i, j, k, temp;
950 struct scatterlist sg[8];
952 @@ -274,7 +285,7 @@ static int __test_hash(struct crypto_aha
953 char *xbuf[XBUFSIZE];
956 - result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
957 + result = kmalloc(digest_size, GFP_KERNEL);
960 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
961 @@ -304,7 +315,7 @@ static int __test_hash(struct crypto_aha
965 - memset(result, 0, MAX_DIGEST_SIZE);
966 + memset(result, 0, digest_size);
969 hash_buff += align_offset;
970 @@ -379,7 +390,7 @@ static int __test_hash(struct crypto_aha
974 - memset(result, 0, MAX_DIGEST_SIZE);
975 + memset(result, 0, digest_size);
978 sg_init_table(sg, template[i].np);
979 @@ -457,7 +468,7 @@ static int __test_hash(struct crypto_aha
983 - memset(result, 0, MAX_DIGEST_SIZE);
984 + memset(result, 0, digest_size);
988 @@ -536,7 +547,8 @@ out_nobuf:
992 -static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
993 +static int test_hash(struct crypto_ahash *tfm,
994 + const struct hash_testvec *template,
995 unsigned int tcount, bool use_digest)
997 unsigned int alignmask;
998 @@ -564,7 +576,7 @@ static int test_hash(struct crypto_ahash
1001 static int __test_aead(struct crypto_aead *tfm, int enc,
1002 - struct aead_testvec *template, unsigned int tcount,
1003 + const struct aead_testvec *template, unsigned int tcount,
1004 const bool diff_dst, const int align_offset)
1006 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
1007 @@ -955,7 +967,7 @@ out_noxbuf:
1010 static int test_aead(struct crypto_aead *tfm, int enc,
1011 - struct aead_testvec *template, unsigned int tcount)
1012 + const struct aead_testvec *template, unsigned int tcount)
1014 unsigned int alignmask;
1016 @@ -987,8 +999,236 @@ static int test_aead(struct crypto_aead
1020 +static int __test_tls(struct crypto_aead *tfm, int enc,
1021 + struct tls_testvec *template, unsigned int tcount,
1022 + const bool diff_dst)
1024 + const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
1025 + unsigned int i, k, authsize;
1027 + struct aead_request *req;
1028 + struct scatterlist *sg;
1029 + struct scatterlist *sgout;
1030 + const char *e, *d;
1031 + struct tcrypt_result result;
1037 + char *xbuf[XBUFSIZE];
1038 + char *xoutbuf[XBUFSIZE];
1039 + char *axbuf[XBUFSIZE];
1040 + int ret = -ENOMEM;
1042 + if (testmgr_alloc_buf(xbuf))
1045 + if (diff_dst && testmgr_alloc_buf(xoutbuf))
1046 + goto out_nooutbuf;
1048 + if (testmgr_alloc_buf(axbuf))
1051 + iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
1055 + key = kzalloc(MAX_KEYLEN, GFP_KERNEL);
1059 + sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 2 : 1), GFP_KERNEL);
1065 + d = diff_dst ? "-ddst" : "";
1066 + e = enc ? "encryption" : "decryption";
1068 + init_completion(&result.completion);
1070 + req = aead_request_alloc(tfm, GFP_KERNEL);
1072 + pr_err("alg: tls%s: Failed to allocate request for %s\n",
1077 + aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1078 + tcrypt_complete, &result);
1080 + for (i = 0; i < tcount; i++) {
1085 + if (WARN_ON(template[i].ilen > PAGE_SIZE ||
1086 + template[i].alen > PAGE_SIZE))
1089 + memcpy(assoc, template[i].assoc, template[i].alen);
1090 + memcpy(input, template[i].input, template[i].ilen);
1092 + if (template[i].iv)
1093 + memcpy(iv, template[i].iv, MAX_IVLEN);
1095 + memset(iv, 0, MAX_IVLEN);
1097 + crypto_aead_clear_flags(tfm, ~0);
1099 + if (template[i].klen > MAX_KEYLEN) {
1100 + pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
1101 + d, i, algo, template[i].klen, MAX_KEYLEN);
1105 + memcpy(key, template[i].key, template[i].klen);
1107 + ret = crypto_aead_setkey(tfm, key, template[i].klen);
1108 + if (!ret == template[i].fail) {
1109 + pr_err("alg: tls%s: setkey failed on test %d for %s: flags=%x\n",
1110 + d, i, algo, crypto_aead_get_flags(tfm));
1116 + ret = crypto_aead_setauthsize(tfm, authsize);
1118 + pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
1119 + d, authsize, i, algo);
1123 + k = !!template[i].alen;
1124 + sg_init_table(sg, k + 1);
1125 + sg_set_buf(&sg[0], assoc, template[i].alen);
1126 + sg_set_buf(&sg[k], input, (enc ? template[i].rlen :
1127 + template[i].ilen));
1131 + sg_init_table(sgout, k + 1);
1132 + sg_set_buf(&sgout[0], assoc, template[i].alen);
1134 + output = xoutbuf[0];
1135 + sg_set_buf(&sgout[k], output,
1136 + (enc ? template[i].rlen : template[i].ilen));
1139 + aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1140 + template[i].ilen, iv);
1142 + aead_request_set_ad(req, template[i].alen);
1144 + ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
1148 + if (template[i].novrfy) {
1149 + /* verification was supposed to fail */
1150 + pr_err("alg: tls%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
1152 + /* so really, we got a bad message */
1157 + case -EINPROGRESS:
1159 + wait_for_completion(&result.completion);
1160 + reinit_completion(&result.completion);
1165 + /* verification failure was expected */
1166 + if (template[i].novrfy)
1168 + /* fall through */
1170 + pr_err("alg: tls%s: %s failed on test %d for %s: ret=%d\n",
1171 + d, e, i, algo, -ret);
1176 + if (memcmp(q, template[i].result, template[i].rlen)) {
1177 + pr_err("alg: tls%s: Test %d failed on %s for %s\n",
1179 + hexdump(q, template[i].rlen);
1180 + pr_err("should be:\n");
1181 + hexdump(template[i].result, template[i].rlen);
1188 + aead_request_free(req);
1196 + testmgr_free_buf(axbuf);
1199 + testmgr_free_buf(xoutbuf);
1201 + testmgr_free_buf(xbuf);
1206 +static int test_tls(struct crypto_aead *tfm, int enc,
1207 + struct tls_testvec *template, unsigned int tcount)
1210 + /* test 'dst == src' case */
1211 + ret = __test_tls(tfm, enc, template, tcount, false);
1214 + /* test 'dst != src' case */
1215 + return __test_tls(tfm, enc, template, tcount, true);
1218 +static int alg_test_tls(const struct alg_test_desc *desc, const char *driver,
1219 + u32 type, u32 mask)
1221 + struct crypto_aead *tfm;
1224 + tfm = crypto_alloc_aead(driver, type, mask);
1225 + if (IS_ERR(tfm)) {
1226 + pr_err("alg: aead: Failed to load transform for %s: %ld\n",
1227 + driver, PTR_ERR(tfm));
1228 + return PTR_ERR(tfm);
1231 + if (desc->suite.tls.enc.vecs) {
1232 + err = test_tls(tfm, ENCRYPT, desc->suite.tls.enc.vecs,
1233 + desc->suite.tls.enc.count);
1238 + if (!err && desc->suite.tls.dec.vecs)
1239 + err = test_tls(tfm, DECRYPT, desc->suite.tls.dec.vecs,
1240 + desc->suite.tls.dec.count);
1243 + crypto_free_aead(tfm);
1247 static int test_cipher(struct crypto_cipher *tfm, int enc,
1248 - struct cipher_testvec *template, unsigned int tcount)
1249 + const struct cipher_testvec *template,
1250 + unsigned int tcount)
1252 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
1253 unsigned int i, j, k;
1254 @@ -1066,7 +1306,8 @@ out_nobuf:
1257 static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
1258 - struct cipher_testvec *template, unsigned int tcount,
1259 + const struct cipher_testvec *template,
1260 + unsigned int tcount,
1261 const bool diff_dst, const int align_offset)
1264 @@ -1079,12 +1320,16 @@ static int __test_skcipher(struct crypto
1266 struct tcrypt_result result;
1268 - char iv[MAX_IVLEN];
1270 char *xbuf[XBUFSIZE];
1271 char *xoutbuf[XBUFSIZE];
1273 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
1275 + iv = kmalloc(MAX_IVLEN, GFP_KERNEL);
1279 if (testmgr_alloc_buf(xbuf))
1282 @@ -1325,12 +1570,14 @@ out:
1283 testmgr_free_buf(xoutbuf);
1285 testmgr_free_buf(xbuf);
1291 static int test_skcipher(struct crypto_skcipher *tfm, int enc,
1292 - struct cipher_testvec *template, unsigned int tcount)
1293 + const struct cipher_testvec *template,
1294 + unsigned int tcount)
1296 unsigned int alignmask;
1298 @@ -1362,8 +1609,10 @@ static int test_skcipher(struct crypto_s
1302 -static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1303 - struct comp_testvec *dtemplate, int ctcount, int dtcount)
1304 +static int test_comp(struct crypto_comp *tfm,
1305 + const struct comp_testvec *ctemplate,
1306 + const struct comp_testvec *dtemplate,
1307 + int ctcount, int dtcount)
1309 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1311 @@ -1442,7 +1691,154 @@ out:
1315 -static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1316 +static int test_acomp(struct crypto_acomp *tfm,
1317 + const struct comp_testvec *ctemplate,
1318 + const struct comp_testvec *dtemplate,
1319 + int ctcount, int dtcount)
1321 + const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1325 + struct scatterlist src, dst;
1326 + struct acomp_req *req;
1327 + struct tcrypt_result result;
1329 + output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1333 + for (i = 0; i < ctcount; i++) {
1334 + unsigned int dlen = COMP_BUF_SIZE;
1335 + int ilen = ctemplate[i].inlen;
1338 + input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
1344 + memset(output, 0, dlen);
1345 + init_completion(&result.completion);
1346 + sg_init_one(&src, input_vec, ilen);
1347 + sg_init_one(&dst, output, dlen);
1349 + req = acomp_request_alloc(tfm);
1351 + pr_err("alg: acomp: request alloc failed for %s\n",
1358 + acomp_request_set_params(req, &src, &dst, ilen, dlen);
1359 + acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1360 + tcrypt_complete, &result);
1362 + ret = wait_async_op(&result, crypto_acomp_compress(req));
1364 + pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1365 + i + 1, algo, -ret);
1367 + acomp_request_free(req);
1371 + if (req->dlen != ctemplate[i].outlen) {
1372 + pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1373 + i + 1, algo, req->dlen);
1376 + acomp_request_free(req);
1380 + if (memcmp(output, ctemplate[i].output, req->dlen)) {
1381 + pr_err("alg: acomp: Compression test %d failed for %s\n",
1383 + hexdump(output, req->dlen);
1386 + acomp_request_free(req);
1391 + acomp_request_free(req);
1394 + for (i = 0; i < dtcount; i++) {
1395 + unsigned int dlen = COMP_BUF_SIZE;
1396 + int ilen = dtemplate[i].inlen;
1399 + input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
1405 + memset(output, 0, dlen);
1406 + init_completion(&result.completion);
1407 + sg_init_one(&src, input_vec, ilen);
1408 + sg_init_one(&dst, output, dlen);
1410 + req = acomp_request_alloc(tfm);
1412 + pr_err("alg: acomp: request alloc failed for %s\n",
1419 + acomp_request_set_params(req, &src, &dst, ilen, dlen);
1420 + acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1421 + tcrypt_complete, &result);
1423 + ret = wait_async_op(&result, crypto_acomp_decompress(req));
1425 + pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1426 + i + 1, algo, -ret);
1428 + acomp_request_free(req);
1432 + if (req->dlen != dtemplate[i].outlen) {
1433 + pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1434 + i + 1, algo, req->dlen);
1437 + acomp_request_free(req);
1441 + if (memcmp(output, dtemplate[i].output, req->dlen)) {
1442 + pr_err("alg: acomp: Decompression test %d failed for %s\n",
1444 + hexdump(output, req->dlen);
1447 + acomp_request_free(req);
1452 + acomp_request_free(req);
1462 +static int test_cprng(struct crypto_rng *tfm,
1463 + const struct cprng_testvec *template,
1464 unsigned int tcount)
1466 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1467 @@ -1509,7 +1905,7 @@ static int alg_test_aead(const struct al
1468 struct crypto_aead *tfm;
1471 - tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
1472 + tfm = crypto_alloc_aead(driver, type, mask);
1474 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1475 "%ld\n", driver, PTR_ERR(tfm));
1476 @@ -1538,7 +1934,7 @@ static int alg_test_cipher(const struct
1477 struct crypto_cipher *tfm;
1480 - tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1481 + tfm = crypto_alloc_cipher(driver, type, mask);
1483 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1484 "%s: %ld\n", driver, PTR_ERR(tfm));
1485 @@ -1567,7 +1963,7 @@ static int alg_test_skcipher(const struc
1486 struct crypto_skcipher *tfm;
1489 - tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1490 + tfm = crypto_alloc_skcipher(driver, type, mask);
1492 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1493 "%s: %ld\n", driver, PTR_ERR(tfm));
1494 @@ -1593,22 +1989,38 @@ out:
1495 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1498 - struct crypto_comp *tfm;
1499 + struct crypto_comp *comp;
1500 + struct crypto_acomp *acomp;
1502 + u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
1504 - tfm = crypto_alloc_comp(driver, type, mask);
1505 - if (IS_ERR(tfm)) {
1506 - printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1507 - "%ld\n", driver, PTR_ERR(tfm));
1508 - return PTR_ERR(tfm);
1510 + if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1511 + acomp = crypto_alloc_acomp(driver, type, mask);
1512 + if (IS_ERR(acomp)) {
1513 + pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1514 + driver, PTR_ERR(acomp));
1515 + return PTR_ERR(acomp);
1517 + err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1518 + desc->suite.comp.decomp.vecs,
1519 + desc->suite.comp.comp.count,
1520 + desc->suite.comp.decomp.count);
1521 + crypto_free_acomp(acomp);
1523 + comp = crypto_alloc_comp(driver, type, mask);
1524 + if (IS_ERR(comp)) {
1525 + pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1526 + driver, PTR_ERR(comp));
1527 + return PTR_ERR(comp);
1530 - err = test_comp(tfm, desc->suite.comp.comp.vecs,
1531 - desc->suite.comp.decomp.vecs,
1532 - desc->suite.comp.comp.count,
1533 - desc->suite.comp.decomp.count);
1534 + err = test_comp(comp, desc->suite.comp.comp.vecs,
1535 + desc->suite.comp.decomp.vecs,
1536 + desc->suite.comp.comp.count,
1537 + desc->suite.comp.decomp.count);
1539 - crypto_free_comp(tfm);
1540 + crypto_free_comp(comp);
1545 @@ -1618,7 +2030,7 @@ static int alg_test_hash(const struct al
1546 struct crypto_ahash *tfm;
1549 - tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
1550 + tfm = crypto_alloc_ahash(driver, type, mask);
1552 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1553 "%ld\n", driver, PTR_ERR(tfm));
1554 @@ -1646,7 +2058,7 @@ static int alg_test_crc32c(const struct
1558 - tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
1559 + tfm = crypto_alloc_shash(driver, type, mask);
1561 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1562 "%ld\n", driver, PTR_ERR(tfm));
1563 @@ -1688,7 +2100,7 @@ static int alg_test_cprng(const struct a
1564 struct crypto_rng *rng;
1567 - rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
1568 + rng = crypto_alloc_rng(driver, type, mask);
1570 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1571 "%ld\n", driver, PTR_ERR(rng));
1572 @@ -1703,7 +2115,7 @@ static int alg_test_cprng(const struct a
1576 -static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1577 +static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
1578 const char *driver, u32 type, u32 mask)
1581 @@ -1715,7 +2127,7 @@ static int drbg_cavs_test(struct drbg_te
1585 - drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
1586 + drng = crypto_alloc_rng(driver, type, mask);
1588 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
1590 @@ -1777,7 +2189,7 @@ static int alg_test_drbg(const struct al
1594 - struct drbg_testvec *template = desc->suite.drbg.vecs;
1595 + const struct drbg_testvec *template = desc->suite.drbg.vecs;
1596 unsigned int tcount = desc->suite.drbg.count;
1598 if (0 == memcmp(driver, "drbg_pr_", 8))
1599 @@ -1796,7 +2208,7 @@ static int alg_test_drbg(const struct al
1603 -static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec,
1604 +static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
1607 struct kpp_request *req;
1608 @@ -1888,7 +2300,7 @@ free_req:
1611 static int test_kpp(struct crypto_kpp *tfm, const char *alg,
1612 - struct kpp_testvec *vecs, unsigned int tcount)
1613 + const struct kpp_testvec *vecs, unsigned int tcount)
1617 @@ -1909,7 +2321,7 @@ static int alg_test_kpp(const struct alg
1618 struct crypto_kpp *tfm;
1621 - tfm = crypto_alloc_kpp(driver, type | CRYPTO_ALG_INTERNAL, mask);
1622 + tfm = crypto_alloc_kpp(driver, type, mask);
1624 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
1625 driver, PTR_ERR(tfm));
1626 @@ -1924,7 +2336,7 @@ static int alg_test_kpp(const struct alg
1629 static int test_akcipher_one(struct crypto_akcipher *tfm,
1630 - struct akcipher_testvec *vecs)
1631 + const struct akcipher_testvec *vecs)
1633 char *xbuf[XBUFSIZE];
1634 struct akcipher_request *req;
1635 @@ -2044,7 +2456,8 @@ free_xbuf:
1638 static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
1639 - struct akcipher_testvec *vecs, unsigned int tcount)
1640 + const struct akcipher_testvec *vecs,
1641 + unsigned int tcount)
1644 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
1645 @@ -2068,7 +2481,7 @@ static int alg_test_akcipher(const struc
1646 struct crypto_akcipher *tfm;
1649 - tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1650 + tfm = crypto_alloc_akcipher(driver, type, mask);
1652 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
1653 driver, PTR_ERR(tfm));
1654 @@ -2088,112 +2501,23 @@ static int alg_test_null(const struct al
1658 +#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
1660 /* Please keep this list sorted by algorithm name. */
1661 static const struct alg_test_desc alg_test_descs[] = {
1663 - .alg = "__cbc-cast5-avx",
1664 - .test = alg_test_null,
1666 - .alg = "__cbc-cast6-avx",
1667 - .test = alg_test_null,
1669 - .alg = "__cbc-serpent-avx",
1670 - .test = alg_test_null,
1672 - .alg = "__cbc-serpent-avx2",
1673 - .test = alg_test_null,
1675 - .alg = "__cbc-serpent-sse2",
1676 - .test = alg_test_null,
1678 - .alg = "__cbc-twofish-avx",
1679 - .test = alg_test_null,
1681 - .alg = "__driver-cbc-aes-aesni",
1682 - .test = alg_test_null,
1683 - .fips_allowed = 1,
1685 - .alg = "__driver-cbc-camellia-aesni",
1686 - .test = alg_test_null,
1688 - .alg = "__driver-cbc-camellia-aesni-avx2",
1689 - .test = alg_test_null,
1691 - .alg = "__driver-cbc-cast5-avx",
1692 - .test = alg_test_null,
1694 - .alg = "__driver-cbc-cast6-avx",
1695 - .test = alg_test_null,
1697 - .alg = "__driver-cbc-serpent-avx",
1698 - .test = alg_test_null,
1700 - .alg = "__driver-cbc-serpent-avx2",
1701 - .test = alg_test_null,
1703 - .alg = "__driver-cbc-serpent-sse2",
1704 - .test = alg_test_null,
1706 - .alg = "__driver-cbc-twofish-avx",
1707 - .test = alg_test_null,
1709 - .alg = "__driver-ecb-aes-aesni",
1710 - .test = alg_test_null,
1711 - .fips_allowed = 1,
1713 - .alg = "__driver-ecb-camellia-aesni",
1714 - .test = alg_test_null,
1716 - .alg = "__driver-ecb-camellia-aesni-avx2",
1717 - .test = alg_test_null,
1719 - .alg = "__driver-ecb-cast5-avx",
1720 - .test = alg_test_null,
1722 - .alg = "__driver-ecb-cast6-avx",
1723 - .test = alg_test_null,
1725 - .alg = "__driver-ecb-serpent-avx",
1726 - .test = alg_test_null,
1728 - .alg = "__driver-ecb-serpent-avx2",
1729 - .test = alg_test_null,
1731 - .alg = "__driver-ecb-serpent-sse2",
1732 - .test = alg_test_null,
1734 - .alg = "__driver-ecb-twofish-avx",
1735 - .test = alg_test_null,
1737 - .alg = "__driver-gcm-aes-aesni",
1738 - .test = alg_test_null,
1739 - .fips_allowed = 1,
1741 - .alg = "__ghash-pclmulqdqni",
1742 - .test = alg_test_null,
1743 - .fips_allowed = 1,
1745 .alg = "ansi_cprng",
1746 .test = alg_test_cprng,
1749 - .vecs = ansi_cprng_aes_tv_template,
1750 - .count = ANSI_CPRNG_AES_TEST_VECTORS
1752 + .cprng = __VECS(ansi_cprng_aes_tv_template)
1755 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1756 .test = alg_test_aead,
1760 - .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1761 - .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1764 - .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1765 - .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1767 + .enc = __VECS(hmac_md5_ecb_cipher_null_enc_tv_template),
1768 + .dec = __VECS(hmac_md5_ecb_cipher_null_dec_tv_template)
1772 @@ -2201,12 +2525,7 @@ static const struct alg_test_desc alg_te
1773 .test = alg_test_aead,
1778 - hmac_sha1_aes_cbc_enc_tv_temp,
1780 - HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1782 + .enc = __VECS(hmac_sha1_aes_cbc_enc_tv_temp)
1786 @@ -2214,12 +2533,7 @@ static const struct alg_test_desc alg_te
1787 .test = alg_test_aead,
1792 - hmac_sha1_des_cbc_enc_tv_temp,
1794 - HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1796 + .enc = __VECS(hmac_sha1_des_cbc_enc_tv_temp)
1800 @@ -2228,12 +2542,7 @@ static const struct alg_test_desc alg_te
1806 - hmac_sha1_des3_ede_cbc_enc_tv_temp,
1808 - HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
1810 + .enc = __VECS(hmac_sha1_des3_ede_cbc_enc_tv_temp)
1814 @@ -2245,18 +2554,8 @@ static const struct alg_test_desc alg_te
1815 .test = alg_test_aead,
1820 - hmac_sha1_ecb_cipher_null_enc_tv_temp,
1822 - HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
1826 - hmac_sha1_ecb_cipher_null_dec_tv_temp,
1828 - HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1830 + .enc = __VECS(hmac_sha1_ecb_cipher_null_enc_tv_temp),
1831 + .dec = __VECS(hmac_sha1_ecb_cipher_null_dec_tv_temp)
1835 @@ -2268,12 +2567,7 @@ static const struct alg_test_desc alg_te
1836 .test = alg_test_aead,
1841 - hmac_sha224_des_cbc_enc_tv_temp,
1843 - HMAC_SHA224_DES_CBC_ENC_TEST_VEC
1845 + .enc = __VECS(hmac_sha224_des_cbc_enc_tv_temp)
1849 @@ -2282,12 +2576,7 @@ static const struct alg_test_desc alg_te
1855 - hmac_sha224_des3_ede_cbc_enc_tv_temp,
1857 - HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
1859 + .enc = __VECS(hmac_sha224_des3_ede_cbc_enc_tv_temp)
1863 @@ -2296,12 +2585,7 @@ static const struct alg_test_desc alg_te
1869 - hmac_sha256_aes_cbc_enc_tv_temp,
1871 - HMAC_SHA256_AES_CBC_ENC_TEST_VEC
1873 + .enc = __VECS(hmac_sha256_aes_cbc_enc_tv_temp)
1877 @@ -2309,12 +2593,7 @@ static const struct alg_test_desc alg_te
1878 .test = alg_test_aead,
1883 - hmac_sha256_des_cbc_enc_tv_temp,
1885 - HMAC_SHA256_DES_CBC_ENC_TEST_VEC
1887 + .enc = __VECS(hmac_sha256_des_cbc_enc_tv_temp)
1891 @@ -2323,12 +2602,7 @@ static const struct alg_test_desc alg_te
1897 - hmac_sha256_des3_ede_cbc_enc_tv_temp,
1899 - HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
1901 + .enc = __VECS(hmac_sha256_des3_ede_cbc_enc_tv_temp)
1905 @@ -2344,12 +2618,7 @@ static const struct alg_test_desc alg_te
1906 .test = alg_test_aead,
1911 - hmac_sha384_des_cbc_enc_tv_temp,
1913 - HMAC_SHA384_DES_CBC_ENC_TEST_VEC
1915 + .enc = __VECS(hmac_sha384_des_cbc_enc_tv_temp)
1919 @@ -2358,12 +2627,7 @@ static const struct alg_test_desc alg_te
1925 - hmac_sha384_des3_ede_cbc_enc_tv_temp,
1927 - HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
1929 + .enc = __VECS(hmac_sha384_des3_ede_cbc_enc_tv_temp)
1933 @@ -2380,12 +2644,7 @@ static const struct alg_test_desc alg_te
1934 .test = alg_test_aead,
1939 - hmac_sha512_aes_cbc_enc_tv_temp,
1941 - HMAC_SHA512_AES_CBC_ENC_TEST_VEC
1943 + .enc = __VECS(hmac_sha512_aes_cbc_enc_tv_temp)
1947 @@ -2393,12 +2652,7 @@ static const struct alg_test_desc alg_te
1948 .test = alg_test_aead,
1953 - hmac_sha512_des_cbc_enc_tv_temp,
1955 - HMAC_SHA512_DES_CBC_ENC_TEST_VEC
1957 + .enc = __VECS(hmac_sha512_des_cbc_enc_tv_temp)
1961 @@ -2407,12 +2661,7 @@ static const struct alg_test_desc alg_te
1967 - hmac_sha512_des3_ede_cbc_enc_tv_temp,
1969 - HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
1971 + .enc = __VECS(hmac_sha512_des3_ede_cbc_enc_tv_temp)
1975 @@ -2429,14 +2678,8 @@ static const struct alg_test_desc alg_te
1980 - .vecs = aes_cbc_enc_tv_template,
1981 - .count = AES_CBC_ENC_TEST_VECTORS
1984 - .vecs = aes_cbc_dec_tv_template,
1985 - .count = AES_CBC_DEC_TEST_VECTORS
1987 + .enc = __VECS(aes_cbc_enc_tv_template),
1988 + .dec = __VECS(aes_cbc_dec_tv_template)
1992 @@ -2444,14 +2687,8 @@ static const struct alg_test_desc alg_te
1993 .test = alg_test_skcipher,
1997 - .vecs = anubis_cbc_enc_tv_template,
1998 - .count = ANUBIS_CBC_ENC_TEST_VECTORS
2001 - .vecs = anubis_cbc_dec_tv_template,
2002 - .count = ANUBIS_CBC_DEC_TEST_VECTORS
2004 + .enc = __VECS(anubis_cbc_enc_tv_template),
2005 + .dec = __VECS(anubis_cbc_dec_tv_template)
2009 @@ -2459,14 +2696,8 @@ static const struct alg_test_desc alg_te
2010 .test = alg_test_skcipher,
2014 - .vecs = bf_cbc_enc_tv_template,
2015 - .count = BF_CBC_ENC_TEST_VECTORS
2018 - .vecs = bf_cbc_dec_tv_template,
2019 - .count = BF_CBC_DEC_TEST_VECTORS
2021 + .enc = __VECS(bf_cbc_enc_tv_template),
2022 + .dec = __VECS(bf_cbc_dec_tv_template)
2026 @@ -2474,14 +2705,8 @@ static const struct alg_test_desc alg_te
2027 .test = alg_test_skcipher,
2031 - .vecs = camellia_cbc_enc_tv_template,
2032 - .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2035 - .vecs = camellia_cbc_dec_tv_template,
2036 - .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2038 + .enc = __VECS(camellia_cbc_enc_tv_template),
2039 + .dec = __VECS(camellia_cbc_dec_tv_template)
2043 @@ -2489,14 +2714,8 @@ static const struct alg_test_desc alg_te
2044 .test = alg_test_skcipher,
2048 - .vecs = cast5_cbc_enc_tv_template,
2049 - .count = CAST5_CBC_ENC_TEST_VECTORS
2052 - .vecs = cast5_cbc_dec_tv_template,
2053 - .count = CAST5_CBC_DEC_TEST_VECTORS
2055 + .enc = __VECS(cast5_cbc_enc_tv_template),
2056 + .dec = __VECS(cast5_cbc_dec_tv_template)
2060 @@ -2504,14 +2723,8 @@ static const struct alg_test_desc alg_te
2061 .test = alg_test_skcipher,
2065 - .vecs = cast6_cbc_enc_tv_template,
2066 - .count = CAST6_CBC_ENC_TEST_VECTORS
2069 - .vecs = cast6_cbc_dec_tv_template,
2070 - .count = CAST6_CBC_DEC_TEST_VECTORS
2072 + .enc = __VECS(cast6_cbc_enc_tv_template),
2073 + .dec = __VECS(cast6_cbc_dec_tv_template)
2077 @@ -2519,14 +2732,8 @@ static const struct alg_test_desc alg_te
2078 .test = alg_test_skcipher,
2082 - .vecs = des_cbc_enc_tv_template,
2083 - .count = DES_CBC_ENC_TEST_VECTORS
2086 - .vecs = des_cbc_dec_tv_template,
2087 - .count = DES_CBC_DEC_TEST_VECTORS
2089 + .enc = __VECS(des_cbc_enc_tv_template),
2090 + .dec = __VECS(des_cbc_dec_tv_template)
2094 @@ -2535,14 +2742,8 @@ static const struct alg_test_desc alg_te
2099 - .vecs = des3_ede_cbc_enc_tv_template,
2100 - .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2103 - .vecs = des3_ede_cbc_dec_tv_template,
2104 - .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2106 + .enc = __VECS(des3_ede_cbc_enc_tv_template),
2107 + .dec = __VECS(des3_ede_cbc_dec_tv_template)
2111 @@ -2550,14 +2751,8 @@ static const struct alg_test_desc alg_te
2112 .test = alg_test_skcipher,
2116 - .vecs = serpent_cbc_enc_tv_template,
2117 - .count = SERPENT_CBC_ENC_TEST_VECTORS
2120 - .vecs = serpent_cbc_dec_tv_template,
2121 - .count = SERPENT_CBC_DEC_TEST_VECTORS
2123 + .enc = __VECS(serpent_cbc_enc_tv_template),
2124 + .dec = __VECS(serpent_cbc_dec_tv_template)
2128 @@ -2565,30 +2760,25 @@ static const struct alg_test_desc alg_te
2129 .test = alg_test_skcipher,
2133 - .vecs = tf_cbc_enc_tv_template,
2134 - .count = TF_CBC_ENC_TEST_VECTORS
2137 - .vecs = tf_cbc_dec_tv_template,
2138 - .count = TF_CBC_DEC_TEST_VECTORS
2140 + .enc = __VECS(tf_cbc_enc_tv_template),
2141 + .dec = __VECS(tf_cbc_dec_tv_template)
2145 + .alg = "cbcmac(aes)",
2146 + .fips_allowed = 1,
2147 + .test = alg_test_hash,
2149 + .hash = __VECS(aes_cbcmac_tv_template)
2153 .test = alg_test_aead,
2158 - .vecs = aes_ccm_enc_tv_template,
2159 - .count = AES_CCM_ENC_TEST_VECTORS
2162 - .vecs = aes_ccm_dec_tv_template,
2163 - .count = AES_CCM_DEC_TEST_VECTORS
2165 + .enc = __VECS(aes_ccm_enc_tv_template),
2166 + .dec = __VECS(aes_ccm_dec_tv_template)
2170 @@ -2596,14 +2786,8 @@ static const struct alg_test_desc alg_te
2171 .test = alg_test_skcipher,
2175 - .vecs = chacha20_enc_tv_template,
2176 - .count = CHACHA20_ENC_TEST_VECTORS
2179 - .vecs = chacha20_enc_tv_template,
2180 - .count = CHACHA20_ENC_TEST_VECTORS
2182 + .enc = __VECS(chacha20_enc_tv_template),
2183 + .dec = __VECS(chacha20_enc_tv_template),
2187 @@ -2611,20 +2795,14 @@ static const struct alg_test_desc alg_te
2189 .test = alg_test_hash,
2192 - .vecs = aes_cmac128_tv_template,
2193 - .count = CMAC_AES_TEST_VECTORS
2195 + .hash = __VECS(aes_cmac128_tv_template)
2198 .alg = "cmac(des3_ede)",
2200 .test = alg_test_hash,
2203 - .vecs = des3_ede_cmac64_tv_template,
2204 - .count = CMAC_DES3_EDE_TEST_VECTORS
2206 + .hash = __VECS(des3_ede_cmac64_tv_template)
2209 .alg = "compress_null",
2210 @@ -2633,94 +2811,30 @@ static const struct alg_test_desc alg_te
2212 .test = alg_test_hash,
2215 - .vecs = crc32_tv_template,
2216 - .count = CRC32_TEST_VECTORS
2218 + .hash = __VECS(crc32_tv_template)
2222 .test = alg_test_crc32c,
2226 - .vecs = crc32c_tv_template,
2227 - .count = CRC32C_TEST_VECTORS
2229 + .hash = __VECS(crc32c_tv_template)
2233 .test = alg_test_hash,
2237 - .vecs = crct10dif_tv_template,
2238 - .count = CRCT10DIF_TEST_VECTORS
2240 + .hash = __VECS(crct10dif_tv_template)
2243 - .alg = "cryptd(__driver-cbc-aes-aesni)",
2244 - .test = alg_test_null,
2245 - .fips_allowed = 1,
2247 - .alg = "cryptd(__driver-cbc-camellia-aesni)",
2248 - .test = alg_test_null,
2250 - .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2251 - .test = alg_test_null,
2253 - .alg = "cryptd(__driver-cbc-serpent-avx2)",
2254 - .test = alg_test_null,
2256 - .alg = "cryptd(__driver-ecb-aes-aesni)",
2257 - .test = alg_test_null,
2258 - .fips_allowed = 1,
2260 - .alg = "cryptd(__driver-ecb-camellia-aesni)",
2261 - .test = alg_test_null,
2263 - .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2264 - .test = alg_test_null,
2266 - .alg = "cryptd(__driver-ecb-cast5-avx)",
2267 - .test = alg_test_null,
2269 - .alg = "cryptd(__driver-ecb-cast6-avx)",
2270 - .test = alg_test_null,
2272 - .alg = "cryptd(__driver-ecb-serpent-avx)",
2273 - .test = alg_test_null,
2275 - .alg = "cryptd(__driver-ecb-serpent-avx2)",
2276 - .test = alg_test_null,
2278 - .alg = "cryptd(__driver-ecb-serpent-sse2)",
2279 - .test = alg_test_null,
2281 - .alg = "cryptd(__driver-ecb-twofish-avx)",
2282 - .test = alg_test_null,
2284 - .alg = "cryptd(__driver-gcm-aes-aesni)",
2285 - .test = alg_test_null,
2286 - .fips_allowed = 1,
2288 - .alg = "cryptd(__ghash-pclmulqdqni)",
2289 - .test = alg_test_null,
2290 - .fips_allowed = 1,
2293 .test = alg_test_skcipher,
2298 - .vecs = aes_ctr_enc_tv_template,
2299 - .count = AES_CTR_ENC_TEST_VECTORS
2302 - .vecs = aes_ctr_dec_tv_template,
2303 - .count = AES_CTR_DEC_TEST_VECTORS
2305 + .enc = __VECS(aes_ctr_enc_tv_template),
2306 + .dec = __VECS(aes_ctr_dec_tv_template)
2310 @@ -2728,14 +2842,8 @@ static const struct alg_test_desc alg_te
2311 .test = alg_test_skcipher,
2315 - .vecs = bf_ctr_enc_tv_template,
2316 - .count = BF_CTR_ENC_TEST_VECTORS
2319 - .vecs = bf_ctr_dec_tv_template,
2320 - .count = BF_CTR_DEC_TEST_VECTORS
2322 + .enc = __VECS(bf_ctr_enc_tv_template),
2323 + .dec = __VECS(bf_ctr_dec_tv_template)
2327 @@ -2743,14 +2851,8 @@ static const struct alg_test_desc alg_te
2328 .test = alg_test_skcipher,
2332 - .vecs = camellia_ctr_enc_tv_template,
2333 - .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2336 - .vecs = camellia_ctr_dec_tv_template,
2337 - .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2339 + .enc = __VECS(camellia_ctr_enc_tv_template),
2340 + .dec = __VECS(camellia_ctr_dec_tv_template)
2344 @@ -2758,14 +2860,8 @@ static const struct alg_test_desc alg_te
2345 .test = alg_test_skcipher,
2349 - .vecs = cast5_ctr_enc_tv_template,
2350 - .count = CAST5_CTR_ENC_TEST_VECTORS
2353 - .vecs = cast5_ctr_dec_tv_template,
2354 - .count = CAST5_CTR_DEC_TEST_VECTORS
2356 + .enc = __VECS(cast5_ctr_enc_tv_template),
2357 + .dec = __VECS(cast5_ctr_dec_tv_template)
2361 @@ -2773,14 +2869,8 @@ static const struct alg_test_desc alg_te
2362 .test = alg_test_skcipher,
2366 - .vecs = cast6_ctr_enc_tv_template,
2367 - .count = CAST6_CTR_ENC_TEST_VECTORS
2370 - .vecs = cast6_ctr_dec_tv_template,
2371 - .count = CAST6_CTR_DEC_TEST_VECTORS
2373 + .enc = __VECS(cast6_ctr_enc_tv_template),
2374 + .dec = __VECS(cast6_ctr_dec_tv_template)
2378 @@ -2788,29 +2878,18 @@ static const struct alg_test_desc alg_te
2379 .test = alg_test_skcipher,
2383 - .vecs = des_ctr_enc_tv_template,
2384 - .count = DES_CTR_ENC_TEST_VECTORS
2387 - .vecs = des_ctr_dec_tv_template,
2388 - .count = DES_CTR_DEC_TEST_VECTORS
2390 + .enc = __VECS(des_ctr_enc_tv_template),
2391 + .dec = __VECS(des_ctr_dec_tv_template)
2395 .alg = "ctr(des3_ede)",
2396 .test = alg_test_skcipher,
2397 + .fips_allowed = 1,
2401 - .vecs = des3_ede_ctr_enc_tv_template,
2402 - .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2405 - .vecs = des3_ede_ctr_dec_tv_template,
2406 - .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2408 + .enc = __VECS(des3_ede_ctr_enc_tv_template),
2409 + .dec = __VECS(des3_ede_ctr_dec_tv_template)
2413 @@ -2818,14 +2897,8 @@ static const struct alg_test_desc alg_te
2414 .test = alg_test_skcipher,
2418 - .vecs = serpent_ctr_enc_tv_template,
2419 - .count = SERPENT_CTR_ENC_TEST_VECTORS
2422 - .vecs = serpent_ctr_dec_tv_template,
2423 - .count = SERPENT_CTR_DEC_TEST_VECTORS
2425 + .enc = __VECS(serpent_ctr_enc_tv_template),
2426 + .dec = __VECS(serpent_ctr_dec_tv_template)
2430 @@ -2833,14 +2906,8 @@ static const struct alg_test_desc alg_te
2431 .test = alg_test_skcipher,
2435 - .vecs = tf_ctr_enc_tv_template,
2436 - .count = TF_CTR_ENC_TEST_VECTORS
2439 - .vecs = tf_ctr_dec_tv_template,
2440 - .count = TF_CTR_DEC_TEST_VECTORS
2442 + .enc = __VECS(tf_ctr_enc_tv_template),
2443 + .dec = __VECS(tf_ctr_dec_tv_template)
2447 @@ -2848,14 +2915,8 @@ static const struct alg_test_desc alg_te
2448 .test = alg_test_skcipher,
2452 - .vecs = cts_mode_enc_tv_template,
2453 - .count = CTS_MODE_ENC_TEST_VECTORS
2456 - .vecs = cts_mode_dec_tv_template,
2457 - .count = CTS_MODE_DEC_TEST_VECTORS
2459 + .enc = __VECS(cts_mode_enc_tv_template),
2460 + .dec = __VECS(cts_mode_dec_tv_template)
2464 @@ -2864,14 +2925,8 @@ static const struct alg_test_desc alg_te
2469 - .vecs = deflate_comp_tv_template,
2470 - .count = DEFLATE_COMP_TEST_VECTORS
2473 - .vecs = deflate_decomp_tv_template,
2474 - .count = DEFLATE_DECOMP_TEST_VECTORS
2476 + .comp = __VECS(deflate_comp_tv_template),
2477 + .decomp = __VECS(deflate_decomp_tv_template)
2481 @@ -2879,10 +2934,7 @@ static const struct alg_test_desc alg_te
2482 .test = alg_test_kpp,
2486 - .vecs = dh_tv_template,
2487 - .count = DH_TEST_VECTORS
2489 + .kpp = __VECS(dh_tv_template)
2492 .alg = "digest_null",
2493 @@ -2892,30 +2944,21 @@ static const struct alg_test_desc alg_te
2494 .test = alg_test_drbg,
2498 - .vecs = drbg_nopr_ctr_aes128_tv_template,
2499 - .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2501 + .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
2504 .alg = "drbg_nopr_ctr_aes192",
2505 .test = alg_test_drbg,
2509 - .vecs = drbg_nopr_ctr_aes192_tv_template,
2510 - .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2512 + .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
2515 .alg = "drbg_nopr_ctr_aes256",
2516 .test = alg_test_drbg,
2520 - .vecs = drbg_nopr_ctr_aes256_tv_template,
2521 - .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2523 + .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
2527 @@ -2930,11 +2973,7 @@ static const struct alg_test_desc alg_te
2528 .test = alg_test_drbg,
2532 - .vecs = drbg_nopr_hmac_sha256_tv_template,
2534 - ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2536 + .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
2539 /* covered by drbg_nopr_hmac_sha256 test */
2540 @@ -2954,10 +2993,7 @@ static const struct alg_test_desc alg_te
2541 .test = alg_test_drbg,
2545 - .vecs = drbg_nopr_sha256_tv_template,
2546 - .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2548 + .drbg = __VECS(drbg_nopr_sha256_tv_template)
2551 /* covered by drbg_nopr_sha256 test */
2552 @@ -2973,10 +3009,7 @@ static const struct alg_test_desc alg_te
2553 .test = alg_test_drbg,
2557 - .vecs = drbg_pr_ctr_aes128_tv_template,
2558 - .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2560 + .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
2563 /* covered by drbg_pr_ctr_aes128 test */
2564 @@ -2996,10 +3029,7 @@ static const struct alg_test_desc alg_te
2565 .test = alg_test_drbg,
2569 - .vecs = drbg_pr_hmac_sha256_tv_template,
2570 - .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2572 + .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
2575 /* covered by drbg_pr_hmac_sha256 test */
2576 @@ -3019,10 +3049,7 @@ static const struct alg_test_desc alg_te
2577 .test = alg_test_drbg,
2581 - .vecs = drbg_pr_sha256_tv_template,
2582 - .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2584 + .drbg = __VECS(drbg_pr_sha256_tv_template)
2587 /* covered by drbg_pr_sha256 test */
2588 @@ -3034,23 +3061,13 @@ static const struct alg_test_desc alg_te
2590 .test = alg_test_null,
2592 - .alg = "ecb(__aes-aesni)",
2593 - .test = alg_test_null,
2594 - .fips_allowed = 1,
2597 .test = alg_test_skcipher,
2602 - .vecs = aes_enc_tv_template,
2603 - .count = AES_ENC_TEST_VECTORS
2606 - .vecs = aes_dec_tv_template,
2607 - .count = AES_DEC_TEST_VECTORS
2609 + .enc = __VECS(aes_enc_tv_template),
2610 + .dec = __VECS(aes_dec_tv_template)
2614 @@ -3058,14 +3075,8 @@ static const struct alg_test_desc alg_te
2615 .test = alg_test_skcipher,
2619 - .vecs = anubis_enc_tv_template,
2620 - .count = ANUBIS_ENC_TEST_VECTORS
2623 - .vecs = anubis_dec_tv_template,
2624 - .count = ANUBIS_DEC_TEST_VECTORS
2626 + .enc = __VECS(anubis_enc_tv_template),
2627 + .dec = __VECS(anubis_dec_tv_template)
2631 @@ -3073,14 +3084,8 @@ static const struct alg_test_desc alg_te
2632 .test = alg_test_skcipher,
2636 - .vecs = arc4_enc_tv_template,
2637 - .count = ARC4_ENC_TEST_VECTORS
2640 - .vecs = arc4_dec_tv_template,
2641 - .count = ARC4_DEC_TEST_VECTORS
2643 + .enc = __VECS(arc4_enc_tv_template),
2644 + .dec = __VECS(arc4_dec_tv_template)
2648 @@ -3088,14 +3093,8 @@ static const struct alg_test_desc alg_te
2649 .test = alg_test_skcipher,
2653 - .vecs = bf_enc_tv_template,
2654 - .count = BF_ENC_TEST_VECTORS
2657 - .vecs = bf_dec_tv_template,
2658 - .count = BF_DEC_TEST_VECTORS
2660 + .enc = __VECS(bf_enc_tv_template),
2661 + .dec = __VECS(bf_dec_tv_template)
2665 @@ -3103,14 +3102,8 @@ static const struct alg_test_desc alg_te
2666 .test = alg_test_skcipher,
2670 - .vecs = camellia_enc_tv_template,
2671 - .count = CAMELLIA_ENC_TEST_VECTORS
2674 - .vecs = camellia_dec_tv_template,
2675 - .count = CAMELLIA_DEC_TEST_VECTORS
2677 + .enc = __VECS(camellia_enc_tv_template),
2678 + .dec = __VECS(camellia_dec_tv_template)
2682 @@ -3118,14 +3111,8 @@ static const struct alg_test_desc alg_te
2683 .test = alg_test_skcipher,
2687 - .vecs = cast5_enc_tv_template,
2688 - .count = CAST5_ENC_TEST_VECTORS
2691 - .vecs = cast5_dec_tv_template,
2692 - .count = CAST5_DEC_TEST_VECTORS
2694 + .enc = __VECS(cast5_enc_tv_template),
2695 + .dec = __VECS(cast5_dec_tv_template)
2699 @@ -3133,14 +3120,8 @@ static const struct alg_test_desc alg_te
2700 .test = alg_test_skcipher,
2704 - .vecs = cast6_enc_tv_template,
2705 - .count = CAST6_ENC_TEST_VECTORS
2708 - .vecs = cast6_dec_tv_template,
2709 - .count = CAST6_DEC_TEST_VECTORS
2711 + .enc = __VECS(cast6_enc_tv_template),
2712 + .dec = __VECS(cast6_dec_tv_template)
2716 @@ -3151,14 +3132,8 @@ static const struct alg_test_desc alg_te
2717 .test = alg_test_skcipher,
2721 - .vecs = des_enc_tv_template,
2722 - .count = DES_ENC_TEST_VECTORS
2725 - .vecs = des_dec_tv_template,
2726 - .count = DES_DEC_TEST_VECTORS
2728 + .enc = __VECS(des_enc_tv_template),
2729 + .dec = __VECS(des_dec_tv_template)
2733 @@ -3167,14 +3142,8 @@ static const struct alg_test_desc alg_te
2738 - .vecs = des3_ede_enc_tv_template,
2739 - .count = DES3_EDE_ENC_TEST_VECTORS
2742 - .vecs = des3_ede_dec_tv_template,
2743 - .count = DES3_EDE_DEC_TEST_VECTORS
2745 + .enc = __VECS(des3_ede_enc_tv_template),
2746 + .dec = __VECS(des3_ede_dec_tv_template)
2750 @@ -3197,14 +3166,8 @@ static const struct alg_test_desc alg_te
2751 .test = alg_test_skcipher,
2755 - .vecs = khazad_enc_tv_template,
2756 - .count = KHAZAD_ENC_TEST_VECTORS
2759 - .vecs = khazad_dec_tv_template,
2760 - .count = KHAZAD_DEC_TEST_VECTORS
2762 + .enc = __VECS(khazad_enc_tv_template),
2763 + .dec = __VECS(khazad_dec_tv_template)
2767 @@ -3212,14 +3175,8 @@ static const struct alg_test_desc alg_te
2768 .test = alg_test_skcipher,
2772 - .vecs = seed_enc_tv_template,
2773 - .count = SEED_ENC_TEST_VECTORS
2776 - .vecs = seed_dec_tv_template,
2777 - .count = SEED_DEC_TEST_VECTORS
2779 + .enc = __VECS(seed_enc_tv_template),
2780 + .dec = __VECS(seed_dec_tv_template)
2784 @@ -3227,14 +3184,8 @@ static const struct alg_test_desc alg_te
2785 .test = alg_test_skcipher,
2789 - .vecs = serpent_enc_tv_template,
2790 - .count = SERPENT_ENC_TEST_VECTORS
2793 - .vecs = serpent_dec_tv_template,
2794 - .count = SERPENT_DEC_TEST_VECTORS
2796 + .enc = __VECS(serpent_enc_tv_template),
2797 + .dec = __VECS(serpent_dec_tv_template)
2801 @@ -3242,14 +3193,8 @@ static const struct alg_test_desc alg_te
2802 .test = alg_test_skcipher,
2806 - .vecs = tea_enc_tv_template,
2807 - .count = TEA_ENC_TEST_VECTORS
2810 - .vecs = tea_dec_tv_template,
2811 - .count = TEA_DEC_TEST_VECTORS
2813 + .enc = __VECS(tea_enc_tv_template),
2814 + .dec = __VECS(tea_dec_tv_template)
2818 @@ -3257,14 +3202,8 @@ static const struct alg_test_desc alg_te
2819 .test = alg_test_skcipher,
2823 - .vecs = tnepres_enc_tv_template,
2824 - .count = TNEPRES_ENC_TEST_VECTORS
2827 - .vecs = tnepres_dec_tv_template,
2828 - .count = TNEPRES_DEC_TEST_VECTORS
2830 + .enc = __VECS(tnepres_enc_tv_template),
2831 + .dec = __VECS(tnepres_dec_tv_template)
2835 @@ -3272,14 +3211,8 @@ static const struct alg_test_desc alg_te
2836 .test = alg_test_skcipher,
2840 - .vecs = tf_enc_tv_template,
2841 - .count = TF_ENC_TEST_VECTORS
2844 - .vecs = tf_dec_tv_template,
2845 - .count = TF_DEC_TEST_VECTORS
2847 + .enc = __VECS(tf_enc_tv_template),
2848 + .dec = __VECS(tf_dec_tv_template)
2852 @@ -3287,14 +3220,8 @@ static const struct alg_test_desc alg_te
2853 .test = alg_test_skcipher,
2857 - .vecs = xeta_enc_tv_template,
2858 - .count = XETA_ENC_TEST_VECTORS
2861 - .vecs = xeta_dec_tv_template,
2862 - .count = XETA_DEC_TEST_VECTORS
2864 + .enc = __VECS(xeta_enc_tv_template),
2865 + .dec = __VECS(xeta_dec_tv_template)
2869 @@ -3302,14 +3229,8 @@ static const struct alg_test_desc alg_te
2870 .test = alg_test_skcipher,
2874 - .vecs = xtea_enc_tv_template,
2875 - .count = XTEA_ENC_TEST_VECTORS
2878 - .vecs = xtea_dec_tv_template,
2879 - .count = XTEA_DEC_TEST_VECTORS
2881 + .enc = __VECS(xtea_enc_tv_template),
2882 + .dec = __VECS(xtea_dec_tv_template)
2886 @@ -3317,10 +3238,7 @@ static const struct alg_test_desc alg_te
2887 .test = alg_test_kpp,
2891 - .vecs = ecdh_tv_template,
2892 - .count = ECDH_TEST_VECTORS
2894 + .kpp = __VECS(ecdh_tv_template)
2898 @@ -3328,14 +3246,8 @@ static const struct alg_test_desc alg_te
2903 - .vecs = aes_gcm_enc_tv_template,
2904 - .count = AES_GCM_ENC_TEST_VECTORS
2907 - .vecs = aes_gcm_dec_tv_template,
2908 - .count = AES_GCM_DEC_TEST_VECTORS
2910 + .enc = __VECS(aes_gcm_enc_tv_template),
2911 + .dec = __VECS(aes_gcm_dec_tv_template)
2915 @@ -3343,136 +3255,94 @@ static const struct alg_test_desc alg_te
2916 .test = alg_test_hash,
2920 - .vecs = ghash_tv_template,
2921 - .count = GHASH_TEST_VECTORS
2923 + .hash = __VECS(ghash_tv_template)
2926 .alg = "hmac(crc32)",
2927 .test = alg_test_hash,
2930 - .vecs = bfin_crc_tv_template,
2931 - .count = BFIN_CRC_TEST_VECTORS
2933 + .hash = __VECS(bfin_crc_tv_template)
2937 .test = alg_test_hash,
2940 - .vecs = hmac_md5_tv_template,
2941 - .count = HMAC_MD5_TEST_VECTORS
2943 + .hash = __VECS(hmac_md5_tv_template)
2946 .alg = "hmac(rmd128)",
2947 .test = alg_test_hash,
2950 - .vecs = hmac_rmd128_tv_template,
2951 - .count = HMAC_RMD128_TEST_VECTORS
2953 + .hash = __VECS(hmac_rmd128_tv_template)
2956 .alg = "hmac(rmd160)",
2957 .test = alg_test_hash,
2960 - .vecs = hmac_rmd160_tv_template,
2961 - .count = HMAC_RMD160_TEST_VECTORS
2963 + .hash = __VECS(hmac_rmd160_tv_template)
2966 .alg = "hmac(sha1)",
2967 .test = alg_test_hash,
2971 - .vecs = hmac_sha1_tv_template,
2972 - .count = HMAC_SHA1_TEST_VECTORS
2974 + .hash = __VECS(hmac_sha1_tv_template)
2977 .alg = "hmac(sha224)",
2978 .test = alg_test_hash,
2982 - .vecs = hmac_sha224_tv_template,
2983 - .count = HMAC_SHA224_TEST_VECTORS
2985 + .hash = __VECS(hmac_sha224_tv_template)
2988 .alg = "hmac(sha256)",
2989 .test = alg_test_hash,
2993 - .vecs = hmac_sha256_tv_template,
2994 - .count = HMAC_SHA256_TEST_VECTORS
2996 + .hash = __VECS(hmac_sha256_tv_template)
2999 .alg = "hmac(sha3-224)",
3000 .test = alg_test_hash,
3004 - .vecs = hmac_sha3_224_tv_template,
3005 - .count = HMAC_SHA3_224_TEST_VECTORS
3007 + .hash = __VECS(hmac_sha3_224_tv_template)
3010 .alg = "hmac(sha3-256)",
3011 .test = alg_test_hash,
3015 - .vecs = hmac_sha3_256_tv_template,
3016 - .count = HMAC_SHA3_256_TEST_VECTORS
3018 + .hash = __VECS(hmac_sha3_256_tv_template)
3021 .alg = "hmac(sha3-384)",
3022 .test = alg_test_hash,
3026 - .vecs = hmac_sha3_384_tv_template,
3027 - .count = HMAC_SHA3_384_TEST_VECTORS
3029 + .hash = __VECS(hmac_sha3_384_tv_template)
3032 .alg = "hmac(sha3-512)",
3033 .test = alg_test_hash,
3037 - .vecs = hmac_sha3_512_tv_template,
3038 - .count = HMAC_SHA3_512_TEST_VECTORS
3040 + .hash = __VECS(hmac_sha3_512_tv_template)
3043 .alg = "hmac(sha384)",
3044 .test = alg_test_hash,
3048 - .vecs = hmac_sha384_tv_template,
3049 - .count = HMAC_SHA384_TEST_VECTORS
3051 + .hash = __VECS(hmac_sha384_tv_template)
3054 .alg = "hmac(sha512)",
3055 .test = alg_test_hash,
3059 - .vecs = hmac_sha512_tv_template,
3060 - .count = HMAC_SHA512_TEST_VECTORS
3062 + .hash = __VECS(hmac_sha512_tv_template)
3065 .alg = "jitterentropy_rng",
3066 @@ -3484,14 +3354,8 @@ static const struct alg_test_desc alg_te
3071 - .vecs = aes_kw_enc_tv_template,
3072 - .count = ARRAY_SIZE(aes_kw_enc_tv_template)
3075 - .vecs = aes_kw_dec_tv_template,
3076 - .count = ARRAY_SIZE(aes_kw_dec_tv_template)
3078 + .enc = __VECS(aes_kw_enc_tv_template),
3079 + .dec = __VECS(aes_kw_dec_tv_template)
3083 @@ -3499,14 +3363,8 @@ static const struct alg_test_desc alg_te
3084 .test = alg_test_skcipher,
3088 - .vecs = aes_lrw_enc_tv_template,
3089 - .count = AES_LRW_ENC_TEST_VECTORS
3092 - .vecs = aes_lrw_dec_tv_template,
3093 - .count = AES_LRW_DEC_TEST_VECTORS
3095 + .enc = __VECS(aes_lrw_enc_tv_template),
3096 + .dec = __VECS(aes_lrw_dec_tv_template)
3100 @@ -3514,14 +3372,8 @@ static const struct alg_test_desc alg_te
3101 .test = alg_test_skcipher,
3105 - .vecs = camellia_lrw_enc_tv_template,
3106 - .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3109 - .vecs = camellia_lrw_dec_tv_template,
3110 - .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3112 + .enc = __VECS(camellia_lrw_enc_tv_template),
3113 + .dec = __VECS(camellia_lrw_dec_tv_template)
3117 @@ -3529,14 +3381,8 @@ static const struct alg_test_desc alg_te
3118 .test = alg_test_skcipher,
3122 - .vecs = cast6_lrw_enc_tv_template,
3123 - .count = CAST6_LRW_ENC_TEST_VECTORS
3126 - .vecs = cast6_lrw_dec_tv_template,
3127 - .count = CAST6_LRW_DEC_TEST_VECTORS
3129 + .enc = __VECS(cast6_lrw_enc_tv_template),
3130 + .dec = __VECS(cast6_lrw_dec_tv_template)
3134 @@ -3544,14 +3390,8 @@ static const struct alg_test_desc alg_te
3135 .test = alg_test_skcipher,
3139 - .vecs = serpent_lrw_enc_tv_template,
3140 - .count = SERPENT_LRW_ENC_TEST_VECTORS
3143 - .vecs = serpent_lrw_dec_tv_template,
3144 - .count = SERPENT_LRW_DEC_TEST_VECTORS
3146 + .enc = __VECS(serpent_lrw_enc_tv_template),
3147 + .dec = __VECS(serpent_lrw_dec_tv_template)
3151 @@ -3559,14 +3399,8 @@ static const struct alg_test_desc alg_te
3152 .test = alg_test_skcipher,
3156 - .vecs = tf_lrw_enc_tv_template,
3157 - .count = TF_LRW_ENC_TEST_VECTORS
3160 - .vecs = tf_lrw_dec_tv_template,
3161 - .count = TF_LRW_DEC_TEST_VECTORS
3163 + .enc = __VECS(tf_lrw_enc_tv_template),
3164 + .dec = __VECS(tf_lrw_dec_tv_template)
3168 @@ -3575,14 +3409,8 @@ static const struct alg_test_desc alg_te
3173 - .vecs = lz4_comp_tv_template,
3174 - .count = LZ4_COMP_TEST_VECTORS
3177 - .vecs = lz4_decomp_tv_template,
3178 - .count = LZ4_DECOMP_TEST_VECTORS
3180 + .comp = __VECS(lz4_comp_tv_template),
3181 + .decomp = __VECS(lz4_decomp_tv_template)
3185 @@ -3591,14 +3419,8 @@ static const struct alg_test_desc alg_te
3190 - .vecs = lz4hc_comp_tv_template,
3191 - .count = LZ4HC_COMP_TEST_VECTORS
3194 - .vecs = lz4hc_decomp_tv_template,
3195 - .count = LZ4HC_DECOMP_TEST_VECTORS
3197 + .comp = __VECS(lz4hc_comp_tv_template),
3198 + .decomp = __VECS(lz4hc_decomp_tv_template)
3202 @@ -3607,42 +3429,27 @@ static const struct alg_test_desc alg_te
3207 - .vecs = lzo_comp_tv_template,
3208 - .count = LZO_COMP_TEST_VECTORS
3211 - .vecs = lzo_decomp_tv_template,
3212 - .count = LZO_DECOMP_TEST_VECTORS
3214 + .comp = __VECS(lzo_comp_tv_template),
3215 + .decomp = __VECS(lzo_decomp_tv_template)
3220 .test = alg_test_hash,
3223 - .vecs = md4_tv_template,
3224 - .count = MD4_TEST_VECTORS
3226 + .hash = __VECS(md4_tv_template)
3230 .test = alg_test_hash,
3233 - .vecs = md5_tv_template,
3234 - .count = MD5_TEST_VECTORS
3236 + .hash = __VECS(md5_tv_template)
3239 .alg = "michael_mic",
3240 .test = alg_test_hash,
3243 - .vecs = michael_mic_tv_template,
3244 - .count = MICHAEL_MIC_TEST_VECTORS
3246 + .hash = __VECS(michael_mic_tv_template)
3250 @@ -3650,14 +3457,8 @@ static const struct alg_test_desc alg_te
3255 - .vecs = aes_ofb_enc_tv_template,
3256 - .count = AES_OFB_ENC_TEST_VECTORS
3259 - .vecs = aes_ofb_dec_tv_template,
3260 - .count = AES_OFB_DEC_TEST_VECTORS
3262 + .enc = __VECS(aes_ofb_enc_tv_template),
3263 + .dec = __VECS(aes_ofb_dec_tv_template)
3267 @@ -3665,24 +3466,15 @@ static const struct alg_test_desc alg_te
3268 .test = alg_test_skcipher,
3272 - .vecs = fcrypt_pcbc_enc_tv_template,
3273 - .count = FCRYPT_ENC_TEST_VECTORS
3276 - .vecs = fcrypt_pcbc_dec_tv_template,
3277 - .count = FCRYPT_DEC_TEST_VECTORS
3279 + .enc = __VECS(fcrypt_pcbc_enc_tv_template),
3280 + .dec = __VECS(fcrypt_pcbc_dec_tv_template)
3285 .test = alg_test_hash,
3288 - .vecs = poly1305_tv_template,
3289 - .count = POLY1305_TEST_VECTORS
3291 + .hash = __VECS(poly1305_tv_template)
3294 .alg = "rfc3686(ctr(aes))",
3295 @@ -3690,14 +3482,8 @@ static const struct alg_test_desc alg_te
3300 - .vecs = aes_ctr_rfc3686_enc_tv_template,
3301 - .count = AES_CTR_3686_ENC_TEST_VECTORS
3304 - .vecs = aes_ctr_rfc3686_dec_tv_template,
3305 - .count = AES_CTR_3686_DEC_TEST_VECTORS
3307 + .enc = __VECS(aes_ctr_rfc3686_enc_tv_template),
3308 + .dec = __VECS(aes_ctr_rfc3686_dec_tv_template)
3312 @@ -3706,14 +3492,8 @@ static const struct alg_test_desc alg_te
3317 - .vecs = aes_gcm_rfc4106_enc_tv_template,
3318 - .count = AES_GCM_4106_ENC_TEST_VECTORS
3321 - .vecs = aes_gcm_rfc4106_dec_tv_template,
3322 - .count = AES_GCM_4106_DEC_TEST_VECTORS
3324 + .enc = __VECS(aes_gcm_rfc4106_enc_tv_template),
3325 + .dec = __VECS(aes_gcm_rfc4106_dec_tv_template)
3329 @@ -3722,14 +3502,8 @@ static const struct alg_test_desc alg_te
3334 - .vecs = aes_ccm_rfc4309_enc_tv_template,
3335 - .count = AES_CCM_4309_ENC_TEST_VECTORS
3338 - .vecs = aes_ccm_rfc4309_dec_tv_template,
3339 - .count = AES_CCM_4309_DEC_TEST_VECTORS
3341 + .enc = __VECS(aes_ccm_rfc4309_enc_tv_template),
3342 + .dec = __VECS(aes_ccm_rfc4309_dec_tv_template)
3346 @@ -3737,14 +3511,8 @@ static const struct alg_test_desc alg_te
3347 .test = alg_test_aead,
3351 - .vecs = aes_gcm_rfc4543_enc_tv_template,
3352 - .count = AES_GCM_4543_ENC_TEST_VECTORS
3355 - .vecs = aes_gcm_rfc4543_dec_tv_template,
3356 - .count = AES_GCM_4543_DEC_TEST_VECTORS
3358 + .enc = __VECS(aes_gcm_rfc4543_enc_tv_template),
3359 + .dec = __VECS(aes_gcm_rfc4543_dec_tv_template),
3363 @@ -3752,14 +3520,8 @@ static const struct alg_test_desc alg_te
3364 .test = alg_test_aead,
3368 - .vecs = rfc7539_enc_tv_template,
3369 - .count = RFC7539_ENC_TEST_VECTORS
3372 - .vecs = rfc7539_dec_tv_template,
3373 - .count = RFC7539_DEC_TEST_VECTORS
3375 + .enc = __VECS(rfc7539_enc_tv_template),
3376 + .dec = __VECS(rfc7539_dec_tv_template),
3380 @@ -3767,71 +3529,47 @@ static const struct alg_test_desc alg_te
3381 .test = alg_test_aead,
3385 - .vecs = rfc7539esp_enc_tv_template,
3386 - .count = RFC7539ESP_ENC_TEST_VECTORS
3389 - .vecs = rfc7539esp_dec_tv_template,
3390 - .count = RFC7539ESP_DEC_TEST_VECTORS
3392 + .enc = __VECS(rfc7539esp_enc_tv_template),
3393 + .dec = __VECS(rfc7539esp_dec_tv_template),
3398 .test = alg_test_hash,
3401 - .vecs = rmd128_tv_template,
3402 - .count = RMD128_TEST_VECTORS
3404 + .hash = __VECS(rmd128_tv_template)
3408 .test = alg_test_hash,
3411 - .vecs = rmd160_tv_template,
3412 - .count = RMD160_TEST_VECTORS
3414 + .hash = __VECS(rmd160_tv_template)
3418 .test = alg_test_hash,
3421 - .vecs = rmd256_tv_template,
3422 - .count = RMD256_TEST_VECTORS
3424 + .hash = __VECS(rmd256_tv_template)
3428 .test = alg_test_hash,
3431 - .vecs = rmd320_tv_template,
3432 - .count = RMD320_TEST_VECTORS
3434 + .hash = __VECS(rmd320_tv_template)
3438 .test = alg_test_akcipher,
3442 - .vecs = rsa_tv_template,
3443 - .count = RSA_TEST_VECTORS
3445 + .akcipher = __VECS(rsa_tv_template)
3449 .test = alg_test_skcipher,
3453 - .vecs = salsa20_stream_enc_tv_template,
3454 - .count = SALSA20_STREAM_ENC_TEST_VECTORS
3456 + .enc = __VECS(salsa20_stream_enc_tv_template)
3460 @@ -3839,162 +3577,120 @@ static const struct alg_test_desc alg_te
3461 .test = alg_test_hash,
3465 - .vecs = sha1_tv_template,
3466 - .count = SHA1_TEST_VECTORS
3468 + .hash = __VECS(sha1_tv_template)
3472 .test = alg_test_hash,
3476 - .vecs = sha224_tv_template,
3477 - .count = SHA224_TEST_VECTORS
3479 + .hash = __VECS(sha224_tv_template)
3483 .test = alg_test_hash,
3487 - .vecs = sha256_tv_template,
3488 - .count = SHA256_TEST_VECTORS
3490 + .hash = __VECS(sha256_tv_template)
3494 .test = alg_test_hash,
3498 - .vecs = sha3_224_tv_template,
3499 - .count = SHA3_224_TEST_VECTORS
3501 + .hash = __VECS(sha3_224_tv_template)
3505 .test = alg_test_hash,
3509 - .vecs = sha3_256_tv_template,
3510 - .count = SHA3_256_TEST_VECTORS
3512 + .hash = __VECS(sha3_256_tv_template)
3516 .test = alg_test_hash,
3520 - .vecs = sha3_384_tv_template,
3521 - .count = SHA3_384_TEST_VECTORS
3523 + .hash = __VECS(sha3_384_tv_template)
3527 .test = alg_test_hash,
3531 - .vecs = sha3_512_tv_template,
3532 - .count = SHA3_512_TEST_VECTORS
3534 + .hash = __VECS(sha3_512_tv_template)
3538 .test = alg_test_hash,
3542 - .vecs = sha384_tv_template,
3543 - .count = SHA384_TEST_VECTORS
3545 + .hash = __VECS(sha384_tv_template)
3549 .test = alg_test_hash,
3553 - .vecs = sha512_tv_template,
3554 - .count = SHA512_TEST_VECTORS
3556 + .hash = __VECS(sha512_tv_template)
3560 .test = alg_test_hash,
3563 - .vecs = tgr128_tv_template,
3564 - .count = TGR128_TEST_VECTORS
3566 + .hash = __VECS(tgr128_tv_template)
3570 .test = alg_test_hash,
3573 - .vecs = tgr160_tv_template,
3574 - .count = TGR160_TEST_VECTORS
3576 + .hash = __VECS(tgr160_tv_template)
3580 .test = alg_test_hash,
3583 - .vecs = tgr192_tv_template,
3584 - .count = TGR192_TEST_VECTORS
3585 + .hash = __VECS(tgr192_tv_template)
3588 + .alg = "tls10(hmac(sha1),cbc(aes))",
3589 + .test = alg_test_tls,
3592 + .enc = __VECS(tls_enc_tv_template),
3593 + .dec = __VECS(tls_dec_tv_template)
3598 .test = alg_test_hash,
3601 - .vecs = aes_vmac128_tv_template,
3602 - .count = VMAC_AES_TEST_VECTORS
3604 + .hash = __VECS(aes_vmac128_tv_template)
3608 .test = alg_test_hash,
3611 - .vecs = wp256_tv_template,
3612 - .count = WP256_TEST_VECTORS
3614 + .hash = __VECS(wp256_tv_template)
3618 .test = alg_test_hash,
3621 - .vecs = wp384_tv_template,
3622 - .count = WP384_TEST_VECTORS
3624 + .hash = __VECS(wp384_tv_template)
3628 .test = alg_test_hash,
3631 - .vecs = wp512_tv_template,
3632 - .count = WP512_TEST_VECTORS
3634 + .hash = __VECS(wp512_tv_template)
3638 .test = alg_test_hash,
3641 - .vecs = aes_xcbc128_tv_template,
3642 - .count = XCBC_AES_TEST_VECTORS
3644 + .hash = __VECS(aes_xcbc128_tv_template)
3648 @@ -4002,14 +3698,8 @@ static const struct alg_test_desc alg_te
3653 - .vecs = aes_xts_enc_tv_template,
3654 - .count = AES_XTS_ENC_TEST_VECTORS
3657 - .vecs = aes_xts_dec_tv_template,
3658 - .count = AES_XTS_DEC_TEST_VECTORS
3660 + .enc = __VECS(aes_xts_enc_tv_template),
3661 + .dec = __VECS(aes_xts_dec_tv_template)
3665 @@ -4017,14 +3707,8 @@ static const struct alg_test_desc alg_te
3666 .test = alg_test_skcipher,
3670 - .vecs = camellia_xts_enc_tv_template,
3671 - .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3674 - .vecs = camellia_xts_dec_tv_template,
3675 - .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3677 + .enc = __VECS(camellia_xts_enc_tv_template),
3678 + .dec = __VECS(camellia_xts_dec_tv_template)
3682 @@ -4032,14 +3716,8 @@ static const struct alg_test_desc alg_te
3683 .test = alg_test_skcipher,
3687 - .vecs = cast6_xts_enc_tv_template,
3688 - .count = CAST6_XTS_ENC_TEST_VECTORS
3691 - .vecs = cast6_xts_dec_tv_template,
3692 - .count = CAST6_XTS_DEC_TEST_VECTORS
3694 + .enc = __VECS(cast6_xts_enc_tv_template),
3695 + .dec = __VECS(cast6_xts_dec_tv_template)
3699 @@ -4047,14 +3725,8 @@ static const struct alg_test_desc alg_te
3700 .test = alg_test_skcipher,
3704 - .vecs = serpent_xts_enc_tv_template,
3705 - .count = SERPENT_XTS_ENC_TEST_VECTORS
3708 - .vecs = serpent_xts_dec_tv_template,
3709 - .count = SERPENT_XTS_DEC_TEST_VECTORS
3711 + .enc = __VECS(serpent_xts_enc_tv_template),
3712 + .dec = __VECS(serpent_xts_dec_tv_template)
3716 @@ -4062,14 +3734,8 @@ static const struct alg_test_desc alg_te
3717 .test = alg_test_skcipher,
3721 - .vecs = tf_xts_enc_tv_template,
3722 - .count = TF_XTS_ENC_TEST_VECTORS
3725 - .vecs = tf_xts_dec_tv_template,
3726 - .count = TF_XTS_DEC_TEST_VECTORS
3728 + .enc = __VECS(tf_xts_enc_tv_template),
3729 + .dec = __VECS(tf_xts_dec_tv_template)
3733 --- a/crypto/testmgr.h
3734 +++ b/crypto/testmgr.h
3737 struct hash_testvec {
3738 /* only used with keyed hash algorithms */
3743 + const char *plaintext;
3744 + const char *digest;
3745 unsigned char tap[MAX_TAP];
3746 unsigned short psize;
3748 @@ -63,11 +63,11 @@ struct hash_testvec {
3751 struct cipher_testvec {
3759 + const char *iv_out;
3760 + const char *input;
3761 + const char *result;
3762 unsigned short tap[MAX_TAP];
3764 unsigned char also_non_np;
3765 @@ -80,11 +80,11 @@ struct cipher_testvec {
3768 struct aead_testvec {
3776 + const char *input;
3777 + const char *assoc;
3778 + const char *result;
3779 unsigned char tap[MAX_TAP];
3780 unsigned char atap[MAX_TAP];
3782 @@ -99,10 +99,10 @@ struct aead_testvec {
3785 struct cprng_testvec {
3793 + const char *result;
3795 unsigned short dtlen;
3796 unsigned short vlen;
3797 @@ -111,24 +111,38 @@ struct cprng_testvec {
3800 struct drbg_testvec {
3801 - unsigned char *entropy;
3802 + const unsigned char *entropy;
3804 - unsigned char *entpra;
3805 - unsigned char *entprb;
3806 + const unsigned char *entpra;
3807 + const unsigned char *entprb;
3809 - unsigned char *addtla;
3810 - unsigned char *addtlb;
3811 + const unsigned char *addtla;
3812 + const unsigned char *addtlb;
3814 - unsigned char *pers;
3815 + const unsigned char *pers;
3817 - unsigned char *expected;
3818 + const unsigned char *expected;
3822 +struct tls_testvec {
3823 + char *key; /* wrapped keys for encryption and authentication */
3824 + char *iv; /* initialization vector */
3825 + char *input; /* input data */
3826 + char *assoc; /* associated data: seq num, type, version, input len */
3827 + char *result; /* result data */
3828 + unsigned char fail; /* the test failure is expected */
3829 + unsigned char novrfy; /* dec verification failure expected */
3830 + unsigned char klen; /* key length */
3831 + unsigned short ilen; /* input data length */
3832 + unsigned short alen; /* associated data length */
3833 + unsigned short rlen; /* result length */
3836 struct akcipher_testvec {
3837 - unsigned char *key;
3840 + const unsigned char *key;
3841 + const unsigned char *m;
3842 + const unsigned char *c;
3843 unsigned int key_len;
3844 unsigned int m_size;
3845 unsigned int c_size;
3846 @@ -136,27 +150,227 @@ struct akcipher_testvec {
3849 struct kpp_testvec {
3850 - unsigned char *secret;
3851 - unsigned char *b_public;
3852 - unsigned char *expected_a_public;
3853 - unsigned char *expected_ss;
3854 + const unsigned char *secret;
3855 + const unsigned char *b_public;
3856 + const unsigned char *expected_a_public;
3857 + const unsigned char *expected_ss;
3858 unsigned short secret_size;
3859 unsigned short b_public_size;
3860 unsigned short expected_a_public_size;
3861 unsigned short expected_ss_size;
3864 -static char zeroed_string[48];
3865 +static const char zeroed_string[48];
3868 - * RSA test vectors. Borrowed from openSSL.
3869 + * TLS1.0 synthetic test vectors
3871 -#ifdef CONFIG_CRYPTO_FIPS
3872 -#define RSA_TEST_VECTORS 2
3873 +static struct tls_testvec tls_enc_tv_template[] = {
3875 +#ifdef __LITTLE_ENDIAN
3876 + .key = "\x08\x00" /* rta length */
3877 + "\x01\x00" /* rta type */
3879 + .key = "\x00\x08" /* rta length */
3880 + "\x00\x01" /* rta type */
3882 + "\x00\x00\x00\x10" /* enc key length */
3883 + "authenticationkey20benckeyis16_bytes",
3884 + .klen = 8 + 20 + 16,
3885 + .iv = "iv0123456789abcd",
3886 + .input = "Single block msg",
3888 + .assoc = "\x00\x01\x02\x03\x04\x05\x06\x07"
3889 + "\x00\x03\x01\x00\x10",
3891 + .result = "\xd5\xac\xb\xd2\xac\xad\x3f\xb1"
3892 + "\x59\x79\x1e\x91\x5f\x52\x14\x9c"
3893 + "\xc0\x75\xd8\x4c\x97\x0f\x07\x73"
3894 + "\xdc\x89\x47\x49\x49\xcb\x30\x6b"
3895 + "\x1b\x45\x23\xa1\xd0\x51\xcf\x02"
3896 + "\x2e\xa8\x5d\xa0\xfe\xca\x82\x61",
3897 + .rlen = 16 + 20 + 12,
3899 +#ifdef __LITTLE_ENDIAN
3900 + .key = "\x08\x00" /* rta length */
3901 + "\x01\x00" /* rta type */
3903 + .key = "\x00\x08" /* rta length */
3904 + "\x00\x01" /* rta type */
3906 + "\x00\x00\x00\x10" /* enc key length */
3907 + "authenticationkey20benckeyis16_bytes",
3908 + .klen = 8 + 20 + 16,
3909 + .iv = "iv0123456789abcd",
3912 + .assoc = "\x00\x01\x02\x03\x04\x05\x06\x07"
3913 + "\x00\x03\x01\x00\x00",
3915 + .result = "\x58\x2a\x11\xc\x86\x8e\x4b\x67"
3916 + "\x2d\x16\x26\x1a\xac\x4b\xe2\x1a"
3917 + "\xe9\x6a\xcc\x4d\x6f\x79\x8a\x45"
3918 + "\x1f\x4e\x27\xf2\xa7\x59\xb4\x5a",
3921 +#ifdef __LITTLE_ENDIAN
3922 + .key = "\x08\x00" /* rta length */
3923 + "\x01\x00" /* rta type */
3925 + .key = "\x00\x08" /* rta length */
3926 + "\x00\x01" /* rta type */
3928 + "\x00\x00\x00\x10" /* enc key length */
3929 + "authenticationkey20benckeyis16_bytes",
3930 + .klen = 8 + 20 + 16,
3931 + .iv = "iv0123456789abcd",
3932 + .input = "285 bytes plaintext285 bytes plaintext285 bytes"
3933 + " plaintext285 bytes plaintext285 bytes plaintext285"
3934 + " bytes plaintext285 bytes plaintext285 bytes"
3935 + " plaintext285 bytes plaintext285 bytes plaintext285"
3936 + " bytes plaintext285 bytes plaintext285 bytes"
3937 + " plaintext285 bytes plaintext285 bytes plaintext285"
3938 + " bytes plaintext285 bytes plaintext",
3940 + .assoc = "\x00\x01\x02\x03\x04\x05\x06\x07"
3941 + "\x00\x03\x01\x01\x1d",
3943 + .result = "\x80\x23\x82\x44\x14\x2a\x1d\x94\xc\xc2\x1d\xd"
3944 + "\x3a\x32\x89\x4c\x57\x30\xa8\x89\x76\x46\xcc\x90"
3945 + "\x1d\x88\xb8\xa6\x1a\x58\xe\x2d\xeb\x2c\xc7\x3a"
3946 + "\x52\x4e\xdb\xb3\x1e\x83\x11\xf5\x3c\xce\x6e\x94"
3947 + "\xd3\x26\x6a\x9a\xd\xbd\xc7\x98\xb9\xb3\x3a\x51"
3948 + "\x1e\x4\x84\x8a\x8f\x54\x9a\x51\x69\x9c\xce\x31"
3949 + "\x8d\x5d\x8b\xee\x5f\x70\xc\xc9\xb8\x50\x54\xf8"
3950 + "\xb2\x4a\x7a\xcd\xeb\x7a\x82\x81\xc6\x41\xc8\x50"
3951 + "\x91\x8d\xc8\xed\xcd\x40\x8f\x55\xd1\xec\xc9\xac"
3952 + "\x15\x18\xf9\x20\xa0\xed\x18\xa1\xe3\x56\xe3\x14"
3953 + "\xe5\xe8\x66\x63\x20\xed\xe4\x62\x9d\xa3\xa4\x1d"
3954 + "\x81\x89\x18\xf2\x36\xae\xc8\x8a\x2b\xbc\xc3\xb8"
3955 + "\x80\xf\x97\x21\x36\x39\x8\x84\x23\x18\x9e\x9c"
3956 + "\x72\x32\x75\x2d\x2e\xf9\x60\xb\xe8\xcc\xd9\x74"
3957 + "\x4\x1b\x8e\x99\xc1\x94\xee\xd0\xac\x4e\xfc\x7e"
3958 + "\xf1\x96\xb3\xe7\x14\xb8\xf2\xc\x25\x97\x82\x6b"
3959 + "\xbd\x0\x65\xab\x5c\xe3\x16\xfb\x68\xef\xea\x9d"
3960 + "\xff\x44\x1d\x2a\x44\xf5\xc8\x56\x77\xb7\xbf\x13"
3961 + "\xc8\x54\xdb\x92\xfe\x16\x4c\xbe\x18\xe9\xb\x8d"
3962 + "\xb\xd4\x43\x58\x43\xaa\xf4\x3\x80\x97\x62\xd5"
3963 + "\xdf\x3c\x28\xaa\xee\x48\x4b\x55\x41\x1b\x31\x2"
3964 + "\xbe\xa0\x1c\xbd\xb7\x22\x2a\xe5\x53\x72\x73\x20"
3965 + "\x44\x4f\xe6\x1\x2b\x34\x33\x11\x7d\xfb\x10\xc1"
3966 + "\x66\x7c\xa6\xf4\x48\x36\x5e\x2\xda\x41\x4b\x3e"
3967 + "\xe7\x80\x17\x17\xce\xf1\x3e\x6a\x8e\x26\xf3\xb7"
3968 + "\x2b\x85\xd\x31\x8d\xba\x6c\x22\xb4\x28\x55\x7e"
3969 + "\x2a\x9e\x26\xf1\x3d\x21\xac\x65",
3970 + .rlen = 285 + 20 + 15,
3974 +static struct tls_testvec tls_dec_tv_template[] = {
3976 +#ifdef __LITTLE_ENDIAN
3977 + .key = "\x08\x00" /* rta length */
3978 + "\x01\x00" /* rta type */
3980 + .key = "\x00\x08" /* rta length */
3981 + "\x00\x01" /* rta type */
3983 + "\x00\x00\x00\x10" /* enc key length */
3984 + "authenticationkey20benckeyis16_bytes",
3985 + .klen = 8 + 20 + 16,
3986 + .iv = "iv0123456789abcd",
3987 + .input = "\xd5\xac\xb\xd2\xac\xad\x3f\xb1"
3988 + "\x59\x79\x1e\x91\x5f\x52\x14\x9c"
3989 + "\xc0\x75\xd8\x4c\x97\x0f\x07\x73"
3990 + "\xdc\x89\x47\x49\x49\xcb\x30\x6b"
3991 + "\x1b\x45\x23\xa1\xd0\x51\xcf\x02"
3992 + "\x2e\xa8\x5d\xa0\xfe\xca\x82\x61",
3993 + .ilen = 16 + 20 + 12,
3994 + .assoc = "\x00\x01\x02\x03\x04\x05\x06\x07"
3995 + "\x00\x03\x01\x00\x30",
3997 + .result = "Single block msg",
4000 +#ifdef __LITTLE_ENDIAN
4001 + .key = "\x08\x00" /* rta length */
4002 + "\x01\x00" /* rta type */
4004 -#define RSA_TEST_VECTORS 5
4005 + .key = "\x00\x08" /* rta length */
4006 + "\x00\x01" /* rta type */
4008 -static struct akcipher_testvec rsa_tv_template[] = {
4009 + "\x00\x00\x00\x10" /* enc key length */
4010 + "authenticationkey20benckeyis16_bytes",
4011 + .klen = 8 + 20 + 16,
4012 + .iv = "iv0123456789abcd",
4013 + .input = "\x58\x2a\x11\xc\x86\x8e\x4b\x67"
4014 + "\x2d\x16\x26\x1a\xac\x4b\xe2\x1a"
4015 + "\xe9\x6a\xcc\x4d\x6f\x79\x8a\x45"
4016 + "\x1f\x4e\x27\xf2\xa7\x59\xb4\x5a",
4018 + .assoc = "\x00\x01\x02\x03\x04\x05\x06\x07"
4019 + "\x00\x03\x01\x00\x20",
4024 +#ifdef __LITTLE_ENDIAN
4025 + .key = "\x08\x00" /* rta length */
4026 + "\x01\x00" /* rta type */
4028 + .key = "\x00\x08" /* rta length */
4029 + "\x00\x01" /* rta type */
4031 + "\x00\x00\x00\x10" /* enc key length */
4032 + "authenticationkey20benckeyis16_bytes",
4033 + .klen = 8 + 20 + 16,
4034 + .iv = "iv0123456789abcd",
4035 + .input = "\x80\x23\x82\x44\x14\x2a\x1d\x94\xc\xc2\x1d\xd"
4036 + "\x3a\x32\x89\x4c\x57\x30\xa8\x89\x76\x46\xcc\x90"
4037 + "\x1d\x88\xb8\xa6\x1a\x58\xe\x2d\xeb\x2c\xc7\x3a"
4038 + "\x52\x4e\xdb\xb3\x1e\x83\x11\xf5\x3c\xce\x6e\x94"
4039 + "\xd3\x26\x6a\x9a\xd\xbd\xc7\x98\xb9\xb3\x3a\x51"
4040 + "\x1e\x4\x84\x8a\x8f\x54\x9a\x51\x69\x9c\xce\x31"
4041 + "\x8d\x5d\x8b\xee\x5f\x70\xc\xc9\xb8\x50\x54\xf8"
4042 + "\xb2\x4a\x7a\xcd\xeb\x7a\x82\x81\xc6\x41\xc8\x50"
4043 + "\x91\x8d\xc8\xed\xcd\x40\x8f\x55\xd1\xec\xc9\xac"
4044 + "\x15\x18\xf9\x20\xa0\xed\x18\xa1\xe3\x56\xe3\x14"
4045 + "\xe5\xe8\x66\x63\x20\xed\xe4\x62\x9d\xa3\xa4\x1d"
4046 + "\x81\x89\x18\xf2\x36\xae\xc8\x8a\x2b\xbc\xc3\xb8"
4047 + "\x80\xf\x97\x21\x36\x39\x8\x84\x23\x18\x9e\x9c"
4048 + "\x72\x32\x75\x2d\x2e\xf9\x60\xb\xe8\xcc\xd9\x74"
4049 + "\x4\x1b\x8e\x99\xc1\x94\xee\xd0\xac\x4e\xfc\x7e"
4050 + "\xf1\x96\xb3\xe7\x14\xb8\xf2\xc\x25\x97\x82\x6b"
4051 + "\xbd\x0\x65\xab\x5c\xe3\x16\xfb\x68\xef\xea\x9d"
4052 + "\xff\x44\x1d\x2a\x44\xf5\xc8\x56\x77\xb7\xbf\x13"
4053 + "\xc8\x54\xdb\x92\xfe\x16\x4c\xbe\x18\xe9\xb\x8d"
4054 + "\xb\xd4\x43\x58\x43\xaa\xf4\x3\x80\x97\x62\xd5"
4055 + "\xdf\x3c\x28\xaa\xee\x48\x4b\x55\x41\x1b\x31\x2"
4056 + "\xbe\xa0\x1c\xbd\xb7\x22\x2a\xe5\x53\x72\x73\x20"
4057 + "\x44\x4f\xe6\x1\x2b\x34\x33\x11\x7d\xfb\x10\xc1"
4058 + "\x66\x7c\xa6\xf4\x48\x36\x5e\x2\xda\x41\x4b\x3e"
4059 + "\xe7\x80\x17\x17\xce\xf1\x3e\x6a\x8e\x26\xf3\xb7"
4060 + "\x2b\x85\xd\x31\x8d\xba\x6c\x22\xb4\x28\x55\x7e"
4061 + "\x2a\x9e\x26\xf1\x3d\x21\xac\x65",
4063 + .ilen = 285 + 20 + 15,
4064 + .assoc = "\x00\x01\x02\x03\x04\x05\x06\x07"
4065 + "\x00\x03\x01\x01\x40",
4067 + .result = "285 bytes plaintext285 bytes plaintext285 bytes"
4068 + " plaintext285 bytes plaintext285 bytes plaintext285"
4069 + " bytes plaintext285 bytes plaintext285 bytes"
4070 + " plaintext285 bytes plaintext285 bytes plaintext285"
4071 + " bytes plaintext285 bytes plaintext285 bytes"
4072 + " plaintext285 bytes plaintext285 bytes plaintext",
4078 + * RSA test vectors. Borrowed from openSSL.
4080 +static const struct akcipher_testvec rsa_tv_template[] = {
4082 #ifndef CONFIG_CRYPTO_FIPS
4084 @@ -340,6 +554,7 @@ static struct akcipher_testvec rsa_tv_te
4087 .public_key_vec = true,
4088 +#ifndef CONFIG_CRYPTO_FIPS
4091 "\x30\x82\x09\x29" /* sequence of 2345 bytes */
4092 @@ -538,12 +753,11 @@ static struct akcipher_testvec rsa_tv_te
4100 -#define DH_TEST_VECTORS 2
4102 -struct kpp_testvec dh_tv_template[] = {
4103 +static const struct kpp_testvec dh_tv_template[] = {
4106 #ifdef __LITTLE_ENDIAN
4107 @@ -760,12 +974,7 @@ struct kpp_testvec dh_tv_template[] = {
4111 -#ifdef CONFIG_CRYPTO_FIPS
4112 -#define ECDH_TEST_VECTORS 1
4114 -#define ECDH_TEST_VECTORS 2
4116 -struct kpp_testvec ecdh_tv_template[] = {
4117 +static const struct kpp_testvec ecdh_tv_template[] = {
4119 #ifndef CONFIG_CRYPTO_FIPS
4121 @@ -856,9 +1065,7 @@ struct kpp_testvec ecdh_tv_template[] =
4123 * MD4 test vectors from RFC1320
4125 -#define MD4_TEST_VECTORS 7
4127 -static struct hash_testvec md4_tv_template [] = {
4128 +static const struct hash_testvec md4_tv_template[] = {
4131 .digest = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31"
4132 @@ -899,8 +1106,7 @@ static struct hash_testvec md4_tv_templa
4136 -#define SHA3_224_TEST_VECTORS 3
4137 -static struct hash_testvec sha3_224_tv_template[] = {
4138 +static const struct hash_testvec sha3_224_tv_template[] = {
4141 .digest = "\x6b\x4e\x03\x42\x36\x67\xdb\xb7"
4142 @@ -925,8 +1131,7 @@ static struct hash_testvec sha3_224_tv_t
4146 -#define SHA3_256_TEST_VECTORS 3
4147 -static struct hash_testvec sha3_256_tv_template[] = {
4148 +static const struct hash_testvec sha3_256_tv_template[] = {
4151 .digest = "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66"
4152 @@ -952,8 +1157,7 @@ static struct hash_testvec sha3_256_tv_t
4156 -#define SHA3_384_TEST_VECTORS 3
4157 -static struct hash_testvec sha3_384_tv_template[] = {
4158 +static const struct hash_testvec sha3_384_tv_template[] = {
4161 .digest = "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d"
4162 @@ -985,8 +1189,7 @@ static struct hash_testvec sha3_384_tv_t
4166 -#define SHA3_512_TEST_VECTORS 3
4167 -static struct hash_testvec sha3_512_tv_template[] = {
4168 +static const struct hash_testvec sha3_512_tv_template[] = {
4171 .digest = "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5"
4172 @@ -1027,9 +1230,7 @@ static struct hash_testvec sha3_512_tv_t
4174 * MD5 test vectors from RFC1321
4176 -#define MD5_TEST_VECTORS 7
4178 -static struct hash_testvec md5_tv_template[] = {
4179 +static const struct hash_testvec md5_tv_template[] = {
4181 .digest = "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04"
4182 "\xe9\x80\x09\x98\xec\xf8\x42\x7e",
4183 @@ -1073,9 +1274,7 @@ static struct hash_testvec md5_tv_templa
4185 * RIPEMD-128 test vectors from ISO/IEC 10118-3:2004(E)
4187 -#define RMD128_TEST_VECTORS 10
4189 -static struct hash_testvec rmd128_tv_template[] = {
4190 +static const struct hash_testvec rmd128_tv_template[] = {
4192 .digest = "\xcd\xf2\x62\x13\xa1\x50\xdc\x3e"
4193 "\xcb\x61\x0f\x18\xf6\xb3\x8b\x46",
4194 @@ -1137,9 +1336,7 @@ static struct hash_testvec rmd128_tv_tem
4196 * RIPEMD-160 test vectors from ISO/IEC 10118-3:2004(E)
4198 -#define RMD160_TEST_VECTORS 10
4200 -static struct hash_testvec rmd160_tv_template[] = {
4201 +static const struct hash_testvec rmd160_tv_template[] = {
4203 .digest = "\x9c\x11\x85\xa5\xc5\xe9\xfc\x54\x61\x28"
4204 "\x08\x97\x7e\xe8\xf5\x48\xb2\x25\x8d\x31",
4205 @@ -1201,9 +1398,7 @@ static struct hash_testvec rmd160_tv_tem
4207 * RIPEMD-256 test vectors
4209 -#define RMD256_TEST_VECTORS 8
4211 -static struct hash_testvec rmd256_tv_template[] = {
4212 +static const struct hash_testvec rmd256_tv_template[] = {
4214 .digest = "\x02\xba\x4c\x4e\x5f\x8e\xcd\x18"
4215 "\x77\xfc\x52\xd6\x4d\x30\xe3\x7a"
4216 @@ -1269,9 +1464,7 @@ static struct hash_testvec rmd256_tv_tem
4218 * RIPEMD-320 test vectors
4220 -#define RMD320_TEST_VECTORS 8
4222 -static struct hash_testvec rmd320_tv_template[] = {
4223 +static const struct hash_testvec rmd320_tv_template[] = {
4225 .digest = "\x22\xd6\x5d\x56\x61\x53\x6c\xdc\x75\xc1"
4226 "\xfd\xf5\xc6\xde\x7b\x41\xb9\xf2\x73\x25"
4227 @@ -1334,36 +1527,49 @@ static struct hash_testvec rmd320_tv_tem
4231 -#define CRCT10DIF_TEST_VECTORS 3
4232 -static struct hash_testvec crct10dif_tv_template[] = {
4233 +static const struct hash_testvec crct10dif_tv_template[] = {
4235 - .plaintext = "abc",
4237 -#ifdef __LITTLE_ENDIAN
4238 - .digest = "\x3b\x44",
4240 - .digest = "\x44\x3b",
4243 - .plaintext = "1234567890123456789012345678901234567890"
4244 - "123456789012345678901234567890123456789",
4246 -#ifdef __LITTLE_ENDIAN
4247 - .digest = "\x70\x4b",
4249 - .digest = "\x4b\x70",
4253 - "abcddddddddddddddddddddddddddddddddddddddddddddddddddddd",
4255 -#ifdef __LITTLE_ENDIAN
4256 - .digest = "\xe3\x9c",
4258 - .digest = "\x9c\xe3",
4262 + .plaintext = "abc",
4264 + .digest = (u8 *)(u16 []){ 0x443b },
4266 + .plaintext = "1234567890123456789012345678901234567890"
4267 + "123456789012345678901234567890123456789",
4269 + .digest = (u8 *)(u16 []){ 0x4b70 },
4271 + .tap = { 63, 16 },
4273 + .plaintext = "abcdddddddddddddddddddddddddddddddddddddddd"
4276 + .digest = (u8 *)(u16 []){ 0x9ce3 },
4278 + .tap = { 1, 2, 28, 7, 6, 5, 4, 3 },
4280 + .plaintext = "1234567890123456789012345678901234567890"
4281 + "1234567890123456789012345678901234567890"
4282 + "1234567890123456789012345678901234567890"
4283 + "1234567890123456789012345678901234567890"
4284 + "1234567890123456789012345678901234567890"
4285 + "1234567890123456789012345678901234567890"
4286 + "1234567890123456789012345678901234567890"
4287 + "123456789012345678901234567890123456789",
4289 + .digest = (u8 *)(u16 []){ 0x44c6 },
4291 + .plaintext = "1234567890123456789012345678901234567890"
4292 + "1234567890123456789012345678901234567890"
4293 + "1234567890123456789012345678901234567890"
4294 + "1234567890123456789012345678901234567890"
4295 + "1234567890123456789012345678901234567890"
4296 + "1234567890123456789012345678901234567890"
4297 + "1234567890123456789012345678901234567890"
4298 + "123456789012345678901234567890123456789",
4300 + .digest = (u8 *)(u16 []){ 0x44c6 },
4302 + .tap = { 1, 255, 57, 6 },
4306 @@ -1371,9 +1577,7 @@ static struct hash_testvec crct10dif_tv_
4307 * SHA1 test vectors from from FIPS PUB 180-1
4308 * Long vector from CAVS 5.0
4310 -#define SHA1_TEST_VECTORS 6
4312 -static struct hash_testvec sha1_tv_template[] = {
4313 +static const struct hash_testvec sha1_tv_template[] = {
4317 @@ -1563,9 +1767,7 @@ static struct hash_testvec sha1_tv_templ
4319 * SHA224 test vectors from from FIPS PUB 180-2
4321 -#define SHA224_TEST_VECTORS 5
4323 -static struct hash_testvec sha224_tv_template[] = {
4324 +static const struct hash_testvec sha224_tv_template[] = {
4328 @@ -1737,9 +1939,7 @@ static struct hash_testvec sha224_tv_tem
4330 * SHA256 test vectors from from NIST
4332 -#define SHA256_TEST_VECTORS 5
4334 -static struct hash_testvec sha256_tv_template[] = {
4335 +static const struct hash_testvec sha256_tv_template[] = {
4339 @@ -1910,9 +2110,7 @@ static struct hash_testvec sha256_tv_tem
4341 * SHA384 test vectors from from NIST and kerneli
4343 -#define SHA384_TEST_VECTORS 6
4345 -static struct hash_testvec sha384_tv_template[] = {
4346 +static const struct hash_testvec sha384_tv_template[] = {
4350 @@ -2104,9 +2302,7 @@ static struct hash_testvec sha384_tv_tem
4352 * SHA512 test vectors from from NIST and kerneli
4354 -#define SHA512_TEST_VECTORS 6
4356 -static struct hash_testvec sha512_tv_template[] = {
4357 +static const struct hash_testvec sha512_tv_template[] = {
4361 @@ -2313,9 +2509,7 @@ static struct hash_testvec sha512_tv_tem
4362 * by Vincent Rijmen and Paulo S. L. M. Barreto as part of the NESSIE
4365 -#define WP512_TEST_VECTORS 8
4367 -static struct hash_testvec wp512_tv_template[] = {
4368 +static const struct hash_testvec wp512_tv_template[] = {
4372 @@ -2411,9 +2605,7 @@ static struct hash_testvec wp512_tv_temp
4376 -#define WP384_TEST_VECTORS 8
4378 -static struct hash_testvec wp384_tv_template[] = {
4379 +static const struct hash_testvec wp384_tv_template[] = {
4383 @@ -2493,9 +2685,7 @@ static struct hash_testvec wp384_tv_temp
4387 -#define WP256_TEST_VECTORS 8
4389 -static struct hash_testvec wp256_tv_template[] = {
4390 +static const struct hash_testvec wp256_tv_template[] = {
4394 @@ -2562,9 +2752,7 @@ static struct hash_testvec wp256_tv_temp
4396 * TIGER test vectors from Tiger website
4398 -#define TGR192_TEST_VECTORS 6
4400 -static struct hash_testvec tgr192_tv_template[] = {
4401 +static const struct hash_testvec tgr192_tv_template[] = {
4405 @@ -2607,9 +2795,7 @@ static struct hash_testvec tgr192_tv_tem
4409 -#define TGR160_TEST_VECTORS 6
4411 -static struct hash_testvec tgr160_tv_template[] = {
4412 +static const struct hash_testvec tgr160_tv_template[] = {
4416 @@ -2652,9 +2838,7 @@ static struct hash_testvec tgr160_tv_tem
4420 -#define TGR128_TEST_VECTORS 6
4422 -static struct hash_testvec tgr128_tv_template[] = {
4423 +static const struct hash_testvec tgr128_tv_template[] = {
4427 @@ -2691,9 +2875,7 @@ static struct hash_testvec tgr128_tv_tem
4431 -#define GHASH_TEST_VECTORS 6
4433 -static struct hash_testvec ghash_tv_template[] =
4434 +static const struct hash_testvec ghash_tv_template[] =
4437 .key = "\xdf\xa6\xbf\x4d\xed\x81\xdb\x03"
4438 @@ -2808,9 +2990,7 @@ static struct hash_testvec ghash_tv_temp
4439 * HMAC-MD5 test vectors from RFC2202
4440 * (These need to be fixed to not use strlen).
4442 -#define HMAC_MD5_TEST_VECTORS 7
4444 -static struct hash_testvec hmac_md5_tv_template[] =
4445 +static const struct hash_testvec hmac_md5_tv_template[] =
4448 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
4449 @@ -2890,9 +3070,7 @@ static struct hash_testvec hmac_md5_tv_t
4451 * HMAC-RIPEMD128 test vectors from RFC2286
4453 -#define HMAC_RMD128_TEST_VECTORS 7
4455 -static struct hash_testvec hmac_rmd128_tv_template[] = {
4456 +static const struct hash_testvec hmac_rmd128_tv_template[] = {
4458 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
4460 @@ -2971,9 +3149,7 @@ static struct hash_testvec hmac_rmd128_t
4462 * HMAC-RIPEMD160 test vectors from RFC2286
4464 -#define HMAC_RMD160_TEST_VECTORS 7
4466 -static struct hash_testvec hmac_rmd160_tv_template[] = {
4467 +static const struct hash_testvec hmac_rmd160_tv_template[] = {
4469 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
4471 @@ -3052,9 +3228,7 @@ static struct hash_testvec hmac_rmd160_t
4473 * HMAC-SHA1 test vectors from RFC2202
4475 -#define HMAC_SHA1_TEST_VECTORS 7
4477 -static struct hash_testvec hmac_sha1_tv_template[] = {
4478 +static const struct hash_testvec hmac_sha1_tv_template[] = {
4480 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
4482 @@ -3135,9 +3309,7 @@ static struct hash_testvec hmac_sha1_tv_
4484 * SHA224 HMAC test vectors from RFC4231
4486 -#define HMAC_SHA224_TEST_VECTORS 4
4488 -static struct hash_testvec hmac_sha224_tv_template[] = {
4489 +static const struct hash_testvec hmac_sha224_tv_template[] = {
4491 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4492 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4493 @@ -3250,9 +3422,7 @@ static struct hash_testvec hmac_sha224_t
4494 * HMAC-SHA256 test vectors from
4495 * draft-ietf-ipsec-ciph-sha-256-01.txt
4497 -#define HMAC_SHA256_TEST_VECTORS 10
4499 -static struct hash_testvec hmac_sha256_tv_template[] = {
4500 +static const struct hash_testvec hmac_sha256_tv_template[] = {
4502 .key = "\x01\x02\x03\x04\x05\x06\x07\x08"
4503 "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
4504 @@ -3387,9 +3557,7 @@ static struct hash_testvec hmac_sha256_t
4508 -#define CMAC_AES_TEST_VECTORS 6
4510 -static struct hash_testvec aes_cmac128_tv_template[] = {
4511 +static const struct hash_testvec aes_cmac128_tv_template[] = {
4512 { /* From NIST Special Publication 800-38B, AES-128 */
4513 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
4514 "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
4515 @@ -3464,9 +3632,67 @@ static struct hash_testvec aes_cmac128_t
4519 -#define CMAC_DES3_EDE_TEST_VECTORS 4
4520 +static const struct hash_testvec aes_cbcmac_tv_template[] = {
4522 + .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
4523 + "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
4524 + .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4525 + "\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
4526 + .digest = "\x3a\xd7\x7b\xb4\x0d\x7a\x36\x60"
4527 + "\xa8\x9e\xca\xf3\x24\x66\xef\x97",
4531 + .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
4532 + "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
4533 + .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4534 + "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4535 + "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4536 + "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4538 + .digest = "\x9d\x0d\xd0\x63\xfb\xcb\x24\x43"
4539 + "\xf8\xf2\x76\x03\xac\x39\xb0\x9d",
4545 + .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
4546 + "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
4547 + .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4548 + "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4549 + "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4550 + "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4551 + "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4552 + "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4553 + "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4554 + "\xad\x2b\x41\x7b\xe6\x6c\x37",
4555 + .digest = "\xc0\x71\x73\xb8\xa0\x2c\x11\x7c"
4556 + "\xaf\xdc\xb2\xf8\x89\x32\xa3\x3a",
4560 + .key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe"
4561 + "\x2b\x73\xae\xf0\x85\x7d\x77\x81"
4562 + "\x1f\x35\x2c\x07\x3b\x61\x08\xd7"
4563 + "\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
4564 + .plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4565 + "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4566 + "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4567 + "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4568 + "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4569 + "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4570 + "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4571 + "\xad\x2b\x41\x7b\xe6\x6c\x37\x10"
4573 + .digest = "\x6a\x4e\xdb\x21\x47\x51\xdf\x4f"
4574 + "\xa8\x4d\x4c\x10\x3b\x72\x7d\xd6",
4580 -static struct hash_testvec des3_ede_cmac64_tv_template[] = {
4581 +static const struct hash_testvec des3_ede_cmac64_tv_template[] = {
4583 * From NIST Special Publication 800-38B, Three Key TDEA
4584 * Corrected test vectors from:
4585 @@ -3512,9 +3738,7 @@ static struct hash_testvec des3_ede_cmac
4589 -#define XCBC_AES_TEST_VECTORS 6
4591 -static struct hash_testvec aes_xcbc128_tv_template[] = {
4592 +static const struct hash_testvec aes_xcbc128_tv_template[] = {
4594 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
4595 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
4596 @@ -3580,36 +3804,35 @@ static struct hash_testvec aes_xcbc128_t
4600 -#define VMAC_AES_TEST_VECTORS 11
4601 -static char vmac_string1[128] = {'\x01', '\x01', '\x01', '\x01',
4602 - '\x02', '\x03', '\x02', '\x02',
4603 - '\x02', '\x04', '\x01', '\x07',
4604 - '\x04', '\x01', '\x04', '\x03',};
4605 -static char vmac_string2[128] = {'a', 'b', 'c',};
4606 -static char vmac_string3[128] = {'a', 'b', 'c', 'a', 'b', 'c',
4607 - 'a', 'b', 'c', 'a', 'b', 'c',
4608 - 'a', 'b', 'c', 'a', 'b', 'c',
4609 - 'a', 'b', 'c', 'a', 'b', 'c',
4610 - 'a', 'b', 'c', 'a', 'b', 'c',
4611 - 'a', 'b', 'c', 'a', 'b', 'c',
4612 - 'a', 'b', 'c', 'a', 'b', 'c',
4613 - 'a', 'b', 'c', 'a', 'b', 'c',
4616 -static char vmac_string4[17] = {'b', 'c', 'e', 'f',
4617 - 'i', 'j', 'l', 'm',
4618 - 'o', 'p', 'r', 's',
4619 - 't', 'u', 'w', 'x', 'z'};
4621 -static char vmac_string5[127] = {'r', 'm', 'b', 't', 'c',
4622 - 'o', 'l', 'k', ']', '%',
4623 - '9', '2', '7', '!', 'A'};
4625 -static char vmac_string6[129] = {'p', 't', '*', '7', 'l',
4626 - 'i', '!', '#', 'w', '0',
4627 - 'z', '/', '4', 'A', 'n'};
4628 +static const char vmac_string1[128] = {'\x01', '\x01', '\x01', '\x01',
4629 + '\x02', '\x03', '\x02', '\x02',
4630 + '\x02', '\x04', '\x01', '\x07',
4631 + '\x04', '\x01', '\x04', '\x03',};
4632 +static const char vmac_string2[128] = {'a', 'b', 'c',};
4633 +static const char vmac_string3[128] = {'a', 'b', 'c', 'a', 'b', 'c',
4634 + 'a', 'b', 'c', 'a', 'b', 'c',
4635 + 'a', 'b', 'c', 'a', 'b', 'c',
4636 + 'a', 'b', 'c', 'a', 'b', 'c',
4637 + 'a', 'b', 'c', 'a', 'b', 'c',
4638 + 'a', 'b', 'c', 'a', 'b', 'c',
4639 + 'a', 'b', 'c', 'a', 'b', 'c',
4640 + 'a', 'b', 'c', 'a', 'b', 'c',
4643 +static const char vmac_string4[17] = {'b', 'c', 'e', 'f',
4644 + 'i', 'j', 'l', 'm',
4645 + 'o', 'p', 'r', 's',
4646 + 't', 'u', 'w', 'x', 'z'};
4648 +static const char vmac_string5[127] = {'r', 'm', 'b', 't', 'c',
4649 + 'o', 'l', 'k', ']', '%',
4650 + '9', '2', '7', '!', 'A'};
4652 +static const char vmac_string6[129] = {'p', 't', '*', '7', 'l',
4653 + 'i', '!', '#', 'w', '0',
4654 + 'z', '/', '4', 'A', 'n'};
4656 -static struct hash_testvec aes_vmac128_tv_template[] = {
4657 +static const struct hash_testvec aes_vmac128_tv_template[] = {
4659 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
4660 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
4661 @@ -3687,9 +3910,7 @@ static struct hash_testvec aes_vmac128_t
4662 * SHA384 HMAC test vectors from RFC4231
4665 -#define HMAC_SHA384_TEST_VECTORS 4
4667 -static struct hash_testvec hmac_sha384_tv_template[] = {
4668 +static const struct hash_testvec hmac_sha384_tv_template[] = {
4670 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4671 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4672 @@ -3787,9 +4008,7 @@ static struct hash_testvec hmac_sha384_t
4673 * SHA512 HMAC test vectors from RFC4231
4676 -#define HMAC_SHA512_TEST_VECTORS 4
4678 -static struct hash_testvec hmac_sha512_tv_template[] = {
4679 +static const struct hash_testvec hmac_sha512_tv_template[] = {
4681 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4682 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4683 @@ -3894,9 +4113,7 @@ static struct hash_testvec hmac_sha512_t
4687 -#define HMAC_SHA3_224_TEST_VECTORS 4
4689 -static struct hash_testvec hmac_sha3_224_tv_template[] = {
4690 +static const struct hash_testvec hmac_sha3_224_tv_template[] = {
4692 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4693 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4694 @@ -3985,9 +4202,7 @@ static struct hash_testvec hmac_sha3_224
4698 -#define HMAC_SHA3_256_TEST_VECTORS 4
4700 -static struct hash_testvec hmac_sha3_256_tv_template[] = {
4701 +static const struct hash_testvec hmac_sha3_256_tv_template[] = {
4703 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4704 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4705 @@ -4076,9 +4291,7 @@ static struct hash_testvec hmac_sha3_256
4709 -#define HMAC_SHA3_384_TEST_VECTORS 4
4711 -static struct hash_testvec hmac_sha3_384_tv_template[] = {
4712 +static const struct hash_testvec hmac_sha3_384_tv_template[] = {
4714 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4715 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4716 @@ -4175,9 +4388,7 @@ static struct hash_testvec hmac_sha3_384
4720 -#define HMAC_SHA3_512_TEST_VECTORS 4
4722 -static struct hash_testvec hmac_sha3_512_tv_template[] = {
4723 +static const struct hash_testvec hmac_sha3_512_tv_template[] = {
4725 .key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4726 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
4727 @@ -4286,9 +4497,7 @@ static struct hash_testvec hmac_sha3_512
4728 * Poly1305 test vectors from RFC7539 A.3.
4731 -#define POLY1305_TEST_VECTORS 11
4733 -static struct hash_testvec poly1305_tv_template[] = {
4734 +static const struct hash_testvec poly1305_tv_template[] = {
4735 { /* Test Vector #1 */
4736 .plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00"
4737 "\x00\x00\x00\x00\x00\x00\x00\x00"
4738 @@ -4533,20 +4742,7 @@ static struct hash_testvec poly1305_tv_t
4742 -#define DES_ENC_TEST_VECTORS 11
4743 -#define DES_DEC_TEST_VECTORS 5
4744 -#define DES_CBC_ENC_TEST_VECTORS 6
4745 -#define DES_CBC_DEC_TEST_VECTORS 5
4746 -#define DES_CTR_ENC_TEST_VECTORS 2
4747 -#define DES_CTR_DEC_TEST_VECTORS 2
4748 -#define DES3_EDE_ENC_TEST_VECTORS 4
4749 -#define DES3_EDE_DEC_TEST_VECTORS 4
4750 -#define DES3_EDE_CBC_ENC_TEST_VECTORS 2
4751 -#define DES3_EDE_CBC_DEC_TEST_VECTORS 2
4752 -#define DES3_EDE_CTR_ENC_TEST_VECTORS 2
4753 -#define DES3_EDE_CTR_DEC_TEST_VECTORS 2
4755 -static struct cipher_testvec des_enc_tv_template[] = {
4756 +static const struct cipher_testvec des_enc_tv_template[] = {
4757 { /* From Applied Cryptography */
4758 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
4760 @@ -4720,7 +4916,7 @@ static struct cipher_testvec des_enc_tv_
4764 -static struct cipher_testvec des_dec_tv_template[] = {
4765 +static const struct cipher_testvec des_dec_tv_template[] = {
4766 { /* From Applied Cryptography */
4767 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
4769 @@ -4830,7 +5026,7 @@ static struct cipher_testvec des_dec_tv_
4773 -static struct cipher_testvec des_cbc_enc_tv_template[] = {
4774 +static const struct cipher_testvec des_cbc_enc_tv_template[] = {
4775 { /* From OpenSSL */
4776 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
4778 @@ -4956,7 +5152,7 @@ static struct cipher_testvec des_cbc_enc
4782 -static struct cipher_testvec des_cbc_dec_tv_template[] = {
4783 +static const struct cipher_testvec des_cbc_dec_tv_template[] = {
4785 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
4787 @@ -5065,7 +5261,7 @@ static struct cipher_testvec des_cbc_dec
4791 -static struct cipher_testvec des_ctr_enc_tv_template[] = {
4792 +static const struct cipher_testvec des_ctr_enc_tv_template[] = {
4793 { /* Generated with Crypto++ */
4794 .key = "\xC9\x83\xA6\xC9\xEC\x0F\x32\x55",
4796 @@ -5211,7 +5407,7 @@ static struct cipher_testvec des_ctr_enc
4800 -static struct cipher_testvec des_ctr_dec_tv_template[] = {
4801 +static const struct cipher_testvec des_ctr_dec_tv_template[] = {
4802 { /* Generated with Crypto++ */
4803 .key = "\xC9\x83\xA6\xC9\xEC\x0F\x32\x55",
4805 @@ -5357,7 +5553,7 @@ static struct cipher_testvec des_ctr_dec
4809 -static struct cipher_testvec des3_ede_enc_tv_template[] = {
4810 +static const struct cipher_testvec des3_ede_enc_tv_template[] = {
4811 { /* These are from openssl */
4812 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef"
4813 "\x55\x55\x55\x55\x55\x55\x55\x55"
4814 @@ -5522,7 +5718,7 @@ static struct cipher_testvec des3_ede_en
4818 -static struct cipher_testvec des3_ede_dec_tv_template[] = {
4819 +static const struct cipher_testvec des3_ede_dec_tv_template[] = {
4820 { /* These are from openssl */
4821 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef"
4822 "\x55\x55\x55\x55\x55\x55\x55\x55"
4823 @@ -5687,7 +5883,7 @@ static struct cipher_testvec des3_ede_de
4827 -static struct cipher_testvec des3_ede_cbc_enc_tv_template[] = {
4828 +static const struct cipher_testvec des3_ede_cbc_enc_tv_template[] = {
4829 { /* Generated from openssl */
4830 .key = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
4831 "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
4832 @@ -5867,7 +6063,7 @@ static struct cipher_testvec des3_ede_cb
4836 -static struct cipher_testvec des3_ede_cbc_dec_tv_template[] = {
4837 +static const struct cipher_testvec des3_ede_cbc_dec_tv_template[] = {
4838 { /* Generated from openssl */
4839 .key = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
4840 "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
4841 @@ -6047,7 +6243,7 @@ static struct cipher_testvec des3_ede_cb
4845 -static struct cipher_testvec des3_ede_ctr_enc_tv_template[] = {
4846 +static const struct cipher_testvec des3_ede_ctr_enc_tv_template[] = {
4847 { /* Generated with Crypto++ */
4848 .key = "\x9C\xD6\xF3\x9C\xB9\x5A\x67\x00"
4849 "\x5A\x67\x00\x2D\xCE\xEB\x2D\xCE"
4850 @@ -6325,7 +6521,7 @@ static struct cipher_testvec des3_ede_ct
4854 -static struct cipher_testvec des3_ede_ctr_dec_tv_template[] = {
4855 +static const struct cipher_testvec des3_ede_ctr_dec_tv_template[] = {
4856 { /* Generated with Crypto++ */
4857 .key = "\x9C\xD6\xF3\x9C\xB9\x5A\x67\x00"
4858 "\x5A\x67\x00\x2D\xCE\xEB\x2D\xCE"
4859 @@ -6606,14 +6802,7 @@ static struct cipher_testvec des3_ede_ct
4861 * Blowfish test vectors.
4863 -#define BF_ENC_TEST_VECTORS 7
4864 -#define BF_DEC_TEST_VECTORS 7
4865 -#define BF_CBC_ENC_TEST_VECTORS 2
4866 -#define BF_CBC_DEC_TEST_VECTORS 2
4867 -#define BF_CTR_ENC_TEST_VECTORS 2
4868 -#define BF_CTR_DEC_TEST_VECTORS 2
4870 -static struct cipher_testvec bf_enc_tv_template[] = {
4871 +static const struct cipher_testvec bf_enc_tv_template[] = {
4872 { /* DES test vectors from OpenSSL */
4873 .key = "\x00\x00\x00\x00\x00\x00\x00\x00",
4875 @@ -6805,7 +6994,7 @@ static struct cipher_testvec bf_enc_tv_t
4879 -static struct cipher_testvec bf_dec_tv_template[] = {
4880 +static const struct cipher_testvec bf_dec_tv_template[] = {
4881 { /* DES test vectors from OpenSSL */
4882 .key = "\x00\x00\x00\x00\x00\x00\x00\x00",
4884 @@ -6997,7 +7186,7 @@ static struct cipher_testvec bf_dec_tv_t
4888 -static struct cipher_testvec bf_cbc_enc_tv_template[] = {
4889 +static const struct cipher_testvec bf_cbc_enc_tv_template[] = {
4890 { /* From OpenSSL */
4891 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef"
4892 "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87",
4893 @@ -7154,7 +7343,7 @@ static struct cipher_testvec bf_cbc_enc_
4897 -static struct cipher_testvec bf_cbc_dec_tv_template[] = {
4898 +static const struct cipher_testvec bf_cbc_dec_tv_template[] = {
4899 { /* From OpenSSL */
4900 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef"
4901 "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87",
4902 @@ -7311,7 +7500,7 @@ static struct cipher_testvec bf_cbc_dec_
4906 -static struct cipher_testvec bf_ctr_enc_tv_template[] = {
4907 +static const struct cipher_testvec bf_ctr_enc_tv_template[] = {
4908 { /* Generated with Crypto++ */
4909 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
4910 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
4911 @@ -7723,7 +7912,7 @@ static struct cipher_testvec bf_ctr_enc_
4915 -static struct cipher_testvec bf_ctr_dec_tv_template[] = {
4916 +static const struct cipher_testvec bf_ctr_dec_tv_template[] = {
4917 { /* Generated with Crypto++ */
4918 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
4919 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
4920 @@ -8138,18 +8327,7 @@ static struct cipher_testvec bf_ctr_dec_
4922 * Twofish test vectors.
4924 -#define TF_ENC_TEST_VECTORS 4
4925 -#define TF_DEC_TEST_VECTORS 4
4926 -#define TF_CBC_ENC_TEST_VECTORS 5
4927 -#define TF_CBC_DEC_TEST_VECTORS 5
4928 -#define TF_CTR_ENC_TEST_VECTORS 2
4929 -#define TF_CTR_DEC_TEST_VECTORS 2
4930 -#define TF_LRW_ENC_TEST_VECTORS 8
4931 -#define TF_LRW_DEC_TEST_VECTORS 8
4932 -#define TF_XTS_ENC_TEST_VECTORS 5
4933 -#define TF_XTS_DEC_TEST_VECTORS 5
4935 -static struct cipher_testvec tf_enc_tv_template[] = {
4936 +static const struct cipher_testvec tf_enc_tv_template[] = {
4938 .key = zeroed_string,
4940 @@ -8317,7 +8495,7 @@ static struct cipher_testvec tf_enc_tv_t
4944 -static struct cipher_testvec tf_dec_tv_template[] = {
4945 +static const struct cipher_testvec tf_dec_tv_template[] = {
4947 .key = zeroed_string,
4949 @@ -8485,7 +8663,7 @@ static struct cipher_testvec tf_dec_tv_t
4953 -static struct cipher_testvec tf_cbc_enc_tv_template[] = {
4954 +static const struct cipher_testvec tf_cbc_enc_tv_template[] = {
4955 { /* Generated with Nettle */
4956 .key = zeroed_string,
4958 @@ -8668,7 +8846,7 @@ static struct cipher_testvec tf_cbc_enc_
4962 -static struct cipher_testvec tf_cbc_dec_tv_template[] = {
4963 +static const struct cipher_testvec tf_cbc_dec_tv_template[] = {
4964 { /* Reverse of the first four above */
4965 .key = zeroed_string,
4967 @@ -8851,7 +9029,7 @@ static struct cipher_testvec tf_cbc_dec_
4971 -static struct cipher_testvec tf_ctr_enc_tv_template[] = {
4972 +static const struct cipher_testvec tf_ctr_enc_tv_template[] = {
4973 { /* Generated with Crypto++ */
4974 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
4975 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
4976 @@ -9262,7 +9440,7 @@ static struct cipher_testvec tf_ctr_enc_
4980 -static struct cipher_testvec tf_ctr_dec_tv_template[] = {
4981 +static const struct cipher_testvec tf_ctr_dec_tv_template[] = {
4982 { /* Generated with Crypto++ */
4983 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
4984 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
4985 @@ -9673,7 +9851,7 @@ static struct cipher_testvec tf_ctr_dec_
4989 -static struct cipher_testvec tf_lrw_enc_tv_template[] = {
4990 +static const struct cipher_testvec tf_lrw_enc_tv_template[] = {
4991 /* Generated from AES-LRW test vectors */
4993 .key = "\x45\x62\xac\x25\xf8\x28\x17\x6d"
4994 @@ -9925,7 +10103,7 @@ static struct cipher_testvec tf_lrw_enc_
4998 -static struct cipher_testvec tf_lrw_dec_tv_template[] = {
4999 +static const struct cipher_testvec tf_lrw_dec_tv_template[] = {
5000 /* Generated from AES-LRW test vectors */
5001 /* same as enc vectors with input and result reversed */
5003 @@ -10178,7 +10356,7 @@ static struct cipher_testvec tf_lrw_dec_
5007 -static struct cipher_testvec tf_xts_enc_tv_template[] = {
5008 +static const struct cipher_testvec tf_xts_enc_tv_template[] = {
5009 /* Generated from AES-XTS test vectors */
5011 .key = "\x00\x00\x00\x00\x00\x00\x00\x00"
5012 @@ -10520,7 +10698,7 @@ static struct cipher_testvec tf_xts_enc_
5016 -static struct cipher_testvec tf_xts_dec_tv_template[] = {
5017 +static const struct cipher_testvec tf_xts_dec_tv_template[] = {
5018 /* Generated from AES-XTS test vectors */
5019 /* same as enc vectors with input and result reversed */
5021 @@ -10867,25 +11045,7 @@ static struct cipher_testvec tf_xts_dec_
5022 * Serpent test vectors. These are backwards because Serpent writes
5023 * octet sequences in right-to-left mode.
5025 -#define SERPENT_ENC_TEST_VECTORS 5
5026 -#define SERPENT_DEC_TEST_VECTORS 5
5028 -#define TNEPRES_ENC_TEST_VECTORS 4
5029 -#define TNEPRES_DEC_TEST_VECTORS 4
5031 -#define SERPENT_CBC_ENC_TEST_VECTORS 1
5032 -#define SERPENT_CBC_DEC_TEST_VECTORS 1
5034 -#define SERPENT_CTR_ENC_TEST_VECTORS 2
5035 -#define SERPENT_CTR_DEC_TEST_VECTORS 2
5037 -#define SERPENT_LRW_ENC_TEST_VECTORS 8
5038 -#define SERPENT_LRW_DEC_TEST_VECTORS 8
5040 -#define SERPENT_XTS_ENC_TEST_VECTORS 5
5041 -#define SERPENT_XTS_DEC_TEST_VECTORS 5
5043 -static struct cipher_testvec serpent_enc_tv_template[] = {
5044 +static const struct cipher_testvec serpent_enc_tv_template[] = {
5046 .input = "\x00\x01\x02\x03\x04\x05\x06\x07"
5047 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
5048 @@ -11061,7 +11221,7 @@ static struct cipher_testvec serpent_enc
5052 -static struct cipher_testvec tnepres_enc_tv_template[] = {
5053 +static const struct cipher_testvec tnepres_enc_tv_template[] = {
5054 { /* KeySize=128, PT=0, I=1 */
5055 .input = "\x00\x00\x00\x00\x00\x00\x00\x00"
5056 "\x00\x00\x00\x00\x00\x00\x00\x00",
5057 @@ -11111,7 +11271,7 @@ static struct cipher_testvec tnepres_enc
5061 -static struct cipher_testvec serpent_dec_tv_template[] = {
5062 +static const struct cipher_testvec serpent_dec_tv_template[] = {
5064 .input = "\x12\x07\xfc\xce\x9b\xd0\xd6\x47"
5065 "\x6a\xe9\x8f\xbe\xd1\x43\xa0\xe2",
5066 @@ -11287,7 +11447,7 @@ static struct cipher_testvec serpent_dec
5070 -static struct cipher_testvec tnepres_dec_tv_template[] = {
5071 +static const struct cipher_testvec tnepres_dec_tv_template[] = {
5073 .input = "\x41\xcc\x6b\x31\x59\x31\x45\x97"
5074 "\x6d\x6f\xbb\x38\x4b\x37\x21\x28",
5075 @@ -11328,7 +11488,7 @@ static struct cipher_testvec tnepres_dec
5079 -static struct cipher_testvec serpent_cbc_enc_tv_template[] = {
5080 +static const struct cipher_testvec serpent_cbc_enc_tv_template[] = {
5081 { /* Generated with Crypto++ */
5082 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5083 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5084 @@ -11469,7 +11629,7 @@ static struct cipher_testvec serpent_cbc
5088 -static struct cipher_testvec serpent_cbc_dec_tv_template[] = {
5089 +static const struct cipher_testvec serpent_cbc_dec_tv_template[] = {
5090 { /* Generated with Crypto++ */
5091 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5092 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5093 @@ -11610,7 +11770,7 @@ static struct cipher_testvec serpent_cbc
5097 -static struct cipher_testvec serpent_ctr_enc_tv_template[] = {
5098 +static const struct cipher_testvec serpent_ctr_enc_tv_template[] = {
5099 { /* Generated with Crypto++ */
5100 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5101 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5102 @@ -12021,7 +12181,7 @@ static struct cipher_testvec serpent_ctr
5106 -static struct cipher_testvec serpent_ctr_dec_tv_template[] = {
5107 +static const struct cipher_testvec serpent_ctr_dec_tv_template[] = {
5108 { /* Generated with Crypto++ */
5109 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5110 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5111 @@ -12432,7 +12592,7 @@ static struct cipher_testvec serpent_ctr
5115 -static struct cipher_testvec serpent_lrw_enc_tv_template[] = {
5116 +static const struct cipher_testvec serpent_lrw_enc_tv_template[] = {
5117 /* Generated from AES-LRW test vectors */
5119 .key = "\x45\x62\xac\x25\xf8\x28\x17\x6d"
5120 @@ -12684,7 +12844,7 @@ static struct cipher_testvec serpent_lrw
5124 -static struct cipher_testvec serpent_lrw_dec_tv_template[] = {
5125 +static const struct cipher_testvec serpent_lrw_dec_tv_template[] = {
5126 /* Generated from AES-LRW test vectors */
5127 /* same as enc vectors with input and result reversed */
5129 @@ -12937,7 +13097,7 @@ static struct cipher_testvec serpent_lrw
5133 -static struct cipher_testvec serpent_xts_enc_tv_template[] = {
5134 +static const struct cipher_testvec serpent_xts_enc_tv_template[] = {
5135 /* Generated from AES-XTS test vectors */
5137 .key = "\x00\x00\x00\x00\x00\x00\x00\x00"
5138 @@ -13279,7 +13439,7 @@ static struct cipher_testvec serpent_xts
5142 -static struct cipher_testvec serpent_xts_dec_tv_template[] = {
5143 +static const struct cipher_testvec serpent_xts_dec_tv_template[] = {
5144 /* Generated from AES-XTS test vectors */
5145 /* same as enc vectors with input and result reversed */
5147 @@ -13623,18 +13783,7 @@ static struct cipher_testvec serpent_xts
5150 /* Cast6 test vectors from RFC 2612 */
5151 -#define CAST6_ENC_TEST_VECTORS 4
5152 -#define CAST6_DEC_TEST_VECTORS 4
5153 -#define CAST6_CBC_ENC_TEST_VECTORS 1
5154 -#define CAST6_CBC_DEC_TEST_VECTORS 1
5155 -#define CAST6_CTR_ENC_TEST_VECTORS 2
5156 -#define CAST6_CTR_DEC_TEST_VECTORS 2
5157 -#define CAST6_LRW_ENC_TEST_VECTORS 1
5158 -#define CAST6_LRW_DEC_TEST_VECTORS 1
5159 -#define CAST6_XTS_ENC_TEST_VECTORS 1
5160 -#define CAST6_XTS_DEC_TEST_VECTORS 1
5162 -static struct cipher_testvec cast6_enc_tv_template[] = {
5163 +static const struct cipher_testvec cast6_enc_tv_template[] = {
5165 .key = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
5166 "\x0a\xf7\x56\x47\xf2\x9f\x61\x5d",
5167 @@ -13805,7 +13954,7 @@ static struct cipher_testvec cast6_enc_t
5171 -static struct cipher_testvec cast6_dec_tv_template[] = {
5172 +static const struct cipher_testvec cast6_dec_tv_template[] = {
5174 .key = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
5175 "\x0a\xf7\x56\x47\xf2\x9f\x61\x5d",
5176 @@ -13976,7 +14125,7 @@ static struct cipher_testvec cast6_dec_t
5180 -static struct cipher_testvec cast6_cbc_enc_tv_template[] = {
5181 +static const struct cipher_testvec cast6_cbc_enc_tv_template[] = {
5182 { /* Generated from TF test vectors */
5183 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5184 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5185 @@ -14117,7 +14266,7 @@ static struct cipher_testvec cast6_cbc_e
5189 -static struct cipher_testvec cast6_cbc_dec_tv_template[] = {
5190 +static const struct cipher_testvec cast6_cbc_dec_tv_template[] = {
5191 { /* Generated from TF test vectors */
5192 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5193 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5194 @@ -14258,7 +14407,7 @@ static struct cipher_testvec cast6_cbc_d
5198 -static struct cipher_testvec cast6_ctr_enc_tv_template[] = {
5199 +static const struct cipher_testvec cast6_ctr_enc_tv_template[] = {
5200 { /* Generated from TF test vectors */
5201 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5202 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5203 @@ -14415,7 +14564,7 @@ static struct cipher_testvec cast6_ctr_e
5207 -static struct cipher_testvec cast6_ctr_dec_tv_template[] = {
5208 +static const struct cipher_testvec cast6_ctr_dec_tv_template[] = {
5209 { /* Generated from TF test vectors */
5210 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5211 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
5212 @@ -14572,7 +14721,7 @@ static struct cipher_testvec cast6_ctr_d
5216 -static struct cipher_testvec cast6_lrw_enc_tv_template[] = {
5217 +static const struct cipher_testvec cast6_lrw_enc_tv_template[] = {
5218 { /* Generated from TF test vectors */
5219 .key = "\xf8\xd4\x76\xff\xd6\x46\xee\x6c"
5220 "\x23\x84\xcb\x1c\x77\xd6\x19\x5d"
5221 @@ -14719,7 +14868,7 @@ static struct cipher_testvec cast6_lrw_e
5225 -static struct cipher_testvec cast6_lrw_dec_tv_template[] = {
5226 +static const struct cipher_testvec cast6_lrw_dec_tv_template[] = {
5227 { /* Generated from TF test vectors */
5228 .key = "\xf8\xd4\x76\xff\xd6\x46\xee\x6c"
5229 "\x23\x84\xcb\x1c\x77\xd6\x19\x5d"
5230 @@ -14866,7 +15015,7 @@ static struct cipher_testvec cast6_lrw_d
5234 -static struct cipher_testvec cast6_xts_enc_tv_template[] = {
5235 +static const struct cipher_testvec cast6_xts_enc_tv_template[] = {
5236 { /* Generated from TF test vectors */
5237 .key = "\x27\x18\x28\x18\x28\x45\x90\x45"
5238 "\x23\x53\x60\x28\x74\x71\x35\x26"
5239 @@ -15015,7 +15164,7 @@ static struct cipher_testvec cast6_xts_e
5243 -static struct cipher_testvec cast6_xts_dec_tv_template[] = {
5244 +static const struct cipher_testvec cast6_xts_dec_tv_template[] = {
5245 { /* Generated from TF test vectors */
5246 .key = "\x27\x18\x28\x18\x28\x45\x90\x45"
5247 "\x23\x53\x60\x28\x74\x71\x35\x26"
5248 @@ -15168,39 +15317,7 @@ static struct cipher_testvec cast6_xts_d
5252 -#define AES_ENC_TEST_VECTORS 4
5253 -#define AES_DEC_TEST_VECTORS 4
5254 -#define AES_CBC_ENC_TEST_VECTORS 5
5255 -#define AES_CBC_DEC_TEST_VECTORS 5
5256 -#define HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS 2
5257 -#define HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS 2
5258 -#define HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC 2
5259 -#define HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC 2
5260 -#define HMAC_SHA1_AES_CBC_ENC_TEST_VEC 7
5261 -#define HMAC_SHA256_AES_CBC_ENC_TEST_VEC 7
5262 -#define HMAC_SHA512_AES_CBC_ENC_TEST_VEC 7
5263 -#define AES_LRW_ENC_TEST_VECTORS 8
5264 -#define AES_LRW_DEC_TEST_VECTORS 8
5265 -#define AES_XTS_ENC_TEST_VECTORS 5
5266 -#define AES_XTS_DEC_TEST_VECTORS 5
5267 -#define AES_CTR_ENC_TEST_VECTORS 5
5268 -#define AES_CTR_DEC_TEST_VECTORS 5
5269 -#define AES_OFB_ENC_TEST_VECTORS 1
5270 -#define AES_OFB_DEC_TEST_VECTORS 1
5271 -#define AES_CTR_3686_ENC_TEST_VECTORS 7
5272 -#define AES_CTR_3686_DEC_TEST_VECTORS 6
5273 -#define AES_GCM_ENC_TEST_VECTORS 9
5274 -#define AES_GCM_DEC_TEST_VECTORS 8
5275 -#define AES_GCM_4106_ENC_TEST_VECTORS 23
5276 -#define AES_GCM_4106_DEC_TEST_VECTORS 23
5277 -#define AES_GCM_4543_ENC_TEST_VECTORS 1
5278 -#define AES_GCM_4543_DEC_TEST_VECTORS 2
5279 -#define AES_CCM_ENC_TEST_VECTORS 8
5280 -#define AES_CCM_DEC_TEST_VECTORS 7
5281 -#define AES_CCM_4309_ENC_TEST_VECTORS 7
5282 -#define AES_CCM_4309_DEC_TEST_VECTORS 10
5284 -static struct cipher_testvec aes_enc_tv_template[] = {
5285 +static const struct cipher_testvec aes_enc_tv_template[] = {
5286 { /* From FIPS-197 */
5287 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
5288 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
5289 @@ -15372,7 +15489,7 @@ static struct cipher_testvec aes_enc_tv_
5293 -static struct cipher_testvec aes_dec_tv_template[] = {
5294 +static const struct cipher_testvec aes_dec_tv_template[] = {
5295 { /* From FIPS-197 */
5296 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
5297 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
5298 @@ -15544,7 +15661,7 @@ static struct cipher_testvec aes_dec_tv_
5302 -static struct cipher_testvec aes_cbc_enc_tv_template[] = {
5303 +static const struct cipher_testvec aes_cbc_enc_tv_template[] = {
5304 { /* From RFC 3602 */
5305 .key = "\x06\xa9\x21\x40\x36\xb8\xa1\x5b"
5306 "\x51\x2e\x03\xd5\x34\x12\x00\x06",
5307 @@ -15766,7 +15883,7 @@ static struct cipher_testvec aes_cbc_enc
5311 -static struct cipher_testvec aes_cbc_dec_tv_template[] = {
5312 +static const struct cipher_testvec aes_cbc_dec_tv_template[] = {
5313 { /* From RFC 3602 */
5314 .key = "\x06\xa9\x21\x40\x36\xb8\xa1\x5b"
5315 "\x51\x2e\x03\xd5\x34\x12\x00\x06",
5316 @@ -15988,7 +16105,7 @@ static struct cipher_testvec aes_cbc_dec
5320 -static struct aead_testvec hmac_md5_ecb_cipher_null_enc_tv_template[] = {
5321 +static const struct aead_testvec hmac_md5_ecb_cipher_null_enc_tv_template[] = {
5322 { /* Input data from RFC 2410 Case 1 */
5323 #ifdef __LITTLE_ENDIAN
5324 .key = "\x08\x00" /* rta length */
5325 @@ -16030,7 +16147,7 @@ static struct aead_testvec hmac_md5_ecb_
5329 -static struct aead_testvec hmac_md5_ecb_cipher_null_dec_tv_template[] = {
5330 +static const struct aead_testvec hmac_md5_ecb_cipher_null_dec_tv_template[] = {
5332 #ifdef __LITTLE_ENDIAN
5333 .key = "\x08\x00" /* rta length */
5334 @@ -16072,7 +16189,7 @@ static struct aead_testvec hmac_md5_ecb_
5338 -static struct aead_testvec hmac_sha1_aes_cbc_enc_tv_temp[] = {
5339 +static const struct aead_testvec hmac_sha1_aes_cbc_enc_tv_temp[] = {
5340 { /* RFC 3602 Case 1 */
5341 #ifdef __LITTLE_ENDIAN
5342 .key = "\x08\x00" /* rta length */
5343 @@ -16341,7 +16458,7 @@ static struct aead_testvec hmac_sha1_aes
5347 -static struct aead_testvec hmac_sha1_ecb_cipher_null_enc_tv_temp[] = {
5348 +static const struct aead_testvec hmac_sha1_ecb_cipher_null_enc_tv_temp[] = {
5349 { /* Input data from RFC 2410 Case 1 */
5350 #ifdef __LITTLE_ENDIAN
5351 .key = "\x08\x00" /* rta length */
5352 @@ -16387,7 +16504,7 @@ static struct aead_testvec hmac_sha1_ecb
5356 -static struct aead_testvec hmac_sha1_ecb_cipher_null_dec_tv_temp[] = {
5357 +static const struct aead_testvec hmac_sha1_ecb_cipher_null_dec_tv_temp[] = {
5359 #ifdef __LITTLE_ENDIAN
5360 .key = "\x08\x00" /* rta length */
5361 @@ -16433,7 +16550,7 @@ static struct aead_testvec hmac_sha1_ecb
5365 -static struct aead_testvec hmac_sha256_aes_cbc_enc_tv_temp[] = {
5366 +static const struct aead_testvec hmac_sha256_aes_cbc_enc_tv_temp[] = {
5367 { /* RFC 3602 Case 1 */
5368 #ifdef __LITTLE_ENDIAN
5369 .key = "\x08\x00" /* rta length */
5370 @@ -16716,7 +16833,7 @@ static struct aead_testvec hmac_sha256_a
5374 -static struct aead_testvec hmac_sha512_aes_cbc_enc_tv_temp[] = {
5375 +static const struct aead_testvec hmac_sha512_aes_cbc_enc_tv_temp[] = {
5376 { /* RFC 3602 Case 1 */
5377 #ifdef __LITTLE_ENDIAN
5378 .key = "\x08\x00" /* rta length */
5379 @@ -17055,9 +17172,7 @@ static struct aead_testvec hmac_sha512_a
5383 -#define HMAC_SHA1_DES_CBC_ENC_TEST_VEC 1
5385 -static struct aead_testvec hmac_sha1_des_cbc_enc_tv_temp[] = {
5386 +static const struct aead_testvec hmac_sha1_des_cbc_enc_tv_temp[] = {
5387 { /*Generated with cryptopp*/
5388 #ifdef __LITTLE_ENDIAN
5389 .key = "\x08\x00" /* rta length */
5390 @@ -17116,9 +17231,7 @@ static struct aead_testvec hmac_sha1_des
5394 -#define HMAC_SHA224_DES_CBC_ENC_TEST_VEC 1
5396 -static struct aead_testvec hmac_sha224_des_cbc_enc_tv_temp[] = {
5397 +static const struct aead_testvec hmac_sha224_des_cbc_enc_tv_temp[] = {
5398 { /*Generated with cryptopp*/
5399 #ifdef __LITTLE_ENDIAN
5400 .key = "\x08\x00" /* rta length */
5401 @@ -17177,9 +17290,7 @@ static struct aead_testvec hmac_sha224_d
5405 -#define HMAC_SHA256_DES_CBC_ENC_TEST_VEC 1
5407 -static struct aead_testvec hmac_sha256_des_cbc_enc_tv_temp[] = {
5408 +static const struct aead_testvec hmac_sha256_des_cbc_enc_tv_temp[] = {
5409 { /*Generated with cryptopp*/
5410 #ifdef __LITTLE_ENDIAN
5411 .key = "\x08\x00" /* rta length */
5412 @@ -17240,9 +17351,7 @@ static struct aead_testvec hmac_sha256_d
5416 -#define HMAC_SHA384_DES_CBC_ENC_TEST_VEC 1
5418 -static struct aead_testvec hmac_sha384_des_cbc_enc_tv_temp[] = {
5419 +static const struct aead_testvec hmac_sha384_des_cbc_enc_tv_temp[] = {
5420 { /*Generated with cryptopp*/
5421 #ifdef __LITTLE_ENDIAN
5422 .key = "\x08\x00" /* rta length */
5423 @@ -17307,9 +17416,7 @@ static struct aead_testvec hmac_sha384_d
5427 -#define HMAC_SHA512_DES_CBC_ENC_TEST_VEC 1
5429 -static struct aead_testvec hmac_sha512_des_cbc_enc_tv_temp[] = {
5430 +static const struct aead_testvec hmac_sha512_des_cbc_enc_tv_temp[] = {
5431 { /*Generated with cryptopp*/
5432 #ifdef __LITTLE_ENDIAN
5433 .key = "\x08\x00" /* rta length */
5434 @@ -17378,9 +17485,7 @@ static struct aead_testvec hmac_sha512_d
5438 -#define HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC 1
5440 -static struct aead_testvec hmac_sha1_des3_ede_cbc_enc_tv_temp[] = {
5441 +static const struct aead_testvec hmac_sha1_des3_ede_cbc_enc_tv_temp[] = {
5442 { /*Generated with cryptopp*/
5443 #ifdef __LITTLE_ENDIAN
5444 .key = "\x08\x00" /* rta length */
5445 @@ -17441,9 +17546,7 @@ static struct aead_testvec hmac_sha1_des
5449 -#define HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC 1
5451 -static struct aead_testvec hmac_sha224_des3_ede_cbc_enc_tv_temp[] = {
5452 +static const struct aead_testvec hmac_sha224_des3_ede_cbc_enc_tv_temp[] = {
5453 { /*Generated with cryptopp*/
5454 #ifdef __LITTLE_ENDIAN
5455 .key = "\x08\x00" /* rta length */
5456 @@ -17504,9 +17607,7 @@ static struct aead_testvec hmac_sha224_d
5460 -#define HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC 1
5462 -static struct aead_testvec hmac_sha256_des3_ede_cbc_enc_tv_temp[] = {
5463 +static const struct aead_testvec hmac_sha256_des3_ede_cbc_enc_tv_temp[] = {
5464 { /*Generated with cryptopp*/
5465 #ifdef __LITTLE_ENDIAN
5466 .key = "\x08\x00" /* rta length */
5467 @@ -17569,9 +17670,7 @@ static struct aead_testvec hmac_sha256_d
5471 -#define HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC 1
5473 -static struct aead_testvec hmac_sha384_des3_ede_cbc_enc_tv_temp[] = {
5474 +static const struct aead_testvec hmac_sha384_des3_ede_cbc_enc_tv_temp[] = {
5475 { /*Generated with cryptopp*/
5476 #ifdef __LITTLE_ENDIAN
5477 .key = "\x08\x00" /* rta length */
5478 @@ -17638,9 +17737,7 @@ static struct aead_testvec hmac_sha384_d
5482 -#define HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC 1
5484 -static struct aead_testvec hmac_sha512_des3_ede_cbc_enc_tv_temp[] = {
5485 +static const struct aead_testvec hmac_sha512_des3_ede_cbc_enc_tv_temp[] = {
5486 { /*Generated with cryptopp*/
5487 #ifdef __LITTLE_ENDIAN
5488 .key = "\x08\x00" /* rta length */
5489 @@ -17711,7 +17808,7 @@ static struct aead_testvec hmac_sha512_d
5493 -static struct cipher_testvec aes_lrw_enc_tv_template[] = {
5494 +static const struct cipher_testvec aes_lrw_enc_tv_template[] = {
5495 /* from http://grouper.ieee.org/groups/1619/email/pdf00017.pdf */
5496 { /* LRW-32-AES 1 */
5497 .key = "\x45\x62\xac\x25\xf8\x28\x17\x6d"
5498 @@ -17964,7 +18061,7 @@ static struct cipher_testvec aes_lrw_enc
5502 -static struct cipher_testvec aes_lrw_dec_tv_template[] = {
5503 +static const struct cipher_testvec aes_lrw_dec_tv_template[] = {
5504 /* from http://grouper.ieee.org/groups/1619/email/pdf00017.pdf */
5505 /* same as enc vectors with input and result reversed */
5506 { /* LRW-32-AES 1 */
5507 @@ -18218,7 +18315,7 @@ static struct cipher_testvec aes_lrw_dec
5511 -static struct cipher_testvec aes_xts_enc_tv_template[] = {
5512 +static const struct cipher_testvec aes_xts_enc_tv_template[] = {
5513 /* http://grouper.ieee.org/groups/1619/email/pdf00086.pdf */
5515 .key = "\x00\x00\x00\x00\x00\x00\x00\x00"
5516 @@ -18561,7 +18658,7 @@ static struct cipher_testvec aes_xts_enc
5520 -static struct cipher_testvec aes_xts_dec_tv_template[] = {
5521 +static const struct cipher_testvec aes_xts_dec_tv_template[] = {
5522 /* http://grouper.ieee.org/groups/1619/email/pdf00086.pdf */
5524 .key = "\x00\x00\x00\x00\x00\x00\x00\x00"
5525 @@ -18905,7 +19002,7 @@ static struct cipher_testvec aes_xts_dec
5529 -static struct cipher_testvec aes_ctr_enc_tv_template[] = {
5530 +static const struct cipher_testvec aes_ctr_enc_tv_template[] = {
5531 { /* From NIST Special Publication 800-38A, Appendix F.5 */
5532 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
5533 "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
5534 @@ -19260,7 +19357,7 @@ static struct cipher_testvec aes_ctr_enc
5538 -static struct cipher_testvec aes_ctr_dec_tv_template[] = {
5539 +static const struct cipher_testvec aes_ctr_dec_tv_template[] = {
5540 { /* From NIST Special Publication 800-38A, Appendix F.5 */
5541 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
5542 "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
5543 @@ -19615,7 +19712,7 @@ static struct cipher_testvec aes_ctr_dec
5547 -static struct cipher_testvec aes_ctr_rfc3686_enc_tv_template[] = {
5548 +static const struct cipher_testvec aes_ctr_rfc3686_enc_tv_template[] = {
5549 { /* From RFC 3686 */
5550 .key = "\xae\x68\x52\xf8\x12\x10\x67\xcc"
5551 "\x4b\xf7\xa5\x76\x55\x77\xf3\x9e"
5552 @@ -20747,7 +20844,7 @@ static struct cipher_testvec aes_ctr_rfc
5556 -static struct cipher_testvec aes_ctr_rfc3686_dec_tv_template[] = {
5557 +static const struct cipher_testvec aes_ctr_rfc3686_dec_tv_template[] = {
5558 { /* From RFC 3686 */
5559 .key = "\xae\x68\x52\xf8\x12\x10\x67\xcc"
5560 "\x4b\xf7\xa5\x76\x55\x77\xf3\x9e"
5561 @@ -20838,7 +20935,7 @@ static struct cipher_testvec aes_ctr_rfc
5565 -static struct cipher_testvec aes_ofb_enc_tv_template[] = {
5566 +static const struct cipher_testvec aes_ofb_enc_tv_template[] = {
5567 /* From NIST Special Publication 800-38A, Appendix F.5 */
5569 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
5570 @@ -20867,7 +20964,7 @@ static struct cipher_testvec aes_ofb_enc
5574 -static struct cipher_testvec aes_ofb_dec_tv_template[] = {
5575 +static const struct cipher_testvec aes_ofb_dec_tv_template[] = {
5576 /* From NIST Special Publication 800-38A, Appendix F.5 */
5578 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
5579 @@ -20896,7 +20993,7 @@ static struct cipher_testvec aes_ofb_dec
5583 -static struct aead_testvec aes_gcm_enc_tv_template[] = {
5584 +static const struct aead_testvec aes_gcm_enc_tv_template[] = {
5585 { /* From McGrew & Viega - http://citeseer.ist.psu.edu/656989.html */
5586 .key = zeroed_string,
5588 @@ -21056,7 +21153,7 @@ static struct aead_testvec aes_gcm_enc_t
5592 -static struct aead_testvec aes_gcm_dec_tv_template[] = {
5593 +static const struct aead_testvec aes_gcm_dec_tv_template[] = {
5594 { /* From McGrew & Viega - http://citeseer.ist.psu.edu/656989.html */
5595 .key = zeroed_string,
5597 @@ -21258,7 +21355,7 @@ static struct aead_testvec aes_gcm_dec_t
5601 -static struct aead_testvec aes_gcm_rfc4106_enc_tv_template[] = {
5602 +static const struct aead_testvec aes_gcm_rfc4106_enc_tv_template[] = {
5603 { /* Generated using Crypto++ */
5604 .key = zeroed_string,
5606 @@ -21871,7 +21968,7 @@ static struct aead_testvec aes_gcm_rfc41
5610 -static struct aead_testvec aes_gcm_rfc4106_dec_tv_template[] = {
5611 +static const struct aead_testvec aes_gcm_rfc4106_dec_tv_template[] = {
5612 { /* Generated using Crypto++ */
5613 .key = zeroed_string,
5615 @@ -22485,7 +22582,7 @@ static struct aead_testvec aes_gcm_rfc41
5619 -static struct aead_testvec aes_gcm_rfc4543_enc_tv_template[] = {
5620 +static const struct aead_testvec aes_gcm_rfc4543_enc_tv_template[] = {
5621 { /* From draft-mcgrew-gcm-test-01 */
5622 .key = "\x4c\x80\xcd\xef\xbb\x5d\x10\xda"
5623 "\x90\x6a\xc7\x3c\x36\x13\xa6\x34"
5624 @@ -22516,7 +22613,7 @@ static struct aead_testvec aes_gcm_rfc45
5628 -static struct aead_testvec aes_gcm_rfc4543_dec_tv_template[] = {
5629 +static const struct aead_testvec aes_gcm_rfc4543_dec_tv_template[] = {
5630 { /* From draft-mcgrew-gcm-test-01 */
5631 .key = "\x4c\x80\xcd\xef\xbb\x5d\x10\xda"
5632 "\x90\x6a\xc7\x3c\x36\x13\xa6\x34"
5633 @@ -22575,7 +22672,7 @@ static struct aead_testvec aes_gcm_rfc45
5637 -static struct aead_testvec aes_ccm_enc_tv_template[] = {
5638 +static const struct aead_testvec aes_ccm_enc_tv_template[] = {
5639 { /* From RFC 3610 */
5640 .key = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
5641 "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
5642 @@ -22859,7 +22956,7 @@ static struct aead_testvec aes_ccm_enc_t
5646 -static struct aead_testvec aes_ccm_dec_tv_template[] = {
5647 +static const struct aead_testvec aes_ccm_dec_tv_template[] = {
5648 { /* From RFC 3610 */
5649 .key = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
5650 "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
5651 @@ -23191,7 +23288,7 @@ static struct aead_testvec aes_ccm_dec_t
5652 * These vectors are copied/generated from the ones for rfc4106 with
5653 * the key truncated by one byte..
5655 -static struct aead_testvec aes_ccm_rfc4309_enc_tv_template[] = {
5656 +static const struct aead_testvec aes_ccm_rfc4309_enc_tv_template[] = {
5657 { /* Generated using Crypto++ */
5658 .key = zeroed_string,
5660 @@ -23804,7 +23901,7 @@ static struct aead_testvec aes_ccm_rfc43
5664 -static struct aead_testvec aes_ccm_rfc4309_dec_tv_template[] = {
5665 +static const struct aead_testvec aes_ccm_rfc4309_dec_tv_template[] = {
5666 { /* Generated using Crypto++ */
5667 .key = zeroed_string,
5669 @@ -24420,9 +24517,7 @@ static struct aead_testvec aes_ccm_rfc43
5671 * ChaCha20-Poly1305 AEAD test vectors from RFC7539 2.8.2./A.5.
5673 -#define RFC7539_ENC_TEST_VECTORS 2
5674 -#define RFC7539_DEC_TEST_VECTORS 2
5675 -static struct aead_testvec rfc7539_enc_tv_template[] = {
5676 +static const struct aead_testvec rfc7539_enc_tv_template[] = {
5678 .key = "\x80\x81\x82\x83\x84\x85\x86\x87"
5679 "\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
5680 @@ -24554,7 +24649,7 @@ static struct aead_testvec rfc7539_enc_t
5684 -static struct aead_testvec rfc7539_dec_tv_template[] = {
5685 +static const struct aead_testvec rfc7539_dec_tv_template[] = {
5687 .key = "\x80\x81\x82\x83\x84\x85\x86\x87"
5688 "\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
5689 @@ -24689,9 +24784,7 @@ static struct aead_testvec rfc7539_dec_t
5691 * draft-irtf-cfrg-chacha20-poly1305
5693 -#define RFC7539ESP_DEC_TEST_VECTORS 1
5694 -#define RFC7539ESP_ENC_TEST_VECTORS 1
5695 -static struct aead_testvec rfc7539esp_enc_tv_template[] = {
5696 +static const struct aead_testvec rfc7539esp_enc_tv_template[] = {
5698 .key = "\x1c\x92\x40\xa5\xeb\x55\xd3\x8a"
5699 "\xf3\x33\x88\x86\x04\xf6\xb5\xf0"
5700 @@ -24779,7 +24872,7 @@ static struct aead_testvec rfc7539esp_en
5704 -static struct aead_testvec rfc7539esp_dec_tv_template[] = {
5705 +static const struct aead_testvec rfc7539esp_dec_tv_template[] = {
5707 .key = "\x1c\x92\x40\xa5\xeb\x55\xd3\x8a"
5708 "\xf3\x33\x88\x86\x04\xf6\xb5\xf0"
5709 @@ -24875,7 +24968,7 @@ static struct aead_testvec rfc7539esp_de
5710 * semiblock of the ciphertext from the test vector. For decryption, iv is
5711 * the first semiblock of the ciphertext.
5713 -static struct cipher_testvec aes_kw_enc_tv_template[] = {
5714 +static const struct cipher_testvec aes_kw_enc_tv_template[] = {
5716 .key = "\x75\x75\xda\x3a\x93\x60\x7c\xc2"
5717 "\xbf\xd8\xce\xc7\xaa\xdf\xd9\xa6",
5718 @@ -24890,7 +24983,7 @@ static struct cipher_testvec aes_kw_enc_
5722 -static struct cipher_testvec aes_kw_dec_tv_template[] = {
5723 +static const struct cipher_testvec aes_kw_dec_tv_template[] = {
5725 .key = "\x80\xaa\x99\x73\x27\xa4\x80\x6b"
5726 "\x6a\x7a\x41\xa5\x2b\x86\xc3\x71"
5727 @@ -24913,9 +25006,7 @@ static struct cipher_testvec aes_kw_dec_
5728 * http://csrc.nist.gov/groups/STM/cavp/documents/rng/RNGVS.pdf
5729 * Only AES-128 is supported at this time.
5731 -#define ANSI_CPRNG_AES_TEST_VECTORS 6
5733 -static struct cprng_testvec ansi_cprng_aes_tv_template[] = {
5734 +static const struct cprng_testvec ansi_cprng_aes_tv_template[] = {
5736 .key = "\xf3\xb1\x66\x6d\x13\x60\x72\x42"
5737 "\xed\x06\x1c\xab\xb8\xd4\x62\x02",
5738 @@ -25011,7 +25102,7 @@ static struct cprng_testvec ansi_cprng_a
5739 * (Hash, HMAC, CTR) are tested with all permutations of use cases (w/ and
5740 * w/o personalization string, w/ and w/o additional input string).
5742 -static struct drbg_testvec drbg_pr_sha256_tv_template[] = {
5743 +static const struct drbg_testvec drbg_pr_sha256_tv_template[] = {
5745 .entropy = (unsigned char *)
5746 "\x72\x88\x4c\xcd\x6c\x85\x57\x70\xf7\x0b\x8b\x86"
5747 @@ -25169,7 +25260,7 @@ static struct drbg_testvec drbg_pr_sha25
5751 -static struct drbg_testvec drbg_pr_hmac_sha256_tv_template[] = {
5752 +static const struct drbg_testvec drbg_pr_hmac_sha256_tv_template[] = {
5754 .entropy = (unsigned char *)
5755 "\x99\x69\xe5\x4b\x47\x03\xff\x31\x78\x5b\x87\x9a"
5756 @@ -25327,7 +25418,7 @@ static struct drbg_testvec drbg_pr_hmac_
5760 -static struct drbg_testvec drbg_pr_ctr_aes128_tv_template[] = {
5761 +static const struct drbg_testvec drbg_pr_ctr_aes128_tv_template[] = {
5763 .entropy = (unsigned char *)
5764 "\xd1\x44\xc6\x61\x81\x6d\xca\x9d\x15\x28\x8a\x42"
5765 @@ -25451,7 +25542,7 @@ static struct drbg_testvec drbg_pr_ctr_a
5766 * (Hash, HMAC, CTR) are tested with all permutations of use cases (w/ and
5767 * w/o personalization string, w/ and w/o additional input string).
5769 -static struct drbg_testvec drbg_nopr_sha256_tv_template[] = {
5770 +static const struct drbg_testvec drbg_nopr_sha256_tv_template[] = {
5772 .entropy = (unsigned char *)
5773 "\xa6\x5a\xd0\xf3\x45\xdb\x4e\x0e\xff\xe8\x75\xc3"
5774 @@ -25573,7 +25664,7 @@ static struct drbg_testvec drbg_nopr_sha
5778 -static struct drbg_testvec drbg_nopr_hmac_sha256_tv_template[] = {
5779 +static const struct drbg_testvec drbg_nopr_hmac_sha256_tv_template[] = {
5781 .entropy = (unsigned char *)
5782 "\xca\x85\x19\x11\x34\x93\x84\xbf\xfe\x89\xde\x1c"
5783 @@ -25695,7 +25786,7 @@ static struct drbg_testvec drbg_nopr_hma
5787 -static struct drbg_testvec drbg_nopr_ctr_aes192_tv_template[] = {
5788 +static const struct drbg_testvec drbg_nopr_ctr_aes192_tv_template[] = {
5790 .entropy = (unsigned char *)
5791 "\xc3\x5c\x2f\xa2\xa8\x9d\x52\xa1\x1f\xa3\x2a\xa9"
5792 @@ -25719,7 +25810,7 @@ static struct drbg_testvec drbg_nopr_ctr
5796 -static struct drbg_testvec drbg_nopr_ctr_aes256_tv_template[] = {
5797 +static const struct drbg_testvec drbg_nopr_ctr_aes256_tv_template[] = {
5799 .entropy = (unsigned char *)
5800 "\x36\x40\x19\x40\xfa\x8b\x1f\xba\x91\xa1\x66\x1f"
5801 @@ -25743,7 +25834,7 @@ static struct drbg_testvec drbg_nopr_ctr
5805 -static struct drbg_testvec drbg_nopr_ctr_aes128_tv_template[] = {
5806 +static const struct drbg_testvec drbg_nopr_ctr_aes128_tv_template[] = {
5808 .entropy = (unsigned char *)
5809 "\x87\xe1\xc5\x32\x99\x7f\x57\xa3\x5c\x28\x6d\xe8"
5810 @@ -25832,14 +25923,7 @@ static struct drbg_testvec drbg_nopr_ctr
5813 /* Cast5 test vectors from RFC 2144 */
5814 -#define CAST5_ENC_TEST_VECTORS 4
5815 -#define CAST5_DEC_TEST_VECTORS 4
5816 -#define CAST5_CBC_ENC_TEST_VECTORS 1
5817 -#define CAST5_CBC_DEC_TEST_VECTORS 1
5818 -#define CAST5_CTR_ENC_TEST_VECTORS 2
5819 -#define CAST5_CTR_DEC_TEST_VECTORS 2
5821 -static struct cipher_testvec cast5_enc_tv_template[] = {
5822 +static const struct cipher_testvec cast5_enc_tv_template[] = {
5824 .key = "\x01\x23\x45\x67\x12\x34\x56\x78"
5825 "\x23\x45\x67\x89\x34\x56\x78\x9a",
5826 @@ -26000,7 +26084,7 @@ static struct cipher_testvec cast5_enc_t
5830 -static struct cipher_testvec cast5_dec_tv_template[] = {
5831 +static const struct cipher_testvec cast5_dec_tv_template[] = {
5833 .key = "\x01\x23\x45\x67\x12\x34\x56\x78"
5834 "\x23\x45\x67\x89\x34\x56\x78\x9a",
5835 @@ -26161,7 +26245,7 @@ static struct cipher_testvec cast5_dec_t
5839 -static struct cipher_testvec cast5_cbc_enc_tv_template[] = {
5840 +static const struct cipher_testvec cast5_cbc_enc_tv_template[] = {
5841 { /* Generated from TF test vectors */
5842 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5843 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A",
5844 @@ -26299,7 +26383,7 @@ static struct cipher_testvec cast5_cbc_e
5848 -static struct cipher_testvec cast5_cbc_dec_tv_template[] = {
5849 +static const struct cipher_testvec cast5_cbc_dec_tv_template[] = {
5850 { /* Generated from TF test vectors */
5851 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5852 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A",
5853 @@ -26437,7 +26521,7 @@ static struct cipher_testvec cast5_cbc_d
5857 -static struct cipher_testvec cast5_ctr_enc_tv_template[] = {
5858 +static const struct cipher_testvec cast5_ctr_enc_tv_template[] = {
5859 { /* Generated from TF test vectors */
5860 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5861 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A",
5862 @@ -26588,7 +26672,7 @@ static struct cipher_testvec cast5_ctr_e
5866 -static struct cipher_testvec cast5_ctr_dec_tv_template[] = {
5867 +static const struct cipher_testvec cast5_ctr_dec_tv_template[] = {
5868 { /* Generated from TF test vectors */
5869 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
5870 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A",
5871 @@ -26742,10 +26826,7 @@ static struct cipher_testvec cast5_ctr_d
5873 * ARC4 test vectors from OpenSSL
5875 -#define ARC4_ENC_TEST_VECTORS 7
5876 -#define ARC4_DEC_TEST_VECTORS 7
5878 -static struct cipher_testvec arc4_enc_tv_template[] = {
5879 +static const struct cipher_testvec arc4_enc_tv_template[] = {
5881 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
5883 @@ -26811,7 +26892,7 @@ static struct cipher_testvec arc4_enc_tv
5887 -static struct cipher_testvec arc4_dec_tv_template[] = {
5888 +static const struct cipher_testvec arc4_dec_tv_template[] = {
5890 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef",
5892 @@ -26880,10 +26961,7 @@ static struct cipher_testvec arc4_dec_tv
5896 -#define TEA_ENC_TEST_VECTORS 4
5897 -#define TEA_DEC_TEST_VECTORS 4
5899 -static struct cipher_testvec tea_enc_tv_template[] = {
5900 +static const struct cipher_testvec tea_enc_tv_template[] = {
5902 .key = zeroed_string,
5904 @@ -26926,7 +27004,7 @@ static struct cipher_testvec tea_enc_tv_
5908 -static struct cipher_testvec tea_dec_tv_template[] = {
5909 +static const struct cipher_testvec tea_dec_tv_template[] = {
5911 .key = zeroed_string,
5913 @@ -26972,10 +27050,7 @@ static struct cipher_testvec tea_dec_tv_
5917 -#define XTEA_ENC_TEST_VECTORS 4
5918 -#define XTEA_DEC_TEST_VECTORS 4
5920 -static struct cipher_testvec xtea_enc_tv_template[] = {
5921 +static const struct cipher_testvec xtea_enc_tv_template[] = {
5923 .key = zeroed_string,
5925 @@ -27018,7 +27093,7 @@ static struct cipher_testvec xtea_enc_tv
5929 -static struct cipher_testvec xtea_dec_tv_template[] = {
5930 +static const struct cipher_testvec xtea_dec_tv_template[] = {
5932 .key = zeroed_string,
5934 @@ -27064,10 +27139,7 @@ static struct cipher_testvec xtea_dec_tv
5936 * KHAZAD test vectors.
5938 -#define KHAZAD_ENC_TEST_VECTORS 5
5939 -#define KHAZAD_DEC_TEST_VECTORS 5
5941 -static struct cipher_testvec khazad_enc_tv_template[] = {
5942 +static const struct cipher_testvec khazad_enc_tv_template[] = {
5944 .key = "\x80\x00\x00\x00\x00\x00\x00\x00"
5945 "\x00\x00\x00\x00\x00\x00\x00\x00",
5946 @@ -27113,7 +27185,7 @@ static struct cipher_testvec khazad_enc_
5950 -static struct cipher_testvec khazad_dec_tv_template[] = {
5951 +static const struct cipher_testvec khazad_dec_tv_template[] = {
5953 .key = "\x80\x00\x00\x00\x00\x00\x00\x00"
5954 "\x00\x00\x00\x00\x00\x00\x00\x00",
5955 @@ -27163,12 +27235,7 @@ static struct cipher_testvec khazad_dec_
5956 * Anubis test vectors.
5959 -#define ANUBIS_ENC_TEST_VECTORS 5
5960 -#define ANUBIS_DEC_TEST_VECTORS 5
5961 -#define ANUBIS_CBC_ENC_TEST_VECTORS 2
5962 -#define ANUBIS_CBC_DEC_TEST_VECTORS 2
5964 -static struct cipher_testvec anubis_enc_tv_template[] = {
5965 +static const struct cipher_testvec anubis_enc_tv_template[] = {
5967 .key = "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
5968 "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe",
5969 @@ -27231,7 +27298,7 @@ static struct cipher_testvec anubis_enc_
5973 -static struct cipher_testvec anubis_dec_tv_template[] = {
5974 +static const struct cipher_testvec anubis_dec_tv_template[] = {
5976 .key = "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
5977 "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe",
5978 @@ -27294,7 +27361,7 @@ static struct cipher_testvec anubis_dec_
5982 -static struct cipher_testvec anubis_cbc_enc_tv_template[] = {
5983 +static const struct cipher_testvec anubis_cbc_enc_tv_template[] = {
5985 .key = "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
5986 "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe",
5987 @@ -27329,7 +27396,7 @@ static struct cipher_testvec anubis_cbc_
5991 -static struct cipher_testvec anubis_cbc_dec_tv_template[] = {
5992 +static const struct cipher_testvec anubis_cbc_dec_tv_template[] = {
5994 .key = "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
5995 "\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe",
5996 @@ -27367,10 +27434,7 @@ static struct cipher_testvec anubis_cbc_
6000 -#define XETA_ENC_TEST_VECTORS 4
6001 -#define XETA_DEC_TEST_VECTORS 4
6003 -static struct cipher_testvec xeta_enc_tv_template[] = {
6004 +static const struct cipher_testvec xeta_enc_tv_template[] = {
6006 .key = zeroed_string,
6008 @@ -27413,7 +27477,7 @@ static struct cipher_testvec xeta_enc_tv
6012 -static struct cipher_testvec xeta_dec_tv_template[] = {
6013 +static const struct cipher_testvec xeta_dec_tv_template[] = {
6015 .key = zeroed_string,
6017 @@ -27459,10 +27523,7 @@ static struct cipher_testvec xeta_dec_tv
6019 * FCrypt test vectors
6021 -#define FCRYPT_ENC_TEST_VECTORS ARRAY_SIZE(fcrypt_pcbc_enc_tv_template)
6022 -#define FCRYPT_DEC_TEST_VECTORS ARRAY_SIZE(fcrypt_pcbc_dec_tv_template)
6024 -static struct cipher_testvec fcrypt_pcbc_enc_tv_template[] = {
6025 +static const struct cipher_testvec fcrypt_pcbc_enc_tv_template[] = {
6026 { /* http://www.openafs.org/pipermail/openafs-devel/2000-December/005320.html */
6027 .key = "\x00\x00\x00\x00\x00\x00\x00\x00",
6029 @@ -27523,7 +27584,7 @@ static struct cipher_testvec fcrypt_pcbc
6033 -static struct cipher_testvec fcrypt_pcbc_dec_tv_template[] = {
6034 +static const struct cipher_testvec fcrypt_pcbc_dec_tv_template[] = {
6035 { /* http://www.openafs.org/pipermail/openafs-devel/2000-December/005320.html */
6036 .key = "\x00\x00\x00\x00\x00\x00\x00\x00",
6038 @@ -27587,18 +27648,7 @@ static struct cipher_testvec fcrypt_pcbc
6040 * CAMELLIA test vectors.
6042 -#define CAMELLIA_ENC_TEST_VECTORS 4
6043 -#define CAMELLIA_DEC_TEST_VECTORS 4
6044 -#define CAMELLIA_CBC_ENC_TEST_VECTORS 3
6045 -#define CAMELLIA_CBC_DEC_TEST_VECTORS 3
6046 -#define CAMELLIA_CTR_ENC_TEST_VECTORS 2
6047 -#define CAMELLIA_CTR_DEC_TEST_VECTORS 2
6048 -#define CAMELLIA_LRW_ENC_TEST_VECTORS 8
6049 -#define CAMELLIA_LRW_DEC_TEST_VECTORS 8
6050 -#define CAMELLIA_XTS_ENC_TEST_VECTORS 5
6051 -#define CAMELLIA_XTS_DEC_TEST_VECTORS 5
6053 -static struct cipher_testvec camellia_enc_tv_template[] = {
6054 +static const struct cipher_testvec camellia_enc_tv_template[] = {
6056 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef"
6057 "\xfe\xdc\xba\x98\x76\x54\x32\x10",
6058 @@ -27898,7 +27948,7 @@ static struct cipher_testvec camellia_en
6062 -static struct cipher_testvec camellia_dec_tv_template[] = {
6063 +static const struct cipher_testvec camellia_dec_tv_template[] = {
6065 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef"
6066 "\xfe\xdc\xba\x98\x76\x54\x32\x10",
6067 @@ -28198,7 +28248,7 @@ static struct cipher_testvec camellia_de
6071 -static struct cipher_testvec camellia_cbc_enc_tv_template[] = {
6072 +static const struct cipher_testvec camellia_cbc_enc_tv_template[] = {
6074 .key = "\x06\xa9\x21\x40\x36\xb8\xa1\x5b"
6075 "\x51\x2e\x03\xd5\x34\x12\x00\x06",
6076 @@ -28494,7 +28544,7 @@ static struct cipher_testvec camellia_cb
6080 -static struct cipher_testvec camellia_cbc_dec_tv_template[] = {
6081 +static const struct cipher_testvec camellia_cbc_dec_tv_template[] = {
6083 .key = "\x06\xa9\x21\x40\x36\xb8\xa1\x5b"
6084 "\x51\x2e\x03\xd5\x34\x12\x00\x06",
6085 @@ -28790,7 +28840,7 @@ static struct cipher_testvec camellia_cb
6089 -static struct cipher_testvec camellia_ctr_enc_tv_template[] = {
6090 +static const struct cipher_testvec camellia_ctr_enc_tv_template[] = {
6091 { /* Generated with Crypto++ */
6092 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
6093 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
6094 @@ -29457,7 +29507,7 @@ static struct cipher_testvec camellia_ct
6098 -static struct cipher_testvec camellia_ctr_dec_tv_template[] = {
6099 +static const struct cipher_testvec camellia_ctr_dec_tv_template[] = {
6100 { /* Generated with Crypto++ */
6101 .key = "\x85\x62\x3F\x1C\xF9\xD6\x1C\xF9"
6102 "\xD6\xB3\x90\x6D\x4A\x90\x6D\x4A"
6103 @@ -30124,7 +30174,7 @@ static struct cipher_testvec camellia_ct
6107 -static struct cipher_testvec camellia_lrw_enc_tv_template[] = {
6108 +static const struct cipher_testvec camellia_lrw_enc_tv_template[] = {
6109 /* Generated from AES-LRW test vectors */
6111 .key = "\x45\x62\xac\x25\xf8\x28\x17\x6d"
6112 @@ -30376,7 +30426,7 @@ static struct cipher_testvec camellia_lr
6116 -static struct cipher_testvec camellia_lrw_dec_tv_template[] = {
6117 +static const struct cipher_testvec camellia_lrw_dec_tv_template[] = {
6118 /* Generated from AES-LRW test vectors */
6119 /* same as enc vectors with input and result reversed */
6121 @@ -30629,7 +30679,7 @@ static struct cipher_testvec camellia_lr
6125 -static struct cipher_testvec camellia_xts_enc_tv_template[] = {
6126 +static const struct cipher_testvec camellia_xts_enc_tv_template[] = {
6127 /* Generated from AES-XTS test vectors */
6129 .key = "\x00\x00\x00\x00\x00\x00\x00\x00"
6130 @@ -30971,7 +31021,7 @@ static struct cipher_testvec camellia_xt
6134 -static struct cipher_testvec camellia_xts_dec_tv_template[] = {
6135 +static const struct cipher_testvec camellia_xts_dec_tv_template[] = {
6136 /* Generated from AES-XTS test vectors */
6137 /* same as enc vectors with input and result reversed */
6139 @@ -31317,10 +31367,7 @@ static struct cipher_testvec camellia_xt
6143 -#define SEED_ENC_TEST_VECTORS 4
6144 -#define SEED_DEC_TEST_VECTORS 4
6146 -static struct cipher_testvec seed_enc_tv_template[] = {
6147 +static const struct cipher_testvec seed_enc_tv_template[] = {
6149 .key = zeroed_string,
6151 @@ -31362,7 +31409,7 @@ static struct cipher_testvec seed_enc_tv
6155 -static struct cipher_testvec seed_dec_tv_template[] = {
6156 +static const struct cipher_testvec seed_dec_tv_template[] = {
6158 .key = zeroed_string,
6160 @@ -31404,8 +31451,7 @@ static struct cipher_testvec seed_dec_tv
6164 -#define SALSA20_STREAM_ENC_TEST_VECTORS 5
6165 -static struct cipher_testvec salsa20_stream_enc_tv_template[] = {
6166 +static const struct cipher_testvec salsa20_stream_enc_tv_template[] = {
6168 * Testvectors from verified.test-vectors submitted to ECRYPT.
6169 * They are truncated to size 39, 64, 111, 129 to test a variety
6170 @@ -32574,8 +32620,7 @@ static struct cipher_testvec salsa20_str
6174 -#define CHACHA20_ENC_TEST_VECTORS 4
6175 -static struct cipher_testvec chacha20_enc_tv_template[] = {
6176 +static const struct cipher_testvec chacha20_enc_tv_template[] = {
6177 { /* RFC7539 A.2. Test Vector #1 */
6178 .key = "\x00\x00\x00\x00\x00\x00\x00\x00"
6179 "\x00\x00\x00\x00\x00\x00\x00\x00"
6180 @@ -33086,9 +33131,7 @@ static struct cipher_testvec chacha20_en
6182 * CTS (Cipher Text Stealing) mode tests
6184 -#define CTS_MODE_ENC_TEST_VECTORS 6
6185 -#define CTS_MODE_DEC_TEST_VECTORS 6
6186 -static struct cipher_testvec cts_mode_enc_tv_template[] = {
6187 +static const struct cipher_testvec cts_mode_enc_tv_template[] = {
6188 { /* from rfc3962 */
6190 .key = "\x63\x68\x69\x63\x6b\x65\x6e\x20"
6191 @@ -33190,7 +33233,7 @@ static struct cipher_testvec cts_mode_en
6195 -static struct cipher_testvec cts_mode_dec_tv_template[] = {
6196 +static const struct cipher_testvec cts_mode_dec_tv_template[] = {
6197 { /* from rfc3962 */
6199 .key = "\x63\x68\x69\x63\x6b\x65\x6e\x20"
6200 @@ -33308,10 +33351,7 @@ struct comp_testvec {
6201 * Params: winbits=-11, Z_DEFAULT_COMPRESSION, MAX_MEM_LEVEL.
6204 -#define DEFLATE_COMP_TEST_VECTORS 2
6205 -#define DEFLATE_DECOMP_TEST_VECTORS 2
6207 -static struct comp_testvec deflate_comp_tv_template[] = {
6208 +static const struct comp_testvec deflate_comp_tv_template[] = {
6212 @@ -33347,7 +33387,7 @@ static struct comp_testvec deflate_comp_
6216 -static struct comp_testvec deflate_decomp_tv_template[] = {
6217 +static const struct comp_testvec deflate_decomp_tv_template[] = {
6221 @@ -33386,10 +33426,7 @@ static struct comp_testvec deflate_decom
6223 * LZO test vectors (null-terminated strings).
6225 -#define LZO_COMP_TEST_VECTORS 2
6226 -#define LZO_DECOMP_TEST_VECTORS 2
6228 -static struct comp_testvec lzo_comp_tv_template[] = {
6229 +static const struct comp_testvec lzo_comp_tv_template[] = {
6233 @@ -33429,7 +33466,7 @@ static struct comp_testvec lzo_comp_tv_t
6237 -static struct comp_testvec lzo_decomp_tv_template[] = {
6238 +static const struct comp_testvec lzo_decomp_tv_template[] = {
6242 @@ -33472,7 +33509,7 @@ static struct comp_testvec lzo_decomp_tv
6244 #define MICHAEL_MIC_TEST_VECTORS 6
6246 -static struct hash_testvec michael_mic_tv_template[] = {
6247 +static const struct hash_testvec michael_mic_tv_template[] = {
6249 .key = "\x00\x00\x00\x00\x00\x00\x00\x00",
6251 @@ -33520,9 +33557,7 @@ static struct hash_testvec michael_mic_t
6253 * CRC32 test vectors
6255 -#define CRC32_TEST_VECTORS 14
6257 -static struct hash_testvec crc32_tv_template[] = {
6258 +static const struct hash_testvec crc32_tv_template[] = {
6260 .key = "\x87\xa9\xcb\xed",
6262 @@ -33954,9 +33989,7 @@ static struct hash_testvec crc32_tv_temp
6264 * CRC32C test vectors
6266 -#define CRC32C_TEST_VECTORS 15
6268 -static struct hash_testvec crc32c_tv_template[] = {
6269 +static const struct hash_testvec crc32c_tv_template[] = {
6272 .digest = "\x00\x00\x00\x00",
6273 @@ -34392,9 +34425,7 @@ static struct hash_testvec crc32c_tv_tem
6275 * Blakcifn CRC test vectors
6277 -#define BFIN_CRC_TEST_VECTORS 6
6279 -static struct hash_testvec bfin_crc_tv_template[] = {
6280 +static const struct hash_testvec bfin_crc_tv_template[] = {
6283 .digest = "\x00\x00\x00\x00",
6284 @@ -34479,9 +34510,6 @@ static struct hash_testvec bfin_crc_tv_t
6288 -#define LZ4_COMP_TEST_VECTORS 1
6289 -#define LZ4_DECOMP_TEST_VECTORS 1
6291 static struct comp_testvec lz4_comp_tv_template[] = {
6294 @@ -34512,9 +34540,6 @@ static struct comp_testvec lz4_decomp_tv
6298 -#define LZ4HC_COMP_TEST_VECTORS 1
6299 -#define LZ4HC_DECOMP_TEST_VECTORS 1
6301 static struct comp_testvec lz4hc_comp_tv_template[] = {
6308 + * Copyright 2013 Freescale Semiconductor, Inc.
6309 + * Copyright 2017 NXP Semiconductor, Inc.
6311 + * This program is free software; you can redistribute it and/or modify it
6312 + * under the terms of the GNU General Public License as published by the Free
6313 + * Software Foundation; either version 2 of the License, or (at your option)
6314 + * any later version.
6318 +#include <crypto/internal/aead.h>
6319 +#include <crypto/internal/hash.h>
6320 +#include <crypto/internal/skcipher.h>
6321 +#include <crypto/authenc.h>
6322 +#include <crypto/null.h>
6323 +#include <crypto/scatterwalk.h>
6324 +#include <linux/err.h>
6325 +#include <linux/init.h>
6326 +#include <linux/module.h>
6327 +#include <linux/rtnetlink.h>
6329 +struct tls_instance_ctx {
6330 + struct crypto_ahash_spawn auth;
6331 + struct crypto_skcipher_spawn enc;
6334 +struct crypto_tls_ctx {
6335 + unsigned int reqoff;
6336 + struct crypto_ahash *auth;
6337 + struct crypto_skcipher *enc;
6338 + struct crypto_skcipher *null;
6341 +struct tls_request_ctx {
6343 + * cryptlen holds the payload length in the case of encryption or
6344 + * payload_len + icv_len + padding_len in case of decryption
6346 + unsigned int cryptlen;
6347 + /* working space for partial results */
6348 + struct scatterlist tmp[2];
6349 + struct scatterlist cipher[2];
6350 + struct scatterlist dst[2];
6355 + struct completion completion;
6359 +static void tls_async_op_done(struct crypto_async_request *req, int err)
6361 + struct async_op *areq = req->data;
6363 + if (err == -EINPROGRESS)
6367 + complete(&areq->completion);
6370 +static int crypto_tls_setkey(struct crypto_aead *tls, const u8 *key,
6371 + unsigned int keylen)
6373 + struct crypto_tls_ctx *ctx = crypto_aead_ctx(tls);
6374 + struct crypto_ahash *auth = ctx->auth;
6375 + struct crypto_skcipher *enc = ctx->enc;
6376 + struct crypto_authenc_keys keys;
6377 + int err = -EINVAL;
6379 + if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
6382 + crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK);
6383 + crypto_ahash_set_flags(auth, crypto_aead_get_flags(tls) &
6384 + CRYPTO_TFM_REQ_MASK);
6385 + err = crypto_ahash_setkey(auth, keys.authkey, keys.authkeylen);
6386 + crypto_aead_set_flags(tls, crypto_ahash_get_flags(auth) &
6387 + CRYPTO_TFM_RES_MASK);
6392 + crypto_skcipher_clear_flags(enc, CRYPTO_TFM_REQ_MASK);
6393 + crypto_skcipher_set_flags(enc, crypto_aead_get_flags(tls) &
6394 + CRYPTO_TFM_REQ_MASK);
6395 + err = crypto_skcipher_setkey(enc, keys.enckey, keys.enckeylen);
6396 + crypto_aead_set_flags(tls, crypto_skcipher_get_flags(enc) &
6397 + CRYPTO_TFM_RES_MASK);
6403 + crypto_aead_set_flags(tls, CRYPTO_TFM_RES_BAD_KEY_LEN);
6408 + * crypto_tls_genicv - Calculate hmac digest for a TLS record
6409 + * @hash: (output) buffer to save the digest into
6410 + * @src: (input) scatterlist with the assoc and payload data
6411 + * @srclen: (input) size of the source buffer (assoclen + cryptlen)
6412 + * @req: (input) aead request
6414 +static int crypto_tls_genicv(u8 *hash, struct scatterlist *src,
6415 + unsigned int srclen, struct aead_request *req)
6417 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
6418 + struct crypto_tls_ctx *ctx = crypto_aead_ctx(tls);
6419 + struct tls_request_ctx *treq_ctx = aead_request_ctx(req);
6420 + struct async_op ahash_op;
6421 + struct ahash_request *ahreq = (void *)(treq_ctx->tail + ctx->reqoff);
6422 + unsigned int flags = CRYPTO_TFM_REQ_MAY_SLEEP;
6423 + int err = -EBADMSG;
6425 + /* Bail out if the request assoc len is 0 */
6426 + if (!req->assoclen)
6429 + init_completion(&ahash_op.completion);
6431 + /* the hash transform to be executed comes from the original request */
6432 + ahash_request_set_tfm(ahreq, ctx->auth);
6433 + /* prepare the hash request with input data and result pointer */
6434 + ahash_request_set_crypt(ahreq, src, hash, srclen);
6435 + /* set the notifier for when the async hash function returns */
6436 + ahash_request_set_callback(ahreq, aead_request_flags(req) & flags,
6437 + tls_async_op_done, &ahash_op);
6439 + /* Calculate the digest on the given data. The result is put in hash */
6440 + err = crypto_ahash_digest(ahreq);
6441 + if (err == -EINPROGRESS) {
6442 + err = wait_for_completion_interruptible(&ahash_op.completion);
6444 + err = ahash_op.err;
6451 + * crypto_tls_gen_padicv - Calculate and pad hmac digest for a TLS record
6452 + * @hash: (output) buffer to save the digest and padding into
6453 + * @phashlen: (output) the size of digest + padding
6454 + * @req: (input) aead request
6456 +static int crypto_tls_gen_padicv(u8 *hash, unsigned int *phashlen,
6457 + struct aead_request *req)
6459 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
6460 + unsigned int hash_size = crypto_aead_authsize(tls);
6461 + unsigned int block_size = crypto_aead_blocksize(tls);
6462 + unsigned int srclen = req->cryptlen + hash_size;
6463 + unsigned int icvlen = req->cryptlen + req->assoclen;
6464 + unsigned int padlen;
6467 + err = crypto_tls_genicv(hash, req->src, icvlen, req);
6471 + /* add padding after digest */
6472 + padlen = block_size - (srclen % block_size);
6473 + memset(hash + hash_size, padlen - 1, padlen);
6475 + *phashlen = hash_size + padlen;
6480 +static int crypto_tls_copy_data(struct aead_request *req,
6481 + struct scatterlist *src,
6482 + struct scatterlist *dst,
6485 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
6486 + struct crypto_tls_ctx *ctx = crypto_aead_ctx(tls);
6487 + SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
6489 + skcipher_request_set_tfm(skreq, ctx->null);
6490 + skcipher_request_set_callback(skreq, aead_request_flags(req),
6492 + skcipher_request_set_crypt(skreq, src, dst, len, NULL);
6494 + return crypto_skcipher_encrypt(skreq);
6497 +static int crypto_tls_encrypt(struct aead_request *req)
6499 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
6500 + struct crypto_tls_ctx *ctx = crypto_aead_ctx(tls);
6501 + struct tls_request_ctx *treq_ctx = aead_request_ctx(req);
6502 + struct skcipher_request *skreq;
6503 + struct scatterlist *cipher = treq_ctx->cipher;
6504 + struct scatterlist *tmp = treq_ctx->tmp;
6505 + struct scatterlist *sg, *src, *dst;
6506 + unsigned int cryptlen, phashlen;
6507 + u8 *hash = treq_ctx->tail;
6511 + * The hash result is saved at the beginning of the tls request ctx
6512 + * and is aligned as required by the hash transform. Enough space was
6513 + * allocated in crypto_tls_init_tfm to accommodate the difference. The
6514 + * requests themselves start later at treq_ctx->tail + ctx->reqoff so
6515 + * the result is not overwritten by the second (cipher) request.
6517 + hash = (u8 *)ALIGN((unsigned long)hash +
6518 + crypto_ahash_alignmask(ctx->auth),
6519 + crypto_ahash_alignmask(ctx->auth) + 1);
6522 + * STEP 1: create ICV together with necessary padding
6524 + err = crypto_tls_gen_padicv(hash, &phashlen, req);
6529 + * STEP 2: Hash and padding are combined with the payload
6530 + * depending on the form it arrives. Scatter tables must have at least
6531 + * one page of data before chaining with another table and can't have
6532 + * an empty data page. The following code addresses these requirements.
6534 + * If the payload is empty, only the hash is encrypted, otherwise the
6535 + * payload scatterlist is merged with the hash. A special merging case
6536 + * is when the payload has only one page of data. In that case the
6537 + * payload page is moved to another scatterlist and prepared there for
6540 + if (req->cryptlen) {
6541 + src = scatterwalk_ffwd(tmp, req->src, req->assoclen);
6543 + sg_init_table(cipher, 2);
6544 + sg_set_buf(cipher + 1, hash, phashlen);
6546 + if (sg_is_last(src)) {
6547 + sg_set_page(cipher, sg_page(src), req->cryptlen,
6551 + unsigned int rem_len = req->cryptlen;
6553 + for (sg = src; rem_len > sg->length; sg = sg_next(sg))
6554 + rem_len -= min(rem_len, sg->length);
6556 + sg_set_page(cipher, sg_page(sg), rem_len, sg->offset);
6557 + sg_chain(sg, 1, cipher);
6560 + sg_init_one(cipher, hash, phashlen);
6565 + * If src != dst copy the associated data from source to destination.
6566 + * In both cases fast-forward passed the associated data in the dest.
6568 + if (req->src != req->dst) {
6569 + err = crypto_tls_copy_data(req, req->src, req->dst,
6574 + dst = scatterwalk_ffwd(treq_ctx->dst, req->dst, req->assoclen);
6577 + * STEP 3: encrypt the frame and return the result
6579 + cryptlen = req->cryptlen + phashlen;
6582 + * The hash and the cipher are applied at different times and their
6583 + * requests can use the same memory space without interference
6585 + skreq = (void *)(treq_ctx->tail + ctx->reqoff);
6586 + skcipher_request_set_tfm(skreq, ctx->enc);
6587 + skcipher_request_set_crypt(skreq, src, dst, cryptlen, req->iv);
6588 + skcipher_request_set_callback(skreq, aead_request_flags(req),
6589 + req->base.complete, req->base.data);
6591 + * Apply the cipher transform. The result will be in req->dst when the
6592 + * asynchronuous call terminates
6594 + err = crypto_skcipher_encrypt(skreq);
6599 +static int crypto_tls_decrypt(struct aead_request *req)
6601 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
6602 + struct crypto_tls_ctx *ctx = crypto_aead_ctx(tls);
6603 + struct tls_request_ctx *treq_ctx = aead_request_ctx(req);
6604 + unsigned int cryptlen = req->cryptlen;
6605 + unsigned int hash_size = crypto_aead_authsize(tls);
6606 + unsigned int block_size = crypto_aead_blocksize(tls);
6607 + struct skcipher_request *skreq = (void *)(treq_ctx->tail + ctx->reqoff);
6608 + struct scatterlist *tmp = treq_ctx->tmp;
6609 + struct scatterlist *src, *dst;
6611 + u8 padding[255]; /* padding can be 0-255 bytes */
6614 + u8 *ihash, *hash = treq_ctx->tail;
6617 + int err = -EINVAL;
6619 + struct async_op ciph_op;
6622 + * Rule out bad packets. The input packet length must be at least one
6623 + * byte more than the hash_size
6625 + if (cryptlen <= hash_size || cryptlen % block_size)
6629 + * Step 1 - Decrypt the source. Fast-forward past the associated data
6630 + * to the encrypted data. The result will be overwritten in place so
6631 + * that the decrypted data will be adjacent to the associated data. The
6632 + * last step (computing the hash) will have it's input data already
6633 + * prepared and ready to be accessed at req->src.
6635 + src = scatterwalk_ffwd(tmp, req->src, req->assoclen);
6638 + init_completion(&ciph_op.completion);
6639 + skcipher_request_set_tfm(skreq, ctx->enc);
6640 + skcipher_request_set_callback(skreq, aead_request_flags(req),
6641 + tls_async_op_done, &ciph_op);
6642 + skcipher_request_set_crypt(skreq, src, dst, cryptlen, req->iv);
6643 + err = crypto_skcipher_decrypt(skreq);
6644 + if (err == -EINPROGRESS) {
6645 + err = wait_for_completion_interruptible(&ciph_op.completion);
6647 + err = ciph_op.err;
6653 + * Step 2 - Verify padding
6654 + * Retrieve the last byte of the payload; this is the padding size.
6657 + scatterwalk_map_and_copy(&pad_size, dst, cryptlen, 1, 0);
6659 + /* RFC recommendation for invalid padding size. */
6660 + if (cryptlen < pad_size + hash_size) {
6662 + paderr = -EBADMSG;
6664 + cryptlen -= pad_size;
6665 + scatterwalk_map_and_copy(padding, dst, cryptlen, pad_size, 0);
6667 + /* Padding content must be equal with pad_size. We verify it all */
6668 + for (i = 0; i < pad_size; i++)
6669 + if (padding[i] != pad_size)
6670 + paderr = -EBADMSG;
6673 + * Step 3 - Verify hash
6674 + * Align the digest result as required by the hash transform. Enough
6675 + * space was allocated in crypto_tls_init_tfm
6677 + hash = (u8 *)ALIGN((unsigned long)hash +
6678 + crypto_ahash_alignmask(ctx->auth),
6679 + crypto_ahash_alignmask(ctx->auth) + 1);
6681 + * Two bytes at the end of the associated data make the length field.
6682 + * It must be updated with the length of the cleartext message before
6683 + * the hash is calculated.
6685 + len_field = sg_virt(req->src) + req->assoclen - 2;
6686 + cryptlen -= hash_size;
6687 + *len_field = htons(cryptlen);
6689 + /* This is the hash from the decrypted packet. Save it for later */
6690 + ihash = hash + hash_size;
6691 + scatterwalk_map_and_copy(ihash, dst, cryptlen, hash_size, 0);
6693 + /* Now compute and compare our ICV with the one from the packet */
6694 + err = crypto_tls_genicv(hash, req->src, cryptlen + req->assoclen, req);
6696 + err = memcmp(hash, ihash, hash_size) ? -EBADMSG : 0;
6698 + if (req->src != req->dst) {
6699 + err = crypto_tls_copy_data(req, req->src, req->dst, cryptlen +
6705 + /* return the first found error */
6710 + aead_request_complete(req, err);
6714 +static int crypto_tls_init_tfm(struct crypto_aead *tfm)
6716 + struct aead_instance *inst = aead_alg_instance(tfm);
6717 + struct tls_instance_ctx *ictx = aead_instance_ctx(inst);
6718 + struct crypto_tls_ctx *ctx = crypto_aead_ctx(tfm);
6719 + struct crypto_ahash *auth;
6720 + struct crypto_skcipher *enc;
6721 + struct crypto_skcipher *null;
6724 + auth = crypto_spawn_ahash(&ictx->auth);
6726 + return PTR_ERR(auth);
6728 + enc = crypto_spawn_skcipher(&ictx->enc);
6729 + err = PTR_ERR(enc);
6731 + goto err_free_ahash;
6733 + null = crypto_get_default_null_skcipher2();
6734 + err = PTR_ERR(null);
6736 + goto err_free_skcipher;
6743 + * Allow enough space for two digests. The two digests will be compared
6744 + * during the decryption phase. One will come from the decrypted packet
6745 + * and the other will be calculated. For encryption, one digest is
6746 + * padded (up to a cipher blocksize) and chained with the payload
6748 + ctx->reqoff = ALIGN(crypto_ahash_digestsize(auth) +
6749 + crypto_ahash_alignmask(auth),
6750 + crypto_ahash_alignmask(auth) + 1) +
6751 + max(crypto_ahash_digestsize(auth),
6752 + crypto_skcipher_blocksize(enc));
6754 + crypto_aead_set_reqsize(tfm,
6755 + sizeof(struct tls_request_ctx) +
6757 + max_t(unsigned int,
6758 + crypto_ahash_reqsize(auth) +
6759 + sizeof(struct ahash_request),
6760 + crypto_skcipher_reqsize(enc) +
6761 + sizeof(struct skcipher_request)));
6766 + crypto_free_skcipher(enc);
6768 + crypto_free_ahash(auth);
6772 +static void crypto_tls_exit_tfm(struct crypto_aead *tfm)
6774 + struct crypto_tls_ctx *ctx = crypto_aead_ctx(tfm);
6776 + crypto_free_ahash(ctx->auth);
6777 + crypto_free_skcipher(ctx->enc);
6778 + crypto_put_default_null_skcipher2();
6781 +static void crypto_tls_free(struct aead_instance *inst)
6783 + struct tls_instance_ctx *ctx = aead_instance_ctx(inst);
6785 + crypto_drop_skcipher(&ctx->enc);
6786 + crypto_drop_ahash(&ctx->auth);
6790 +static int crypto_tls_create(struct crypto_template *tmpl, struct rtattr **tb)
6792 + struct crypto_attr_type *algt;
6793 + struct aead_instance *inst;
6794 + struct hash_alg_common *auth;
6795 + struct crypto_alg *auth_base;
6796 + struct skcipher_alg *enc;
6797 + struct tls_instance_ctx *ctx;
6798 + const char *enc_name;
6801 + algt = crypto_get_attr_type(tb);
6803 + return PTR_ERR(algt);
6805 + if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
6808 + auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
6809 + CRYPTO_ALG_TYPE_AHASH_MASK |
6810 + crypto_requires_sync(algt->type, algt->mask));
6812 + return PTR_ERR(auth);
6814 + auth_base = &auth->base;
6816 + enc_name = crypto_attr_alg_name(tb[2]);
6817 + err = PTR_ERR(enc_name);
6818 + if (IS_ERR(enc_name))
6819 + goto out_put_auth;
6821 + inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
6824 + goto out_put_auth;
6826 + ctx = aead_instance_ctx(inst);
6828 + err = crypto_init_ahash_spawn(&ctx->auth, auth,
6829 + aead_crypto_instance(inst));
6831 + goto err_free_inst;
6833 + crypto_set_skcipher_spawn(&ctx->enc, aead_crypto_instance(inst));
6834 + err = crypto_grab_skcipher(&ctx->enc, enc_name, 0,
6835 + crypto_requires_sync(algt->type,
6838 + goto err_drop_auth;
6840 + enc = crypto_spawn_skcipher_alg(&ctx->enc);
6842 + err = -ENAMETOOLONG;
6843 + if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
6844 + "tls10(%s,%s)", auth_base->cra_name,
6845 + enc->base.cra_name) >= CRYPTO_MAX_ALG_NAME)
6846 + goto err_drop_enc;
6848 + if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
6849 + "tls10(%s,%s)", auth_base->cra_driver_name,
6850 + enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
6851 + goto err_drop_enc;
6853 + inst->alg.base.cra_flags = (auth_base->cra_flags |
6854 + enc->base.cra_flags) & CRYPTO_ALG_ASYNC;
6855 + inst->alg.base.cra_priority = enc->base.cra_priority * 10 +
6856 + auth_base->cra_priority;
6857 + inst->alg.base.cra_blocksize = enc->base.cra_blocksize;
6858 + inst->alg.base.cra_alignmask = auth_base->cra_alignmask |
6859 + enc->base.cra_alignmask;
6860 + inst->alg.base.cra_ctxsize = sizeof(struct crypto_tls_ctx);
6862 + inst->alg.ivsize = crypto_skcipher_alg_ivsize(enc);
6863 + inst->alg.chunksize = crypto_skcipher_alg_chunksize(enc);
6864 + inst->alg.maxauthsize = auth->digestsize;
6866 + inst->alg.init = crypto_tls_init_tfm;
6867 + inst->alg.exit = crypto_tls_exit_tfm;
6869 + inst->alg.setkey = crypto_tls_setkey;
6870 + inst->alg.encrypt = crypto_tls_encrypt;
6871 + inst->alg.decrypt = crypto_tls_decrypt;
6873 + inst->free = crypto_tls_free;
6875 + err = aead_register_instance(tmpl, inst);
6877 + goto err_drop_enc;
6880 + crypto_mod_put(auth_base);
6884 + crypto_drop_skcipher(&ctx->enc);
6886 + crypto_drop_ahash(&ctx->auth);
6893 +static struct crypto_template crypto_tls_tmpl = {
6895 + .create = crypto_tls_create,
6896 + .module = THIS_MODULE,
6899 +static int __init crypto_tls_module_init(void)
6901 + return crypto_register_template(&crypto_tls_tmpl);
6904 +static void __exit crypto_tls_module_exit(void)
6906 + crypto_unregister_template(&crypto_tls_tmpl);
6909 +module_init(crypto_tls_module_init);
6910 +module_exit(crypto_tls_module_exit);
6912 +MODULE_LICENSE("GPL");
6913 +MODULE_DESCRIPTION("TLS 1.0 record encryption");
6914 --- a/drivers/crypto/caam/Kconfig
6915 +++ b/drivers/crypto/caam/Kconfig
6917 +config CRYPTO_DEV_FSL_CAAM_COMMON
6920 config CRYPTO_DEV_FSL_CAAM
6921 - tristate "Freescale CAAM-Multicore driver backend"
6922 + tristate "Freescale CAAM-Multicore platform driver backend"
6923 depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE
6924 + select CRYPTO_DEV_FSL_CAAM_COMMON
6927 Enables the driver module for Freescale's Cryptographic Accelerator
6928 and Assurance Module (CAAM), also known as the SEC version 4 (SEC4).
6929 @@ -11,9 +16,16 @@ config CRYPTO_DEV_FSL_CAAM
6930 To compile this driver as a module, choose M here: the module
6931 will be called caam.
6933 +if CRYPTO_DEV_FSL_CAAM
6935 +config CRYPTO_DEV_FSL_CAAM_DEBUG
6936 + bool "Enable debug output in CAAM driver"
6938 + Selecting this will enable printing of various debug
6939 + information in the CAAM driver.
6941 config CRYPTO_DEV_FSL_CAAM_JR
6942 tristate "Freescale CAAM Job Ring driver backend"
6943 - depends on CRYPTO_DEV_FSL_CAAM
6946 Enables the driver module for Job Rings which are part of
6947 @@ -24,9 +36,10 @@ config CRYPTO_DEV_FSL_CAAM_JR
6948 To compile this driver as a module, choose M here: the module
6949 will be called caam_jr.
6951 +if CRYPTO_DEV_FSL_CAAM_JR
6953 config CRYPTO_DEV_FSL_CAAM_RINGSIZE
6955 - depends on CRYPTO_DEV_FSL_CAAM_JR
6959 @@ -44,7 +57,6 @@ config CRYPTO_DEV_FSL_CAAM_RINGSIZE
6961 config CRYPTO_DEV_FSL_CAAM_INTC
6962 bool "Job Ring interrupt coalescing"
6963 - depends on CRYPTO_DEV_FSL_CAAM_JR
6965 Enable the Job Ring's interrupt coalescing feature.
6967 @@ -74,7 +86,6 @@ config CRYPTO_DEV_FSL_CAAM_INTC_TIME_THL
6969 config CRYPTO_DEV_FSL_CAAM_CRYPTO_API
6970 tristate "Register algorithm implementations with the Crypto API"
6971 - depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
6974 select CRYPTO_AUTHENC
6975 @@ -87,9 +98,25 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API
6976 To compile this as a module, choose M here: the module
6977 will be called caamalg.
6979 +config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI
6980 + tristate "Queue Interface as Crypto API backend"
6981 + depends on FSL_SDK_DPA && NET
6983 + select CRYPTO_AUTHENC
6984 + select CRYPTO_BLKCIPHER
6986 + Selecting this will use CAAM Queue Interface (QI) for sending
6987 + & receiving crypto jobs to/from CAAM. This gives better performance
6988 + than job ring interface when the number of cores are more than the
6989 + number of job rings assigned to the kernel. The number of portals
6990 + assigned to the kernel should also be more than the number of
6993 + To compile this as a module, choose M here: the module
6994 + will be called caamalg_qi.
6996 config CRYPTO_DEV_FSL_CAAM_AHASH_API
6997 tristate "Register hash algorithm implementations with Crypto API"
6998 - depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
7002 @@ -101,7 +128,6 @@ config CRYPTO_DEV_FSL_CAAM_AHASH_API
7004 config CRYPTO_DEV_FSL_CAAM_PKC_API
7005 tristate "Register public key cryptography implementations with Crypto API"
7006 - depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
7010 @@ -113,7 +139,6 @@ config CRYPTO_DEV_FSL_CAAM_PKC_API
7012 config CRYPTO_DEV_FSL_CAAM_RNG_API
7013 tristate "Register caam device for hwrng API"
7014 - depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
7018 @@ -124,13 +149,31 @@ config CRYPTO_DEV_FSL_CAAM_RNG_API
7019 To compile this as a module, choose M here: the module
7020 will be called caamrng.
7022 -config CRYPTO_DEV_FSL_CAAM_IMX
7023 - def_bool SOC_IMX6 || SOC_IMX7D
7024 - depends on CRYPTO_DEV_FSL_CAAM
7025 +endif # CRYPTO_DEV_FSL_CAAM_JR
7027 -config CRYPTO_DEV_FSL_CAAM_DEBUG
7028 - bool "Enable debug output in CAAM driver"
7029 - depends on CRYPTO_DEV_FSL_CAAM
7031 - Selecting this will enable printing of various debug
7032 - information in the CAAM driver.
7033 +endif # CRYPTO_DEV_FSL_CAAM
7035 +config CRYPTO_DEV_FSL_DPAA2_CAAM
7036 + tristate "QorIQ DPAA2 CAAM (DPSECI) driver"
7037 + depends on FSL_MC_DPIO
7038 + select CRYPTO_DEV_FSL_CAAM_COMMON
7039 + select CRYPTO_BLKCIPHER
7040 + select CRYPTO_AUTHENC
7041 + select CRYPTO_AEAD
7042 + select CRYPTO_HASH
7044 + CAAM driver for QorIQ Data Path Acceleration Architecture 2.
7045 + It handles DPSECI DPAA2 objects that sit on the Management Complex
7048 + To compile this as a module, choose M here: the module
7049 + will be called dpaa2_caam.
7051 +config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
7052 + def_tristate (CRYPTO_DEV_FSL_CAAM_CRYPTO_API || \
7053 + CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI || \
7054 + CRYPTO_DEV_FSL_DPAA2_CAAM)
7056 +config CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
7057 + def_tristate (CRYPTO_DEV_FSL_CAAM_AHASH_API || \
7058 + CRYPTO_DEV_FSL_DPAA2_CAAM)
7059 --- a/drivers/crypto/caam/Makefile
7060 +++ b/drivers/crypto/caam/Makefile
7061 @@ -5,13 +5,27 @@ ifeq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG
7062 ccflags-y := -DDEBUG
7065 +ccflags-y += -DVERSION=\"\"
7067 +obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_COMMON) += error.o
7068 obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM) += caam.o
7069 obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_JR) += caam_jr.o
7070 obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
7071 +obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o
7072 +obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC) += caamalg_desc.o
7073 obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
7074 +obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC) += caamhash_desc.o
7075 obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
7076 obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caam_pkc.o
7079 -caam_jr-objs := jr.o key_gen.o error.o
7080 +caam_jr-objs := jr.o key_gen.o
7081 caam_pkc-y := caampkc.o pkc_desc.o
7082 +ifneq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI),)
7083 + ccflags-y += -DCONFIG_CAAM_QI
7087 +obj-$(CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM) += dpaa2_caam.o
7089 +dpaa2_caam-y := caamalg_qi2.o dpseci.o
7090 --- a/drivers/crypto/caam/caamalg.c
7091 +++ b/drivers/crypto/caam/caamalg.c
7093 * caam - Freescale FSL CAAM support for crypto API
7095 * Copyright 2008-2011 Freescale Semiconductor, Inc.
7096 + * Copyright 2016 NXP
7098 * Based on talitos crypto API driver.
7102 #include "sg_sw_sec4.h"
7103 #include "key_gen.h"
7104 +#include "caamalg_desc.h"
7109 #define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \
7110 CTR_RFC3686_NONCE_SIZE + \
7111 SHA512_DIGEST_SIZE * 2)
7112 -/* max IV is max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
7113 -#define CAAM_MAX_IV_LENGTH 16
7115 #define AEAD_DESC_JOB_IO_LEN (DESC_JOB_IO_LEN + CAAM_CMD_SZ * 2)
7116 #define GCM_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
7118 #define AUTHENC_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
7121 -/* length of descriptors text */
7122 -#define DESC_AEAD_BASE (4 * CAAM_CMD_SZ)
7123 -#define DESC_AEAD_ENC_LEN (DESC_AEAD_BASE + 11 * CAAM_CMD_SZ)
7124 -#define DESC_AEAD_DEC_LEN (DESC_AEAD_BASE + 15 * CAAM_CMD_SZ)
7125 -#define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 9 * CAAM_CMD_SZ)
7127 -/* Note: Nonce is counted in enckeylen */
7128 -#define DESC_AEAD_CTR_RFC3686_LEN (4 * CAAM_CMD_SZ)
7130 -#define DESC_AEAD_NULL_BASE (3 * CAAM_CMD_SZ)
7131 -#define DESC_AEAD_NULL_ENC_LEN (DESC_AEAD_NULL_BASE + 11 * CAAM_CMD_SZ)
7132 -#define DESC_AEAD_NULL_DEC_LEN (DESC_AEAD_NULL_BASE + 13 * CAAM_CMD_SZ)
7134 -#define DESC_GCM_BASE (3 * CAAM_CMD_SZ)
7135 -#define DESC_GCM_ENC_LEN (DESC_GCM_BASE + 16 * CAAM_CMD_SZ)
7136 -#define DESC_GCM_DEC_LEN (DESC_GCM_BASE + 12 * CAAM_CMD_SZ)
7138 -#define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ)
7139 -#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
7140 -#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
7142 -#define DESC_RFC4543_BASE (3 * CAAM_CMD_SZ)
7143 -#define DESC_RFC4543_ENC_LEN (DESC_RFC4543_BASE + 11 * CAAM_CMD_SZ)
7144 -#define DESC_RFC4543_DEC_LEN (DESC_RFC4543_BASE + 12 * CAAM_CMD_SZ)
7146 -#define DESC_ABLKCIPHER_BASE (3 * CAAM_CMD_SZ)
7147 -#define DESC_ABLKCIPHER_ENC_LEN (DESC_ABLKCIPHER_BASE + \
7149 -#define DESC_ABLKCIPHER_DEC_LEN (DESC_ABLKCIPHER_BASE + \
7152 #define DESC_MAX_USED_BYTES (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN)
7153 #define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
7155 @@ -112,47 +81,11 @@
7156 #define debug(format, arg...)
7160 -#include <linux/highmem.h>
7162 -static void dbg_dump_sg(const char *level, const char *prefix_str,
7163 - int prefix_type, int rowsize, int groupsize,
7164 - struct scatterlist *sg, size_t tlen, bool ascii,
7167 - struct scatterlist *it;
7172 - for (it = sg; it != NULL && tlen > 0 ; it = sg_next(sg)) {
7174 - * make sure the scatterlist's page
7175 - * has a valid virtual memory mapping
7177 - it_page = kmap_atomic(sg_page(it));
7178 - if (unlikely(!it_page)) {
7179 - printk(KERN_ERR "dbg_dump_sg: kmap failed\n");
7183 - buf = it_page + it->offset;
7184 - len = min_t(size_t, tlen, it->length);
7185 - print_hex_dump(level, prefix_str, prefix_type, rowsize,
7186 - groupsize, buf, len, ascii);
7189 - kunmap_atomic(it_page);
7194 static struct list_head alg_list;
7196 struct caam_alg_entry {
7197 int class1_alg_type;
7198 int class2_alg_type;
7203 @@ -163,302 +96,70 @@ struct caam_aead_alg {
7207 -/* Set DK bit in class 1 operation if shared */
7208 -static inline void append_dec_op1(u32 *desc, u32 type)
7210 - u32 *jump_cmd, *uncond_jump_cmd;
7212 - /* DK bit is valid only for AES */
7213 - if ((type & OP_ALG_ALGSEL_MASK) != OP_ALG_ALGSEL_AES) {
7214 - append_operation(desc, type | OP_ALG_AS_INITFINAL |
7219 - jump_cmd = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD);
7220 - append_operation(desc, type | OP_ALG_AS_INITFINAL |
7222 - uncond_jump_cmd = append_jump(desc, JUMP_TEST_ALL);
7223 - set_jump_tgt_here(desc, jump_cmd);
7224 - append_operation(desc, type | OP_ALG_AS_INITFINAL |
7225 - OP_ALG_DECRYPT | OP_ALG_AAI_DK);
7226 - set_jump_tgt_here(desc, uncond_jump_cmd);
7230 - * For aead functions, read payload and write payload,
7231 - * both of which are specified in req->src and req->dst
7233 -static inline void aead_append_src_dst(u32 *desc, u32 msg_type)
7235 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
7236 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH |
7237 - KEY_VLF | msg_type | FIFOLD_TYPE_LASTBOTH);
7241 - * For ablkcipher encrypt and decrypt, read from req->src and
7242 - * write to req->dst
7244 -static inline void ablkcipher_append_src_dst(u32 *desc)
7246 - append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7247 - append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7248 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 |
7249 - KEY_VLF | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
7250 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
7254 * per-session context
7257 - struct device *jrdev;
7258 u32 sh_desc_enc[DESC_MAX_USED_LEN];
7259 u32 sh_desc_dec[DESC_MAX_USED_LEN];
7260 u32 sh_desc_givenc[DESC_MAX_USED_LEN];
7261 + u8 key[CAAM_MAX_KEY_SIZE];
7262 dma_addr_t sh_desc_enc_dma;
7263 dma_addr_t sh_desc_dec_dma;
7264 dma_addr_t sh_desc_givenc_dma;
7265 - u32 class1_alg_type;
7266 - u32 class2_alg_type;
7268 - u8 key[CAAM_MAX_KEY_SIZE];
7270 - unsigned int enckeylen;
7271 - unsigned int split_key_len;
7272 - unsigned int split_key_pad_len;
7273 + struct device *jrdev;
7274 + struct alginfo adata;
7275 + struct alginfo cdata;
7276 unsigned int authsize;
7279 -static void append_key_aead(u32 *desc, struct caam_ctx *ctx,
7280 - int keys_fit_inline, bool is_rfc3686)
7283 - unsigned int enckeylen = ctx->enckeylen;
7286 - * RFC3686 specific:
7287 - * | ctx->key = {AUTH_KEY, ENC_KEY, NONCE}
7288 - * | enckeylen = encryption key size + nonce size
7291 - enckeylen -= CTR_RFC3686_NONCE_SIZE;
7293 - if (keys_fit_inline) {
7294 - append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
7295 - ctx->split_key_len, CLASS_2 |
7296 - KEY_DEST_MDHA_SPLIT | KEY_ENC);
7297 - append_key_as_imm(desc, (void *)ctx->key +
7298 - ctx->split_key_pad_len, enckeylen,
7299 - enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
7301 - append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
7302 - KEY_DEST_MDHA_SPLIT | KEY_ENC);
7303 - append_key(desc, ctx->key_dma + ctx->split_key_pad_len,
7304 - enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
7307 - /* Load Counter into CONTEXT1 reg */
7309 - nonce = (u32 *)((void *)ctx->key + ctx->split_key_pad_len +
7311 - append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
7312 - LDST_CLASS_IND_CCB |
7313 - LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
7315 - MOVE_SRC_OUTFIFO |
7316 - MOVE_DEST_CLASS1CTX |
7317 - (16 << MOVE_OFFSET_SHIFT) |
7318 - (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
7322 -static void init_sh_desc_key_aead(u32 *desc, struct caam_ctx *ctx,
7323 - int keys_fit_inline, bool is_rfc3686)
7325 - u32 *key_jump_cmd;
7327 - /* Note: Context registers are saved. */
7328 - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
7330 - /* Skip if already shared */
7331 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
7334 - append_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
7336 - set_jump_tgt_here(desc, key_jump_cmd);
7339 static int aead_null_set_sh_desc(struct crypto_aead *aead)
7341 struct caam_ctx *ctx = crypto_aead_ctx(aead);
7342 struct device *jrdev = ctx->jrdev;
7343 - bool keys_fit_inline = false;
7344 - u32 *key_jump_cmd, *jump_cmd, *read_move_cmd, *write_move_cmd;
7345 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
7347 + int rem_bytes = CAAM_DESC_BYTES_MAX - AEAD_DESC_JOB_IO_LEN -
7348 + ctx->adata.keylen_pad;
7351 * Job Descriptor and Shared Descriptors
7352 * must all fit into the 64-word Descriptor h/w Buffer
7354 - if (DESC_AEAD_NULL_ENC_LEN + AEAD_DESC_JOB_IO_LEN +
7355 - ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX)
7356 - keys_fit_inline = true;
7357 + if (rem_bytes >= DESC_AEAD_NULL_ENC_LEN) {
7358 + ctx->adata.key_inline = true;
7359 + ctx->adata.key_virt = ctx->key;
7361 + ctx->adata.key_inline = false;
7362 + ctx->adata.key_dma = ctx->key_dma;
7365 /* aead_encrypt shared descriptor */
7366 desc = ctx->sh_desc_enc;
7368 - init_sh_desc(desc, HDR_SHARE_SERIAL);
7370 - /* Skip if already shared */
7371 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
7373 - if (keys_fit_inline)
7374 - append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
7375 - ctx->split_key_len, CLASS_2 |
7376 - KEY_DEST_MDHA_SPLIT | KEY_ENC);
7378 - append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
7379 - KEY_DEST_MDHA_SPLIT | KEY_ENC);
7380 - set_jump_tgt_here(desc, key_jump_cmd);
7382 - /* assoclen + cryptlen = seqinlen */
7383 - append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
7385 - /* Prepare to read and write cryptlen + assoclen bytes */
7386 - append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
7387 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
7390 - * MOVE_LEN opcode is not available in all SEC HW revisions,
7391 - * thus need to do some magic, i.e. self-patch the descriptor
7394 - read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
7396 - (0x6 << MOVE_LEN_SHIFT));
7397 - write_move_cmd = append_move(desc, MOVE_SRC_MATH3 |
7398 - MOVE_DEST_DESCBUF |
7400 - (0x8 << MOVE_LEN_SHIFT));
7402 - /* Class 2 operation */
7403 - append_operation(desc, ctx->class2_alg_type |
7404 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
7406 - /* Read and write cryptlen bytes */
7407 - aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
7409 - set_move_tgt_here(desc, read_move_cmd);
7410 - set_move_tgt_here(desc, write_move_cmd);
7411 - append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
7412 - append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
7416 - append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
7417 - LDST_SRCDST_BYTE_CONTEXT);
7419 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
7422 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
7423 - dev_err(jrdev, "unable to map shared descriptor\n");
7427 - print_hex_dump(KERN_ERR,
7428 - "aead null enc shdesc@"__stringify(__LINE__)": ",
7429 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
7430 - desc_bytes(desc), 1);
7432 + cnstr_shdsc_aead_null_encap(desc, &ctx->adata, ctx->authsize,
7434 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
7435 + desc_bytes(desc), DMA_TO_DEVICE);
7438 * Job Descriptor and Shared Descriptors
7439 * must all fit into the 64-word Descriptor h/w Buffer
7441 - keys_fit_inline = false;
7442 - if (DESC_AEAD_NULL_DEC_LEN + DESC_JOB_IO_LEN +
7443 - ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX)
7444 - keys_fit_inline = true;
7446 - desc = ctx->sh_desc_dec;
7447 + if (rem_bytes >= DESC_AEAD_NULL_DEC_LEN) {
7448 + ctx->adata.key_inline = true;
7449 + ctx->adata.key_virt = ctx->key;
7451 + ctx->adata.key_inline = false;
7452 + ctx->adata.key_dma = ctx->key_dma;
7455 /* aead_decrypt shared descriptor */
7456 - init_sh_desc(desc, HDR_SHARE_SERIAL);
7458 - /* Skip if already shared */
7459 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
7461 - if (keys_fit_inline)
7462 - append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
7463 - ctx->split_key_len, CLASS_2 |
7464 - KEY_DEST_MDHA_SPLIT | KEY_ENC);
7466 - append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
7467 - KEY_DEST_MDHA_SPLIT | KEY_ENC);
7468 - set_jump_tgt_here(desc, key_jump_cmd);
7470 - /* Class 2 operation */
7471 - append_operation(desc, ctx->class2_alg_type |
7472 - OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
7474 - /* assoclen + cryptlen = seqoutlen */
7475 - append_math_sub(desc, REG2, SEQOUTLEN, REG0, CAAM_CMD_SZ);
7477 - /* Prepare to read and write cryptlen + assoclen bytes */
7478 - append_math_add(desc, VARSEQINLEN, ZERO, REG2, CAAM_CMD_SZ);
7479 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG2, CAAM_CMD_SZ);
7482 - * MOVE_LEN opcode is not available in all SEC HW revisions,
7483 - * thus need to do some magic, i.e. self-patch the descriptor
7486 - read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
7488 - (0x6 << MOVE_LEN_SHIFT));
7489 - write_move_cmd = append_move(desc, MOVE_SRC_MATH2 |
7490 - MOVE_DEST_DESCBUF |
7492 - (0x8 << MOVE_LEN_SHIFT));
7494 - /* Read and write cryptlen bytes */
7495 - aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
7498 - * Insert a NOP here, since we need at least 4 instructions between
7499 - * code patching the descriptor buffer and the location being patched.
7501 - jump_cmd = append_jump(desc, JUMP_TEST_ALL);
7502 - set_jump_tgt_here(desc, jump_cmd);
7504 - set_move_tgt_here(desc, read_move_cmd);
7505 - set_move_tgt_here(desc, write_move_cmd);
7506 - append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
7507 - append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
7509 - append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
7512 - append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 |
7513 - FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
7515 - ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
7518 - if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
7519 - dev_err(jrdev, "unable to map shared descriptor\n");
7523 - print_hex_dump(KERN_ERR,
7524 - "aead null dec shdesc@"__stringify(__LINE__)": ",
7525 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
7526 - desc_bytes(desc), 1);
7528 + desc = ctx->sh_desc_dec;
7529 + cnstr_shdsc_aead_null_decap(desc, &ctx->adata, ctx->authsize,
7531 + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
7532 + desc_bytes(desc), DMA_TO_DEVICE);
7536 @@ -470,11 +171,12 @@ static int aead_set_sh_desc(struct crypt
7537 unsigned int ivsize = crypto_aead_ivsize(aead);
7538 struct caam_ctx *ctx = crypto_aead_ctx(aead);
7539 struct device *jrdev = ctx->jrdev;
7540 - bool keys_fit_inline;
7541 - u32 geniv, moveiv;
7542 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
7543 u32 ctx1_iv_off = 0;
7545 - const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
7546 + u32 *desc, *nonce = NULL;
7548 + unsigned int data_len[2];
7549 + const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
7550 OP_ALG_AAI_CTR_MOD128);
7551 const bool is_rfc3686 = alg->caam.rfc3686;
7553 @@ -482,7 +184,7 @@ static int aead_set_sh_desc(struct crypt
7556 /* NULL encryption / decryption */
7557 - if (!ctx->enckeylen)
7558 + if (!ctx->cdata.keylen)
7559 return aead_null_set_sh_desc(aead);
7562 @@ -497,8 +199,14 @@ static int aead_set_sh_desc(struct crypt
7564 * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
7568 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
7569 + nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
7570 + ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
7573 + data_len[0] = ctx->adata.keylen_pad;
7574 + data_len[1] = ctx->cdata.keylen;
7576 if (alg->caam.geniv)
7578 @@ -507,146 +215,64 @@ static int aead_set_sh_desc(struct crypt
7579 * Job Descriptor and Shared Descriptors
7580 * must all fit into the 64-word Descriptor h/w Buffer
7582 - keys_fit_inline = false;
7583 - if (DESC_AEAD_ENC_LEN + AUTHENC_DESC_JOB_IO_LEN +
7584 - ctx->split_key_pad_len + ctx->enckeylen +
7585 - (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
7586 - CAAM_DESC_BYTES_MAX)
7587 - keys_fit_inline = true;
7589 - /* aead_encrypt shared descriptor */
7590 - desc = ctx->sh_desc_enc;
7592 - /* Note: Context registers are saved. */
7593 - init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
7595 - /* Class 2 operation */
7596 - append_operation(desc, ctx->class2_alg_type |
7597 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
7599 - /* Read and write assoclen bytes */
7600 - append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
7601 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
7602 + if (desc_inline_query(DESC_AEAD_ENC_LEN +
7603 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
7604 + AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
7605 + ARRAY_SIZE(data_len)) < 0)
7608 - /* Skip assoc data */
7609 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
7611 + ctx->adata.key_virt = ctx->key;
7613 + ctx->adata.key_dma = ctx->key_dma;
7615 - /* read assoc before reading payload */
7616 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
7619 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
7621 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
7623 - /* Load Counter into CONTEXT1 reg */
7625 - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
7626 - LDST_SRCDST_BYTE_CONTEXT |
7627 - ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
7628 - LDST_OFFSET_SHIFT));
7630 - /* Class 1 operation */
7631 - append_operation(desc, ctx->class1_alg_type |
7632 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
7634 - /* Read and write cryptlen bytes */
7635 - append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7636 - append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7637 - aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
7640 - append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
7641 - LDST_SRCDST_BYTE_CONTEXT);
7642 + ctx->adata.key_inline = !!(inl_mask & 1);
7643 + ctx->cdata.key_inline = !!(inl_mask & 2);
7645 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
7648 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
7649 - dev_err(jrdev, "unable to map shared descriptor\n");
7653 - print_hex_dump(KERN_ERR, "aead enc shdesc@"__stringify(__LINE__)": ",
7654 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
7655 - desc_bytes(desc), 1);
7657 + /* aead_encrypt shared descriptor */
7658 + desc = ctx->sh_desc_enc;
7659 + cnstr_shdsc_aead_encap(desc, &ctx->cdata, &ctx->adata, ivsize,
7660 + ctx->authsize, is_rfc3686, nonce, ctx1_iv_off,
7661 + false, ctrlpriv->era);
7662 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
7663 + desc_bytes(desc), DMA_TO_DEVICE);
7667 * Job Descriptor and Shared Descriptors
7668 * must all fit into the 64-word Descriptor h/w Buffer
7670 - keys_fit_inline = false;
7671 - if (DESC_AEAD_DEC_LEN + AUTHENC_DESC_JOB_IO_LEN +
7672 - ctx->split_key_pad_len + ctx->enckeylen +
7673 - (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
7674 - CAAM_DESC_BYTES_MAX)
7675 - keys_fit_inline = true;
7677 - /* aead_decrypt shared descriptor */
7678 - desc = ctx->sh_desc_dec;
7680 - /* Note: Context registers are saved. */
7681 - init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
7683 - /* Class 2 operation */
7684 - append_operation(desc, ctx->class2_alg_type |
7685 - OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
7686 + if (desc_inline_query(DESC_AEAD_DEC_LEN +
7687 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
7688 + AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
7689 + ARRAY_SIZE(data_len)) < 0)
7692 - /* Read and write assoclen bytes */
7693 - append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
7694 - if (alg->caam.geniv)
7695 - append_math_add_imm_u32(desc, VARSEQOUTLEN, REG3, IMM, ivsize);
7697 + ctx->adata.key_virt = ctx->key;
7699 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
7701 - /* Skip assoc data */
7702 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
7704 - /* read assoc before reading payload */
7705 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
7708 - if (alg->caam.geniv) {
7709 - append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
7710 - LDST_SRCDST_BYTE_CONTEXT |
7711 - (ctx1_iv_off << LDST_OFFSET_SHIFT));
7712 - append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_CLASS2INFIFO |
7713 - (ctx1_iv_off << MOVE_OFFSET_SHIFT) | ivsize);
7716 - /* Load Counter into CONTEXT1 reg */
7718 - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
7719 - LDST_SRCDST_BYTE_CONTEXT |
7720 - ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
7721 - LDST_OFFSET_SHIFT));
7722 + ctx->adata.key_dma = ctx->key_dma;
7724 - /* Choose operation */
7726 - append_operation(desc, ctx->class1_alg_type |
7727 - OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
7729 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
7731 - append_dec_op1(desc, ctx->class1_alg_type);
7732 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
7734 - /* Read and write cryptlen bytes */
7735 - append_math_add(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
7736 - append_math_add(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
7737 - aead_append_src_dst(desc, FIFOLD_TYPE_MSG);
7740 - append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 |
7741 - FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
7742 + ctx->adata.key_inline = !!(inl_mask & 1);
7743 + ctx->cdata.key_inline = !!(inl_mask & 2);
7745 - ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
7748 - if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
7749 - dev_err(jrdev, "unable to map shared descriptor\n");
7753 - print_hex_dump(KERN_ERR, "aead dec shdesc@"__stringify(__LINE__)": ",
7754 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
7755 - desc_bytes(desc), 1);
7757 + /* aead_decrypt shared descriptor */
7758 + desc = ctx->sh_desc_dec;
7759 + cnstr_shdsc_aead_decap(desc, &ctx->cdata, &ctx->adata, ivsize,
7760 + ctx->authsize, alg->caam.geniv, is_rfc3686,
7761 + nonce, ctx1_iv_off, false, ctrlpriv->era);
7762 + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
7763 + desc_bytes(desc), DMA_TO_DEVICE);
7765 if (!alg->caam.geniv)
7767 @@ -655,107 +281,32 @@ skip_enc:
7768 * Job Descriptor and Shared Descriptors
7769 * must all fit into the 64-word Descriptor h/w Buffer
7771 - keys_fit_inline = false;
7772 - if (DESC_AEAD_GIVENC_LEN + AUTHENC_DESC_JOB_IO_LEN +
7773 - ctx->split_key_pad_len + ctx->enckeylen +
7774 - (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
7775 - CAAM_DESC_BYTES_MAX)
7776 - keys_fit_inline = true;
7778 - /* aead_givencrypt shared descriptor */
7779 - desc = ctx->sh_desc_enc;
7781 - /* Note: Context registers are saved. */
7782 - init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
7783 + if (desc_inline_query(DESC_AEAD_GIVENC_LEN +
7784 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
7785 + AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
7786 + ARRAY_SIZE(data_len)) < 0)
7792 + ctx->adata.key_virt = ctx->key;
7794 + ctx->adata.key_dma = ctx->key_dma;
7797 - geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
7798 - NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
7799 - NFIFOENTRY_PTYPE_RND | (ivsize << NFIFOENTRY_DLEN_SHIFT);
7800 - append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
7801 - LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
7802 - append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
7803 - append_move(desc, MOVE_WAITCOMP |
7804 - MOVE_SRC_INFIFO | MOVE_DEST_CLASS1CTX |
7805 - (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
7806 - (ivsize << MOVE_LEN_SHIFT));
7807 - append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
7810 - /* Copy IV to class 1 context */
7811 - append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_OUTFIFO |
7812 - (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
7813 - (ivsize << MOVE_LEN_SHIFT));
7815 - /* Return to encryption */
7816 - append_operation(desc, ctx->class2_alg_type |
7817 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
7819 - /* Read and write assoclen bytes */
7820 - append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
7821 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
7823 - /* ivsize + cryptlen = seqoutlen - authsize */
7824 - append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize);
7826 - /* Skip assoc data */
7827 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
7829 - /* read assoc before reading payload */
7830 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
7833 - /* Copy iv from outfifo to class 2 fifo */
7834 - moveiv = NFIFOENTRY_STYPE_OFIFO | NFIFOENTRY_DEST_CLASS2 |
7835 - NFIFOENTRY_DTYPE_MSG | (ivsize << NFIFOENTRY_DLEN_SHIFT);
7836 - append_load_imm_u32(desc, moveiv, LDST_CLASS_IND_CCB |
7837 - LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
7838 - append_load_imm_u32(desc, ivsize, LDST_CLASS_2_CCB |
7839 - LDST_SRCDST_WORD_DATASZ_REG | LDST_IMM);
7841 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
7843 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
7845 - /* Load Counter into CONTEXT1 reg */
7847 - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
7848 - LDST_SRCDST_BYTE_CONTEXT |
7849 - ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
7850 - LDST_OFFSET_SHIFT));
7852 - /* Class 1 operation */
7853 - append_operation(desc, ctx->class1_alg_type |
7854 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
7856 - /* Will write ivsize + cryptlen */
7857 - append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7859 - /* Not need to reload iv */
7860 - append_seq_fifo_load(desc, ivsize,
7861 - FIFOLD_CLASS_SKIP);
7863 - /* Will read cryptlen */
7864 - append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7865 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | KEY_VLF |
7866 - FIFOLD_TYPE_MSG1OUT2 | FIFOLD_TYPE_LASTBOTH);
7867 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
7870 - append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
7871 - LDST_SRCDST_BYTE_CONTEXT);
7872 + ctx->adata.key_inline = !!(inl_mask & 1);
7873 + ctx->cdata.key_inline = !!(inl_mask & 2);
7875 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
7878 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
7879 - dev_err(jrdev, "unable to map shared descriptor\n");
7883 - print_hex_dump(KERN_ERR, "aead givenc shdesc@"__stringify(__LINE__)": ",
7884 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
7885 - desc_bytes(desc), 1);
7887 + /* aead_givencrypt shared descriptor */
7888 + desc = ctx->sh_desc_enc;
7889 + cnstr_shdsc_aead_givencap(desc, &ctx->cdata, &ctx->adata, ivsize,
7890 + ctx->authsize, is_rfc3686, nonce,
7891 + ctx1_iv_off, false, ctrlpriv->era);
7892 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
7893 + desc_bytes(desc), DMA_TO_DEVICE);
7897 @@ -776,12 +327,12 @@ static int gcm_set_sh_desc(struct crypto
7899 struct caam_ctx *ctx = crypto_aead_ctx(aead);
7900 struct device *jrdev = ctx->jrdev;
7901 - bool keys_fit_inline = false;
7902 - u32 *key_jump_cmd, *zero_payload_jump_cmd,
7903 - *zero_assoc_jump_cmd1, *zero_assoc_jump_cmd2;
7904 + unsigned int ivsize = crypto_aead_ivsize(aead);
7906 + int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
7907 + ctx->cdata.keylen;
7909 - if (!ctx->enckeylen || !ctx->authsize)
7910 + if (!ctx->cdata.keylen || !ctx->authsize)
7914 @@ -789,175 +340,35 @@ static int gcm_set_sh_desc(struct crypto
7915 * Job Descriptor and Shared Descriptor
7916 * must fit into the 64-word Descriptor h/w Buffer
7918 - if (DESC_GCM_ENC_LEN + GCM_DESC_JOB_IO_LEN +
7919 - ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
7920 - keys_fit_inline = true;
7921 + if (rem_bytes >= DESC_GCM_ENC_LEN) {
7922 + ctx->cdata.key_inline = true;
7923 + ctx->cdata.key_virt = ctx->key;
7925 + ctx->cdata.key_inline = false;
7926 + ctx->cdata.key_dma = ctx->key_dma;
7929 desc = ctx->sh_desc_enc;
7931 - init_sh_desc(desc, HDR_SHARE_SERIAL);
7933 - /* skip key loading if they are loaded due to sharing */
7934 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
7935 - JUMP_COND_SHRD | JUMP_COND_SELF);
7936 - if (keys_fit_inline)
7937 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
7938 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
7940 - append_key(desc, ctx->key_dma, ctx->enckeylen,
7941 - CLASS_1 | KEY_DEST_CLASS_REG);
7942 - set_jump_tgt_here(desc, key_jump_cmd);
7944 - /* class 1 operation */
7945 - append_operation(desc, ctx->class1_alg_type |
7946 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
7948 - /* if assoclen + cryptlen is ZERO, skip to ICV write */
7949 - append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7950 - zero_assoc_jump_cmd2 = append_jump(desc, JUMP_TEST_ALL |
7951 - JUMP_COND_MATH_Z);
7953 - /* if assoclen is ZERO, skip reading the assoc data */
7954 - append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
7955 - zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
7956 - JUMP_COND_MATH_Z);
7958 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
7960 - /* skip assoc data */
7961 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
7963 - /* cryptlen = seqinlen - assoclen */
7964 - append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ);
7966 - /* if cryptlen is ZERO jump to zero-payload commands */
7967 - zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
7968 - JUMP_COND_MATH_Z);
7970 - /* read assoc data */
7971 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
7972 - FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
7973 - set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
7975 - append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
7977 - /* write encrypted data */
7978 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
7980 - /* read payload data */
7981 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
7982 - FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
7984 - /* jump the zero-payload commands */
7985 - append_jump(desc, JUMP_TEST_ALL | 2);
7987 - /* zero-payload commands */
7988 - set_jump_tgt_here(desc, zero_payload_jump_cmd);
7990 - /* read assoc data */
7991 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
7992 - FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1);
7994 - /* There is no input data */
7995 - set_jump_tgt_here(desc, zero_assoc_jump_cmd2);
7998 - append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
7999 - LDST_SRCDST_BYTE_CONTEXT);
8001 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
8004 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
8005 - dev_err(jrdev, "unable to map shared descriptor\n");
8009 - print_hex_dump(KERN_ERR, "gcm enc shdesc@"__stringify(__LINE__)": ",
8010 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8011 - desc_bytes(desc), 1);
8013 + cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ivsize, ctx->authsize, false);
8014 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
8015 + desc_bytes(desc), DMA_TO_DEVICE);
8018 * Job Descriptor and Shared Descriptors
8019 * must all fit into the 64-word Descriptor h/w Buffer
8021 - keys_fit_inline = false;
8022 - if (DESC_GCM_DEC_LEN + GCM_DESC_JOB_IO_LEN +
8023 - ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
8024 - keys_fit_inline = true;
8025 + if (rem_bytes >= DESC_GCM_DEC_LEN) {
8026 + ctx->cdata.key_inline = true;
8027 + ctx->cdata.key_virt = ctx->key;
8029 + ctx->cdata.key_inline = false;
8030 + ctx->cdata.key_dma = ctx->key_dma;
8033 desc = ctx->sh_desc_dec;
8035 - init_sh_desc(desc, HDR_SHARE_SERIAL);
8037 - /* skip key loading if they are loaded due to sharing */
8038 - key_jump_cmd = append_jump(desc, JUMP_JSL |
8039 - JUMP_TEST_ALL | JUMP_COND_SHRD |
8041 - if (keys_fit_inline)
8042 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8043 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
8045 - append_key(desc, ctx->key_dma, ctx->enckeylen,
8046 - CLASS_1 | KEY_DEST_CLASS_REG);
8047 - set_jump_tgt_here(desc, key_jump_cmd);
8049 - /* class 1 operation */
8050 - append_operation(desc, ctx->class1_alg_type |
8051 - OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
8053 - /* if assoclen is ZERO, skip reading the assoc data */
8054 - append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
8055 - zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
8056 - JUMP_COND_MATH_Z);
8058 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
8060 - /* skip assoc data */
8061 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
8063 - /* read assoc data */
8064 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
8065 - FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
8067 - set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
8069 - /* cryptlen = seqoutlen - assoclen */
8070 - append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
8072 - /* jump to zero-payload command if cryptlen is zero */
8073 - zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
8074 - JUMP_COND_MATH_Z);
8076 - append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
8078 - /* store encrypted data */
8079 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
8081 - /* read payload data */
8082 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
8083 - FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
8085 - /* zero-payload command */
8086 - set_jump_tgt_here(desc, zero_payload_jump_cmd);
8089 - append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
8090 - FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
8092 - ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
8095 - if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
8096 - dev_err(jrdev, "unable to map shared descriptor\n");
8100 - print_hex_dump(KERN_ERR, "gcm dec shdesc@"__stringify(__LINE__)": ",
8101 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8102 - desc_bytes(desc), 1);
8104 + cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ivsize, ctx->authsize, false);
8105 + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
8106 + desc_bytes(desc), DMA_TO_DEVICE);
8110 @@ -976,11 +387,12 @@ static int rfc4106_set_sh_desc(struct cr
8112 struct caam_ctx *ctx = crypto_aead_ctx(aead);
8113 struct device *jrdev = ctx->jrdev;
8114 - bool keys_fit_inline = false;
8115 - u32 *key_jump_cmd;
8116 + unsigned int ivsize = crypto_aead_ivsize(aead);
8118 + int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
8119 + ctx->cdata.keylen;
8121 - if (!ctx->enckeylen || !ctx->authsize)
8122 + if (!ctx->cdata.keylen || !ctx->authsize)
8126 @@ -988,148 +400,37 @@ static int rfc4106_set_sh_desc(struct cr
8127 * Job Descriptor and Shared Descriptor
8128 * must fit into the 64-word Descriptor h/w Buffer
8130 - if (DESC_RFC4106_ENC_LEN + GCM_DESC_JOB_IO_LEN +
8131 - ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
8132 - keys_fit_inline = true;
8133 + if (rem_bytes >= DESC_RFC4106_ENC_LEN) {
8134 + ctx->cdata.key_inline = true;
8135 + ctx->cdata.key_virt = ctx->key;
8137 + ctx->cdata.key_inline = false;
8138 + ctx->cdata.key_dma = ctx->key_dma;
8141 desc = ctx->sh_desc_enc;
8143 - init_sh_desc(desc, HDR_SHARE_SERIAL);
8145 - /* Skip key loading if it is loaded due to sharing */
8146 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
8148 - if (keys_fit_inline)
8149 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8150 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
8152 - append_key(desc, ctx->key_dma, ctx->enckeylen,
8153 - CLASS_1 | KEY_DEST_CLASS_REG);
8154 - set_jump_tgt_here(desc, key_jump_cmd);
8156 - /* Class 1 operation */
8157 - append_operation(desc, ctx->class1_alg_type |
8158 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
8160 - append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
8161 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
8163 - /* Read assoc data */
8164 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
8165 - FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
8168 - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
8170 - /* Will read cryptlen bytes */
8171 - append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
8173 - /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
8174 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
8176 - /* Skip assoc data */
8177 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
8179 - /* cryptlen = seqoutlen - assoclen */
8180 - append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ);
8182 - /* Write encrypted data */
8183 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
8185 - /* Read payload data */
8186 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
8187 - FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
8190 - append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
8191 - LDST_SRCDST_BYTE_CONTEXT);
8193 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
8196 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
8197 - dev_err(jrdev, "unable to map shared descriptor\n");
8201 - print_hex_dump(KERN_ERR, "rfc4106 enc shdesc@"__stringify(__LINE__)": ",
8202 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8203 - desc_bytes(desc), 1);
8205 + cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
8207 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
8208 + desc_bytes(desc), DMA_TO_DEVICE);
8211 * Job Descriptor and Shared Descriptors
8212 * must all fit into the 64-word Descriptor h/w Buffer
8214 - keys_fit_inline = false;
8215 - if (DESC_RFC4106_DEC_LEN + DESC_JOB_IO_LEN +
8216 - ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
8217 - keys_fit_inline = true;
8218 + if (rem_bytes >= DESC_RFC4106_DEC_LEN) {
8219 + ctx->cdata.key_inline = true;
8220 + ctx->cdata.key_virt = ctx->key;
8222 + ctx->cdata.key_inline = false;
8223 + ctx->cdata.key_dma = ctx->key_dma;
8226 desc = ctx->sh_desc_dec;
8228 - init_sh_desc(desc, HDR_SHARE_SERIAL);
8230 - /* Skip key loading if it is loaded due to sharing */
8231 - key_jump_cmd = append_jump(desc, JUMP_JSL |
8232 - JUMP_TEST_ALL | JUMP_COND_SHRD);
8233 - if (keys_fit_inline)
8234 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8235 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
8237 - append_key(desc, ctx->key_dma, ctx->enckeylen,
8238 - CLASS_1 | KEY_DEST_CLASS_REG);
8239 - set_jump_tgt_here(desc, key_jump_cmd);
8241 - /* Class 1 operation */
8242 - append_operation(desc, ctx->class1_alg_type |
8243 - OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
8245 - append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
8246 - append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
8248 - /* Read assoc data */
8249 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
8250 - FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
8253 - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
8255 - /* Will read cryptlen bytes */
8256 - append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ);
8258 - /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
8259 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
8261 - /* Skip assoc data */
8262 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
8264 - /* Will write cryptlen bytes */
8265 - append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
8267 - /* Store payload data */
8268 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
8270 - /* Read encrypted data */
8271 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
8272 - FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
8275 - append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
8276 - FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
8278 - ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
8281 - if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
8282 - dev_err(jrdev, "unable to map shared descriptor\n");
8286 - print_hex_dump(KERN_ERR, "rfc4106 dec shdesc@"__stringify(__LINE__)": ",
8287 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8288 - desc_bytes(desc), 1);
8290 + cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
8292 + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
8293 + desc_bytes(desc), DMA_TO_DEVICE);
8297 @@ -1149,12 +450,12 @@ static int rfc4543_set_sh_desc(struct cr
8299 struct caam_ctx *ctx = crypto_aead_ctx(aead);
8300 struct device *jrdev = ctx->jrdev;
8301 - bool keys_fit_inline = false;
8302 - u32 *key_jump_cmd;
8303 - u32 *read_move_cmd, *write_move_cmd;
8304 + unsigned int ivsize = crypto_aead_ivsize(aead);
8306 + int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
8307 + ctx->cdata.keylen;
8309 - if (!ctx->enckeylen || !ctx->authsize)
8310 + if (!ctx->cdata.keylen || !ctx->authsize)
8314 @@ -1162,151 +463,37 @@ static int rfc4543_set_sh_desc(struct cr
8315 * Job Descriptor and Shared Descriptor
8316 * must fit into the 64-word Descriptor h/w Buffer
8318 - if (DESC_RFC4543_ENC_LEN + GCM_DESC_JOB_IO_LEN +
8319 - ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
8320 - keys_fit_inline = true;
8321 + if (rem_bytes >= DESC_RFC4543_ENC_LEN) {
8322 + ctx->cdata.key_inline = true;
8323 + ctx->cdata.key_virt = ctx->key;
8325 + ctx->cdata.key_inline = false;
8326 + ctx->cdata.key_dma = ctx->key_dma;
8329 desc = ctx->sh_desc_enc;
8331 - init_sh_desc(desc, HDR_SHARE_SERIAL);
8333 - /* Skip key loading if it is loaded due to sharing */
8334 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
8336 - if (keys_fit_inline)
8337 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8338 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
8340 - append_key(desc, ctx->key_dma, ctx->enckeylen,
8341 - CLASS_1 | KEY_DEST_CLASS_REG);
8342 - set_jump_tgt_here(desc, key_jump_cmd);
8344 - /* Class 1 operation */
8345 - append_operation(desc, ctx->class1_alg_type |
8346 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
8348 - /* assoclen + cryptlen = seqinlen */
8349 - append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
8352 - * MOVE_LEN opcode is not available in all SEC HW revisions,
8353 - * thus need to do some magic, i.e. self-patch the descriptor
8356 - read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
8357 - (0x6 << MOVE_LEN_SHIFT));
8358 - write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
8359 - (0x8 << MOVE_LEN_SHIFT));
8361 - /* Will read assoclen + cryptlen bytes */
8362 - append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
8364 - /* Will write assoclen + cryptlen bytes */
8365 - append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
8367 - /* Read and write assoclen + cryptlen bytes */
8368 - aead_append_src_dst(desc, FIFOLD_TYPE_AAD);
8370 - set_move_tgt_here(desc, read_move_cmd);
8371 - set_move_tgt_here(desc, write_move_cmd);
8372 - append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
8373 - /* Move payload data to OFIFO */
8374 - append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
8377 - append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
8378 - LDST_SRCDST_BYTE_CONTEXT);
8380 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
8383 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
8384 - dev_err(jrdev, "unable to map shared descriptor\n");
8388 - print_hex_dump(KERN_ERR, "rfc4543 enc shdesc@"__stringify(__LINE__)": ",
8389 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8390 - desc_bytes(desc), 1);
8392 + cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
8394 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
8395 + desc_bytes(desc), DMA_TO_DEVICE);
8398 * Job Descriptor and Shared Descriptors
8399 * must all fit into the 64-word Descriptor h/w Buffer
8401 - keys_fit_inline = false;
8402 - if (DESC_RFC4543_DEC_LEN + GCM_DESC_JOB_IO_LEN +
8403 - ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
8404 - keys_fit_inline = true;
8405 + if (rem_bytes >= DESC_RFC4543_DEC_LEN) {
8406 + ctx->cdata.key_inline = true;
8407 + ctx->cdata.key_virt = ctx->key;
8409 + ctx->cdata.key_inline = false;
8410 + ctx->cdata.key_dma = ctx->key_dma;
8413 desc = ctx->sh_desc_dec;
8415 - init_sh_desc(desc, HDR_SHARE_SERIAL);
8417 - /* Skip key loading if it is loaded due to sharing */
8418 - key_jump_cmd = append_jump(desc, JUMP_JSL |
8419 - JUMP_TEST_ALL | JUMP_COND_SHRD);
8420 - if (keys_fit_inline)
8421 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8422 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
8424 - append_key(desc, ctx->key_dma, ctx->enckeylen,
8425 - CLASS_1 | KEY_DEST_CLASS_REG);
8426 - set_jump_tgt_here(desc, key_jump_cmd);
8428 - /* Class 1 operation */
8429 - append_operation(desc, ctx->class1_alg_type |
8430 - OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
8432 - /* assoclen + cryptlen = seqoutlen */
8433 - append_math_sub(desc, REG3, SEQOUTLEN, REG0, CAAM_CMD_SZ);
8436 - * MOVE_LEN opcode is not available in all SEC HW revisions,
8437 - * thus need to do some magic, i.e. self-patch the descriptor
8440 - read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
8441 - (0x6 << MOVE_LEN_SHIFT));
8442 - write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
8443 - (0x8 << MOVE_LEN_SHIFT));
8445 - /* Will read assoclen + cryptlen bytes */
8446 - append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
8448 - /* Will write assoclen + cryptlen bytes */
8449 - append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
8451 - /* Store payload data */
8452 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
8454 - /* In-snoop assoclen + cryptlen data */
8455 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | FIFOLDST_VLF |
8456 - FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST2FLUSH1);
8458 - set_move_tgt_here(desc, read_move_cmd);
8459 - set_move_tgt_here(desc, write_move_cmd);
8460 - append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
8461 - /* Move payload data to OFIFO */
8462 - append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
8463 - append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
8466 - append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
8467 - FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
8469 - ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
8472 - if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
8473 - dev_err(jrdev, "unable to map shared descriptor\n");
8477 - print_hex_dump(KERN_ERR, "rfc4543 dec shdesc@"__stringify(__LINE__)": ",
8478 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8479 - desc_bytes(desc), 1);
8481 + cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
8483 + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
8484 + desc_bytes(desc), DMA_TO_DEVICE);
8488 @@ -1322,74 +509,67 @@ static int rfc4543_setauthsize(struct cr
8492 -static u32 gen_split_aead_key(struct caam_ctx *ctx, const u8 *key_in,
8495 - return gen_split_key(ctx->jrdev, ctx->key, ctx->split_key_len,
8496 - ctx->split_key_pad_len, key_in, authkeylen,
8500 static int aead_setkey(struct crypto_aead *aead,
8501 const u8 *key, unsigned int keylen)
8503 - /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */
8504 - static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 };
8505 struct caam_ctx *ctx = crypto_aead_ctx(aead);
8506 struct device *jrdev = ctx->jrdev;
8507 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
8508 struct crypto_authenc_keys keys;
8511 if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
8514 - /* Pick class 2 key length from algorithm submask */
8515 - ctx->split_key_len = mdpadlen[(ctx->alg_op & OP_ALG_ALGSEL_SUBMASK) >>
8516 - OP_ALG_ALGSEL_SHIFT] * 2;
8517 - ctx->split_key_pad_len = ALIGN(ctx->split_key_len, 16);
8519 - if (ctx->split_key_pad_len + keys.enckeylen > CAAM_MAX_KEY_SIZE)
8523 printk(KERN_ERR "keylen %d enckeylen %d authkeylen %d\n",
8524 keys.authkeylen + keys.enckeylen, keys.enckeylen,
8526 - printk(KERN_ERR "split_key_len %d split_key_pad_len %d\n",
8527 - ctx->split_key_len, ctx->split_key_pad_len);
8528 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
8529 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
8532 - ret = gen_split_aead_key(ctx, keys.authkey, keys.authkeylen);
8534 + * If DKP is supported, use it in the shared descriptor to generate
8537 + if (ctrlpriv->era >= 6) {
8538 + ctx->adata.keylen = keys.authkeylen;
8539 + ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
8540 + OP_ALG_ALGSEL_MASK);
8542 + if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE)
8545 + memcpy(ctx->key, keys.authkey, keys.authkeylen);
8546 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey,
8548 + dma_sync_single_for_device(jrdev, ctx->key_dma,
8549 + ctx->adata.keylen_pad +
8550 + keys.enckeylen, DMA_TO_DEVICE);
8551 + goto skip_split_key;
8554 + ret = gen_split_key(ctx->jrdev, ctx->key, &ctx->adata, keys.authkey,
8555 + keys.authkeylen, CAAM_MAX_KEY_SIZE -
8561 /* postpend encryption key to auth split key */
8562 - memcpy(ctx->key + ctx->split_key_pad_len, keys.enckey, keys.enckeylen);
8564 - ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len +
8565 - keys.enckeylen, DMA_TO_DEVICE);
8566 - if (dma_mapping_error(jrdev, ctx->key_dma)) {
8567 - dev_err(jrdev, "unable to map key i/o memory\n");
8570 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
8571 + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
8572 + keys.enckeylen, DMA_TO_DEVICE);
8574 print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
8575 DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
8576 - ctx->split_key_pad_len + keys.enckeylen, 1);
8577 + ctx->adata.keylen_pad + keys.enckeylen, 1);
8580 - ctx->enckeylen = keys.enckeylen;
8582 - ret = aead_set_sh_desc(aead);
8584 - dma_unmap_single(jrdev, ctx->key_dma, ctx->split_key_pad_len +
8585 - keys.enckeylen, DMA_TO_DEVICE);
8590 + ctx->cdata.keylen = keys.enckeylen;
8591 + return aead_set_sh_desc(aead);
8593 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
8595 @@ -1400,7 +580,6 @@ static int gcm_setkey(struct crypto_aead
8597 struct caam_ctx *ctx = crypto_aead_ctx(aead);
8598 struct device *jrdev = ctx->jrdev;
8602 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
8603 @@ -1408,21 +587,10 @@ static int gcm_setkey(struct crypto_aead
8606 memcpy(ctx->key, key, keylen);
8607 - ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen,
8609 - if (dma_mapping_error(jrdev, ctx->key_dma)) {
8610 - dev_err(jrdev, "unable to map key i/o memory\n");
8613 - ctx->enckeylen = keylen;
8614 + dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
8615 + ctx->cdata.keylen = keylen;
8617 - ret = gcm_set_sh_desc(aead);
8619 - dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
8624 + return gcm_set_sh_desc(aead);
8627 static int rfc4106_setkey(struct crypto_aead *aead,
8628 @@ -1430,7 +598,6 @@ static int rfc4106_setkey(struct crypto_
8630 struct caam_ctx *ctx = crypto_aead_ctx(aead);
8631 struct device *jrdev = ctx->jrdev;
8636 @@ -1446,22 +613,10 @@ static int rfc4106_setkey(struct crypto_
8637 * The last four bytes of the key material are used as the salt value
8638 * in the nonce. Update the AES key length.
8640 - ctx->enckeylen = keylen - 4;
8642 - ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->enckeylen,
8644 - if (dma_mapping_error(jrdev, ctx->key_dma)) {
8645 - dev_err(jrdev, "unable to map key i/o memory\n");
8649 - ret = rfc4106_set_sh_desc(aead);
8651 - dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
8656 + ctx->cdata.keylen = keylen - 4;
8657 + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
8659 + return rfc4106_set_sh_desc(aead);
8662 static int rfc4543_setkey(struct crypto_aead *aead,
8663 @@ -1469,7 +624,6 @@ static int rfc4543_setkey(struct crypto_
8665 struct caam_ctx *ctx = crypto_aead_ctx(aead);
8666 struct device *jrdev = ctx->jrdev;
8671 @@ -1485,43 +639,28 @@ static int rfc4543_setkey(struct crypto_
8672 * The last four bytes of the key material are used as the salt value
8673 * in the nonce. Update the AES key length.
8675 - ctx->enckeylen = keylen - 4;
8677 - ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->enckeylen,
8679 - if (dma_mapping_error(jrdev, ctx->key_dma)) {
8680 - dev_err(jrdev, "unable to map key i/o memory\n");
8684 - ret = rfc4543_set_sh_desc(aead);
8686 - dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
8691 + ctx->cdata.keylen = keylen - 4;
8692 + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
8694 + return rfc4543_set_sh_desc(aead);
8697 static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
8698 const u8 *key, unsigned int keylen)
8700 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
8701 - struct ablkcipher_tfm *crt = &ablkcipher->base.crt_ablkcipher;
8702 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher);
8703 const char *alg_name = crypto_tfm_alg_name(tfm);
8704 struct device *jrdev = ctx->jrdev;
8706 - u32 *key_jump_cmd;
8707 + unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
8711 u32 ctx1_iv_off = 0;
8712 - const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
8713 + const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
8714 OP_ALG_AAI_CTR_MOD128);
8715 const bool is_rfc3686 = (ctr_mode &&
8716 (strstr(alg_name, "rfc3686") != NULL));
8718 + memcpy(ctx->key, key, keylen);
8720 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
8721 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
8722 @@ -1544,215 +683,33 @@ static int ablkcipher_setkey(struct cryp
8723 keylen -= CTR_RFC3686_NONCE_SIZE;
8726 - memcpy(ctx->key, key, keylen);
8727 - ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen,
8729 - if (dma_mapping_error(jrdev, ctx->key_dma)) {
8730 - dev_err(jrdev, "unable to map key i/o memory\n");
8733 - ctx->enckeylen = keylen;
8734 + dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
8735 + ctx->cdata.keylen = keylen;
8736 + ctx->cdata.key_virt = ctx->key;
8737 + ctx->cdata.key_inline = true;
8739 /* ablkcipher_encrypt shared descriptor */
8740 desc = ctx->sh_desc_enc;
8741 - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
8742 - /* Skip if already shared */
8743 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
8746 - /* Load class1 key only */
8747 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8748 - ctx->enckeylen, CLASS_1 |
8749 - KEY_DEST_CLASS_REG);
8751 - /* Load nonce into CONTEXT1 reg */
8753 - nonce = (u8 *)key + keylen;
8754 - append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
8755 - LDST_CLASS_IND_CCB |
8756 - LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
8757 - append_move(desc, MOVE_WAITCOMP |
8758 - MOVE_SRC_OUTFIFO |
8759 - MOVE_DEST_CLASS1CTX |
8760 - (16 << MOVE_OFFSET_SHIFT) |
8761 - (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
8764 - set_jump_tgt_here(desc, key_jump_cmd);
8767 - append_seq_load(desc, crt->ivsize, LDST_SRCDST_BYTE_CONTEXT |
8768 - LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
8769 + cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686,
8771 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
8772 + desc_bytes(desc), DMA_TO_DEVICE);
8774 - /* Load counter into CONTEXT1 reg */
8776 - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
8777 - LDST_SRCDST_BYTE_CONTEXT |
8778 - ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
8779 - LDST_OFFSET_SHIFT));
8781 - /* Load operation */
8782 - append_operation(desc, ctx->class1_alg_type |
8783 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
8785 - /* Perform operation */
8786 - ablkcipher_append_src_dst(desc);
8788 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
8791 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
8792 - dev_err(jrdev, "unable to map shared descriptor\n");
8796 - print_hex_dump(KERN_ERR,
8797 - "ablkcipher enc shdesc@"__stringify(__LINE__)": ",
8798 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8799 - desc_bytes(desc), 1);
8801 /* ablkcipher_decrypt shared descriptor */
8802 desc = ctx->sh_desc_dec;
8803 + cnstr_shdsc_ablkcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686,
8805 + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
8806 + desc_bytes(desc), DMA_TO_DEVICE);
8808 - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
8809 - /* Skip if already shared */
8810 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
8813 - /* Load class1 key only */
8814 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8815 - ctx->enckeylen, CLASS_1 |
8816 - KEY_DEST_CLASS_REG);
8818 - /* Load nonce into CONTEXT1 reg */
8820 - nonce = (u8 *)key + keylen;
8821 - append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
8822 - LDST_CLASS_IND_CCB |
8823 - LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
8824 - append_move(desc, MOVE_WAITCOMP |
8825 - MOVE_SRC_OUTFIFO |
8826 - MOVE_DEST_CLASS1CTX |
8827 - (16 << MOVE_OFFSET_SHIFT) |
8828 - (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
8831 - set_jump_tgt_here(desc, key_jump_cmd);
8834 - append_seq_load(desc, crt->ivsize, LDST_SRCDST_BYTE_CONTEXT |
8835 - LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
8837 - /* Load counter into CONTEXT1 reg */
8839 - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
8840 - LDST_SRCDST_BYTE_CONTEXT |
8841 - ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
8842 - LDST_OFFSET_SHIFT));
8844 - /* Choose operation */
8846 - append_operation(desc, ctx->class1_alg_type |
8847 - OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
8849 - append_dec_op1(desc, ctx->class1_alg_type);
8851 - /* Perform operation */
8852 - ablkcipher_append_src_dst(desc);
8854 - ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
8857 - if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
8858 - dev_err(jrdev, "unable to map shared descriptor\n");
8863 - print_hex_dump(KERN_ERR,
8864 - "ablkcipher dec shdesc@"__stringify(__LINE__)": ",
8865 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8866 - desc_bytes(desc), 1);
8868 /* ablkcipher_givencrypt shared descriptor */
8869 desc = ctx->sh_desc_givenc;
8870 + cnstr_shdsc_ablkcipher_givencap(desc, &ctx->cdata, ivsize, is_rfc3686,
8872 + dma_sync_single_for_device(jrdev, ctx->sh_desc_givenc_dma,
8873 + desc_bytes(desc), DMA_TO_DEVICE);
8875 - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
8876 - /* Skip if already shared */
8877 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
8880 - /* Load class1 key only */
8881 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8882 - ctx->enckeylen, CLASS_1 |
8883 - KEY_DEST_CLASS_REG);
8885 - /* Load Nonce into CONTEXT1 reg */
8887 - nonce = (u8 *)key + keylen;
8888 - append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
8889 - LDST_CLASS_IND_CCB |
8890 - LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
8891 - append_move(desc, MOVE_WAITCOMP |
8892 - MOVE_SRC_OUTFIFO |
8893 - MOVE_DEST_CLASS1CTX |
8894 - (16 << MOVE_OFFSET_SHIFT) |
8895 - (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
8897 - set_jump_tgt_here(desc, key_jump_cmd);
8900 - geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
8901 - NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
8902 - NFIFOENTRY_PTYPE_RND | (crt->ivsize << NFIFOENTRY_DLEN_SHIFT);
8903 - append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
8904 - LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
8905 - append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
8906 - append_move(desc, MOVE_WAITCOMP |
8908 - MOVE_DEST_CLASS1CTX |
8909 - (crt->ivsize << MOVE_LEN_SHIFT) |
8910 - (ctx1_iv_off << MOVE_OFFSET_SHIFT));
8911 - append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
8913 - /* Copy generated IV to memory */
8914 - append_seq_store(desc, crt->ivsize,
8915 - LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
8916 - (ctx1_iv_off << LDST_OFFSET_SHIFT));
8918 - /* Load Counter into CONTEXT1 reg */
8920 - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
8921 - LDST_SRCDST_BYTE_CONTEXT |
8922 - ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
8923 - LDST_OFFSET_SHIFT));
8926 - append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NCP |
8927 - (1 << JUMP_OFFSET_SHIFT));
8929 - /* Load operation */
8930 - append_operation(desc, ctx->class1_alg_type |
8931 - OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
8933 - /* Perform operation */
8934 - ablkcipher_append_src_dst(desc);
8936 - ctx->sh_desc_givenc_dma = dma_map_single(jrdev, desc,
8939 - if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) {
8940 - dev_err(jrdev, "unable to map shared descriptor\n");
8944 - print_hex_dump(KERN_ERR,
8945 - "ablkcipher givenc shdesc@" __stringify(__LINE__) ": ",
8946 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
8947 - desc_bytes(desc), 1);
8954 static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
8955 @@ -1760,8 +717,7 @@ static int xts_ablkcipher_setkey(struct
8957 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
8958 struct device *jrdev = ctx->jrdev;
8959 - u32 *key_jump_cmd, *desc;
8960 - __be64 sector_size = cpu_to_be64(512);
8963 if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
8964 crypto_ablkcipher_set_flags(ablkcipher,
8965 @@ -1771,126 +727,38 @@ static int xts_ablkcipher_setkey(struct
8968 memcpy(ctx->key, key, keylen);
8969 - ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen, DMA_TO_DEVICE);
8970 - if (dma_mapping_error(jrdev, ctx->key_dma)) {
8971 - dev_err(jrdev, "unable to map key i/o memory\n");
8974 - ctx->enckeylen = keylen;
8975 + dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
8976 + ctx->cdata.keylen = keylen;
8977 + ctx->cdata.key_virt = ctx->key;
8978 + ctx->cdata.key_inline = true;
8980 /* xts_ablkcipher_encrypt shared descriptor */
8981 desc = ctx->sh_desc_enc;
8982 - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
8983 - /* Skip if already shared */
8984 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
8987 - /* Load class1 keys only */
8988 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
8989 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
8991 - /* Load sector size with index 40 bytes (0x28) */
8992 - append_cmd(desc, CMD_LOAD | IMMEDIATE | LDST_SRCDST_BYTE_CONTEXT |
8993 - LDST_CLASS_1_CCB | (0x28 << LDST_OFFSET_SHIFT) | 8);
8994 - append_data(desc, (void *)§or_size, 8);
8996 - set_jump_tgt_here(desc, key_jump_cmd);
8999 - * create sequence for loading the sector index
9000 - * Upper 8B of IV - will be used as sector index
9001 - * Lower 8B of IV - will be discarded
9003 - append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
9004 - LDST_CLASS_1_CCB | (0x20 << LDST_OFFSET_SHIFT) | 8);
9005 - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
9007 - /* Load operation */
9008 - append_operation(desc, ctx->class1_alg_type | OP_ALG_AS_INITFINAL |
9011 - /* Perform operation */
9012 - ablkcipher_append_src_dst(desc);
9014 - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc, desc_bytes(desc),
9016 - if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
9017 - dev_err(jrdev, "unable to map shared descriptor\n");
9021 - print_hex_dump(KERN_ERR,
9022 - "xts ablkcipher enc shdesc@" __stringify(__LINE__) ": ",
9023 - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
9025 + cnstr_shdsc_xts_ablkcipher_encap(desc, &ctx->cdata);
9026 + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
9027 + desc_bytes(desc), DMA_TO_DEVICE);
9029 /* xts_ablkcipher_decrypt shared descriptor */
9030 desc = ctx->sh_desc_dec;
9032 - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
9033 - /* Skip if already shared */
9034 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
9037 - /* Load class1 key only */
9038 - append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
9039 - ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
9041 - /* Load sector size with index 40 bytes (0x28) */
9042 - append_cmd(desc, CMD_LOAD | IMMEDIATE | LDST_SRCDST_BYTE_CONTEXT |
9043 - LDST_CLASS_1_CCB | (0x28 << LDST_OFFSET_SHIFT) | 8);
9044 - append_data(desc, (void *)§or_size, 8);
9046 - set_jump_tgt_here(desc, key_jump_cmd);
9049 - * create sequence for loading the sector index
9050 - * Upper 8B of IV - will be used as sector index
9051 - * Lower 8B of IV - will be discarded
9053 - append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
9054 - LDST_CLASS_1_CCB | (0x20 << LDST_OFFSET_SHIFT) | 8);
9055 - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
9057 - /* Load operation */
9058 - append_dec_op1(desc, ctx->class1_alg_type);
9060 - /* Perform operation */
9061 - ablkcipher_append_src_dst(desc);
9063 - ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc, desc_bytes(desc),
9065 - if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
9066 - dma_unmap_single(jrdev, ctx->sh_desc_enc_dma,
9067 - desc_bytes(ctx->sh_desc_enc), DMA_TO_DEVICE);
9068 - dev_err(jrdev, "unable to map shared descriptor\n");
9072 - print_hex_dump(KERN_ERR,
9073 - "xts ablkcipher dec shdesc@" __stringify(__LINE__) ": ",
9074 - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
9076 + cnstr_shdsc_xts_ablkcipher_decap(desc, &ctx->cdata);
9077 + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
9078 + desc_bytes(desc), DMA_TO_DEVICE);
9084 * aead_edesc - s/w-extended aead descriptor
9085 - * @assoc_nents: number of segments in associated data (SPI+Seq) scatterlist
9086 - * @src_nents: number of segments in input scatterlist
9087 - * @dst_nents: number of segments in output scatterlist
9088 - * @iv_dma: dma address of iv for checking continuity and link table
9089 - * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE)
9090 + * @src_nents: number of segments in input s/w scatterlist
9091 + * @dst_nents: number of segments in output s/w scatterlist
9092 * @sec4_sg_bytes: length of dma mapped sec4_sg space
9093 * @sec4_sg_dma: bus physical mapped address of h/w link table
9094 + * @sec4_sg: pointer to h/w link table
9095 * @hw_desc: the h/w job descriptor followed by any referenced link tables
9101 - dma_addr_t iv_dma;
9103 dma_addr_t sec4_sg_dma;
9104 struct sec4_sg_entry *sec4_sg;
9105 @@ -1899,12 +767,12 @@ struct aead_edesc {
9108 * ablkcipher_edesc - s/w-extended ablkcipher descriptor
9109 - * @src_nents: number of segments in input scatterlist
9110 - * @dst_nents: number of segments in output scatterlist
9111 + * @src_nents: number of segments in input s/w scatterlist
9112 + * @dst_nents: number of segments in output s/w scatterlist
9113 * @iv_dma: dma address of iv for checking continuity and link table
9114 - * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE)
9115 * @sec4_sg_bytes: length of dma mapped sec4_sg space
9116 * @sec4_sg_dma: bus physical mapped address of h/w link table
9117 + * @sec4_sg: pointer to h/w link table
9118 * @hw_desc: the h/w job descriptor followed by any referenced link tables
9120 struct ablkcipher_edesc {
9121 @@ -1924,10 +792,11 @@ static void caam_unmap(struct device *de
9125 - dma_unmap_sg(dev, src, src_nents ? : 1, DMA_TO_DEVICE);
9126 - dma_unmap_sg(dev, dst, dst_nents ? : 1, DMA_FROM_DEVICE);
9128 + dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
9129 + dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
9131 - dma_unmap_sg(dev, src, src_nents ? : 1, DMA_BIDIRECTIONAL);
9132 + dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
9136 @@ -2021,8 +890,7 @@ static void ablkcipher_encrypt_done(stru
9137 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
9140 - edesc = (struct ablkcipher_edesc *)((char *)desc -
9141 - offsetof(struct ablkcipher_edesc, hw_desc));
9142 + edesc = container_of(desc, struct ablkcipher_edesc, hw_desc[0]);
9145 caam_jr_strstatus(jrdev, err);
9146 @@ -2031,10 +899,10 @@ static void ablkcipher_encrypt_done(stru
9147 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
9148 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
9149 edesc->src_nents > 1 ? 100 : ivsize, 1);
9150 - dbg_dump_sg(KERN_ERR, "dst @"__stringify(__LINE__)": ",
9151 - DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
9152 - edesc->dst_nents > 1 ? 100 : req->nbytes, 1, true);
9154 + caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ",
9155 + DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
9156 + edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
9158 ablkcipher_unmap(jrdev, edesc, req);
9160 @@ -2062,8 +930,7 @@ static void ablkcipher_decrypt_done(stru
9161 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
9164 - edesc = (struct ablkcipher_edesc *)((char *)desc -
9165 - offsetof(struct ablkcipher_edesc, hw_desc));
9166 + edesc = container_of(desc, struct ablkcipher_edesc, hw_desc[0]);
9168 caam_jr_strstatus(jrdev, err);
9170 @@ -2071,10 +938,10 @@ static void ablkcipher_decrypt_done(stru
9171 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
9172 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
9174 - dbg_dump_sg(KERN_ERR, "dst @"__stringify(__LINE__)": ",
9175 - DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
9176 - edesc->dst_nents > 1 ? 100 : req->nbytes, 1, true);
9178 + caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ",
9179 + DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
9180 + edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
9182 ablkcipher_unmap(jrdev, edesc, req);
9184 @@ -2114,7 +981,7 @@ static void init_aead_job(struct aead_re
9185 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
9188 - src_dma = sg_dma_address(req->src);
9189 + src_dma = edesc->src_nents ? sg_dma_address(req->src) : 0;
9192 src_dma = edesc->sec4_sg_dma;
9193 @@ -2129,7 +996,7 @@ static void init_aead_job(struct aead_re
9194 out_options = in_options;
9196 if (unlikely(req->src != req->dst)) {
9197 - if (!edesc->dst_nents) {
9198 + if (edesc->dst_nents == 1) {
9199 dst_dma = sg_dma_address(req->dst);
9201 dst_dma = edesc->sec4_sg_dma +
9202 @@ -2147,9 +1014,6 @@ static void init_aead_job(struct aead_re
9203 append_seq_out_ptr(desc, dst_dma,
9204 req->assoclen + req->cryptlen - authsize,
9207 - /* REG3 = assoclen */
9208 - append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
9211 static void init_gcm_job(struct aead_request *req,
9212 @@ -2164,6 +1028,7 @@ static void init_gcm_job(struct aead_req
9215 init_aead_job(req, edesc, all_contig, encrypt);
9216 + append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
9218 /* BUG This should not be specific to generic GCM. */
9220 @@ -2175,7 +1040,7 @@ static void init_gcm_job(struct aead_req
9221 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | 12 | last);
9224 - append_data(desc, ctx->key + ctx->enckeylen, 4);
9225 + append_data(desc, ctx->key + ctx->cdata.keylen, 4);
9227 append_data(desc, req->iv, ivsize);
9228 /* End of blank commands */
9229 @@ -2190,7 +1055,8 @@ static void init_authenc_job(struct aead
9230 struct caam_aead_alg, aead);
9231 unsigned int ivsize = crypto_aead_ivsize(aead);
9232 struct caam_ctx *ctx = crypto_aead_ctx(aead);
9233 - const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
9234 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
9235 + const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
9236 OP_ALG_AAI_CTR_MOD128);
9237 const bool is_rfc3686 = alg->caam.rfc3686;
9238 u32 *desc = edesc->hw_desc;
9239 @@ -2213,6 +1079,15 @@ static void init_authenc_job(struct aead
9241 init_aead_job(req, edesc, all_contig, encrypt);
9244 + * {REG3, DPOVRD} = assoclen, depending on whether MATH command supports
9245 + * having DPOVRD as destination.
9247 + if (ctrlpriv->era < 3)
9248 + append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
9250 + append_math_add_imm_u32(desc, DPOVRD, ZERO, IMM, req->assoclen);
9252 if (ivsize && ((is_rfc3686 && encrypt) || !alg->caam.geniv))
9253 append_load_as_imm(desc, req->iv, ivsize,
9255 @@ -2236,16 +1111,15 @@ static void init_ablkcipher_job(u32 *sh_
9256 int len, sec4_sg_index = 0;
9259 - bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
9260 - CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
9261 print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ",
9262 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
9264 - printk(KERN_ERR "asked=%d, nbytes%d\n", (int)edesc->src_nents ? 100 : req->nbytes, req->nbytes);
9265 - dbg_dump_sg(KERN_ERR, "src @"__stringify(__LINE__)": ",
9266 - DUMP_PREFIX_ADDRESS, 16, 4, req->src,
9267 - edesc->src_nents ? 100 : req->nbytes, 1, may_sleep);
9268 + pr_err("asked=%d, nbytes%d\n",
9269 + (int)edesc->src_nents > 1 ? 100 : req->nbytes, req->nbytes);
9271 + caam_dump_sg(KERN_ERR, "src @" __stringify(__LINE__)": ",
9272 + DUMP_PREFIX_ADDRESS, 16, 4, req->src,
9273 + edesc->src_nents > 1 ? 100 : req->nbytes, 1);
9275 len = desc_len(sh_desc);
9276 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
9277 @@ -2261,7 +1135,7 @@ static void init_ablkcipher_job(u32 *sh_
9278 append_seq_in_ptr(desc, src_dma, req->nbytes + ivsize, in_options);
9280 if (likely(req->src == req->dst)) {
9281 - if (!edesc->src_nents && iv_contig) {
9282 + if (edesc->src_nents == 1 && iv_contig) {
9283 dst_dma = sg_dma_address(req->src);
9285 dst_dma = edesc->sec4_sg_dma +
9286 @@ -2269,7 +1143,7 @@ static void init_ablkcipher_job(u32 *sh_
9287 out_options = LDST_SGF;
9290 - if (!edesc->dst_nents) {
9291 + if (edesc->dst_nents == 1) {
9292 dst_dma = sg_dma_address(req->dst);
9294 dst_dma = edesc->sec4_sg_dma +
9295 @@ -2296,20 +1170,18 @@ static void init_ablkcipher_giv_job(u32
9296 int len, sec4_sg_index = 0;
9299 - bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
9300 - CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
9301 print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ",
9302 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
9304 - dbg_dump_sg(KERN_ERR, "src @" __stringify(__LINE__) ": ",
9305 - DUMP_PREFIX_ADDRESS, 16, 4, req->src,
9306 - edesc->src_nents ? 100 : req->nbytes, 1, may_sleep);
9308 + caam_dump_sg(KERN_ERR, "src @" __stringify(__LINE__) ": ",
9309 + DUMP_PREFIX_ADDRESS, 16, 4, req->src,
9310 + edesc->src_nents > 1 ? 100 : req->nbytes, 1);
9312 len = desc_len(sh_desc);
9313 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
9315 - if (!edesc->src_nents) {
9316 + if (edesc->src_nents == 1) {
9317 src_dma = sg_dma_address(req->src);
9320 @@ -2340,87 +1212,100 @@ static struct aead_edesc *aead_edesc_all
9321 struct crypto_aead *aead = crypto_aead_reqtfm(req);
9322 struct caam_ctx *ctx = crypto_aead_ctx(aead);
9323 struct device *jrdev = ctx->jrdev;
9324 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
9325 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
9326 - int src_nents, dst_nents = 0;
9327 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
9328 + GFP_KERNEL : GFP_ATOMIC;
9329 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
9330 struct aead_edesc *edesc;
9332 - bool all_contig = true;
9333 - int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
9334 + int sec4_sg_index, sec4_sg_len, sec4_sg_bytes;
9335 unsigned int authsize = ctx->authsize;
9337 if (unlikely(req->dst != req->src)) {
9338 - src_nents = sg_count(req->src, req->assoclen + req->cryptlen);
9339 - dst_nents = sg_count(req->dst,
9340 - req->assoclen + req->cryptlen +
9341 - (encrypt ? authsize : (-authsize)));
9343 - src_nents = sg_count(req->src,
9344 - req->assoclen + req->cryptlen +
9345 - (encrypt ? authsize : 0));
9348 - /* Check if data are contiguous. */
9349 - all_contig = !src_nents;
9350 - if (!all_contig) {
9351 - src_nents = src_nents ? : 1;
9352 - sec4_sg_len = src_nents;
9355 - sec4_sg_len += dst_nents;
9357 - sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
9358 + src_nents = sg_nents_for_len(req->src, req->assoclen +
9360 + if (unlikely(src_nents < 0)) {
9361 + dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
9362 + req->assoclen + req->cryptlen);
9363 + return ERR_PTR(src_nents);
9366 - /* allocate space for base edesc and hw desc commands, link tables */
9367 - edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
9370 - dev_err(jrdev, "could not allocate extended descriptor\n");
9371 - return ERR_PTR(-ENOMEM);
9372 + dst_nents = sg_nents_for_len(req->dst, req->assoclen +
9374 + (encrypt ? authsize :
9376 + if (unlikely(dst_nents < 0)) {
9377 + dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
9378 + req->assoclen + req->cryptlen +
9379 + (encrypt ? authsize : (-authsize)));
9380 + return ERR_PTR(dst_nents);
9383 + src_nents = sg_nents_for_len(req->src, req->assoclen +
9385 + (encrypt ? authsize : 0));
9386 + if (unlikely(src_nents < 0)) {
9387 + dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
9388 + req->assoclen + req->cryptlen +
9389 + (encrypt ? authsize : 0));
9390 + return ERR_PTR(src_nents);
9394 if (likely(req->src == req->dst)) {
9395 - sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
9396 - DMA_BIDIRECTIONAL);
9397 - if (unlikely(!sgc)) {
9398 + mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
9399 + DMA_BIDIRECTIONAL);
9400 + if (unlikely(!mapped_src_nents)) {
9401 dev_err(jrdev, "unable to map source\n");
9403 return ERR_PTR(-ENOMEM);
9406 - sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
9408 - if (unlikely(!sgc)) {
9409 - dev_err(jrdev, "unable to map source\n");
9411 - return ERR_PTR(-ENOMEM);
9412 + /* Cover also the case of null (zero length) input data */
9414 + mapped_src_nents = dma_map_sg(jrdev, req->src,
9415 + src_nents, DMA_TO_DEVICE);
9416 + if (unlikely(!mapped_src_nents)) {
9417 + dev_err(jrdev, "unable to map source\n");
9418 + return ERR_PTR(-ENOMEM);
9421 + mapped_src_nents = 0;
9424 - sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1,
9426 - if (unlikely(!sgc)) {
9427 + mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
9429 + if (unlikely(!mapped_dst_nents)) {
9430 dev_err(jrdev, "unable to map destination\n");
9431 - dma_unmap_sg(jrdev, req->src, src_nents ? : 1,
9434 + dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
9435 return ERR_PTR(-ENOMEM);
9439 + sec4_sg_len = mapped_src_nents > 1 ? mapped_src_nents : 0;
9440 + sec4_sg_len += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
9441 + sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
9443 + /* allocate space for base edesc and hw desc commands, link tables */
9444 + edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
9447 + caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
9449 + return ERR_PTR(-ENOMEM);
9452 edesc->src_nents = src_nents;
9453 edesc->dst_nents = dst_nents;
9454 edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
9456 - *all_contig_ptr = all_contig;
9457 + *all_contig_ptr = !(mapped_src_nents > 1);
9460 - if (!all_contig) {
9461 - sg_to_sec4_sg_last(req->src, src_nents,
9462 - edesc->sec4_sg + sec4_sg_index, 0);
9463 - sec4_sg_index += src_nents;
9464 + if (mapped_src_nents > 1) {
9465 + sg_to_sec4_sg_last(req->src, mapped_src_nents,
9466 + edesc->sec4_sg + sec4_sg_index, 0);
9467 + sec4_sg_index += mapped_src_nents;
9470 - sg_to_sec4_sg_last(req->dst, dst_nents,
9471 + if (mapped_dst_nents > 1) {
9472 + sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
9473 edesc->sec4_sg + sec4_sg_index, 0);
9476 @@ -2573,13 +1458,9 @@ static int aead_decrypt(struct aead_requ
9481 - bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
9482 - CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
9483 - dbg_dump_sg(KERN_ERR, "dec src@"__stringify(__LINE__)": ",
9484 - DUMP_PREFIX_ADDRESS, 16, 4, req->src,
9485 - req->assoclen + req->cryptlen, 1, may_sleep);
9487 + caam_dump_sg(KERN_ERR, "dec src@" __stringify(__LINE__)": ",
9488 + DUMP_PREFIX_ADDRESS, 16, 4, req->src,
9489 + req->assoclen + req->cryptlen, 1);
9491 /* allocate extended descriptor */
9492 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
9493 @@ -2619,51 +1500,80 @@ static struct ablkcipher_edesc *ablkciph
9494 struct device *jrdev = ctx->jrdev;
9495 gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
9496 GFP_KERNEL : GFP_ATOMIC;
9497 - int src_nents, dst_nents = 0, sec4_sg_bytes;
9498 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
9499 struct ablkcipher_edesc *edesc;
9500 dma_addr_t iv_dma = 0;
9501 - bool iv_contig = false;
9504 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
9505 - int sec4_sg_index;
9506 + int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
9508 - src_nents = sg_count(req->src, req->nbytes);
9509 + src_nents = sg_nents_for_len(req->src, req->nbytes);
9510 + if (unlikely(src_nents < 0)) {
9511 + dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
9513 + return ERR_PTR(src_nents);
9516 - if (req->dst != req->src)
9517 - dst_nents = sg_count(req->dst, req->nbytes);
9518 + if (req->dst != req->src) {
9519 + dst_nents = sg_nents_for_len(req->dst, req->nbytes);
9520 + if (unlikely(dst_nents < 0)) {
9521 + dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
9523 + return ERR_PTR(dst_nents);
9527 if (likely(req->src == req->dst)) {
9528 - sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
9529 - DMA_BIDIRECTIONAL);
9530 + mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
9531 + DMA_BIDIRECTIONAL);
9532 + if (unlikely(!mapped_src_nents)) {
9533 + dev_err(jrdev, "unable to map source\n");
9534 + return ERR_PTR(-ENOMEM);
9537 - sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
9539 - sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1,
9541 + mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
9543 + if (unlikely(!mapped_src_nents)) {
9544 + dev_err(jrdev, "unable to map source\n");
9545 + return ERR_PTR(-ENOMEM);
9548 + mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
9550 + if (unlikely(!mapped_dst_nents)) {
9551 + dev_err(jrdev, "unable to map destination\n");
9552 + dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
9553 + return ERR_PTR(-ENOMEM);
9557 iv_dma = dma_map_single(jrdev, req->info, ivsize, DMA_TO_DEVICE);
9558 if (dma_mapping_error(jrdev, iv_dma)) {
9559 dev_err(jrdev, "unable to map IV\n");
9560 + caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
9562 return ERR_PTR(-ENOMEM);
9566 - * Check if iv can be contiguous with source and destination.
9567 - * If so, include it. If not, create scatterlist.
9569 - if (!src_nents && iv_dma + ivsize == sg_dma_address(req->src))
9572 - src_nents = src_nents ? : 1;
9573 - sec4_sg_bytes = ((iv_contig ? 0 : 1) + src_nents + dst_nents) *
9574 - sizeof(struct sec4_sg_entry);
9575 + if (mapped_src_nents == 1 &&
9576 + iv_dma + ivsize == sg_dma_address(req->src)) {
9580 + in_contig = false;
9581 + sec4_sg_ents = 1 + mapped_src_nents;
9583 + dst_sg_idx = sec4_sg_ents;
9584 + sec4_sg_ents += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
9585 + sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
9587 /* allocate space for base edesc and hw desc commands, link tables */
9588 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
9591 dev_err(jrdev, "could not allocate extended descriptor\n");
9592 + caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
9593 + iv_dma, ivsize, 0, 0);
9594 return ERR_PTR(-ENOMEM);
9597 @@ -2673,23 +1583,24 @@ static struct ablkcipher_edesc *ablkciph
9598 edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
9601 - sec4_sg_index = 0;
9604 dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0);
9605 - sg_to_sec4_sg_last(req->src, src_nents,
9606 + sg_to_sec4_sg_last(req->src, mapped_src_nents,
9607 edesc->sec4_sg + 1, 0);
9608 - sec4_sg_index += 1 + src_nents;
9612 - sg_to_sec4_sg_last(req->dst, dst_nents,
9613 - edesc->sec4_sg + sec4_sg_index, 0);
9614 + if (mapped_dst_nents > 1) {
9615 + sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
9616 + edesc->sec4_sg + dst_sg_idx, 0);
9619 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
9620 sec4_sg_bytes, DMA_TO_DEVICE);
9621 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
9622 dev_err(jrdev, "unable to map S/G table\n");
9623 + caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
9624 + iv_dma, ivsize, 0, 0);
9626 return ERR_PTR(-ENOMEM);
9629 @@ -2701,7 +1612,7 @@ static struct ablkcipher_edesc *ablkciph
9633 - *iv_contig_out = iv_contig;
9634 + *iv_contig_out = in_contig;
9638 @@ -2792,30 +1703,54 @@ static struct ablkcipher_edesc *ablkciph
9639 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
9640 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
9641 struct device *jrdev = ctx->jrdev;
9642 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
9643 - CRYPTO_TFM_REQ_MAY_SLEEP)) ?
9644 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
9645 GFP_KERNEL : GFP_ATOMIC;
9646 - int src_nents, dst_nents = 0, sec4_sg_bytes;
9647 + int src_nents, mapped_src_nents, dst_nents, mapped_dst_nents;
9648 struct ablkcipher_edesc *edesc;
9649 dma_addr_t iv_dma = 0;
9650 - bool iv_contig = false;
9653 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
9654 - int sec4_sg_index;
9655 + int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
9657 - src_nents = sg_count(req->src, req->nbytes);
9659 - if (unlikely(req->dst != req->src))
9660 - dst_nents = sg_count(req->dst, req->nbytes);
9661 + src_nents = sg_nents_for_len(req->src, req->nbytes);
9662 + if (unlikely(src_nents < 0)) {
9663 + dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
9665 + return ERR_PTR(src_nents);
9668 if (likely(req->src == req->dst)) {
9669 - sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
9670 - DMA_BIDIRECTIONAL);
9671 + mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
9672 + DMA_BIDIRECTIONAL);
9673 + if (unlikely(!mapped_src_nents)) {
9674 + dev_err(jrdev, "unable to map source\n");
9675 + return ERR_PTR(-ENOMEM);
9678 + dst_nents = src_nents;
9679 + mapped_dst_nents = src_nents;
9681 - sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
9683 - sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1,
9685 + mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
9687 + if (unlikely(!mapped_src_nents)) {
9688 + dev_err(jrdev, "unable to map source\n");
9689 + return ERR_PTR(-ENOMEM);
9692 + dst_nents = sg_nents_for_len(req->dst, req->nbytes);
9693 + if (unlikely(dst_nents < 0)) {
9694 + dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
9696 + return ERR_PTR(dst_nents);
9699 + mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
9701 + if (unlikely(!mapped_dst_nents)) {
9702 + dev_err(jrdev, "unable to map destination\n");
9703 + dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
9704 + return ERR_PTR(-ENOMEM);
9709 @@ -2825,21 +1760,29 @@ static struct ablkcipher_edesc *ablkciph
9710 iv_dma = dma_map_single(jrdev, greq->giv, ivsize, DMA_TO_DEVICE);
9711 if (dma_mapping_error(jrdev, iv_dma)) {
9712 dev_err(jrdev, "unable to map IV\n");
9713 + caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
9715 return ERR_PTR(-ENOMEM);
9718 - if (!dst_nents && iv_dma + ivsize == sg_dma_address(req->dst))
9721 - dst_nents = dst_nents ? : 1;
9722 - sec4_sg_bytes = ((iv_contig ? 0 : 1) + src_nents + dst_nents) *
9723 - sizeof(struct sec4_sg_entry);
9724 + sec4_sg_ents = mapped_src_nents > 1 ? mapped_src_nents : 0;
9725 + dst_sg_idx = sec4_sg_ents;
9726 + if (mapped_dst_nents == 1 &&
9727 + iv_dma + ivsize == sg_dma_address(req->dst)) {
9728 + out_contig = true;
9730 + out_contig = false;
9731 + sec4_sg_ents += 1 + mapped_dst_nents;
9734 /* allocate space for base edesc and hw desc commands, link tables */
9735 + sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
9736 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
9739 dev_err(jrdev, "could not allocate extended descriptor\n");
9740 + caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
9741 + iv_dma, ivsize, 0, 0);
9742 return ERR_PTR(-ENOMEM);
9745 @@ -2849,24 +1792,24 @@ static struct ablkcipher_edesc *ablkciph
9746 edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
9749 - sec4_sg_index = 0;
9751 - sg_to_sec4_sg_last(req->src, src_nents, edesc->sec4_sg, 0);
9752 - sec4_sg_index += src_nents;
9754 + if (mapped_src_nents > 1)
9755 + sg_to_sec4_sg_last(req->src, mapped_src_nents, edesc->sec4_sg,
9759 - dma_to_sec4_sg_one(edesc->sec4_sg + sec4_sg_index,
9760 + if (!out_contig) {
9761 + dma_to_sec4_sg_one(edesc->sec4_sg + dst_sg_idx,
9763 - sec4_sg_index += 1;
9764 - sg_to_sec4_sg_last(req->dst, dst_nents,
9765 - edesc->sec4_sg + sec4_sg_index, 0);
9766 + sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
9767 + edesc->sec4_sg + dst_sg_idx + 1, 0);
9770 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
9771 sec4_sg_bytes, DMA_TO_DEVICE);
9772 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
9773 dev_err(jrdev, "unable to map S/G table\n");
9774 + caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
9775 + iv_dma, ivsize, 0, 0);
9777 return ERR_PTR(-ENOMEM);
9779 edesc->iv_dma = iv_dma;
9780 @@ -2878,7 +1821,7 @@ static struct ablkcipher_edesc *ablkciph
9784 - *iv_contig_out = iv_contig;
9785 + *iv_contig_out = out_contig;
9789 @@ -2889,7 +1832,7 @@ static int ablkcipher_givencrypt(struct
9790 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
9791 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
9792 struct device *jrdev = ctx->jrdev;
9794 + bool iv_contig = false;
9798 @@ -2933,7 +1876,6 @@ struct caam_alg_template {
9800 u32 class1_alg_type;
9801 u32 class2_alg_type;
9805 static struct caam_alg_template driver_algs[] = {
9806 @@ -3118,7 +2060,6 @@ static struct caam_aead_alg driver_aeads
9808 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
9809 OP_ALG_AAI_HMAC_PRECOMP,
9810 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
9814 @@ -3140,7 +2081,6 @@ static struct caam_aead_alg driver_aeads
9816 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
9817 OP_ALG_AAI_HMAC_PRECOMP,
9818 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
9822 @@ -3162,7 +2102,6 @@ static struct caam_aead_alg driver_aeads
9824 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
9825 OP_ALG_AAI_HMAC_PRECOMP,
9826 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
9830 @@ -3184,7 +2123,6 @@ static struct caam_aead_alg driver_aeads
9832 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
9833 OP_ALG_AAI_HMAC_PRECOMP,
9834 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
9838 @@ -3206,7 +2144,6 @@ static struct caam_aead_alg driver_aeads
9840 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
9841 OP_ALG_AAI_HMAC_PRECOMP,
9842 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
9846 @@ -3228,7 +2165,6 @@ static struct caam_aead_alg driver_aeads
9848 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
9849 OP_ALG_AAI_HMAC_PRECOMP,
9850 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
9854 @@ -3250,7 +2186,6 @@ static struct caam_aead_alg driver_aeads
9855 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9856 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
9857 OP_ALG_AAI_HMAC_PRECOMP,
9858 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
9862 @@ -3273,7 +2208,6 @@ static struct caam_aead_alg driver_aeads
9863 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9864 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
9865 OP_ALG_AAI_HMAC_PRECOMP,
9866 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
9870 @@ -3296,7 +2230,6 @@ static struct caam_aead_alg driver_aeads
9871 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9872 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
9873 OP_ALG_AAI_HMAC_PRECOMP,
9874 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
9878 @@ -3319,7 +2252,6 @@ static struct caam_aead_alg driver_aeads
9879 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9880 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
9881 OP_ALG_AAI_HMAC_PRECOMP,
9882 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
9886 @@ -3342,7 +2274,6 @@ static struct caam_aead_alg driver_aeads
9887 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9888 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
9889 OP_ALG_AAI_HMAC_PRECOMP,
9890 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
9894 @@ -3365,7 +2296,6 @@ static struct caam_aead_alg driver_aeads
9895 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9896 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
9897 OP_ALG_AAI_HMAC_PRECOMP,
9898 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
9902 @@ -3388,7 +2318,6 @@ static struct caam_aead_alg driver_aeads
9903 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9904 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
9905 OP_ALG_AAI_HMAC_PRECOMP,
9906 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
9910 @@ -3411,7 +2340,6 @@ static struct caam_aead_alg driver_aeads
9911 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9912 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
9913 OP_ALG_AAI_HMAC_PRECOMP,
9914 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
9918 @@ -3434,7 +2362,6 @@ static struct caam_aead_alg driver_aeads
9919 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9920 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
9921 OP_ALG_AAI_HMAC_PRECOMP,
9922 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
9926 @@ -3457,7 +2384,6 @@ static struct caam_aead_alg driver_aeads
9927 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9928 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
9929 OP_ALG_AAI_HMAC_PRECOMP,
9930 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
9934 @@ -3480,7 +2406,6 @@ static struct caam_aead_alg driver_aeads
9935 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9936 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
9937 OP_ALG_AAI_HMAC_PRECOMP,
9938 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
9942 @@ -3503,7 +2428,6 @@ static struct caam_aead_alg driver_aeads
9943 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
9944 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
9945 OP_ALG_AAI_HMAC_PRECOMP,
9946 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
9950 @@ -3526,7 +2450,6 @@ static struct caam_aead_alg driver_aeads
9951 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
9952 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
9953 OP_ALG_AAI_HMAC_PRECOMP,
9954 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
9958 @@ -3549,7 +2472,6 @@ static struct caam_aead_alg driver_aeads
9959 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
9960 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
9961 OP_ALG_AAI_HMAC_PRECOMP,
9962 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
9966 @@ -3573,7 +2495,6 @@ static struct caam_aead_alg driver_aeads
9967 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
9968 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
9969 OP_ALG_AAI_HMAC_PRECOMP,
9970 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
9974 @@ -3597,7 +2518,6 @@ static struct caam_aead_alg driver_aeads
9975 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
9976 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
9977 OP_ALG_AAI_HMAC_PRECOMP,
9978 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
9982 @@ -3621,7 +2541,6 @@ static struct caam_aead_alg driver_aeads
9983 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
9984 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
9985 OP_ALG_AAI_HMAC_PRECOMP,
9986 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
9990 @@ -3645,7 +2564,6 @@ static struct caam_aead_alg driver_aeads
9991 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
9992 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
9993 OP_ALG_AAI_HMAC_PRECOMP,
9994 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
9998 @@ -3669,7 +2587,6 @@ static struct caam_aead_alg driver_aeads
9999 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
10000 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
10001 OP_ALG_AAI_HMAC_PRECOMP,
10002 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
10006 @@ -3693,7 +2610,6 @@ static struct caam_aead_alg driver_aeads
10007 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
10008 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
10009 OP_ALG_AAI_HMAC_PRECOMP,
10010 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
10014 @@ -3717,7 +2633,6 @@ static struct caam_aead_alg driver_aeads
10015 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
10016 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
10017 OP_ALG_AAI_HMAC_PRECOMP,
10018 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
10022 @@ -3741,7 +2656,6 @@ static struct caam_aead_alg driver_aeads
10023 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
10024 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
10025 OP_ALG_AAI_HMAC_PRECOMP,
10026 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
10030 @@ -3765,7 +2679,6 @@ static struct caam_aead_alg driver_aeads
10031 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
10032 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
10033 OP_ALG_AAI_HMAC_PRECOMP,
10034 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
10038 @@ -3789,7 +2702,6 @@ static struct caam_aead_alg driver_aeads
10039 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
10040 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
10041 OP_ALG_AAI_HMAC_PRECOMP,
10042 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
10046 @@ -3812,7 +2724,6 @@ static struct caam_aead_alg driver_aeads
10047 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10048 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
10049 OP_ALG_AAI_HMAC_PRECOMP,
10050 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
10054 @@ -3835,7 +2746,6 @@ static struct caam_aead_alg driver_aeads
10055 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10056 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
10057 OP_ALG_AAI_HMAC_PRECOMP,
10058 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
10062 @@ -3858,7 +2768,6 @@ static struct caam_aead_alg driver_aeads
10063 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10064 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
10065 OP_ALG_AAI_HMAC_PRECOMP,
10066 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
10070 @@ -3881,7 +2790,6 @@ static struct caam_aead_alg driver_aeads
10071 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10072 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
10073 OP_ALG_AAI_HMAC_PRECOMP,
10074 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
10078 @@ -3904,7 +2812,6 @@ static struct caam_aead_alg driver_aeads
10079 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10080 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
10081 OP_ALG_AAI_HMAC_PRECOMP,
10082 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
10086 @@ -3927,7 +2834,6 @@ static struct caam_aead_alg driver_aeads
10087 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10088 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
10089 OP_ALG_AAI_HMAC_PRECOMP,
10090 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
10094 @@ -3950,7 +2856,6 @@ static struct caam_aead_alg driver_aeads
10095 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10096 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
10097 OP_ALG_AAI_HMAC_PRECOMP,
10098 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
10102 @@ -3973,7 +2878,6 @@ static struct caam_aead_alg driver_aeads
10103 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10104 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
10105 OP_ALG_AAI_HMAC_PRECOMP,
10106 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
10110 @@ -3996,7 +2900,6 @@ static struct caam_aead_alg driver_aeads
10111 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10112 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
10113 OP_ALG_AAI_HMAC_PRECOMP,
10114 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
10118 @@ -4019,7 +2922,6 @@ static struct caam_aead_alg driver_aeads
10119 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10120 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
10121 OP_ALG_AAI_HMAC_PRECOMP,
10122 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
10126 @@ -4042,7 +2944,6 @@ static struct caam_aead_alg driver_aeads
10127 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10128 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
10129 OP_ALG_AAI_HMAC_PRECOMP,
10130 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
10134 @@ -4065,7 +2966,6 @@ static struct caam_aead_alg driver_aeads
10135 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
10136 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
10137 OP_ALG_AAI_HMAC_PRECOMP,
10138 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
10142 @@ -4090,7 +2990,6 @@ static struct caam_aead_alg driver_aeads
10143 OP_ALG_AAI_CTR_MOD128,
10144 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
10145 OP_ALG_AAI_HMAC_PRECOMP,
10146 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
10150 @@ -4115,7 +3014,6 @@ static struct caam_aead_alg driver_aeads
10151 OP_ALG_AAI_CTR_MOD128,
10152 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
10153 OP_ALG_AAI_HMAC_PRECOMP,
10154 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
10158 @@ -4141,7 +3039,6 @@ static struct caam_aead_alg driver_aeads
10159 OP_ALG_AAI_CTR_MOD128,
10160 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
10161 OP_ALG_AAI_HMAC_PRECOMP,
10162 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
10166 @@ -4166,7 +3063,6 @@ static struct caam_aead_alg driver_aeads
10167 OP_ALG_AAI_CTR_MOD128,
10168 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
10169 OP_ALG_AAI_HMAC_PRECOMP,
10170 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
10174 @@ -4192,7 +3088,6 @@ static struct caam_aead_alg driver_aeads
10175 OP_ALG_AAI_CTR_MOD128,
10176 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
10177 OP_ALG_AAI_HMAC_PRECOMP,
10178 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
10182 @@ -4217,7 +3112,6 @@ static struct caam_aead_alg driver_aeads
10183 OP_ALG_AAI_CTR_MOD128,
10184 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
10185 OP_ALG_AAI_HMAC_PRECOMP,
10186 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
10190 @@ -4243,7 +3137,6 @@ static struct caam_aead_alg driver_aeads
10191 OP_ALG_AAI_CTR_MOD128,
10192 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
10193 OP_ALG_AAI_HMAC_PRECOMP,
10194 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
10198 @@ -4268,7 +3161,6 @@ static struct caam_aead_alg driver_aeads
10199 OP_ALG_AAI_CTR_MOD128,
10200 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
10201 OP_ALG_AAI_HMAC_PRECOMP,
10202 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
10206 @@ -4294,7 +3186,6 @@ static struct caam_aead_alg driver_aeads
10207 OP_ALG_AAI_CTR_MOD128,
10208 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
10209 OP_ALG_AAI_HMAC_PRECOMP,
10210 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
10214 @@ -4319,7 +3210,6 @@ static struct caam_aead_alg driver_aeads
10215 OP_ALG_AAI_CTR_MOD128,
10216 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
10217 OP_ALG_AAI_HMAC_PRECOMP,
10218 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
10222 @@ -4345,7 +3235,6 @@ static struct caam_aead_alg driver_aeads
10223 OP_ALG_AAI_CTR_MOD128,
10224 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
10225 OP_ALG_AAI_HMAC_PRECOMP,
10226 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
10230 @@ -4370,7 +3259,6 @@ static struct caam_aead_alg driver_aeads
10231 OP_ALG_AAI_CTR_MOD128,
10232 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
10233 OP_ALG_AAI_HMAC_PRECOMP,
10234 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
10238 @@ -4385,16 +3273,34 @@ struct caam_crypto_alg {
10240 static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam)
10242 + dma_addr_t dma_addr;
10244 ctx->jrdev = caam_jr_alloc();
10245 if (IS_ERR(ctx->jrdev)) {
10246 pr_err("Job Ring Device allocation for transform failed\n");
10247 return PTR_ERR(ctx->jrdev);
10250 + dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_enc,
10251 + offsetof(struct caam_ctx,
10252 + sh_desc_enc_dma),
10253 + DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
10254 + if (dma_mapping_error(ctx->jrdev, dma_addr)) {
10255 + dev_err(ctx->jrdev, "unable to map key, shared descriptors\n");
10256 + caam_jr_free(ctx->jrdev);
10260 + ctx->sh_desc_enc_dma = dma_addr;
10261 + ctx->sh_desc_dec_dma = dma_addr + offsetof(struct caam_ctx,
10263 + ctx->sh_desc_givenc_dma = dma_addr + offsetof(struct caam_ctx,
10265 + ctx->key_dma = dma_addr + offsetof(struct caam_ctx, key);
10267 /* copy descriptor header template value */
10268 - ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
10269 - ctx->class2_alg_type = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
10270 - ctx->alg_op = OP_TYPE_CLASS2_ALG | caam->alg_op;
10271 + ctx->cdata.algtype = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
10272 + ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
10276 @@ -4421,25 +3327,9 @@ static int caam_aead_init(struct crypto_
10278 static void caam_exit_common(struct caam_ctx *ctx)
10280 - if (ctx->sh_desc_enc_dma &&
10281 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_enc_dma))
10282 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_enc_dma,
10283 - desc_bytes(ctx->sh_desc_enc), DMA_TO_DEVICE);
10284 - if (ctx->sh_desc_dec_dma &&
10285 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_dec_dma))
10286 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_dec_dma,
10287 - desc_bytes(ctx->sh_desc_dec), DMA_TO_DEVICE);
10288 - if (ctx->sh_desc_givenc_dma &&
10289 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_givenc_dma))
10290 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma,
10291 - desc_bytes(ctx->sh_desc_givenc),
10293 - if (ctx->key_dma &&
10294 - !dma_mapping_error(ctx->jrdev, ctx->key_dma))
10295 - dma_unmap_single(ctx->jrdev, ctx->key_dma,
10296 - ctx->enckeylen + ctx->split_key_pad_len,
10299 + dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_enc_dma,
10300 + offsetof(struct caam_ctx, sh_desc_enc_dma),
10301 + DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
10302 caam_jr_free(ctx->jrdev);
10305 @@ -4515,7 +3405,6 @@ static struct caam_crypto_alg *caam_alg_
10307 t_alg->caam.class1_alg_type = template->class1_alg_type;
10308 t_alg->caam.class2_alg_type = template->class2_alg_type;
10309 - t_alg->caam.alg_op = template->alg_op;
10314 +++ b/drivers/crypto/caam/caamalg_desc.c
10317 + * Shared descriptors for aead, ablkcipher algorithms
10319 + * Copyright 2016 NXP
10322 +#include "compat.h"
10323 +#include "desc_constr.h"
10324 +#include "caamalg_desc.h"
10327 + * For aead functions, read payload and write payload,
10328 + * both of which are specified in req->src and req->dst
10330 +static inline void aead_append_src_dst(u32 *desc, u32 msg_type)
10332 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
10333 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH |
10334 + KEY_VLF | msg_type | FIFOLD_TYPE_LASTBOTH);
10337 +/* Set DK bit in class 1 operation if shared */
10338 +static inline void append_dec_op1(u32 *desc, u32 type)
10340 + u32 *jump_cmd, *uncond_jump_cmd;
10342 + /* DK bit is valid only for AES */
10343 + if ((type & OP_ALG_ALGSEL_MASK) != OP_ALG_ALGSEL_AES) {
10344 + append_operation(desc, type | OP_ALG_AS_INITFINAL |
10349 + jump_cmd = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD);
10350 + append_operation(desc, type | OP_ALG_AS_INITFINAL |
10352 + uncond_jump_cmd = append_jump(desc, JUMP_TEST_ALL);
10353 + set_jump_tgt_here(desc, jump_cmd);
10354 + append_operation(desc, type | OP_ALG_AS_INITFINAL |
10355 + OP_ALG_DECRYPT | OP_ALG_AAI_DK);
10356 + set_jump_tgt_here(desc, uncond_jump_cmd);
10360 + * cnstr_shdsc_aead_null_encap - IPSec ESP encapsulation shared descriptor
10361 + * (non-protocol) with no (null) encryption.
10362 + * @desc: pointer to buffer used for descriptor construction
10363 + * @adata: pointer to authentication transform definitions.
10364 + * A split key is required for SEC Era < 6; the size of the split key
10365 + * is specified in this case. Valid algorithm values - one of
10366 + * OP_ALG_ALGSEL_{MD5, SHA1, SHA224, SHA256, SHA384, SHA512} ANDed
10367 + * with OP_ALG_AAI_HMAC_PRECOMP.
10368 + * @icvsize: integrity check value (ICV) size (truncated or full)
10371 +void cnstr_shdsc_aead_null_encap(u32 * const desc, struct alginfo *adata,
10372 + unsigned int icvsize, int era)
10374 + u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd;
10376 + init_sh_desc(desc, HDR_SHARE_SERIAL);
10378 + /* Skip if already shared */
10379 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
10382 + if (adata->key_inline)
10383 + append_key_as_imm(desc, adata->key_virt,
10384 + adata->keylen_pad, adata->keylen,
10385 + CLASS_2 | KEY_DEST_MDHA_SPLIT |
10388 + append_key(desc, adata->key_dma, adata->keylen,
10389 + CLASS_2 | KEY_DEST_MDHA_SPLIT | KEY_ENC);
10391 + append_proto_dkp(desc, adata);
10393 + set_jump_tgt_here(desc, key_jump_cmd);
10395 + /* assoclen + cryptlen = seqinlen */
10396 + append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
10398 + /* Prepare to read and write cryptlen + assoclen bytes */
10399 + append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
10400 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
10403 + * MOVE_LEN opcode is not available in all SEC HW revisions,
10404 + * thus need to do some magic, i.e. self-patch the descriptor
10407 + read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
10408 + MOVE_DEST_MATH3 |
10409 + (0x6 << MOVE_LEN_SHIFT));
10410 + write_move_cmd = append_move(desc, MOVE_SRC_MATH3 |
10411 + MOVE_DEST_DESCBUF |
10413 + (0x8 << MOVE_LEN_SHIFT));
10415 + /* Class 2 operation */
10416 + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
10419 + /* Read and write cryptlen bytes */
10420 + aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
10422 + set_move_tgt_here(desc, read_move_cmd);
10423 + set_move_tgt_here(desc, write_move_cmd);
10424 + append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
10425 + append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
10429 + append_seq_store(desc, icvsize, LDST_CLASS_2_CCB |
10430 + LDST_SRCDST_BYTE_CONTEXT);
10433 + print_hex_dump(KERN_ERR,
10434 + "aead null enc shdesc@" __stringify(__LINE__)": ",
10435 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
10438 +EXPORT_SYMBOL(cnstr_shdsc_aead_null_encap);
10441 + * cnstr_shdsc_aead_null_decap - IPSec ESP decapsulation shared descriptor
10442 + * (non-protocol) with no (null) decryption.
10443 + * @desc: pointer to buffer used for descriptor construction
10444 + * @adata: pointer to authentication transform definitions.
10445 + * A split key is required for SEC Era < 6; the size of the split key
10446 + * is specified in this case. Valid algorithm values - one of
10447 + * OP_ALG_ALGSEL_{MD5, SHA1, SHA224, SHA256, SHA384, SHA512} ANDed
10448 + * with OP_ALG_AAI_HMAC_PRECOMP.
10449 + * @icvsize: integrity check value (ICV) size (truncated or full)
10452 +void cnstr_shdsc_aead_null_decap(u32 * const desc, struct alginfo *adata,
10453 + unsigned int icvsize, int era)
10455 + u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd, *jump_cmd;
10457 + init_sh_desc(desc, HDR_SHARE_SERIAL);
10459 + /* Skip if already shared */
10460 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
10463 + if (adata->key_inline)
10464 + append_key_as_imm(desc, adata->key_virt,
10465 + adata->keylen_pad, adata->keylen,
10466 + CLASS_2 | KEY_DEST_MDHA_SPLIT |
10469 + append_key(desc, adata->key_dma, adata->keylen,
10470 + CLASS_2 | KEY_DEST_MDHA_SPLIT | KEY_ENC);
10472 + append_proto_dkp(desc, adata);
10474 + set_jump_tgt_here(desc, key_jump_cmd);
10476 + /* Class 2 operation */
10477 + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
10478 + OP_ALG_DECRYPT | OP_ALG_ICV_ON);
10480 + /* assoclen + cryptlen = seqoutlen */
10481 + append_math_sub(desc, REG2, SEQOUTLEN, REG0, CAAM_CMD_SZ);
10483 + /* Prepare to read and write cryptlen + assoclen bytes */
10484 + append_math_add(desc, VARSEQINLEN, ZERO, REG2, CAAM_CMD_SZ);
10485 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG2, CAAM_CMD_SZ);
10488 + * MOVE_LEN opcode is not available in all SEC HW revisions,
10489 + * thus need to do some magic, i.e. self-patch the descriptor
10492 + read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
10493 + MOVE_DEST_MATH2 |
10494 + (0x6 << MOVE_LEN_SHIFT));
10495 + write_move_cmd = append_move(desc, MOVE_SRC_MATH2 |
10496 + MOVE_DEST_DESCBUF |
10498 + (0x8 << MOVE_LEN_SHIFT));
10500 + /* Read and write cryptlen bytes */
10501 + aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
10504 + * Insert a NOP here, since we need at least 4 instructions between
10505 + * code patching the descriptor buffer and the location being patched.
10507 + jump_cmd = append_jump(desc, JUMP_TEST_ALL);
10508 + set_jump_tgt_here(desc, jump_cmd);
10510 + set_move_tgt_here(desc, read_move_cmd);
10511 + set_move_tgt_here(desc, write_move_cmd);
10512 + append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
10513 + append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
10515 + append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
10518 + append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 |
10519 + FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
10522 + print_hex_dump(KERN_ERR,
10523 + "aead null dec shdesc@" __stringify(__LINE__)": ",
10524 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
10527 +EXPORT_SYMBOL(cnstr_shdsc_aead_null_decap);
10529 +static void init_sh_desc_key_aead(u32 * const desc,
10530 + struct alginfo * const cdata,
10531 + struct alginfo * const adata,
10532 + const bool is_rfc3686, u32 *nonce, int era)
10534 + u32 *key_jump_cmd;
10535 + unsigned int enckeylen = cdata->keylen;
10537 + /* Note: Context registers are saved. */
10538 + init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
10540 + /* Skip if already shared */
10541 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
10545 + * RFC3686 specific:
10546 + * | key = {AUTH_KEY, ENC_KEY, NONCE}
10547 + * | enckeylen = encryption key size + nonce size
10550 + enckeylen -= CTR_RFC3686_NONCE_SIZE;
10553 + if (adata->key_inline)
10554 + append_key_as_imm(desc, adata->key_virt,
10555 + adata->keylen_pad, adata->keylen,
10556 + CLASS_2 | KEY_DEST_MDHA_SPLIT |
10559 + append_key(desc, adata->key_dma, adata->keylen,
10560 + CLASS_2 | KEY_DEST_MDHA_SPLIT | KEY_ENC);
10562 + append_proto_dkp(desc, adata);
10565 + if (cdata->key_inline)
10566 + append_key_as_imm(desc, cdata->key_virt, enckeylen,
10567 + enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
10569 + append_key(desc, cdata->key_dma, enckeylen, CLASS_1 |
10570 + KEY_DEST_CLASS_REG);
10572 + /* Load Counter into CONTEXT1 reg */
10573 + if (is_rfc3686) {
10574 + append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
10575 + LDST_CLASS_IND_CCB |
10576 + LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
10577 + append_move(desc,
10578 + MOVE_SRC_OUTFIFO |
10579 + MOVE_DEST_CLASS1CTX |
10580 + (16 << MOVE_OFFSET_SHIFT) |
10581 + (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
10584 + set_jump_tgt_here(desc, key_jump_cmd);
10588 + * cnstr_shdsc_aead_encap - IPSec ESP encapsulation shared descriptor
10589 + * (non-protocol).
10590 + * @desc: pointer to buffer used for descriptor construction
10591 + * @cdata: pointer to block cipher transform definitions
10592 + * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
10593 + * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128.
10594 + * @adata: pointer to authentication transform definitions.
10595 + * A split key is required for SEC Era < 6; the size of the split key
10596 + * is specified in this case. Valid algorithm values - one of
10597 + * OP_ALG_ALGSEL_{MD5, SHA1, SHA224, SHA256, SHA384, SHA512} ANDed
10598 + * with OP_ALG_AAI_HMAC_PRECOMP.
10599 + * @ivsize: initialization vector size
10600 + * @icvsize: integrity check value (ICV) size (truncated or full)
10601 + * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
10602 + * @nonce: pointer to rfc3686 nonce
10603 + * @ctx1_iv_off: IV offset in CONTEXT1 register
10604 + * @is_qi: true when called from caam/qi
10607 +void cnstr_shdsc_aead_encap(u32 * const desc, struct alginfo *cdata,
10608 + struct alginfo *adata, unsigned int ivsize,
10609 + unsigned int icvsize, const bool is_rfc3686,
10610 + u32 *nonce, const u32 ctx1_iv_off, const bool is_qi,
10613 + /* Note: Context registers are saved. */
10614 + init_sh_desc_key_aead(desc, cdata, adata, is_rfc3686, nonce, era);
10616 + /* Class 2 operation */
10617 + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
10621 + u32 *wait_load_cmd;
10623 + /* REG3 = assoclen */
10624 + append_seq_load(desc, 4, LDST_CLASS_DECO |
10625 + LDST_SRCDST_WORD_DECO_MATH3 |
10626 + (4 << LDST_OFFSET_SHIFT));
10628 + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
10629 + JUMP_COND_CALM | JUMP_COND_NCP |
10630 + JUMP_COND_NOP | JUMP_COND_NIP |
10632 + set_jump_tgt_here(desc, wait_load_cmd);
10634 + append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
10635 + LDST_SRCDST_BYTE_CONTEXT |
10636 + (ctx1_iv_off << LDST_OFFSET_SHIFT));
10639 + /* Read and write assoclen bytes */
10640 + if (is_qi || era < 3) {
10641 + append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
10642 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
10644 + append_math_add(desc, VARSEQINLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
10645 + append_math_add(desc, VARSEQOUTLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
10648 + /* Skip assoc data */
10649 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
10651 + /* read assoc before reading payload */
10652 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
10655 + /* Load Counter into CONTEXT1 reg */
10657 + append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
10658 + LDST_SRCDST_BYTE_CONTEXT |
10659 + ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
10660 + LDST_OFFSET_SHIFT));
10662 + /* Class 1 operation */
10663 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
10666 + /* Read and write cryptlen bytes */
10667 + append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
10668 + append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
10669 + aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
10672 + append_seq_store(desc, icvsize, LDST_CLASS_2_CCB |
10673 + LDST_SRCDST_BYTE_CONTEXT);
10676 + print_hex_dump(KERN_ERR, "aead enc shdesc@" __stringify(__LINE__)": ",
10677 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
10680 +EXPORT_SYMBOL(cnstr_shdsc_aead_encap);
10683 + * cnstr_shdsc_aead_decap - IPSec ESP decapsulation shared descriptor
10684 + * (non-protocol).
10685 + * @desc: pointer to buffer used for descriptor construction
10686 + * @cdata: pointer to block cipher transform definitions
10687 + * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
10688 + * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128.
10689 + * @adata: pointer to authentication transform definitions.
10690 + * A split key is required for SEC Era < 6; the size of the split key
10691 + * is specified in this case. Valid algorithm values - one of
10692 + * OP_ALG_ALGSEL_{MD5, SHA1, SHA224, SHA256, SHA384, SHA512} ANDed
10693 + * with OP_ALG_AAI_HMAC_PRECOMP.
10694 + * @ivsize: initialization vector size
10695 + * @icvsize: integrity check value (ICV) size (truncated or full)
10696 + * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
10697 + * @nonce: pointer to rfc3686 nonce
10698 + * @ctx1_iv_off: IV offset in CONTEXT1 register
10699 + * @is_qi: true when called from caam/qi
10702 +void cnstr_shdsc_aead_decap(u32 * const desc, struct alginfo *cdata,
10703 + struct alginfo *adata, unsigned int ivsize,
10704 + unsigned int icvsize, const bool geniv,
10705 + const bool is_rfc3686, u32 *nonce,
10706 + const u32 ctx1_iv_off, const bool is_qi, int era)
10708 + /* Note: Context registers are saved. */
10709 + init_sh_desc_key_aead(desc, cdata, adata, is_rfc3686, nonce, era);
10711 + /* Class 2 operation */
10712 + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
10713 + OP_ALG_DECRYPT | OP_ALG_ICV_ON);
10716 + u32 *wait_load_cmd;
10718 + /* REG3 = assoclen */
10719 + append_seq_load(desc, 4, LDST_CLASS_DECO |
10720 + LDST_SRCDST_WORD_DECO_MATH3 |
10721 + (4 << LDST_OFFSET_SHIFT));
10723 + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
10724 + JUMP_COND_CALM | JUMP_COND_NCP |
10725 + JUMP_COND_NOP | JUMP_COND_NIP |
10727 + set_jump_tgt_here(desc, wait_load_cmd);
10730 + append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
10731 + LDST_SRCDST_BYTE_CONTEXT |
10732 + (ctx1_iv_off << LDST_OFFSET_SHIFT));
10735 + /* Read and write assoclen bytes */
10736 + if (is_qi || era < 3) {
10737 + append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
10739 + append_math_add_imm_u32(desc, VARSEQOUTLEN, REG3, IMM,
10742 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3,
10745 + append_math_add(desc, VARSEQINLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
10747 + append_math_add_imm_u32(desc, VARSEQOUTLEN, DPOVRD, IMM,
10750 + append_math_add(desc, VARSEQOUTLEN, ZERO, DPOVRD,
10754 + /* Skip assoc data */
10755 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
10757 + /* read assoc before reading payload */
10758 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
10762 + append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
10763 + LDST_SRCDST_BYTE_CONTEXT |
10764 + (ctx1_iv_off << LDST_OFFSET_SHIFT));
10765 + append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_CLASS2INFIFO |
10766 + (ctx1_iv_off << MOVE_OFFSET_SHIFT) | ivsize);
10769 + /* Load Counter into CONTEXT1 reg */
10771 + append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
10772 + LDST_SRCDST_BYTE_CONTEXT |
10773 + ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
10774 + LDST_OFFSET_SHIFT));
10776 + /* Choose operation */
10778 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
10781 + append_dec_op1(desc, cdata->algtype);
10783 + /* Read and write cryptlen bytes */
10784 + append_math_add(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
10785 + append_math_add(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
10786 + aead_append_src_dst(desc, FIFOLD_TYPE_MSG);
10789 + append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 |
10790 + FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
10793 + print_hex_dump(KERN_ERR, "aead dec shdesc@" __stringify(__LINE__)": ",
10794 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
10797 +EXPORT_SYMBOL(cnstr_shdsc_aead_decap);
10800 + * cnstr_shdsc_aead_givencap - IPSec ESP encapsulation shared descriptor
10801 + * (non-protocol) with HW-generated initialization
10803 + * @desc: pointer to buffer used for descriptor construction
10804 + * @cdata: pointer to block cipher transform definitions
10805 + * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
10806 + * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128.
10807 + * @adata: pointer to authentication transform definitions.
10808 + * A split key is required for SEC Era < 6; the size of the split key
10809 + * is specified in this case. Valid algorithm values - one of
10810 + * OP_ALG_ALGSEL_{MD5, SHA1, SHA224, SHA256, SHA384, SHA512} ANDed
10811 + * with OP_ALG_AAI_HMAC_PRECOMP.
10812 + * @ivsize: initialization vector size
10813 + * @icvsize: integrity check value (ICV) size (truncated or full)
10814 + * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
10815 + * @nonce: pointer to rfc3686 nonce
10816 + * @ctx1_iv_off: IV offset in CONTEXT1 register
10817 + * @is_qi: true when called from caam/qi
10820 +void cnstr_shdsc_aead_givencap(u32 * const desc, struct alginfo *cdata,
10821 + struct alginfo *adata, unsigned int ivsize,
10822 + unsigned int icvsize, const bool is_rfc3686,
10823 + u32 *nonce, const u32 ctx1_iv_off,
10824 + const bool is_qi, int era)
10826 + u32 geniv, moveiv;
10828 + /* Note: Context registers are saved. */
10829 + init_sh_desc_key_aead(desc, cdata, adata, is_rfc3686, nonce, era);
10832 + u32 *wait_load_cmd;
10834 + /* REG3 = assoclen */
10835 + append_seq_load(desc, 4, LDST_CLASS_DECO |
10836 + LDST_SRCDST_WORD_DECO_MATH3 |
10837 + (4 << LDST_OFFSET_SHIFT));
10839 + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
10840 + JUMP_COND_CALM | JUMP_COND_NCP |
10841 + JUMP_COND_NOP | JUMP_COND_NIP |
10843 + set_jump_tgt_here(desc, wait_load_cmd);
10846 + if (is_rfc3686) {
10848 + append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
10849 + LDST_SRCDST_BYTE_CONTEXT |
10850 + (ctx1_iv_off << LDST_OFFSET_SHIFT));
10855 + /* Generate IV */
10856 + geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
10857 + NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
10858 + NFIFOENTRY_PTYPE_RND | (ivsize << NFIFOENTRY_DLEN_SHIFT);
10859 + append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
10860 + LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
10861 + append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
10862 + append_move(desc, MOVE_WAITCOMP |
10863 + MOVE_SRC_INFIFO | MOVE_DEST_CLASS1CTX |
10864 + (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
10865 + (ivsize << MOVE_LEN_SHIFT));
10866 + append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
10869 + /* Copy IV to class 1 context */
10870 + append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_OUTFIFO |
10871 + (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
10872 + (ivsize << MOVE_LEN_SHIFT));
10874 + /* Return to encryption */
10875 + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
10878 + /* Read and write assoclen bytes */
10879 + if (is_qi || era < 3) {
10880 + append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
10881 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
10883 + append_math_add(desc, VARSEQINLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
10884 + append_math_add(desc, VARSEQOUTLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
10887 + /* Skip assoc data */
10888 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
10890 + /* read assoc before reading payload */
10891 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
10894 + /* Copy iv from outfifo to class 2 fifo */
10895 + moveiv = NFIFOENTRY_STYPE_OFIFO | NFIFOENTRY_DEST_CLASS2 |
10896 + NFIFOENTRY_DTYPE_MSG | (ivsize << NFIFOENTRY_DLEN_SHIFT);
10897 + append_load_imm_u32(desc, moveiv, LDST_CLASS_IND_CCB |
10898 + LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
10899 + append_load_imm_u32(desc, ivsize, LDST_CLASS_2_CCB |
10900 + LDST_SRCDST_WORD_DATASZ_REG | LDST_IMM);
10902 + /* Load Counter into CONTEXT1 reg */
10904 + append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
10905 + LDST_SRCDST_BYTE_CONTEXT |
10906 + ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
10907 + LDST_OFFSET_SHIFT));
10909 + /* Class 1 operation */
10910 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
10913 + /* Will write ivsize + cryptlen */
10914 + append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
10916 + /* Not need to reload iv */
10917 + append_seq_fifo_load(desc, ivsize,
10918 + FIFOLD_CLASS_SKIP);
10920 + /* Will read cryptlen */
10921 + append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
10922 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | KEY_VLF |
10923 + FIFOLD_TYPE_MSG1OUT2 | FIFOLD_TYPE_LASTBOTH);
10924 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
10927 + append_seq_store(desc, icvsize, LDST_CLASS_2_CCB |
10928 + LDST_SRCDST_BYTE_CONTEXT);
10931 + print_hex_dump(KERN_ERR,
10932 + "aead givenc shdesc@" __stringify(__LINE__)": ",
10933 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
10936 +EXPORT_SYMBOL(cnstr_shdsc_aead_givencap);
10939 + * cnstr_shdsc_tls_encap - tls encapsulation shared descriptor
10940 + * @desc: pointer to buffer used for descriptor construction
10941 + * @cdata: pointer to block cipher transform definitions
10942 + * Valid algorithm values - one of OP_ALG_ALGSEL_AES ANDed
10943 + * with OP_ALG_AAI_CBC
10944 + * @adata: pointer to authentication transform definitions.
10945 + * A split key is required for SEC Era < 6; the size of the split key
10946 + * is specified in this case. Valid algorithm values OP_ALG_ALGSEL_SHA1
10947 + * ANDed with OP_ALG_AAI_HMAC_PRECOMP.
10948 + * @assoclen: associated data length
10949 + * @ivsize: initialization vector size
10950 + * @authsize: authentication data size
10951 + * @blocksize: block cipher size
10954 +void cnstr_shdsc_tls_encap(u32 * const desc, struct alginfo *cdata,
10955 + struct alginfo *adata, unsigned int assoclen,
10956 + unsigned int ivsize, unsigned int authsize,
10957 + unsigned int blocksize, int era)
10959 + u32 *key_jump_cmd, *zero_payload_jump_cmd;
10960 + u32 genpad, idx_ld_datasz, idx_ld_pad, stidx;
10963 + * Compute the index (in bytes) for the LOAD with destination of
10964 + * Class 1 Data Size Register and for the LOAD that generates padding
10966 + if (adata->key_inline) {
10967 + idx_ld_datasz = DESC_TLS10_ENC_LEN + adata->keylen_pad +
10968 + cdata->keylen - 4 * CAAM_CMD_SZ;
10969 + idx_ld_pad = DESC_TLS10_ENC_LEN + adata->keylen_pad +
10970 + cdata->keylen - 2 * CAAM_CMD_SZ;
10972 + idx_ld_datasz = DESC_TLS10_ENC_LEN + 2 * CAAM_PTR_SZ -
10974 + idx_ld_pad = DESC_TLS10_ENC_LEN + 2 * CAAM_PTR_SZ -
10978 + stidx = 1 << HDR_START_IDX_SHIFT;
10979 + init_sh_desc(desc, HDR_SHARE_SERIAL | stidx);
10981 + /* skip key loading if they are loaded due to sharing */
10982 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
10986 + if (adata->key_inline)
10987 + append_key_as_imm(desc, adata->key_virt,
10988 + adata->keylen_pad, adata->keylen,
10989 + CLASS_2 | KEY_DEST_MDHA_SPLIT |
10992 + append_key(desc, adata->key_dma, adata->keylen,
10993 + CLASS_2 | KEY_DEST_MDHA_SPLIT | KEY_ENC);
10995 + append_proto_dkp(desc, adata);
10998 + if (cdata->key_inline)
10999 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11000 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
11002 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11003 + KEY_DEST_CLASS_REG);
11005 + set_jump_tgt_here(desc, key_jump_cmd);
11007 + /* class 2 operation */
11008 + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
11010 + /* class 1 operation */
11011 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11014 + /* payloadlen = input data length - (assoclen + ivlen) */
11015 + append_math_sub_imm_u32(desc, REG0, SEQINLEN, IMM, assoclen + ivsize);
11017 + /* math1 = payloadlen + icvlen */
11018 + append_math_add_imm_u32(desc, REG1, REG0, IMM, authsize);
11020 + /* padlen = block_size - math1 % block_size */
11021 + append_math_and_imm_u32(desc, REG3, REG1, IMM, blocksize - 1);
11022 + append_math_sub_imm_u32(desc, REG2, IMM, REG3, blocksize);
11024 + /* cryptlen = payloadlen + icvlen + padlen */
11025 + append_math_add(desc, VARSEQOUTLEN, REG1, REG2, 4);
11028 + * update immediate data with the padding length value
11029 + * for the LOAD in the class 1 data size register.
11031 + append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH2 |
11032 + (idx_ld_datasz << MOVE_OFFSET_SHIFT) | 7);
11033 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH2 | MOVE_DEST_DESCBUF |
11034 + (idx_ld_datasz << MOVE_OFFSET_SHIFT) | 8);
11036 + /* overwrite PL field for the padding iNFO FIFO entry */
11037 + append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH2 |
11038 + (idx_ld_pad << MOVE_OFFSET_SHIFT) | 7);
11039 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH2 | MOVE_DEST_DESCBUF |
11040 + (idx_ld_pad << MOVE_OFFSET_SHIFT) | 8);
11042 + /* store encrypted payload, icv and padding */
11043 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | LDST_VLF);
11045 + /* if payload length is zero, jump to zero-payload commands */
11046 + append_math_add(desc, VARSEQINLEN, ZERO, REG0, 4);
11047 + zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
11048 + JUMP_COND_MATH_Z);
11050 + /* load iv in context1 */
11051 + append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_WORD_CLASS_CTX |
11052 + LDST_CLASS_1_CCB | ivsize);
11054 + /* read assoc for authentication */
11055 + append_seq_fifo_load(desc, assoclen, FIFOLD_CLASS_CLASS2 |
11056 + FIFOLD_TYPE_MSG);
11057 + /* insnoop payload */
11058 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | FIFOLD_TYPE_MSG |
11059 + FIFOLD_TYPE_LAST2 | FIFOLDST_VLF);
11061 + /* jump the zero-payload commands */
11062 + append_jump(desc, JUMP_TEST_ALL | 3);
11064 + /* zero-payload commands */
11065 + set_jump_tgt_here(desc, zero_payload_jump_cmd);
11067 + /* load iv in context1 */
11068 + append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_WORD_CLASS_CTX |
11069 + LDST_CLASS_1_CCB | ivsize);
11071 + /* assoc data is the only data for authentication */
11072 + append_seq_fifo_load(desc, assoclen, FIFOLD_CLASS_CLASS2 |
11073 + FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST2);
11075 + /* send icv to encryption */
11076 + append_move(desc, MOVE_SRC_CLASS2CTX | MOVE_DEST_CLASS1INFIFO |
11079 + /* update class 1 data size register with padding length */
11080 + append_load_imm_u32(desc, 0, LDST_CLASS_1_CCB |
11081 + LDST_SRCDST_WORD_DATASZ_REG | LDST_IMM);
11083 + /* generate padding and send it to encryption */
11084 + genpad = NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_LC1 | NFIFOENTRY_FC1 |
11085 + NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_PTYPE_N;
11086 + append_load_imm_u32(desc, genpad, LDST_CLASS_IND_CCB |
11087 + LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
11090 + print_hex_dump(KERN_ERR, "tls enc shdesc@" __stringify(__LINE__) ": ",
11091 + DUMP_PREFIX_ADDRESS, 16, 4, desc,
11092 + desc_bytes(desc), 1);
11095 +EXPORT_SYMBOL(cnstr_shdsc_tls_encap);
11098 + * cnstr_shdsc_tls_decap - tls decapsulation shared descriptor
11099 + * @desc: pointer to buffer used for descriptor construction
11100 + * @cdata: pointer to block cipher transform definitions
11101 + * Valid algorithm values - one of OP_ALG_ALGSEL_AES ANDed
11102 + * with OP_ALG_AAI_CBC
11103 + * @adata: pointer to authentication transform definitions.
11104 + * A split key is required for SEC Era < 6; the size of the split key
11105 + * is specified in this case. Valid algorithm values OP_ALG_ALGSEL_SHA1
11106 + * ANDed with OP_ALG_AAI_HMAC_PRECOMP.
11107 + * @assoclen: associated data length
11108 + * @ivsize: initialization vector size
11109 + * @authsize: authentication data size
11110 + * @blocksize: block cipher size
11113 +void cnstr_shdsc_tls_decap(u32 * const desc, struct alginfo *cdata,
11114 + struct alginfo *adata, unsigned int assoclen,
11115 + unsigned int ivsize, unsigned int authsize,
11116 + unsigned int blocksize, int era)
11118 + u32 stidx, jumpback;
11119 + u32 *key_jump_cmd, *zero_payload_jump_cmd, *skip_zero_jump_cmd;
11121 + * Pointer Size bool determines the size of address pointers.
11122 + * false - Pointers fit in one 32-bit word.
11123 + * true - Pointers fit in two 32-bit words.
11125 + static const bool ps = (CAAM_PTR_SZ != CAAM_CMD_SZ);
11127 + stidx = 1 << HDR_START_IDX_SHIFT;
11128 + init_sh_desc(desc, HDR_SHARE_SERIAL | stidx);
11130 + /* skip key loading if they are loaded due to sharing */
11131 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11135 + append_key(desc, adata->key_dma, adata->keylen, CLASS_2 |
11136 + KEY_DEST_MDHA_SPLIT | KEY_ENC);
11138 + append_proto_dkp(desc, adata);
11140 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11141 + KEY_DEST_CLASS_REG);
11143 + set_jump_tgt_here(desc, key_jump_cmd);
11145 + /* class 2 operation */
11146 + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
11147 + OP_ALG_DECRYPT | OP_ALG_ICV_ON);
11148 + /* class 1 operation */
11149 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11152 + /* VSIL = input data length - 2 * block_size */
11153 + append_math_sub_imm_u32(desc, VARSEQINLEN, SEQINLEN, IMM, 2 *
11157 + * payloadlen + icvlen + padlen = input data length - (assoclen +
11160 + append_math_sub_imm_u32(desc, REG3, SEQINLEN, IMM, assoclen + ivsize);
11162 + /* skip data to the last but one cipher block */
11163 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_SKIP | LDST_VLF);
11165 + /* load iv for the last cipher block */
11166 + append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_WORD_CLASS_CTX |
11167 + LDST_CLASS_1_CCB | ivsize);
11169 + /* read last cipher block */
11170 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG |
11171 + FIFOLD_TYPE_LAST1 | blocksize);
11173 + /* move decrypted block into math0 and math1 */
11174 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_OUTFIFO | MOVE_DEST_MATH0 |
11177 + /* reset AES CHA */
11178 + append_load_imm_u32(desc, CCTRL_RESET_CHA_AESA, LDST_CLASS_IND_CCB |
11179 + LDST_SRCDST_WORD_CHACTRL | LDST_IMM);
11181 + /* rewind input sequence */
11182 + append_seq_in_ptr_intlen(desc, 0, 65535, SQIN_RTO);
11184 + /* key1 is in decryption form */
11185 + append_operation(desc, cdata->algtype | OP_ALG_AAI_DK |
11186 + OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
11188 + /* load iv in context1 */
11189 + append_cmd(desc, CMD_SEQ_LOAD | LDST_CLASS_1_CCB |
11190 + LDST_SRCDST_WORD_CLASS_CTX | ivsize);
11192 + /* read sequence number */
11193 + append_seq_fifo_load(desc, 8, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG);
11194 + /* load Type, Version and Len fields in math0 */
11195 + append_cmd(desc, CMD_SEQ_LOAD | LDST_CLASS_DECO |
11196 + LDST_SRCDST_WORD_DECO_MATH0 | (3 << LDST_OFFSET_SHIFT) | 5);
11198 + /* compute (padlen - 1) */
11199 + append_math_and_imm_u64(desc, REG1, REG1, IMM, 255);
11201 + /* math2 = icvlen + (padlen - 1) + 1 */
11202 + append_math_add_imm_u32(desc, REG2, REG1, IMM, authsize + 1);
11204 + append_jump(desc, JUMP_TEST_ALL | JUMP_COND_CALM | 1);
11206 + /* VSOL = payloadlen + icvlen + padlen */
11207 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, 4);
11209 +#ifdef __LITTLE_ENDIAN
11210 + append_moveb(desc, MOVE_WAITCOMP |
11211 + MOVE_SRC_MATH0 | MOVE_DEST_MATH0 | 8);
11213 + /* update Len field */
11214 + append_math_sub(desc, REG0, REG0, REG2, 8);
11216 + /* store decrypted payload, icv and padding */
11217 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | LDST_VLF);
11219 + /* VSIL = (payloadlen + icvlen + padlen) - (icvlen + padlen)*/
11220 + append_math_sub(desc, VARSEQINLEN, REG3, REG2, 4);
11222 + zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
11223 + JUMP_COND_MATH_Z);
11225 + /* send Type, Version and Len(pre ICV) fields to authentication */
11226 + append_move(desc, MOVE_WAITCOMP |
11227 + MOVE_SRC_MATH0 | MOVE_DEST_CLASS2INFIFO |
11228 + (3 << MOVE_OFFSET_SHIFT) | 5);
11230 + /* outsnooping payload */
11231 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH |
11232 + FIFOLD_TYPE_MSG1OUT2 | FIFOLD_TYPE_LAST2 |
11234 + skip_zero_jump_cmd = append_jump(desc, JUMP_TEST_ALL | 2);
11236 + set_jump_tgt_here(desc, zero_payload_jump_cmd);
11237 + /* send Type, Version and Len(pre ICV) fields to authentication */
11238 + append_move(desc, MOVE_WAITCOMP | MOVE_AUX_LS |
11239 + MOVE_SRC_MATH0 | MOVE_DEST_CLASS2INFIFO |
11240 + (3 << MOVE_OFFSET_SHIFT) | 5);
11242 + set_jump_tgt_here(desc, skip_zero_jump_cmd);
11243 + append_math_add(desc, VARSEQINLEN, ZERO, REG2, 4);
11245 + /* load icvlen and padlen */
11246 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG |
11247 + FIFOLD_TYPE_LAST1 | FIFOLDST_VLF);
11249 + /* VSIL = (payloadlen + icvlen + padlen) - icvlen + padlen */
11250 + append_math_sub(desc, VARSEQINLEN, REG3, REG2, 4);
11253 + * Start a new input sequence using the SEQ OUT PTR command options,
11254 + * pointer and length used when the current output sequence was defined.
11258 + * Move the lower 32 bits of Shared Descriptor address, the
11259 + * SEQ OUT PTR command, Output Pointer (2 words) and
11260 + * Output Length into math registers.
11262 +#ifdef __LITTLE_ENDIAN
11263 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF |
11264 + MOVE_DEST_MATH0 | (55 * 4 << MOVE_OFFSET_SHIFT) |
11267 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF |
11268 + MOVE_DEST_MATH0 | (54 * 4 << MOVE_OFFSET_SHIFT) |
11271 + /* Transform SEQ OUT PTR command in SEQ IN PTR command */
11272 + append_math_and_imm_u32(desc, REG0, REG0, IMM,
11273 + ~(CMD_SEQ_IN_PTR ^ CMD_SEQ_OUT_PTR));
11274 + /* Append a JUMP command after the copied fields */
11275 + jumpback = CMD_JUMP | (char)-9;
11276 + append_load_imm_u32(desc, jumpback, LDST_CLASS_DECO | LDST_IMM |
11277 + LDST_SRCDST_WORD_DECO_MATH2 |
11278 + (4 << LDST_OFFSET_SHIFT));
11279 + append_jump(desc, JUMP_TEST_ALL | JUMP_COND_CALM | 1);
11280 + /* Move the updated fields back to the Job Descriptor */
11281 +#ifdef __LITTLE_ENDIAN
11282 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 |
11283 + MOVE_DEST_DESCBUF | (55 * 4 << MOVE_OFFSET_SHIFT) |
11286 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 |
11287 + MOVE_DEST_DESCBUF | (54 * 4 << MOVE_OFFSET_SHIFT) |
11291 + * Read the new SEQ IN PTR command, Input Pointer, Input Length
11292 + * and then jump back to the next command from the
11293 + * Shared Descriptor.
11295 + append_jump(desc, JUMP_TEST_ALL | JUMP_COND_CALM | 6);
11298 + * Move the SEQ OUT PTR command, Output Pointer (1 word) and
11299 + * Output Length into math registers.
11301 +#ifdef __LITTLE_ENDIAN
11302 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF |
11303 + MOVE_DEST_MATH0 | (54 * 4 << MOVE_OFFSET_SHIFT) |
11306 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF |
11307 + MOVE_DEST_MATH0 | (53 * 4 << MOVE_OFFSET_SHIFT) |
11310 + /* Transform SEQ OUT PTR command in SEQ IN PTR command */
11311 + append_math_and_imm_u64(desc, REG0, REG0, IMM,
11312 + ~(((u64)(CMD_SEQ_IN_PTR ^
11313 + CMD_SEQ_OUT_PTR)) << 32));
11314 + /* Append a JUMP command after the copied fields */
11315 + jumpback = CMD_JUMP | (char)-7;
11316 + append_load_imm_u32(desc, jumpback, LDST_CLASS_DECO | LDST_IMM |
11317 + LDST_SRCDST_WORD_DECO_MATH1 |
11318 + (4 << LDST_OFFSET_SHIFT));
11319 + append_jump(desc, JUMP_TEST_ALL | JUMP_COND_CALM | 1);
11320 + /* Move the updated fields back to the Job Descriptor */
11321 +#ifdef __LITTLE_ENDIAN
11322 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 |
11323 + MOVE_DEST_DESCBUF | (54 * 4 << MOVE_OFFSET_SHIFT) |
11326 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 |
11327 + MOVE_DEST_DESCBUF | (53 * 4 << MOVE_OFFSET_SHIFT) |
11331 + * Read the new SEQ IN PTR command, Input Pointer, Input Length
11332 + * and then jump back to the next command from the
11333 + * Shared Descriptor.
11335 + append_jump(desc, JUMP_TEST_ALL | JUMP_COND_CALM | 5);
11338 + /* skip payload */
11339 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_SKIP | FIFOLDST_VLF);
11341 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_ICV |
11342 + FIFOLD_TYPE_LAST2 | authsize);
11345 + print_hex_dump(KERN_ERR, "tls dec shdesc@" __stringify(__LINE__) ": ",
11346 + DUMP_PREFIX_ADDRESS, 16, 4, desc,
11347 + desc_bytes(desc), 1);
11350 +EXPORT_SYMBOL(cnstr_shdsc_tls_decap);
11353 + * cnstr_shdsc_gcm_encap - gcm encapsulation shared descriptor
11354 + * @desc: pointer to buffer used for descriptor construction
11355 + * @cdata: pointer to block cipher transform definitions
11356 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_GCM.
11357 + * @ivsize: initialization vector size
11358 + * @icvsize: integrity check value (ICV) size (truncated or full)
11359 + * @is_qi: true when called from caam/qi
11361 +void cnstr_shdsc_gcm_encap(u32 * const desc, struct alginfo *cdata,
11362 + unsigned int ivsize, unsigned int icvsize,
11363 + const bool is_qi)
11365 + u32 *key_jump_cmd, *zero_payload_jump_cmd, *zero_assoc_jump_cmd1,
11366 + *zero_assoc_jump_cmd2;
11368 + init_sh_desc(desc, HDR_SHARE_SERIAL);
11370 + /* skip key loading if they are loaded due to sharing */
11371 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11373 + if (cdata->key_inline)
11374 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11375 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
11377 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11378 + KEY_DEST_CLASS_REG);
11379 + set_jump_tgt_here(desc, key_jump_cmd);
11381 + /* class 1 operation */
11382 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11386 + u32 *wait_load_cmd;
11388 + /* REG3 = assoclen */
11389 + append_seq_load(desc, 4, LDST_CLASS_DECO |
11390 + LDST_SRCDST_WORD_DECO_MATH3 |
11391 + (4 << LDST_OFFSET_SHIFT));
11393 + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11394 + JUMP_COND_CALM | JUMP_COND_NCP |
11395 + JUMP_COND_NOP | JUMP_COND_NIP |
11397 + set_jump_tgt_here(desc, wait_load_cmd);
11399 + append_math_sub_imm_u32(desc, VARSEQOUTLEN, SEQINLEN, IMM,
11402 + append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0,
11406 + /* if assoclen + cryptlen is ZERO, skip to ICV write */
11407 + zero_assoc_jump_cmd2 = append_jump(desc, JUMP_TEST_ALL |
11408 + JUMP_COND_MATH_Z);
11411 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
11412 + FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
11414 + /* if assoclen is ZERO, skip reading the assoc data */
11415 + append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
11416 + zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
11417 + JUMP_COND_MATH_Z);
11419 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
11421 + /* skip assoc data */
11422 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
11424 + /* cryptlen = seqinlen - assoclen */
11425 + append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ);
11427 + /* if cryptlen is ZERO jump to zero-payload commands */
11428 + zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
11429 + JUMP_COND_MATH_Z);
11431 + /* read assoc data */
11432 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11433 + FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
11434 + set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
11436 + append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
11438 + /* write encrypted data */
11439 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
11441 + /* read payload data */
11442 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11443 + FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
11445 + /* jump to ICV writing */
11447 + append_jump(desc, JUMP_TEST_ALL | 4);
11449 + append_jump(desc, JUMP_TEST_ALL | 2);
11451 + /* zero-payload commands */
11452 + set_jump_tgt_here(desc, zero_payload_jump_cmd);
11454 + /* read assoc data */
11455 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11456 + FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1);
11458 + /* jump to ICV writing */
11459 + append_jump(desc, JUMP_TEST_ALL | 2);
11461 + /* There is no input data */
11462 + set_jump_tgt_here(desc, zero_assoc_jump_cmd2);
11465 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
11466 + FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 |
11467 + FIFOLD_TYPE_LAST1);
11470 + append_seq_store(desc, icvsize, LDST_CLASS_1_CCB |
11471 + LDST_SRCDST_BYTE_CONTEXT);
11474 + print_hex_dump(KERN_ERR, "gcm enc shdesc@" __stringify(__LINE__)": ",
11475 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
11478 +EXPORT_SYMBOL(cnstr_shdsc_gcm_encap);
11481 + * cnstr_shdsc_gcm_decap - gcm decapsulation shared descriptor
11482 + * @desc: pointer to buffer used for descriptor construction
11483 + * @cdata: pointer to block cipher transform definitions
11484 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_GCM.
11485 + * @ivsize: initialization vector size
11486 + * @icvsize: integrity check value (ICV) size (truncated or full)
11487 + * @is_qi: true when called from caam/qi
11489 +void cnstr_shdsc_gcm_decap(u32 * const desc, struct alginfo *cdata,
11490 + unsigned int ivsize, unsigned int icvsize,
11491 + const bool is_qi)
11493 + u32 *key_jump_cmd, *zero_payload_jump_cmd, *zero_assoc_jump_cmd1;
11495 + init_sh_desc(desc, HDR_SHARE_SERIAL);
11497 + /* skip key loading if they are loaded due to sharing */
11498 + key_jump_cmd = append_jump(desc, JUMP_JSL |
11499 + JUMP_TEST_ALL | JUMP_COND_SHRD);
11500 + if (cdata->key_inline)
11501 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11502 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
11504 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11505 + KEY_DEST_CLASS_REG);
11506 + set_jump_tgt_here(desc, key_jump_cmd);
11508 + /* class 1 operation */
11509 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11510 + OP_ALG_DECRYPT | OP_ALG_ICV_ON);
11513 + u32 *wait_load_cmd;
11515 + /* REG3 = assoclen */
11516 + append_seq_load(desc, 4, LDST_CLASS_DECO |
11517 + LDST_SRCDST_WORD_DECO_MATH3 |
11518 + (4 << LDST_OFFSET_SHIFT));
11520 + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11521 + JUMP_COND_CALM | JUMP_COND_NCP |
11522 + JUMP_COND_NOP | JUMP_COND_NIP |
11524 + set_jump_tgt_here(desc, wait_load_cmd);
11526 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
11527 + FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
11530 + /* if assoclen is ZERO, skip reading the assoc data */
11531 + append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
11532 + zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
11533 + JUMP_COND_MATH_Z);
11535 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
11537 + /* skip assoc data */
11538 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
11540 + /* read assoc data */
11541 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11542 + FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
11544 + set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
11546 + /* cryptlen = seqoutlen - assoclen */
11547 + append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
11549 + /* jump to zero-payload command if cryptlen is zero */
11550 + zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
11551 + JUMP_COND_MATH_Z);
11553 + append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
11555 + /* store encrypted data */
11556 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
11558 + /* read payload data */
11559 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11560 + FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
11562 + /* zero-payload command */
11563 + set_jump_tgt_here(desc, zero_payload_jump_cmd);
11566 + append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 |
11567 + FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
11570 + print_hex_dump(KERN_ERR, "gcm dec shdesc@" __stringify(__LINE__)": ",
11571 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
11574 +EXPORT_SYMBOL(cnstr_shdsc_gcm_decap);
11577 + * cnstr_shdsc_rfc4106_encap - IPSec ESP gcm encapsulation shared descriptor
11578 + * (non-protocol).
11579 + * @desc: pointer to buffer used for descriptor construction
11580 + * @cdata: pointer to block cipher transform definitions
11581 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_GCM.
11582 + * @ivsize: initialization vector size
11583 + * @icvsize: integrity check value (ICV) size (truncated or full)
11584 + * @is_qi: true when called from caam/qi
11586 +void cnstr_shdsc_rfc4106_encap(u32 * const desc, struct alginfo *cdata,
11587 + unsigned int ivsize, unsigned int icvsize,
11588 + const bool is_qi)
11590 + u32 *key_jump_cmd;
11592 + init_sh_desc(desc, HDR_SHARE_SERIAL);
11594 + /* Skip key loading if it is loaded due to sharing */
11595 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11597 + if (cdata->key_inline)
11598 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11599 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
11601 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11602 + KEY_DEST_CLASS_REG);
11603 + set_jump_tgt_here(desc, key_jump_cmd);
11605 + /* Class 1 operation */
11606 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11610 + u32 *wait_load_cmd;
11612 + /* REG3 = assoclen */
11613 + append_seq_load(desc, 4, LDST_CLASS_DECO |
11614 + LDST_SRCDST_WORD_DECO_MATH3 |
11615 + (4 << LDST_OFFSET_SHIFT));
11617 + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11618 + JUMP_COND_CALM | JUMP_COND_NCP |
11619 + JUMP_COND_NOP | JUMP_COND_NIP |
11621 + set_jump_tgt_here(desc, wait_load_cmd);
11623 + /* Read salt and IV */
11624 + append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
11625 + cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
11627 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
11628 + FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
11631 + append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, ivsize);
11632 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
11634 + /* Read assoc data */
11635 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11636 + FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
11639 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_SKIP);
11641 + /* Will read cryptlen bytes */
11642 + append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
11644 + /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
11645 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
11647 + /* Skip assoc data */
11648 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
11650 + /* cryptlen = seqoutlen - assoclen */
11651 + append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ);
11653 + /* Write encrypted data */
11654 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
11656 + /* Read payload data */
11657 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11658 + FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
11661 + append_seq_store(desc, icvsize, LDST_CLASS_1_CCB |
11662 + LDST_SRCDST_BYTE_CONTEXT);
11665 + print_hex_dump(KERN_ERR,
11666 + "rfc4106 enc shdesc@" __stringify(__LINE__)": ",
11667 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
11670 +EXPORT_SYMBOL(cnstr_shdsc_rfc4106_encap);
11673 + * cnstr_shdsc_rfc4106_decap - IPSec ESP gcm decapsulation shared descriptor
11674 + * (non-protocol).
11675 + * @desc: pointer to buffer used for descriptor construction
11676 + * @cdata: pointer to block cipher transform definitions
11677 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_GCM.
11678 + * @ivsize: initialization vector size
11679 + * @icvsize: integrity check value (ICV) size (truncated or full)
11680 + * @is_qi: true when called from caam/qi
11682 +void cnstr_shdsc_rfc4106_decap(u32 * const desc, struct alginfo *cdata,
11683 + unsigned int ivsize, unsigned int icvsize,
11684 + const bool is_qi)
11686 + u32 *key_jump_cmd;
11688 + init_sh_desc(desc, HDR_SHARE_SERIAL);
11690 + /* Skip key loading if it is loaded due to sharing */
11691 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11693 + if (cdata->key_inline)
11694 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11695 + cdata->keylen, CLASS_1 |
11696 + KEY_DEST_CLASS_REG);
11698 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11699 + KEY_DEST_CLASS_REG);
11700 + set_jump_tgt_here(desc, key_jump_cmd);
11702 + /* Class 1 operation */
11703 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11704 + OP_ALG_DECRYPT | OP_ALG_ICV_ON);
11707 + u32 *wait_load_cmd;
11709 + /* REG3 = assoclen */
11710 + append_seq_load(desc, 4, LDST_CLASS_DECO |
11711 + LDST_SRCDST_WORD_DECO_MATH3 |
11712 + (4 << LDST_OFFSET_SHIFT));
11714 + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11715 + JUMP_COND_CALM | JUMP_COND_NCP |
11716 + JUMP_COND_NOP | JUMP_COND_NIP |
11718 + set_jump_tgt_here(desc, wait_load_cmd);
11720 + /* Read salt and IV */
11721 + append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
11722 + cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
11724 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
11725 + FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
11728 + append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, ivsize);
11729 + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
11731 + /* Read assoc data */
11732 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11733 + FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
11736 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_SKIP);
11738 + /* Will read cryptlen bytes */
11739 + append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ);
11741 + /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
11742 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
11744 + /* Skip assoc data */
11745 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
11747 + /* Will write cryptlen bytes */
11748 + append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
11750 + /* Store payload data */
11751 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
11753 + /* Read encrypted data */
11754 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
11755 + FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
11758 + append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 |
11759 + FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
11762 + print_hex_dump(KERN_ERR,
11763 + "rfc4106 dec shdesc@" __stringify(__LINE__)": ",
11764 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
11767 +EXPORT_SYMBOL(cnstr_shdsc_rfc4106_decap);
11770 + * cnstr_shdsc_rfc4543_encap - IPSec ESP gmac encapsulation shared descriptor
11771 + * (non-protocol).
11772 + * @desc: pointer to buffer used for descriptor construction
11773 + * @cdata: pointer to block cipher transform definitions
11774 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_GCM.
11775 + * @ivsize: initialization vector size
11776 + * @icvsize: integrity check value (ICV) size (truncated or full)
11777 + * @is_qi: true when called from caam/qi
11779 +void cnstr_shdsc_rfc4543_encap(u32 * const desc, struct alginfo *cdata,
11780 + unsigned int ivsize, unsigned int icvsize,
11781 + const bool is_qi)
11783 + u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd;
11785 + init_sh_desc(desc, HDR_SHARE_SERIAL);
11787 + /* Skip key loading if it is loaded due to sharing */
11788 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11790 + if (cdata->key_inline)
11791 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11792 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
11794 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11795 + KEY_DEST_CLASS_REG);
11796 + set_jump_tgt_here(desc, key_jump_cmd);
11798 + /* Class 1 operation */
11799 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11803 + /* assoclen is not needed, skip it */
11804 + append_seq_fifo_load(desc, 4, FIFOLD_CLASS_SKIP);
11806 + /* Read salt and IV */
11807 + append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
11808 + cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
11810 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
11811 + FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
11814 + /* assoclen + cryptlen = seqinlen */
11815 + append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
11818 + * MOVE_LEN opcode is not available in all SEC HW revisions,
11819 + * thus need to do some magic, i.e. self-patch the descriptor
11822 + read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
11823 + (0x6 << MOVE_LEN_SHIFT));
11824 + write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
11825 + (0x8 << MOVE_LEN_SHIFT));
11827 + /* Will read assoclen + cryptlen bytes */
11828 + append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
11830 + /* Will write assoclen + cryptlen bytes */
11831 + append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
11833 + /* Read and write assoclen + cryptlen bytes */
11834 + aead_append_src_dst(desc, FIFOLD_TYPE_AAD);
11836 + set_move_tgt_here(desc, read_move_cmd);
11837 + set_move_tgt_here(desc, write_move_cmd);
11838 + append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
11839 + /* Move payload data to OFIFO */
11840 + append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
11843 + append_seq_store(desc, icvsize, LDST_CLASS_1_CCB |
11844 + LDST_SRCDST_BYTE_CONTEXT);
11847 + print_hex_dump(KERN_ERR,
11848 + "rfc4543 enc shdesc@" __stringify(__LINE__)": ",
11849 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
11852 +EXPORT_SYMBOL(cnstr_shdsc_rfc4543_encap);
11855 + * cnstr_shdsc_rfc4543_decap - IPSec ESP gmac decapsulation shared descriptor
11856 + * (non-protocol).
11857 + * @desc: pointer to buffer used for descriptor construction
11858 + * @cdata: pointer to block cipher transform definitions
11859 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_GCM.
11860 + * @ivsize: initialization vector size
11861 + * @icvsize: integrity check value (ICV) size (truncated or full)
11862 + * @is_qi: true when called from caam/qi
11864 +void cnstr_shdsc_rfc4543_decap(u32 * const desc, struct alginfo *cdata,
11865 + unsigned int ivsize, unsigned int icvsize,
11866 + const bool is_qi)
11868 + u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd;
11870 + init_sh_desc(desc, HDR_SHARE_SERIAL);
11872 + /* Skip key loading if it is loaded due to sharing */
11873 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11875 + if (cdata->key_inline)
11876 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11877 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
11879 + append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
11880 + KEY_DEST_CLASS_REG);
11881 + set_jump_tgt_here(desc, key_jump_cmd);
11883 + /* Class 1 operation */
11884 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
11885 + OP_ALG_DECRYPT | OP_ALG_ICV_ON);
11888 + /* assoclen is not needed, skip it */
11889 + append_seq_fifo_load(desc, 4, FIFOLD_CLASS_SKIP);
11891 + /* Read salt and IV */
11892 + append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
11893 + cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
11895 + append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
11896 + FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
11899 + /* assoclen + cryptlen = seqoutlen */
11900 + append_math_sub(desc, REG3, SEQOUTLEN, REG0, CAAM_CMD_SZ);
11903 + * MOVE_LEN opcode is not available in all SEC HW revisions,
11904 + * thus need to do some magic, i.e. self-patch the descriptor
11907 + read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
11908 + (0x6 << MOVE_LEN_SHIFT));
11909 + write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
11910 + (0x8 << MOVE_LEN_SHIFT));
11912 + /* Will read assoclen + cryptlen bytes */
11913 + append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
11915 + /* Will write assoclen + cryptlen bytes */
11916 + append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
11918 + /* Store payload data */
11919 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
11921 + /* In-snoop assoclen + cryptlen data */
11922 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | FIFOLDST_VLF |
11923 + FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST2FLUSH1);
11925 + set_move_tgt_here(desc, read_move_cmd);
11926 + set_move_tgt_here(desc, write_move_cmd);
11927 + append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
11928 + /* Move payload data to OFIFO */
11929 + append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
11930 + append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
11933 + append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 |
11934 + FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
11937 + print_hex_dump(KERN_ERR,
11938 + "rfc4543 dec shdesc@" __stringify(__LINE__)": ",
11939 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
11942 +EXPORT_SYMBOL(cnstr_shdsc_rfc4543_decap);
11945 + * For ablkcipher encrypt and decrypt, read from req->src and
11946 + * write to req->dst
11948 +static inline void ablkcipher_append_src_dst(u32 *desc)
11950 + append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
11951 + append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
11952 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 |
11953 + KEY_VLF | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
11954 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
11958 + * cnstr_shdsc_ablkcipher_encap - ablkcipher encapsulation shared descriptor
11959 + * @desc: pointer to buffer used for descriptor construction
11960 + * @cdata: pointer to block cipher transform definitions
11961 + * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
11962 + * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128.
11963 + * @ivsize: initialization vector size
11964 + * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
11965 + * @ctx1_iv_off: IV offset in CONTEXT1 register
11967 +void cnstr_shdsc_ablkcipher_encap(u32 * const desc, struct alginfo *cdata,
11968 + unsigned int ivsize, const bool is_rfc3686,
11969 + const u32 ctx1_iv_off)
11971 + u32 *key_jump_cmd;
11973 + init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
11974 + /* Skip if already shared */
11975 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
11978 + /* Load class1 key only */
11979 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
11980 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
11982 + /* Load nonce into CONTEXT1 reg */
11983 + if (is_rfc3686) {
11984 + const u8 *nonce = cdata->key_virt + cdata->keylen;
11986 + append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
11987 + LDST_CLASS_IND_CCB |
11988 + LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
11989 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_OUTFIFO |
11990 + MOVE_DEST_CLASS1CTX | (16 << MOVE_OFFSET_SHIFT) |
11991 + (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
11994 + set_jump_tgt_here(desc, key_jump_cmd);
11997 + append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT |
11998 + LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
12000 + /* Load counter into CONTEXT1 reg */
12002 + append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
12003 + LDST_SRCDST_BYTE_CONTEXT |
12004 + ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
12005 + LDST_OFFSET_SHIFT));
12007 + /* Load operation */
12008 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
12011 + /* Perform operation */
12012 + ablkcipher_append_src_dst(desc);
12015 + print_hex_dump(KERN_ERR,
12016 + "ablkcipher enc shdesc@" __stringify(__LINE__)": ",
12017 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
12020 +EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_encap);
12023 + * cnstr_shdsc_ablkcipher_decap - ablkcipher decapsulation shared descriptor
12024 + * @desc: pointer to buffer used for descriptor construction
12025 + * @cdata: pointer to block cipher transform definitions
12026 + * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
12027 + * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128.
12028 + * @ivsize: initialization vector size
12029 + * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
12030 + * @ctx1_iv_off: IV offset in CONTEXT1 register
12032 +void cnstr_shdsc_ablkcipher_decap(u32 * const desc, struct alginfo *cdata,
12033 + unsigned int ivsize, const bool is_rfc3686,
12034 + const u32 ctx1_iv_off)
12036 + u32 *key_jump_cmd;
12038 + init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
12039 + /* Skip if already shared */
12040 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
12043 + /* Load class1 key only */
12044 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
12045 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
12047 + /* Load nonce into CONTEXT1 reg */
12048 + if (is_rfc3686) {
12049 + const u8 *nonce = cdata->key_virt + cdata->keylen;
12051 + append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
12052 + LDST_CLASS_IND_CCB |
12053 + LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
12054 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_OUTFIFO |
12055 + MOVE_DEST_CLASS1CTX | (16 << MOVE_OFFSET_SHIFT) |
12056 + (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
12059 + set_jump_tgt_here(desc, key_jump_cmd);
12062 + append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT |
12063 + LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
12065 + /* Load counter into CONTEXT1 reg */
12067 + append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
12068 + LDST_SRCDST_BYTE_CONTEXT |
12069 + ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
12070 + LDST_OFFSET_SHIFT));
12072 + /* Choose operation */
12074 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
12077 + append_dec_op1(desc, cdata->algtype);
12079 + /* Perform operation */
12080 + ablkcipher_append_src_dst(desc);
12083 + print_hex_dump(KERN_ERR,
12084 + "ablkcipher dec shdesc@" __stringify(__LINE__)": ",
12085 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
12088 +EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_decap);
12091 + * cnstr_shdsc_ablkcipher_givencap - ablkcipher encapsulation shared descriptor
12092 + * with HW-generated initialization vector.
12093 + * @desc: pointer to buffer used for descriptor construction
12094 + * @cdata: pointer to block cipher transform definitions
12095 + * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
12096 + * with OP_ALG_AAI_CBC.
12097 + * @ivsize: initialization vector size
12098 + * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
12099 + * @ctx1_iv_off: IV offset in CONTEXT1 register
12101 +void cnstr_shdsc_ablkcipher_givencap(u32 * const desc, struct alginfo *cdata,
12102 + unsigned int ivsize, const bool is_rfc3686,
12103 + const u32 ctx1_iv_off)
12105 + u32 *key_jump_cmd, geniv;
12107 + init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
12108 + /* Skip if already shared */
12109 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
12112 + /* Load class1 key only */
12113 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
12114 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
12116 + /* Load Nonce into CONTEXT1 reg */
12117 + if (is_rfc3686) {
12118 + const u8 *nonce = cdata->key_virt + cdata->keylen;
12120 + append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
12121 + LDST_CLASS_IND_CCB |
12122 + LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
12123 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_OUTFIFO |
12124 + MOVE_DEST_CLASS1CTX | (16 << MOVE_OFFSET_SHIFT) |
12125 + (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
12127 + set_jump_tgt_here(desc, key_jump_cmd);
12129 + /* Generate IV */
12130 + geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
12131 + NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 | NFIFOENTRY_PTYPE_RND |
12132 + (ivsize << NFIFOENTRY_DLEN_SHIFT);
12133 + append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
12134 + LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
12135 + append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
12136 + append_move(desc, MOVE_WAITCOMP | MOVE_SRC_INFIFO |
12137 + MOVE_DEST_CLASS1CTX | (ivsize << MOVE_LEN_SHIFT) |
12138 + (ctx1_iv_off << MOVE_OFFSET_SHIFT));
12139 + append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
12141 + /* Copy generated IV to memory */
12142 + append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT |
12143 + LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
12145 + /* Load Counter into CONTEXT1 reg */
12147 + append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
12148 + LDST_SRCDST_BYTE_CONTEXT |
12149 + ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
12150 + LDST_OFFSET_SHIFT));
12153 + append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NCP |
12154 + (1 << JUMP_OFFSET_SHIFT));
12156 + /* Load operation */
12157 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
12160 + /* Perform operation */
12161 + ablkcipher_append_src_dst(desc);
12164 + print_hex_dump(KERN_ERR,
12165 + "ablkcipher givenc shdesc@" __stringify(__LINE__) ": ",
12166 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
12169 +EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_givencap);
12172 + * cnstr_shdsc_xts_ablkcipher_encap - xts ablkcipher encapsulation shared
12174 + * @desc: pointer to buffer used for descriptor construction
12175 + * @cdata: pointer to block cipher transform definitions
12176 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS.
12178 +void cnstr_shdsc_xts_ablkcipher_encap(u32 * const desc, struct alginfo *cdata)
12180 + __be64 sector_size = cpu_to_be64(512);
12181 + u32 *key_jump_cmd;
12183 + init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
12184 + /* Skip if already shared */
12185 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
12188 + /* Load class1 keys only */
12189 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
12190 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
12192 + /* Load sector size with index 40 bytes (0x28) */
12193 + append_load_as_imm(desc, (void *)§or_size, 8, LDST_CLASS_1_CCB |
12194 + LDST_SRCDST_BYTE_CONTEXT |
12195 + (0x28 << LDST_OFFSET_SHIFT));
12197 + set_jump_tgt_here(desc, key_jump_cmd);
12200 + * create sequence for loading the sector index
12201 + * Upper 8B of IV - will be used as sector index
12202 + * Lower 8B of IV - will be discarded
12204 + append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
12205 + (0x20 << LDST_OFFSET_SHIFT));
12206 + append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
12208 + /* Load operation */
12209 + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
12212 + /* Perform operation */
12213 + ablkcipher_append_src_dst(desc);
12216 + print_hex_dump(KERN_ERR,
12217 + "xts ablkcipher enc shdesc@" __stringify(__LINE__) ": ",
12218 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
12221 +EXPORT_SYMBOL(cnstr_shdsc_xts_ablkcipher_encap);
12224 + * cnstr_shdsc_xts_ablkcipher_decap - xts ablkcipher decapsulation shared
12226 + * @desc: pointer to buffer used for descriptor construction
12227 + * @cdata: pointer to block cipher transform definitions
12228 + * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS.
12230 +void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata)
12232 + __be64 sector_size = cpu_to_be64(512);
12233 + u32 *key_jump_cmd;
12235 + init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
12236 + /* Skip if already shared */
12237 + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
12240 + /* Load class1 key only */
12241 + append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
12242 + cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
12244 + /* Load sector size with index 40 bytes (0x28) */
12245 + append_load_as_imm(desc, (void *)§or_size, 8, LDST_CLASS_1_CCB |
12246 + LDST_SRCDST_BYTE_CONTEXT |
12247 + (0x28 << LDST_OFFSET_SHIFT));
12249 + set_jump_tgt_here(desc, key_jump_cmd);
12252 + * create sequence for loading the sector index
12253 + * Upper 8B of IV - will be used as sector index
12254 + * Lower 8B of IV - will be discarded
12256 + append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
12257 + (0x20 << LDST_OFFSET_SHIFT));
12258 + append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
12260 + /* Load operation */
12261 + append_dec_op1(desc, cdata->algtype);
12263 + /* Perform operation */
12264 + ablkcipher_append_src_dst(desc);
12267 + print_hex_dump(KERN_ERR,
12268 + "xts ablkcipher dec shdesc@" __stringify(__LINE__) ": ",
12269 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
12272 +EXPORT_SYMBOL(cnstr_shdsc_xts_ablkcipher_decap);
12274 +MODULE_LICENSE("GPL");
12275 +MODULE_DESCRIPTION("FSL CAAM descriptor support");
12276 +MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");
12278 +++ b/drivers/crypto/caam/caamalg_desc.h
12281 + * Shared descriptors for aead, ablkcipher algorithms
12283 + * Copyright 2016 NXP
12286 +#ifndef _CAAMALG_DESC_H_
12287 +#define _CAAMALG_DESC_H_
12289 +/* length of descriptors text */
12290 +#define DESC_AEAD_BASE (4 * CAAM_CMD_SZ)
12291 +#define DESC_AEAD_ENC_LEN (DESC_AEAD_BASE + 11 * CAAM_CMD_SZ)
12292 +#define DESC_AEAD_DEC_LEN (DESC_AEAD_BASE + 15 * CAAM_CMD_SZ)
12293 +#define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 7 * CAAM_CMD_SZ)
12294 +#define DESC_QI_AEAD_ENC_LEN (DESC_AEAD_ENC_LEN + 3 * CAAM_CMD_SZ)
12295 +#define DESC_QI_AEAD_DEC_LEN (DESC_AEAD_DEC_LEN + 3 * CAAM_CMD_SZ)
12296 +#define DESC_QI_AEAD_GIVENC_LEN (DESC_AEAD_GIVENC_LEN + 3 * CAAM_CMD_SZ)
12298 +#define DESC_TLS_BASE (4 * CAAM_CMD_SZ)
12299 +#define DESC_TLS10_ENC_LEN (DESC_TLS_BASE + 29 * CAAM_CMD_SZ)
12301 +/* Note: Nonce is counted in cdata.keylen */
12302 +#define DESC_AEAD_CTR_RFC3686_LEN (4 * CAAM_CMD_SZ)
12304 +#define DESC_AEAD_NULL_BASE (3 * CAAM_CMD_SZ)
12305 +#define DESC_AEAD_NULL_ENC_LEN (DESC_AEAD_NULL_BASE + 11 * CAAM_CMD_SZ)
12306 +#define DESC_AEAD_NULL_DEC_LEN (DESC_AEAD_NULL_BASE + 13 * CAAM_CMD_SZ)
12308 +#define DESC_GCM_BASE (3 * CAAM_CMD_SZ)
12309 +#define DESC_GCM_ENC_LEN (DESC_GCM_BASE + 16 * CAAM_CMD_SZ)
12310 +#define DESC_GCM_DEC_LEN (DESC_GCM_BASE + 12 * CAAM_CMD_SZ)
12311 +#define DESC_QI_GCM_ENC_LEN (DESC_GCM_ENC_LEN + 6 * CAAM_CMD_SZ)
12312 +#define DESC_QI_GCM_DEC_LEN (DESC_GCM_DEC_LEN + 3 * CAAM_CMD_SZ)
12314 +#define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ)
12315 +#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
12316 +#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
12317 +#define DESC_QI_RFC4106_ENC_LEN (DESC_RFC4106_ENC_LEN + 5 * CAAM_CMD_SZ)
12318 +#define DESC_QI_RFC4106_DEC_LEN (DESC_RFC4106_DEC_LEN + 5 * CAAM_CMD_SZ)
12320 +#define DESC_RFC4543_BASE (3 * CAAM_CMD_SZ)
12321 +#define DESC_RFC4543_ENC_LEN (DESC_RFC4543_BASE + 11 * CAAM_CMD_SZ)
12322 +#define DESC_RFC4543_DEC_LEN (DESC_RFC4543_BASE + 12 * CAAM_CMD_SZ)
12323 +#define DESC_QI_RFC4543_ENC_LEN (DESC_RFC4543_ENC_LEN + 4 * CAAM_CMD_SZ)
12324 +#define DESC_QI_RFC4543_DEC_LEN (DESC_RFC4543_DEC_LEN + 4 * CAAM_CMD_SZ)
12326 +#define DESC_ABLKCIPHER_BASE (3 * CAAM_CMD_SZ)
12327 +#define DESC_ABLKCIPHER_ENC_LEN (DESC_ABLKCIPHER_BASE + \
12328 + 20 * CAAM_CMD_SZ)
12329 +#define DESC_ABLKCIPHER_DEC_LEN (DESC_ABLKCIPHER_BASE + \
12330 + 15 * CAAM_CMD_SZ)
12332 +void cnstr_shdsc_aead_null_encap(u32 * const desc, struct alginfo *adata,
12333 + unsigned int icvsize, int era);
12335 +void cnstr_shdsc_aead_null_decap(u32 * const desc, struct alginfo *adata,
12336 + unsigned int icvsize, int era);
12338 +void cnstr_shdsc_aead_encap(u32 * const desc, struct alginfo *cdata,
12339 + struct alginfo *adata, unsigned int ivsize,
12340 + unsigned int icvsize, const bool is_rfc3686,
12341 + u32 *nonce, const u32 ctx1_iv_off,
12342 + const bool is_qi, int era);
12344 +void cnstr_shdsc_aead_decap(u32 * const desc, struct alginfo *cdata,
12345 + struct alginfo *adata, unsigned int ivsize,
12346 + unsigned int icvsize, const bool geniv,
12347 + const bool is_rfc3686, u32 *nonce,
12348 + const u32 ctx1_iv_off, const bool is_qi, int era);
12350 +void cnstr_shdsc_aead_givencap(u32 * const desc, struct alginfo *cdata,
12351 + struct alginfo *adata, unsigned int ivsize,
12352 + unsigned int icvsize, const bool is_rfc3686,
12353 + u32 *nonce, const u32 ctx1_iv_off,
12354 + const bool is_qi, int era);
12356 +void cnstr_shdsc_tls_encap(u32 *const desc, struct alginfo *cdata,
12357 + struct alginfo *adata, unsigned int assoclen,
12358 + unsigned int ivsize, unsigned int authsize,
12359 + unsigned int blocksize, int era);
12361 +void cnstr_shdsc_tls_decap(u32 *const desc, struct alginfo *cdata,
12362 + struct alginfo *adata, unsigned int assoclen,
12363 + unsigned int ivsize, unsigned int authsize,
12364 + unsigned int blocksize, int era);
12366 +void cnstr_shdsc_gcm_encap(u32 * const desc, struct alginfo *cdata,
12367 + unsigned int ivsize, unsigned int icvsize,
12368 + const bool is_qi);
12370 +void cnstr_shdsc_gcm_decap(u32 * const desc, struct alginfo *cdata,
12371 + unsigned int ivsize, unsigned int icvsize,
12372 + const bool is_qi);
12374 +void cnstr_shdsc_rfc4106_encap(u32 * const desc, struct alginfo *cdata,
12375 + unsigned int ivsize, unsigned int icvsize,
12376 + const bool is_qi);
12378 +void cnstr_shdsc_rfc4106_decap(u32 * const desc, struct alginfo *cdata,
12379 + unsigned int ivsize, unsigned int icvsize,
12380 + const bool is_qi);
12382 +void cnstr_shdsc_rfc4543_encap(u32 * const desc, struct alginfo *cdata,
12383 + unsigned int ivsize, unsigned int icvsize,
12384 + const bool is_qi);
12386 +void cnstr_shdsc_rfc4543_decap(u32 * const desc, struct alginfo *cdata,
12387 + unsigned int ivsize, unsigned int icvsize,
12388 + const bool is_qi);
12390 +void cnstr_shdsc_ablkcipher_encap(u32 * const desc, struct alginfo *cdata,
12391 + unsigned int ivsize, const bool is_rfc3686,
12392 + const u32 ctx1_iv_off);
12394 +void cnstr_shdsc_ablkcipher_decap(u32 * const desc, struct alginfo *cdata,
12395 + unsigned int ivsize, const bool is_rfc3686,
12396 + const u32 ctx1_iv_off);
12398 +void cnstr_shdsc_ablkcipher_givencap(u32 * const desc, struct alginfo *cdata,
12399 + unsigned int ivsize, const bool is_rfc3686,
12400 + const u32 ctx1_iv_off);
12402 +void cnstr_shdsc_xts_ablkcipher_encap(u32 * const desc, struct alginfo *cdata);
12404 +void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata);
12406 +#endif /* _CAAMALG_DESC_H_ */
12408 +++ b/drivers/crypto/caam/caamalg_qi.c
12411 + * Freescale FSL CAAM support for crypto API over QI backend.
12412 + * Based on caamalg.c
12414 + * Copyright 2013-2016 Freescale Semiconductor, Inc.
12415 + * Copyright 2016-2017 NXP
12418 +#include "compat.h"
12421 +#include "intern.h"
12422 +#include "desc_constr.h"
12423 +#include "error.h"
12424 +#include "sg_sw_qm.h"
12425 +#include "key_gen.h"
12428 +#include "caamalg_desc.h"
12433 +#define CAAM_CRA_PRIORITY 2000
12434 +/* max key is sum of AES_MAX_KEY_SIZE, max split key size */
12435 +#define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \
12436 + SHA512_DIGEST_SIZE * 2)
12438 +#define DESC_MAX_USED_BYTES (DESC_QI_AEAD_GIVENC_LEN + \
12439 + CAAM_MAX_KEY_SIZE)
12440 +#define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
12442 +struct caam_alg_entry {
12443 + int class1_alg_type;
12444 + int class2_alg_type;
12449 +struct caam_aead_alg {
12450 + struct aead_alg aead;
12451 + struct caam_alg_entry caam;
12456 + * per-session context
12459 + struct device *jrdev;
12460 + u32 sh_desc_enc[DESC_MAX_USED_LEN];
12461 + u32 sh_desc_dec[DESC_MAX_USED_LEN];
12462 + u32 sh_desc_givenc[DESC_MAX_USED_LEN];
12463 + u8 key[CAAM_MAX_KEY_SIZE];
12464 + dma_addr_t key_dma;
12465 + struct alginfo adata;
12466 + struct alginfo cdata;
12467 + unsigned int authsize;
12468 + struct device *qidev;
12469 + spinlock_t lock; /* Protects multiple init of driver context */
12470 + struct caam_drv_ctx *drv_ctx[NUM_OP];
12473 +static int aead_set_sh_desc(struct crypto_aead *aead)
12475 + struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
12476 + typeof(*alg), aead);
12477 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
12478 + unsigned int ivsize = crypto_aead_ivsize(aead);
12479 + u32 ctx1_iv_off = 0;
12480 + u32 *nonce = NULL;
12481 + unsigned int data_len[2];
12483 + const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
12484 + OP_ALG_AAI_CTR_MOD128);
12485 + const bool is_rfc3686 = alg->caam.rfc3686;
12486 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
12488 + if (!ctx->cdata.keylen || !ctx->authsize)
12492 + * AES-CTR needs to load IV in CONTEXT1 reg
12493 + * at an offset of 128bits (16bytes)
12494 + * CONTEXT1[255:128] = IV
12497 + ctx1_iv_off = 16;
12500 + * RFC3686 specific:
12501 + * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
12503 + if (is_rfc3686) {
12504 + ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
12505 + nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
12506 + ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
12509 + data_len[0] = ctx->adata.keylen_pad;
12510 + data_len[1] = ctx->cdata.keylen;
12512 + if (alg->caam.geniv)
12515 + /* aead_encrypt shared descriptor */
12516 + if (desc_inline_query(DESC_QI_AEAD_ENC_LEN +
12517 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
12518 + DESC_JOB_IO_LEN, data_len, &inl_mask,
12519 + ARRAY_SIZE(data_len)) < 0)
12522 + if (inl_mask & 1)
12523 + ctx->adata.key_virt = ctx->key;
12525 + ctx->adata.key_dma = ctx->key_dma;
12527 + if (inl_mask & 2)
12528 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
12530 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
12532 + ctx->adata.key_inline = !!(inl_mask & 1);
12533 + ctx->cdata.key_inline = !!(inl_mask & 2);
12535 + cnstr_shdsc_aead_encap(ctx->sh_desc_enc, &ctx->cdata, &ctx->adata,
12536 + ivsize, ctx->authsize, is_rfc3686, nonce,
12537 + ctx1_iv_off, true, ctrlpriv->era);
12540 + /* aead_decrypt shared descriptor */
12541 + if (desc_inline_query(DESC_QI_AEAD_DEC_LEN +
12542 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
12543 + DESC_JOB_IO_LEN, data_len, &inl_mask,
12544 + ARRAY_SIZE(data_len)) < 0)
12547 + if (inl_mask & 1)
12548 + ctx->adata.key_virt = ctx->key;
12550 + ctx->adata.key_dma = ctx->key_dma;
12552 + if (inl_mask & 2)
12553 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
12555 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
12557 + ctx->adata.key_inline = !!(inl_mask & 1);
12558 + ctx->cdata.key_inline = !!(inl_mask & 2);
12560 + cnstr_shdsc_aead_decap(ctx->sh_desc_dec, &ctx->cdata, &ctx->adata,
12561 + ivsize, ctx->authsize, alg->caam.geniv,
12562 + is_rfc3686, nonce, ctx1_iv_off, true,
12565 + if (!alg->caam.geniv)
12566 + goto skip_givenc;
12568 + /* aead_givencrypt shared descriptor */
12569 + if (desc_inline_query(DESC_QI_AEAD_GIVENC_LEN +
12570 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
12571 + DESC_JOB_IO_LEN, data_len, &inl_mask,
12572 + ARRAY_SIZE(data_len)) < 0)
12575 + if (inl_mask & 1)
12576 + ctx->adata.key_virt = ctx->key;
12578 + ctx->adata.key_dma = ctx->key_dma;
12580 + if (inl_mask & 2)
12581 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
12583 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
12585 + ctx->adata.key_inline = !!(inl_mask & 1);
12586 + ctx->cdata.key_inline = !!(inl_mask & 2);
12588 + cnstr_shdsc_aead_givencap(ctx->sh_desc_enc, &ctx->cdata, &ctx->adata,
12589 + ivsize, ctx->authsize, is_rfc3686, nonce,
12590 + ctx1_iv_off, true, ctrlpriv->era);
12596 +static int aead_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
12598 + struct caam_ctx *ctx = crypto_aead_ctx(authenc);
12600 + ctx->authsize = authsize;
12601 + aead_set_sh_desc(authenc);
12606 +static int aead_setkey(struct crypto_aead *aead, const u8 *key,
12607 + unsigned int keylen)
12609 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
12610 + struct device *jrdev = ctx->jrdev;
12611 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
12612 + struct crypto_authenc_keys keys;
12615 + if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
12619 + dev_err(jrdev, "keylen %d enckeylen %d authkeylen %d\n",
12620 + keys.authkeylen + keys.enckeylen, keys.enckeylen,
12621 + keys.authkeylen);
12622 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
12623 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
12627 + * If DKP is supported, use it in the shared descriptor to generate
12630 + if (ctrlpriv->era >= 6) {
12631 + ctx->adata.keylen = keys.authkeylen;
12632 + ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
12633 + OP_ALG_ALGSEL_MASK);
12635 + if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE)
12638 + memcpy(ctx->key, keys.authkey, keys.authkeylen);
12639 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey,
12641 + dma_sync_single_for_device(jrdev, ctx->key_dma,
12642 + ctx->adata.keylen_pad +
12643 + keys.enckeylen, DMA_TO_DEVICE);
12644 + goto skip_split_key;
12647 + ret = gen_split_key(jrdev, ctx->key, &ctx->adata, keys.authkey,
12648 + keys.authkeylen, CAAM_MAX_KEY_SIZE -
12653 + /* postpend encryption key to auth split key */
12654 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
12655 + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
12656 + keys.enckeylen, DMA_TO_DEVICE);
12658 + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ",
12659 + DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
12660 + ctx->adata.keylen_pad + keys.enckeylen, 1);
12664 + ctx->cdata.keylen = keys.enckeylen;
12666 + ret = aead_set_sh_desc(aead);
12670 + /* Now update the driver contexts with the new shared descriptor */
12671 + if (ctx->drv_ctx[ENCRYPT]) {
12672 + ret = caam_drv_ctx_update(ctx->drv_ctx[ENCRYPT],
12673 + ctx->sh_desc_enc);
12675 + dev_err(jrdev, "driver enc context update failed\n");
12680 + if (ctx->drv_ctx[DECRYPT]) {
12681 + ret = caam_drv_ctx_update(ctx->drv_ctx[DECRYPT],
12682 + ctx->sh_desc_dec);
12684 + dev_err(jrdev, "driver dec context update failed\n");
12691 + crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
12695 +static int tls_set_sh_desc(struct crypto_aead *tls)
12697 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
12698 + unsigned int ivsize = crypto_aead_ivsize(tls);
12699 + unsigned int blocksize = crypto_aead_blocksize(tls);
12700 + unsigned int assoclen = 13; /* always 13 bytes for TLS */
12701 + unsigned int data_len[2];
12703 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
12705 + if (!ctx->cdata.keylen || !ctx->authsize)
12709 + * TLS 1.0 encrypt shared descriptor
12710 + * Job Descriptor and Shared Descriptor
12711 + * must fit into the 64-word Descriptor h/w Buffer
12713 + data_len[0] = ctx->adata.keylen_pad;
12714 + data_len[1] = ctx->cdata.keylen;
12716 + if (desc_inline_query(DESC_TLS10_ENC_LEN, DESC_JOB_IO_LEN, data_len,
12717 + &inl_mask, ARRAY_SIZE(data_len)) < 0)
12720 + if (inl_mask & 1)
12721 + ctx->adata.key_virt = ctx->key;
12723 + ctx->adata.key_dma = ctx->key_dma;
12725 + if (inl_mask & 2)
12726 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
12728 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
12730 + ctx->adata.key_inline = !!(inl_mask & 1);
12731 + ctx->cdata.key_inline = !!(inl_mask & 2);
12733 + cnstr_shdsc_tls_encap(ctx->sh_desc_enc, &ctx->cdata, &ctx->adata,
12734 + assoclen, ivsize, ctx->authsize, blocksize,
12738 + * TLS 1.0 decrypt shared descriptor
12739 + * Keys do not fit inline, regardless of algorithms used
12741 + ctx->adata.key_inline = false;
12742 + ctx->adata.key_dma = ctx->key_dma;
12743 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
12745 + cnstr_shdsc_tls_decap(ctx->sh_desc_dec, &ctx->cdata, &ctx->adata,
12746 + assoclen, ivsize, ctx->authsize, blocksize,
12752 +static int tls_setauthsize(struct crypto_aead *tls, unsigned int authsize)
12754 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
12756 + ctx->authsize = authsize;
12757 + tls_set_sh_desc(tls);
12762 +static int tls_setkey(struct crypto_aead *tls, const u8 *key,
12763 + unsigned int keylen)
12765 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
12766 + struct device *jrdev = ctx->jrdev;
12767 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
12768 + struct crypto_authenc_keys keys;
12771 + if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
12775 + dev_err(jrdev, "keylen %d enckeylen %d authkeylen %d\n",
12776 + keys.authkeylen + keys.enckeylen, keys.enckeylen,
12777 + keys.authkeylen);
12778 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
12779 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
12783 + * If DKP is supported, use it in the shared descriptor to generate
12786 + if (ctrlpriv->era >= 6) {
12787 + ctx->adata.keylen = keys.authkeylen;
12788 + ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
12789 + OP_ALG_ALGSEL_MASK);
12791 + if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE)
12794 + memcpy(ctx->key, keys.authkey, keys.authkeylen);
12795 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey,
12797 + dma_sync_single_for_device(jrdev, ctx->key_dma,
12798 + ctx->adata.keylen_pad +
12799 + keys.enckeylen, DMA_TO_DEVICE);
12800 + goto skip_split_key;
12803 + ret = gen_split_key(jrdev, ctx->key, &ctx->adata, keys.authkey,
12804 + keys.authkeylen, CAAM_MAX_KEY_SIZE -
12809 + /* postpend encryption key to auth split key */
12810 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
12811 + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
12812 + keys.enckeylen, DMA_TO_DEVICE);
12815 + dev_err(jrdev, "split keylen %d split keylen padded %d\n",
12816 + ctx->adata.keylen, ctx->adata.keylen_pad);
12817 + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ",
12818 + DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
12819 + ctx->adata.keylen_pad + keys.enckeylen, 1);
12823 + ctx->cdata.keylen = keys.enckeylen;
12825 + ret = tls_set_sh_desc(tls);
12829 + /* Now update the driver contexts with the new shared descriptor */
12830 + if (ctx->drv_ctx[ENCRYPT]) {
12831 + ret = caam_drv_ctx_update(ctx->drv_ctx[ENCRYPT],
12832 + ctx->sh_desc_enc);
12834 + dev_err(jrdev, "driver enc context update failed\n");
12839 + if (ctx->drv_ctx[DECRYPT]) {
12840 + ret = caam_drv_ctx_update(ctx->drv_ctx[DECRYPT],
12841 + ctx->sh_desc_dec);
12843 + dev_err(jrdev, "driver dec context update failed\n");
12850 + crypto_aead_set_flags(tls, CRYPTO_TFM_RES_BAD_KEY_LEN);
12854 +static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
12855 + const u8 *key, unsigned int keylen)
12857 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
12858 + struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher);
12859 + const char *alg_name = crypto_tfm_alg_name(tfm);
12860 + struct device *jrdev = ctx->jrdev;
12861 + unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
12862 + u32 ctx1_iv_off = 0;
12863 + const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
12864 + OP_ALG_AAI_CTR_MOD128);
12865 + const bool is_rfc3686 = (ctr_mode && strstr(alg_name, "rfc3686"));
12868 + memcpy(ctx->key, key, keylen);
12870 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
12871 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
12874 + * AES-CTR needs to load IV in CONTEXT1 reg
12875 + * at an offset of 128bits (16bytes)
12876 + * CONTEXT1[255:128] = IV
12879 + ctx1_iv_off = 16;
12882 + * RFC3686 specific:
12883 + * | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
12884 + * | *key = {KEY, NONCE}
12886 + if (is_rfc3686) {
12887 + ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
12888 + keylen -= CTR_RFC3686_NONCE_SIZE;
12891 + dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
12892 + ctx->cdata.keylen = keylen;
12893 + ctx->cdata.key_virt = ctx->key;
12894 + ctx->cdata.key_inline = true;
12896 + /* ablkcipher encrypt, decrypt, givencrypt shared descriptors */
12897 + cnstr_shdsc_ablkcipher_encap(ctx->sh_desc_enc, &ctx->cdata, ivsize,
12898 + is_rfc3686, ctx1_iv_off);
12899 + cnstr_shdsc_ablkcipher_decap(ctx->sh_desc_dec, &ctx->cdata, ivsize,
12900 + is_rfc3686, ctx1_iv_off);
12901 + cnstr_shdsc_ablkcipher_givencap(ctx->sh_desc_givenc, &ctx->cdata,
12902 + ivsize, is_rfc3686, ctx1_iv_off);
12904 + /* Now update the driver contexts with the new shared descriptor */
12905 + if (ctx->drv_ctx[ENCRYPT]) {
12906 + ret = caam_drv_ctx_update(ctx->drv_ctx[ENCRYPT],
12907 + ctx->sh_desc_enc);
12909 + dev_err(jrdev, "driver enc context update failed\n");
12914 + if (ctx->drv_ctx[DECRYPT]) {
12915 + ret = caam_drv_ctx_update(ctx->drv_ctx[DECRYPT],
12916 + ctx->sh_desc_dec);
12918 + dev_err(jrdev, "driver dec context update failed\n");
12923 + if (ctx->drv_ctx[GIVENCRYPT]) {
12924 + ret = caam_drv_ctx_update(ctx->drv_ctx[GIVENCRYPT],
12925 + ctx->sh_desc_givenc);
12927 + dev_err(jrdev, "driver givenc context update failed\n");
12934 + crypto_ablkcipher_set_flags(ablkcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
12938 +static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
12939 + const u8 *key, unsigned int keylen)
12941 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
12942 + struct device *jrdev = ctx->jrdev;
12945 + if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
12946 + crypto_ablkcipher_set_flags(ablkcipher,
12947 + CRYPTO_TFM_RES_BAD_KEY_LEN);
12948 + dev_err(jrdev, "key size mismatch\n");
12952 + memcpy(ctx->key, key, keylen);
12953 + dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
12954 + ctx->cdata.keylen = keylen;
12955 + ctx->cdata.key_virt = ctx->key;
12956 + ctx->cdata.key_inline = true;
12958 + /* xts ablkcipher encrypt, decrypt shared descriptors */
12959 + cnstr_shdsc_xts_ablkcipher_encap(ctx->sh_desc_enc, &ctx->cdata);
12960 + cnstr_shdsc_xts_ablkcipher_decap(ctx->sh_desc_dec, &ctx->cdata);
12962 + /* Now update the driver contexts with the new shared descriptor */
12963 + if (ctx->drv_ctx[ENCRYPT]) {
12964 + ret = caam_drv_ctx_update(ctx->drv_ctx[ENCRYPT],
12965 + ctx->sh_desc_enc);
12967 + dev_err(jrdev, "driver enc context update failed\n");
12972 + if (ctx->drv_ctx[DECRYPT]) {
12973 + ret = caam_drv_ctx_update(ctx->drv_ctx[DECRYPT],
12974 + ctx->sh_desc_dec);
12976 + dev_err(jrdev, "driver dec context update failed\n");
12983 + crypto_ablkcipher_set_flags(ablkcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
12988 + * aead_edesc - s/w-extended aead descriptor
12989 + * @src_nents: number of segments in input scatterlist
12990 + * @dst_nents: number of segments in output scatterlist
12991 + * @iv_dma: dma address of iv for checking continuity and link table
12992 + * @qm_sg_bytes: length of dma mapped h/w link table
12993 + * @qm_sg_dma: bus physical mapped address of h/w link table
12994 + * @assoclen: associated data length, in CAAM endianness
12995 + * @assoclen_dma: bus physical mapped address of req->assoclen
12996 + * @drv_req: driver-specific request structure
12997 + * @sgt: the h/w link table
12999 +struct aead_edesc {
13002 + dma_addr_t iv_dma;
13004 + dma_addr_t qm_sg_dma;
13005 + unsigned int assoclen;
13006 + dma_addr_t assoclen_dma;
13007 + struct caam_drv_req drv_req;
13008 +#define CAAM_QI_MAX_AEAD_SG \
13009 + ((CAAM_QI_MEMCACHE_SIZE - offsetof(struct aead_edesc, sgt)) / \
13010 + sizeof(struct qm_sg_entry))
13011 + struct qm_sg_entry sgt[0];
13015 + * tls_edesc - s/w-extended tls descriptor
13016 + * @src_nents: number of segments in input scatterlist
13017 + * @dst_nents: number of segments in output scatterlist
13018 + * @iv_dma: dma address of iv for checking continuity and link table
13019 + * @qm_sg_bytes: length of dma mapped h/w link table
13020 + * @tmp: array of scatterlists used by 'scatterwalk_ffwd'
13021 + * @qm_sg_dma: bus physical mapped address of h/w link table
13022 + * @drv_req: driver-specific request structure
13023 + * @sgt: the h/w link table
13025 +struct tls_edesc {
13028 + dma_addr_t iv_dma;
13030 + dma_addr_t qm_sg_dma;
13031 + struct scatterlist tmp[2];
13032 + struct scatterlist *dst;
13033 + struct caam_drv_req drv_req;
13034 + struct qm_sg_entry sgt[0];
13038 + * ablkcipher_edesc - s/w-extended ablkcipher descriptor
13039 + * @src_nents: number of segments in input scatterlist
13040 + * @dst_nents: number of segments in output scatterlist
13041 + * @iv_dma: dma address of iv for checking continuity and link table
13042 + * @qm_sg_bytes: length of dma mapped h/w link table
13043 + * @qm_sg_dma: bus physical mapped address of h/w link table
13044 + * @drv_req: driver-specific request structure
13045 + * @sgt: the h/w link table
13047 +struct ablkcipher_edesc {
13050 + dma_addr_t iv_dma;
13052 + dma_addr_t qm_sg_dma;
13053 + struct caam_drv_req drv_req;
13054 +#define CAAM_QI_MAX_ABLKCIPHER_SG \
13055 + ((CAAM_QI_MEMCACHE_SIZE - offsetof(struct ablkcipher_edesc, sgt)) / \
13056 + sizeof(struct qm_sg_entry))
13057 + struct qm_sg_entry sgt[0];
13060 +static struct caam_drv_ctx *get_drv_ctx(struct caam_ctx *ctx,
13061 + enum optype type)
13064 + * This function is called on the fast path with values of 'type'
13065 + * known at compile time. Invalid arguments are not expected and
13066 + * thus no checks are made.
13068 + struct caam_drv_ctx *drv_ctx = ctx->drv_ctx[type];
13071 + if (unlikely(!drv_ctx)) {
13072 + spin_lock(&ctx->lock);
13074 + /* Read again to check if some other core init drv_ctx */
13075 + drv_ctx = ctx->drv_ctx[type];
13079 + if (type == ENCRYPT)
13080 + desc = ctx->sh_desc_enc;
13081 + else if (type == DECRYPT)
13082 + desc = ctx->sh_desc_dec;
13083 + else /* (type == GIVENCRYPT) */
13084 + desc = ctx->sh_desc_givenc;
13086 + cpu = smp_processor_id();
13087 + drv_ctx = caam_drv_ctx_init(ctx->qidev, &cpu, desc);
13088 + if (likely(!IS_ERR_OR_NULL(drv_ctx)))
13089 + drv_ctx->op_type = type;
13091 + ctx->drv_ctx[type] = drv_ctx;
13094 + spin_unlock(&ctx->lock);
13100 +static void caam_unmap(struct device *dev, struct scatterlist *src,
13101 + struct scatterlist *dst, int src_nents,
13102 + int dst_nents, dma_addr_t iv_dma, int ivsize,
13103 + enum optype op_type, dma_addr_t qm_sg_dma,
13106 + if (dst != src) {
13108 + dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
13109 + dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
13111 + dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
13115 + dma_unmap_single(dev, iv_dma, ivsize,
13116 + op_type == GIVENCRYPT ? DMA_FROM_DEVICE :
13119 + dma_unmap_single(dev, qm_sg_dma, qm_sg_bytes, DMA_TO_DEVICE);
13122 +static void aead_unmap(struct device *dev,
13123 + struct aead_edesc *edesc,
13124 + struct aead_request *req)
13126 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
13127 + int ivsize = crypto_aead_ivsize(aead);
13129 + caam_unmap(dev, req->src, req->dst, edesc->src_nents, edesc->dst_nents,
13130 + edesc->iv_dma, ivsize, edesc->drv_req.drv_ctx->op_type,
13131 + edesc->qm_sg_dma, edesc->qm_sg_bytes);
13132 + dma_unmap_single(dev, edesc->assoclen_dma, 4, DMA_TO_DEVICE);
13135 +static void tls_unmap(struct device *dev,
13136 + struct tls_edesc *edesc,
13137 + struct aead_request *req)
13139 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
13140 + int ivsize = crypto_aead_ivsize(aead);
13142 + caam_unmap(dev, req->src, edesc->dst, edesc->src_nents,
13143 + edesc->dst_nents, edesc->iv_dma, ivsize,
13144 + edesc->drv_req.drv_ctx->op_type, edesc->qm_sg_dma,
13145 + edesc->qm_sg_bytes);
13148 +static void ablkcipher_unmap(struct device *dev,
13149 + struct ablkcipher_edesc *edesc,
13150 + struct ablkcipher_request *req)
13152 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
13153 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
13155 + caam_unmap(dev, req->src, req->dst, edesc->src_nents, edesc->dst_nents,
13156 + edesc->iv_dma, ivsize, edesc->drv_req.drv_ctx->op_type,
13157 + edesc->qm_sg_dma, edesc->qm_sg_bytes);
13160 +static void aead_done(struct caam_drv_req *drv_req, u32 status)
13162 + struct device *qidev;
13163 + struct aead_edesc *edesc;
13164 + struct aead_request *aead_req = drv_req->app_ctx;
13165 + struct crypto_aead *aead = crypto_aead_reqtfm(aead_req);
13166 + struct caam_ctx *caam_ctx = crypto_aead_ctx(aead);
13169 + qidev = caam_ctx->qidev;
13171 + if (unlikely(status)) {
13172 + caam_jr_strstatus(qidev, status);
13176 + edesc = container_of(drv_req, typeof(*edesc), drv_req);
13177 + aead_unmap(qidev, edesc, aead_req);
13179 + aead_request_complete(aead_req, ecode);
13180 + qi_cache_free(edesc);
13184 + * allocate and map the aead extended descriptor
13186 +static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
13189 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
13190 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
13191 + struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
13192 + typeof(*alg), aead);
13193 + struct device *qidev = ctx->qidev;
13194 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
13195 + GFP_KERNEL : GFP_ATOMIC;
13196 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
13197 + struct aead_edesc *edesc;
13198 + dma_addr_t qm_sg_dma, iv_dma = 0;
13200 + unsigned int authsize = ctx->authsize;
13201 + int qm_sg_index = 0, qm_sg_ents = 0, qm_sg_bytes;
13202 + int in_len, out_len;
13203 + struct qm_sg_entry *sg_table, *fd_sgt;
13204 + struct caam_drv_ctx *drv_ctx;
13205 + enum optype op_type = encrypt ? ENCRYPT : DECRYPT;
13207 + drv_ctx = get_drv_ctx(ctx, op_type);
13208 + if (unlikely(IS_ERR_OR_NULL(drv_ctx)))
13209 + return (struct aead_edesc *)drv_ctx;
13211 + /* allocate space for base edesc and hw desc commands, link tables */
13212 + edesc = qi_cache_alloc(GFP_DMA | flags);
13213 + if (unlikely(!edesc)) {
13214 + dev_err(qidev, "could not allocate extended descriptor\n");
13215 + return ERR_PTR(-ENOMEM);
13218 + if (likely(req->src == req->dst)) {
13219 + src_nents = sg_nents_for_len(req->src, req->assoclen +
13221 + (encrypt ? authsize : 0));
13222 + if (unlikely(src_nents < 0)) {
13223 + dev_err(qidev, "Insufficient bytes (%d) in src S/G\n",
13224 + req->assoclen + req->cryptlen +
13225 + (encrypt ? authsize : 0));
13226 + qi_cache_free(edesc);
13227 + return ERR_PTR(src_nents);
13230 + mapped_src_nents = dma_map_sg(qidev, req->src, src_nents,
13231 + DMA_BIDIRECTIONAL);
13232 + if (unlikely(!mapped_src_nents)) {
13233 + dev_err(qidev, "unable to map source\n");
13234 + qi_cache_free(edesc);
13235 + return ERR_PTR(-ENOMEM);
13238 + src_nents = sg_nents_for_len(req->src, req->assoclen +
13240 + if (unlikely(src_nents < 0)) {
13241 + dev_err(qidev, "Insufficient bytes (%d) in src S/G\n",
13242 + req->assoclen + req->cryptlen);
13243 + qi_cache_free(edesc);
13244 + return ERR_PTR(src_nents);
13247 + dst_nents = sg_nents_for_len(req->dst, req->assoclen +
13249 + (encrypt ? authsize :
13251 + if (unlikely(dst_nents < 0)) {
13252 + dev_err(qidev, "Insufficient bytes (%d) in dst S/G\n",
13253 + req->assoclen + req->cryptlen +
13254 + (encrypt ? authsize : (-authsize)));
13255 + qi_cache_free(edesc);
13256 + return ERR_PTR(dst_nents);
13260 + mapped_src_nents = dma_map_sg(qidev, req->src,
13261 + src_nents, DMA_TO_DEVICE);
13262 + if (unlikely(!mapped_src_nents)) {
13263 + dev_err(qidev, "unable to map source\n");
13264 + qi_cache_free(edesc);
13265 + return ERR_PTR(-ENOMEM);
13268 + mapped_src_nents = 0;
13271 + mapped_dst_nents = dma_map_sg(qidev, req->dst, dst_nents,
13272 + DMA_FROM_DEVICE);
13273 + if (unlikely(!mapped_dst_nents)) {
13274 + dev_err(qidev, "unable to map destination\n");
13275 + dma_unmap_sg(qidev, req->src, src_nents, DMA_TO_DEVICE);
13276 + qi_cache_free(edesc);
13277 + return ERR_PTR(-ENOMEM);
13281 + if ((alg->caam.rfc3686 && encrypt) || !alg->caam.geniv) {
13282 + ivsize = crypto_aead_ivsize(aead);
13283 + iv_dma = dma_map_single(qidev, req->iv, ivsize, DMA_TO_DEVICE);
13284 + if (dma_mapping_error(qidev, iv_dma)) {
13285 + dev_err(qidev, "unable to map IV\n");
13286 + caam_unmap(qidev, req->src, req->dst, src_nents,
13287 + dst_nents, 0, 0, op_type, 0, 0);
13288 + qi_cache_free(edesc);
13289 + return ERR_PTR(-ENOMEM);
13294 + * Create S/G table: req->assoclen, [IV,] req->src [, req->dst].
13295 + * Input is not contiguous.
13297 + qm_sg_ents = 1 + !!ivsize + mapped_src_nents +
13298 + (mapped_dst_nents > 1 ? mapped_dst_nents : 0);
13299 + if (unlikely(qm_sg_ents > CAAM_QI_MAX_AEAD_SG)) {
13300 + dev_err(qidev, "Insufficient S/G entries: %d > %lu\n",
13301 + qm_sg_ents, CAAM_QI_MAX_AEAD_SG);
13302 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13303 + iv_dma, ivsize, op_type, 0, 0);
13304 + qi_cache_free(edesc);
13305 + return ERR_PTR(-ENOMEM);
13307 + sg_table = &edesc->sgt[0];
13308 + qm_sg_bytes = qm_sg_ents * sizeof(*sg_table);
13310 + edesc->src_nents = src_nents;
13311 + edesc->dst_nents = dst_nents;
13312 + edesc->iv_dma = iv_dma;
13313 + edesc->drv_req.app_ctx = req;
13314 + edesc->drv_req.cbk = aead_done;
13315 + edesc->drv_req.drv_ctx = drv_ctx;
13317 + edesc->assoclen = cpu_to_caam32(req->assoclen);
13318 + edesc->assoclen_dma = dma_map_single(qidev, &edesc->assoclen, 4,
13320 + if (dma_mapping_error(qidev, edesc->assoclen_dma)) {
13321 + dev_err(qidev, "unable to map assoclen\n");
13322 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13323 + iv_dma, ivsize, op_type, 0, 0);
13324 + qi_cache_free(edesc);
13325 + return ERR_PTR(-ENOMEM);
13328 + dma_to_qm_sg_one(sg_table, edesc->assoclen_dma, 4, 0);
13331 + dma_to_qm_sg_one(sg_table + qm_sg_index, iv_dma, ivsize, 0);
13334 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table + qm_sg_index, 0);
13335 + qm_sg_index += mapped_src_nents;
13337 + if (mapped_dst_nents > 1)
13338 + sg_to_qm_sg_last(req->dst, mapped_dst_nents, sg_table +
13341 + qm_sg_dma = dma_map_single(qidev, sg_table, qm_sg_bytes, DMA_TO_DEVICE);
13342 + if (dma_mapping_error(qidev, qm_sg_dma)) {
13343 + dev_err(qidev, "unable to map S/G table\n");
13344 + dma_unmap_single(qidev, edesc->assoclen_dma, 4, DMA_TO_DEVICE);
13345 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13346 + iv_dma, ivsize, op_type, 0, 0);
13347 + qi_cache_free(edesc);
13348 + return ERR_PTR(-ENOMEM);
13351 + edesc->qm_sg_dma = qm_sg_dma;
13352 + edesc->qm_sg_bytes = qm_sg_bytes;
13354 + out_len = req->assoclen + req->cryptlen +
13355 + (encrypt ? ctx->authsize : (-ctx->authsize));
13356 + in_len = 4 + ivsize + req->assoclen + req->cryptlen;
13358 + fd_sgt = &edesc->drv_req.fd_sgt[0];
13359 + dma_to_qm_sg_one_last_ext(&fd_sgt[1], qm_sg_dma, in_len, 0);
13361 + if (req->dst == req->src) {
13362 + if (mapped_src_nents == 1)
13363 + dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->src),
13366 + dma_to_qm_sg_one_ext(&fd_sgt[0], qm_sg_dma +
13367 + (1 + !!ivsize) * sizeof(*sg_table),
13369 + } else if (mapped_dst_nents == 1) {
13370 + dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->dst), out_len,
13373 + dma_to_qm_sg_one_ext(&fd_sgt[0], qm_sg_dma + sizeof(*sg_table) *
13374 + qm_sg_index, out_len, 0);
13380 +static inline int aead_crypt(struct aead_request *req, bool encrypt)
13382 + struct aead_edesc *edesc;
13383 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
13384 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
13387 + if (unlikely(caam_congested))
13390 + /* allocate extended descriptor */
13391 + edesc = aead_edesc_alloc(req, encrypt);
13392 + if (IS_ERR_OR_NULL(edesc))
13393 + return PTR_ERR(edesc);
13395 + /* Create and submit job descriptor */
13396 + ret = caam_qi_enqueue(ctx->qidev, &edesc->drv_req);
13398 + ret = -EINPROGRESS;
13400 + aead_unmap(ctx->qidev, edesc, req);
13401 + qi_cache_free(edesc);
13407 +static int aead_encrypt(struct aead_request *req)
13409 + return aead_crypt(req, true);
13412 +static int aead_decrypt(struct aead_request *req)
13414 + return aead_crypt(req, false);
13417 +static void tls_done(struct caam_drv_req *drv_req, u32 status)
13419 + struct device *qidev;
13420 + struct tls_edesc *edesc;
13421 + struct aead_request *aead_req = drv_req->app_ctx;
13422 + struct crypto_aead *aead = crypto_aead_reqtfm(aead_req);
13423 + struct caam_ctx *caam_ctx = crypto_aead_ctx(aead);
13426 + qidev = caam_ctx->qidev;
13428 + if (unlikely(status)) {
13429 + caam_jr_strstatus(qidev, status);
13433 + edesc = container_of(drv_req, typeof(*edesc), drv_req);
13434 + tls_unmap(qidev, edesc, aead_req);
13436 + aead_request_complete(aead_req, ecode);
13437 + qi_cache_free(edesc);
13441 + * allocate and map the tls extended descriptor
13443 +static struct tls_edesc *tls_edesc_alloc(struct aead_request *req, bool encrypt)
13445 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
13446 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
13447 + unsigned int blocksize = crypto_aead_blocksize(aead);
13448 + unsigned int padsize, authsize;
13449 + struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
13450 + typeof(*alg), aead);
13451 + struct device *qidev = ctx->qidev;
13452 + gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
13453 + CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
13454 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
13455 + struct tls_edesc *edesc;
13456 + dma_addr_t qm_sg_dma, iv_dma = 0;
13458 + int qm_sg_index, qm_sg_ents = 0, qm_sg_bytes;
13459 + int in_len, out_len;
13460 + struct qm_sg_entry *sg_table, *fd_sgt;
13461 + struct caam_drv_ctx *drv_ctx;
13462 + enum optype op_type = encrypt ? ENCRYPT : DECRYPT;
13463 + struct scatterlist *dst;
13466 + padsize = blocksize - ((req->cryptlen + ctx->authsize) %
13468 + authsize = ctx->authsize + padsize;
13470 + authsize = ctx->authsize;
13473 + drv_ctx = get_drv_ctx(ctx, op_type);
13474 + if (unlikely(IS_ERR_OR_NULL(drv_ctx)))
13475 + return (struct tls_edesc *)drv_ctx;
13477 + /* allocate space for base edesc and hw desc commands, link tables */
13478 + edesc = qi_cache_alloc(GFP_DMA | flags);
13479 + if (unlikely(!edesc)) {
13480 + dev_err(qidev, "could not allocate extended descriptor\n");
13481 + return ERR_PTR(-ENOMEM);
13484 + if (likely(req->src == req->dst)) {
13485 + src_nents = sg_nents_for_len(req->src, req->assoclen +
13487 + (encrypt ? authsize : 0));
13488 + if (unlikely(src_nents < 0)) {
13489 + dev_err(qidev, "Insufficient bytes (%d) in src S/G\n",
13490 + req->assoclen + req->cryptlen +
13491 + (encrypt ? authsize : 0));
13492 + qi_cache_free(edesc);
13493 + return ERR_PTR(src_nents);
13496 + mapped_src_nents = dma_map_sg(qidev, req->src, src_nents,
13497 + DMA_BIDIRECTIONAL);
13498 + if (unlikely(!mapped_src_nents)) {
13499 + dev_err(qidev, "unable to map source\n");
13500 + qi_cache_free(edesc);
13501 + return ERR_PTR(-ENOMEM);
13505 + src_nents = sg_nents_for_len(req->src, req->assoclen +
13507 + if (unlikely(src_nents < 0)) {
13508 + dev_err(qidev, "Insufficient bytes (%d) in src S/G\n",
13509 + req->assoclen + req->cryptlen);
13510 + qi_cache_free(edesc);
13511 + return ERR_PTR(src_nents);
13514 + dst = scatterwalk_ffwd(edesc->tmp, req->dst, req->assoclen);
13515 + dst_nents = sg_nents_for_len(dst, req->cryptlen +
13516 + (encrypt ? authsize : 0));
13517 + if (unlikely(dst_nents < 0)) {
13518 + dev_err(qidev, "Insufficient bytes (%d) in dst S/G\n",
13520 + (encrypt ? authsize : 0));
13521 + qi_cache_free(edesc);
13522 + return ERR_PTR(dst_nents);
13526 + mapped_src_nents = dma_map_sg(qidev, req->src,
13527 + src_nents, DMA_TO_DEVICE);
13528 + if (unlikely(!mapped_src_nents)) {
13529 + dev_err(qidev, "unable to map source\n");
13530 + qi_cache_free(edesc);
13531 + return ERR_PTR(-ENOMEM);
13534 + mapped_src_nents = 0;
13537 + mapped_dst_nents = dma_map_sg(qidev, dst, dst_nents,
13538 + DMA_FROM_DEVICE);
13539 + if (unlikely(!mapped_dst_nents)) {
13540 + dev_err(qidev, "unable to map destination\n");
13541 + dma_unmap_sg(qidev, req->src, src_nents, DMA_TO_DEVICE);
13542 + qi_cache_free(edesc);
13543 + return ERR_PTR(-ENOMEM);
13547 + ivsize = crypto_aead_ivsize(aead);
13548 + iv_dma = dma_map_single(qidev, req->iv, ivsize, DMA_TO_DEVICE);
13549 + if (dma_mapping_error(qidev, iv_dma)) {
13550 + dev_err(qidev, "unable to map IV\n");
13551 + caam_unmap(qidev, req->src, dst, src_nents, dst_nents, 0, 0,
13553 + qi_cache_free(edesc);
13554 + return ERR_PTR(-ENOMEM);
13558 + * Create S/G table: IV, src, dst.
13559 + * Input is not contiguous.
13561 + qm_sg_ents = 1 + mapped_src_nents +
13562 + (mapped_dst_nents > 1 ? mapped_dst_nents : 0);
13563 + sg_table = &edesc->sgt[0];
13564 + qm_sg_bytes = qm_sg_ents * sizeof(*sg_table);
13566 + edesc->src_nents = src_nents;
13567 + edesc->dst_nents = dst_nents;
13568 + edesc->dst = dst;
13569 + edesc->iv_dma = iv_dma;
13570 + edesc->drv_req.app_ctx = req;
13571 + edesc->drv_req.cbk = tls_done;
13572 + edesc->drv_req.drv_ctx = drv_ctx;
13574 + dma_to_qm_sg_one(sg_table, iv_dma, ivsize, 0);
13577 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table + qm_sg_index, 0);
13578 + qm_sg_index += mapped_src_nents;
13580 + if (mapped_dst_nents > 1)
13581 + sg_to_qm_sg_last(dst, mapped_dst_nents, sg_table +
13584 + qm_sg_dma = dma_map_single(qidev, sg_table, qm_sg_bytes, DMA_TO_DEVICE);
13585 + if (dma_mapping_error(qidev, qm_sg_dma)) {
13586 + dev_err(qidev, "unable to map S/G table\n");
13587 + caam_unmap(qidev, req->src, dst, src_nents, dst_nents, iv_dma,
13588 + ivsize, op_type, 0, 0);
13589 + qi_cache_free(edesc);
13590 + return ERR_PTR(-ENOMEM);
13593 + edesc->qm_sg_dma = qm_sg_dma;
13594 + edesc->qm_sg_bytes = qm_sg_bytes;
13596 + out_len = req->cryptlen + (encrypt ? authsize : 0);
13597 + in_len = ivsize + req->assoclen + req->cryptlen;
13599 + fd_sgt = &edesc->drv_req.fd_sgt[0];
13601 + dma_to_qm_sg_one_last_ext(&fd_sgt[1], qm_sg_dma, in_len, 0);
13603 + if (req->dst == req->src)
13604 + dma_to_qm_sg_one_ext(&fd_sgt[0], qm_sg_dma +
13605 + (sg_nents_for_len(req->src, req->assoclen) +
13606 + 1) * sizeof(*sg_table), out_len, 0);
13607 + else if (mapped_dst_nents == 1)
13608 + dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(dst), out_len, 0);
13610 + dma_to_qm_sg_one_ext(&fd_sgt[0], qm_sg_dma + sizeof(*sg_table) *
13611 + qm_sg_index, out_len, 0);
13616 +static int tls_crypt(struct aead_request *req, bool encrypt)
13618 + struct tls_edesc *edesc;
13619 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
13620 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
13623 + if (unlikely(caam_congested))
13626 + edesc = tls_edesc_alloc(req, encrypt);
13627 + if (IS_ERR_OR_NULL(edesc))
13628 + return PTR_ERR(edesc);
13630 + ret = caam_qi_enqueue(ctx->qidev, &edesc->drv_req);
13632 + ret = -EINPROGRESS;
13634 + tls_unmap(ctx->qidev, edesc, req);
13635 + qi_cache_free(edesc);
13641 +static int tls_encrypt(struct aead_request *req)
13643 + return tls_crypt(req, true);
13646 +static int tls_decrypt(struct aead_request *req)
13648 + return tls_crypt(req, false);
13651 +static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status)
13653 + struct ablkcipher_edesc *edesc;
13654 + struct ablkcipher_request *req = drv_req->app_ctx;
13655 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
13656 + struct caam_ctx *caam_ctx = crypto_ablkcipher_ctx(ablkcipher);
13657 + struct device *qidev = caam_ctx->qidev;
13658 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
13661 + dev_err(qidev, "%s %d: status 0x%x\n", __func__, __LINE__, status);
13664 + edesc = container_of(drv_req, typeof(*edesc), drv_req);
13667 + caam_jr_strstatus(qidev, status);
13670 + print_hex_dump(KERN_ERR, "dstiv @" __stringify(__LINE__)": ",
13671 + DUMP_PREFIX_ADDRESS, 16, 4, req->info,
13672 + edesc->src_nents > 1 ? 100 : ivsize, 1);
13673 + caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ",
13674 + DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
13675 + edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
13678 + ablkcipher_unmap(qidev, edesc, req);
13679 + qi_cache_free(edesc);
13682 + * The crypto API expects us to set the IV (req->info) to the last
13683 + * ciphertext block. This is used e.g. by the CTS mode.
13685 + scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize,
13688 + ablkcipher_request_complete(req, status);
13691 +static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
13692 + *req, bool encrypt)
13694 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
13695 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
13696 + struct device *qidev = ctx->qidev;
13697 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
13698 + GFP_KERNEL : GFP_ATOMIC;
13699 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
13700 + struct ablkcipher_edesc *edesc;
13701 + dma_addr_t iv_dma;
13703 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
13704 + int dst_sg_idx, qm_sg_ents;
13705 + struct qm_sg_entry *sg_table, *fd_sgt;
13706 + struct caam_drv_ctx *drv_ctx;
13707 + enum optype op_type = encrypt ? ENCRYPT : DECRYPT;
13709 + drv_ctx = get_drv_ctx(ctx, op_type);
13710 + if (unlikely(IS_ERR_OR_NULL(drv_ctx)))
13711 + return (struct ablkcipher_edesc *)drv_ctx;
13713 + src_nents = sg_nents_for_len(req->src, req->nbytes);
13714 + if (unlikely(src_nents < 0)) {
13715 + dev_err(qidev, "Insufficient bytes (%d) in src S/G\n",
13717 + return ERR_PTR(src_nents);
13720 + if (unlikely(req->src != req->dst)) {
13721 + dst_nents = sg_nents_for_len(req->dst, req->nbytes);
13722 + if (unlikely(dst_nents < 0)) {
13723 + dev_err(qidev, "Insufficient bytes (%d) in dst S/G\n",
13725 + return ERR_PTR(dst_nents);
13728 + mapped_src_nents = dma_map_sg(qidev, req->src, src_nents,
13730 + if (unlikely(!mapped_src_nents)) {
13731 + dev_err(qidev, "unable to map source\n");
13732 + return ERR_PTR(-ENOMEM);
13735 + mapped_dst_nents = dma_map_sg(qidev, req->dst, dst_nents,
13736 + DMA_FROM_DEVICE);
13737 + if (unlikely(!mapped_dst_nents)) {
13738 + dev_err(qidev, "unable to map destination\n");
13739 + dma_unmap_sg(qidev, req->src, src_nents, DMA_TO_DEVICE);
13740 + return ERR_PTR(-ENOMEM);
13743 + mapped_src_nents = dma_map_sg(qidev, req->src, src_nents,
13744 + DMA_BIDIRECTIONAL);
13745 + if (unlikely(!mapped_src_nents)) {
13746 + dev_err(qidev, "unable to map source\n");
13747 + return ERR_PTR(-ENOMEM);
13751 + iv_dma = dma_map_single(qidev, req->info, ivsize, DMA_TO_DEVICE);
13752 + if (dma_mapping_error(qidev, iv_dma)) {
13753 + dev_err(qidev, "unable to map IV\n");
13754 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents, 0,
13756 + return ERR_PTR(-ENOMEM);
13759 + if (mapped_src_nents == 1 &&
13760 + iv_dma + ivsize == sg_dma_address(req->src)) {
13761 + in_contig = true;
13764 + in_contig = false;
13765 + qm_sg_ents = 1 + mapped_src_nents;
13767 + dst_sg_idx = qm_sg_ents;
13769 + qm_sg_ents += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
13770 + if (unlikely(qm_sg_ents > CAAM_QI_MAX_ABLKCIPHER_SG)) {
13771 + dev_err(qidev, "Insufficient S/G entries: %d > %lu\n",
13772 + qm_sg_ents, CAAM_QI_MAX_ABLKCIPHER_SG);
13773 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13774 + iv_dma, ivsize, op_type, 0, 0);
13775 + return ERR_PTR(-ENOMEM);
13778 + /* allocate space for base edesc and link tables */
13779 + edesc = qi_cache_alloc(GFP_DMA | flags);
13780 + if (unlikely(!edesc)) {
13781 + dev_err(qidev, "could not allocate extended descriptor\n");
13782 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13783 + iv_dma, ivsize, op_type, 0, 0);
13784 + return ERR_PTR(-ENOMEM);
13787 + edesc->src_nents = src_nents;
13788 + edesc->dst_nents = dst_nents;
13789 + edesc->iv_dma = iv_dma;
13790 + sg_table = &edesc->sgt[0];
13791 + edesc->qm_sg_bytes = qm_sg_ents * sizeof(*sg_table);
13792 + edesc->drv_req.app_ctx = req;
13793 + edesc->drv_req.cbk = ablkcipher_done;
13794 + edesc->drv_req.drv_ctx = drv_ctx;
13796 + if (!in_contig) {
13797 + dma_to_qm_sg_one(sg_table, iv_dma, ivsize, 0);
13798 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table + 1, 0);
13801 + if (mapped_dst_nents > 1)
13802 + sg_to_qm_sg_last(req->dst, mapped_dst_nents, sg_table +
13805 + edesc->qm_sg_dma = dma_map_single(qidev, sg_table, edesc->qm_sg_bytes,
13807 + if (dma_mapping_error(qidev, edesc->qm_sg_dma)) {
13808 + dev_err(qidev, "unable to map S/G table\n");
13809 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13810 + iv_dma, ivsize, op_type, 0, 0);
13811 + qi_cache_free(edesc);
13812 + return ERR_PTR(-ENOMEM);
13815 + fd_sgt = &edesc->drv_req.fd_sgt[0];
13818 + dma_to_qm_sg_one_last_ext(&fd_sgt[1], edesc->qm_sg_dma,
13819 + ivsize + req->nbytes, 0);
13821 + dma_to_qm_sg_one_last(&fd_sgt[1], iv_dma, ivsize + req->nbytes,
13824 + if (req->src == req->dst) {
13826 + dma_to_qm_sg_one_ext(&fd_sgt[0], edesc->qm_sg_dma +
13827 + sizeof(*sg_table), req->nbytes, 0);
13829 + dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->src),
13831 + } else if (mapped_dst_nents > 1) {
13832 + dma_to_qm_sg_one_ext(&fd_sgt[0], edesc->qm_sg_dma + dst_sg_idx *
13833 + sizeof(*sg_table), req->nbytes, 0);
13835 + dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->dst),
13842 +static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
13843 + struct skcipher_givcrypt_request *creq)
13845 + struct ablkcipher_request *req = &creq->creq;
13846 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
13847 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
13848 + struct device *qidev = ctx->qidev;
13849 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
13850 + GFP_KERNEL : GFP_ATOMIC;
13851 + int src_nents, mapped_src_nents, dst_nents, mapped_dst_nents;
13852 + struct ablkcipher_edesc *edesc;
13853 + dma_addr_t iv_dma;
13855 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
13856 + struct qm_sg_entry *sg_table, *fd_sgt;
13857 + int dst_sg_idx, qm_sg_ents;
13858 + struct caam_drv_ctx *drv_ctx;
13860 + drv_ctx = get_drv_ctx(ctx, GIVENCRYPT);
13861 + if (unlikely(IS_ERR_OR_NULL(drv_ctx)))
13862 + return (struct ablkcipher_edesc *)drv_ctx;
13864 + src_nents = sg_nents_for_len(req->src, req->nbytes);
13865 + if (unlikely(src_nents < 0)) {
13866 + dev_err(qidev, "Insufficient bytes (%d) in src S/G\n",
13868 + return ERR_PTR(src_nents);
13871 + if (unlikely(req->src != req->dst)) {
13872 + dst_nents = sg_nents_for_len(req->dst, req->nbytes);
13873 + if (unlikely(dst_nents < 0)) {
13874 + dev_err(qidev, "Insufficient bytes (%d) in dst S/G\n",
13876 + return ERR_PTR(dst_nents);
13879 + mapped_src_nents = dma_map_sg(qidev, req->src, src_nents,
13881 + if (unlikely(!mapped_src_nents)) {
13882 + dev_err(qidev, "unable to map source\n");
13883 + return ERR_PTR(-ENOMEM);
13886 + mapped_dst_nents = dma_map_sg(qidev, req->dst, dst_nents,
13887 + DMA_FROM_DEVICE);
13888 + if (unlikely(!mapped_dst_nents)) {
13889 + dev_err(qidev, "unable to map destination\n");
13890 + dma_unmap_sg(qidev, req->src, src_nents, DMA_TO_DEVICE);
13891 + return ERR_PTR(-ENOMEM);
13894 + mapped_src_nents = dma_map_sg(qidev, req->src, src_nents,
13895 + DMA_BIDIRECTIONAL);
13896 + if (unlikely(!mapped_src_nents)) {
13897 + dev_err(qidev, "unable to map source\n");
13898 + return ERR_PTR(-ENOMEM);
13901 + dst_nents = src_nents;
13902 + mapped_dst_nents = src_nents;
13905 + iv_dma = dma_map_single(qidev, creq->giv, ivsize, DMA_FROM_DEVICE);
13906 + if (dma_mapping_error(qidev, iv_dma)) {
13907 + dev_err(qidev, "unable to map IV\n");
13908 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents, 0,
13910 + return ERR_PTR(-ENOMEM);
13913 + qm_sg_ents = mapped_src_nents > 1 ? mapped_src_nents : 0;
13914 + dst_sg_idx = qm_sg_ents;
13915 + if (mapped_dst_nents == 1 &&
13916 + iv_dma + ivsize == sg_dma_address(req->dst)) {
13917 + out_contig = true;
13919 + out_contig = false;
13920 + qm_sg_ents += 1 + mapped_dst_nents;
13923 + if (unlikely(qm_sg_ents > CAAM_QI_MAX_ABLKCIPHER_SG)) {
13924 + dev_err(qidev, "Insufficient S/G entries: %d > %lu\n",
13925 + qm_sg_ents, CAAM_QI_MAX_ABLKCIPHER_SG);
13926 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13927 + iv_dma, ivsize, GIVENCRYPT, 0, 0);
13928 + return ERR_PTR(-ENOMEM);
13931 + /* allocate space for base edesc and link tables */
13932 + edesc = qi_cache_alloc(GFP_DMA | flags);
13934 + dev_err(qidev, "could not allocate extended descriptor\n");
13935 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13936 + iv_dma, ivsize, GIVENCRYPT, 0, 0);
13937 + return ERR_PTR(-ENOMEM);
13940 + edesc->src_nents = src_nents;
13941 + edesc->dst_nents = dst_nents;
13942 + edesc->iv_dma = iv_dma;
13943 + sg_table = &edesc->sgt[0];
13944 + edesc->qm_sg_bytes = qm_sg_ents * sizeof(*sg_table);
13945 + edesc->drv_req.app_ctx = req;
13946 + edesc->drv_req.cbk = ablkcipher_done;
13947 + edesc->drv_req.drv_ctx = drv_ctx;
13949 + if (mapped_src_nents > 1)
13950 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table, 0);
13952 + if (!out_contig) {
13953 + dma_to_qm_sg_one(sg_table + dst_sg_idx, iv_dma, ivsize, 0);
13954 + sg_to_qm_sg_last(req->dst, mapped_dst_nents, sg_table +
13955 + dst_sg_idx + 1, 0);
13958 + edesc->qm_sg_dma = dma_map_single(qidev, sg_table, edesc->qm_sg_bytes,
13960 + if (dma_mapping_error(qidev, edesc->qm_sg_dma)) {
13961 + dev_err(qidev, "unable to map S/G table\n");
13962 + caam_unmap(qidev, req->src, req->dst, src_nents, dst_nents,
13963 + iv_dma, ivsize, GIVENCRYPT, 0, 0);
13964 + qi_cache_free(edesc);
13965 + return ERR_PTR(-ENOMEM);
13968 + fd_sgt = &edesc->drv_req.fd_sgt[0];
13970 + if (mapped_src_nents > 1)
13971 + dma_to_qm_sg_one_ext(&fd_sgt[1], edesc->qm_sg_dma, req->nbytes,
13974 + dma_to_qm_sg_one(&fd_sgt[1], sg_dma_address(req->src),
13978 + dma_to_qm_sg_one_ext(&fd_sgt[0], edesc->qm_sg_dma + dst_sg_idx *
13979 + sizeof(*sg_table), ivsize + req->nbytes,
13982 + dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->dst),
13983 + ivsize + req->nbytes, 0);
13988 +static inline int ablkcipher_crypt(struct ablkcipher_request *req, bool encrypt)
13990 + struct ablkcipher_edesc *edesc;
13991 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
13992 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
13995 + if (unlikely(caam_congested))
13998 + /* allocate extended descriptor */
13999 + edesc = ablkcipher_edesc_alloc(req, encrypt);
14000 + if (IS_ERR(edesc))
14001 + return PTR_ERR(edesc);
14003 + ret = caam_qi_enqueue(ctx->qidev, &edesc->drv_req);
14005 + ret = -EINPROGRESS;
14007 + ablkcipher_unmap(ctx->qidev, edesc, req);
14008 + qi_cache_free(edesc);
14014 +static int ablkcipher_encrypt(struct ablkcipher_request *req)
14016 + return ablkcipher_crypt(req, true);
14019 +static int ablkcipher_decrypt(struct ablkcipher_request *req)
14021 + return ablkcipher_crypt(req, false);
14024 +static int ablkcipher_givencrypt(struct skcipher_givcrypt_request *creq)
14026 + struct ablkcipher_request *req = &creq->creq;
14027 + struct ablkcipher_edesc *edesc;
14028 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
14029 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
14032 + if (unlikely(caam_congested))
14035 + /* allocate extended descriptor */
14036 + edesc = ablkcipher_giv_edesc_alloc(creq);
14037 + if (IS_ERR(edesc))
14038 + return PTR_ERR(edesc);
14040 + ret = caam_qi_enqueue(ctx->qidev, &edesc->drv_req);
14042 + ret = -EINPROGRESS;
14044 + ablkcipher_unmap(ctx->qidev, edesc, req);
14045 + qi_cache_free(edesc);
14051 +#define template_ablkcipher template_u.ablkcipher
14052 +struct caam_alg_template {
14053 + char name[CRYPTO_MAX_ALG_NAME];
14054 + char driver_name[CRYPTO_MAX_ALG_NAME];
14055 + unsigned int blocksize;
14058 + struct ablkcipher_alg ablkcipher;
14060 + u32 class1_alg_type;
14061 + u32 class2_alg_type;
14064 +static struct caam_alg_template driver_algs[] = {
14065 + /* ablkcipher descriptor */
14067 + .name = "cbc(aes)",
14068 + .driver_name = "cbc-aes-caam-qi",
14069 + .blocksize = AES_BLOCK_SIZE,
14070 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
14071 + .template_ablkcipher = {
14072 + .setkey = ablkcipher_setkey,
14073 + .encrypt = ablkcipher_encrypt,
14074 + .decrypt = ablkcipher_decrypt,
14075 + .givencrypt = ablkcipher_givencrypt,
14076 + .geniv = "<built-in>",
14077 + .min_keysize = AES_MIN_KEY_SIZE,
14078 + .max_keysize = AES_MAX_KEY_SIZE,
14079 + .ivsize = AES_BLOCK_SIZE,
14081 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14084 + .name = "cbc(des3_ede)",
14085 + .driver_name = "cbc-3des-caam-qi",
14086 + .blocksize = DES3_EDE_BLOCK_SIZE,
14087 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
14088 + .template_ablkcipher = {
14089 + .setkey = ablkcipher_setkey,
14090 + .encrypt = ablkcipher_encrypt,
14091 + .decrypt = ablkcipher_decrypt,
14092 + .givencrypt = ablkcipher_givencrypt,
14093 + .geniv = "<built-in>",
14094 + .min_keysize = DES3_EDE_KEY_SIZE,
14095 + .max_keysize = DES3_EDE_KEY_SIZE,
14096 + .ivsize = DES3_EDE_BLOCK_SIZE,
14098 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14101 + .name = "cbc(des)",
14102 + .driver_name = "cbc-des-caam-qi",
14103 + .blocksize = DES_BLOCK_SIZE,
14104 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
14105 + .template_ablkcipher = {
14106 + .setkey = ablkcipher_setkey,
14107 + .encrypt = ablkcipher_encrypt,
14108 + .decrypt = ablkcipher_decrypt,
14109 + .givencrypt = ablkcipher_givencrypt,
14110 + .geniv = "<built-in>",
14111 + .min_keysize = DES_KEY_SIZE,
14112 + .max_keysize = DES_KEY_SIZE,
14113 + .ivsize = DES_BLOCK_SIZE,
14115 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14118 + .name = "ctr(aes)",
14119 + .driver_name = "ctr-aes-caam-qi",
14121 + .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
14122 + .template_ablkcipher = {
14123 + .setkey = ablkcipher_setkey,
14124 + .encrypt = ablkcipher_encrypt,
14125 + .decrypt = ablkcipher_decrypt,
14126 + .geniv = "chainiv",
14127 + .min_keysize = AES_MIN_KEY_SIZE,
14128 + .max_keysize = AES_MAX_KEY_SIZE,
14129 + .ivsize = AES_BLOCK_SIZE,
14131 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
14134 + .name = "rfc3686(ctr(aes))",
14135 + .driver_name = "rfc3686-ctr-aes-caam-qi",
14137 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
14138 + .template_ablkcipher = {
14139 + .setkey = ablkcipher_setkey,
14140 + .encrypt = ablkcipher_encrypt,
14141 + .decrypt = ablkcipher_decrypt,
14142 + .givencrypt = ablkcipher_givencrypt,
14143 + .geniv = "<built-in>",
14144 + .min_keysize = AES_MIN_KEY_SIZE +
14145 + CTR_RFC3686_NONCE_SIZE,
14146 + .max_keysize = AES_MAX_KEY_SIZE +
14147 + CTR_RFC3686_NONCE_SIZE,
14148 + .ivsize = CTR_RFC3686_IV_SIZE,
14150 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
14153 + .name = "xts(aes)",
14154 + .driver_name = "xts-aes-caam-qi",
14155 + .blocksize = AES_BLOCK_SIZE,
14156 + .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
14157 + .template_ablkcipher = {
14158 + .setkey = xts_ablkcipher_setkey,
14159 + .encrypt = ablkcipher_encrypt,
14160 + .decrypt = ablkcipher_decrypt,
14161 + .geniv = "eseqiv",
14162 + .min_keysize = 2 * AES_MIN_KEY_SIZE,
14163 + .max_keysize = 2 * AES_MAX_KEY_SIZE,
14164 + .ivsize = AES_BLOCK_SIZE,
14166 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
14170 +static struct caam_aead_alg driver_aeads[] = {
14171 + /* single-pass ipsec_esp descriptor */
14175 + .cra_name = "authenc(hmac(md5),cbc(aes))",
14176 + .cra_driver_name = "authenc-hmac-md5-"
14177 + "cbc-aes-caam-qi",
14178 + .cra_blocksize = AES_BLOCK_SIZE,
14180 + .setkey = aead_setkey,
14181 + .setauthsize = aead_setauthsize,
14182 + .encrypt = aead_encrypt,
14183 + .decrypt = aead_decrypt,
14184 + .ivsize = AES_BLOCK_SIZE,
14185 + .maxauthsize = MD5_DIGEST_SIZE,
14188 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14189 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
14190 + OP_ALG_AAI_HMAC_PRECOMP,
14196 + .cra_name = "echainiv(authenc(hmac(md5),"
14198 + .cra_driver_name = "echainiv-authenc-hmac-md5-"
14199 + "cbc-aes-caam-qi",
14200 + .cra_blocksize = AES_BLOCK_SIZE,
14202 + .setkey = aead_setkey,
14203 + .setauthsize = aead_setauthsize,
14204 + .encrypt = aead_encrypt,
14205 + .decrypt = aead_decrypt,
14206 + .ivsize = AES_BLOCK_SIZE,
14207 + .maxauthsize = MD5_DIGEST_SIZE,
14210 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14211 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
14212 + OP_ALG_AAI_HMAC_PRECOMP,
14219 + .cra_name = "authenc(hmac(sha1),cbc(aes))",
14220 + .cra_driver_name = "authenc-hmac-sha1-"
14221 + "cbc-aes-caam-qi",
14222 + .cra_blocksize = AES_BLOCK_SIZE,
14224 + .setkey = aead_setkey,
14225 + .setauthsize = aead_setauthsize,
14226 + .encrypt = aead_encrypt,
14227 + .decrypt = aead_decrypt,
14228 + .ivsize = AES_BLOCK_SIZE,
14229 + .maxauthsize = SHA1_DIGEST_SIZE,
14232 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14233 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
14234 + OP_ALG_AAI_HMAC_PRECOMP,
14240 + .cra_name = "echainiv(authenc(hmac(sha1),"
14242 + .cra_driver_name = "echainiv-authenc-"
14243 + "hmac-sha1-cbc-aes-caam-qi",
14244 + .cra_blocksize = AES_BLOCK_SIZE,
14246 + .setkey = aead_setkey,
14247 + .setauthsize = aead_setauthsize,
14248 + .encrypt = aead_encrypt,
14249 + .decrypt = aead_decrypt,
14250 + .ivsize = AES_BLOCK_SIZE,
14251 + .maxauthsize = SHA1_DIGEST_SIZE,
14254 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14255 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
14256 + OP_ALG_AAI_HMAC_PRECOMP,
14263 + .cra_name = "authenc(hmac(sha224),cbc(aes))",
14264 + .cra_driver_name = "authenc-hmac-sha224-"
14265 + "cbc-aes-caam-qi",
14266 + .cra_blocksize = AES_BLOCK_SIZE,
14268 + .setkey = aead_setkey,
14269 + .setauthsize = aead_setauthsize,
14270 + .encrypt = aead_encrypt,
14271 + .decrypt = aead_decrypt,
14272 + .ivsize = AES_BLOCK_SIZE,
14273 + .maxauthsize = SHA224_DIGEST_SIZE,
14276 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14277 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
14278 + OP_ALG_AAI_HMAC_PRECOMP,
14284 + .cra_name = "echainiv(authenc(hmac(sha224),"
14286 + .cra_driver_name = "echainiv-authenc-"
14287 + "hmac-sha224-cbc-aes-caam-qi",
14288 + .cra_blocksize = AES_BLOCK_SIZE,
14290 + .setkey = aead_setkey,
14291 + .setauthsize = aead_setauthsize,
14292 + .encrypt = aead_encrypt,
14293 + .decrypt = aead_decrypt,
14294 + .ivsize = AES_BLOCK_SIZE,
14295 + .maxauthsize = SHA224_DIGEST_SIZE,
14298 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14299 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
14300 + OP_ALG_AAI_HMAC_PRECOMP,
14307 + .cra_name = "authenc(hmac(sha256),cbc(aes))",
14308 + .cra_driver_name = "authenc-hmac-sha256-"
14309 + "cbc-aes-caam-qi",
14310 + .cra_blocksize = AES_BLOCK_SIZE,
14312 + .setkey = aead_setkey,
14313 + .setauthsize = aead_setauthsize,
14314 + .encrypt = aead_encrypt,
14315 + .decrypt = aead_decrypt,
14316 + .ivsize = AES_BLOCK_SIZE,
14317 + .maxauthsize = SHA256_DIGEST_SIZE,
14320 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14321 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
14322 + OP_ALG_AAI_HMAC_PRECOMP,
14328 + .cra_name = "echainiv(authenc(hmac(sha256),"
14330 + .cra_driver_name = "echainiv-authenc-"
14331 + "hmac-sha256-cbc-aes-"
14333 + .cra_blocksize = AES_BLOCK_SIZE,
14335 + .setkey = aead_setkey,
14336 + .setauthsize = aead_setauthsize,
14337 + .encrypt = aead_encrypt,
14338 + .decrypt = aead_decrypt,
14339 + .ivsize = AES_BLOCK_SIZE,
14340 + .maxauthsize = SHA256_DIGEST_SIZE,
14343 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14344 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
14345 + OP_ALG_AAI_HMAC_PRECOMP,
14352 + .cra_name = "authenc(hmac(sha384),cbc(aes))",
14353 + .cra_driver_name = "authenc-hmac-sha384-"
14354 + "cbc-aes-caam-qi",
14355 + .cra_blocksize = AES_BLOCK_SIZE,
14357 + .setkey = aead_setkey,
14358 + .setauthsize = aead_setauthsize,
14359 + .encrypt = aead_encrypt,
14360 + .decrypt = aead_decrypt,
14361 + .ivsize = AES_BLOCK_SIZE,
14362 + .maxauthsize = SHA384_DIGEST_SIZE,
14365 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14366 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
14367 + OP_ALG_AAI_HMAC_PRECOMP,
14373 + .cra_name = "echainiv(authenc(hmac(sha384),"
14375 + .cra_driver_name = "echainiv-authenc-"
14376 + "hmac-sha384-cbc-aes-"
14378 + .cra_blocksize = AES_BLOCK_SIZE,
14380 + .setkey = aead_setkey,
14381 + .setauthsize = aead_setauthsize,
14382 + .encrypt = aead_encrypt,
14383 + .decrypt = aead_decrypt,
14384 + .ivsize = AES_BLOCK_SIZE,
14385 + .maxauthsize = SHA384_DIGEST_SIZE,
14388 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14389 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
14390 + OP_ALG_AAI_HMAC_PRECOMP,
14397 + .cra_name = "authenc(hmac(sha512),cbc(aes))",
14398 + .cra_driver_name = "authenc-hmac-sha512-"
14399 + "cbc-aes-caam-qi",
14400 + .cra_blocksize = AES_BLOCK_SIZE,
14402 + .setkey = aead_setkey,
14403 + .setauthsize = aead_setauthsize,
14404 + .encrypt = aead_encrypt,
14405 + .decrypt = aead_decrypt,
14406 + .ivsize = AES_BLOCK_SIZE,
14407 + .maxauthsize = SHA512_DIGEST_SIZE,
14410 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14411 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
14412 + OP_ALG_AAI_HMAC_PRECOMP,
14418 + .cra_name = "echainiv(authenc(hmac(sha512),"
14420 + .cra_driver_name = "echainiv-authenc-"
14421 + "hmac-sha512-cbc-aes-"
14423 + .cra_blocksize = AES_BLOCK_SIZE,
14425 + .setkey = aead_setkey,
14426 + .setauthsize = aead_setauthsize,
14427 + .encrypt = aead_encrypt,
14428 + .decrypt = aead_decrypt,
14429 + .ivsize = AES_BLOCK_SIZE,
14430 + .maxauthsize = SHA512_DIGEST_SIZE,
14433 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14434 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
14435 + OP_ALG_AAI_HMAC_PRECOMP,
14442 + .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
14443 + .cra_driver_name = "authenc-hmac-md5-"
14444 + "cbc-des3_ede-caam-qi",
14445 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14447 + .setkey = aead_setkey,
14448 + .setauthsize = aead_setauthsize,
14449 + .encrypt = aead_encrypt,
14450 + .decrypt = aead_decrypt,
14451 + .ivsize = DES3_EDE_BLOCK_SIZE,
14452 + .maxauthsize = MD5_DIGEST_SIZE,
14455 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14456 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
14457 + OP_ALG_AAI_HMAC_PRECOMP,
14463 + .cra_name = "echainiv(authenc(hmac(md5),"
14464 + "cbc(des3_ede)))",
14465 + .cra_driver_name = "echainiv-authenc-hmac-md5-"
14466 + "cbc-des3_ede-caam-qi",
14467 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14469 + .setkey = aead_setkey,
14470 + .setauthsize = aead_setauthsize,
14471 + .encrypt = aead_encrypt,
14472 + .decrypt = aead_decrypt,
14473 + .ivsize = DES3_EDE_BLOCK_SIZE,
14474 + .maxauthsize = MD5_DIGEST_SIZE,
14477 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14478 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
14479 + OP_ALG_AAI_HMAC_PRECOMP,
14486 + .cra_name = "authenc(hmac(sha1),"
14487 + "cbc(des3_ede))",
14488 + .cra_driver_name = "authenc-hmac-sha1-"
14489 + "cbc-des3_ede-caam-qi",
14490 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14492 + .setkey = aead_setkey,
14493 + .setauthsize = aead_setauthsize,
14494 + .encrypt = aead_encrypt,
14495 + .decrypt = aead_decrypt,
14496 + .ivsize = DES3_EDE_BLOCK_SIZE,
14497 + .maxauthsize = SHA1_DIGEST_SIZE,
14500 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14501 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
14502 + OP_ALG_AAI_HMAC_PRECOMP,
14508 + .cra_name = "echainiv(authenc(hmac(sha1),"
14509 + "cbc(des3_ede)))",
14510 + .cra_driver_name = "echainiv-authenc-"
14512 + "cbc-des3_ede-caam-qi",
14513 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14515 + .setkey = aead_setkey,
14516 + .setauthsize = aead_setauthsize,
14517 + .encrypt = aead_encrypt,
14518 + .decrypt = aead_decrypt,
14519 + .ivsize = DES3_EDE_BLOCK_SIZE,
14520 + .maxauthsize = SHA1_DIGEST_SIZE,
14523 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14524 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
14525 + OP_ALG_AAI_HMAC_PRECOMP,
14532 + .cra_name = "authenc(hmac(sha224),"
14533 + "cbc(des3_ede))",
14534 + .cra_driver_name = "authenc-hmac-sha224-"
14535 + "cbc-des3_ede-caam-qi",
14536 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14538 + .setkey = aead_setkey,
14539 + .setauthsize = aead_setauthsize,
14540 + .encrypt = aead_encrypt,
14541 + .decrypt = aead_decrypt,
14542 + .ivsize = DES3_EDE_BLOCK_SIZE,
14543 + .maxauthsize = SHA224_DIGEST_SIZE,
14546 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14547 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
14548 + OP_ALG_AAI_HMAC_PRECOMP,
14554 + .cra_name = "echainiv(authenc(hmac(sha224),"
14555 + "cbc(des3_ede)))",
14556 + .cra_driver_name = "echainiv-authenc-"
14558 + "cbc-des3_ede-caam-qi",
14559 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14561 + .setkey = aead_setkey,
14562 + .setauthsize = aead_setauthsize,
14563 + .encrypt = aead_encrypt,
14564 + .decrypt = aead_decrypt,
14565 + .ivsize = DES3_EDE_BLOCK_SIZE,
14566 + .maxauthsize = SHA224_DIGEST_SIZE,
14569 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14570 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
14571 + OP_ALG_AAI_HMAC_PRECOMP,
14578 + .cra_name = "authenc(hmac(sha256),"
14579 + "cbc(des3_ede))",
14580 + .cra_driver_name = "authenc-hmac-sha256-"
14581 + "cbc-des3_ede-caam-qi",
14582 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14584 + .setkey = aead_setkey,
14585 + .setauthsize = aead_setauthsize,
14586 + .encrypt = aead_encrypt,
14587 + .decrypt = aead_decrypt,
14588 + .ivsize = DES3_EDE_BLOCK_SIZE,
14589 + .maxauthsize = SHA256_DIGEST_SIZE,
14592 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14593 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
14594 + OP_ALG_AAI_HMAC_PRECOMP,
14600 + .cra_name = "echainiv(authenc(hmac(sha256),"
14601 + "cbc(des3_ede)))",
14602 + .cra_driver_name = "echainiv-authenc-"
14604 + "cbc-des3_ede-caam-qi",
14605 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14607 + .setkey = aead_setkey,
14608 + .setauthsize = aead_setauthsize,
14609 + .encrypt = aead_encrypt,
14610 + .decrypt = aead_decrypt,
14611 + .ivsize = DES3_EDE_BLOCK_SIZE,
14612 + .maxauthsize = SHA256_DIGEST_SIZE,
14615 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14616 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
14617 + OP_ALG_AAI_HMAC_PRECOMP,
14624 + .cra_name = "authenc(hmac(sha384),"
14625 + "cbc(des3_ede))",
14626 + .cra_driver_name = "authenc-hmac-sha384-"
14627 + "cbc-des3_ede-caam-qi",
14628 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14630 + .setkey = aead_setkey,
14631 + .setauthsize = aead_setauthsize,
14632 + .encrypt = aead_encrypt,
14633 + .decrypt = aead_decrypt,
14634 + .ivsize = DES3_EDE_BLOCK_SIZE,
14635 + .maxauthsize = SHA384_DIGEST_SIZE,
14638 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14639 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
14640 + OP_ALG_AAI_HMAC_PRECOMP,
14646 + .cra_name = "echainiv(authenc(hmac(sha384),"
14647 + "cbc(des3_ede)))",
14648 + .cra_driver_name = "echainiv-authenc-"
14650 + "cbc-des3_ede-caam-qi",
14651 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14653 + .setkey = aead_setkey,
14654 + .setauthsize = aead_setauthsize,
14655 + .encrypt = aead_encrypt,
14656 + .decrypt = aead_decrypt,
14657 + .ivsize = DES3_EDE_BLOCK_SIZE,
14658 + .maxauthsize = SHA384_DIGEST_SIZE,
14661 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14662 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
14663 + OP_ALG_AAI_HMAC_PRECOMP,
14670 + .cra_name = "authenc(hmac(sha512),"
14671 + "cbc(des3_ede))",
14672 + .cra_driver_name = "authenc-hmac-sha512-"
14673 + "cbc-des3_ede-caam-qi",
14674 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14676 + .setkey = aead_setkey,
14677 + .setauthsize = aead_setauthsize,
14678 + .encrypt = aead_encrypt,
14679 + .decrypt = aead_decrypt,
14680 + .ivsize = DES3_EDE_BLOCK_SIZE,
14681 + .maxauthsize = SHA512_DIGEST_SIZE,
14684 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14685 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
14686 + OP_ALG_AAI_HMAC_PRECOMP,
14692 + .cra_name = "echainiv(authenc(hmac(sha512),"
14693 + "cbc(des3_ede)))",
14694 + .cra_driver_name = "echainiv-authenc-"
14696 + "cbc-des3_ede-caam-qi",
14697 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
14699 + .setkey = aead_setkey,
14700 + .setauthsize = aead_setauthsize,
14701 + .encrypt = aead_encrypt,
14702 + .decrypt = aead_decrypt,
14703 + .ivsize = DES3_EDE_BLOCK_SIZE,
14704 + .maxauthsize = SHA512_DIGEST_SIZE,
14707 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
14708 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
14709 + OP_ALG_AAI_HMAC_PRECOMP,
14716 + .cra_name = "authenc(hmac(md5),cbc(des))",
14717 + .cra_driver_name = "authenc-hmac-md5-"
14718 + "cbc-des-caam-qi",
14719 + .cra_blocksize = DES_BLOCK_SIZE,
14721 + .setkey = aead_setkey,
14722 + .setauthsize = aead_setauthsize,
14723 + .encrypt = aead_encrypt,
14724 + .decrypt = aead_decrypt,
14725 + .ivsize = DES_BLOCK_SIZE,
14726 + .maxauthsize = MD5_DIGEST_SIZE,
14729 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14730 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
14731 + OP_ALG_AAI_HMAC_PRECOMP,
14737 + .cra_name = "echainiv(authenc(hmac(md5),"
14739 + .cra_driver_name = "echainiv-authenc-hmac-md5-"
14740 + "cbc-des-caam-qi",
14741 + .cra_blocksize = DES_BLOCK_SIZE,
14743 + .setkey = aead_setkey,
14744 + .setauthsize = aead_setauthsize,
14745 + .encrypt = aead_encrypt,
14746 + .decrypt = aead_decrypt,
14747 + .ivsize = DES_BLOCK_SIZE,
14748 + .maxauthsize = MD5_DIGEST_SIZE,
14751 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14752 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
14753 + OP_ALG_AAI_HMAC_PRECOMP,
14760 + .cra_name = "authenc(hmac(sha1),cbc(des))",
14761 + .cra_driver_name = "authenc-hmac-sha1-"
14762 + "cbc-des-caam-qi",
14763 + .cra_blocksize = DES_BLOCK_SIZE,
14765 + .setkey = aead_setkey,
14766 + .setauthsize = aead_setauthsize,
14767 + .encrypt = aead_encrypt,
14768 + .decrypt = aead_decrypt,
14769 + .ivsize = DES_BLOCK_SIZE,
14770 + .maxauthsize = SHA1_DIGEST_SIZE,
14773 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14774 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
14775 + OP_ALG_AAI_HMAC_PRECOMP,
14781 + .cra_name = "echainiv(authenc(hmac(sha1),"
14783 + .cra_driver_name = "echainiv-authenc-"
14784 + "hmac-sha1-cbc-des-caam-qi",
14785 + .cra_blocksize = DES_BLOCK_SIZE,
14787 + .setkey = aead_setkey,
14788 + .setauthsize = aead_setauthsize,
14789 + .encrypt = aead_encrypt,
14790 + .decrypt = aead_decrypt,
14791 + .ivsize = DES_BLOCK_SIZE,
14792 + .maxauthsize = SHA1_DIGEST_SIZE,
14795 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14796 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
14797 + OP_ALG_AAI_HMAC_PRECOMP,
14804 + .cra_name = "authenc(hmac(sha224),cbc(des))",
14805 + .cra_driver_name = "authenc-hmac-sha224-"
14806 + "cbc-des-caam-qi",
14807 + .cra_blocksize = DES_BLOCK_SIZE,
14809 + .setkey = aead_setkey,
14810 + .setauthsize = aead_setauthsize,
14811 + .encrypt = aead_encrypt,
14812 + .decrypt = aead_decrypt,
14813 + .ivsize = DES_BLOCK_SIZE,
14814 + .maxauthsize = SHA224_DIGEST_SIZE,
14817 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14818 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
14819 + OP_ALG_AAI_HMAC_PRECOMP,
14825 + .cra_name = "echainiv(authenc(hmac(sha224),"
14827 + .cra_driver_name = "echainiv-authenc-"
14828 + "hmac-sha224-cbc-des-"
14830 + .cra_blocksize = DES_BLOCK_SIZE,
14832 + .setkey = aead_setkey,
14833 + .setauthsize = aead_setauthsize,
14834 + .encrypt = aead_encrypt,
14835 + .decrypt = aead_decrypt,
14836 + .ivsize = DES_BLOCK_SIZE,
14837 + .maxauthsize = SHA224_DIGEST_SIZE,
14840 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14841 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
14842 + OP_ALG_AAI_HMAC_PRECOMP,
14849 + .cra_name = "authenc(hmac(sha256),cbc(des))",
14850 + .cra_driver_name = "authenc-hmac-sha256-"
14851 + "cbc-des-caam-qi",
14852 + .cra_blocksize = DES_BLOCK_SIZE,
14854 + .setkey = aead_setkey,
14855 + .setauthsize = aead_setauthsize,
14856 + .encrypt = aead_encrypt,
14857 + .decrypt = aead_decrypt,
14858 + .ivsize = DES_BLOCK_SIZE,
14859 + .maxauthsize = SHA256_DIGEST_SIZE,
14862 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14863 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
14864 + OP_ALG_AAI_HMAC_PRECOMP,
14870 + .cra_name = "echainiv(authenc(hmac(sha256),"
14872 + .cra_driver_name = "echainiv-authenc-"
14873 + "hmac-sha256-cbc-des-"
14875 + .cra_blocksize = DES_BLOCK_SIZE,
14877 + .setkey = aead_setkey,
14878 + .setauthsize = aead_setauthsize,
14879 + .encrypt = aead_encrypt,
14880 + .decrypt = aead_decrypt,
14881 + .ivsize = DES_BLOCK_SIZE,
14882 + .maxauthsize = SHA256_DIGEST_SIZE,
14885 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14886 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
14887 + OP_ALG_AAI_HMAC_PRECOMP,
14894 + .cra_name = "authenc(hmac(sha384),cbc(des))",
14895 + .cra_driver_name = "authenc-hmac-sha384-"
14896 + "cbc-des-caam-qi",
14897 + .cra_blocksize = DES_BLOCK_SIZE,
14899 + .setkey = aead_setkey,
14900 + .setauthsize = aead_setauthsize,
14901 + .encrypt = aead_encrypt,
14902 + .decrypt = aead_decrypt,
14903 + .ivsize = DES_BLOCK_SIZE,
14904 + .maxauthsize = SHA384_DIGEST_SIZE,
14907 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14908 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
14909 + OP_ALG_AAI_HMAC_PRECOMP,
14915 + .cra_name = "echainiv(authenc(hmac(sha384),"
14917 + .cra_driver_name = "echainiv-authenc-"
14918 + "hmac-sha384-cbc-des-"
14920 + .cra_blocksize = DES_BLOCK_SIZE,
14922 + .setkey = aead_setkey,
14923 + .setauthsize = aead_setauthsize,
14924 + .encrypt = aead_encrypt,
14925 + .decrypt = aead_decrypt,
14926 + .ivsize = DES_BLOCK_SIZE,
14927 + .maxauthsize = SHA384_DIGEST_SIZE,
14930 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14931 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
14932 + OP_ALG_AAI_HMAC_PRECOMP,
14939 + .cra_name = "authenc(hmac(sha512),cbc(des))",
14940 + .cra_driver_name = "authenc-hmac-sha512-"
14941 + "cbc-des-caam-qi",
14942 + .cra_blocksize = DES_BLOCK_SIZE,
14944 + .setkey = aead_setkey,
14945 + .setauthsize = aead_setauthsize,
14946 + .encrypt = aead_encrypt,
14947 + .decrypt = aead_decrypt,
14948 + .ivsize = DES_BLOCK_SIZE,
14949 + .maxauthsize = SHA512_DIGEST_SIZE,
14952 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14953 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
14954 + OP_ALG_AAI_HMAC_PRECOMP,
14960 + .cra_name = "echainiv(authenc(hmac(sha512),"
14962 + .cra_driver_name = "echainiv-authenc-"
14963 + "hmac-sha512-cbc-des-"
14965 + .cra_blocksize = DES_BLOCK_SIZE,
14967 + .setkey = aead_setkey,
14968 + .setauthsize = aead_setauthsize,
14969 + .encrypt = aead_encrypt,
14970 + .decrypt = aead_decrypt,
14971 + .ivsize = DES_BLOCK_SIZE,
14972 + .maxauthsize = SHA512_DIGEST_SIZE,
14975 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
14976 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
14977 + OP_ALG_AAI_HMAC_PRECOMP,
14984 + .cra_name = "tls10(hmac(sha1),cbc(aes))",
14985 + .cra_driver_name = "tls10-hmac-sha1-cbc-aes-caam-qi",
14986 + .cra_blocksize = AES_BLOCK_SIZE,
14988 + .setkey = tls_setkey,
14989 + .setauthsize = tls_setauthsize,
14990 + .encrypt = tls_encrypt,
14991 + .decrypt = tls_decrypt,
14992 + .ivsize = AES_BLOCK_SIZE,
14993 + .maxauthsize = SHA1_DIGEST_SIZE,
14996 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
14997 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
14998 + OP_ALG_AAI_HMAC_PRECOMP,
15003 +struct caam_crypto_alg {
15004 + struct list_head entry;
15005 + struct crypto_alg crypto_alg;
15006 + struct caam_alg_entry caam;
15009 +static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam)
15011 + struct caam_drv_private *priv;
15012 + /* Digest sizes for MD5, SHA1, SHA-224, SHA-256, SHA-384, SHA-512 */
15013 + static const u8 digest_size[] = {
15015 + SHA1_DIGEST_SIZE,
15016 + SHA224_DIGEST_SIZE,
15017 + SHA256_DIGEST_SIZE,
15018 + SHA384_DIGEST_SIZE,
15019 + SHA512_DIGEST_SIZE
15024 + * distribute tfms across job rings to ensure in-order
15025 + * crypto request processing per tfm
15027 + ctx->jrdev = caam_jr_alloc();
15028 + if (IS_ERR(ctx->jrdev)) {
15029 + pr_err("Job Ring Device allocation for transform failed\n");
15030 + return PTR_ERR(ctx->jrdev);
15033 + ctx->key_dma = dma_map_single(ctx->jrdev, ctx->key, sizeof(ctx->key),
15035 + if (dma_mapping_error(ctx->jrdev, ctx->key_dma)) {
15036 + dev_err(ctx->jrdev, "unable to map key\n");
15037 + caam_jr_free(ctx->jrdev);
15041 + /* copy descriptor header template value */
15042 + ctx->cdata.algtype = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
15043 + ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
15045 + if (ctx->adata.algtype) {
15046 + op_id = (ctx->adata.algtype & OP_ALG_ALGSEL_SUBMASK)
15047 + >> OP_ALG_ALGSEL_SHIFT;
15048 + if (op_id < ARRAY_SIZE(digest_size)) {
15049 + ctx->authsize = digest_size[op_id];
15051 + dev_err(ctx->jrdev,
15052 + "incorrect op_id %d; must be less than %zu\n",
15053 + op_id, ARRAY_SIZE(digest_size));
15054 + caam_jr_free(ctx->jrdev);
15058 + ctx->authsize = 0;
15061 + priv = dev_get_drvdata(ctx->jrdev->parent);
15062 + ctx->qidev = priv->qidev;
15064 + spin_lock_init(&ctx->lock);
15065 + ctx->drv_ctx[ENCRYPT] = NULL;
15066 + ctx->drv_ctx[DECRYPT] = NULL;
15067 + ctx->drv_ctx[GIVENCRYPT] = NULL;
15072 +static int caam_cra_init(struct crypto_tfm *tfm)
15074 + struct crypto_alg *alg = tfm->__crt_alg;
15075 + struct caam_crypto_alg *caam_alg = container_of(alg, typeof(*caam_alg),
15077 + struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
15079 + return caam_init_common(ctx, &caam_alg->caam);
15082 +static int caam_aead_init(struct crypto_aead *tfm)
15084 + struct aead_alg *alg = crypto_aead_alg(tfm);
15085 + struct caam_aead_alg *caam_alg = container_of(alg, typeof(*caam_alg),
15087 + struct caam_ctx *ctx = crypto_aead_ctx(tfm);
15089 + return caam_init_common(ctx, &caam_alg->caam);
15092 +static void caam_exit_common(struct caam_ctx *ctx)
15094 + caam_drv_ctx_rel(ctx->drv_ctx[ENCRYPT]);
15095 + caam_drv_ctx_rel(ctx->drv_ctx[DECRYPT]);
15096 + caam_drv_ctx_rel(ctx->drv_ctx[GIVENCRYPT]);
15098 + dma_unmap_single(ctx->jrdev, ctx->key_dma, sizeof(ctx->key),
15101 + caam_jr_free(ctx->jrdev);
15104 +static void caam_cra_exit(struct crypto_tfm *tfm)
15106 + caam_exit_common(crypto_tfm_ctx(tfm));
15109 +static void caam_aead_exit(struct crypto_aead *tfm)
15111 + caam_exit_common(crypto_aead_ctx(tfm));
15114 +static struct list_head alg_list;
15115 +static void __exit caam_qi_algapi_exit(void)
15117 + struct caam_crypto_alg *t_alg, *n;
15120 + for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
15121 + struct caam_aead_alg *t_alg = driver_aeads + i;
15123 + if (t_alg->registered)
15124 + crypto_unregister_aead(&t_alg->aead);
15127 + if (!alg_list.next)
15130 + list_for_each_entry_safe(t_alg, n, &alg_list, entry) {
15131 + crypto_unregister_alg(&t_alg->crypto_alg);
15132 + list_del(&t_alg->entry);
15137 +static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template
15140 + struct caam_crypto_alg *t_alg;
15141 + struct crypto_alg *alg;
15143 + t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
15145 + return ERR_PTR(-ENOMEM);
15147 + alg = &t_alg->crypto_alg;
15149 + snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
15150 + snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
15151 + template->driver_name);
15152 + alg->cra_module = THIS_MODULE;
15153 + alg->cra_init = caam_cra_init;
15154 + alg->cra_exit = caam_cra_exit;
15155 + alg->cra_priority = CAAM_CRA_PRIORITY;
15156 + alg->cra_blocksize = template->blocksize;
15157 + alg->cra_alignmask = 0;
15158 + alg->cra_ctxsize = sizeof(struct caam_ctx);
15159 + alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
15161 + switch (template->type) {
15162 + case CRYPTO_ALG_TYPE_GIVCIPHER:
15163 + alg->cra_type = &crypto_givcipher_type;
15164 + alg->cra_ablkcipher = template->template_ablkcipher;
15166 + case CRYPTO_ALG_TYPE_ABLKCIPHER:
15167 + alg->cra_type = &crypto_ablkcipher_type;
15168 + alg->cra_ablkcipher = template->template_ablkcipher;
15172 + t_alg->caam.class1_alg_type = template->class1_alg_type;
15173 + t_alg->caam.class2_alg_type = template->class2_alg_type;
15178 +static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
15180 + struct aead_alg *alg = &t_alg->aead;
15182 + alg->base.cra_module = THIS_MODULE;
15183 + alg->base.cra_priority = CAAM_CRA_PRIORITY;
15184 + alg->base.cra_ctxsize = sizeof(struct caam_ctx);
15185 + alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
15187 + alg->init = caam_aead_init;
15188 + alg->exit = caam_aead_exit;
15191 +static int __init caam_qi_algapi_init(void)
15193 + struct device_node *dev_node;
15194 + struct platform_device *pdev;
15195 + struct device *ctrldev;
15196 + struct caam_drv_private *priv;
15197 + int i = 0, err = 0;
15198 + u32 cha_vid, cha_inst, des_inst, aes_inst, md_inst;
15199 + unsigned int md_limit = SHA512_DIGEST_SIZE;
15200 + bool registered = false;
15202 + dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
15204 + dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
15209 + pdev = of_find_device_by_node(dev_node);
15210 + of_node_put(dev_node);
15214 + ctrldev = &pdev->dev;
15215 + priv = dev_get_drvdata(ctrldev);
15218 + * If priv is NULL, it's probably because the caam driver wasn't
15219 + * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
15221 + if (!priv || !priv->qi_present)
15224 + if (caam_dpaa2) {
15225 + dev_info(ctrldev, "caam/qi frontend driver not suitable for DPAA 2.x, aborting...\n");
15229 + INIT_LIST_HEAD(&alg_list);
15232 + * Register crypto algorithms the device supports.
15233 + * First, detect presence and attributes of DES, AES, and MD blocks.
15235 + cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls);
15236 + cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls);
15237 + des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >> CHA_ID_LS_DES_SHIFT;
15238 + aes_inst = (cha_inst & CHA_ID_LS_AES_MASK) >> CHA_ID_LS_AES_SHIFT;
15239 + md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
15241 + /* If MD is present, limit digest size based on LP256 */
15242 + if (md_inst && ((cha_vid & CHA_ID_LS_MD_MASK) == CHA_ID_LS_MD_LP256))
15243 + md_limit = SHA256_DIGEST_SIZE;
15245 + for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
15246 + struct caam_crypto_alg *t_alg;
15247 + struct caam_alg_template *alg = driver_algs + i;
15248 + u32 alg_sel = alg->class1_alg_type & OP_ALG_ALGSEL_MASK;
15250 + /* Skip DES algorithms if not supported by device */
15252 + ((alg_sel == OP_ALG_ALGSEL_3DES) ||
15253 + (alg_sel == OP_ALG_ALGSEL_DES)))
15256 + /* Skip AES algorithms if not supported by device */
15257 + if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
15260 + t_alg = caam_alg_alloc(alg);
15261 + if (IS_ERR(t_alg)) {
15262 + err = PTR_ERR(t_alg);
15263 + dev_warn(priv->qidev, "%s alg allocation failed\n",
15264 + alg->driver_name);
15268 + err = crypto_register_alg(&t_alg->crypto_alg);
15270 + dev_warn(priv->qidev, "%s alg registration failed\n",
15271 + t_alg->crypto_alg.cra_driver_name);
15276 + list_add_tail(&t_alg->entry, &alg_list);
15277 + registered = true;
15280 + for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
15281 + struct caam_aead_alg *t_alg = driver_aeads + i;
15282 + u32 c1_alg_sel = t_alg->caam.class1_alg_type &
15283 + OP_ALG_ALGSEL_MASK;
15284 + u32 c2_alg_sel = t_alg->caam.class2_alg_type &
15285 + OP_ALG_ALGSEL_MASK;
15286 + u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
15288 + /* Skip DES algorithms if not supported by device */
15290 + ((c1_alg_sel == OP_ALG_ALGSEL_3DES) ||
15291 + (c1_alg_sel == OP_ALG_ALGSEL_DES)))
15294 + /* Skip AES algorithms if not supported by device */
15295 + if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES))
15299 + * Check support for AES algorithms not available
15302 + if (((cha_vid & CHA_ID_LS_AES_MASK) == CHA_ID_LS_AES_LP) &&
15303 + (alg_aai == OP_ALG_AAI_GCM))
15307 + * Skip algorithms requiring message digests
15308 + * if MD or MD size is not supported by device.
15310 + if (c2_alg_sel &&
15311 + (!md_inst || (t_alg->aead.maxauthsize > md_limit)))
15314 + caam_aead_alg_init(t_alg);
15316 + err = crypto_register_aead(&t_alg->aead);
15318 + pr_warn("%s alg registration failed\n",
15319 + t_alg->aead.base.cra_driver_name);
15323 + t_alg->registered = true;
15324 + registered = true;
15328 + dev_info(priv->qidev, "algorithms registered in /proc/crypto\n");
15333 +module_init(caam_qi_algapi_init);
15334 +module_exit(caam_qi_algapi_exit);
15336 +MODULE_LICENSE("GPL");
15337 +MODULE_DESCRIPTION("Support for crypto API using CAAM-QI backend");
15338 +MODULE_AUTHOR("Freescale Semiconductor");
15340 +++ b/drivers/crypto/caam/caamalg_qi2.c
15343 + * Copyright 2015-2016 Freescale Semiconductor Inc.
15344 + * Copyright 2017 NXP
15346 + * Redistribution and use in source and binary forms, with or without
15347 + * modification, are permitted provided that the following conditions are met:
15348 + * * Redistributions of source code must retain the above copyright
15349 + * notice, this list of conditions and the following disclaimer.
15350 + * * Redistributions in binary form must reproduce the above copyright
15351 + * notice, this list of conditions and the following disclaimer in the
15352 + * documentation and/or other materials provided with the distribution.
15353 + * * Neither the names of the above-listed copyright holders nor the
15354 + * names of any contributors may be used to endorse or promote products
15355 + * derived from this software without specific prior written permission.
15358 + * ALTERNATIVELY, this software may be distributed under the terms of the
15359 + * GNU General Public License ("GPL") as published by the Free Software
15360 + * Foundation, either version 2 of that License or (at your option) any
15363 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15364 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15365 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15366 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
15367 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
15368 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
15369 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
15370 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
15371 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
15372 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
15373 + * POSSIBILITY OF SUCH DAMAGE.
15376 +#include "compat.h"
15378 +#include "caamalg_qi2.h"
15379 +#include "dpseci_cmd.h"
15380 +#include "desc_constr.h"
15381 +#include "error.h"
15382 +#include "sg_sw_sec4.h"
15383 +#include "sg_sw_qm2.h"
15384 +#include "key_gen.h"
15385 +#include "caamalg_desc.h"
15386 +#include "caamhash_desc.h"
15387 +#include "../../../drivers/staging/fsl-mc/include/mc.h"
15388 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-io.h"
15389 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
15391 +#define CAAM_CRA_PRIORITY 2000
15393 +/* max key is sum of AES_MAX_KEY_SIZE, max split key size */
15394 +#define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE + \
15395 + SHA512_DIGEST_SIZE * 2)
15397 +#ifndef CONFIG_CRYPTO_DEV_FSL_CAAM
15398 +bool caam_little_end;
15399 +EXPORT_SYMBOL(caam_little_end);
15401 +EXPORT_SYMBOL(caam_imx);
15405 + * This is a a cache of buffers, from which the users of CAAM QI driver
15406 + * can allocate short buffers. It's speedier than doing kmalloc on the hotpath.
15407 + * NOTE: A more elegant solution would be to have some headroom in the frames
15408 + * being processed. This can be added by the dpaa2-eth driver. This would
15409 + * pose a problem for userspace application processing which cannot
15410 + * know of this limitation. So for now, this will work.
15411 + * NOTE: The memcache is SMP-safe. No need to handle spinlocks in-here
15413 +static struct kmem_cache *qi_cache;
15415 +struct caam_alg_entry {
15416 + struct device *dev;
15417 + int class1_alg_type;
15418 + int class2_alg_type;
15423 +struct caam_aead_alg {
15424 + struct aead_alg aead;
15425 + struct caam_alg_entry caam;
15430 + * caam_ctx - per-session context
15431 + * @flc: Flow Contexts array
15432 + * @key: virtual address of the key(s): [authentication key], encryption key
15433 + * @flc_dma: I/O virtual addresses of the Flow Contexts
15434 + * @key_dma: I/O virtual address of the key
15435 + * @dev: dpseci device
15436 + * @adata: authentication algorithm details
15437 + * @cdata: encryption algorithm details
15438 + * @authsize: authentication tag (a.k.a. ICV / MAC) size
15441 + struct caam_flc flc[NUM_OP];
15442 + u8 key[CAAM_MAX_KEY_SIZE];
15443 + dma_addr_t flc_dma[NUM_OP];
15444 + dma_addr_t key_dma;
15445 + struct device *dev;
15446 + struct alginfo adata;
15447 + struct alginfo cdata;
15448 + unsigned int authsize;
15451 +void *dpaa2_caam_iova_to_virt(struct dpaa2_caam_priv *priv,
15452 + dma_addr_t iova_addr)
15454 + phys_addr_t phys_addr;
15456 + phys_addr = priv->domain ? iommu_iova_to_phys(priv->domain, iova_addr) :
15459 + return phys_to_virt(phys_addr);
15463 + * qi_cache_zalloc - Allocate buffers from CAAM-QI cache
15465 + * Allocate data on the hotpath. Instead of using kzalloc, one can use the
15466 + * services of the CAAM QI memory cache (backed by kmem_cache). The buffers
15467 + * will have a size of CAAM_QI_MEMCACHE_SIZE, which should be sufficient for
15468 + * hosting 16 SG entries.
15470 + * @flags - flags that would be used for the equivalent kmalloc(..) call
15472 + * Returns a pointer to a retrieved buffer on success or NULL on failure.
15474 +static inline void *qi_cache_zalloc(gfp_t flags)
15476 + return kmem_cache_zalloc(qi_cache, flags);
15480 + * qi_cache_free - Frees buffers allocated from CAAM-QI cache
15482 + * @obj - buffer previously allocated by qi_cache_zalloc
15484 + * No checking is being done, the call is a passthrough call to
15485 + * kmem_cache_free(...)
15487 +static inline void qi_cache_free(void *obj)
15489 + kmem_cache_free(qi_cache, obj);
15492 +static struct caam_request *to_caam_req(struct crypto_async_request *areq)
15494 + switch (crypto_tfm_alg_type(areq->tfm)) {
15495 + case CRYPTO_ALG_TYPE_ABLKCIPHER:
15496 + case CRYPTO_ALG_TYPE_GIVCIPHER:
15497 + return ablkcipher_request_ctx(ablkcipher_request_cast(areq));
15498 + case CRYPTO_ALG_TYPE_AEAD:
15499 + return aead_request_ctx(container_of(areq, struct aead_request,
15501 + case CRYPTO_ALG_TYPE_AHASH:
15502 + return ahash_request_ctx(ahash_request_cast(areq));
15504 + return ERR_PTR(-EINVAL);
15508 +static void caam_unmap(struct device *dev, struct scatterlist *src,
15509 + struct scatterlist *dst, int src_nents,
15510 + int dst_nents, dma_addr_t iv_dma, int ivsize,
15511 + enum optype op_type, dma_addr_t qm_sg_dma,
15514 + if (dst != src) {
15516 + dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
15517 + dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
15519 + dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
15523 + dma_unmap_single(dev, iv_dma, ivsize,
15524 + op_type == GIVENCRYPT ? DMA_FROM_DEVICE :
15528 + dma_unmap_single(dev, qm_sg_dma, qm_sg_bytes, DMA_TO_DEVICE);
15531 +static int aead_set_sh_desc(struct crypto_aead *aead)
15533 + struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
15534 + typeof(*alg), aead);
15535 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
15536 + unsigned int ivsize = crypto_aead_ivsize(aead);
15537 + struct device *dev = ctx->dev;
15538 + struct dpaa2_caam_priv *priv = dev_get_drvdata(dev);
15539 + struct caam_flc *flc;
15541 + u32 ctx1_iv_off = 0;
15542 + u32 *nonce = NULL;
15543 + unsigned int data_len[2];
15545 + const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
15546 + OP_ALG_AAI_CTR_MOD128);
15547 + const bool is_rfc3686 = alg->caam.rfc3686;
15549 + if (!ctx->cdata.keylen || !ctx->authsize)
15553 + * AES-CTR needs to load IV in CONTEXT1 reg
15554 + * at an offset of 128bits (16bytes)
15555 + * CONTEXT1[255:128] = IV
15558 + ctx1_iv_off = 16;
15561 + * RFC3686 specific:
15562 + * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
15564 + if (is_rfc3686) {
15565 + ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
15566 + nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
15567 + ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
15570 + data_len[0] = ctx->adata.keylen_pad;
15571 + data_len[1] = ctx->cdata.keylen;
15573 + /* aead_encrypt shared descriptor */
15574 + if (desc_inline_query((alg->caam.geniv ? DESC_QI_AEAD_GIVENC_LEN :
15575 + DESC_QI_AEAD_ENC_LEN) +
15576 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
15577 + DESC_JOB_IO_LEN, data_len, &inl_mask,
15578 + ARRAY_SIZE(data_len)) < 0)
15581 + if (inl_mask & 1)
15582 + ctx->adata.key_virt = ctx->key;
15584 + ctx->adata.key_dma = ctx->key_dma;
15586 + if (inl_mask & 2)
15587 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
15589 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
15591 + ctx->adata.key_inline = !!(inl_mask & 1);
15592 + ctx->cdata.key_inline = !!(inl_mask & 2);
15594 + flc = &ctx->flc[ENCRYPT];
15595 + desc = flc->sh_desc;
15597 + if (alg->caam.geniv)
15598 + cnstr_shdsc_aead_givencap(desc, &ctx->cdata, &ctx->adata,
15599 + ivsize, ctx->authsize, is_rfc3686,
15600 + nonce, ctx1_iv_off, true,
15601 + priv->sec_attr.era);
15603 + cnstr_shdsc_aead_encap(desc, &ctx->cdata, &ctx->adata,
15604 + ivsize, ctx->authsize, is_rfc3686, nonce,
15605 + ctx1_iv_off, true, priv->sec_attr.era);
15607 + flc->flc[1] = desc_len(desc); /* SDL */
15608 + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT],
15609 + sizeof(flc->flc) + desc_bytes(desc),
15610 + DMA_BIDIRECTIONAL);
15612 + /* aead_decrypt shared descriptor */
15613 + if (desc_inline_query(DESC_QI_AEAD_DEC_LEN +
15614 + (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
15615 + DESC_JOB_IO_LEN, data_len, &inl_mask,
15616 + ARRAY_SIZE(data_len)) < 0)
15619 + if (inl_mask & 1)
15620 + ctx->adata.key_virt = ctx->key;
15622 + ctx->adata.key_dma = ctx->key_dma;
15624 + if (inl_mask & 2)
15625 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
15627 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
15629 + ctx->adata.key_inline = !!(inl_mask & 1);
15630 + ctx->cdata.key_inline = !!(inl_mask & 2);
15632 + flc = &ctx->flc[DECRYPT];
15633 + desc = flc->sh_desc;
15634 + cnstr_shdsc_aead_decap(desc, &ctx->cdata, &ctx->adata,
15635 + ivsize, ctx->authsize, alg->caam.geniv,
15636 + is_rfc3686, nonce, ctx1_iv_off, true,
15637 + priv->sec_attr.era);
15638 + flc->flc[1] = desc_len(desc); /* SDL */
15639 + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT],
15640 + sizeof(flc->flc) + desc_bytes(desc),
15641 + DMA_BIDIRECTIONAL);
15646 +static int aead_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
15648 + struct caam_ctx *ctx = crypto_aead_ctx(authenc);
15650 + ctx->authsize = authsize;
15651 + aead_set_sh_desc(authenc);
15656 +struct split_key_sh_result {
15657 + struct completion completion;
15659 + struct device *dev;
15662 +static void split_key_sh_done(void *cbk_ctx, u32 err)
15664 + struct split_key_sh_result *res = cbk_ctx;
15667 + dev_err(res->dev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
15671 + caam_qi2_strstatus(res->dev, err);
15674 + complete(&res->completion);
15677 +static int aead_setkey(struct crypto_aead *aead, const u8 *key,
15678 + unsigned int keylen)
15680 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
15681 + struct device *dev = ctx->dev;
15682 + struct crypto_authenc_keys keys;
15684 + if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
15688 + dev_err(dev, "keylen %d enckeylen %d authkeylen %d\n",
15689 + keys.authkeylen + keys.enckeylen, keys.enckeylen,
15690 + keys.authkeylen);
15691 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
15692 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
15695 + ctx->adata.keylen = keys.authkeylen;
15696 + ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
15697 + OP_ALG_ALGSEL_MASK);
15699 + if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE)
15702 + memcpy(ctx->key, keys.authkey, keys.authkeylen);
15703 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
15704 + dma_sync_single_for_device(dev, ctx->key_dma, ctx->adata.keylen_pad +
15705 + keys.enckeylen, DMA_BIDIRECTIONAL);
15707 + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ",
15708 + DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
15709 + ctx->adata.keylen_pad + keys.enckeylen, 1);
15712 + ctx->cdata.keylen = keys.enckeylen;
15714 + return aead_set_sh_desc(aead);
15716 + crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
15720 +static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
15723 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
15724 + struct caam_request *req_ctx = aead_request_ctx(req);
15725 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
15726 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
15727 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
15728 + struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
15729 + typeof(*alg), aead);
15730 + struct device *dev = ctx->dev;
15731 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
15732 + GFP_KERNEL : GFP_ATOMIC;
15733 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
15734 + struct aead_edesc *edesc;
15735 + dma_addr_t qm_sg_dma, iv_dma = 0;
15737 + unsigned int authsize = ctx->authsize;
15738 + int qm_sg_index = 0, qm_sg_nents = 0, qm_sg_bytes;
15739 + int in_len, out_len;
15740 + struct dpaa2_sg_entry *sg_table;
15741 + enum optype op_type = encrypt ? ENCRYPT : DECRYPT;
15743 + /* allocate space for base edesc and link tables */
15744 + edesc = qi_cache_zalloc(GFP_DMA | flags);
15745 + if (unlikely(!edesc)) {
15746 + dev_err(dev, "could not allocate extended descriptor\n");
15747 + return ERR_PTR(-ENOMEM);
15750 + if (unlikely(req->dst != req->src)) {
15751 + src_nents = sg_nents_for_len(req->src, req->assoclen +
15753 + if (unlikely(src_nents < 0)) {
15754 + dev_err(dev, "Insufficient bytes (%d) in src S/G\n",
15755 + req->assoclen + req->cryptlen);
15756 + qi_cache_free(edesc);
15757 + return ERR_PTR(src_nents);
15760 + dst_nents = sg_nents_for_len(req->dst, req->assoclen +
15762 + (encrypt ? authsize :
15764 + if (unlikely(dst_nents < 0)) {
15765 + dev_err(dev, "Insufficient bytes (%d) in dst S/G\n",
15766 + req->assoclen + req->cryptlen +
15767 + (encrypt ? authsize : (-authsize)));
15768 + qi_cache_free(edesc);
15769 + return ERR_PTR(dst_nents);
15773 + mapped_src_nents = dma_map_sg(dev, req->src, src_nents,
15775 + if (unlikely(!mapped_src_nents)) {
15776 + dev_err(dev, "unable to map source\n");
15777 + qi_cache_free(edesc);
15778 + return ERR_PTR(-ENOMEM);
15781 + mapped_src_nents = 0;
15784 + mapped_dst_nents = dma_map_sg(dev, req->dst, dst_nents,
15785 + DMA_FROM_DEVICE);
15786 + if (unlikely(!mapped_dst_nents)) {
15787 + dev_err(dev, "unable to map destination\n");
15788 + dma_unmap_sg(dev, req->src, src_nents, DMA_TO_DEVICE);
15789 + qi_cache_free(edesc);
15790 + return ERR_PTR(-ENOMEM);
15793 + src_nents = sg_nents_for_len(req->src, req->assoclen +
15795 + (encrypt ? authsize : 0));
15796 + if (unlikely(src_nents < 0)) {
15797 + dev_err(dev, "Insufficient bytes (%d) in src S/G\n",
15798 + req->assoclen + req->cryptlen +
15799 + (encrypt ? authsize : 0));
15800 + qi_cache_free(edesc);
15801 + return ERR_PTR(src_nents);
15804 + mapped_src_nents = dma_map_sg(dev, req->src, src_nents,
15805 + DMA_BIDIRECTIONAL);
15806 + if (unlikely(!mapped_src_nents)) {
15807 + dev_err(dev, "unable to map source\n");
15808 + qi_cache_free(edesc);
15809 + return ERR_PTR(-ENOMEM);
15813 + if ((alg->caam.rfc3686 && encrypt) || !alg->caam.geniv) {
15814 + ivsize = crypto_aead_ivsize(aead);
15815 + iv_dma = dma_map_single(dev, req->iv, ivsize, DMA_TO_DEVICE);
15816 + if (dma_mapping_error(dev, iv_dma)) {
15817 + dev_err(dev, "unable to map IV\n");
15818 + caam_unmap(dev, req->src, req->dst, src_nents,
15819 + dst_nents, 0, 0, op_type, 0, 0);
15820 + qi_cache_free(edesc);
15821 + return ERR_PTR(-ENOMEM);
15826 + * Create S/G table: req->assoclen, [IV,] req->src [, req->dst].
15827 + * Input is not contiguous.
15829 + qm_sg_nents = 1 + !!ivsize + mapped_src_nents +
15830 + (mapped_dst_nents > 1 ? mapped_dst_nents : 0);
15831 + if (unlikely(qm_sg_nents > CAAM_QI_MAX_AEAD_SG)) {
15832 + dev_err(dev, "Insufficient S/G entries: %d > %lu\n",
15833 + qm_sg_nents, CAAM_QI_MAX_AEAD_SG);
15834 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
15835 + iv_dma, ivsize, op_type, 0, 0);
15836 + qi_cache_free(edesc);
15837 + return ERR_PTR(-ENOMEM);
15839 + sg_table = &edesc->sgt[0];
15840 + qm_sg_bytes = qm_sg_nents * sizeof(*sg_table);
15842 + edesc->src_nents = src_nents;
15843 + edesc->dst_nents = dst_nents;
15844 + edesc->iv_dma = iv_dma;
15846 + edesc->assoclen_dma = dma_map_single(dev, &req->assoclen, 4,
15848 + if (dma_mapping_error(dev, edesc->assoclen_dma)) {
15849 + dev_err(dev, "unable to map assoclen\n");
15850 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
15851 + iv_dma, ivsize, op_type, 0, 0);
15852 + qi_cache_free(edesc);
15853 + return ERR_PTR(-ENOMEM);
15856 + dma_to_qm_sg_one(sg_table, edesc->assoclen_dma, 4, 0);
15859 + dma_to_qm_sg_one(sg_table + qm_sg_index, iv_dma, ivsize, 0);
15862 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table + qm_sg_index, 0);
15863 + qm_sg_index += mapped_src_nents;
15865 + if (mapped_dst_nents > 1)
15866 + sg_to_qm_sg_last(req->dst, mapped_dst_nents, sg_table +
15869 + qm_sg_dma = dma_map_single(dev, sg_table, qm_sg_bytes, DMA_TO_DEVICE);
15870 + if (dma_mapping_error(dev, qm_sg_dma)) {
15871 + dev_err(dev, "unable to map S/G table\n");
15872 + dma_unmap_single(dev, edesc->assoclen_dma, 4, DMA_TO_DEVICE);
15873 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
15874 + iv_dma, ivsize, op_type, 0, 0);
15875 + qi_cache_free(edesc);
15876 + return ERR_PTR(-ENOMEM);
15879 + edesc->qm_sg_dma = qm_sg_dma;
15880 + edesc->qm_sg_bytes = qm_sg_bytes;
15882 + out_len = req->assoclen + req->cryptlen +
15883 + (encrypt ? ctx->authsize : (-ctx->authsize));
15884 + in_len = 4 + ivsize + req->assoclen + req->cryptlen;
15886 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
15887 + dpaa2_fl_set_final(in_fle, true);
15888 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
15889 + dpaa2_fl_set_addr(in_fle, qm_sg_dma);
15890 + dpaa2_fl_set_len(in_fle, in_len);
15892 + if (req->dst == req->src) {
15893 + if (mapped_src_nents == 1) {
15894 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
15895 + dpaa2_fl_set_addr(out_fle, sg_dma_address(req->src));
15897 + dpaa2_fl_set_format(out_fle, dpaa2_fl_sg);
15898 + dpaa2_fl_set_addr(out_fle, qm_sg_dma +
15899 + (1 + !!ivsize) * sizeof(*sg_table));
15901 + } else if (mapped_dst_nents == 1) {
15902 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
15903 + dpaa2_fl_set_addr(out_fle, sg_dma_address(req->dst));
15905 + dpaa2_fl_set_format(out_fle, dpaa2_fl_sg);
15906 + dpaa2_fl_set_addr(out_fle, qm_sg_dma + qm_sg_index *
15907 + sizeof(*sg_table));
15910 + dpaa2_fl_set_len(out_fle, out_len);
15915 +static struct tls_edesc *tls_edesc_alloc(struct aead_request *req,
15918 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
15919 + unsigned int blocksize = crypto_aead_blocksize(tls);
15920 + unsigned int padsize, authsize;
15921 + struct caam_request *req_ctx = aead_request_ctx(req);
15922 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
15923 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
15924 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
15925 + struct caam_aead_alg *alg = container_of(crypto_aead_alg(tls),
15926 + typeof(*alg), aead);
15927 + struct device *dev = ctx->dev;
15928 + gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
15929 + CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
15930 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
15931 + struct tls_edesc *edesc;
15932 + dma_addr_t qm_sg_dma, iv_dma = 0;
15934 + int qm_sg_index, qm_sg_ents = 0, qm_sg_bytes;
15935 + int in_len, out_len;
15936 + struct dpaa2_sg_entry *sg_table;
15937 + enum optype op_type = encrypt ? ENCRYPT : DECRYPT;
15938 + struct scatterlist *dst;
15941 + padsize = blocksize - ((req->cryptlen + ctx->authsize) %
15943 + authsize = ctx->authsize + padsize;
15945 + authsize = ctx->authsize;
15948 + /* allocate space for base edesc and link tables */
15949 + edesc = qi_cache_zalloc(GFP_DMA | flags);
15950 + if (unlikely(!edesc)) {
15951 + dev_err(dev, "could not allocate extended descriptor\n");
15952 + return ERR_PTR(-ENOMEM);
15955 + if (likely(req->src == req->dst)) {
15956 + src_nents = sg_nents_for_len(req->src, req->assoclen +
15958 + (encrypt ? authsize : 0));
15959 + if (unlikely(src_nents < 0)) {
15960 + dev_err(dev, "Insufficient bytes (%d) in src S/G\n",
15961 + req->assoclen + req->cryptlen +
15962 + (encrypt ? authsize : 0));
15963 + qi_cache_free(edesc);
15964 + return ERR_PTR(src_nents);
15967 + mapped_src_nents = dma_map_sg(dev, req->src, src_nents,
15968 + DMA_BIDIRECTIONAL);
15969 + if (unlikely(!mapped_src_nents)) {
15970 + dev_err(dev, "unable to map source\n");
15971 + qi_cache_free(edesc);
15972 + return ERR_PTR(-ENOMEM);
15976 + src_nents = sg_nents_for_len(req->src, req->assoclen +
15978 + if (unlikely(src_nents < 0)) {
15979 + dev_err(dev, "Insufficient bytes (%d) in src S/G\n",
15980 + req->assoclen + req->cryptlen);
15981 + qi_cache_free(edesc);
15982 + return ERR_PTR(src_nents);
15985 + dst = scatterwalk_ffwd(edesc->tmp, req->dst, req->assoclen);
15986 + dst_nents = sg_nents_for_len(dst, req->cryptlen +
15987 + (encrypt ? authsize : 0));
15988 + if (unlikely(dst_nents < 0)) {
15989 + dev_err(dev, "Insufficient bytes (%d) in dst S/G\n",
15991 + (encrypt ? authsize : 0));
15992 + qi_cache_free(edesc);
15993 + return ERR_PTR(dst_nents);
15997 + mapped_src_nents = dma_map_sg(dev, req->src,
15998 + src_nents, DMA_TO_DEVICE);
15999 + if (unlikely(!mapped_src_nents)) {
16000 + dev_err(dev, "unable to map source\n");
16001 + qi_cache_free(edesc);
16002 + return ERR_PTR(-ENOMEM);
16005 + mapped_src_nents = 0;
16008 + mapped_dst_nents = dma_map_sg(dev, dst, dst_nents,
16009 + DMA_FROM_DEVICE);
16010 + if (unlikely(!mapped_dst_nents)) {
16011 + dev_err(dev, "unable to map destination\n");
16012 + dma_unmap_sg(dev, req->src, src_nents, DMA_TO_DEVICE);
16013 + qi_cache_free(edesc);
16014 + return ERR_PTR(-ENOMEM);
16018 + ivsize = crypto_aead_ivsize(tls);
16019 + iv_dma = dma_map_single(dev, req->iv, ivsize, DMA_TO_DEVICE);
16020 + if (dma_mapping_error(dev, iv_dma)) {
16021 + dev_err(dev, "unable to map IV\n");
16022 + caam_unmap(dev, req->src, dst, src_nents, dst_nents, 0, 0,
16024 + qi_cache_free(edesc);
16025 + return ERR_PTR(-ENOMEM);
16029 + * Create S/G table: IV, src, dst.
16030 + * Input is not contiguous.
16032 + qm_sg_ents = 1 + mapped_src_nents +
16033 + (mapped_dst_nents > 1 ? mapped_dst_nents : 0);
16034 + sg_table = &edesc->sgt[0];
16035 + qm_sg_bytes = qm_sg_ents * sizeof(*sg_table);
16037 + edesc->src_nents = src_nents;
16038 + edesc->dst_nents = dst_nents;
16039 + edesc->dst = dst;
16040 + edesc->iv_dma = iv_dma;
16042 + dma_to_qm_sg_one(sg_table, iv_dma, ivsize, 0);
16045 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table + qm_sg_index, 0);
16046 + qm_sg_index += mapped_src_nents;
16048 + if (mapped_dst_nents > 1)
16049 + sg_to_qm_sg_last(dst, mapped_dst_nents, sg_table +
16052 + qm_sg_dma = dma_map_single(dev, sg_table, qm_sg_bytes, DMA_TO_DEVICE);
16053 + if (dma_mapping_error(dev, qm_sg_dma)) {
16054 + dev_err(dev, "unable to map S/G table\n");
16055 + caam_unmap(dev, req->src, dst, src_nents, dst_nents, iv_dma,
16056 + ivsize, op_type, 0, 0);
16057 + qi_cache_free(edesc);
16058 + return ERR_PTR(-ENOMEM);
16061 + edesc->qm_sg_dma = qm_sg_dma;
16062 + edesc->qm_sg_bytes = qm_sg_bytes;
16064 + out_len = req->cryptlen + (encrypt ? authsize : 0);
16065 + in_len = ivsize + req->assoclen + req->cryptlen;
16067 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
16068 + dpaa2_fl_set_final(in_fle, true);
16069 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
16070 + dpaa2_fl_set_addr(in_fle, qm_sg_dma);
16071 + dpaa2_fl_set_len(in_fle, in_len);
16073 + if (req->dst == req->src) {
16074 + dpaa2_fl_set_format(out_fle, dpaa2_fl_sg);
16075 + dpaa2_fl_set_addr(out_fle, qm_sg_dma +
16076 + (sg_nents_for_len(req->src, req->assoclen) +
16077 + 1) * sizeof(*sg_table));
16078 + } else if (mapped_dst_nents == 1) {
16079 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
16080 + dpaa2_fl_set_addr(out_fle, sg_dma_address(dst));
16082 + dpaa2_fl_set_format(out_fle, dpaa2_fl_sg);
16083 + dpaa2_fl_set_addr(out_fle, qm_sg_dma + qm_sg_index *
16084 + sizeof(*sg_table));
16087 + dpaa2_fl_set_len(out_fle, out_len);
16092 +static int tls_set_sh_desc(struct crypto_aead *tls)
16094 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
16095 + unsigned int ivsize = crypto_aead_ivsize(tls);
16096 + unsigned int blocksize = crypto_aead_blocksize(tls);
16097 + struct device *dev = ctx->dev;
16098 + struct dpaa2_caam_priv *priv = dev_get_drvdata(dev);
16099 + struct caam_flc *flc;
16101 + unsigned int assoclen = 13; /* always 13 bytes for TLS */
16102 + unsigned int data_len[2];
16105 + if (!ctx->cdata.keylen || !ctx->authsize)
16109 + * TLS 1.0 encrypt shared descriptor
16110 + * Job Descriptor and Shared Descriptor
16111 + * must fit into the 64-word Descriptor h/w Buffer
16113 + data_len[0] = ctx->adata.keylen_pad;
16114 + data_len[1] = ctx->cdata.keylen;
16116 + if (desc_inline_query(DESC_TLS10_ENC_LEN, DESC_JOB_IO_LEN, data_len,
16117 + &inl_mask, ARRAY_SIZE(data_len)) < 0)
16120 + if (inl_mask & 1)
16121 + ctx->adata.key_virt = ctx->key;
16123 + ctx->adata.key_dma = ctx->key_dma;
16125 + if (inl_mask & 2)
16126 + ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
16128 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
16130 + ctx->adata.key_inline = !!(inl_mask & 1);
16131 + ctx->cdata.key_inline = !!(inl_mask & 2);
16133 + flc = &ctx->flc[ENCRYPT];
16134 + desc = flc->sh_desc;
16135 + cnstr_shdsc_tls_encap(desc, &ctx->cdata, &ctx->adata,
16136 + assoclen, ivsize, ctx->authsize, blocksize,
16137 + priv->sec_attr.era);
16138 + flc->flc[1] = desc_len(desc);
16139 + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT],
16140 + sizeof(flc->flc) + desc_bytes(desc),
16141 + DMA_BIDIRECTIONAL);
16144 + * TLS 1.0 decrypt shared descriptor
16145 + * Keys do not fit inline, regardless of algorithms used
16147 + ctx->adata.key_inline = false;
16148 + ctx->adata.key_dma = ctx->key_dma;
16149 + ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
16151 + flc = &ctx->flc[DECRYPT];
16152 + desc = flc->sh_desc;
16153 + cnstr_shdsc_tls_decap(desc, &ctx->cdata, &ctx->adata, assoclen, ivsize,
16154 + ctx->authsize, blocksize, priv->sec_attr.era);
16155 + flc->flc[1] = desc_len(desc); /* SDL */
16156 + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT],
16157 + sizeof(flc->flc) + desc_bytes(desc),
16158 + DMA_BIDIRECTIONAL);
16163 +static int tls_setkey(struct crypto_aead *tls, const u8 *key,
16164 + unsigned int keylen)
16166 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
16167 + struct device *dev = ctx->dev;
16168 + struct crypto_authenc_keys keys;
16170 + if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
16174 + dev_err(dev, "keylen %d enckeylen %d authkeylen %d\n",
16175 + keys.authkeylen + keys.enckeylen, keys.enckeylen,
16176 + keys.authkeylen);
16177 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
16178 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
16181 + ctx->adata.keylen = keys.authkeylen;
16182 + ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
16183 + OP_ALG_ALGSEL_MASK);
16185 + if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE)
16188 + memcpy(ctx->key, keys.authkey, keys.authkeylen);
16189 + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
16190 + dma_sync_single_for_device(dev, ctx->key_dma, ctx->adata.keylen_pad +
16191 + keys.enckeylen, DMA_BIDIRECTIONAL);
16193 + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ",
16194 + DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
16195 + ctx->adata.keylen_pad + keys.enckeylen, 1);
16198 + ctx->cdata.keylen = keys.enckeylen;
16200 + return tls_set_sh_desc(tls);
16202 + crypto_aead_set_flags(tls, CRYPTO_TFM_RES_BAD_KEY_LEN);
16206 +static int tls_setauthsize(struct crypto_aead *tls, unsigned int authsize)
16208 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
16210 + ctx->authsize = authsize;
16211 + tls_set_sh_desc(tls);
16216 +static int gcm_set_sh_desc(struct crypto_aead *aead)
16218 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16219 + struct device *dev = ctx->dev;
16220 + unsigned int ivsize = crypto_aead_ivsize(aead);
16221 + struct caam_flc *flc;
16223 + int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN -
16224 + ctx->cdata.keylen;
16226 + if (!ctx->cdata.keylen || !ctx->authsize)
16230 + * AES GCM encrypt shared descriptor
16231 + * Job Descriptor and Shared Descriptor
16232 + * must fit into the 64-word Descriptor h/w Buffer
16234 + if (rem_bytes >= DESC_QI_GCM_ENC_LEN) {
16235 + ctx->cdata.key_inline = true;
16236 + ctx->cdata.key_virt = ctx->key;
16238 + ctx->cdata.key_inline = false;
16239 + ctx->cdata.key_dma = ctx->key_dma;
16242 + flc = &ctx->flc[ENCRYPT];
16243 + desc = flc->sh_desc;
16244 + cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ivsize, ctx->authsize, true);
16245 + flc->flc[1] = desc_len(desc); /* SDL */
16246 + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT],
16247 + sizeof(flc->flc) + desc_bytes(desc),
16248 + DMA_BIDIRECTIONAL);
16251 + * Job Descriptor and Shared Descriptors
16252 + * must all fit into the 64-word Descriptor h/w Buffer
16254 + if (rem_bytes >= DESC_QI_GCM_DEC_LEN) {
16255 + ctx->cdata.key_inline = true;
16256 + ctx->cdata.key_virt = ctx->key;
16258 + ctx->cdata.key_inline = false;
16259 + ctx->cdata.key_dma = ctx->key_dma;
16262 + flc = &ctx->flc[DECRYPT];
16263 + desc = flc->sh_desc;
16264 + cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ivsize, ctx->authsize, true);
16265 + flc->flc[1] = desc_len(desc); /* SDL */
16266 + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT],
16267 + sizeof(flc->flc) + desc_bytes(desc),
16268 + DMA_BIDIRECTIONAL);
16273 +static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
16275 + struct caam_ctx *ctx = crypto_aead_ctx(authenc);
16277 + ctx->authsize = authsize;
16278 + gcm_set_sh_desc(authenc);
16283 +static int gcm_setkey(struct crypto_aead *aead,
16284 + const u8 *key, unsigned int keylen)
16286 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16287 + struct device *dev = ctx->dev;
16290 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
16291 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
16294 + memcpy(ctx->key, key, keylen);
16295 + dma_sync_single_for_device(dev, ctx->key_dma, keylen,
16296 + DMA_BIDIRECTIONAL);
16297 + ctx->cdata.keylen = keylen;
16299 + return gcm_set_sh_desc(aead);
16302 +static int rfc4106_set_sh_desc(struct crypto_aead *aead)
16304 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16305 + struct device *dev = ctx->dev;
16306 + unsigned int ivsize = crypto_aead_ivsize(aead);
16307 + struct caam_flc *flc;
16309 + int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN -
16310 + ctx->cdata.keylen;
16312 + if (!ctx->cdata.keylen || !ctx->authsize)
16315 + ctx->cdata.key_virt = ctx->key;
16318 + * RFC4106 encrypt shared descriptor
16319 + * Job Descriptor and Shared Descriptor
16320 + * must fit into the 64-word Descriptor h/w Buffer
16322 + if (rem_bytes >= DESC_QI_RFC4106_ENC_LEN) {
16323 + ctx->cdata.key_inline = true;
16325 + ctx->cdata.key_inline = false;
16326 + ctx->cdata.key_dma = ctx->key_dma;
16329 + flc = &ctx->flc[ENCRYPT];
16330 + desc = flc->sh_desc;
16331 + cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
16333 + flc->flc[1] = desc_len(desc); /* SDL */
16334 + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT],
16335 + sizeof(flc->flc) + desc_bytes(desc),
16336 + DMA_BIDIRECTIONAL);
16339 + * Job Descriptor and Shared Descriptors
16340 + * must all fit into the 64-word Descriptor h/w Buffer
16342 + if (rem_bytes >= DESC_QI_RFC4106_DEC_LEN) {
16343 + ctx->cdata.key_inline = true;
16345 + ctx->cdata.key_inline = false;
16346 + ctx->cdata.key_dma = ctx->key_dma;
16349 + flc = &ctx->flc[DECRYPT];
16350 + desc = flc->sh_desc;
16351 + cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
16353 + flc->flc[1] = desc_len(desc); /* SDL */
16354 + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT],
16355 + sizeof(flc->flc) + desc_bytes(desc),
16356 + DMA_BIDIRECTIONAL);
16361 +static int rfc4106_setauthsize(struct crypto_aead *authenc,
16362 + unsigned int authsize)
16364 + struct caam_ctx *ctx = crypto_aead_ctx(authenc);
16366 + ctx->authsize = authsize;
16367 + rfc4106_set_sh_desc(authenc);
16372 +static int rfc4106_setkey(struct crypto_aead *aead,
16373 + const u8 *key, unsigned int keylen)
16375 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16376 + struct device *dev = ctx->dev;
16382 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
16383 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
16386 + memcpy(ctx->key, key, keylen);
16388 + * The last four bytes of the key material are used as the salt value
16389 + * in the nonce. Update the AES key length.
16391 + ctx->cdata.keylen = keylen - 4;
16392 + dma_sync_single_for_device(dev, ctx->key_dma, ctx->cdata.keylen,
16393 + DMA_BIDIRECTIONAL);
16395 + return rfc4106_set_sh_desc(aead);
16398 +static int rfc4543_set_sh_desc(struct crypto_aead *aead)
16400 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16401 + struct device *dev = ctx->dev;
16402 + unsigned int ivsize = crypto_aead_ivsize(aead);
16403 + struct caam_flc *flc;
16405 + int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN -
16406 + ctx->cdata.keylen;
16408 + if (!ctx->cdata.keylen || !ctx->authsize)
16411 + ctx->cdata.key_virt = ctx->key;
16414 + * RFC4543 encrypt shared descriptor
16415 + * Job Descriptor and Shared Descriptor
16416 + * must fit into the 64-word Descriptor h/w Buffer
16418 + if (rem_bytes >= DESC_QI_RFC4543_ENC_LEN) {
16419 + ctx->cdata.key_inline = true;
16421 + ctx->cdata.key_inline = false;
16422 + ctx->cdata.key_dma = ctx->key_dma;
16425 + flc = &ctx->flc[ENCRYPT];
16426 + desc = flc->sh_desc;
16427 + cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
16429 + flc->flc[1] = desc_len(desc); /* SDL */
16430 + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT],
16431 + sizeof(flc->flc) + desc_bytes(desc),
16432 + DMA_BIDIRECTIONAL);
16435 + * Job Descriptor and Shared Descriptors
16436 + * must all fit into the 64-word Descriptor h/w Buffer
16438 + if (rem_bytes >= DESC_QI_RFC4543_DEC_LEN) {
16439 + ctx->cdata.key_inline = true;
16441 + ctx->cdata.key_inline = false;
16442 + ctx->cdata.key_dma = ctx->key_dma;
16445 + flc = &ctx->flc[DECRYPT];
16446 + desc = flc->sh_desc;
16447 + cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
16449 + flc->flc[1] = desc_len(desc); /* SDL */
16450 + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT],
16451 + sizeof(flc->flc) + desc_bytes(desc),
16452 + DMA_BIDIRECTIONAL);
16457 +static int rfc4543_setauthsize(struct crypto_aead *authenc,
16458 + unsigned int authsize)
16460 + struct caam_ctx *ctx = crypto_aead_ctx(authenc);
16462 + ctx->authsize = authsize;
16463 + rfc4543_set_sh_desc(authenc);
16468 +static int rfc4543_setkey(struct crypto_aead *aead,
16469 + const u8 *key, unsigned int keylen)
16471 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16472 + struct device *dev = ctx->dev;
16478 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
16479 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
16482 + memcpy(ctx->key, key, keylen);
16484 + * The last four bytes of the key material are used as the salt value
16485 + * in the nonce. Update the AES key length.
16487 + ctx->cdata.keylen = keylen - 4;
16488 + dma_sync_single_for_device(dev, ctx->key_dma, ctx->cdata.keylen,
16489 + DMA_BIDIRECTIONAL);
16491 + return rfc4543_set_sh_desc(aead);
16494 +static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
16495 + const u8 *key, unsigned int keylen)
16497 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
16498 + struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher);
16499 + const char *alg_name = crypto_tfm_alg_name(tfm);
16500 + struct device *dev = ctx->dev;
16501 + struct caam_flc *flc;
16502 + unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
16504 + u32 ctx1_iv_off = 0;
16505 + const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
16506 + OP_ALG_AAI_CTR_MOD128);
16507 + const bool is_rfc3686 = (ctr_mode && strstr(alg_name, "rfc3686"));
16510 + print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ",
16511 + DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
16514 + * AES-CTR needs to load IV in CONTEXT1 reg
16515 + * at an offset of 128bits (16bytes)
16516 + * CONTEXT1[255:128] = IV
16519 + ctx1_iv_off = 16;
16522 + * RFC3686 specific:
16523 + * | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
16524 + * | *key = {KEY, NONCE}
16526 + if (is_rfc3686) {
16527 + ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
16528 + keylen -= CTR_RFC3686_NONCE_SIZE;
16531 + ctx->cdata.keylen = keylen;
16532 + ctx->cdata.key_virt = key;
16533 + ctx->cdata.key_inline = true;
16535 + /* ablkcipher_encrypt shared descriptor */
16536 + flc = &ctx->flc[ENCRYPT];
16537 + desc = flc->sh_desc;
16538 + cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize,
16539 + is_rfc3686, ctx1_iv_off);
16540 + flc->flc[1] = desc_len(desc); /* SDL */
16541 + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT],
16542 + sizeof(flc->flc) + desc_bytes(desc),
16543 + DMA_BIDIRECTIONAL);
16545 + /* ablkcipher_decrypt shared descriptor */
16546 + flc = &ctx->flc[DECRYPT];
16547 + desc = flc->sh_desc;
16548 + cnstr_shdsc_ablkcipher_decap(desc, &ctx->cdata, ivsize,
16549 + is_rfc3686, ctx1_iv_off);
16550 + flc->flc[1] = desc_len(desc); /* SDL */
16551 + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT],
16552 + sizeof(flc->flc) + desc_bytes(desc),
16553 + DMA_BIDIRECTIONAL);
16555 + /* ablkcipher_givencrypt shared descriptor */
16556 + flc = &ctx->flc[GIVENCRYPT];
16557 + desc = flc->sh_desc;
16558 + cnstr_shdsc_ablkcipher_givencap(desc, &ctx->cdata,
16559 + ivsize, is_rfc3686, ctx1_iv_off);
16560 + flc->flc[1] = desc_len(desc); /* SDL */
16561 + dma_sync_single_for_device(dev, ctx->flc_dma[GIVENCRYPT],
16562 + sizeof(flc->flc) + desc_bytes(desc),
16563 + DMA_BIDIRECTIONAL);
16568 +static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
16569 + const u8 *key, unsigned int keylen)
16571 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
16572 + struct device *dev = ctx->dev;
16573 + struct caam_flc *flc;
16576 + if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
16577 + dev_err(dev, "key size mismatch\n");
16578 + crypto_ablkcipher_set_flags(ablkcipher,
16579 + CRYPTO_TFM_RES_BAD_KEY_LEN);
16583 + ctx->cdata.keylen = keylen;
16584 + ctx->cdata.key_virt = key;
16585 + ctx->cdata.key_inline = true;
16587 + /* xts_ablkcipher_encrypt shared descriptor */
16588 + flc = &ctx->flc[ENCRYPT];
16589 + desc = flc->sh_desc;
16590 + cnstr_shdsc_xts_ablkcipher_encap(desc, &ctx->cdata);
16591 + flc->flc[1] = desc_len(desc); /* SDL */
16592 + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT],
16593 + sizeof(flc->flc) + desc_bytes(desc),
16594 + DMA_BIDIRECTIONAL);
16596 + /* xts_ablkcipher_decrypt shared descriptor */
16597 + flc = &ctx->flc[DECRYPT];
16598 + desc = flc->sh_desc;
16599 + cnstr_shdsc_xts_ablkcipher_decap(desc, &ctx->cdata);
16600 + flc->flc[1] = desc_len(desc); /* SDL */
16601 + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT],
16602 + sizeof(flc->flc) + desc_bytes(desc),
16603 + DMA_BIDIRECTIONAL);
16608 +static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
16609 + *req, bool encrypt)
16611 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
16612 + struct caam_request *req_ctx = ablkcipher_request_ctx(req);
16613 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
16614 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
16615 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
16616 + struct device *dev = ctx->dev;
16617 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
16618 + GFP_KERNEL : GFP_ATOMIC;
16619 + int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
16620 + struct ablkcipher_edesc *edesc;
16621 + dma_addr_t iv_dma;
16623 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
16624 + int dst_sg_idx, qm_sg_ents;
16625 + struct dpaa2_sg_entry *sg_table;
16626 + enum optype op_type = encrypt ? ENCRYPT : DECRYPT;
16628 + src_nents = sg_nents_for_len(req->src, req->nbytes);
16629 + if (unlikely(src_nents < 0)) {
16630 + dev_err(dev, "Insufficient bytes (%d) in src S/G\n",
16632 + return ERR_PTR(src_nents);
16635 + if (unlikely(req->dst != req->src)) {
16636 + dst_nents = sg_nents_for_len(req->dst, req->nbytes);
16637 + if (unlikely(dst_nents < 0)) {
16638 + dev_err(dev, "Insufficient bytes (%d) in dst S/G\n",
16640 + return ERR_PTR(dst_nents);
16643 + mapped_src_nents = dma_map_sg(dev, req->src, src_nents,
16645 + if (unlikely(!mapped_src_nents)) {
16646 + dev_err(dev, "unable to map source\n");
16647 + return ERR_PTR(-ENOMEM);
16650 + mapped_dst_nents = dma_map_sg(dev, req->dst, dst_nents,
16651 + DMA_FROM_DEVICE);
16652 + if (unlikely(!mapped_dst_nents)) {
16653 + dev_err(dev, "unable to map destination\n");
16654 + dma_unmap_sg(dev, req->src, src_nents, DMA_TO_DEVICE);
16655 + return ERR_PTR(-ENOMEM);
16658 + mapped_src_nents = dma_map_sg(dev, req->src, src_nents,
16659 + DMA_BIDIRECTIONAL);
16660 + if (unlikely(!mapped_src_nents)) {
16661 + dev_err(dev, "unable to map source\n");
16662 + return ERR_PTR(-ENOMEM);
16666 + iv_dma = dma_map_single(dev, req->info, ivsize, DMA_TO_DEVICE);
16667 + if (dma_mapping_error(dev, iv_dma)) {
16668 + dev_err(dev, "unable to map IV\n");
16669 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents, 0,
16671 + return ERR_PTR(-ENOMEM);
16674 + if (mapped_src_nents == 1 &&
16675 + iv_dma + ivsize == sg_dma_address(req->src)) {
16676 + in_contig = true;
16679 + in_contig = false;
16680 + qm_sg_ents = 1 + mapped_src_nents;
16682 + dst_sg_idx = qm_sg_ents;
16684 + qm_sg_ents += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
16685 + if (unlikely(qm_sg_ents > CAAM_QI_MAX_ABLKCIPHER_SG)) {
16686 + dev_err(dev, "Insufficient S/G entries: %d > %lu\n",
16687 + qm_sg_ents, CAAM_QI_MAX_ABLKCIPHER_SG);
16688 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
16689 + iv_dma, ivsize, op_type, 0, 0);
16690 + return ERR_PTR(-ENOMEM);
16693 + /* allocate space for base edesc and link tables */
16694 + edesc = qi_cache_zalloc(GFP_DMA | flags);
16695 + if (unlikely(!edesc)) {
16696 + dev_err(dev, "could not allocate extended descriptor\n");
16697 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
16698 + iv_dma, ivsize, op_type, 0, 0);
16699 + return ERR_PTR(-ENOMEM);
16702 + edesc->src_nents = src_nents;
16703 + edesc->dst_nents = dst_nents;
16704 + edesc->iv_dma = iv_dma;
16705 + sg_table = &edesc->sgt[0];
16706 + edesc->qm_sg_bytes = qm_sg_ents * sizeof(*sg_table);
16708 + if (!in_contig) {
16709 + dma_to_qm_sg_one(sg_table, iv_dma, ivsize, 0);
16710 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table + 1, 0);
16713 + if (mapped_dst_nents > 1)
16714 + sg_to_qm_sg_last(req->dst, mapped_dst_nents, sg_table +
16717 + edesc->qm_sg_dma = dma_map_single(dev, sg_table, edesc->qm_sg_bytes,
16719 + if (dma_mapping_error(dev, edesc->qm_sg_dma)) {
16720 + dev_err(dev, "unable to map S/G table\n");
16721 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
16722 + iv_dma, ivsize, op_type, 0, 0);
16723 + qi_cache_free(edesc);
16724 + return ERR_PTR(-ENOMEM);
16727 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
16728 + dpaa2_fl_set_final(in_fle, true);
16729 + dpaa2_fl_set_len(in_fle, req->nbytes + ivsize);
16730 + dpaa2_fl_set_len(out_fle, req->nbytes);
16732 + if (!in_contig) {
16733 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
16734 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
16736 + dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
16737 + dpaa2_fl_set_addr(in_fle, iv_dma);
16740 + if (req->src == req->dst) {
16741 + if (!in_contig) {
16742 + dpaa2_fl_set_format(out_fle, dpaa2_fl_sg);
16743 + dpaa2_fl_set_addr(out_fle, edesc->qm_sg_dma +
16744 + sizeof(*sg_table));
16746 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
16747 + dpaa2_fl_set_addr(out_fle, sg_dma_address(req->src));
16749 + } else if (mapped_dst_nents > 1) {
16750 + dpaa2_fl_set_format(out_fle, dpaa2_fl_sg);
16751 + dpaa2_fl_set_addr(out_fle, edesc->qm_sg_dma + dst_sg_idx *
16752 + sizeof(*sg_table));
16754 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
16755 + dpaa2_fl_set_addr(out_fle, sg_dma_address(req->dst));
16761 +static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
16762 + struct skcipher_givcrypt_request *greq)
16764 + struct ablkcipher_request *req = &greq->creq;
16765 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
16766 + struct caam_request *req_ctx = ablkcipher_request_ctx(req);
16767 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
16768 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
16769 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
16770 + struct device *dev = ctx->dev;
16771 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
16772 + GFP_KERNEL : GFP_ATOMIC;
16773 + int src_nents, mapped_src_nents, dst_nents, mapped_dst_nents;
16774 + struct ablkcipher_edesc *edesc;
16775 + dma_addr_t iv_dma;
16777 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
16778 + struct dpaa2_sg_entry *sg_table;
16779 + int dst_sg_idx, qm_sg_ents;
16781 + src_nents = sg_nents_for_len(req->src, req->nbytes);
16782 + if (unlikely(src_nents < 0)) {
16783 + dev_err(dev, "Insufficient bytes (%d) in src S/G\n",
16785 + return ERR_PTR(src_nents);
16788 + if (unlikely(req->dst != req->src)) {
16789 + dst_nents = sg_nents_for_len(req->dst, req->nbytes);
16790 + if (unlikely(dst_nents < 0)) {
16791 + dev_err(dev, "Insufficient bytes (%d) in dst S/G\n",
16793 + return ERR_PTR(dst_nents);
16796 + mapped_src_nents = dma_map_sg(dev, req->src, src_nents,
16798 + if (unlikely(!mapped_src_nents)) {
16799 + dev_err(dev, "unable to map source\n");
16800 + return ERR_PTR(-ENOMEM);
16803 + mapped_dst_nents = dma_map_sg(dev, req->dst, dst_nents,
16804 + DMA_FROM_DEVICE);
16805 + if (unlikely(!mapped_dst_nents)) {
16806 + dev_err(dev, "unable to map destination\n");
16807 + dma_unmap_sg(dev, req->src, src_nents, DMA_TO_DEVICE);
16808 + return ERR_PTR(-ENOMEM);
16811 + mapped_src_nents = dma_map_sg(dev, req->src, src_nents,
16812 + DMA_BIDIRECTIONAL);
16813 + if (unlikely(!mapped_src_nents)) {
16814 + dev_err(dev, "unable to map source\n");
16815 + return ERR_PTR(-ENOMEM);
16818 + dst_nents = src_nents;
16819 + mapped_dst_nents = src_nents;
16822 + iv_dma = dma_map_single(dev, greq->giv, ivsize, DMA_FROM_DEVICE);
16823 + if (dma_mapping_error(dev, iv_dma)) {
16824 + dev_err(dev, "unable to map IV\n");
16825 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents, 0,
16827 + return ERR_PTR(-ENOMEM);
16830 + qm_sg_ents = mapped_src_nents > 1 ? mapped_src_nents : 0;
16831 + dst_sg_idx = qm_sg_ents;
16832 + if (mapped_dst_nents == 1 &&
16833 + iv_dma + ivsize == sg_dma_address(req->dst)) {
16834 + out_contig = true;
16836 + out_contig = false;
16837 + qm_sg_ents += 1 + mapped_dst_nents;
16840 + if (unlikely(qm_sg_ents > CAAM_QI_MAX_ABLKCIPHER_SG)) {
16841 + dev_err(dev, "Insufficient S/G entries: %d > %lu\n",
16842 + qm_sg_ents, CAAM_QI_MAX_ABLKCIPHER_SG);
16843 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
16844 + iv_dma, ivsize, GIVENCRYPT, 0, 0);
16845 + return ERR_PTR(-ENOMEM);
16848 + /* allocate space for base edesc and link tables */
16849 + edesc = qi_cache_zalloc(GFP_DMA | flags);
16851 + dev_err(dev, "could not allocate extended descriptor\n");
16852 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
16853 + iv_dma, ivsize, GIVENCRYPT, 0, 0);
16854 + return ERR_PTR(-ENOMEM);
16857 + edesc->src_nents = src_nents;
16858 + edesc->dst_nents = dst_nents;
16859 + edesc->iv_dma = iv_dma;
16860 + sg_table = &edesc->sgt[0];
16861 + edesc->qm_sg_bytes = qm_sg_ents * sizeof(*sg_table);
16863 + if (mapped_src_nents > 1)
16864 + sg_to_qm_sg_last(req->src, mapped_src_nents, sg_table, 0);
16866 + if (!out_contig) {
16867 + dma_to_qm_sg_one(sg_table + dst_sg_idx, iv_dma, ivsize, 0);
16868 + sg_to_qm_sg_last(req->dst, mapped_dst_nents, sg_table +
16869 + dst_sg_idx + 1, 0);
16872 + edesc->qm_sg_dma = dma_map_single(dev, sg_table, edesc->qm_sg_bytes,
16874 + if (dma_mapping_error(dev, edesc->qm_sg_dma)) {
16875 + dev_err(dev, "unable to map S/G table\n");
16876 + caam_unmap(dev, req->src, req->dst, src_nents, dst_nents,
16877 + iv_dma, ivsize, GIVENCRYPT, 0, 0);
16878 + qi_cache_free(edesc);
16879 + return ERR_PTR(-ENOMEM);
16882 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
16883 + dpaa2_fl_set_final(in_fle, true);
16884 + dpaa2_fl_set_len(in_fle, req->nbytes);
16885 + dpaa2_fl_set_len(out_fle, ivsize + req->nbytes);
16887 + if (mapped_src_nents > 1) {
16888 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
16889 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
16891 + dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
16892 + dpaa2_fl_set_addr(in_fle, sg_dma_address(req->src));
16895 + if (!out_contig) {
16896 + dpaa2_fl_set_format(out_fle, dpaa2_fl_sg);
16897 + dpaa2_fl_set_addr(out_fle, edesc->qm_sg_dma + dst_sg_idx *
16898 + sizeof(*sg_table));
16900 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
16901 + dpaa2_fl_set_addr(out_fle, sg_dma_address(req->dst));
16907 +static void aead_unmap(struct device *dev, struct aead_edesc *edesc,
16908 + struct aead_request *req)
16910 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
16911 + int ivsize = crypto_aead_ivsize(aead);
16912 + struct caam_request *caam_req = aead_request_ctx(req);
16914 + caam_unmap(dev, req->src, req->dst, edesc->src_nents, edesc->dst_nents,
16915 + edesc->iv_dma, ivsize, caam_req->op_type,
16916 + edesc->qm_sg_dma, edesc->qm_sg_bytes);
16917 + dma_unmap_single(dev, edesc->assoclen_dma, 4, DMA_TO_DEVICE);
16920 +static void tls_unmap(struct device *dev, struct tls_edesc *edesc,
16921 + struct aead_request *req)
16923 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
16924 + int ivsize = crypto_aead_ivsize(tls);
16925 + struct caam_request *caam_req = aead_request_ctx(req);
16927 + caam_unmap(dev, req->src, edesc->dst, edesc->src_nents,
16928 + edesc->dst_nents, edesc->iv_dma, ivsize, caam_req->op_type,
16929 + edesc->qm_sg_dma, edesc->qm_sg_bytes);
16932 +static void ablkcipher_unmap(struct device *dev,
16933 + struct ablkcipher_edesc *edesc,
16934 + struct ablkcipher_request *req)
16936 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
16937 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
16938 + struct caam_request *caam_req = ablkcipher_request_ctx(req);
16940 + caam_unmap(dev, req->src, req->dst, edesc->src_nents, edesc->dst_nents,
16941 + edesc->iv_dma, ivsize, caam_req->op_type,
16942 + edesc->qm_sg_dma, edesc->qm_sg_bytes);
16945 +static void aead_encrypt_done(void *cbk_ctx, u32 status)
16947 + struct crypto_async_request *areq = cbk_ctx;
16948 + struct aead_request *req = container_of(areq, struct aead_request,
16950 + struct caam_request *req_ctx = to_caam_req(areq);
16951 + struct aead_edesc *edesc = req_ctx->edesc;
16952 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
16953 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16957 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
16960 + if (unlikely(status)) {
16961 + caam_qi2_strstatus(ctx->dev, status);
16965 + aead_unmap(ctx->dev, edesc, req);
16966 + qi_cache_free(edesc);
16967 + aead_request_complete(req, ecode);
16970 +static void aead_decrypt_done(void *cbk_ctx, u32 status)
16972 + struct crypto_async_request *areq = cbk_ctx;
16973 + struct aead_request *req = container_of(areq, struct aead_request,
16975 + struct caam_request *req_ctx = to_caam_req(areq);
16976 + struct aead_edesc *edesc = req_ctx->edesc;
16977 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
16978 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
16982 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
16985 + if (unlikely(status)) {
16986 + caam_qi2_strstatus(ctx->dev, status);
16988 + * verify hw auth check passed else return -EBADMSG
16990 + if ((status & JRSTA_CCBERR_ERRID_MASK) ==
16991 + JRSTA_CCBERR_ERRID_ICVCHK)
16992 + ecode = -EBADMSG;
16997 + aead_unmap(ctx->dev, edesc, req);
16998 + qi_cache_free(edesc);
16999 + aead_request_complete(req, ecode);
17002 +static int aead_encrypt(struct aead_request *req)
17004 + struct aead_edesc *edesc;
17005 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
17006 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
17007 + struct caam_request *caam_req = aead_request_ctx(req);
17010 + /* allocate extended descriptor */
17011 + edesc = aead_edesc_alloc(req, true);
17012 + if (IS_ERR(edesc))
17013 + return PTR_ERR(edesc);
17015 + caam_req->flc = &ctx->flc[ENCRYPT];
17016 + caam_req->flc_dma = ctx->flc_dma[ENCRYPT];
17017 + caam_req->op_type = ENCRYPT;
17018 + caam_req->cbk = aead_encrypt_done;
17019 + caam_req->ctx = &req->base;
17020 + caam_req->edesc = edesc;
17021 + ret = dpaa2_caam_enqueue(ctx->dev, caam_req);
17022 + if (ret != -EINPROGRESS &&
17023 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
17024 + aead_unmap(ctx->dev, edesc, req);
17025 + qi_cache_free(edesc);
17031 +static int aead_decrypt(struct aead_request *req)
17033 + struct aead_edesc *edesc;
17034 + struct crypto_aead *aead = crypto_aead_reqtfm(req);
17035 + struct caam_ctx *ctx = crypto_aead_ctx(aead);
17036 + struct caam_request *caam_req = aead_request_ctx(req);
17039 + /* allocate extended descriptor */
17040 + edesc = aead_edesc_alloc(req, false);
17041 + if (IS_ERR(edesc))
17042 + return PTR_ERR(edesc);
17044 + caam_req->flc = &ctx->flc[DECRYPT];
17045 + caam_req->flc_dma = ctx->flc_dma[DECRYPT];
17046 + caam_req->op_type = DECRYPT;
17047 + caam_req->cbk = aead_decrypt_done;
17048 + caam_req->ctx = &req->base;
17049 + caam_req->edesc = edesc;
17050 + ret = dpaa2_caam_enqueue(ctx->dev, caam_req);
17051 + if (ret != -EINPROGRESS &&
17052 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
17053 + aead_unmap(ctx->dev, edesc, req);
17054 + qi_cache_free(edesc);
17060 +static void tls_encrypt_done(void *cbk_ctx, u32 status)
17062 + struct crypto_async_request *areq = cbk_ctx;
17063 + struct aead_request *req = container_of(areq, struct aead_request,
17065 + struct caam_request *req_ctx = to_caam_req(areq);
17066 + struct tls_edesc *edesc = req_ctx->edesc;
17067 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
17068 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
17072 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
17075 + if (unlikely(status)) {
17076 + caam_qi2_strstatus(ctx->dev, status);
17080 + tls_unmap(ctx->dev, edesc, req);
17081 + qi_cache_free(edesc);
17082 + aead_request_complete(req, ecode);
17085 +static void tls_decrypt_done(void *cbk_ctx, u32 status)
17087 + struct crypto_async_request *areq = cbk_ctx;
17088 + struct aead_request *req = container_of(areq, struct aead_request,
17090 + struct caam_request *req_ctx = to_caam_req(areq);
17091 + struct tls_edesc *edesc = req_ctx->edesc;
17092 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
17093 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
17097 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
17100 + if (unlikely(status)) {
17101 + caam_qi2_strstatus(ctx->dev, status);
17103 + * verify hw auth check passed else return -EBADMSG
17105 + if ((status & JRSTA_CCBERR_ERRID_MASK) ==
17106 + JRSTA_CCBERR_ERRID_ICVCHK)
17107 + ecode = -EBADMSG;
17112 + tls_unmap(ctx->dev, edesc, req);
17113 + qi_cache_free(edesc);
17114 + aead_request_complete(req, ecode);
17117 +static int tls_encrypt(struct aead_request *req)
17119 + struct tls_edesc *edesc;
17120 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
17121 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
17122 + struct caam_request *caam_req = aead_request_ctx(req);
17125 + /* allocate extended descriptor */
17126 + edesc = tls_edesc_alloc(req, true);
17127 + if (IS_ERR(edesc))
17128 + return PTR_ERR(edesc);
17130 + caam_req->flc = &ctx->flc[ENCRYPT];
17131 + caam_req->flc_dma = ctx->flc_dma[ENCRYPT];
17132 + caam_req->op_type = ENCRYPT;
17133 + caam_req->cbk = tls_encrypt_done;
17134 + caam_req->ctx = &req->base;
17135 + caam_req->edesc = edesc;
17136 + ret = dpaa2_caam_enqueue(ctx->dev, caam_req);
17137 + if (ret != -EINPROGRESS &&
17138 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
17139 + tls_unmap(ctx->dev, edesc, req);
17140 + qi_cache_free(edesc);
17146 +static int tls_decrypt(struct aead_request *req)
17148 + struct tls_edesc *edesc;
17149 + struct crypto_aead *tls = crypto_aead_reqtfm(req);
17150 + struct caam_ctx *ctx = crypto_aead_ctx(tls);
17151 + struct caam_request *caam_req = aead_request_ctx(req);
17154 + /* allocate extended descriptor */
17155 + edesc = tls_edesc_alloc(req, false);
17156 + if (IS_ERR(edesc))
17157 + return PTR_ERR(edesc);
17159 + caam_req->flc = &ctx->flc[DECRYPT];
17160 + caam_req->flc_dma = ctx->flc_dma[DECRYPT];
17161 + caam_req->op_type = DECRYPT;
17162 + caam_req->cbk = tls_decrypt_done;
17163 + caam_req->ctx = &req->base;
17164 + caam_req->edesc = edesc;
17165 + ret = dpaa2_caam_enqueue(ctx->dev, caam_req);
17166 + if (ret != -EINPROGRESS &&
17167 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
17168 + tls_unmap(ctx->dev, edesc, req);
17169 + qi_cache_free(edesc);
17175 +static int ipsec_gcm_encrypt(struct aead_request *req)
17177 + if (req->assoclen < 8)
17180 + return aead_encrypt(req);
17183 +static int ipsec_gcm_decrypt(struct aead_request *req)
17185 + if (req->assoclen < 8)
17188 + return aead_decrypt(req);
17191 +static void ablkcipher_done(void *cbk_ctx, u32 status)
17193 + struct crypto_async_request *areq = cbk_ctx;
17194 + struct ablkcipher_request *req = ablkcipher_request_cast(areq);
17195 + struct caam_request *req_ctx = to_caam_req(areq);
17196 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
17197 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
17198 + struct ablkcipher_edesc *edesc = req_ctx->edesc;
17200 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
17203 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
17206 + if (unlikely(status)) {
17207 + caam_qi2_strstatus(ctx->dev, status);
17212 + print_hex_dump(KERN_ERR, "dstiv @" __stringify(__LINE__)": ",
17213 + DUMP_PREFIX_ADDRESS, 16, 4, req->info,
17214 + edesc->src_nents > 1 ? 100 : ivsize, 1);
17215 + caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ",
17216 + DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
17217 + edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
17220 + ablkcipher_unmap(ctx->dev, edesc, req);
17221 + qi_cache_free(edesc);
17224 + * The crypto API expects us to set the IV (req->info) to the last
17225 + * ciphertext block. This is used e.g. by the CTS mode.
17227 + scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize,
17230 + ablkcipher_request_complete(req, ecode);
17233 +static int ablkcipher_encrypt(struct ablkcipher_request *req)
17235 + struct ablkcipher_edesc *edesc;
17236 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
17237 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
17238 + struct caam_request *caam_req = ablkcipher_request_ctx(req);
17241 + /* allocate extended descriptor */
17242 + edesc = ablkcipher_edesc_alloc(req, true);
17243 + if (IS_ERR(edesc))
17244 + return PTR_ERR(edesc);
17246 + caam_req->flc = &ctx->flc[ENCRYPT];
17247 + caam_req->flc_dma = ctx->flc_dma[ENCRYPT];
17248 + caam_req->op_type = ENCRYPT;
17249 + caam_req->cbk = ablkcipher_done;
17250 + caam_req->ctx = &req->base;
17251 + caam_req->edesc = edesc;
17252 + ret = dpaa2_caam_enqueue(ctx->dev, caam_req);
17253 + if (ret != -EINPROGRESS &&
17254 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
17255 + ablkcipher_unmap(ctx->dev, edesc, req);
17256 + qi_cache_free(edesc);
17262 +static int ablkcipher_givencrypt(struct skcipher_givcrypt_request *greq)
17264 + struct ablkcipher_request *req = &greq->creq;
17265 + struct ablkcipher_edesc *edesc;
17266 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
17267 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
17268 + struct caam_request *caam_req = ablkcipher_request_ctx(req);
17271 + /* allocate extended descriptor */
17272 + edesc = ablkcipher_giv_edesc_alloc(greq);
17273 + if (IS_ERR(edesc))
17274 + return PTR_ERR(edesc);
17276 + caam_req->flc = &ctx->flc[GIVENCRYPT];
17277 + caam_req->flc_dma = ctx->flc_dma[GIVENCRYPT];
17278 + caam_req->op_type = GIVENCRYPT;
17279 + caam_req->cbk = ablkcipher_done;
17280 + caam_req->ctx = &req->base;
17281 + caam_req->edesc = edesc;
17282 + ret = dpaa2_caam_enqueue(ctx->dev, caam_req);
17283 + if (ret != -EINPROGRESS &&
17284 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
17285 + ablkcipher_unmap(ctx->dev, edesc, req);
17286 + qi_cache_free(edesc);
17292 +static int ablkcipher_decrypt(struct ablkcipher_request *req)
17294 + struct ablkcipher_edesc *edesc;
17295 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
17296 + struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
17297 + struct caam_request *caam_req = ablkcipher_request_ctx(req);
17300 + /* allocate extended descriptor */
17301 + edesc = ablkcipher_edesc_alloc(req, false);
17302 + if (IS_ERR(edesc))
17303 + return PTR_ERR(edesc);
17305 + caam_req->flc = &ctx->flc[DECRYPT];
17306 + caam_req->flc_dma = ctx->flc_dma[DECRYPT];
17307 + caam_req->op_type = DECRYPT;
17308 + caam_req->cbk = ablkcipher_done;
17309 + caam_req->ctx = &req->base;
17310 + caam_req->edesc = edesc;
17311 + ret = dpaa2_caam_enqueue(ctx->dev, caam_req);
17312 + if (ret != -EINPROGRESS &&
17313 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
17314 + ablkcipher_unmap(ctx->dev, edesc, req);
17315 + qi_cache_free(edesc);
17321 +struct caam_crypto_alg {
17322 + struct list_head entry;
17323 + struct crypto_alg crypto_alg;
17324 + struct caam_alg_entry caam;
17327 +static int caam_cra_init(struct crypto_tfm *tfm)
17329 + struct crypto_alg *alg = tfm->__crt_alg;
17330 + struct caam_crypto_alg *caam_alg = container_of(alg, typeof(*caam_alg),
17332 + struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
17333 + dma_addr_t dma_addr;
17336 + /* copy descriptor header template value */
17337 + ctx->cdata.algtype = OP_TYPE_CLASS1_ALG |
17338 + caam_alg->caam.class1_alg_type;
17339 + ctx->adata.algtype = OP_TYPE_CLASS2_ALG |
17340 + caam_alg->caam.class2_alg_type;
17342 + ctx->dev = caam_alg->caam.dev;
17344 + dma_addr = dma_map_single_attrs(ctx->dev, ctx->flc,
17345 + offsetof(struct caam_ctx, flc_dma),
17346 + DMA_BIDIRECTIONAL,
17347 + DMA_ATTR_SKIP_CPU_SYNC);
17348 + if (dma_mapping_error(ctx->dev, dma_addr)) {
17349 + dev_err(ctx->dev, "unable to map key, shared descriptors\n");
17353 + for (i = 0; i < NUM_OP; i++)
17354 + ctx->flc_dma[i] = dma_addr + i * sizeof(ctx->flc[i]);
17355 + ctx->key_dma = dma_addr + NUM_OP * sizeof(ctx->flc[0]);
17360 +static int caam_cra_init_ablkcipher(struct crypto_tfm *tfm)
17362 + struct ablkcipher_tfm *ablkcipher_tfm =
17363 + crypto_ablkcipher_crt(__crypto_ablkcipher_cast(tfm));
17365 + ablkcipher_tfm->reqsize = sizeof(struct caam_request);
17366 + return caam_cra_init(tfm);
17369 +static int caam_cra_init_aead(struct crypto_aead *tfm)
17371 + crypto_aead_set_reqsize(tfm, sizeof(struct caam_request));
17372 + return caam_cra_init(crypto_aead_tfm(tfm));
17375 +static void caam_exit_common(struct caam_ctx *ctx)
17377 + dma_unmap_single_attrs(ctx->dev, ctx->flc_dma[0],
17378 + offsetof(struct caam_ctx, flc_dma),
17379 + DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
17382 +static void caam_cra_exit(struct crypto_tfm *tfm)
17384 + caam_exit_common(crypto_tfm_ctx(tfm));
17387 +static void caam_cra_exit_aead(struct crypto_aead *tfm)
17389 + caam_exit_common(crypto_aead_ctx(tfm));
17392 +#define template_ablkcipher template_u.ablkcipher
17393 +struct caam_alg_template {
17394 + char name[CRYPTO_MAX_ALG_NAME];
17395 + char driver_name[CRYPTO_MAX_ALG_NAME];
17396 + unsigned int blocksize;
17399 + struct ablkcipher_alg ablkcipher;
17401 + u32 class1_alg_type;
17402 + u32 class2_alg_type;
17405 +static struct caam_alg_template driver_algs[] = {
17406 + /* ablkcipher descriptor */
17408 + .name = "cbc(aes)",
17409 + .driver_name = "cbc-aes-caam-qi2",
17410 + .blocksize = AES_BLOCK_SIZE,
17411 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
17412 + .template_ablkcipher = {
17413 + .setkey = ablkcipher_setkey,
17414 + .encrypt = ablkcipher_encrypt,
17415 + .decrypt = ablkcipher_decrypt,
17416 + .givencrypt = ablkcipher_givencrypt,
17417 + .geniv = "<built-in>",
17418 + .min_keysize = AES_MIN_KEY_SIZE,
17419 + .max_keysize = AES_MAX_KEY_SIZE,
17420 + .ivsize = AES_BLOCK_SIZE,
17422 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17425 + .name = "cbc(des3_ede)",
17426 + .driver_name = "cbc-3des-caam-qi2",
17427 + .blocksize = DES3_EDE_BLOCK_SIZE,
17428 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
17429 + .template_ablkcipher = {
17430 + .setkey = ablkcipher_setkey,
17431 + .encrypt = ablkcipher_encrypt,
17432 + .decrypt = ablkcipher_decrypt,
17433 + .givencrypt = ablkcipher_givencrypt,
17434 + .geniv = "<built-in>",
17435 + .min_keysize = DES3_EDE_KEY_SIZE,
17436 + .max_keysize = DES3_EDE_KEY_SIZE,
17437 + .ivsize = DES3_EDE_BLOCK_SIZE,
17439 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17442 + .name = "cbc(des)",
17443 + .driver_name = "cbc-des-caam-qi2",
17444 + .blocksize = DES_BLOCK_SIZE,
17445 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
17446 + .template_ablkcipher = {
17447 + .setkey = ablkcipher_setkey,
17448 + .encrypt = ablkcipher_encrypt,
17449 + .decrypt = ablkcipher_decrypt,
17450 + .givencrypt = ablkcipher_givencrypt,
17451 + .geniv = "<built-in>",
17452 + .min_keysize = DES_KEY_SIZE,
17453 + .max_keysize = DES_KEY_SIZE,
17454 + .ivsize = DES_BLOCK_SIZE,
17456 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
17459 + .name = "ctr(aes)",
17460 + .driver_name = "ctr-aes-caam-qi2",
17462 + .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
17463 + .template_ablkcipher = {
17464 + .setkey = ablkcipher_setkey,
17465 + .encrypt = ablkcipher_encrypt,
17466 + .decrypt = ablkcipher_decrypt,
17467 + .geniv = "chainiv",
17468 + .min_keysize = AES_MIN_KEY_SIZE,
17469 + .max_keysize = AES_MAX_KEY_SIZE,
17470 + .ivsize = AES_BLOCK_SIZE,
17472 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
17475 + .name = "rfc3686(ctr(aes))",
17476 + .driver_name = "rfc3686-ctr-aes-caam-qi2",
17478 + .type = CRYPTO_ALG_TYPE_GIVCIPHER,
17479 + .template_ablkcipher = {
17480 + .setkey = ablkcipher_setkey,
17481 + .encrypt = ablkcipher_encrypt,
17482 + .decrypt = ablkcipher_decrypt,
17483 + .givencrypt = ablkcipher_givencrypt,
17484 + .geniv = "<built-in>",
17485 + .min_keysize = AES_MIN_KEY_SIZE +
17486 + CTR_RFC3686_NONCE_SIZE,
17487 + .max_keysize = AES_MAX_KEY_SIZE +
17488 + CTR_RFC3686_NONCE_SIZE,
17489 + .ivsize = CTR_RFC3686_IV_SIZE,
17491 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
17494 + .name = "xts(aes)",
17495 + .driver_name = "xts-aes-caam-qi2",
17496 + .blocksize = AES_BLOCK_SIZE,
17497 + .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
17498 + .template_ablkcipher = {
17499 + .setkey = xts_ablkcipher_setkey,
17500 + .encrypt = ablkcipher_encrypt,
17501 + .decrypt = ablkcipher_decrypt,
17502 + .geniv = "eseqiv",
17503 + .min_keysize = 2 * AES_MIN_KEY_SIZE,
17504 + .max_keysize = 2 * AES_MAX_KEY_SIZE,
17505 + .ivsize = AES_BLOCK_SIZE,
17507 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
17511 +static struct caam_aead_alg driver_aeads[] = {
17515 + .cra_name = "rfc4106(gcm(aes))",
17516 + .cra_driver_name = "rfc4106-gcm-aes-caam-qi2",
17517 + .cra_blocksize = 1,
17519 + .setkey = rfc4106_setkey,
17520 + .setauthsize = rfc4106_setauthsize,
17521 + .encrypt = ipsec_gcm_encrypt,
17522 + .decrypt = ipsec_gcm_decrypt,
17524 + .maxauthsize = AES_BLOCK_SIZE,
17527 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
17533 + .cra_name = "rfc4543(gcm(aes))",
17534 + .cra_driver_name = "rfc4543-gcm-aes-caam-qi2",
17535 + .cra_blocksize = 1,
17537 + .setkey = rfc4543_setkey,
17538 + .setauthsize = rfc4543_setauthsize,
17539 + .encrypt = ipsec_gcm_encrypt,
17540 + .decrypt = ipsec_gcm_decrypt,
17542 + .maxauthsize = AES_BLOCK_SIZE,
17545 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
17548 + /* Galois Counter Mode */
17552 + .cra_name = "gcm(aes)",
17553 + .cra_driver_name = "gcm-aes-caam-qi2",
17554 + .cra_blocksize = 1,
17556 + .setkey = gcm_setkey,
17557 + .setauthsize = gcm_setauthsize,
17558 + .encrypt = aead_encrypt,
17559 + .decrypt = aead_decrypt,
17561 + .maxauthsize = AES_BLOCK_SIZE,
17564 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
17567 + /* single-pass ipsec_esp descriptor */
17571 + .cra_name = "authenc(hmac(md5),cbc(aes))",
17572 + .cra_driver_name = "authenc-hmac-md5-"
17573 + "cbc-aes-caam-qi2",
17574 + .cra_blocksize = AES_BLOCK_SIZE,
17576 + .setkey = aead_setkey,
17577 + .setauthsize = aead_setauthsize,
17578 + .encrypt = aead_encrypt,
17579 + .decrypt = aead_decrypt,
17580 + .ivsize = AES_BLOCK_SIZE,
17581 + .maxauthsize = MD5_DIGEST_SIZE,
17584 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17585 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
17586 + OP_ALG_AAI_HMAC_PRECOMP,
17592 + .cra_name = "echainiv(authenc(hmac(md5),"
17594 + .cra_driver_name = "echainiv-authenc-hmac-md5-"
17595 + "cbc-aes-caam-qi2",
17596 + .cra_blocksize = AES_BLOCK_SIZE,
17598 + .setkey = aead_setkey,
17599 + .setauthsize = aead_setauthsize,
17600 + .encrypt = aead_encrypt,
17601 + .decrypt = aead_decrypt,
17602 + .ivsize = AES_BLOCK_SIZE,
17603 + .maxauthsize = MD5_DIGEST_SIZE,
17606 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17607 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
17608 + OP_ALG_AAI_HMAC_PRECOMP,
17615 + .cra_name = "authenc(hmac(sha1),cbc(aes))",
17616 + .cra_driver_name = "authenc-hmac-sha1-"
17617 + "cbc-aes-caam-qi2",
17618 + .cra_blocksize = AES_BLOCK_SIZE,
17620 + .setkey = aead_setkey,
17621 + .setauthsize = aead_setauthsize,
17622 + .encrypt = aead_encrypt,
17623 + .decrypt = aead_decrypt,
17624 + .ivsize = AES_BLOCK_SIZE,
17625 + .maxauthsize = SHA1_DIGEST_SIZE,
17628 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17629 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
17630 + OP_ALG_AAI_HMAC_PRECOMP,
17636 + .cra_name = "echainiv(authenc(hmac(sha1),"
17638 + .cra_driver_name = "echainiv-authenc-"
17639 + "hmac-sha1-cbc-aes-caam-qi2",
17640 + .cra_blocksize = AES_BLOCK_SIZE,
17642 + .setkey = aead_setkey,
17643 + .setauthsize = aead_setauthsize,
17644 + .encrypt = aead_encrypt,
17645 + .decrypt = aead_decrypt,
17646 + .ivsize = AES_BLOCK_SIZE,
17647 + .maxauthsize = SHA1_DIGEST_SIZE,
17650 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17651 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
17652 + OP_ALG_AAI_HMAC_PRECOMP,
17659 + .cra_name = "authenc(hmac(sha224),cbc(aes))",
17660 + .cra_driver_name = "authenc-hmac-sha224-"
17661 + "cbc-aes-caam-qi2",
17662 + .cra_blocksize = AES_BLOCK_SIZE,
17664 + .setkey = aead_setkey,
17665 + .setauthsize = aead_setauthsize,
17666 + .encrypt = aead_encrypt,
17667 + .decrypt = aead_decrypt,
17668 + .ivsize = AES_BLOCK_SIZE,
17669 + .maxauthsize = SHA224_DIGEST_SIZE,
17672 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17673 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
17674 + OP_ALG_AAI_HMAC_PRECOMP,
17680 + .cra_name = "echainiv(authenc(hmac(sha224),"
17682 + .cra_driver_name = "echainiv-authenc-"
17683 + "hmac-sha224-cbc-aes-caam-qi2",
17684 + .cra_blocksize = AES_BLOCK_SIZE,
17686 + .setkey = aead_setkey,
17687 + .setauthsize = aead_setauthsize,
17688 + .encrypt = aead_encrypt,
17689 + .decrypt = aead_decrypt,
17690 + .ivsize = AES_BLOCK_SIZE,
17691 + .maxauthsize = SHA224_DIGEST_SIZE,
17694 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17695 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
17696 + OP_ALG_AAI_HMAC_PRECOMP,
17703 + .cra_name = "authenc(hmac(sha256),cbc(aes))",
17704 + .cra_driver_name = "authenc-hmac-sha256-"
17705 + "cbc-aes-caam-qi2",
17706 + .cra_blocksize = AES_BLOCK_SIZE,
17708 + .setkey = aead_setkey,
17709 + .setauthsize = aead_setauthsize,
17710 + .encrypt = aead_encrypt,
17711 + .decrypt = aead_decrypt,
17712 + .ivsize = AES_BLOCK_SIZE,
17713 + .maxauthsize = SHA256_DIGEST_SIZE,
17716 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17717 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
17718 + OP_ALG_AAI_HMAC_PRECOMP,
17724 + .cra_name = "echainiv(authenc(hmac(sha256),"
17726 + .cra_driver_name = "echainiv-authenc-"
17727 + "hmac-sha256-cbc-aes-"
17729 + .cra_blocksize = AES_BLOCK_SIZE,
17731 + .setkey = aead_setkey,
17732 + .setauthsize = aead_setauthsize,
17733 + .encrypt = aead_encrypt,
17734 + .decrypt = aead_decrypt,
17735 + .ivsize = AES_BLOCK_SIZE,
17736 + .maxauthsize = SHA256_DIGEST_SIZE,
17739 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17740 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
17741 + OP_ALG_AAI_HMAC_PRECOMP,
17748 + .cra_name = "authenc(hmac(sha384),cbc(aes))",
17749 + .cra_driver_name = "authenc-hmac-sha384-"
17750 + "cbc-aes-caam-qi2",
17751 + .cra_blocksize = AES_BLOCK_SIZE,
17753 + .setkey = aead_setkey,
17754 + .setauthsize = aead_setauthsize,
17755 + .encrypt = aead_encrypt,
17756 + .decrypt = aead_decrypt,
17757 + .ivsize = AES_BLOCK_SIZE,
17758 + .maxauthsize = SHA384_DIGEST_SIZE,
17761 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17762 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
17763 + OP_ALG_AAI_HMAC_PRECOMP,
17769 + .cra_name = "echainiv(authenc(hmac(sha384),"
17771 + .cra_driver_name = "echainiv-authenc-"
17772 + "hmac-sha384-cbc-aes-"
17774 + .cra_blocksize = AES_BLOCK_SIZE,
17776 + .setkey = aead_setkey,
17777 + .setauthsize = aead_setauthsize,
17778 + .encrypt = aead_encrypt,
17779 + .decrypt = aead_decrypt,
17780 + .ivsize = AES_BLOCK_SIZE,
17781 + .maxauthsize = SHA384_DIGEST_SIZE,
17784 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17785 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
17786 + OP_ALG_AAI_HMAC_PRECOMP,
17793 + .cra_name = "authenc(hmac(sha512),cbc(aes))",
17794 + .cra_driver_name = "authenc-hmac-sha512-"
17795 + "cbc-aes-caam-qi2",
17796 + .cra_blocksize = AES_BLOCK_SIZE,
17798 + .setkey = aead_setkey,
17799 + .setauthsize = aead_setauthsize,
17800 + .encrypt = aead_encrypt,
17801 + .decrypt = aead_decrypt,
17802 + .ivsize = AES_BLOCK_SIZE,
17803 + .maxauthsize = SHA512_DIGEST_SIZE,
17806 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17807 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
17808 + OP_ALG_AAI_HMAC_PRECOMP,
17814 + .cra_name = "echainiv(authenc(hmac(sha512),"
17816 + .cra_driver_name = "echainiv-authenc-"
17817 + "hmac-sha512-cbc-aes-"
17819 + .cra_blocksize = AES_BLOCK_SIZE,
17821 + .setkey = aead_setkey,
17822 + .setauthsize = aead_setauthsize,
17823 + .encrypt = aead_encrypt,
17824 + .decrypt = aead_decrypt,
17825 + .ivsize = AES_BLOCK_SIZE,
17826 + .maxauthsize = SHA512_DIGEST_SIZE,
17829 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
17830 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
17831 + OP_ALG_AAI_HMAC_PRECOMP,
17838 + .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
17839 + .cra_driver_name = "authenc-hmac-md5-"
17840 + "cbc-des3_ede-caam-qi2",
17841 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
17843 + .setkey = aead_setkey,
17844 + .setauthsize = aead_setauthsize,
17845 + .encrypt = aead_encrypt,
17846 + .decrypt = aead_decrypt,
17847 + .ivsize = DES3_EDE_BLOCK_SIZE,
17848 + .maxauthsize = MD5_DIGEST_SIZE,
17851 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17852 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
17853 + OP_ALG_AAI_HMAC_PRECOMP,
17859 + .cra_name = "echainiv(authenc(hmac(md5),"
17860 + "cbc(des3_ede)))",
17861 + .cra_driver_name = "echainiv-authenc-hmac-md5-"
17862 + "cbc-des3_ede-caam-qi2",
17863 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
17865 + .setkey = aead_setkey,
17866 + .setauthsize = aead_setauthsize,
17867 + .encrypt = aead_encrypt,
17868 + .decrypt = aead_decrypt,
17869 + .ivsize = DES3_EDE_BLOCK_SIZE,
17870 + .maxauthsize = MD5_DIGEST_SIZE,
17873 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17874 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
17875 + OP_ALG_AAI_HMAC_PRECOMP,
17882 + .cra_name = "authenc(hmac(sha1),"
17883 + "cbc(des3_ede))",
17884 + .cra_driver_name = "authenc-hmac-sha1-"
17885 + "cbc-des3_ede-caam-qi2",
17886 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
17888 + .setkey = aead_setkey,
17889 + .setauthsize = aead_setauthsize,
17890 + .encrypt = aead_encrypt,
17891 + .decrypt = aead_decrypt,
17892 + .ivsize = DES3_EDE_BLOCK_SIZE,
17893 + .maxauthsize = SHA1_DIGEST_SIZE,
17896 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17897 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
17898 + OP_ALG_AAI_HMAC_PRECOMP,
17904 + .cra_name = "echainiv(authenc(hmac(sha1),"
17905 + "cbc(des3_ede)))",
17906 + .cra_driver_name = "echainiv-authenc-"
17908 + "cbc-des3_ede-caam-qi2",
17909 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
17911 + .setkey = aead_setkey,
17912 + .setauthsize = aead_setauthsize,
17913 + .encrypt = aead_encrypt,
17914 + .decrypt = aead_decrypt,
17915 + .ivsize = DES3_EDE_BLOCK_SIZE,
17916 + .maxauthsize = SHA1_DIGEST_SIZE,
17919 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17920 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
17921 + OP_ALG_AAI_HMAC_PRECOMP,
17928 + .cra_name = "authenc(hmac(sha224),"
17929 + "cbc(des3_ede))",
17930 + .cra_driver_name = "authenc-hmac-sha224-"
17931 + "cbc-des3_ede-caam-qi2",
17932 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
17934 + .setkey = aead_setkey,
17935 + .setauthsize = aead_setauthsize,
17936 + .encrypt = aead_encrypt,
17937 + .decrypt = aead_decrypt,
17938 + .ivsize = DES3_EDE_BLOCK_SIZE,
17939 + .maxauthsize = SHA224_DIGEST_SIZE,
17942 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17943 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
17944 + OP_ALG_AAI_HMAC_PRECOMP,
17950 + .cra_name = "echainiv(authenc(hmac(sha224),"
17951 + "cbc(des3_ede)))",
17952 + .cra_driver_name = "echainiv-authenc-"
17954 + "cbc-des3_ede-caam-qi2",
17955 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
17957 + .setkey = aead_setkey,
17958 + .setauthsize = aead_setauthsize,
17959 + .encrypt = aead_encrypt,
17960 + .decrypt = aead_decrypt,
17961 + .ivsize = DES3_EDE_BLOCK_SIZE,
17962 + .maxauthsize = SHA224_DIGEST_SIZE,
17965 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17966 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
17967 + OP_ALG_AAI_HMAC_PRECOMP,
17974 + .cra_name = "authenc(hmac(sha256),"
17975 + "cbc(des3_ede))",
17976 + .cra_driver_name = "authenc-hmac-sha256-"
17977 + "cbc-des3_ede-caam-qi2",
17978 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
17980 + .setkey = aead_setkey,
17981 + .setauthsize = aead_setauthsize,
17982 + .encrypt = aead_encrypt,
17983 + .decrypt = aead_decrypt,
17984 + .ivsize = DES3_EDE_BLOCK_SIZE,
17985 + .maxauthsize = SHA256_DIGEST_SIZE,
17988 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
17989 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
17990 + OP_ALG_AAI_HMAC_PRECOMP,
17996 + .cra_name = "echainiv(authenc(hmac(sha256),"
17997 + "cbc(des3_ede)))",
17998 + .cra_driver_name = "echainiv-authenc-"
18000 + "cbc-des3_ede-caam-qi2",
18001 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
18003 + .setkey = aead_setkey,
18004 + .setauthsize = aead_setauthsize,
18005 + .encrypt = aead_encrypt,
18006 + .decrypt = aead_decrypt,
18007 + .ivsize = DES3_EDE_BLOCK_SIZE,
18008 + .maxauthsize = SHA256_DIGEST_SIZE,
18011 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
18012 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
18013 + OP_ALG_AAI_HMAC_PRECOMP,
18020 + .cra_name = "authenc(hmac(sha384),"
18021 + "cbc(des3_ede))",
18022 + .cra_driver_name = "authenc-hmac-sha384-"
18023 + "cbc-des3_ede-caam-qi2",
18024 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
18026 + .setkey = aead_setkey,
18027 + .setauthsize = aead_setauthsize,
18028 + .encrypt = aead_encrypt,
18029 + .decrypt = aead_decrypt,
18030 + .ivsize = DES3_EDE_BLOCK_SIZE,
18031 + .maxauthsize = SHA384_DIGEST_SIZE,
18034 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
18035 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
18036 + OP_ALG_AAI_HMAC_PRECOMP,
18042 + .cra_name = "echainiv(authenc(hmac(sha384),"
18043 + "cbc(des3_ede)))",
18044 + .cra_driver_name = "echainiv-authenc-"
18046 + "cbc-des3_ede-caam-qi2",
18047 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
18049 + .setkey = aead_setkey,
18050 + .setauthsize = aead_setauthsize,
18051 + .encrypt = aead_encrypt,
18052 + .decrypt = aead_decrypt,
18053 + .ivsize = DES3_EDE_BLOCK_SIZE,
18054 + .maxauthsize = SHA384_DIGEST_SIZE,
18057 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
18058 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
18059 + OP_ALG_AAI_HMAC_PRECOMP,
18066 + .cra_name = "authenc(hmac(sha512),"
18067 + "cbc(des3_ede))",
18068 + .cra_driver_name = "authenc-hmac-sha512-"
18069 + "cbc-des3_ede-caam-qi2",
18070 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
18072 + .setkey = aead_setkey,
18073 + .setauthsize = aead_setauthsize,
18074 + .encrypt = aead_encrypt,
18075 + .decrypt = aead_decrypt,
18076 + .ivsize = DES3_EDE_BLOCK_SIZE,
18077 + .maxauthsize = SHA512_DIGEST_SIZE,
18080 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
18081 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
18082 + OP_ALG_AAI_HMAC_PRECOMP,
18088 + .cra_name = "echainiv(authenc(hmac(sha512),"
18089 + "cbc(des3_ede)))",
18090 + .cra_driver_name = "echainiv-authenc-"
18092 + "cbc-des3_ede-caam-qi2",
18093 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
18095 + .setkey = aead_setkey,
18096 + .setauthsize = aead_setauthsize,
18097 + .encrypt = aead_encrypt,
18098 + .decrypt = aead_decrypt,
18099 + .ivsize = DES3_EDE_BLOCK_SIZE,
18100 + .maxauthsize = SHA512_DIGEST_SIZE,
18103 + .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
18104 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
18105 + OP_ALG_AAI_HMAC_PRECOMP,
18112 + .cra_name = "authenc(hmac(md5),cbc(des))",
18113 + .cra_driver_name = "authenc-hmac-md5-"
18114 + "cbc-des-caam-qi2",
18115 + .cra_blocksize = DES_BLOCK_SIZE,
18117 + .setkey = aead_setkey,
18118 + .setauthsize = aead_setauthsize,
18119 + .encrypt = aead_encrypt,
18120 + .decrypt = aead_decrypt,
18121 + .ivsize = DES_BLOCK_SIZE,
18122 + .maxauthsize = MD5_DIGEST_SIZE,
18125 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18126 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
18127 + OP_ALG_AAI_HMAC_PRECOMP,
18133 + .cra_name = "echainiv(authenc(hmac(md5),"
18135 + .cra_driver_name = "echainiv-authenc-hmac-md5-"
18136 + "cbc-des-caam-qi2",
18137 + .cra_blocksize = DES_BLOCK_SIZE,
18139 + .setkey = aead_setkey,
18140 + .setauthsize = aead_setauthsize,
18141 + .encrypt = aead_encrypt,
18142 + .decrypt = aead_decrypt,
18143 + .ivsize = DES_BLOCK_SIZE,
18144 + .maxauthsize = MD5_DIGEST_SIZE,
18147 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18148 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
18149 + OP_ALG_AAI_HMAC_PRECOMP,
18156 + .cra_name = "authenc(hmac(sha1),cbc(des))",
18157 + .cra_driver_name = "authenc-hmac-sha1-"
18158 + "cbc-des-caam-qi2",
18159 + .cra_blocksize = DES_BLOCK_SIZE,
18161 + .setkey = aead_setkey,
18162 + .setauthsize = aead_setauthsize,
18163 + .encrypt = aead_encrypt,
18164 + .decrypt = aead_decrypt,
18165 + .ivsize = DES_BLOCK_SIZE,
18166 + .maxauthsize = SHA1_DIGEST_SIZE,
18169 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18170 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
18171 + OP_ALG_AAI_HMAC_PRECOMP,
18177 + .cra_name = "echainiv(authenc(hmac(sha1),"
18179 + .cra_driver_name = "echainiv-authenc-"
18180 + "hmac-sha1-cbc-des-caam-qi2",
18181 + .cra_blocksize = DES_BLOCK_SIZE,
18183 + .setkey = aead_setkey,
18184 + .setauthsize = aead_setauthsize,
18185 + .encrypt = aead_encrypt,
18186 + .decrypt = aead_decrypt,
18187 + .ivsize = DES_BLOCK_SIZE,
18188 + .maxauthsize = SHA1_DIGEST_SIZE,
18191 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18192 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
18193 + OP_ALG_AAI_HMAC_PRECOMP,
18200 + .cra_name = "authenc(hmac(sha224),cbc(des))",
18201 + .cra_driver_name = "authenc-hmac-sha224-"
18202 + "cbc-des-caam-qi2",
18203 + .cra_blocksize = DES_BLOCK_SIZE,
18205 + .setkey = aead_setkey,
18206 + .setauthsize = aead_setauthsize,
18207 + .encrypt = aead_encrypt,
18208 + .decrypt = aead_decrypt,
18209 + .ivsize = DES_BLOCK_SIZE,
18210 + .maxauthsize = SHA224_DIGEST_SIZE,
18213 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18214 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
18215 + OP_ALG_AAI_HMAC_PRECOMP,
18221 + .cra_name = "echainiv(authenc(hmac(sha224),"
18223 + .cra_driver_name = "echainiv-authenc-"
18224 + "hmac-sha224-cbc-des-"
18226 + .cra_blocksize = DES_BLOCK_SIZE,
18228 + .setkey = aead_setkey,
18229 + .setauthsize = aead_setauthsize,
18230 + .encrypt = aead_encrypt,
18231 + .decrypt = aead_decrypt,
18232 + .ivsize = DES_BLOCK_SIZE,
18233 + .maxauthsize = SHA224_DIGEST_SIZE,
18236 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18237 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
18238 + OP_ALG_AAI_HMAC_PRECOMP,
18245 + .cra_name = "authenc(hmac(sha256),cbc(des))",
18246 + .cra_driver_name = "authenc-hmac-sha256-"
18247 + "cbc-des-caam-qi2",
18248 + .cra_blocksize = DES_BLOCK_SIZE,
18250 + .setkey = aead_setkey,
18251 + .setauthsize = aead_setauthsize,
18252 + .encrypt = aead_encrypt,
18253 + .decrypt = aead_decrypt,
18254 + .ivsize = DES_BLOCK_SIZE,
18255 + .maxauthsize = SHA256_DIGEST_SIZE,
18258 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18259 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
18260 + OP_ALG_AAI_HMAC_PRECOMP,
18266 + .cra_name = "echainiv(authenc(hmac(sha256),"
18268 + .cra_driver_name = "echainiv-authenc-"
18269 + "hmac-sha256-cbc-desi-"
18271 + .cra_blocksize = DES_BLOCK_SIZE,
18273 + .setkey = aead_setkey,
18274 + .setauthsize = aead_setauthsize,
18275 + .encrypt = aead_encrypt,
18276 + .decrypt = aead_decrypt,
18277 + .ivsize = DES_BLOCK_SIZE,
18278 + .maxauthsize = SHA256_DIGEST_SIZE,
18281 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18282 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
18283 + OP_ALG_AAI_HMAC_PRECOMP,
18290 + .cra_name = "authenc(hmac(sha384),cbc(des))",
18291 + .cra_driver_name = "authenc-hmac-sha384-"
18292 + "cbc-des-caam-qi2",
18293 + .cra_blocksize = DES_BLOCK_SIZE,
18295 + .setkey = aead_setkey,
18296 + .setauthsize = aead_setauthsize,
18297 + .encrypt = aead_encrypt,
18298 + .decrypt = aead_decrypt,
18299 + .ivsize = DES_BLOCK_SIZE,
18300 + .maxauthsize = SHA384_DIGEST_SIZE,
18303 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18304 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
18305 + OP_ALG_AAI_HMAC_PRECOMP,
18311 + .cra_name = "echainiv(authenc(hmac(sha384),"
18313 + .cra_driver_name = "echainiv-authenc-"
18314 + "hmac-sha384-cbc-des-"
18316 + .cra_blocksize = DES_BLOCK_SIZE,
18318 + .setkey = aead_setkey,
18319 + .setauthsize = aead_setauthsize,
18320 + .encrypt = aead_encrypt,
18321 + .decrypt = aead_decrypt,
18322 + .ivsize = DES_BLOCK_SIZE,
18323 + .maxauthsize = SHA384_DIGEST_SIZE,
18326 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18327 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
18328 + OP_ALG_AAI_HMAC_PRECOMP,
18335 + .cra_name = "authenc(hmac(sha512),cbc(des))",
18336 + .cra_driver_name = "authenc-hmac-sha512-"
18337 + "cbc-des-caam-qi2",
18338 + .cra_blocksize = DES_BLOCK_SIZE,
18340 + .setkey = aead_setkey,
18341 + .setauthsize = aead_setauthsize,
18342 + .encrypt = aead_encrypt,
18343 + .decrypt = aead_decrypt,
18344 + .ivsize = DES_BLOCK_SIZE,
18345 + .maxauthsize = SHA512_DIGEST_SIZE,
18348 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18349 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
18350 + OP_ALG_AAI_HMAC_PRECOMP,
18356 + .cra_name = "echainiv(authenc(hmac(sha512),"
18358 + .cra_driver_name = "echainiv-authenc-"
18359 + "hmac-sha512-cbc-des-"
18361 + .cra_blocksize = DES_BLOCK_SIZE,
18363 + .setkey = aead_setkey,
18364 + .setauthsize = aead_setauthsize,
18365 + .encrypt = aead_encrypt,
18366 + .decrypt = aead_decrypt,
18367 + .ivsize = DES_BLOCK_SIZE,
18368 + .maxauthsize = SHA512_DIGEST_SIZE,
18371 + .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
18372 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
18373 + OP_ALG_AAI_HMAC_PRECOMP,
18380 + .cra_name = "authenc(hmac(md5),"
18381 + "rfc3686(ctr(aes)))",
18382 + .cra_driver_name = "authenc-hmac-md5-"
18383 + "rfc3686-ctr-aes-caam-qi2",
18384 + .cra_blocksize = 1,
18386 + .setkey = aead_setkey,
18387 + .setauthsize = aead_setauthsize,
18388 + .encrypt = aead_encrypt,
18389 + .decrypt = aead_decrypt,
18390 + .ivsize = CTR_RFC3686_IV_SIZE,
18391 + .maxauthsize = MD5_DIGEST_SIZE,
18394 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18395 + OP_ALG_AAI_CTR_MOD128,
18396 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
18397 + OP_ALG_AAI_HMAC_PRECOMP,
18404 + .cra_name = "seqiv(authenc("
18405 + "hmac(md5),rfc3686(ctr(aes))))",
18406 + .cra_driver_name = "seqiv-authenc-hmac-md5-"
18407 + "rfc3686-ctr-aes-caam-qi2",
18408 + .cra_blocksize = 1,
18410 + .setkey = aead_setkey,
18411 + .setauthsize = aead_setauthsize,
18412 + .encrypt = aead_encrypt,
18413 + .decrypt = aead_decrypt,
18414 + .ivsize = CTR_RFC3686_IV_SIZE,
18415 + .maxauthsize = MD5_DIGEST_SIZE,
18418 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18419 + OP_ALG_AAI_CTR_MOD128,
18420 + .class2_alg_type = OP_ALG_ALGSEL_MD5 |
18421 + OP_ALG_AAI_HMAC_PRECOMP,
18429 + .cra_name = "authenc(hmac(sha1),"
18430 + "rfc3686(ctr(aes)))",
18431 + .cra_driver_name = "authenc-hmac-sha1-"
18432 + "rfc3686-ctr-aes-caam-qi2",
18433 + .cra_blocksize = 1,
18435 + .setkey = aead_setkey,
18436 + .setauthsize = aead_setauthsize,
18437 + .encrypt = aead_encrypt,
18438 + .decrypt = aead_decrypt,
18439 + .ivsize = CTR_RFC3686_IV_SIZE,
18440 + .maxauthsize = SHA1_DIGEST_SIZE,
18443 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18444 + OP_ALG_AAI_CTR_MOD128,
18445 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
18446 + OP_ALG_AAI_HMAC_PRECOMP,
18453 + .cra_name = "seqiv(authenc("
18454 + "hmac(sha1),rfc3686(ctr(aes))))",
18455 + .cra_driver_name = "seqiv-authenc-hmac-sha1-"
18456 + "rfc3686-ctr-aes-caam-qi2",
18457 + .cra_blocksize = 1,
18459 + .setkey = aead_setkey,
18460 + .setauthsize = aead_setauthsize,
18461 + .encrypt = aead_encrypt,
18462 + .decrypt = aead_decrypt,
18463 + .ivsize = CTR_RFC3686_IV_SIZE,
18464 + .maxauthsize = SHA1_DIGEST_SIZE,
18467 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18468 + OP_ALG_AAI_CTR_MOD128,
18469 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
18470 + OP_ALG_AAI_HMAC_PRECOMP,
18478 + .cra_name = "authenc(hmac(sha224),"
18479 + "rfc3686(ctr(aes)))",
18480 + .cra_driver_name = "authenc-hmac-sha224-"
18481 + "rfc3686-ctr-aes-caam-qi2",
18482 + .cra_blocksize = 1,
18484 + .setkey = aead_setkey,
18485 + .setauthsize = aead_setauthsize,
18486 + .encrypt = aead_encrypt,
18487 + .decrypt = aead_decrypt,
18488 + .ivsize = CTR_RFC3686_IV_SIZE,
18489 + .maxauthsize = SHA224_DIGEST_SIZE,
18492 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18493 + OP_ALG_AAI_CTR_MOD128,
18494 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
18495 + OP_ALG_AAI_HMAC_PRECOMP,
18502 + .cra_name = "seqiv(authenc("
18503 + "hmac(sha224),rfc3686(ctr(aes))))",
18504 + .cra_driver_name = "seqiv-authenc-hmac-sha224-"
18505 + "rfc3686-ctr-aes-caam-qi2",
18506 + .cra_blocksize = 1,
18508 + .setkey = aead_setkey,
18509 + .setauthsize = aead_setauthsize,
18510 + .encrypt = aead_encrypt,
18511 + .decrypt = aead_decrypt,
18512 + .ivsize = CTR_RFC3686_IV_SIZE,
18513 + .maxauthsize = SHA224_DIGEST_SIZE,
18516 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18517 + OP_ALG_AAI_CTR_MOD128,
18518 + .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
18519 + OP_ALG_AAI_HMAC_PRECOMP,
18527 + .cra_name = "authenc(hmac(sha256),"
18528 + "rfc3686(ctr(aes)))",
18529 + .cra_driver_name = "authenc-hmac-sha256-"
18530 + "rfc3686-ctr-aes-caam-qi2",
18531 + .cra_blocksize = 1,
18533 + .setkey = aead_setkey,
18534 + .setauthsize = aead_setauthsize,
18535 + .encrypt = aead_encrypt,
18536 + .decrypt = aead_decrypt,
18537 + .ivsize = CTR_RFC3686_IV_SIZE,
18538 + .maxauthsize = SHA256_DIGEST_SIZE,
18541 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18542 + OP_ALG_AAI_CTR_MOD128,
18543 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
18544 + OP_ALG_AAI_HMAC_PRECOMP,
18551 + .cra_name = "seqiv(authenc(hmac(sha256),"
18552 + "rfc3686(ctr(aes))))",
18553 + .cra_driver_name = "seqiv-authenc-hmac-sha256-"
18554 + "rfc3686-ctr-aes-caam-qi2",
18555 + .cra_blocksize = 1,
18557 + .setkey = aead_setkey,
18558 + .setauthsize = aead_setauthsize,
18559 + .encrypt = aead_encrypt,
18560 + .decrypt = aead_decrypt,
18561 + .ivsize = CTR_RFC3686_IV_SIZE,
18562 + .maxauthsize = SHA256_DIGEST_SIZE,
18565 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18566 + OP_ALG_AAI_CTR_MOD128,
18567 + .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
18568 + OP_ALG_AAI_HMAC_PRECOMP,
18576 + .cra_name = "authenc(hmac(sha384),"
18577 + "rfc3686(ctr(aes)))",
18578 + .cra_driver_name = "authenc-hmac-sha384-"
18579 + "rfc3686-ctr-aes-caam-qi2",
18580 + .cra_blocksize = 1,
18582 + .setkey = aead_setkey,
18583 + .setauthsize = aead_setauthsize,
18584 + .encrypt = aead_encrypt,
18585 + .decrypt = aead_decrypt,
18586 + .ivsize = CTR_RFC3686_IV_SIZE,
18587 + .maxauthsize = SHA384_DIGEST_SIZE,
18590 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18591 + OP_ALG_AAI_CTR_MOD128,
18592 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
18593 + OP_ALG_AAI_HMAC_PRECOMP,
18600 + .cra_name = "seqiv(authenc(hmac(sha384),"
18601 + "rfc3686(ctr(aes))))",
18602 + .cra_driver_name = "seqiv-authenc-hmac-sha384-"
18603 + "rfc3686-ctr-aes-caam-qi2",
18604 + .cra_blocksize = 1,
18606 + .setkey = aead_setkey,
18607 + .setauthsize = aead_setauthsize,
18608 + .encrypt = aead_encrypt,
18609 + .decrypt = aead_decrypt,
18610 + .ivsize = CTR_RFC3686_IV_SIZE,
18611 + .maxauthsize = SHA384_DIGEST_SIZE,
18614 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18615 + OP_ALG_AAI_CTR_MOD128,
18616 + .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
18617 + OP_ALG_AAI_HMAC_PRECOMP,
18625 + .cra_name = "authenc(hmac(sha512),"
18626 + "rfc3686(ctr(aes)))",
18627 + .cra_driver_name = "authenc-hmac-sha512-"
18628 + "rfc3686-ctr-aes-caam-qi2",
18629 + .cra_blocksize = 1,
18631 + .setkey = aead_setkey,
18632 + .setauthsize = aead_setauthsize,
18633 + .encrypt = aead_encrypt,
18634 + .decrypt = aead_decrypt,
18635 + .ivsize = CTR_RFC3686_IV_SIZE,
18636 + .maxauthsize = SHA512_DIGEST_SIZE,
18639 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18640 + OP_ALG_AAI_CTR_MOD128,
18641 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
18642 + OP_ALG_AAI_HMAC_PRECOMP,
18649 + .cra_name = "seqiv(authenc(hmac(sha512),"
18650 + "rfc3686(ctr(aes))))",
18651 + .cra_driver_name = "seqiv-authenc-hmac-sha512-"
18652 + "rfc3686-ctr-aes-caam-qi2",
18653 + .cra_blocksize = 1,
18655 + .setkey = aead_setkey,
18656 + .setauthsize = aead_setauthsize,
18657 + .encrypt = aead_encrypt,
18658 + .decrypt = aead_decrypt,
18659 + .ivsize = CTR_RFC3686_IV_SIZE,
18660 + .maxauthsize = SHA512_DIGEST_SIZE,
18663 + .class1_alg_type = OP_ALG_ALGSEL_AES |
18664 + OP_ALG_AAI_CTR_MOD128,
18665 + .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
18666 + OP_ALG_AAI_HMAC_PRECOMP,
18674 + .cra_name = "tls10(hmac(sha1),cbc(aes))",
18675 + .cra_driver_name = "tls10-hmac-sha1-cbc-aes-caam-qi2",
18676 + .cra_blocksize = AES_BLOCK_SIZE,
18678 + .setkey = tls_setkey,
18679 + .setauthsize = tls_setauthsize,
18680 + .encrypt = tls_encrypt,
18681 + .decrypt = tls_decrypt,
18682 + .ivsize = AES_BLOCK_SIZE,
18683 + .maxauthsize = SHA1_DIGEST_SIZE,
18686 + .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
18687 + .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
18688 + OP_ALG_AAI_HMAC_PRECOMP,
18693 +static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template
18696 + struct caam_crypto_alg *t_alg;
18697 + struct crypto_alg *alg;
18699 + t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
18701 + return ERR_PTR(-ENOMEM);
18703 + alg = &t_alg->crypto_alg;
18705 + snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
18706 + snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
18707 + template->driver_name);
18708 + alg->cra_module = THIS_MODULE;
18709 + alg->cra_exit = caam_cra_exit;
18710 + alg->cra_priority = CAAM_CRA_PRIORITY;
18711 + alg->cra_blocksize = template->blocksize;
18712 + alg->cra_alignmask = 0;
18713 + alg->cra_ctxsize = sizeof(struct caam_ctx);
18714 + alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
18716 + switch (template->type) {
18717 + case CRYPTO_ALG_TYPE_GIVCIPHER:
18718 + alg->cra_init = caam_cra_init_ablkcipher;
18719 + alg->cra_type = &crypto_givcipher_type;
18720 + alg->cra_ablkcipher = template->template_ablkcipher;
18722 + case CRYPTO_ALG_TYPE_ABLKCIPHER:
18723 + alg->cra_init = caam_cra_init_ablkcipher;
18724 + alg->cra_type = &crypto_ablkcipher_type;
18725 + alg->cra_ablkcipher = template->template_ablkcipher;
18729 + t_alg->caam.class1_alg_type = template->class1_alg_type;
18730 + t_alg->caam.class2_alg_type = template->class2_alg_type;
18735 +static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
18737 + struct aead_alg *alg = &t_alg->aead;
18739 + alg->base.cra_module = THIS_MODULE;
18740 + alg->base.cra_priority = CAAM_CRA_PRIORITY;
18741 + alg->base.cra_ctxsize = sizeof(struct caam_ctx);
18742 + alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
18744 + alg->init = caam_cra_init_aead;
18745 + alg->exit = caam_cra_exit_aead;
18748 +/* max hash key is max split key size */
18749 +#define CAAM_MAX_HASH_KEY_SIZE (SHA512_DIGEST_SIZE * 2)
18751 +#define CAAM_MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
18752 +#define CAAM_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
18754 +#define DESC_HASH_MAX_USED_BYTES (DESC_AHASH_FINAL_LEN + \
18755 + CAAM_MAX_HASH_KEY_SIZE)
18756 +#define DESC_HASH_MAX_USED_LEN (DESC_HASH_MAX_USED_BYTES / CAAM_CMD_SZ)
18758 +/* caam context sizes for hashes: running digest + 8 */
18759 +#define HASH_MSG_LEN 8
18760 +#define MAX_CTX_LEN (HASH_MSG_LEN + SHA512_DIGEST_SIZE)
18762 +enum hash_optype {
18771 + * caam_hash_ctx - ahash per-session context
18772 + * @flc: Flow Contexts array
18773 + * @flc_dma: I/O virtual addresses of the Flow Contexts
18774 + * @key: virtual address of the authentication key
18775 + * @dev: dpseci device
18776 + * @ctx_len: size of Context Register
18777 + * @adata: hashing algorithm details
18779 +struct caam_hash_ctx {
18780 + struct caam_flc flc[HASH_NUM_OP];
18781 + dma_addr_t flc_dma[HASH_NUM_OP];
18782 + u8 key[CAAM_MAX_HASH_KEY_SIZE];
18783 + struct device *dev;
18785 + struct alginfo adata;
18789 +struct caam_hash_state {
18790 + struct caam_request caam_req;
18791 + dma_addr_t buf_dma;
18792 + dma_addr_t ctx_dma;
18793 + u8 buf_0[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned;
18795 + u8 buf_1[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned;
18797 + u8 caam_ctx[MAX_CTX_LEN] ____cacheline_aligned;
18798 + int (*update)(struct ahash_request *req);
18799 + int (*final)(struct ahash_request *req);
18800 + int (*finup)(struct ahash_request *req);
18804 +struct caam_export_state {
18805 + u8 buf[CAAM_MAX_HASH_BLOCK_SIZE];
18806 + u8 caam_ctx[MAX_CTX_LEN];
18808 + int (*update)(struct ahash_request *req);
18809 + int (*final)(struct ahash_request *req);
18810 + int (*finup)(struct ahash_request *req);
18813 +static inline void switch_buf(struct caam_hash_state *state)
18815 + state->current_buf ^= 1;
18818 +static inline u8 *current_buf(struct caam_hash_state *state)
18820 + return state->current_buf ? state->buf_1 : state->buf_0;
18823 +static inline u8 *alt_buf(struct caam_hash_state *state)
18825 + return state->current_buf ? state->buf_0 : state->buf_1;
18828 +static inline int *current_buflen(struct caam_hash_state *state)
18830 + return state->current_buf ? &state->buflen_1 : &state->buflen_0;
18833 +static inline int *alt_buflen(struct caam_hash_state *state)
18835 + return state->current_buf ? &state->buflen_0 : &state->buflen_1;
18838 +/* Map current buffer in state (if length > 0) and put it in link table */
18839 +static inline int buf_map_to_qm_sg(struct device *dev,
18840 + struct dpaa2_sg_entry *qm_sg,
18841 + struct caam_hash_state *state)
18843 + int buflen = *current_buflen(state);
18848 + state->buf_dma = dma_map_single(dev, current_buf(state), buflen,
18850 + if (dma_mapping_error(dev, state->buf_dma)) {
18851 + dev_err(dev, "unable to map buf\n");
18852 + state->buf_dma = 0;
18856 + dma_to_qm_sg_one(qm_sg, state->buf_dma, buflen, 0);
18861 +/* Map state->caam_ctx, and add it to link table */
18862 +static inline int ctx_map_to_qm_sg(struct device *dev,
18863 + struct caam_hash_state *state, int ctx_len,
18864 + struct dpaa2_sg_entry *qm_sg, u32 flag)
18866 + state->ctx_dma = dma_map_single(dev, state->caam_ctx, ctx_len, flag);
18867 + if (dma_mapping_error(dev, state->ctx_dma)) {
18868 + dev_err(dev, "unable to map ctx\n");
18869 + state->ctx_dma = 0;
18873 + dma_to_qm_sg_one(qm_sg, state->ctx_dma, ctx_len, 0);
18878 +static int ahash_set_sh_desc(struct crypto_ahash *ahash)
18880 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
18881 + int digestsize = crypto_ahash_digestsize(ahash);
18882 + struct dpaa2_caam_priv *priv = dev_get_drvdata(ctx->dev);
18883 + struct caam_flc *flc;
18886 + ctx->adata.key_virt = ctx->key;
18887 + ctx->adata.key_inline = true;
18889 + /* ahash_update shared descriptor */
18890 + flc = &ctx->flc[UPDATE];
18891 + desc = flc->sh_desc;
18892 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_UPDATE, ctx->ctx_len,
18893 + ctx->ctx_len, true, priv->sec_attr.era);
18894 + flc->flc[1] = desc_len(desc); /* SDL */
18895 + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[UPDATE],
18896 + desc_bytes(desc), DMA_BIDIRECTIONAL);
18898 + print_hex_dump(KERN_ERR,
18899 + "ahash update shdesc@" __stringify(__LINE__)": ",
18900 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
18903 + /* ahash_update_first shared descriptor */
18904 + flc = &ctx->flc[UPDATE_FIRST];
18905 + desc = flc->sh_desc;
18906 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INIT, ctx->ctx_len,
18907 + ctx->ctx_len, false, priv->sec_attr.era);
18908 + flc->flc[1] = desc_len(desc); /* SDL */
18909 + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[UPDATE_FIRST],
18910 + desc_bytes(desc), DMA_BIDIRECTIONAL);
18912 + print_hex_dump(KERN_ERR,
18913 + "ahash update first shdesc@" __stringify(__LINE__)": ",
18914 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
18917 + /* ahash_final shared descriptor */
18918 + flc = &ctx->flc[FINALIZE];
18919 + desc = flc->sh_desc;
18920 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_FINALIZE, digestsize,
18921 + ctx->ctx_len, true, priv->sec_attr.era);
18922 + flc->flc[1] = desc_len(desc); /* SDL */
18923 + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[FINALIZE],
18924 + desc_bytes(desc), DMA_BIDIRECTIONAL);
18926 + print_hex_dump(KERN_ERR,
18927 + "ahash final shdesc@" __stringify(__LINE__)": ",
18928 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
18931 + /* ahash_digest shared descriptor */
18932 + flc = &ctx->flc[DIGEST];
18933 + desc = flc->sh_desc;
18934 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INITFINAL, digestsize,
18935 + ctx->ctx_len, false, priv->sec_attr.era);
18936 + flc->flc[1] = desc_len(desc); /* SDL */
18937 + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[DIGEST],
18938 + desc_bytes(desc), DMA_BIDIRECTIONAL);
18940 + print_hex_dump(KERN_ERR,
18941 + "ahash digest shdesc@" __stringify(__LINE__)": ",
18942 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
18948 +/* Digest hash size if it is too large */
18949 +static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,
18950 + u32 *keylen, u8 *key_out, u32 digestsize)
18952 + struct caam_request *req_ctx;
18954 + struct split_key_sh_result result;
18955 + dma_addr_t src_dma, dst_dma;
18956 + struct caam_flc *flc;
18957 + dma_addr_t flc_dma;
18958 + int ret = -ENOMEM;
18959 + struct dpaa2_fl_entry *in_fle, *out_fle;
18961 + req_ctx = kzalloc(sizeof(*req_ctx), GFP_KERNEL | GFP_DMA);
18965 + in_fle = &req_ctx->fd_flt[1];
18966 + out_fle = &req_ctx->fd_flt[0];
18968 + flc = kzalloc(sizeof(*flc), GFP_KERNEL | GFP_DMA);
18972 + src_dma = dma_map_single(ctx->dev, (void *)key_in, *keylen,
18974 + if (dma_mapping_error(ctx->dev, src_dma)) {
18975 + dev_err(ctx->dev, "unable to map key input memory\n");
18976 + goto err_src_dma;
18978 + dst_dma = dma_map_single(ctx->dev, (void *)key_out, digestsize,
18979 + DMA_FROM_DEVICE);
18980 + if (dma_mapping_error(ctx->dev, dst_dma)) {
18981 + dev_err(ctx->dev, "unable to map key output memory\n");
18982 + goto err_dst_dma;
18985 + desc = flc->sh_desc;
18987 + init_sh_desc(desc, 0);
18989 + /* descriptor to perform unkeyed hash on key_in */
18990 + append_operation(desc, ctx->adata.algtype | OP_ALG_ENCRYPT |
18991 + OP_ALG_AS_INITFINAL);
18992 + append_seq_fifo_load(desc, *keylen, FIFOLD_CLASS_CLASS2 |
18993 + FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_MSG);
18994 + append_seq_store(desc, digestsize, LDST_CLASS_2_CCB |
18995 + LDST_SRCDST_BYTE_CONTEXT);
18997 + flc->flc[1] = desc_len(desc); /* SDL */
18998 + flc_dma = dma_map_single(ctx->dev, flc, sizeof(flc->flc) +
18999 + desc_bytes(desc), DMA_TO_DEVICE);
19000 + if (dma_mapping_error(ctx->dev, flc_dma)) {
19001 + dev_err(ctx->dev, "unable to map shared descriptor\n");
19002 + goto err_flc_dma;
19005 + dpaa2_fl_set_final(in_fle, true);
19006 + dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
19007 + dpaa2_fl_set_addr(in_fle, src_dma);
19008 + dpaa2_fl_set_len(in_fle, *keylen);
19009 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19010 + dpaa2_fl_set_addr(out_fle, dst_dma);
19011 + dpaa2_fl_set_len(out_fle, digestsize);
19014 + print_hex_dump(KERN_ERR, "key_in@" __stringify(__LINE__)": ",
19015 + DUMP_PREFIX_ADDRESS, 16, 4, key_in, *keylen, 1);
19016 + print_hex_dump(KERN_ERR, "shdesc@" __stringify(__LINE__)": ",
19017 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
19021 + init_completion(&result.completion);
19022 + result.dev = ctx->dev;
19024 + req_ctx->flc = flc;
19025 + req_ctx->flc_dma = flc_dma;
19026 + req_ctx->cbk = split_key_sh_done;
19027 + req_ctx->ctx = &result;
19029 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19030 + if (ret == -EINPROGRESS) {
19031 + /* in progress */
19032 + wait_for_completion(&result.completion);
19033 + ret = result.err;
19035 + print_hex_dump(KERN_ERR,
19036 + "digested key@" __stringify(__LINE__)": ",
19037 + DUMP_PREFIX_ADDRESS, 16, 4, key_in, digestsize,
19042 + dma_unmap_single(ctx->dev, flc_dma, sizeof(flc->flc) + desc_bytes(desc),
19045 + dma_unmap_single(ctx->dev, dst_dma, digestsize, DMA_FROM_DEVICE);
19047 + dma_unmap_single(ctx->dev, src_dma, *keylen, DMA_TO_DEVICE);
19053 + *keylen = digestsize;
19058 +static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key,
19059 + unsigned int keylen)
19061 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19062 + unsigned int blocksize = crypto_tfm_alg_blocksize(&ahash->base);
19063 + unsigned int digestsize = crypto_ahash_digestsize(ahash);
19065 + u8 *hashed_key = NULL;
19068 + dev_err(ctx->dev, "keylen %d blocksize %d\n", keylen, blocksize);
19071 + if (keylen > blocksize) {
19072 + hashed_key = kmalloc_array(digestsize, sizeof(*hashed_key),
19073 + GFP_KERNEL | GFP_DMA);
19076 + ret = hash_digest_key(ctx, key, &keylen, hashed_key,
19079 + goto bad_free_key;
19080 + key = hashed_key;
19083 + ctx->adata.keylen = keylen;
19084 + ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
19085 + OP_ALG_ALGSEL_MASK);
19086 + if (ctx->adata.keylen_pad > CAAM_MAX_HASH_KEY_SIZE)
19087 + goto bad_free_key;
19089 + memcpy(ctx->key, key, keylen);
19091 + kfree(hashed_key);
19092 + return ahash_set_sh_desc(ahash);
19094 + kfree(hashed_key);
19095 + crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
19099 +static inline void ahash_unmap(struct device *dev, struct ahash_edesc *edesc,
19100 + struct ahash_request *req, int dst_len)
19102 + struct caam_hash_state *state = ahash_request_ctx(req);
19104 + if (edesc->src_nents)
19105 + dma_unmap_sg(dev, req->src, edesc->src_nents, DMA_TO_DEVICE);
19106 + if (edesc->dst_dma)
19107 + dma_unmap_single(dev, edesc->dst_dma, dst_len, DMA_FROM_DEVICE);
19109 + if (edesc->qm_sg_bytes)
19110 + dma_unmap_single(dev, edesc->qm_sg_dma, edesc->qm_sg_bytes,
19113 + if (state->buf_dma) {
19114 + dma_unmap_single(dev, state->buf_dma, *current_buflen(state),
19116 + state->buf_dma = 0;
19120 +static inline void ahash_unmap_ctx(struct device *dev,
19121 + struct ahash_edesc *edesc,
19122 + struct ahash_request *req, int dst_len,
19125 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19126 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19127 + struct caam_hash_state *state = ahash_request_ctx(req);
19129 + if (state->ctx_dma) {
19130 + dma_unmap_single(dev, state->ctx_dma, ctx->ctx_len, flag);
19131 + state->ctx_dma = 0;
19133 + ahash_unmap(dev, edesc, req, dst_len);
19136 +static void ahash_done(void *cbk_ctx, u32 status)
19138 + struct crypto_async_request *areq = cbk_ctx;
19139 + struct ahash_request *req = ahash_request_cast(areq);
19140 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19141 + struct caam_hash_state *state = ahash_request_ctx(req);
19142 + struct ahash_edesc *edesc = state->caam_req.edesc;
19143 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19144 + int digestsize = crypto_ahash_digestsize(ahash);
19148 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
19151 + if (unlikely(status)) {
19152 + caam_qi2_strstatus(ctx->dev, status);
19156 + ahash_unmap(ctx->dev, edesc, req, digestsize);
19157 + qi_cache_free(edesc);
19160 + print_hex_dump(KERN_ERR, "ctx@" __stringify(__LINE__)": ",
19161 + DUMP_PREFIX_ADDRESS, 16, 4, state->caam_ctx,
19162 + ctx->ctx_len, 1);
19164 + print_hex_dump(KERN_ERR, "result@" __stringify(__LINE__)": ",
19165 + DUMP_PREFIX_ADDRESS, 16, 4, req->result,
19169 + req->base.complete(&req->base, ecode);
19172 +static void ahash_done_bi(void *cbk_ctx, u32 status)
19174 + struct crypto_async_request *areq = cbk_ctx;
19175 + struct ahash_request *req = ahash_request_cast(areq);
19176 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19177 + struct caam_hash_state *state = ahash_request_ctx(req);
19178 + struct ahash_edesc *edesc = state->caam_req.edesc;
19179 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19182 + int digestsize = crypto_ahash_digestsize(ahash);
19184 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
19187 + if (unlikely(status)) {
19188 + caam_qi2_strstatus(ctx->dev, status);
19192 + ahash_unmap_ctx(ctx->dev, edesc, req, ctx->ctx_len, DMA_BIDIRECTIONAL);
19193 + switch_buf(state);
19194 + qi_cache_free(edesc);
19197 + print_hex_dump(KERN_ERR, "ctx@" __stringify(__LINE__)": ",
19198 + DUMP_PREFIX_ADDRESS, 16, 4, state->caam_ctx,
19199 + ctx->ctx_len, 1);
19201 + print_hex_dump(KERN_ERR, "result@" __stringify(__LINE__)": ",
19202 + DUMP_PREFIX_ADDRESS, 16, 4, req->result,
19206 + req->base.complete(&req->base, ecode);
19209 +static void ahash_done_ctx_src(void *cbk_ctx, u32 status)
19211 + struct crypto_async_request *areq = cbk_ctx;
19212 + struct ahash_request *req = ahash_request_cast(areq);
19213 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19214 + struct caam_hash_state *state = ahash_request_ctx(req);
19215 + struct ahash_edesc *edesc = state->caam_req.edesc;
19216 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19217 + int digestsize = crypto_ahash_digestsize(ahash);
19221 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
19224 + if (unlikely(status)) {
19225 + caam_qi2_strstatus(ctx->dev, status);
19229 + ahash_unmap_ctx(ctx->dev, edesc, req, digestsize, DMA_TO_DEVICE);
19230 + qi_cache_free(edesc);
19233 + print_hex_dump(KERN_ERR, "ctx@" __stringify(__LINE__)": ",
19234 + DUMP_PREFIX_ADDRESS, 16, 4, state->caam_ctx,
19235 + ctx->ctx_len, 1);
19237 + print_hex_dump(KERN_ERR, "result@" __stringify(__LINE__)": ",
19238 + DUMP_PREFIX_ADDRESS, 16, 4, req->result,
19242 + req->base.complete(&req->base, ecode);
19245 +static void ahash_done_ctx_dst(void *cbk_ctx, u32 status)
19247 + struct crypto_async_request *areq = cbk_ctx;
19248 + struct ahash_request *req = ahash_request_cast(areq);
19249 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19250 + struct caam_hash_state *state = ahash_request_ctx(req);
19251 + struct ahash_edesc *edesc = state->caam_req.edesc;
19252 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19255 + int digestsize = crypto_ahash_digestsize(ahash);
19257 + dev_err(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status);
19260 + if (unlikely(status)) {
19261 + caam_qi2_strstatus(ctx->dev, status);
19265 + ahash_unmap_ctx(ctx->dev, edesc, req, ctx->ctx_len, DMA_FROM_DEVICE);
19266 + switch_buf(state);
19267 + qi_cache_free(edesc);
19270 + print_hex_dump(KERN_ERR, "ctx@" __stringify(__LINE__)": ",
19271 + DUMP_PREFIX_ADDRESS, 16, 4, state->caam_ctx,
19272 + ctx->ctx_len, 1);
19274 + print_hex_dump(KERN_ERR, "result@" __stringify(__LINE__)": ",
19275 + DUMP_PREFIX_ADDRESS, 16, 4, req->result,
19279 + req->base.complete(&req->base, ecode);
19282 +static int ahash_update_ctx(struct ahash_request *req)
19284 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19285 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19286 + struct caam_hash_state *state = ahash_request_ctx(req);
19287 + struct caam_request *req_ctx = &state->caam_req;
19288 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19289 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19290 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19291 + GFP_KERNEL : GFP_ATOMIC;
19292 + u8 *buf = current_buf(state);
19293 + int *buflen = current_buflen(state);
19294 + u8 *next_buf = alt_buf(state);
19295 + int *next_buflen = alt_buflen(state), last_buflen;
19296 + int in_len = *buflen + req->nbytes, to_hash;
19297 + int src_nents, mapped_nents, qm_sg_bytes, qm_sg_src_index;
19298 + struct ahash_edesc *edesc;
19301 + last_buflen = *next_buflen;
19302 + *next_buflen = in_len & (crypto_tfm_alg_blocksize(&ahash->base) - 1);
19303 + to_hash = in_len - *next_buflen;
19306 + struct dpaa2_sg_entry *sg_table;
19308 + src_nents = sg_nents_for_len(req->src,
19309 + req->nbytes - (*next_buflen));
19310 + if (src_nents < 0) {
19311 + dev_err(ctx->dev, "Invalid number of src SG.\n");
19312 + return src_nents;
19316 + mapped_nents = dma_map_sg(ctx->dev, req->src, src_nents,
19318 + if (!mapped_nents) {
19319 + dev_err(ctx->dev, "unable to DMA map source\n");
19323 + mapped_nents = 0;
19326 + /* allocate space for base edesc and link tables */
19327 + edesc = qi_cache_zalloc(GFP_DMA | flags);
19329 + dma_unmap_sg(ctx->dev, req->src, src_nents,
19334 + edesc->src_nents = src_nents;
19335 + qm_sg_src_index = 1 + (*buflen ? 1 : 0);
19336 + qm_sg_bytes = (qm_sg_src_index + mapped_nents) *
19337 + sizeof(*sg_table);
19338 + sg_table = &edesc->sgt[0];
19340 + ret = ctx_map_to_qm_sg(ctx->dev, state, ctx->ctx_len, sg_table,
19341 + DMA_BIDIRECTIONAL);
19345 + ret = buf_map_to_qm_sg(ctx->dev, sg_table + 1, state);
19349 + if (mapped_nents) {
19350 + sg_to_qm_sg_last(req->src, mapped_nents,
19351 + sg_table + qm_sg_src_index, 0);
19352 + if (*next_buflen)
19353 + scatterwalk_map_and_copy(next_buf, req->src,
19354 + to_hash - *buflen,
19355 + *next_buflen, 0);
19357 + dpaa2_sg_set_final(sg_table + qm_sg_src_index - 1,
19361 + edesc->qm_sg_dma = dma_map_single(ctx->dev, sg_table,
19362 + qm_sg_bytes, DMA_TO_DEVICE);
19363 + if (dma_mapping_error(ctx->dev, edesc->qm_sg_dma)) {
19364 + dev_err(ctx->dev, "unable to map S/G table\n");
19368 + edesc->qm_sg_bytes = qm_sg_bytes;
19370 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
19371 + dpaa2_fl_set_final(in_fle, true);
19372 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
19373 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
19374 + dpaa2_fl_set_len(in_fle, ctx->ctx_len + to_hash);
19375 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19376 + dpaa2_fl_set_addr(out_fle, state->ctx_dma);
19377 + dpaa2_fl_set_len(out_fle, ctx->ctx_len);
19379 + req_ctx->flc = &ctx->flc[UPDATE];
19380 + req_ctx->flc_dma = ctx->flc_dma[UPDATE];
19381 + req_ctx->cbk = ahash_done_bi;
19382 + req_ctx->ctx = &req->base;
19383 + req_ctx->edesc = edesc;
19385 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19386 + if (ret != -EINPROGRESS &&
19387 + !(ret == -EBUSY &&
19388 + req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
19390 + } else if (*next_buflen) {
19391 + scatterwalk_map_and_copy(buf + *buflen, req->src, 0,
19393 + *buflen = *next_buflen;
19394 + *next_buflen = last_buflen;
19397 + print_hex_dump(KERN_ERR, "buf@" __stringify(__LINE__)": ",
19398 + DUMP_PREFIX_ADDRESS, 16, 4, buf, *buflen, 1);
19399 + print_hex_dump(KERN_ERR, "next buf@" __stringify(__LINE__)": ",
19400 + DUMP_PREFIX_ADDRESS, 16, 4, next_buf,
19401 + *next_buflen, 1);
19406 + ahash_unmap_ctx(ctx->dev, edesc, req, ctx->ctx_len, DMA_BIDIRECTIONAL);
19407 + qi_cache_free(edesc);
19411 +static int ahash_final_ctx(struct ahash_request *req)
19413 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19414 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19415 + struct caam_hash_state *state = ahash_request_ctx(req);
19416 + struct caam_request *req_ctx = &state->caam_req;
19417 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19418 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19419 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19420 + GFP_KERNEL : GFP_ATOMIC;
19421 + int buflen = *current_buflen(state);
19422 + int qm_sg_bytes, qm_sg_src_index;
19423 + int digestsize = crypto_ahash_digestsize(ahash);
19424 + struct ahash_edesc *edesc;
19425 + struct dpaa2_sg_entry *sg_table;
19428 + /* allocate space for base edesc and link tables */
19429 + edesc = qi_cache_zalloc(GFP_DMA | flags);
19433 + qm_sg_src_index = 1 + (buflen ? 1 : 0);
19434 + qm_sg_bytes = qm_sg_src_index * sizeof(*sg_table);
19435 + sg_table = &edesc->sgt[0];
19437 + ret = ctx_map_to_qm_sg(ctx->dev, state, ctx->ctx_len, sg_table,
19442 + ret = buf_map_to_qm_sg(ctx->dev, sg_table + 1, state);
19446 + dpaa2_sg_set_final(sg_table + qm_sg_src_index - 1, true);
19448 + edesc->qm_sg_dma = dma_map_single(ctx->dev, sg_table, qm_sg_bytes,
19450 + if (dma_mapping_error(ctx->dev, edesc->qm_sg_dma)) {
19451 + dev_err(ctx->dev, "unable to map S/G table\n");
19455 + edesc->qm_sg_bytes = qm_sg_bytes;
19457 + edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize,
19458 + DMA_FROM_DEVICE);
19459 + if (dma_mapping_error(ctx->dev, edesc->dst_dma)) {
19460 + dev_err(ctx->dev, "unable to map dst\n");
19461 + edesc->dst_dma = 0;
19466 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
19467 + dpaa2_fl_set_final(in_fle, true);
19468 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
19469 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
19470 + dpaa2_fl_set_len(in_fle, ctx->ctx_len + buflen);
19471 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19472 + dpaa2_fl_set_addr(out_fle, edesc->dst_dma);
19473 + dpaa2_fl_set_len(out_fle, digestsize);
19475 + req_ctx->flc = &ctx->flc[FINALIZE];
19476 + req_ctx->flc_dma = ctx->flc_dma[FINALIZE];
19477 + req_ctx->cbk = ahash_done_ctx_src;
19478 + req_ctx->ctx = &req->base;
19479 + req_ctx->edesc = edesc;
19481 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19482 + if (ret == -EINPROGRESS ||
19483 + (ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
19487 + ahash_unmap_ctx(ctx->dev, edesc, req, digestsize, DMA_FROM_DEVICE);
19488 + qi_cache_free(edesc);
19492 +static int ahash_finup_ctx(struct ahash_request *req)
19494 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19495 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19496 + struct caam_hash_state *state = ahash_request_ctx(req);
19497 + struct caam_request *req_ctx = &state->caam_req;
19498 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19499 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19500 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19501 + GFP_KERNEL : GFP_ATOMIC;
19502 + int buflen = *current_buflen(state);
19503 + int qm_sg_bytes, qm_sg_src_index;
19504 + int src_nents, mapped_nents;
19505 + int digestsize = crypto_ahash_digestsize(ahash);
19506 + struct ahash_edesc *edesc;
19507 + struct dpaa2_sg_entry *sg_table;
19510 + src_nents = sg_nents_for_len(req->src, req->nbytes);
19511 + if (src_nents < 0) {
19512 + dev_err(ctx->dev, "Invalid number of src SG.\n");
19513 + return src_nents;
19517 + mapped_nents = dma_map_sg(ctx->dev, req->src, src_nents,
19519 + if (!mapped_nents) {
19520 + dev_err(ctx->dev, "unable to DMA map source\n");
19524 + mapped_nents = 0;
19527 + /* allocate space for base edesc and link tables */
19528 + edesc = qi_cache_zalloc(GFP_DMA | flags);
19530 + dma_unmap_sg(ctx->dev, req->src, src_nents, DMA_TO_DEVICE);
19534 + edesc->src_nents = src_nents;
19535 + qm_sg_src_index = 1 + (buflen ? 1 : 0);
19536 + qm_sg_bytes = (qm_sg_src_index + mapped_nents) * sizeof(*sg_table);
19537 + sg_table = &edesc->sgt[0];
19539 + ret = ctx_map_to_qm_sg(ctx->dev, state, ctx->ctx_len, sg_table,
19544 + ret = buf_map_to_qm_sg(ctx->dev, sg_table + 1, state);
19548 + sg_to_qm_sg_last(req->src, mapped_nents, sg_table + qm_sg_src_index, 0);
19550 + edesc->qm_sg_dma = dma_map_single(ctx->dev, sg_table, qm_sg_bytes,
19552 + if (dma_mapping_error(ctx->dev, edesc->qm_sg_dma)) {
19553 + dev_err(ctx->dev, "unable to map S/G table\n");
19557 + edesc->qm_sg_bytes = qm_sg_bytes;
19559 + edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize,
19560 + DMA_FROM_DEVICE);
19561 + if (dma_mapping_error(ctx->dev, edesc->dst_dma)) {
19562 + dev_err(ctx->dev, "unable to map dst\n");
19563 + edesc->dst_dma = 0;
19568 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
19569 + dpaa2_fl_set_final(in_fle, true);
19570 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
19571 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
19572 + dpaa2_fl_set_len(in_fle, ctx->ctx_len + buflen + req->nbytes);
19573 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19574 + dpaa2_fl_set_addr(out_fle, edesc->dst_dma);
19575 + dpaa2_fl_set_len(out_fle, digestsize);
19577 + req_ctx->flc = &ctx->flc[FINALIZE];
19578 + req_ctx->flc_dma = ctx->flc_dma[FINALIZE];
19579 + req_ctx->cbk = ahash_done_ctx_src;
19580 + req_ctx->ctx = &req->base;
19581 + req_ctx->edesc = edesc;
19583 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19584 + if (ret == -EINPROGRESS ||
19585 + (ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
19589 + ahash_unmap_ctx(ctx->dev, edesc, req, digestsize, DMA_FROM_DEVICE);
19590 + qi_cache_free(edesc);
19594 +static int ahash_digest(struct ahash_request *req)
19596 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19597 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19598 + struct caam_hash_state *state = ahash_request_ctx(req);
19599 + struct caam_request *req_ctx = &state->caam_req;
19600 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19601 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19602 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19603 + GFP_KERNEL : GFP_ATOMIC;
19604 + int digestsize = crypto_ahash_digestsize(ahash);
19605 + int src_nents, mapped_nents;
19606 + struct ahash_edesc *edesc;
19607 + int ret = -ENOMEM;
19609 + state->buf_dma = 0;
19611 + src_nents = sg_nents_for_len(req->src, req->nbytes);
19612 + if (src_nents < 0) {
19613 + dev_err(ctx->dev, "Invalid number of src SG.\n");
19614 + return src_nents;
19618 + mapped_nents = dma_map_sg(ctx->dev, req->src, src_nents,
19620 + if (!mapped_nents) {
19621 + dev_err(ctx->dev, "unable to map source for DMA\n");
19625 + mapped_nents = 0;
19628 + /* allocate space for base edesc and link tables */
19629 + edesc = qi_cache_zalloc(GFP_DMA | flags);
19631 + dma_unmap_sg(ctx->dev, req->src, src_nents, DMA_TO_DEVICE);
19635 + edesc->src_nents = src_nents;
19636 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
19638 + if (mapped_nents > 1) {
19640 + struct dpaa2_sg_entry *sg_table = &edesc->sgt[0];
19642 + qm_sg_bytes = mapped_nents * sizeof(*sg_table);
19643 + sg_to_qm_sg_last(req->src, mapped_nents, sg_table, 0);
19644 + edesc->qm_sg_dma = dma_map_single(ctx->dev, sg_table,
19645 + qm_sg_bytes, DMA_TO_DEVICE);
19646 + if (dma_mapping_error(ctx->dev, edesc->qm_sg_dma)) {
19647 + dev_err(ctx->dev, "unable to map S/G table\n");
19650 + edesc->qm_sg_bytes = qm_sg_bytes;
19651 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
19652 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
19654 + dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
19655 + dpaa2_fl_set_addr(in_fle, sg_dma_address(req->src));
19658 + edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize,
19659 + DMA_FROM_DEVICE);
19660 + if (dma_mapping_error(ctx->dev, edesc->dst_dma)) {
19661 + dev_err(ctx->dev, "unable to map dst\n");
19662 + edesc->dst_dma = 0;
19666 + dpaa2_fl_set_final(in_fle, true);
19667 + dpaa2_fl_set_len(in_fle, req->nbytes);
19668 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19669 + dpaa2_fl_set_addr(out_fle, edesc->dst_dma);
19670 + dpaa2_fl_set_len(out_fle, digestsize);
19672 + req_ctx->flc = &ctx->flc[DIGEST];
19673 + req_ctx->flc_dma = ctx->flc_dma[DIGEST];
19674 + req_ctx->cbk = ahash_done;
19675 + req_ctx->ctx = &req->base;
19676 + req_ctx->edesc = edesc;
19677 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19678 + if (ret == -EINPROGRESS ||
19679 + (ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
19683 + ahash_unmap(ctx->dev, edesc, req, digestsize);
19684 + qi_cache_free(edesc);
19688 +static int ahash_final_no_ctx(struct ahash_request *req)
19690 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19691 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19692 + struct caam_hash_state *state = ahash_request_ctx(req);
19693 + struct caam_request *req_ctx = &state->caam_req;
19694 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19695 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19696 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19697 + GFP_KERNEL : GFP_ATOMIC;
19698 + u8 *buf = current_buf(state);
19699 + int buflen = *current_buflen(state);
19700 + int digestsize = crypto_ahash_digestsize(ahash);
19701 + struct ahash_edesc *edesc;
19702 + int ret = -ENOMEM;
19704 + /* allocate space for base edesc and link tables */
19705 + edesc = qi_cache_zalloc(GFP_DMA | flags);
19709 + state->buf_dma = dma_map_single(ctx->dev, buf, buflen, DMA_TO_DEVICE);
19710 + if (dma_mapping_error(ctx->dev, state->buf_dma)) {
19711 + dev_err(ctx->dev, "unable to map src\n");
19715 + edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize,
19716 + DMA_FROM_DEVICE);
19717 + if (dma_mapping_error(ctx->dev, edesc->dst_dma)) {
19718 + dev_err(ctx->dev, "unable to map dst\n");
19719 + edesc->dst_dma = 0;
19723 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
19724 + dpaa2_fl_set_final(in_fle, true);
19725 + dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
19726 + dpaa2_fl_set_addr(in_fle, state->buf_dma);
19727 + dpaa2_fl_set_len(in_fle, buflen);
19728 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19729 + dpaa2_fl_set_addr(out_fle, edesc->dst_dma);
19730 + dpaa2_fl_set_len(out_fle, digestsize);
19732 + req_ctx->flc = &ctx->flc[DIGEST];
19733 + req_ctx->flc_dma = ctx->flc_dma[DIGEST];
19734 + req_ctx->cbk = ahash_done;
19735 + req_ctx->ctx = &req->base;
19736 + req_ctx->edesc = edesc;
19738 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19739 + if (ret == -EINPROGRESS ||
19740 + (ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
19744 + ahash_unmap(ctx->dev, edesc, req, digestsize);
19745 + qi_cache_free(edesc);
19749 +static int ahash_update_no_ctx(struct ahash_request *req)
19751 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19752 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19753 + struct caam_hash_state *state = ahash_request_ctx(req);
19754 + struct caam_request *req_ctx = &state->caam_req;
19755 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19756 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19757 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19758 + GFP_KERNEL : GFP_ATOMIC;
19759 + u8 *buf = current_buf(state);
19760 + int *buflen = current_buflen(state);
19761 + u8 *next_buf = alt_buf(state);
19762 + int *next_buflen = alt_buflen(state);
19763 + int in_len = *buflen + req->nbytes, to_hash;
19764 + int qm_sg_bytes, src_nents, mapped_nents;
19765 + struct ahash_edesc *edesc;
19768 + *next_buflen = in_len & (crypto_tfm_alg_blocksize(&ahash->base) - 1);
19769 + to_hash = in_len - *next_buflen;
19772 + struct dpaa2_sg_entry *sg_table;
19774 + src_nents = sg_nents_for_len(req->src,
19775 + req->nbytes - *next_buflen);
19776 + if (src_nents < 0) {
19777 + dev_err(ctx->dev, "Invalid number of src SG.\n");
19778 + return src_nents;
19782 + mapped_nents = dma_map_sg(ctx->dev, req->src, src_nents,
19784 + if (!mapped_nents) {
19785 + dev_err(ctx->dev, "unable to DMA map source\n");
19789 + mapped_nents = 0;
19792 + /* allocate space for base edesc and link tables */
19793 + edesc = qi_cache_zalloc(GFP_DMA | flags);
19795 + dma_unmap_sg(ctx->dev, req->src, src_nents,
19800 + edesc->src_nents = src_nents;
19801 + qm_sg_bytes = (1 + mapped_nents) * sizeof(*sg_table);
19802 + sg_table = &edesc->sgt[0];
19804 + ret = buf_map_to_qm_sg(ctx->dev, sg_table, state);
19808 + sg_to_qm_sg_last(req->src, mapped_nents, sg_table + 1, 0);
19810 + if (*next_buflen)
19811 + scatterwalk_map_and_copy(next_buf, req->src,
19812 + to_hash - *buflen,
19813 + *next_buflen, 0);
19815 + edesc->qm_sg_dma = dma_map_single(ctx->dev, sg_table,
19816 + qm_sg_bytes, DMA_TO_DEVICE);
19817 + if (dma_mapping_error(ctx->dev, edesc->qm_sg_dma)) {
19818 + dev_err(ctx->dev, "unable to map S/G table\n");
19822 + edesc->qm_sg_bytes = qm_sg_bytes;
19824 + state->ctx_dma = dma_map_single(ctx->dev, state->caam_ctx,
19825 + ctx->ctx_len, DMA_FROM_DEVICE);
19826 + if (dma_mapping_error(ctx->dev, state->ctx_dma)) {
19827 + dev_err(ctx->dev, "unable to map ctx\n");
19828 + state->ctx_dma = 0;
19833 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
19834 + dpaa2_fl_set_final(in_fle, true);
19835 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
19836 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
19837 + dpaa2_fl_set_len(in_fle, to_hash);
19838 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19839 + dpaa2_fl_set_addr(out_fle, state->ctx_dma);
19840 + dpaa2_fl_set_len(out_fle, ctx->ctx_len);
19842 + req_ctx->flc = &ctx->flc[UPDATE_FIRST];
19843 + req_ctx->flc_dma = ctx->flc_dma[UPDATE_FIRST];
19844 + req_ctx->cbk = ahash_done_ctx_dst;
19845 + req_ctx->ctx = &req->base;
19846 + req_ctx->edesc = edesc;
19848 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19849 + if (ret != -EINPROGRESS &&
19850 + !(ret == -EBUSY &&
19851 + req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
19854 + state->update = ahash_update_ctx;
19855 + state->finup = ahash_finup_ctx;
19856 + state->final = ahash_final_ctx;
19857 + } else if (*next_buflen) {
19858 + scatterwalk_map_and_copy(buf + *buflen, req->src, 0,
19860 + *buflen = *next_buflen;
19861 + *next_buflen = 0;
19864 + print_hex_dump(KERN_ERR, "buf@" __stringify(__LINE__)": ",
19865 + DUMP_PREFIX_ADDRESS, 16, 4, buf, *buflen, 1);
19866 + print_hex_dump(KERN_ERR, "next buf@" __stringify(__LINE__)": ",
19867 + DUMP_PREFIX_ADDRESS, 16, 4, next_buf,
19868 + *next_buflen, 1);
19873 + ahash_unmap_ctx(ctx->dev, edesc, req, ctx->ctx_len, DMA_TO_DEVICE);
19874 + qi_cache_free(edesc);
19878 +static int ahash_finup_no_ctx(struct ahash_request *req)
19880 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19881 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19882 + struct caam_hash_state *state = ahash_request_ctx(req);
19883 + struct caam_request *req_ctx = &state->caam_req;
19884 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19885 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19886 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19887 + GFP_KERNEL : GFP_ATOMIC;
19888 + int buflen = *current_buflen(state);
19889 + int qm_sg_bytes, src_nents, mapped_nents;
19890 + int digestsize = crypto_ahash_digestsize(ahash);
19891 + struct ahash_edesc *edesc;
19892 + struct dpaa2_sg_entry *sg_table;
19895 + src_nents = sg_nents_for_len(req->src, req->nbytes);
19896 + if (src_nents < 0) {
19897 + dev_err(ctx->dev, "Invalid number of src SG.\n");
19898 + return src_nents;
19902 + mapped_nents = dma_map_sg(ctx->dev, req->src, src_nents,
19904 + if (!mapped_nents) {
19905 + dev_err(ctx->dev, "unable to DMA map source\n");
19909 + mapped_nents = 0;
19912 + /* allocate space for base edesc and link tables */
19913 + edesc = qi_cache_zalloc(GFP_DMA | flags);
19915 + dma_unmap_sg(ctx->dev, req->src, src_nents, DMA_TO_DEVICE);
19919 + edesc->src_nents = src_nents;
19920 + qm_sg_bytes = (2 + mapped_nents) * sizeof(*sg_table);
19921 + sg_table = &edesc->sgt[0];
19923 + ret = buf_map_to_qm_sg(ctx->dev, sg_table, state);
19927 + sg_to_qm_sg_last(req->src, mapped_nents, sg_table + 1, 0);
19929 + edesc->qm_sg_dma = dma_map_single(ctx->dev, sg_table, qm_sg_bytes,
19931 + if (dma_mapping_error(ctx->dev, edesc->qm_sg_dma)) {
19932 + dev_err(ctx->dev, "unable to map S/G table\n");
19936 + edesc->qm_sg_bytes = qm_sg_bytes;
19938 + edesc->dst_dma = dma_map_single(ctx->dev, req->result, digestsize,
19939 + DMA_FROM_DEVICE);
19940 + if (dma_mapping_error(ctx->dev, edesc->dst_dma)) {
19941 + dev_err(ctx->dev, "unable to map dst\n");
19942 + edesc->dst_dma = 0;
19947 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
19948 + dpaa2_fl_set_final(in_fle, true);
19949 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
19950 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
19951 + dpaa2_fl_set_len(in_fle, buflen + req->nbytes);
19952 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
19953 + dpaa2_fl_set_addr(out_fle, edesc->dst_dma);
19954 + dpaa2_fl_set_len(out_fle, digestsize);
19956 + req_ctx->flc = &ctx->flc[DIGEST];
19957 + req_ctx->flc_dma = ctx->flc_dma[DIGEST];
19958 + req_ctx->cbk = ahash_done;
19959 + req_ctx->ctx = &req->base;
19960 + req_ctx->edesc = edesc;
19961 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
19962 + if (ret != -EINPROGRESS &&
19963 + !(ret == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
19968 + ahash_unmap(ctx->dev, edesc, req, digestsize);
19969 + qi_cache_free(edesc);
19973 +static int ahash_update_first(struct ahash_request *req)
19975 + struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
19976 + struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
19977 + struct caam_hash_state *state = ahash_request_ctx(req);
19978 + struct caam_request *req_ctx = &state->caam_req;
19979 + struct dpaa2_fl_entry *in_fle = &req_ctx->fd_flt[1];
19980 + struct dpaa2_fl_entry *out_fle = &req_ctx->fd_flt[0];
19981 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
19982 + GFP_KERNEL : GFP_ATOMIC;
19983 + u8 *next_buf = alt_buf(state);
19984 + int *next_buflen = alt_buflen(state);
19986 + int src_nents, mapped_nents;
19987 + struct ahash_edesc *edesc;
19990 + *next_buflen = req->nbytes & (crypto_tfm_alg_blocksize(&ahash->base) -
19992 + to_hash = req->nbytes - *next_buflen;
19995 + struct dpaa2_sg_entry *sg_table;
19997 + src_nents = sg_nents_for_len(req->src,
19998 + req->nbytes - (*next_buflen));
19999 + if (src_nents < 0) {
20000 + dev_err(ctx->dev, "Invalid number of src SG.\n");
20001 + return src_nents;
20005 + mapped_nents = dma_map_sg(ctx->dev, req->src, src_nents,
20007 + if (!mapped_nents) {
20008 + dev_err(ctx->dev, "unable to map source for DMA\n");
20012 + mapped_nents = 0;
20015 + /* allocate space for base edesc and link tables */
20016 + edesc = qi_cache_zalloc(GFP_DMA | flags);
20018 + dma_unmap_sg(ctx->dev, req->src, src_nents,
20023 + edesc->src_nents = src_nents;
20024 + sg_table = &edesc->sgt[0];
20026 + memset(&req_ctx->fd_flt, 0, sizeof(req_ctx->fd_flt));
20027 + dpaa2_fl_set_final(in_fle, true);
20028 + dpaa2_fl_set_len(in_fle, to_hash);
20030 + if (mapped_nents > 1) {
20033 + sg_to_qm_sg_last(req->src, mapped_nents, sg_table, 0);
20034 + qm_sg_bytes = mapped_nents * sizeof(*sg_table);
20035 + edesc->qm_sg_dma = dma_map_single(ctx->dev, sg_table,
20038 + if (dma_mapping_error(ctx->dev, edesc->qm_sg_dma)) {
20039 + dev_err(ctx->dev, "unable to map S/G table\n");
20043 + edesc->qm_sg_bytes = qm_sg_bytes;
20044 + dpaa2_fl_set_format(in_fle, dpaa2_fl_sg);
20045 + dpaa2_fl_set_addr(in_fle, edesc->qm_sg_dma);
20047 + dpaa2_fl_set_format(in_fle, dpaa2_fl_single);
20048 + dpaa2_fl_set_addr(in_fle, sg_dma_address(req->src));
20051 + if (*next_buflen)
20052 + scatterwalk_map_and_copy(next_buf, req->src, to_hash,
20053 + *next_buflen, 0);
20055 + state->ctx_dma = dma_map_single(ctx->dev, state->caam_ctx,
20056 + ctx->ctx_len, DMA_FROM_DEVICE);
20057 + if (dma_mapping_error(ctx->dev, state->ctx_dma)) {
20058 + dev_err(ctx->dev, "unable to map ctx\n");
20059 + state->ctx_dma = 0;
20064 + dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
20065 + dpaa2_fl_set_addr(out_fle, state->ctx_dma);
20066 + dpaa2_fl_set_len(out_fle, ctx->ctx_len);
20068 + req_ctx->flc = &ctx->flc[UPDATE_FIRST];
20069 + req_ctx->flc_dma = ctx->flc_dma[UPDATE_FIRST];
20070 + req_ctx->cbk = ahash_done_ctx_dst;
20071 + req_ctx->ctx = &req->base;
20072 + req_ctx->edesc = edesc;
20074 + ret = dpaa2_caam_enqueue(ctx->dev, req_ctx);
20075 + if (ret != -EINPROGRESS &&
20076 + !(ret == -EBUSY && req->base.flags &
20077 + CRYPTO_TFM_REQ_MAY_BACKLOG))
20080 + state->update = ahash_update_ctx;
20081 + state->finup = ahash_finup_ctx;
20082 + state->final = ahash_final_ctx;
20083 + } else if (*next_buflen) {
20084 + state->update = ahash_update_no_ctx;
20085 + state->finup = ahash_finup_no_ctx;
20086 + state->final = ahash_final_no_ctx;
20087 + scatterwalk_map_and_copy(next_buf, req->src, 0,
20089 + switch_buf(state);
20092 + print_hex_dump(KERN_ERR, "next buf@" __stringify(__LINE__)": ",
20093 + DUMP_PREFIX_ADDRESS, 16, 4, next_buf, *next_buflen, 1);
20098 + ahash_unmap_ctx(ctx->dev, edesc, req, ctx->ctx_len, DMA_TO_DEVICE);
20099 + qi_cache_free(edesc);
20103 +static int ahash_finup_first(struct ahash_request *req)
20105 + return ahash_digest(req);
20108 +static int ahash_init(struct ahash_request *req)
20110 + struct caam_hash_state *state = ahash_request_ctx(req);
20112 + state->update = ahash_update_first;
20113 + state->finup = ahash_finup_first;
20114 + state->final = ahash_final_no_ctx;
20116 + state->ctx_dma = 0;
20117 + state->current_buf = 0;
20118 + state->buf_dma = 0;
20119 + state->buflen_0 = 0;
20120 + state->buflen_1 = 0;
20125 +static int ahash_update(struct ahash_request *req)
20127 + struct caam_hash_state *state = ahash_request_ctx(req);
20129 + return state->update(req);
20132 +static int ahash_finup(struct ahash_request *req)
20134 + struct caam_hash_state *state = ahash_request_ctx(req);
20136 + return state->finup(req);
20139 +static int ahash_final(struct ahash_request *req)
20141 + struct caam_hash_state *state = ahash_request_ctx(req);
20143 + return state->final(req);
20146 +static int ahash_export(struct ahash_request *req, void *out)
20148 + struct caam_hash_state *state = ahash_request_ctx(req);
20149 + struct caam_export_state *export = out;
20153 + if (state->current_buf) {
20154 + buf = state->buf_1;
20155 + len = state->buflen_1;
20157 + buf = state->buf_0;
20158 + len = state->buflen_0;
20161 + memcpy(export->buf, buf, len);
20162 + memcpy(export->caam_ctx, state->caam_ctx, sizeof(export->caam_ctx));
20163 + export->buflen = len;
20164 + export->update = state->update;
20165 + export->final = state->final;
20166 + export->finup = state->finup;
20171 +static int ahash_import(struct ahash_request *req, const void *in)
20173 + struct caam_hash_state *state = ahash_request_ctx(req);
20174 + const struct caam_export_state *export = in;
20176 + memset(state, 0, sizeof(*state));
20177 + memcpy(state->buf_0, export->buf, export->buflen);
20178 + memcpy(state->caam_ctx, export->caam_ctx, sizeof(state->caam_ctx));
20179 + state->buflen_0 = export->buflen;
20180 + state->update = export->update;
20181 + state->final = export->final;
20182 + state->finup = export->finup;
20187 +struct caam_hash_template {
20188 + char name[CRYPTO_MAX_ALG_NAME];
20189 + char driver_name[CRYPTO_MAX_ALG_NAME];
20190 + char hmac_name[CRYPTO_MAX_ALG_NAME];
20191 + char hmac_driver_name[CRYPTO_MAX_ALG_NAME];
20192 + unsigned int blocksize;
20193 + struct ahash_alg template_ahash;
20197 +/* ahash descriptors */
20198 +static struct caam_hash_template driver_hash[] = {
20201 + .driver_name = "sha1-caam-qi2",
20202 + .hmac_name = "hmac(sha1)",
20203 + .hmac_driver_name = "hmac-sha1-caam-qi2",
20204 + .blocksize = SHA1_BLOCK_SIZE,
20205 + .template_ahash = {
20206 + .init = ahash_init,
20207 + .update = ahash_update,
20208 + .final = ahash_final,
20209 + .finup = ahash_finup,
20210 + .digest = ahash_digest,
20211 + .export = ahash_export,
20212 + .import = ahash_import,
20213 + .setkey = ahash_setkey,
20215 + .digestsize = SHA1_DIGEST_SIZE,
20216 + .statesize = sizeof(struct caam_export_state),
20219 + .alg_type = OP_ALG_ALGSEL_SHA1,
20221 + .name = "sha224",
20222 + .driver_name = "sha224-caam-qi2",
20223 + .hmac_name = "hmac(sha224)",
20224 + .hmac_driver_name = "hmac-sha224-caam-qi2",
20225 + .blocksize = SHA224_BLOCK_SIZE,
20226 + .template_ahash = {
20227 + .init = ahash_init,
20228 + .update = ahash_update,
20229 + .final = ahash_final,
20230 + .finup = ahash_finup,
20231 + .digest = ahash_digest,
20232 + .export = ahash_export,
20233 + .import = ahash_import,
20234 + .setkey = ahash_setkey,
20236 + .digestsize = SHA224_DIGEST_SIZE,
20237 + .statesize = sizeof(struct caam_export_state),
20240 + .alg_type = OP_ALG_ALGSEL_SHA224,
20242 + .name = "sha256",
20243 + .driver_name = "sha256-caam-qi2",
20244 + .hmac_name = "hmac(sha256)",
20245 + .hmac_driver_name = "hmac-sha256-caam-qi2",
20246 + .blocksize = SHA256_BLOCK_SIZE,
20247 + .template_ahash = {
20248 + .init = ahash_init,
20249 + .update = ahash_update,
20250 + .final = ahash_final,
20251 + .finup = ahash_finup,
20252 + .digest = ahash_digest,
20253 + .export = ahash_export,
20254 + .import = ahash_import,
20255 + .setkey = ahash_setkey,
20257 + .digestsize = SHA256_DIGEST_SIZE,
20258 + .statesize = sizeof(struct caam_export_state),
20261 + .alg_type = OP_ALG_ALGSEL_SHA256,
20263 + .name = "sha384",
20264 + .driver_name = "sha384-caam-qi2",
20265 + .hmac_name = "hmac(sha384)",
20266 + .hmac_driver_name = "hmac-sha384-caam-qi2",
20267 + .blocksize = SHA384_BLOCK_SIZE,
20268 + .template_ahash = {
20269 + .init = ahash_init,
20270 + .update = ahash_update,
20271 + .final = ahash_final,
20272 + .finup = ahash_finup,
20273 + .digest = ahash_digest,
20274 + .export = ahash_export,
20275 + .import = ahash_import,
20276 + .setkey = ahash_setkey,
20278 + .digestsize = SHA384_DIGEST_SIZE,
20279 + .statesize = sizeof(struct caam_export_state),
20282 + .alg_type = OP_ALG_ALGSEL_SHA384,
20284 + .name = "sha512",
20285 + .driver_name = "sha512-caam-qi2",
20286 + .hmac_name = "hmac(sha512)",
20287 + .hmac_driver_name = "hmac-sha512-caam-qi2",
20288 + .blocksize = SHA512_BLOCK_SIZE,
20289 + .template_ahash = {
20290 + .init = ahash_init,
20291 + .update = ahash_update,
20292 + .final = ahash_final,
20293 + .finup = ahash_finup,
20294 + .digest = ahash_digest,
20295 + .export = ahash_export,
20296 + .import = ahash_import,
20297 + .setkey = ahash_setkey,
20299 + .digestsize = SHA512_DIGEST_SIZE,
20300 + .statesize = sizeof(struct caam_export_state),
20303 + .alg_type = OP_ALG_ALGSEL_SHA512,
20306 + .driver_name = "md5-caam-qi2",
20307 + .hmac_name = "hmac(md5)",
20308 + .hmac_driver_name = "hmac-md5-caam-qi2",
20309 + .blocksize = MD5_BLOCK_WORDS * 4,
20310 + .template_ahash = {
20311 + .init = ahash_init,
20312 + .update = ahash_update,
20313 + .final = ahash_final,
20314 + .finup = ahash_finup,
20315 + .digest = ahash_digest,
20316 + .export = ahash_export,
20317 + .import = ahash_import,
20318 + .setkey = ahash_setkey,
20320 + .digestsize = MD5_DIGEST_SIZE,
20321 + .statesize = sizeof(struct caam_export_state),
20324 + .alg_type = OP_ALG_ALGSEL_MD5,
20328 +struct caam_hash_alg {
20329 + struct list_head entry;
20330 + struct device *dev;
20332 + struct ahash_alg ahash_alg;
20335 +static int caam_hash_cra_init(struct crypto_tfm *tfm)
20337 + struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
20338 + struct crypto_alg *base = tfm->__crt_alg;
20339 + struct hash_alg_common *halg =
20340 + container_of(base, struct hash_alg_common, base);
20341 + struct ahash_alg *alg =
20342 + container_of(halg, struct ahash_alg, halg);
20343 + struct caam_hash_alg *caam_hash =
20344 + container_of(alg, struct caam_hash_alg, ahash_alg);
20345 + struct caam_hash_ctx *ctx = crypto_tfm_ctx(tfm);
20346 + /* Sizes for MDHA running digests: MD5, SHA1, 224, 256, 384, 512 */
20347 + static const u8 runninglen[] = { HASH_MSG_LEN + MD5_DIGEST_SIZE,
20348 + HASH_MSG_LEN + SHA1_DIGEST_SIZE,
20349 + HASH_MSG_LEN + 32,
20350 + HASH_MSG_LEN + SHA256_DIGEST_SIZE,
20351 + HASH_MSG_LEN + 64,
20352 + HASH_MSG_LEN + SHA512_DIGEST_SIZE };
20353 + dma_addr_t dma_addr;
20356 + ctx->dev = caam_hash->dev;
20358 + dma_addr = dma_map_single_attrs(ctx->dev, ctx->flc, sizeof(ctx->flc),
20359 + DMA_BIDIRECTIONAL,
20360 + DMA_ATTR_SKIP_CPU_SYNC);
20361 + if (dma_mapping_error(ctx->dev, dma_addr)) {
20362 + dev_err(ctx->dev, "unable to map shared descriptors\n");
20366 + for (i = 0; i < HASH_NUM_OP; i++)
20367 + ctx->flc_dma[i] = dma_addr + i * sizeof(ctx->flc[i]);
20369 + /* copy descriptor header template value */
20370 + ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam_hash->alg_type;
20372 + ctx->ctx_len = runninglen[(ctx->adata.algtype &
20373 + OP_ALG_ALGSEL_SUBMASK) >>
20374 + OP_ALG_ALGSEL_SHIFT];
20376 + crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
20377 + sizeof(struct caam_hash_state));
20379 + return ahash_set_sh_desc(ahash);
20382 +static void caam_hash_cra_exit(struct crypto_tfm *tfm)
20384 + struct caam_hash_ctx *ctx = crypto_tfm_ctx(tfm);
20386 + dma_unmap_single_attrs(ctx->dev, ctx->flc_dma[0], sizeof(ctx->flc),
20387 + DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
20390 +static struct caam_hash_alg *caam_hash_alloc(struct device *dev,
20391 + struct caam_hash_template *template, bool keyed)
20393 + struct caam_hash_alg *t_alg;
20394 + struct ahash_alg *halg;
20395 + struct crypto_alg *alg;
20397 + t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
20399 + return ERR_PTR(-ENOMEM);
20401 + t_alg->ahash_alg = template->template_ahash;
20402 + halg = &t_alg->ahash_alg;
20403 + alg = &halg->halg.base;
20406 + snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
20407 + template->hmac_name);
20408 + snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
20409 + template->hmac_driver_name);
20411 + snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
20413 + snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
20414 + template->driver_name);
20416 + alg->cra_module = THIS_MODULE;
20417 + alg->cra_init = caam_hash_cra_init;
20418 + alg->cra_exit = caam_hash_cra_exit;
20419 + alg->cra_ctxsize = sizeof(struct caam_hash_ctx);
20420 + alg->cra_priority = CAAM_CRA_PRIORITY;
20421 + alg->cra_blocksize = template->blocksize;
20422 + alg->cra_alignmask = 0;
20423 + alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_TYPE_AHASH;
20424 + alg->cra_type = &crypto_ahash_type;
20426 + t_alg->alg_type = template->alg_type;
20427 + t_alg->dev = dev;
20432 +static void dpaa2_caam_fqdan_cb(struct dpaa2_io_notification_ctx *nctx)
20434 + struct dpaa2_caam_priv_per_cpu *ppriv;
20436 + ppriv = container_of(nctx, struct dpaa2_caam_priv_per_cpu, nctx);
20437 + napi_schedule_irqoff(&ppriv->napi);
20440 +static int __cold dpaa2_dpseci_dpio_setup(struct dpaa2_caam_priv *priv)
20442 + struct device *dev = priv->dev;
20443 + struct dpaa2_io_notification_ctx *nctx;
20444 + struct dpaa2_caam_priv_per_cpu *ppriv;
20445 + int err, i = 0, cpu;
20447 + for_each_online_cpu(cpu) {
20448 + ppriv = per_cpu_ptr(priv->ppriv, cpu);
20449 + ppriv->priv = priv;
20450 + nctx = &ppriv->nctx;
20451 + nctx->is_cdan = 0;
20452 + nctx->id = ppriv->rsp_fqid;
20453 + nctx->desired_cpu = cpu;
20454 + nctx->cb = dpaa2_caam_fqdan_cb;
20456 + /* Register notification callbacks */
20457 + err = dpaa2_io_service_register(NULL, nctx);
20458 + if (unlikely(err)) {
20459 + dev_err(dev, "notification register failed\n");
20464 + ppriv->store = dpaa2_io_store_create(DPAA2_CAAM_STORE_SIZE,
20466 + if (unlikely(!ppriv->store)) {
20467 + dev_err(dev, "dpaa2_io_store_create() failed\n");
20471 + if (++i == priv->num_pairs)
20478 + for_each_online_cpu(cpu) {
20479 + ppriv = per_cpu_ptr(priv->ppriv, cpu);
20480 + if (!ppriv->nctx.cb)
20482 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
20485 + for_each_online_cpu(cpu) {
20486 + ppriv = per_cpu_ptr(priv->ppriv, cpu);
20487 + if (!ppriv->store)
20489 + dpaa2_io_store_destroy(ppriv->store);
20495 +static void __cold dpaa2_dpseci_dpio_free(struct dpaa2_caam_priv *priv)
20497 + struct dpaa2_caam_priv_per_cpu *ppriv;
20500 + for_each_online_cpu(cpu) {
20501 + ppriv = per_cpu_ptr(priv->ppriv, cpu);
20502 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
20503 + dpaa2_io_store_destroy(ppriv->store);
20505 + if (++i == priv->num_pairs)
20510 +static int dpaa2_dpseci_bind(struct dpaa2_caam_priv *priv)
20512 + struct dpseci_rx_queue_cfg rx_queue_cfg;
20513 + struct device *dev = priv->dev;
20514 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
20515 + struct dpaa2_caam_priv_per_cpu *ppriv;
20516 + int err = 0, i = 0, cpu;
20518 + /* Configure Rx queues */
20519 + for_each_online_cpu(cpu) {
20520 + ppriv = per_cpu_ptr(priv->ppriv, cpu);
20522 + rx_queue_cfg.options = DPSECI_QUEUE_OPT_DEST |
20523 + DPSECI_QUEUE_OPT_USER_CTX;
20524 + rx_queue_cfg.order_preservation_en = 0;
20525 + rx_queue_cfg.dest_cfg.dest_type = DPSECI_DEST_DPIO;
20526 + rx_queue_cfg.dest_cfg.dest_id = ppriv->nctx.dpio_id;
20528 + * Rx priority (WQ) doesn't really matter, since we use
20529 + * pull mode, i.e. volatile dequeues from specific FQs
20531 + rx_queue_cfg.dest_cfg.priority = 0;
20532 + rx_queue_cfg.user_ctx = ppriv->nctx.qman64;
20534 + err = dpseci_set_rx_queue(priv->mc_io, 0, ls_dev->mc_handle, i,
20537 + dev_err(dev, "dpseci_set_rx_queue() failed with err %d\n",
20542 + if (++i == priv->num_pairs)
20549 +static void dpaa2_dpseci_congestion_free(struct dpaa2_caam_priv *priv)
20551 + struct device *dev = priv->dev;
20553 + if (!priv->cscn_mem)
20556 + dma_unmap_single(dev, priv->cscn_dma, DPAA2_CSCN_SIZE, DMA_FROM_DEVICE);
20557 + kfree(priv->cscn_mem);
20560 +static void dpaa2_dpseci_free(struct dpaa2_caam_priv *priv)
20562 + struct device *dev = priv->dev;
20563 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
20565 + dpaa2_dpseci_congestion_free(priv);
20566 + dpseci_close(priv->mc_io, 0, ls_dev->mc_handle);
20569 +static void dpaa2_caam_process_fd(struct dpaa2_caam_priv *priv,
20570 + const struct dpaa2_fd *fd)
20572 + struct caam_request *req;
20575 + if (dpaa2_fd_get_format(fd) != dpaa2_fd_list) {
20576 + dev_err(priv->dev, "Only Frame List FD format is supported!\n");
20580 + fd_err = dpaa2_fd_get_ctrl(fd) & FD_CTRL_ERR_MASK;
20581 + if (unlikely(fd_err))
20582 + dev_err(priv->dev, "FD error: %08x\n", fd_err);
20585 + * FD[ADDR] is guaranteed to be valid, irrespective of errors reported
20586 + * in FD[ERR] or FD[FRC].
20588 + req = dpaa2_caam_iova_to_virt(priv, dpaa2_fd_get_addr(fd));
20589 + dma_unmap_single(priv->dev, req->fd_flt_dma, sizeof(req->fd_flt),
20590 + DMA_BIDIRECTIONAL);
20591 + req->cbk(req->ctx, dpaa2_fd_get_frc(fd));
20594 +static int dpaa2_caam_pull_fq(struct dpaa2_caam_priv_per_cpu *ppriv)
20598 + /* Retry while portal is busy */
20600 + err = dpaa2_io_service_pull_fq(NULL, ppriv->rsp_fqid,
20602 + } while (err == -EBUSY);
20604 + if (unlikely(err))
20605 + dev_err(ppriv->priv->dev, "dpaa2_io_service_pull err %d", err);
20610 +static int dpaa2_caam_store_consume(struct dpaa2_caam_priv_per_cpu *ppriv)
20612 + struct dpaa2_dq *dq;
20613 + int cleaned = 0, is_last;
20616 + dq = dpaa2_io_store_next(ppriv->store, &is_last);
20617 + if (unlikely(!dq)) {
20618 + if (unlikely(!is_last)) {
20619 + dev_dbg(ppriv->priv->dev,
20620 + "FQ %d returned no valid frames\n",
20621 + ppriv->rsp_fqid);
20623 + * MUST retry until we get some sort of
20624 + * valid response token (be it "empty dequeue"
20625 + * or a valid frame).
20633 + dpaa2_caam_process_fd(ppriv->priv, dpaa2_dq_fd(dq));
20635 + } while (!is_last);
20640 +static int dpaa2_dpseci_poll(struct napi_struct *napi, int budget)
20642 + struct dpaa2_caam_priv_per_cpu *ppriv;
20643 + struct dpaa2_caam_priv *priv;
20644 + int err, cleaned = 0, store_cleaned;
20646 + ppriv = container_of(napi, struct dpaa2_caam_priv_per_cpu, napi);
20647 + priv = ppriv->priv;
20649 + if (unlikely(dpaa2_caam_pull_fq(ppriv)))
20653 + store_cleaned = dpaa2_caam_store_consume(ppriv);
20654 + cleaned += store_cleaned;
20656 + if (store_cleaned == 0 ||
20657 + cleaned > budget - DPAA2_CAAM_STORE_SIZE)
20660 + /* Try to dequeue some more */
20661 + err = dpaa2_caam_pull_fq(ppriv);
20662 + if (unlikely(err))
20666 + if (cleaned < budget) {
20667 + napi_complete_done(napi, cleaned);
20668 + err = dpaa2_io_service_rearm(NULL, &ppriv->nctx);
20669 + if (unlikely(err))
20670 + dev_err(priv->dev, "Notification rearm failed: %d\n",
20677 +static int dpaa2_dpseci_congestion_setup(struct dpaa2_caam_priv *priv,
20680 + struct dpseci_congestion_notification_cfg cong_notif_cfg = { 0 };
20681 + struct device *dev = priv->dev;
20685 + * Congestion group feature supported starting with DPSECI API v5.1
20686 + * and only when object has been created with this capability.
20688 + if ((DPSECI_VER(priv->major_ver, priv->minor_ver) < DPSECI_VER(5, 1)) ||
20689 + !(priv->dpseci_attr.options & DPSECI_OPT_HAS_CG))
20692 + priv->cscn_mem = kzalloc(DPAA2_CSCN_SIZE + DPAA2_CSCN_ALIGN,
20693 + GFP_KERNEL | GFP_DMA);
20694 + if (!priv->cscn_mem)
20697 + priv->cscn_mem_aligned = PTR_ALIGN(priv->cscn_mem, DPAA2_CSCN_ALIGN);
20698 + priv->cscn_dma = dma_map_single(dev, priv->cscn_mem_aligned,
20699 + DPAA2_CSCN_SIZE, DMA_FROM_DEVICE);
20700 + if (dma_mapping_error(dev, priv->cscn_dma)) {
20701 + dev_err(dev, "Error mapping CSCN memory area\n");
20703 + goto err_dma_map;
20706 + cong_notif_cfg.units = DPSECI_CONGESTION_UNIT_BYTES;
20707 + cong_notif_cfg.threshold_entry = DPAA2_SEC_CONG_ENTRY_THRESH;
20708 + cong_notif_cfg.threshold_exit = DPAA2_SEC_CONG_EXIT_THRESH;
20709 + cong_notif_cfg.message_ctx = (u64)priv;
20710 + cong_notif_cfg.message_iova = priv->cscn_dma;
20711 + cong_notif_cfg.notification_mode = DPSECI_CGN_MODE_WRITE_MEM_ON_ENTER |
20712 + DPSECI_CGN_MODE_WRITE_MEM_ON_EXIT |
20713 + DPSECI_CGN_MODE_COHERENT_WRITE;
20715 + err = dpseci_set_congestion_notification(priv->mc_io, 0, token,
20716 + &cong_notif_cfg);
20718 + dev_err(dev, "dpseci_set_congestion_notification failed\n");
20719 + goto err_set_cong;
20725 + dma_unmap_single(dev, priv->cscn_dma, DPAA2_CSCN_SIZE, DMA_FROM_DEVICE);
20727 + kfree(priv->cscn_mem);
20732 +static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
20734 + struct device *dev = &ls_dev->dev;
20735 + struct dpaa2_caam_priv *priv;
20736 + struct dpaa2_caam_priv_per_cpu *ppriv;
20740 + priv = dev_get_drvdata(dev);
20743 + priv->dpsec_id = ls_dev->obj_desc.id;
20745 + /* Get a handle for the DPSECI this interface is associate with */
20746 + err = dpseci_open(priv->mc_io, 0, priv->dpsec_id, &ls_dev->mc_handle);
20748 + dev_err(dev, "dpsec_open() failed: %d\n", err);
20752 + dev_info(dev, "Opened dpseci object successfully\n");
20754 + err = dpseci_get_api_version(priv->mc_io, 0, &priv->major_ver,
20755 + &priv->minor_ver);
20757 + dev_err(dev, "dpseci_get_api_version() failed\n");
20758 + goto err_get_vers;
20761 + err = dpseci_get_attributes(priv->mc_io, 0, ls_dev->mc_handle,
20762 + &priv->dpseci_attr);
20764 + dev_err(dev, "dpseci_get_attributes() failed\n");
20765 + goto err_get_vers;
20768 + err = dpseci_get_sec_attr(priv->mc_io, 0, ls_dev->mc_handle,
20769 + &priv->sec_attr);
20771 + dev_err(dev, "dpseci_get_sec_attr() failed\n");
20772 + goto err_get_vers;
20775 + err = dpaa2_dpseci_congestion_setup(priv, ls_dev->mc_handle);
20777 + dev_err(dev, "setup_congestion() failed\n");
20778 + goto err_get_vers;
20781 + priv->num_pairs = min(priv->dpseci_attr.num_rx_queues,
20782 + priv->dpseci_attr.num_tx_queues);
20783 + if (priv->num_pairs > num_online_cpus()) {
20784 + dev_warn(dev, "%d queues won't be used\n",
20785 + priv->num_pairs - num_online_cpus());
20786 + priv->num_pairs = num_online_cpus();
20789 + for (i = 0; i < priv->dpseci_attr.num_rx_queues; i++) {
20790 + err = dpseci_get_rx_queue(priv->mc_io, 0, ls_dev->mc_handle, i,
20791 + &priv->rx_queue_attr[i]);
20793 + dev_err(dev, "dpseci_get_rx_queue() failed\n");
20794 + goto err_get_rx_queue;
20798 + for (i = 0; i < priv->dpseci_attr.num_tx_queues; i++) {
20799 + err = dpseci_get_tx_queue(priv->mc_io, 0, ls_dev->mc_handle, i,
20800 + &priv->tx_queue_attr[i]);
20802 + dev_err(dev, "dpseci_get_tx_queue() failed\n");
20803 + goto err_get_rx_queue;
20808 + for_each_online_cpu(cpu) {
20809 + dev_info(dev, "prio %d: rx queue %d, tx queue %d\n", i,
20810 + priv->rx_queue_attr[i].fqid,
20811 + priv->tx_queue_attr[i].fqid);
20813 + ppriv = per_cpu_ptr(priv->ppriv, cpu);
20814 + ppriv->req_fqid = priv->tx_queue_attr[i].fqid;
20815 + ppriv->rsp_fqid = priv->rx_queue_attr[i].fqid;
20818 + ppriv->net_dev.dev = *dev;
20819 + INIT_LIST_HEAD(&ppriv->net_dev.napi_list);
20820 + netif_napi_add(&ppriv->net_dev, &ppriv->napi, dpaa2_dpseci_poll,
20821 + DPAA2_CAAM_NAPI_WEIGHT);
20822 + if (++i == priv->num_pairs)
20829 + dpaa2_dpseci_congestion_free(priv);
20831 + dpseci_close(priv->mc_io, 0, ls_dev->mc_handle);
20836 +static int dpaa2_dpseci_enable(struct dpaa2_caam_priv *priv)
20838 + struct device *dev = priv->dev;
20839 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
20840 + struct dpaa2_caam_priv_per_cpu *ppriv;
20843 + for (i = 0; i < priv->num_pairs; i++) {
20844 + ppriv = per_cpu_ptr(priv->ppriv, i);
20845 + napi_enable(&ppriv->napi);
20848 + err = dpseci_enable(priv->mc_io, 0, ls_dev->mc_handle);
20850 + dev_err(dev, "dpseci_enable() failed\n");
20854 + dev_info(dev, "DPSECI version %d.%d\n",
20856 + priv->minor_ver);
20861 +static int __cold dpaa2_dpseci_disable(struct dpaa2_caam_priv *priv)
20863 + struct device *dev = priv->dev;
20864 + struct dpaa2_caam_priv_per_cpu *ppriv;
20865 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
20866 + int i, err = 0, enabled;
20868 + err = dpseci_disable(priv->mc_io, 0, ls_dev->mc_handle);
20870 + dev_err(dev, "dpseci_disable() failed\n");
20874 + err = dpseci_is_enabled(priv->mc_io, 0, ls_dev->mc_handle, &enabled);
20876 + dev_err(dev, "dpseci_is_enabled() failed\n");
20880 + dev_dbg(dev, "disable: %s\n", enabled ? "false" : "true");
20882 + for (i = 0; i < priv->num_pairs; i++) {
20883 + ppriv = per_cpu_ptr(priv->ppriv, i);
20884 + napi_disable(&ppriv->napi);
20885 + netif_napi_del(&ppriv->napi);
20891 +static struct list_head alg_list;
20892 +static struct list_head hash_list;
20894 +static int dpaa2_caam_probe(struct fsl_mc_device *dpseci_dev)
20896 + struct device *dev;
20897 + struct dpaa2_caam_priv *priv;
20899 + bool registered = false;
20902 + * There is no way to get CAAM endianness - there is no direct register
20903 + * space access and MC f/w does not provide this attribute.
20904 + * All DPAA2-based SoCs have little endian CAAM, thus hard-code this
20907 + caam_little_end = true;
20909 + caam_imx = false;
20911 + dev = &dpseci_dev->dev;
20913 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
20917 + dev_set_drvdata(dev, priv);
20919 + priv->domain = iommu_get_domain_for_dev(dev);
20921 + qi_cache = kmem_cache_create("dpaa2_caamqicache", CAAM_QI_MEMCACHE_SIZE,
20922 + 0, SLAB_CACHE_DMA, NULL);
20924 + dev_err(dev, "Can't allocate SEC cache\n");
20926 + goto err_qicache;
20929 + err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(49));
20931 + dev_err(dev, "dma_set_mask_and_coherent() failed\n");
20932 + goto err_dma_mask;
20935 + /* Obtain a MC portal */
20936 + err = fsl_mc_portal_allocate(dpseci_dev, 0, &priv->mc_io);
20938 + dev_err(dev, "MC portal allocation failed\n");
20939 + goto err_dma_mask;
20942 + priv->ppriv = alloc_percpu(*priv->ppriv);
20943 + if (!priv->ppriv) {
20944 + dev_err(dev, "alloc_percpu() failed\n");
20945 + goto err_alloc_ppriv;
20948 + /* DPSECI initialization */
20949 + err = dpaa2_dpseci_setup(dpseci_dev);
20951 + dev_err(dev, "dpaa2_dpseci_setup() failed\n");
20952 + goto err_dpseci_setup;
20956 + err = dpaa2_dpseci_dpio_setup(priv);
20958 + dev_err(dev, "dpaa2_dpseci_dpio_setup() failed\n");
20959 + goto err_dpio_setup;
20962 + /* DPSECI binding to DPIO */
20963 + err = dpaa2_dpseci_bind(priv);
20965 + dev_err(dev, "dpaa2_dpseci_bind() failed\n");
20969 + /* DPSECI enable */
20970 + err = dpaa2_dpseci_enable(priv);
20972 + dev_err(dev, "dpaa2_dpseci_enable() failed");
20976 + /* register crypto algorithms the device supports */
20977 + INIT_LIST_HEAD(&alg_list);
20978 + for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
20979 + struct caam_crypto_alg *t_alg;
20980 + struct caam_alg_template *alg = driver_algs + i;
20981 + u32 alg_sel = alg->class1_alg_type & OP_ALG_ALGSEL_MASK;
20983 + /* Skip DES algorithms if not supported by device */
20984 + if (!priv->sec_attr.des_acc_num &&
20985 + ((alg_sel == OP_ALG_ALGSEL_3DES) ||
20986 + (alg_sel == OP_ALG_ALGSEL_DES)))
20989 + /* Skip AES algorithms if not supported by device */
20990 + if (!priv->sec_attr.aes_acc_num &&
20991 + (alg_sel == OP_ALG_ALGSEL_AES))
20994 + t_alg = caam_alg_alloc(alg);
20995 + if (IS_ERR(t_alg)) {
20996 + err = PTR_ERR(t_alg);
20997 + dev_warn(dev, "%s alg allocation failed: %d\n",
20998 + alg->driver_name, err);
21001 + t_alg->caam.dev = dev;
21003 + err = crypto_register_alg(&t_alg->crypto_alg);
21005 + dev_warn(dev, "%s alg registration failed: %d\n",
21006 + t_alg->crypto_alg.cra_driver_name, err);
21011 + list_add_tail(&t_alg->entry, &alg_list);
21012 + registered = true;
21015 + for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
21016 + struct caam_aead_alg *t_alg = driver_aeads + i;
21017 + u32 c1_alg_sel = t_alg->caam.class1_alg_type &
21018 + OP_ALG_ALGSEL_MASK;
21019 + u32 c2_alg_sel = t_alg->caam.class2_alg_type &
21020 + OP_ALG_ALGSEL_MASK;
21022 + /* Skip DES algorithms if not supported by device */
21023 + if (!priv->sec_attr.des_acc_num &&
21024 + ((c1_alg_sel == OP_ALG_ALGSEL_3DES) ||
21025 + (c1_alg_sel == OP_ALG_ALGSEL_DES)))
21028 + /* Skip AES algorithms if not supported by device */
21029 + if (!priv->sec_attr.aes_acc_num &&
21030 + (c1_alg_sel == OP_ALG_ALGSEL_AES))
21034 + * Skip algorithms requiring message digests
21035 + * if MD not supported by device.
21037 + if (!priv->sec_attr.md_acc_num && c2_alg_sel)
21040 + t_alg->caam.dev = dev;
21041 + caam_aead_alg_init(t_alg);
21043 + err = crypto_register_aead(&t_alg->aead);
21045 + dev_warn(dev, "%s alg registration failed: %d\n",
21046 + t_alg->aead.base.cra_driver_name, err);
21050 + t_alg->registered = true;
21051 + registered = true;
21054 + dev_info(dev, "algorithms registered in /proc/crypto\n");
21056 + /* register hash algorithms the device supports */
21057 + INIT_LIST_HEAD(&hash_list);
21060 + * Skip registration of any hashing algorithms if MD block
21061 + * is not present.
21063 + if (!priv->sec_attr.md_acc_num)
21066 + for (i = 0; i < ARRAY_SIZE(driver_hash); i++) {
21067 + struct caam_hash_alg *t_alg;
21068 + struct caam_hash_template *alg = driver_hash + i;
21070 + /* register hmac version */
21071 + t_alg = caam_hash_alloc(dev, alg, true);
21072 + if (IS_ERR(t_alg)) {
21073 + err = PTR_ERR(t_alg);
21074 + dev_warn(dev, "%s hash alg allocation failed: %d\n",
21075 + alg->driver_name, err);
21079 + err = crypto_register_ahash(&t_alg->ahash_alg);
21081 + dev_warn(dev, "%s alg registration failed: %d\n",
21082 + t_alg->ahash_alg.halg.base.cra_driver_name,
21086 + list_add_tail(&t_alg->entry, &hash_list);
21089 + /* register unkeyed version */
21090 + t_alg = caam_hash_alloc(dev, alg, false);
21091 + if (IS_ERR(t_alg)) {
21092 + err = PTR_ERR(t_alg);
21093 + dev_warn(dev, "%s alg allocation failed: %d\n",
21094 + alg->driver_name, err);
21098 + err = crypto_register_ahash(&t_alg->ahash_alg);
21100 + dev_warn(dev, "%s alg registration failed: %d\n",
21101 + t_alg->ahash_alg.halg.base.cra_driver_name,
21105 + list_add_tail(&t_alg->entry, &hash_list);
21108 + if (!list_empty(&hash_list))
21109 + dev_info(dev, "hash algorithms registered in /proc/crypto\n");
21114 + dpaa2_dpseci_dpio_free(priv);
21116 + dpaa2_dpseci_free(priv);
21118 + free_percpu(priv->ppriv);
21120 + fsl_mc_portal_free(priv->mc_io);
21122 + kmem_cache_destroy(qi_cache);
21124 + dev_set_drvdata(dev, NULL);
21129 +static int __cold dpaa2_caam_remove(struct fsl_mc_device *ls_dev)
21131 + struct device *dev;
21132 + struct dpaa2_caam_priv *priv;
21135 + dev = &ls_dev->dev;
21136 + priv = dev_get_drvdata(dev);
21138 + for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
21139 + struct caam_aead_alg *t_alg = driver_aeads + i;
21141 + if (t_alg->registered)
21142 + crypto_unregister_aead(&t_alg->aead);
21145 + if (alg_list.next) {
21146 + struct caam_crypto_alg *t_alg, *n;
21148 + list_for_each_entry_safe(t_alg, n, &alg_list, entry) {
21149 + crypto_unregister_alg(&t_alg->crypto_alg);
21150 + list_del(&t_alg->entry);
21155 + if (hash_list.next) {
21156 + struct caam_hash_alg *t_hash_alg, *p;
21158 + list_for_each_entry_safe(t_hash_alg, p, &hash_list, entry) {
21159 + crypto_unregister_ahash(&t_hash_alg->ahash_alg);
21160 + list_del(&t_hash_alg->entry);
21161 + kfree(t_hash_alg);
21165 + dpaa2_dpseci_disable(priv);
21166 + dpaa2_dpseci_dpio_free(priv);
21167 + dpaa2_dpseci_free(priv);
21168 + free_percpu(priv->ppriv);
21169 + fsl_mc_portal_free(priv->mc_io);
21170 + dev_set_drvdata(dev, NULL);
21171 + kmem_cache_destroy(qi_cache);
21176 +int dpaa2_caam_enqueue(struct device *dev, struct caam_request *req)
21178 + struct dpaa2_fd fd;
21179 + struct dpaa2_caam_priv *priv = dev_get_drvdata(dev);
21180 + int err = 0, i, id;
21183 + return PTR_ERR(req);
21185 + if (priv->cscn_mem) {
21186 + dma_sync_single_for_cpu(priv->dev, priv->cscn_dma,
21188 + DMA_FROM_DEVICE);
21189 + if (unlikely(dpaa2_cscn_state_congested(priv->cscn_mem_aligned))) {
21190 + dev_dbg_ratelimited(dev, "Dropping request\n");
21195 + dpaa2_fl_set_flc(&req->fd_flt[1], req->flc_dma);
21197 + req->fd_flt_dma = dma_map_single(dev, req->fd_flt, sizeof(req->fd_flt),
21198 + DMA_BIDIRECTIONAL);
21199 + if (dma_mapping_error(dev, req->fd_flt_dma)) {
21200 + dev_err(dev, "DMA mapping error for QI enqueue request\n");
21204 + memset(&fd, 0, sizeof(fd));
21205 + dpaa2_fd_set_format(&fd, dpaa2_fd_list);
21206 + dpaa2_fd_set_addr(&fd, req->fd_flt_dma);
21207 + dpaa2_fd_set_len(&fd, req->fd_flt[1].len);
21208 + dpaa2_fd_set_flc(&fd, req->flc_dma);
21211 + * There is no guarantee that preemption is disabled here,
21212 + * thus take action.
21214 + preempt_disable();
21215 + id = smp_processor_id() % priv->dpseci_attr.num_tx_queues;
21216 + for (i = 0; i < (priv->dpseci_attr.num_tx_queues << 1); i++) {
21217 + err = dpaa2_io_service_enqueue_fq(NULL,
21218 + priv->tx_queue_attr[id].fqid,
21220 + if (err != -EBUSY)
21223 + preempt_enable();
21225 + if (unlikely(err < 0)) {
21226 + dev_err(dev, "Error enqueuing frame: %d\n", err);
21230 + return -EINPROGRESS;
21233 + dma_unmap_single(dev, req->fd_flt_dma, sizeof(req->fd_flt),
21234 + DMA_BIDIRECTIONAL);
21237 +EXPORT_SYMBOL(dpaa2_caam_enqueue);
21239 +const struct fsl_mc_device_id dpaa2_caam_match_id_table[] = {
21241 + .vendor = FSL_MC_VENDOR_FREESCALE,
21242 + .obj_type = "dpseci",
21244 + { .vendor = 0x0 }
21247 +static struct fsl_mc_driver dpaa2_caam_driver = {
21249 + .name = KBUILD_MODNAME,
21250 + .owner = THIS_MODULE,
21252 + .probe = dpaa2_caam_probe,
21253 + .remove = dpaa2_caam_remove,
21254 + .match_id_table = dpaa2_caam_match_id_table
21257 +MODULE_LICENSE("Dual BSD/GPL");
21258 +MODULE_AUTHOR("Freescale Semiconductor, Inc");
21259 +MODULE_DESCRIPTION("Freescale DPAA2 CAAM Driver");
21261 +module_fsl_mc_driver(dpaa2_caam_driver);
21263 +++ b/drivers/crypto/caam/caamalg_qi2.h
21266 + * Copyright 2015-2016 Freescale Semiconductor Inc.
21267 + * Copyright 2017 NXP
21269 + * Redistribution and use in source and binary forms, with or without
21270 + * modification, are permitted provided that the following conditions are met:
21271 + * * Redistributions of source code must retain the above copyright
21272 + * notice, this list of conditions and the following disclaimer.
21273 + * * Redistributions in binary form must reproduce the above copyright
21274 + * notice, this list of conditions and the following disclaimer in the
21275 + * documentation and/or other materials provided with the distribution.
21276 + * * Neither the names of the above-listed copyright holders nor the
21277 + * names of any contributors may be used to endorse or promote products
21278 + * derived from this software without specific prior written permission.
21281 + * ALTERNATIVELY, this software may be distributed under the terms of the
21282 + * GNU General Public License ("GPL") as published by the Free Software
21283 + * Foundation, either version 2 of that License or (at your option) any
21286 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21287 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21288 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21289 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21290 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21291 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21292 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21293 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21294 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21295 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21296 + * POSSIBILITY OF SUCH DAMAGE.
21299 +#ifndef _CAAMALG_QI2_H_
21300 +#define _CAAMALG_QI2_H_
21302 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-io.h"
21303 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
21304 +#include <linux/threads.h>
21305 +#include "dpseci.h"
21306 +#include "desc_constr.h"
21308 +#define DPAA2_CAAM_STORE_SIZE 16
21309 +/* NAPI weight *must* be a multiple of the store size. */
21310 +#define DPAA2_CAAM_NAPI_WEIGHT 64
21312 +/* The congestion entrance threshold was chosen so that on LS2088
21313 + * we support the maximum throughput for the available memory
21315 +#define DPAA2_SEC_CONG_ENTRY_THRESH (128 * 1024 * 1024)
21316 +#define DPAA2_SEC_CONG_EXIT_THRESH (DPAA2_SEC_CONG_ENTRY_THRESH * 9 / 10)
21319 + * dpaa2_caam_priv - driver private data
21320 + * @dpseci_id: DPSECI object unique ID
21321 + * @major_ver: DPSECI major version
21322 + * @minor_ver: DPSECI minor version
21323 + * @dpseci_attr: DPSECI attributes
21324 + * @sec_attr: SEC engine attributes
21325 + * @rx_queue_attr: array of Rx queue attributes
21326 + * @tx_queue_attr: array of Tx queue attributes
21327 + * @cscn_mem: pointer to memory region containing the
21328 + * dpaa2_cscn struct; it's size is larger than
21329 + * sizeof(struct dpaa2_cscn) to accommodate alignment
21330 + * @cscn_mem_aligned: pointer to struct dpaa2_cscn; it is computed
21331 + * as PTR_ALIGN(cscn_mem, DPAA2_CSCN_ALIGN)
21332 + * @cscn_dma: dma address used by the QMAN to write CSCN messages
21333 + * @dev: device associated with the DPSECI object
21334 + * @mc_io: pointer to MC portal's I/O object
21335 + * @domain: IOMMU domain
21336 + * @ppriv: per CPU pointers to privata data
21338 +struct dpaa2_caam_priv {
21344 + struct dpseci_attr dpseci_attr;
21345 + struct dpseci_sec_attr sec_attr;
21346 + struct dpseci_rx_queue_attr rx_queue_attr[DPSECI_PRIO_NUM];
21347 + struct dpseci_tx_queue_attr tx_queue_attr[DPSECI_PRIO_NUM];
21352 + void *cscn_mem_aligned;
21353 + dma_addr_t cscn_dma;
21355 + struct device *dev;
21356 + struct fsl_mc_io *mc_io;
21357 + struct iommu_domain *domain;
21359 + struct dpaa2_caam_priv_per_cpu __percpu *ppriv;
21363 + * dpaa2_caam_priv_per_cpu - per CPU private data
21364 + * @napi: napi structure
21365 + * @net_dev: netdev used by napi
21366 + * @req_fqid: (virtual) request (Tx / enqueue) FQID
21367 + * @rsp_fqid: (virtual) response (Rx / dequeue) FQID
21368 + * @prio: internal queue number - index for dpaa2_caam_priv.*_queue_attr
21369 + * @nctx: notification context of response FQ
21370 + * @store: where dequeued frames are stored
21371 + * @priv: backpointer to dpaa2_caam_priv
21373 +struct dpaa2_caam_priv_per_cpu {
21374 + struct napi_struct napi;
21375 + struct net_device net_dev;
21379 + struct dpaa2_io_notification_ctx nctx;
21380 + struct dpaa2_io_store *store;
21381 + struct dpaa2_caam_priv *priv;
21385 + * The CAAM QI hardware constructs a job descriptor which points
21386 + * to shared descriptor (as pointed by context_a of FQ to CAAM).
21387 + * When the job descriptor is executed by deco, the whole job
21388 + * descriptor together with shared descriptor gets loaded in
21389 + * deco buffer which is 64 words long (each 32-bit).
21391 + * The job descriptor constructed by QI hardware has layout:
21393 + * HEADER (1 word)
21394 + * Shdesc ptr (1 or 2 words)
21395 + * SEQ_OUT_PTR (1 word)
21396 + * Out ptr (1 or 2 words)
21397 + * Out length (1 word)
21398 + * SEQ_IN_PTR (1 word)
21399 + * In ptr (1 or 2 words)
21400 + * In length (1 word)
21402 + * The shdesc ptr is used to fetch shared descriptor contents
21403 + * into deco buffer.
21405 + * Apart from shdesc contents, the total number of words that
21406 + * get loaded in deco buffer are '8' or '11'. The remaining words
21407 + * in deco buffer can be used for storing shared descriptor.
21409 +#define MAX_SDLEN ((CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN) / CAAM_CMD_SZ)
21411 +/* Length of a single buffer in the QI driver memory cache */
21412 +#define CAAM_QI_MEMCACHE_SIZE 512
21415 + * aead_edesc - s/w-extended aead descriptor
21416 + * @src_nents: number of segments in input scatterlist
21417 + * @dst_nents: number of segments in output scatterlist
21418 + * @iv_dma: dma address of iv for checking continuity and link table
21419 + * @qm_sg_bytes: length of dma mapped h/w link table
21420 + * @qm_sg_dma: bus physical mapped address of h/w link table
21421 + * @assoclen_dma: bus physical mapped address of req->assoclen
21422 + * @sgt: the h/w link table
21424 +struct aead_edesc {
21427 + dma_addr_t iv_dma;
21429 + dma_addr_t qm_sg_dma;
21430 + dma_addr_t assoclen_dma;
21431 +#define CAAM_QI_MAX_AEAD_SG \
21432 + ((CAAM_QI_MEMCACHE_SIZE - offsetof(struct aead_edesc, sgt)) / \
21433 + sizeof(struct dpaa2_sg_entry))
21434 + struct dpaa2_sg_entry sgt[0];
21438 + * tls_edesc - s/w-extended tls descriptor
21439 + * @src_nents: number of segments in input scatterlist
21440 + * @dst_nents: number of segments in output scatterlist
21441 + * @iv_dma: dma address of iv for checking continuity and link table
21442 + * @qm_sg_bytes: length of dma mapped h/w link table
21443 + * @qm_sg_dma: bus physical mapped address of h/w link table
21444 + * @tmp: array of scatterlists used by 'scatterwalk_ffwd'
21445 + * @dst: pointer to output scatterlist, usefull for unmapping
21446 + * @sgt: the h/w link table
21448 +struct tls_edesc {
21451 + dma_addr_t iv_dma;
21453 + dma_addr_t qm_sg_dma;
21454 + struct scatterlist tmp[2];
21455 + struct scatterlist *dst;
21456 + struct dpaa2_sg_entry sgt[0];
21460 + * ablkcipher_edesc - s/w-extended ablkcipher descriptor
21461 + * @src_nents: number of segments in input scatterlist
21462 + * @dst_nents: number of segments in output scatterlist
21463 + * @iv_dma: dma address of iv for checking continuity and link table
21464 + * @qm_sg_bytes: length of dma mapped qm_sg space
21465 + * @qm_sg_dma: I/O virtual address of h/w link table
21466 + * @sgt: the h/w link table
21468 +struct ablkcipher_edesc {
21471 + dma_addr_t iv_dma;
21473 + dma_addr_t qm_sg_dma;
21474 +#define CAAM_QI_MAX_ABLKCIPHER_SG \
21475 + ((CAAM_QI_MEMCACHE_SIZE - offsetof(struct ablkcipher_edesc, sgt)) / \
21476 + sizeof(struct dpaa2_sg_entry))
21477 + struct dpaa2_sg_entry sgt[0];
21481 + * ahash_edesc - s/w-extended ahash descriptor
21482 + * @dst_dma: I/O virtual address of req->result
21483 + * @qm_sg_dma: I/O virtual address of h/w link table
21484 + * @src_nents: number of segments in input scatterlist
21485 + * @qm_sg_bytes: length of dma mapped qm_sg space
21486 + * @sgt: pointer to h/w link table
21488 +struct ahash_edesc {
21489 + dma_addr_t dst_dma;
21490 + dma_addr_t qm_sg_dma;
21493 + struct dpaa2_sg_entry sgt[0];
21497 + * caam_flc - Flow Context (FLC)
21498 + * @flc: Flow Context options
21499 + * @sh_desc: Shared Descriptor
21503 + u32 sh_desc[MAX_SDLEN];
21504 +} ____cacheline_aligned;
21514 + * caam_request - the request structure the driver application should fill while
21515 + * submitting a job to driver.
21516 + * @fd_flt: Frame list table defining input and output
21517 + * fd_flt[0] - FLE pointing to output buffer
21518 + * fd_flt[1] - FLE pointing to input buffer
21519 + * @fd_flt_dma: DMA address for the frame list table
21520 + * @flc: Flow Context
21521 + * @flc_dma: I/O virtual address of Flow Context
21522 + * @op_type: operation type
21523 + * @cbk: Callback function to invoke when job is completed
21524 + * @ctx: arbit context attached with request by the application
21525 + * @edesc: extended descriptor; points to one of {ablkcipher,aead}_edesc
21527 +struct caam_request {
21528 + struct dpaa2_fl_entry fd_flt[2];
21529 + dma_addr_t fd_flt_dma;
21530 + struct caam_flc *flc;
21531 + dma_addr_t flc_dma;
21532 + enum optype op_type;
21533 + void (*cbk)(void *ctx, u32 err);
21539 + * dpaa2_caam_enqueue() - enqueue a crypto request
21540 + * @dev: device associated with the DPSECI object
21541 + * @req: pointer to caam_request
21543 +int dpaa2_caam_enqueue(struct device *dev, struct caam_request *req);
21545 +#endif /* _CAAMALG_QI2_H_ */
21546 --- a/drivers/crypto/caam/caamhash.c
21547 +++ b/drivers/crypto/caam/caamhash.c
21550 #include "sg_sw_sec4.h"
21551 #include "key_gen.h"
21552 +#include "caamhash_desc.h"
21554 #define CAAM_CRA_PRIORITY 3000
21557 #define CAAM_MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
21558 #define CAAM_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
21560 -/* length of descriptors text */
21561 -#define DESC_AHASH_BASE (4 * CAAM_CMD_SZ)
21562 -#define DESC_AHASH_UPDATE_LEN (6 * CAAM_CMD_SZ)
21563 -#define DESC_AHASH_UPDATE_FIRST_LEN (DESC_AHASH_BASE + 4 * CAAM_CMD_SZ)
21564 -#define DESC_AHASH_FINAL_LEN (DESC_AHASH_BASE + 5 * CAAM_CMD_SZ)
21565 -#define DESC_AHASH_FINUP_LEN (DESC_AHASH_BASE + 5 * CAAM_CMD_SZ)
21566 -#define DESC_AHASH_DIGEST_LEN (DESC_AHASH_BASE + 4 * CAAM_CMD_SZ)
21568 #define DESC_HASH_MAX_USED_BYTES (DESC_AHASH_FINAL_LEN + \
21569 CAAM_MAX_HASH_KEY_SIZE)
21570 #define DESC_HASH_MAX_USED_LEN (DESC_HASH_MAX_USED_BYTES / CAAM_CMD_SZ)
21571 @@ -103,20 +96,14 @@ struct caam_hash_ctx {
21572 u32 sh_desc_update_first[DESC_HASH_MAX_USED_LEN] ____cacheline_aligned;
21573 u32 sh_desc_fin[DESC_HASH_MAX_USED_LEN] ____cacheline_aligned;
21574 u32 sh_desc_digest[DESC_HASH_MAX_USED_LEN] ____cacheline_aligned;
21575 - u32 sh_desc_finup[DESC_HASH_MAX_USED_LEN] ____cacheline_aligned;
21576 dma_addr_t sh_desc_update_dma ____cacheline_aligned;
21577 dma_addr_t sh_desc_update_first_dma;
21578 dma_addr_t sh_desc_fin_dma;
21579 dma_addr_t sh_desc_digest_dma;
21580 - dma_addr_t sh_desc_finup_dma;
21581 struct device *jrdev;
21584 u8 key[CAAM_MAX_HASH_KEY_SIZE];
21585 - dma_addr_t key_dma;
21587 - unsigned int split_key_len;
21588 - unsigned int split_key_pad_len;
21589 + struct alginfo adata;
21593 @@ -143,6 +130,31 @@ struct caam_export_state {
21594 int (*finup)(struct ahash_request *req);
21597 +static inline void switch_buf(struct caam_hash_state *state)
21599 + state->current_buf ^= 1;
21602 +static inline u8 *current_buf(struct caam_hash_state *state)
21604 + return state->current_buf ? state->buf_1 : state->buf_0;
21607 +static inline u8 *alt_buf(struct caam_hash_state *state)
21609 + return state->current_buf ? state->buf_0 : state->buf_1;
21612 +static inline int *current_buflen(struct caam_hash_state *state)
21614 + return state->current_buf ? &state->buflen_1 : &state->buflen_0;
21617 +static inline int *alt_buflen(struct caam_hash_state *state)
21619 + return state->current_buf ? &state->buflen_0 : &state->buflen_1;
21622 /* Common job descriptor seq in/out ptr routines */
21624 /* Map state->caam_ctx, and append seq_out_ptr command that points to it */
21625 @@ -175,40 +187,31 @@ static inline dma_addr_t map_seq_out_ptr
21629 -/* Map current buffer in state and put it in link table */
21630 -static inline dma_addr_t buf_map_to_sec4_sg(struct device *jrdev,
21631 - struct sec4_sg_entry *sec4_sg,
21632 - u8 *buf, int buflen)
21633 +/* Map current buffer in state (if length > 0) and put it in link table */
21634 +static inline int buf_map_to_sec4_sg(struct device *jrdev,
21635 + struct sec4_sg_entry *sec4_sg,
21636 + struct caam_hash_state *state)
21638 - dma_addr_t buf_dma;
21639 + int buflen = *current_buflen(state);
21641 - buf_dma = dma_map_single(jrdev, buf, buflen, DMA_TO_DEVICE);
21642 - dma_to_sec4_sg_one(sec4_sg, buf_dma, buflen, 0);
21648 + state->buf_dma = dma_map_single(jrdev, current_buf(state), buflen,
21650 + if (dma_mapping_error(jrdev, state->buf_dma)) {
21651 + dev_err(jrdev, "unable to map buf\n");
21652 + state->buf_dma = 0;
21657 - * Only put buffer in link table if it contains data, which is possible,
21658 - * since a buffer has previously been used, and needs to be unmapped,
21660 -static inline dma_addr_t
21661 -try_buf_map_to_sec4_sg(struct device *jrdev, struct sec4_sg_entry *sec4_sg,
21662 - u8 *buf, dma_addr_t buf_dma, int buflen,
21665 - if (buf_dma && !dma_mapping_error(jrdev, buf_dma))
21666 - dma_unmap_single(jrdev, buf_dma, last_buflen, DMA_TO_DEVICE);
21668 - buf_dma = buf_map_to_sec4_sg(jrdev, sec4_sg, buf, buflen);
21671 + dma_to_sec4_sg_one(sec4_sg, state->buf_dma, buflen, 0);
21677 /* Map state->caam_ctx, and add it to link table */
21678 -static inline int ctx_map_to_sec4_sg(u32 *desc, struct device *jrdev,
21679 +static inline int ctx_map_to_sec4_sg(struct device *jrdev,
21680 struct caam_hash_state *state, int ctx_len,
21681 struct sec4_sg_entry *sec4_sg, u32 flag)
21683 @@ -224,124 +227,22 @@ static inline int ctx_map_to_sec4_sg(u32
21687 -/* Common shared descriptor commands */
21688 -static inline void append_key_ahash(u32 *desc, struct caam_hash_ctx *ctx)
21690 - append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
21691 - ctx->split_key_len, CLASS_2 |
21692 - KEY_DEST_MDHA_SPLIT | KEY_ENC);
21695 -/* Append key if it has been set */
21696 -static inline void init_sh_desc_key_ahash(u32 *desc, struct caam_hash_ctx *ctx)
21698 - u32 *key_jump_cmd;
21700 - init_sh_desc(desc, HDR_SHARE_SERIAL);
21702 - if (ctx->split_key_len) {
21703 - /* Skip if already shared */
21704 - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
21707 - append_key_ahash(desc, ctx);
21709 - set_jump_tgt_here(desc, key_jump_cmd);
21712 - /* Propagate errors from shared to job descriptor */
21713 - append_cmd(desc, SET_OK_NO_PROP_ERRORS | CMD_LOAD);
21717 - * For ahash read data from seqin following state->caam_ctx,
21718 - * and write resulting class2 context to seqout, which may be state->caam_ctx
21721 -static inline void ahash_append_load_str(u32 *desc, int digestsize)
21723 - /* Calculate remaining bytes to read */
21724 - append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
21726 - /* Read remaining bytes */
21727 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_LAST2 |
21728 - FIFOLD_TYPE_MSG | KEY_VLF);
21730 - /* Store class2 context bytes */
21731 - append_seq_store(desc, digestsize, LDST_CLASS_2_CCB |
21732 - LDST_SRCDST_BYTE_CONTEXT);
21736 - * For ahash update, final and finup, import context, read and write to seqout
21738 -static inline void ahash_ctx_data_to_out(u32 *desc, u32 op, u32 state,
21740 - struct caam_hash_ctx *ctx)
21742 - init_sh_desc_key_ahash(desc, ctx);
21744 - /* Import context from software */
21745 - append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
21746 - LDST_CLASS_2_CCB | ctx->ctx_len);
21748 - /* Class 2 operation */
21749 - append_operation(desc, op | state | OP_ALG_ENCRYPT);
21752 - * Load from buf and/or src and write to req->result or state->context
21754 - ahash_append_load_str(desc, digestsize);
21757 -/* For ahash firsts and digest, read and write to seqout */
21758 -static inline void ahash_data_to_out(u32 *desc, u32 op, u32 state,
21759 - int digestsize, struct caam_hash_ctx *ctx)
21761 - init_sh_desc_key_ahash(desc, ctx);
21763 - /* Class 2 operation */
21764 - append_operation(desc, op | state | OP_ALG_ENCRYPT);
21767 - * Load from buf and/or src and write to req->result or state->context
21769 - ahash_append_load_str(desc, digestsize);
21772 static int ahash_set_sh_desc(struct crypto_ahash *ahash)
21774 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
21775 int digestsize = crypto_ahash_digestsize(ahash);
21776 struct device *jrdev = ctx->jrdev;
21777 - u32 have_key = 0;
21778 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
21781 - if (ctx->split_key_len)
21782 - have_key = OP_ALG_AAI_HMAC_PRECOMP;
21783 + ctx->adata.key_virt = ctx->key;
21785 /* ahash_update shared descriptor */
21786 desc = ctx->sh_desc_update;
21788 - init_sh_desc(desc, HDR_SHARE_SERIAL);
21790 - /* Import context from software */
21791 - append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
21792 - LDST_CLASS_2_CCB | ctx->ctx_len);
21794 - /* Class 2 operation */
21795 - append_operation(desc, ctx->alg_type | OP_ALG_AS_UPDATE |
21798 - /* Load data and write to result or context */
21799 - ahash_append_load_str(desc, ctx->ctx_len);
21801 - ctx->sh_desc_update_dma = dma_map_single(jrdev, desc, desc_bytes(desc),
21803 - if (dma_mapping_error(jrdev, ctx->sh_desc_update_dma)) {
21804 - dev_err(jrdev, "unable to map shared descriptor\n");
21807 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_UPDATE, ctx->ctx_len,
21808 + ctx->ctx_len, true, ctrlpriv->era);
21809 + dma_sync_single_for_device(jrdev, ctx->sh_desc_update_dma,
21810 + desc_bytes(desc), DMA_TO_DEVICE);
21812 print_hex_dump(KERN_ERR,
21813 "ahash update shdesc@"__stringify(__LINE__)": ",
21814 @@ -350,17 +251,10 @@ static int ahash_set_sh_desc(struct cryp
21816 /* ahash_update_first shared descriptor */
21817 desc = ctx->sh_desc_update_first;
21819 - ahash_data_to_out(desc, have_key | ctx->alg_type, OP_ALG_AS_INIT,
21820 - ctx->ctx_len, ctx);
21822 - ctx->sh_desc_update_first_dma = dma_map_single(jrdev, desc,
21823 - desc_bytes(desc),
21825 - if (dma_mapping_error(jrdev, ctx->sh_desc_update_first_dma)) {
21826 - dev_err(jrdev, "unable to map shared descriptor\n");
21829 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INIT, ctx->ctx_len,
21830 + ctx->ctx_len, false, ctrlpriv->era);
21831 + dma_sync_single_for_device(jrdev, ctx->sh_desc_update_first_dma,
21832 + desc_bytes(desc), DMA_TO_DEVICE);
21834 print_hex_dump(KERN_ERR,
21835 "ahash update first shdesc@"__stringify(__LINE__)": ",
21836 @@ -369,53 +263,22 @@ static int ahash_set_sh_desc(struct cryp
21838 /* ahash_final shared descriptor */
21839 desc = ctx->sh_desc_fin;
21841 - ahash_ctx_data_to_out(desc, have_key | ctx->alg_type,
21842 - OP_ALG_AS_FINALIZE, digestsize, ctx);
21844 - ctx->sh_desc_fin_dma = dma_map_single(jrdev, desc, desc_bytes(desc),
21846 - if (dma_mapping_error(jrdev, ctx->sh_desc_fin_dma)) {
21847 - dev_err(jrdev, "unable to map shared descriptor\n");
21850 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_FINALIZE, digestsize,
21851 + ctx->ctx_len, true, ctrlpriv->era);
21852 + dma_sync_single_for_device(jrdev, ctx->sh_desc_fin_dma,
21853 + desc_bytes(desc), DMA_TO_DEVICE);
21855 print_hex_dump(KERN_ERR, "ahash final shdesc@"__stringify(__LINE__)": ",
21856 DUMP_PREFIX_ADDRESS, 16, 4, desc,
21857 desc_bytes(desc), 1);
21860 - /* ahash_finup shared descriptor */
21861 - desc = ctx->sh_desc_finup;
21863 - ahash_ctx_data_to_out(desc, have_key | ctx->alg_type,
21864 - OP_ALG_AS_FINALIZE, digestsize, ctx);
21866 - ctx->sh_desc_finup_dma = dma_map_single(jrdev, desc, desc_bytes(desc),
21868 - if (dma_mapping_error(jrdev, ctx->sh_desc_finup_dma)) {
21869 - dev_err(jrdev, "unable to map shared descriptor\n");
21873 - print_hex_dump(KERN_ERR, "ahash finup shdesc@"__stringify(__LINE__)": ",
21874 - DUMP_PREFIX_ADDRESS, 16, 4, desc,
21875 - desc_bytes(desc), 1);
21878 /* ahash_digest shared descriptor */
21879 desc = ctx->sh_desc_digest;
21881 - ahash_data_to_out(desc, have_key | ctx->alg_type, OP_ALG_AS_INITFINAL,
21882 - digestsize, ctx);
21884 - ctx->sh_desc_digest_dma = dma_map_single(jrdev, desc,
21885 - desc_bytes(desc),
21887 - if (dma_mapping_error(jrdev, ctx->sh_desc_digest_dma)) {
21888 - dev_err(jrdev, "unable to map shared descriptor\n");
21891 + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INITFINAL, digestsize,
21892 + ctx->ctx_len, false, ctrlpriv->era);
21893 + dma_sync_single_for_device(jrdev, ctx->sh_desc_digest_dma,
21894 + desc_bytes(desc), DMA_TO_DEVICE);
21896 print_hex_dump(KERN_ERR,
21897 "ahash digest shdesc@"__stringify(__LINE__)": ",
21898 @@ -426,14 +289,6 @@ static int ahash_set_sh_desc(struct cryp
21902 -static int gen_split_hash_key(struct caam_hash_ctx *ctx, const u8 *key_in,
21905 - return gen_split_key(ctx->jrdev, ctx->key, ctx->split_key_len,
21906 - ctx->split_key_pad_len, key_in, keylen,
21910 /* Digest hash size if it is too large */
21911 static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,
21912 u32 *keylen, u8 *key_out, u32 digestsize)
21913 @@ -469,7 +324,7 @@ static int hash_digest_key(struct caam_h
21916 /* Job descriptor to perform unkeyed hash on key_in */
21917 - append_operation(desc, ctx->alg_type | OP_ALG_ENCRYPT |
21918 + append_operation(desc, ctx->adata.algtype | OP_ALG_ENCRYPT |
21919 OP_ALG_AS_INITFINAL);
21920 append_seq_in_ptr(desc, src_dma, *keylen, 0);
21921 append_seq_fifo_load(desc, *keylen, FIFOLD_CLASS_CLASS2 |
21922 @@ -513,12 +368,10 @@ static int hash_digest_key(struct caam_h
21923 static int ahash_setkey(struct crypto_ahash *ahash,
21924 const u8 *key, unsigned int keylen)
21926 - /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */
21927 - static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 };
21928 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
21929 - struct device *jrdev = ctx->jrdev;
21930 int blocksize = crypto_tfm_alg_blocksize(&ahash->base);
21931 int digestsize = crypto_ahash_digestsize(ahash);
21932 + struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
21934 u8 *hashed_key = NULL;
21936 @@ -539,43 +392,29 @@ static int ahash_setkey(struct crypto_ah
21940 - /* Pick class 2 key length from algorithm submask */
21941 - ctx->split_key_len = mdpadlen[(ctx->alg_op & OP_ALG_ALGSEL_SUBMASK) >>
21942 - OP_ALG_ALGSEL_SHIFT] * 2;
21943 - ctx->split_key_pad_len = ALIGN(ctx->split_key_len, 16);
21946 - printk(KERN_ERR "split_key_len %d split_key_pad_len %d\n",
21947 - ctx->split_key_len, ctx->split_key_pad_len);
21948 - print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
21949 - DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
21952 + * If DKP is supported, use it in the shared descriptor to generate
21955 + if (ctrlpriv->era >= 6) {
21956 + ctx->adata.key_inline = true;
21957 + ctx->adata.keylen = keylen;
21958 + ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
21959 + OP_ALG_ALGSEL_MASK);
21961 - ret = gen_split_hash_key(ctx, key, keylen);
21963 - goto bad_free_key;
21964 + if (ctx->adata.keylen_pad > CAAM_MAX_HASH_KEY_SIZE)
21965 + goto bad_free_key;
21967 - ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len,
21969 - if (dma_mapping_error(jrdev, ctx->key_dma)) {
21970 - dev_err(jrdev, "unable to map key i/o memory\n");
21972 - goto error_free_key;
21973 + memcpy(ctx->key, key, keylen);
21975 + ret = gen_split_key(ctx->jrdev, ctx->key, &ctx->adata, key,
21976 + keylen, CAAM_MAX_HASH_KEY_SIZE);
21978 + goto bad_free_key;
21981 - print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
21982 - DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
21983 - ctx->split_key_pad_len, 1);
21986 - ret = ahash_set_sh_desc(ahash);
21988 - dma_unmap_single(jrdev, ctx->key_dma, ctx->split_key_pad_len,
21994 + return ahash_set_sh_desc(ahash);
21997 crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
21998 @@ -604,6 +443,8 @@ static inline void ahash_unmap(struct de
21999 struct ahash_edesc *edesc,
22000 struct ahash_request *req, int dst_len)
22002 + struct caam_hash_state *state = ahash_request_ctx(req);
22004 if (edesc->src_nents)
22005 dma_unmap_sg(dev, req->src, edesc->src_nents, DMA_TO_DEVICE);
22006 if (edesc->dst_dma)
22007 @@ -612,6 +453,12 @@ static inline void ahash_unmap(struct de
22008 if (edesc->sec4_sg_bytes)
22009 dma_unmap_single(dev, edesc->sec4_sg_dma,
22010 edesc->sec4_sg_bytes, DMA_TO_DEVICE);
22012 + if (state->buf_dma) {
22013 + dma_unmap_single(dev, state->buf_dma, *current_buflen(state),
22015 + state->buf_dma = 0;
22019 static inline void ahash_unmap_ctx(struct device *dev,
22020 @@ -643,8 +490,7 @@ static void ahash_done(struct device *jr
22021 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
22024 - edesc = (struct ahash_edesc *)((char *)desc -
22025 - offsetof(struct ahash_edesc, hw_desc));
22026 + edesc = container_of(desc, struct ahash_edesc, hw_desc[0]);
22028 caam_jr_strstatus(jrdev, err);
22030 @@ -671,19 +517,19 @@ static void ahash_done_bi(struct device
22031 struct ahash_edesc *edesc;
22032 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
22033 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22035 struct caam_hash_state *state = ahash_request_ctx(req);
22037 int digestsize = crypto_ahash_digestsize(ahash);
22039 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
22042 - edesc = (struct ahash_edesc *)((char *)desc -
22043 - offsetof(struct ahash_edesc, hw_desc));
22044 + edesc = container_of(desc, struct ahash_edesc, hw_desc[0]);
22046 caam_jr_strstatus(jrdev, err);
22048 ahash_unmap_ctx(jrdev, edesc, req, ctx->ctx_len, DMA_BIDIRECTIONAL);
22049 + switch_buf(state);
22053 @@ -713,8 +559,7 @@ static void ahash_done_ctx_src(struct de
22054 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
22057 - edesc = (struct ahash_edesc *)((char *)desc -
22058 - offsetof(struct ahash_edesc, hw_desc));
22059 + edesc = container_of(desc, struct ahash_edesc, hw_desc[0]);
22061 caam_jr_strstatus(jrdev, err);
22063 @@ -741,19 +586,19 @@ static void ahash_done_ctx_dst(struct de
22064 struct ahash_edesc *edesc;
22065 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
22066 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22068 struct caam_hash_state *state = ahash_request_ctx(req);
22070 int digestsize = crypto_ahash_digestsize(ahash);
22072 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
22075 - edesc = (struct ahash_edesc *)((char *)desc -
22076 - offsetof(struct ahash_edesc, hw_desc));
22077 + edesc = container_of(desc, struct ahash_edesc, hw_desc[0]);
22079 caam_jr_strstatus(jrdev, err);
22081 ahash_unmap_ctx(jrdev, edesc, req, ctx->ctx_len, DMA_FROM_DEVICE);
22082 + switch_buf(state);
22086 @@ -835,13 +680,12 @@ static int ahash_update_ctx(struct ahash
22087 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22088 struct caam_hash_state *state = ahash_request_ctx(req);
22089 struct device *jrdev = ctx->jrdev;
22090 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22091 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22092 - u8 *buf = state->current_buf ? state->buf_1 : state->buf_0;
22093 - int *buflen = state->current_buf ? &state->buflen_1 : &state->buflen_0;
22094 - u8 *next_buf = state->current_buf ? state->buf_0 : state->buf_1;
22095 - int *next_buflen = state->current_buf ? &state->buflen_0 :
22096 - &state->buflen_1, last_buflen;
22097 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22098 + GFP_KERNEL : GFP_ATOMIC;
22099 + u8 *buf = current_buf(state);
22100 + int *buflen = current_buflen(state);
22101 + u8 *next_buf = alt_buf(state);
22102 + int *next_buflen = alt_buflen(state), last_buflen;
22103 int in_len = *buflen + req->nbytes, to_hash;
22105 int src_nents, mapped_nents, sec4_sg_bytes, sec4_sg_src_index;
22106 @@ -890,15 +734,14 @@ static int ahash_update_ctx(struct ahash
22107 edesc->src_nents = src_nents;
22108 edesc->sec4_sg_bytes = sec4_sg_bytes;
22110 - ret = ctx_map_to_sec4_sg(desc, jrdev, state, ctx->ctx_len,
22111 + ret = ctx_map_to_sec4_sg(jrdev, state, ctx->ctx_len,
22112 edesc->sec4_sg, DMA_BIDIRECTIONAL);
22116 - state->buf_dma = try_buf_map_to_sec4_sg(jrdev,
22117 - edesc->sec4_sg + 1,
22118 - buf, state->buf_dma,
22119 - *buflen, last_buflen);
22120 + ret = buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1, state);
22124 if (mapped_nents) {
22125 sg_to_sec4_sg_last(req->src, mapped_nents,
22126 @@ -909,12 +752,10 @@ static int ahash_update_ctx(struct ahash
22130 - (edesc->sec4_sg + sec4_sg_src_index - 1)->len |=
22131 - cpu_to_caam32(SEC4_SG_LEN_FIN);
22132 + sg_to_sec4_set_last(edesc->sec4_sg + sec4_sg_src_index -
22136 - state->current_buf = !state->current_buf;
22138 desc = edesc->hw_desc;
22140 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
22141 @@ -969,12 +810,9 @@ static int ahash_final_ctx(struct ahash_
22142 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22143 struct caam_hash_state *state = ahash_request_ctx(req);
22144 struct device *jrdev = ctx->jrdev;
22145 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22146 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22147 - u8 *buf = state->current_buf ? state->buf_1 : state->buf_0;
22148 - int buflen = state->current_buf ? state->buflen_1 : state->buflen_0;
22149 - int last_buflen = state->current_buf ? state->buflen_0 :
22151 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22152 + GFP_KERNEL : GFP_ATOMIC;
22153 + int buflen = *current_buflen(state);
22155 int sec4_sg_bytes, sec4_sg_src_index;
22156 int digestsize = crypto_ahash_digestsize(ahash);
22157 @@ -994,18 +832,17 @@ static int ahash_final_ctx(struct ahash_
22158 desc = edesc->hw_desc;
22160 edesc->sec4_sg_bytes = sec4_sg_bytes;
22161 - edesc->src_nents = 0;
22163 - ret = ctx_map_to_sec4_sg(desc, jrdev, state, ctx->ctx_len,
22164 + ret = ctx_map_to_sec4_sg(jrdev, state, ctx->ctx_len,
22165 edesc->sec4_sg, DMA_TO_DEVICE);
22169 - state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1,
22170 - buf, state->buf_dma, buflen,
22172 - (edesc->sec4_sg + sec4_sg_src_index - 1)->len |=
22173 - cpu_to_caam32(SEC4_SG_LEN_FIN);
22174 + ret = buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1, state);
22178 + sg_to_sec4_set_last(edesc->sec4_sg + sec4_sg_src_index - 1);
22180 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
22181 sec4_sg_bytes, DMA_TO_DEVICE);
22182 @@ -1048,12 +885,9 @@ static int ahash_finup_ctx(struct ahash_
22183 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22184 struct caam_hash_state *state = ahash_request_ctx(req);
22185 struct device *jrdev = ctx->jrdev;
22186 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22187 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22188 - u8 *buf = state->current_buf ? state->buf_1 : state->buf_0;
22189 - int buflen = state->current_buf ? state->buflen_1 : state->buflen_0;
22190 - int last_buflen = state->current_buf ? state->buflen_0 :
22192 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22193 + GFP_KERNEL : GFP_ATOMIC;
22194 + int buflen = *current_buflen(state);
22196 int sec4_sg_src_index;
22197 int src_nents, mapped_nents;
22198 @@ -1082,7 +916,7 @@ static int ahash_finup_ctx(struct ahash_
22200 /* allocate space for base edesc and hw desc commands, link tables */
22201 edesc = ahash_edesc_alloc(ctx, sec4_sg_src_index + mapped_nents,
22202 - ctx->sh_desc_finup, ctx->sh_desc_finup_dma,
22203 + ctx->sh_desc_fin, ctx->sh_desc_fin_dma,
22206 dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
22207 @@ -1093,14 +927,14 @@ static int ahash_finup_ctx(struct ahash_
22209 edesc->src_nents = src_nents;
22211 - ret = ctx_map_to_sec4_sg(desc, jrdev, state, ctx->ctx_len,
22212 + ret = ctx_map_to_sec4_sg(jrdev, state, ctx->ctx_len,
22213 edesc->sec4_sg, DMA_TO_DEVICE);
22217 - state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1,
22218 - buf, state->buf_dma, buflen,
22220 + ret = buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1, state);
22224 ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents,
22225 sec4_sg_src_index, ctx->ctx_len + buflen,
22226 @@ -1136,15 +970,18 @@ static int ahash_digest(struct ahash_req
22228 struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
22229 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22230 + struct caam_hash_state *state = ahash_request_ctx(req);
22231 struct device *jrdev = ctx->jrdev;
22232 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22233 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22234 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22235 + GFP_KERNEL : GFP_ATOMIC;
22237 int digestsize = crypto_ahash_digestsize(ahash);
22238 int src_nents, mapped_nents;
22239 struct ahash_edesc *edesc;
22242 + state->buf_dma = 0;
22244 src_nents = sg_nents_for_len(req->src, req->nbytes);
22245 if (src_nents < 0) {
22246 dev_err(jrdev, "Invalid number of src SG.\n");
22247 @@ -1215,10 +1052,10 @@ static int ahash_final_no_ctx(struct aha
22248 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22249 struct caam_hash_state *state = ahash_request_ctx(req);
22250 struct device *jrdev = ctx->jrdev;
22251 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22252 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22253 - u8 *buf = state->current_buf ? state->buf_1 : state->buf_0;
22254 - int buflen = state->current_buf ? state->buflen_1 : state->buflen_0;
22255 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22256 + GFP_KERNEL : GFP_ATOMIC;
22257 + u8 *buf = current_buf(state);
22258 + int buflen = *current_buflen(state);
22260 int digestsize = crypto_ahash_digestsize(ahash);
22261 struct ahash_edesc *edesc;
22262 @@ -1246,7 +1083,6 @@ static int ahash_final_no_ctx(struct aha
22263 dev_err(jrdev, "unable to map dst\n");
22266 - edesc->src_nents = 0;
22269 print_hex_dump(KERN_ERR, "jobdesc@"__stringify(__LINE__)": ",
22270 @@ -1276,13 +1112,12 @@ static int ahash_update_no_ctx(struct ah
22271 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22272 struct caam_hash_state *state = ahash_request_ctx(req);
22273 struct device *jrdev = ctx->jrdev;
22274 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22275 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22276 - u8 *buf = state->current_buf ? state->buf_1 : state->buf_0;
22277 - int *buflen = state->current_buf ? &state->buflen_1 : &state->buflen_0;
22278 - u8 *next_buf = state->current_buf ? state->buf_0 : state->buf_1;
22279 - int *next_buflen = state->current_buf ? &state->buflen_0 :
22280 - &state->buflen_1;
22281 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22282 + GFP_KERNEL : GFP_ATOMIC;
22283 + u8 *buf = current_buf(state);
22284 + int *buflen = current_buflen(state);
22285 + u8 *next_buf = alt_buf(state);
22286 + int *next_buflen = alt_buflen(state);
22287 int in_len = *buflen + req->nbytes, to_hash;
22288 int sec4_sg_bytes, src_nents, mapped_nents;
22289 struct ahash_edesc *edesc;
22290 @@ -1329,10 +1164,11 @@ static int ahash_update_no_ctx(struct ah
22292 edesc->src_nents = src_nents;
22293 edesc->sec4_sg_bytes = sec4_sg_bytes;
22294 - edesc->dst_dma = 0;
22296 - state->buf_dma = buf_map_to_sec4_sg(jrdev, edesc->sec4_sg,
22298 + ret = buf_map_to_sec4_sg(jrdev, edesc->sec4_sg, state);
22302 sg_to_sec4_sg_last(req->src, mapped_nents,
22303 edesc->sec4_sg + 1, 0);
22305 @@ -1342,8 +1178,6 @@ static int ahash_update_no_ctx(struct ah
22309 - state->current_buf = !state->current_buf;
22311 desc = edesc->hw_desc;
22313 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
22314 @@ -1403,12 +1237,9 @@ static int ahash_finup_no_ctx(struct aha
22315 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22316 struct caam_hash_state *state = ahash_request_ctx(req);
22317 struct device *jrdev = ctx->jrdev;
22318 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22319 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22320 - u8 *buf = state->current_buf ? state->buf_1 : state->buf_0;
22321 - int buflen = state->current_buf ? state->buflen_1 : state->buflen_0;
22322 - int last_buflen = state->current_buf ? state->buflen_0 :
22324 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22325 + GFP_KERNEL : GFP_ATOMIC;
22326 + int buflen = *current_buflen(state);
22328 int sec4_sg_bytes, sec4_sg_src_index, src_nents, mapped_nents;
22329 int digestsize = crypto_ahash_digestsize(ahash);
22330 @@ -1450,9 +1281,9 @@ static int ahash_finup_no_ctx(struct aha
22331 edesc->src_nents = src_nents;
22332 edesc->sec4_sg_bytes = sec4_sg_bytes;
22334 - state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg, buf,
22335 - state->buf_dma, buflen,
22337 + ret = buf_map_to_sec4_sg(jrdev, edesc->sec4_sg, state);
22341 ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, 1, buflen,
22343 @@ -1496,11 +1327,10 @@ static int ahash_update_first(struct aha
22344 struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
22345 struct caam_hash_state *state = ahash_request_ctx(req);
22346 struct device *jrdev = ctx->jrdev;
22347 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22348 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22349 - u8 *next_buf = state->current_buf ? state->buf_1 : state->buf_0;
22350 - int *next_buflen = state->current_buf ?
22351 - &state->buflen_1 : &state->buflen_0;
22352 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22353 + GFP_KERNEL : GFP_ATOMIC;
22354 + u8 *next_buf = alt_buf(state);
22355 + int *next_buflen = alt_buflen(state);
22358 int src_nents, mapped_nents;
22359 @@ -1545,7 +1375,6 @@ static int ahash_update_first(struct aha
22362 edesc->src_nents = src_nents;
22363 - edesc->dst_dma = 0;
22365 ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, 0, 0,
22367 @@ -1582,6 +1411,7 @@ static int ahash_update_first(struct aha
22368 state->final = ahash_final_no_ctx;
22369 scatterwalk_map_and_copy(next_buf, req->src, 0,
22371 + switch_buf(state);
22374 print_hex_dump(KERN_ERR, "next buf@"__stringify(__LINE__)": ",
22375 @@ -1688,7 +1518,6 @@ struct caam_hash_template {
22376 unsigned int blocksize;
22377 struct ahash_alg template_ahash;
22382 /* ahash descriptors */
22383 @@ -1714,7 +1543,6 @@ static struct caam_hash_template driver_
22386 .alg_type = OP_ALG_ALGSEL_SHA1,
22387 - .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
22390 .driver_name = "sha224-caam",
22391 @@ -1736,7 +1564,6 @@ static struct caam_hash_template driver_
22394 .alg_type = OP_ALG_ALGSEL_SHA224,
22395 - .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
22398 .driver_name = "sha256-caam",
22399 @@ -1758,7 +1585,6 @@ static struct caam_hash_template driver_
22402 .alg_type = OP_ALG_ALGSEL_SHA256,
22403 - .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
22406 .driver_name = "sha384-caam",
22407 @@ -1780,7 +1606,6 @@ static struct caam_hash_template driver_
22410 .alg_type = OP_ALG_ALGSEL_SHA384,
22411 - .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
22414 .driver_name = "sha512-caam",
22415 @@ -1802,7 +1627,6 @@ static struct caam_hash_template driver_
22418 .alg_type = OP_ALG_ALGSEL_SHA512,
22419 - .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
22422 .driver_name = "md5-caam",
22423 @@ -1824,14 +1648,12 @@ static struct caam_hash_template driver_
22426 .alg_type = OP_ALG_ALGSEL_MD5,
22427 - .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
22431 struct caam_hash_alg {
22432 struct list_head entry;
22435 struct ahash_alg ahash_alg;
22438 @@ -1853,6 +1675,7 @@ static int caam_hash_cra_init(struct cry
22439 HASH_MSG_LEN + SHA256_DIGEST_SIZE,
22441 HASH_MSG_LEN + SHA512_DIGEST_SIZE };
22442 + dma_addr_t dma_addr;
22445 * Get a Job ring from Job Ring driver to ensure in-order
22446 @@ -1863,11 +1686,31 @@ static int caam_hash_cra_init(struct cry
22447 pr_err("Job Ring Device allocation for transform failed\n");
22448 return PTR_ERR(ctx->jrdev);
22451 + dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_update,
22452 + offsetof(struct caam_hash_ctx,
22453 + sh_desc_update_dma),
22454 + DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
22455 + if (dma_mapping_error(ctx->jrdev, dma_addr)) {
22456 + dev_err(ctx->jrdev, "unable to map shared descriptors\n");
22457 + caam_jr_free(ctx->jrdev);
22461 + ctx->sh_desc_update_dma = dma_addr;
22462 + ctx->sh_desc_update_first_dma = dma_addr +
22463 + offsetof(struct caam_hash_ctx,
22464 + sh_desc_update_first);
22465 + ctx->sh_desc_fin_dma = dma_addr + offsetof(struct caam_hash_ctx,
22467 + ctx->sh_desc_digest_dma = dma_addr + offsetof(struct caam_hash_ctx,
22470 /* copy descriptor header template value */
22471 - ctx->alg_type = OP_TYPE_CLASS2_ALG | caam_hash->alg_type;
22472 - ctx->alg_op = OP_TYPE_CLASS2_ALG | caam_hash->alg_op;
22473 + ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam_hash->alg_type;
22475 - ctx->ctx_len = runninglen[(ctx->alg_op & OP_ALG_ALGSEL_SUBMASK) >>
22476 + ctx->ctx_len = runninglen[(ctx->adata.algtype &
22477 + OP_ALG_ALGSEL_SUBMASK) >>
22478 OP_ALG_ALGSEL_SHIFT];
22480 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
22481 @@ -1879,30 +1722,10 @@ static void caam_hash_cra_exit(struct cr
22483 struct caam_hash_ctx *ctx = crypto_tfm_ctx(tfm);
22485 - if (ctx->sh_desc_update_dma &&
22486 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_update_dma))
22487 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_update_dma,
22488 - desc_bytes(ctx->sh_desc_update),
22490 - if (ctx->sh_desc_update_first_dma &&
22491 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_update_first_dma))
22492 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_update_first_dma,
22493 - desc_bytes(ctx->sh_desc_update_first),
22495 - if (ctx->sh_desc_fin_dma &&
22496 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_fin_dma))
22497 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_fin_dma,
22498 - desc_bytes(ctx->sh_desc_fin), DMA_TO_DEVICE);
22499 - if (ctx->sh_desc_digest_dma &&
22500 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_digest_dma))
22501 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_digest_dma,
22502 - desc_bytes(ctx->sh_desc_digest),
22504 - if (ctx->sh_desc_finup_dma &&
22505 - !dma_mapping_error(ctx->jrdev, ctx->sh_desc_finup_dma))
22506 - dma_unmap_single(ctx->jrdev, ctx->sh_desc_finup_dma,
22507 - desc_bytes(ctx->sh_desc_finup), DMA_TO_DEVICE);
22509 + dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_update_dma,
22510 + offsetof(struct caam_hash_ctx,
22511 + sh_desc_update_dma),
22512 + DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
22513 caam_jr_free(ctx->jrdev);
22516 @@ -1961,7 +1784,6 @@ caam_hash_alloc(struct caam_hash_templat
22517 alg->cra_type = &crypto_ahash_type;
22519 t_alg->alg_type = template->alg_type;
22520 - t_alg->alg_op = template->alg_op;
22525 +++ b/drivers/crypto/caam/caamhash_desc.c
22528 + * Shared descriptors for ahash algorithms
22530 + * Copyright 2017 NXP
22532 + * Redistribution and use in source and binary forms, with or without
22533 + * modification, are permitted provided that the following conditions are met:
22534 + * * Redistributions of source code must retain the above copyright
22535 + * notice, this list of conditions and the following disclaimer.
22536 + * * Redistributions in binary form must reproduce the above copyright
22537 + * notice, this list of conditions and the following disclaimer in the
22538 + * documentation and/or other materials provided with the distribution.
22539 + * * Neither the names of the above-listed copyright holders nor the
22540 + * names of any contributors may be used to endorse or promote products
22541 + * derived from this software without specific prior written permission.
22544 + * ALTERNATIVELY, this software may be distributed under the terms of the
22545 + * GNU General Public License ("GPL") as published by the Free Software
22546 + * Foundation, either version 2 of that License or (at your option) any
22549 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22550 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22551 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22552 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22553 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22554 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22555 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22556 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22557 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22558 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22559 + * POSSIBILITY OF SUCH DAMAGE.
22562 +#include "compat.h"
22563 +#include "desc_constr.h"
22564 +#include "caamhash_desc.h"
22567 + * cnstr_shdsc_ahash - ahash shared descriptor
22568 + * @desc: pointer to buffer used for descriptor construction
22569 + * @adata: pointer to authentication transform definitions.
22570 + * A split key is required for SEC Era < 6; the size of the split key
22571 + * is specified in this case.
22572 + * Valid algorithm values - one of OP_ALG_ALGSEL_{MD5, SHA1, SHA224,
22573 + * SHA256, SHA384, SHA512}.
22574 + * @state: algorithm state OP_ALG_AS_{INIT, FINALIZE, INITFINALIZE, UPDATE}
22575 + * @digestsize: algorithm's digest size
22576 + * @ctx_len: size of Context Register
22577 + * @import_ctx: true if previous Context Register needs to be restored
22578 + * must be true for ahash update and final
22579 + * must be false for for ahash first and digest
22582 +void cnstr_shdsc_ahash(u32 * const desc, struct alginfo *adata, u32 state,
22583 + int digestsize, int ctx_len, bool import_ctx, int era)
22585 + u32 op = adata->algtype;
22587 + init_sh_desc(desc, HDR_SHARE_SERIAL);
22589 + /* Append key if it has been set; ahash update excluded */
22590 + if (state != OP_ALG_AS_UPDATE && adata->keylen) {
22591 + u32 *skip_key_load;
22593 + /* Skip key loading if already shared */
22594 + skip_key_load = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
22598 + append_key_as_imm(desc, adata->key_virt,
22599 + adata->keylen_pad,
22600 + adata->keylen, CLASS_2 |
22601 + KEY_DEST_MDHA_SPLIT | KEY_ENC);
22603 + append_proto_dkp(desc, adata);
22605 + set_jump_tgt_here(desc, skip_key_load);
22607 + op |= OP_ALG_AAI_HMAC_PRECOMP;
22610 + /* If needed, import context from software */
22612 + append_seq_load(desc, ctx_len, LDST_CLASS_2_CCB |
22613 + LDST_SRCDST_BYTE_CONTEXT);
22615 + /* Class 2 operation */
22616 + append_operation(desc, op | state | OP_ALG_ENCRYPT);
22619 + * Load from buf and/or src and write to req->result or state->context
22620 + * Calculate remaining bytes to read
22622 + append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
22623 + /* Read remaining bytes */
22624 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_LAST2 |
22625 + FIFOLD_TYPE_MSG | KEY_VLF);
22626 + /* Store class2 context bytes */
22627 + append_seq_store(desc, digestsize, LDST_CLASS_2_CCB |
22628 + LDST_SRCDST_BYTE_CONTEXT);
22630 +EXPORT_SYMBOL(cnstr_shdsc_ahash);
22632 +MODULE_LICENSE("Dual BSD/GPL");
22633 +MODULE_DESCRIPTION("FSL CAAM ahash descriptors support");
22634 +MODULE_AUTHOR("NXP Semiconductors");
22636 +++ b/drivers/crypto/caam/caamhash_desc.h
22639 + * Shared descriptors for ahash algorithms
22641 + * Copyright 2017 NXP
22643 + * Redistribution and use in source and binary forms, with or without
22644 + * modification, are permitted provided that the following conditions are met:
22645 + * * Redistributions of source code must retain the above copyright
22646 + * notice, this list of conditions and the following disclaimer.
22647 + * * Redistributions in binary form must reproduce the above copyright
22648 + * notice, this list of conditions and the following disclaimer in the
22649 + * documentation and/or other materials provided with the distribution.
22650 + * * Neither the names of the above-listed copyright holders nor the
22651 + * names of any contributors may be used to endorse or promote products
22652 + * derived from this software without specific prior written permission.
22655 + * ALTERNATIVELY, this software may be distributed under the terms of the
22656 + * GNU General Public License ("GPL") as published by the Free Software
22657 + * Foundation, either version 2 of that License or (at your option) any
22660 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22661 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22662 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22663 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22664 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22665 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22666 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22667 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22668 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22669 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22670 + * POSSIBILITY OF SUCH DAMAGE.
22673 +#ifndef _CAAMHASH_DESC_H_
22674 +#define _CAAMHASH_DESC_H_
22676 +/* length of descriptors text */
22677 +#define DESC_AHASH_BASE (3 * CAAM_CMD_SZ)
22678 +#define DESC_AHASH_UPDATE_LEN (6 * CAAM_CMD_SZ)
22679 +#define DESC_AHASH_UPDATE_FIRST_LEN (DESC_AHASH_BASE + 4 * CAAM_CMD_SZ)
22680 +#define DESC_AHASH_FINAL_LEN (DESC_AHASH_BASE + 5 * CAAM_CMD_SZ)
22681 +#define DESC_AHASH_DIGEST_LEN (DESC_AHASH_BASE + 4 * CAAM_CMD_SZ)
22683 +void cnstr_shdsc_ahash(u32 * const desc, struct alginfo *adata, u32 state,
22684 + int digestsize, int ctx_len, bool import_ctx, int era);
22686 +#endif /* _CAAMHASH_DESC_H_ */
22687 --- a/drivers/crypto/caam/caampkc.c
22688 +++ b/drivers/crypto/caam/caampkc.c
22690 #define DESC_RSA_PUB_LEN (2 * CAAM_CMD_SZ + sizeof(struct rsa_pub_pdb))
22691 #define DESC_RSA_PRIV_F1_LEN (2 * CAAM_CMD_SZ + \
22692 sizeof(struct rsa_priv_f1_pdb))
22693 +#define DESC_RSA_PRIV_F2_LEN (2 * CAAM_CMD_SZ + \
22694 + sizeof(struct rsa_priv_f2_pdb))
22695 +#define DESC_RSA_PRIV_F3_LEN (2 * CAAM_CMD_SZ + \
22696 + sizeof(struct rsa_priv_f3_pdb))
22698 static void rsa_io_unmap(struct device *dev, struct rsa_edesc *edesc,
22699 struct akcipher_request *req)
22700 @@ -54,6 +58,42 @@ static void rsa_priv_f1_unmap(struct dev
22701 dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
22704 +static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc *edesc,
22705 + struct akcipher_request *req)
22707 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
22708 + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
22709 + struct caam_rsa_key *key = &ctx->key;
22710 + struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
22711 + size_t p_sz = key->p_sz;
22712 + size_t q_sz = key->p_sz;
22714 + dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
22715 + dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
22716 + dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
22717 + dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE);
22718 + dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_TO_DEVICE);
22721 +static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc,
22722 + struct akcipher_request *req)
22724 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
22725 + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
22726 + struct caam_rsa_key *key = &ctx->key;
22727 + struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
22728 + size_t p_sz = key->p_sz;
22729 + size_t q_sz = key->p_sz;
22731 + dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
22732 + dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
22733 + dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE);
22734 + dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE);
22735 + dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
22736 + dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE);
22737 + dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_TO_DEVICE);
22740 /* RSA Job Completion handler */
22741 static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context)
22743 @@ -90,6 +130,42 @@ static void rsa_priv_f1_done(struct devi
22744 akcipher_request_complete(req, err);
22747 +static void rsa_priv_f2_done(struct device *dev, u32 *desc, u32 err,
22750 + struct akcipher_request *req = context;
22751 + struct rsa_edesc *edesc;
22754 + caam_jr_strstatus(dev, err);
22756 + edesc = container_of(desc, struct rsa_edesc, hw_desc[0]);
22758 + rsa_priv_f2_unmap(dev, edesc, req);
22759 + rsa_io_unmap(dev, edesc, req);
22762 + akcipher_request_complete(req, err);
22765 +static void rsa_priv_f3_done(struct device *dev, u32 *desc, u32 err,
22768 + struct akcipher_request *req = context;
22769 + struct rsa_edesc *edesc;
22772 + caam_jr_strstatus(dev, err);
22774 + edesc = container_of(desc, struct rsa_edesc, hw_desc[0]);
22776 + rsa_priv_f3_unmap(dev, edesc, req);
22777 + rsa_io_unmap(dev, edesc, req);
22780 + akcipher_request_complete(req, err);
22783 static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
22786 @@ -97,8 +173,8 @@ static struct rsa_edesc *rsa_edesc_alloc
22787 struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
22788 struct device *dev = ctx->dev;
22789 struct rsa_edesc *edesc;
22790 - gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
22791 - CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
22792 + gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
22793 + GFP_KERNEL : GFP_ATOMIC;
22795 int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
22796 int src_nents, dst_nents;
22797 @@ -258,6 +334,172 @@ static int set_rsa_priv_f1_pdb(struct ak
22801 +static int set_rsa_priv_f2_pdb(struct akcipher_request *req,
22802 + struct rsa_edesc *edesc)
22804 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
22805 + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
22806 + struct caam_rsa_key *key = &ctx->key;
22807 + struct device *dev = ctx->dev;
22808 + struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
22809 + int sec4_sg_index = 0;
22810 + size_t p_sz = key->p_sz;
22811 + size_t q_sz = key->p_sz;
22813 + pdb->d_dma = dma_map_single(dev, key->d, key->d_sz, DMA_TO_DEVICE);
22814 + if (dma_mapping_error(dev, pdb->d_dma)) {
22815 + dev_err(dev, "Unable to map RSA private exponent memory\n");
22819 + pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE);
22820 + if (dma_mapping_error(dev, pdb->p_dma)) {
22821 + dev_err(dev, "Unable to map RSA prime factor p memory\n");
22825 + pdb->q_dma = dma_map_single(dev, key->q, q_sz, DMA_TO_DEVICE);
22826 + if (dma_mapping_error(dev, pdb->q_dma)) {
22827 + dev_err(dev, "Unable to map RSA prime factor q memory\n");
22831 + pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_TO_DEVICE);
22832 + if (dma_mapping_error(dev, pdb->tmp1_dma)) {
22833 + dev_err(dev, "Unable to map RSA tmp1 memory\n");
22837 + pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_TO_DEVICE);
22838 + if (dma_mapping_error(dev, pdb->tmp2_dma)) {
22839 + dev_err(dev, "Unable to map RSA tmp2 memory\n");
22843 + if (edesc->src_nents > 1) {
22844 + pdb->sgf |= RSA_PRIV_PDB_SGF_G;
22845 + pdb->g_dma = edesc->sec4_sg_dma;
22846 + sec4_sg_index += edesc->src_nents;
22848 + pdb->g_dma = sg_dma_address(req->src);
22851 + if (edesc->dst_nents > 1) {
22852 + pdb->sgf |= RSA_PRIV_PDB_SGF_F;
22853 + pdb->f_dma = edesc->sec4_sg_dma +
22854 + sec4_sg_index * sizeof(struct sec4_sg_entry);
22856 + pdb->f_dma = sg_dma_address(req->dst);
22859 + pdb->sgf |= (key->d_sz << RSA_PDB_D_SHIFT) | key->n_sz;
22860 + pdb->p_q_len = (q_sz << RSA_PDB_Q_SHIFT) | p_sz;
22865 + dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE);
22867 + dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
22869 + dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
22871 + dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
22876 +static int set_rsa_priv_f3_pdb(struct akcipher_request *req,
22877 + struct rsa_edesc *edesc)
22879 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
22880 + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
22881 + struct caam_rsa_key *key = &ctx->key;
22882 + struct device *dev = ctx->dev;
22883 + struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
22884 + int sec4_sg_index = 0;
22885 + size_t p_sz = key->p_sz;
22886 + size_t q_sz = key->p_sz;
22888 + pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE);
22889 + if (dma_mapping_error(dev, pdb->p_dma)) {
22890 + dev_err(dev, "Unable to map RSA prime factor p memory\n");
22894 + pdb->q_dma = dma_map_single(dev, key->q, q_sz, DMA_TO_DEVICE);
22895 + if (dma_mapping_error(dev, pdb->q_dma)) {
22896 + dev_err(dev, "Unable to map RSA prime factor q memory\n");
22900 + pdb->dp_dma = dma_map_single(dev, key->dp, p_sz, DMA_TO_DEVICE);
22901 + if (dma_mapping_error(dev, pdb->dp_dma)) {
22902 + dev_err(dev, "Unable to map RSA exponent dp memory\n");
22906 + pdb->dq_dma = dma_map_single(dev, key->dq, q_sz, DMA_TO_DEVICE);
22907 + if (dma_mapping_error(dev, pdb->dq_dma)) {
22908 + dev_err(dev, "Unable to map RSA exponent dq memory\n");
22912 + pdb->c_dma = dma_map_single(dev, key->qinv, p_sz, DMA_TO_DEVICE);
22913 + if (dma_mapping_error(dev, pdb->c_dma)) {
22914 + dev_err(dev, "Unable to map RSA CRT coefficient qinv memory\n");
22918 + pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_TO_DEVICE);
22919 + if (dma_mapping_error(dev, pdb->tmp1_dma)) {
22920 + dev_err(dev, "Unable to map RSA tmp1 memory\n");
22924 + pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_TO_DEVICE);
22925 + if (dma_mapping_error(dev, pdb->tmp2_dma)) {
22926 + dev_err(dev, "Unable to map RSA tmp2 memory\n");
22930 + if (edesc->src_nents > 1) {
22931 + pdb->sgf |= RSA_PRIV_PDB_SGF_G;
22932 + pdb->g_dma = edesc->sec4_sg_dma;
22933 + sec4_sg_index += edesc->src_nents;
22935 + pdb->g_dma = sg_dma_address(req->src);
22938 + if (edesc->dst_nents > 1) {
22939 + pdb->sgf |= RSA_PRIV_PDB_SGF_F;
22940 + pdb->f_dma = edesc->sec4_sg_dma +
22941 + sec4_sg_index * sizeof(struct sec4_sg_entry);
22943 + pdb->f_dma = sg_dma_address(req->dst);
22946 + pdb->sgf |= key->n_sz;
22947 + pdb->p_q_len = (q_sz << RSA_PDB_Q_SHIFT) | p_sz;
22952 + dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE);
22954 + dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
22956 + dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE);
22958 + dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE);
22960 + dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
22962 + dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
22967 static int caam_rsa_enc(struct akcipher_request *req)
22969 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
22970 @@ -301,24 +543,14 @@ init_fail:
22974 -static int caam_rsa_dec(struct akcipher_request *req)
22975 +static int caam_rsa_dec_priv_f1(struct akcipher_request *req)
22977 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
22978 struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
22979 - struct caam_rsa_key *key = &ctx->key;
22980 struct device *jrdev = ctx->dev;
22981 struct rsa_edesc *edesc;
22984 - if (unlikely(!key->n || !key->d))
22987 - if (req->dst_len < key->n_sz) {
22988 - req->dst_len = key->n_sz;
22989 - dev_err(jrdev, "Output buffer length less than parameter n\n");
22990 - return -EOVERFLOW;
22993 /* Allocate extended descriptor */
22994 edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F1_LEN);
22996 @@ -344,17 +576,147 @@ init_fail:
23000 +static int caam_rsa_dec_priv_f2(struct akcipher_request *req)
23002 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
23003 + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
23004 + struct device *jrdev = ctx->dev;
23005 + struct rsa_edesc *edesc;
23008 + /* Allocate extended descriptor */
23009 + edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F2_LEN);
23010 + if (IS_ERR(edesc))
23011 + return PTR_ERR(edesc);
23013 + /* Set RSA Decrypt Protocol Data Block - Private Key Form #2 */
23014 + ret = set_rsa_priv_f2_pdb(req, edesc);
23018 + /* Initialize Job Descriptor */
23019 + init_rsa_priv_f2_desc(edesc->hw_desc, &edesc->pdb.priv_f2);
23021 + ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f2_done, req);
23023 + return -EINPROGRESS;
23025 + rsa_priv_f2_unmap(jrdev, edesc, req);
23028 + rsa_io_unmap(jrdev, edesc, req);
23033 +static int caam_rsa_dec_priv_f3(struct akcipher_request *req)
23035 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
23036 + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
23037 + struct device *jrdev = ctx->dev;
23038 + struct rsa_edesc *edesc;
23041 + /* Allocate extended descriptor */
23042 + edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F3_LEN);
23043 + if (IS_ERR(edesc))
23044 + return PTR_ERR(edesc);
23046 + /* Set RSA Decrypt Protocol Data Block - Private Key Form #3 */
23047 + ret = set_rsa_priv_f3_pdb(req, edesc);
23051 + /* Initialize Job Descriptor */
23052 + init_rsa_priv_f3_desc(edesc->hw_desc, &edesc->pdb.priv_f3);
23054 + ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f3_done, req);
23056 + return -EINPROGRESS;
23058 + rsa_priv_f3_unmap(jrdev, edesc, req);
23061 + rsa_io_unmap(jrdev, edesc, req);
23066 +static int caam_rsa_dec(struct akcipher_request *req)
23068 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
23069 + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
23070 + struct caam_rsa_key *key = &ctx->key;
23073 + if (unlikely(!key->n || !key->d))
23076 + if (req->dst_len < key->n_sz) {
23077 + req->dst_len = key->n_sz;
23078 + dev_err(ctx->dev, "Output buffer length less than parameter n\n");
23079 + return -EOVERFLOW;
23082 + if (key->priv_form == FORM3)
23083 + ret = caam_rsa_dec_priv_f3(req);
23084 + else if (key->priv_form == FORM2)
23085 + ret = caam_rsa_dec_priv_f2(req);
23087 + ret = caam_rsa_dec_priv_f1(req);
23092 static void caam_rsa_free_key(struct caam_rsa_key *key)
23099 + kzfree(key->qinv);
23100 + kzfree(key->tmp1);
23101 + kzfree(key->tmp2);
23110 + memset(key, 0, sizeof(*key));
23113 +static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
23115 + while (!**ptr && *nbytes) {
23122 + * caam_read_rsa_crt - Used for reading dP, dQ, qInv CRT members.
23123 + * dP, dQ and qInv could decode to less than corresponding p, q length, as the
23124 + * BER-encoding requires that the minimum number of bytes be used to encode the
23125 + * integer. dP, dQ, qInv decoded values have to be zero-padded to appropriate
23128 + * @ptr : pointer to {dP, dQ, qInv} CRT member
23129 + * @nbytes: length in bytes of {dP, dQ, qInv} CRT member
23130 + * @dstlen: length in bytes of corresponding p or q prime factor
23132 +static u8 *caam_read_rsa_crt(const u8 *ptr, size_t nbytes, size_t dstlen)
23136 + caam_rsa_drop_leading_zeros(&ptr, &nbytes);
23140 + dst = kzalloc(dstlen, GFP_DMA | GFP_KERNEL);
23144 + memcpy(dst + (dstlen - nbytes), ptr, nbytes);
23150 @@ -370,10 +732,9 @@ static inline u8 *caam_read_raw_data(con
23154 - while (!*buf && *nbytes) {
23158 + caam_rsa_drop_leading_zeros(&buf, nbytes);
23162 val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL);
23164 @@ -395,7 +756,7 @@ static int caam_rsa_set_pub_key(struct c
23165 unsigned int keylen)
23167 struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
23168 - struct rsa_key raw_key = {0};
23169 + struct rsa_key raw_key = {NULL};
23170 struct caam_rsa_key *rsa_key = &ctx->key;
23173 @@ -437,11 +798,69 @@ err:
23177 +static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
23178 + struct rsa_key *raw_key)
23180 + struct caam_rsa_key *rsa_key = &ctx->key;
23181 + size_t p_sz = raw_key->p_sz;
23182 + size_t q_sz = raw_key->q_sz;
23184 + rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz);
23187 + rsa_key->p_sz = p_sz;
23189 + rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz);
23192 + rsa_key->q_sz = q_sz;
23194 + rsa_key->tmp1 = kzalloc(raw_key->p_sz, GFP_DMA | GFP_KERNEL);
23195 + if (!rsa_key->tmp1)
23198 + rsa_key->tmp2 = kzalloc(raw_key->q_sz, GFP_DMA | GFP_KERNEL);
23199 + if (!rsa_key->tmp2)
23202 + rsa_key->priv_form = FORM2;
23204 + rsa_key->dp = caam_read_rsa_crt(raw_key->dp, raw_key->dp_sz, p_sz);
23205 + if (!rsa_key->dp)
23208 + rsa_key->dq = caam_read_rsa_crt(raw_key->dq, raw_key->dq_sz, q_sz);
23209 + if (!rsa_key->dq)
23212 + rsa_key->qinv = caam_read_rsa_crt(raw_key->qinv, raw_key->qinv_sz,
23214 + if (!rsa_key->qinv)
23217 + rsa_key->priv_form = FORM3;
23222 + kzfree(rsa_key->dq);
23224 + kzfree(rsa_key->dp);
23226 + kzfree(rsa_key->tmp2);
23228 + kzfree(rsa_key->tmp1);
23230 + kzfree(rsa_key->q);
23232 + kzfree(rsa_key->p);
23235 static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
23236 unsigned int keylen)
23238 struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
23239 - struct rsa_key raw_key = {0};
23240 + struct rsa_key raw_key = {NULL};
23241 struct caam_rsa_key *rsa_key = &ctx->key;
23244 @@ -483,6 +902,8 @@ static int caam_rsa_set_priv_key(struct
23245 memcpy(rsa_key->d, raw_key.d, raw_key.d_sz);
23246 memcpy(rsa_key->e, raw_key.e, raw_key.e_sz);
23248 + caam_rsa_set_priv_key_form(ctx, &raw_key);
23253 --- a/drivers/crypto/caam/caampkc.h
23254 +++ b/drivers/crypto/caam/caampkc.h
23255 @@ -13,21 +13,75 @@
23259 + * caam_priv_key_form - CAAM RSA private key representation
23260 + * CAAM RSA private key may have either of three forms.
23262 + * 1. The first representation consists of the pair (n, d), where the
23263 + * components have the following meanings:
23264 + * n the RSA modulus
23265 + * d the RSA private exponent
23267 + * 2. The second representation consists of the triplet (p, q, d), where the
23268 + * components have the following meanings:
23269 + * p the first prime factor of the RSA modulus n
23270 + * q the second prime factor of the RSA modulus n
23271 + * d the RSA private exponent
23273 + * 3. The third representation consists of the quintuple (p, q, dP, dQ, qInv),
23274 + * where the components have the following meanings:
23275 + * p the first prime factor of the RSA modulus n
23276 + * q the second prime factor of the RSA modulus n
23277 + * dP the first factors's CRT exponent
23278 + * dQ the second factors's CRT exponent
23279 + * qInv the (first) CRT coefficient
23281 + * The benefit of using the third or the second key form is lower computational
23282 + * cost for the decryption and signature operations.
23284 +enum caam_priv_key_form {
23291 * caam_rsa_key - CAAM RSA key structure. Keys are allocated in DMA zone.
23292 * @n : RSA modulus raw byte stream
23293 * @e : RSA public exponent raw byte stream
23294 * @d : RSA private exponent raw byte stream
23295 + * @p : RSA prime factor p of RSA modulus n
23296 + * @q : RSA prime factor q of RSA modulus n
23297 + * @dp : RSA CRT exponent of p
23298 + * @dp : RSA CRT exponent of q
23299 + * @qinv : RSA CRT coefficient
23300 + * @tmp1 : CAAM uses this temporary buffer as internal state buffer.
23301 + * It is assumed to be as long as p.
23302 + * @tmp2 : CAAM uses this temporary buffer as internal state buffer.
23303 + * It is assumed to be as long as q.
23304 * @n_sz : length in bytes of RSA modulus n
23305 * @e_sz : length in bytes of RSA public exponent
23306 * @d_sz : length in bytes of RSA private exponent
23307 + * @p_sz : length in bytes of RSA prime factor p of RSA modulus n
23308 + * @q_sz : length in bytes of RSA prime factor q of RSA modulus n
23309 + * @priv_form : CAAM RSA private key representation
23311 struct caam_rsa_key {
23327 + enum caam_priv_key_form priv_form;
23331 @@ -59,6 +113,8 @@ struct rsa_edesc {
23333 struct rsa_pub_pdb pub;
23334 struct rsa_priv_f1_pdb priv_f1;
23335 + struct rsa_priv_f2_pdb priv_f2;
23336 + struct rsa_priv_f3_pdb priv_f3;
23340 @@ -66,5 +122,7 @@ struct rsa_edesc {
23341 /* Descriptor construction primitives. */
23342 void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb);
23343 void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb);
23344 +void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb);
23345 +void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb);
23348 --- a/drivers/crypto/caam/caamrng.c
23349 +++ b/drivers/crypto/caam/caamrng.c
23352 /* length of descriptors */
23353 #define DESC_JOB_O_LEN (CAAM_CMD_SZ * 2 + CAAM_PTR_SZ * 2)
23354 -#define DESC_RNG_LEN (4 * CAAM_CMD_SZ)
23355 +#define DESC_RNG_LEN (3 * CAAM_CMD_SZ)
23357 /* Buffer, its dma address and lock */
23359 @@ -100,8 +100,7 @@ static void rng_done(struct device *jrde
23361 struct buf_data *bd;
23363 - bd = (struct buf_data *)((char *)desc -
23364 - offsetof(struct buf_data, hw_desc));
23365 + bd = container_of(desc, struct buf_data, hw_desc[0]);
23368 caam_jr_strstatus(jrdev, err);
23369 @@ -196,9 +195,6 @@ static inline int rng_create_sh_desc(str
23371 init_sh_desc(desc, HDR_SHARE_SERIAL);
23373 - /* Propagate errors from shared to job descriptor */
23374 - append_cmd(desc, SET_OK_NO_PROP_ERRORS | CMD_LOAD);
23376 /* Generate random bytes */
23377 append_operation(desc, OP_ALG_ALGSEL_RNG | OP_TYPE_CLASS1_ALG);
23379 @@ -289,11 +285,7 @@ static int caam_init_rng(struct caam_rng
23383 - err = caam_init_buf(ctx, 1);
23388 + return caam_init_buf(ctx, 1);
23391 static struct hwrng caam_rng = {
23392 @@ -351,7 +343,7 @@ static int __init caam_rng_init(void)
23393 pr_err("Job Ring Device allocation for transform failed\n");
23394 return PTR_ERR(dev);
23396 - rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA);
23397 + rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA | GFP_KERNEL);
23400 goto free_caam_alloc;
23401 --- a/drivers/crypto/caam/compat.h
23402 +++ b/drivers/crypto/caam/compat.h
23404 #include <linux/of_platform.h>
23405 #include <linux/dma-mapping.h>
23406 #include <linux/io.h>
23407 +#include <linux/iommu.h>
23408 #include <linux/spinlock.h>
23409 #include <linux/rtnetlink.h>
23410 #include <linux/in.h>
23411 --- a/drivers/crypto/caam/ctrl.c
23412 +++ b/drivers/crypto/caam/ctrl.c
23414 * Controller-level driver, kernel property detection, initialization
23416 * Copyright 2008-2012 Freescale Semiconductor, Inc.
23417 + * Copyright 2017 NXP
23420 #include <linux/device.h>
23421 #include <linux/of_address.h>
23422 #include <linux/of_irq.h>
23423 +#include <linux/sys_soc.h>
23425 #include "compat.h"
23427 #include "intern.h"
23429 #include "desc_constr.h"
23430 -#include "error.h"
23433 bool caam_little_end;
23434 EXPORT_SYMBOL(caam_little_end);
23436 +EXPORT_SYMBOL(caam_imx);
23438 +EXPORT_SYMBOL(caam_dpaa2);
23440 +#ifdef CONFIG_CAAM_QI
23445 * i.MX targets tend to have clock control subsystems that can
23446 * enable/disable clocking to our device.
23448 -#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX
23449 -static inline struct clk *caam_drv_identify_clk(struct device *dev,
23452 - return devm_clk_get(dev, clk_name);
23455 static inline struct clk *caam_drv_identify_clk(struct device *dev,
23459 + return caam_imx ? devm_clk_get(dev, clk_name) : NULL;
23464 * Descriptor to instantiate RNG State Handle 0 in normal mode and
23465 @@ -274,7 +275,7 @@ static int deinstantiate_rng(struct devi
23467 * If the corresponding bit is set, then it means the state
23468 * handle was initialized by us, and thus it needs to be
23469 - * deintialized as well
23470 + * deinitialized as well
23472 if ((1 << sh_idx) & state_handle_mask) {
23474 @@ -307,20 +308,24 @@ static int caam_remove(struct platform_d
23475 struct device *ctrldev;
23476 struct caam_drv_private *ctrlpriv;
23477 struct caam_ctrl __iomem *ctrl;
23480 ctrldev = &pdev->dev;
23481 ctrlpriv = dev_get_drvdata(ctrldev);
23482 ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
23484 - /* Remove platform devices for JobRs */
23485 - for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) {
23486 - if (ctrlpriv->jrpdev[ring])
23487 - of_device_unregister(ctrlpriv->jrpdev[ring]);
23489 + /* Remove platform devices under the crypto node */
23490 + of_platform_depopulate(ctrldev);
23492 +#ifdef CONFIG_CAAM_QI
23493 + if (ctrlpriv->qidev)
23494 + caam_qi_shutdown(ctrlpriv->qidev);
23497 - /* De-initialize RNG state handles initialized by this driver. */
23498 - if (ctrlpriv->rng4_sh_init)
23500 + * De-initialize RNG state handles initialized by this driver.
23501 + * In case of DPAA 2.x, RNG is managed by MC firmware.
23503 + if (!caam_dpaa2 && ctrlpriv->rng4_sh_init)
23504 deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init);
23506 /* Shut down debug views */
23507 @@ -335,8 +340,8 @@ static int caam_remove(struct platform_d
23508 clk_disable_unprepare(ctrlpriv->caam_ipg);
23509 clk_disable_unprepare(ctrlpriv->caam_mem);
23510 clk_disable_unprepare(ctrlpriv->caam_aclk);
23511 - clk_disable_unprepare(ctrlpriv->caam_emi_slow);
23513 + if (ctrlpriv->caam_emi_slow)
23514 + clk_disable_unprepare(ctrlpriv->caam_emi_slow);
23518 @@ -370,11 +375,8 @@ static void kick_trng(struct platform_de
23520 val = (rd_reg32(&r4tst->rtsdctl) & RTSDCTL_ENT_DLY_MASK)
23521 >> RTSDCTL_ENT_DLY_SHIFT;
23522 - if (ent_delay <= val) {
23523 - /* put RNG4 into run mode */
23524 - clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, 0);
23527 + if (ent_delay <= val)
23530 val = rd_reg32(&r4tst->rtsdctl);
23531 val = (val & ~RTSDCTL_ENT_DLY_MASK) |
23532 @@ -386,15 +388,12 @@ static void kick_trng(struct platform_de
23533 wr_reg32(&r4tst->rtfrqmax, RTFRQMAX_DISABLE);
23534 /* read the control register */
23535 val = rd_reg32(&r4tst->rtmctl);
23538 * select raw sampling in both entropy shifter
23539 - * and statistical checker
23540 + * and statistical checker; ; put RNG4 into run mode
23542 - clrsetbits_32(&val, 0, RTMCTL_SAMP_MODE_RAW_ES_SC);
23543 - /* put RNG4 into run mode */
23544 - clrsetbits_32(&val, RTMCTL_PRGM, 0);
23545 - /* write back the control register */
23546 - wr_reg32(&r4tst->rtmctl, val);
23547 + clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
23551 @@ -415,28 +414,26 @@ int caam_get_era(void)
23553 EXPORT_SYMBOL(caam_get_era);
23555 -#ifdef CONFIG_DEBUG_FS
23556 -static int caam_debugfs_u64_get(void *data, u64 *val)
23558 - *val = caam64_to_cpu(*(u64 *)data);
23562 -static int caam_debugfs_u32_get(void *data, u64 *val)
23564 - *val = caam32_to_cpu(*(u32 *)data);
23568 -DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u32_ro, caam_debugfs_u32_get, NULL, "%llu\n");
23569 -DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u64_ro, caam_debugfs_u64_get, NULL, "%llu\n");
23571 +static const struct of_device_id caam_match[] = {
23573 + .compatible = "fsl,sec-v4.0",
23576 + .compatible = "fsl,sec4.0",
23580 +MODULE_DEVICE_TABLE(of, caam_match);
23582 /* Probe routine for CAAM top (controller) level */
23583 static int caam_probe(struct platform_device *pdev)
23585 - int ret, ring, rspec, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
23586 + int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
23588 + static const struct soc_device_attribute imx_soc[] = {
23589 + {.family = "Freescale i.MX"},
23592 struct device *dev;
23593 struct device_node *nprop, *np;
23594 struct caam_ctrl __iomem *ctrl;
23595 @@ -456,9 +453,10 @@ static int caam_probe(struct platform_de
23598 dev_set_drvdata(dev, ctrlpriv);
23599 - ctrlpriv->pdev = pdev;
23600 nprop = pdev->dev.of_node;
23602 + caam_imx = (bool)soc_device_match(imx_soc);
23604 /* Enable clocking */
23605 clk = caam_drv_identify_clk(&pdev->dev, "ipg");
23607 @@ -487,14 +485,16 @@ static int caam_probe(struct platform_de
23609 ctrlpriv->caam_aclk = clk;
23611 - clk = caam_drv_identify_clk(&pdev->dev, "emi_slow");
23612 - if (IS_ERR(clk)) {
23613 - ret = PTR_ERR(clk);
23614 - dev_err(&pdev->dev,
23615 - "can't identify CAAM emi_slow clk: %d\n", ret);
23617 + if (!of_machine_is_compatible("fsl,imx6ul")) {
23618 + clk = caam_drv_identify_clk(&pdev->dev, "emi_slow");
23619 + if (IS_ERR(clk)) {
23620 + ret = PTR_ERR(clk);
23621 + dev_err(&pdev->dev,
23622 + "can't identify CAAM emi_slow clk: %d\n", ret);
23625 + ctrlpriv->caam_emi_slow = clk;
23627 - ctrlpriv->caam_emi_slow = clk;
23629 ret = clk_prepare_enable(ctrlpriv->caam_ipg);
23631 @@ -515,11 +515,13 @@ static int caam_probe(struct platform_de
23632 goto disable_caam_mem;
23635 - ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
23637 - dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
23639 - goto disable_caam_aclk;
23640 + if (ctrlpriv->caam_emi_slow) {
23641 + ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
23643 + dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
23645 + goto disable_caam_aclk;
23649 /* Get configuration properties from device tree */
23650 @@ -546,13 +548,13 @@ static int caam_probe(struct platform_de
23652 BLOCK_OFFSET = PG_SIZE_64K;
23654 - ctrlpriv->ctrl = (struct caam_ctrl __force *)ctrl;
23655 - ctrlpriv->assure = (struct caam_assurance __force *)
23656 - ((uint8_t *)ctrl +
23657 + ctrlpriv->ctrl = (struct caam_ctrl __iomem __force *)ctrl;
23658 + ctrlpriv->assure = (struct caam_assurance __iomem __force *)
23659 + ((__force uint8_t *)ctrl +
23660 BLOCK_OFFSET * ASSURE_BLOCK_NUMBER
23662 - ctrlpriv->deco = (struct caam_deco __force *)
23663 - ((uint8_t *)ctrl +
23664 + ctrlpriv->deco = (struct caam_deco __iomem __force *)
23665 + ((__force uint8_t *)ctrl +
23666 BLOCK_OFFSET * DECO_BLOCK_NUMBER
23669 @@ -561,12 +563,17 @@ static int caam_probe(struct platform_de
23672 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
23673 - * long pointers in master configuration register
23674 + * long pointers in master configuration register.
23675 + * In case of DPAA 2.x, Management Complex firmware performs
23676 + * the configuration.
23678 - clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK | MCFGR_LONG_PTR,
23679 - MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF |
23680 - MCFGR_WDENABLE | MCFGR_LARGE_BURST |
23681 - (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0));
23682 + caam_dpaa2 = !!(comp_params & CTPR_MS_DPAA2);
23684 + clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK | MCFGR_LONG_PTR,
23685 + MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF |
23686 + MCFGR_WDENABLE | MCFGR_LARGE_BURST |
23687 + (sizeof(dma_addr_t) == sizeof(u64) ?
23688 + MCFGR_LONG_PTR : 0));
23691 * Read the Compile Time paramters and SCFGR to determine
23692 @@ -594,64 +601,69 @@ static int caam_probe(struct platform_de
23693 JRSTART_JR1_START | JRSTART_JR2_START |
23694 JRSTART_JR3_START);
23696 - if (sizeof(dma_addr_t) == sizeof(u64))
23697 - if (of_device_is_compatible(nprop, "fsl,sec-v5.0"))
23698 - dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40));
23699 + if (sizeof(dma_addr_t) == sizeof(u64)) {
23701 + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(49));
23702 + else if (of_device_is_compatible(nprop, "fsl,sec-v5.0"))
23703 + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40));
23705 - dma_set_mask_and_coherent(dev, DMA_BIT_MASK(36));
23707 - dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
23708 + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(36));
23710 + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
23713 + dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
23714 + goto iounmap_ctrl;
23718 - * Detect and enable JobRs
23719 - * First, find out how many ring spec'ed, allocate references
23720 - * for all, then go probe each one.
23723 - for_each_available_child_of_node(nprop, np)
23724 - if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
23725 - of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
23727 + ctrlpriv->era = caam_get_era();
23729 - ctrlpriv->jrpdev = devm_kcalloc(&pdev->dev, rspec,
23730 - sizeof(*ctrlpriv->jrpdev), GFP_KERNEL);
23731 - if (ctrlpriv->jrpdev == NULL) {
23733 + ret = of_platform_populate(nprop, caam_match, NULL, dev);
23735 + dev_err(dev, "JR platform devices creation error\n");
23739 +#ifdef CONFIG_DEBUG_FS
23741 + * FIXME: needs better naming distinction, as some amalgamation of
23742 + * "caam" and nprop->full_name. The OF name isn't distinctive,
23743 + * but does separate instances
23745 + perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
23747 + ctrlpriv->dfs_root = debugfs_create_dir(dev_name(dev), NULL);
23748 + ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);
23751 - ctrlpriv->total_jobrs = 0;
23752 for_each_available_child_of_node(nprop, np)
23753 if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
23754 of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
23755 - ctrlpriv->jrpdev[ring] =
23756 - of_platform_device_create(np, NULL, dev);
23757 - if (!ctrlpriv->jrpdev[ring]) {
23758 - pr_warn("JR%d Platform device creation error\n",
23762 - ctrlpriv->jr[ring] = (struct caam_job_ring __force *)
23763 - ((uint8_t *)ctrl +
23764 + ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
23765 + ((__force uint8_t *)ctrl +
23766 (ring + JR_BLOCK_NUMBER) *
23769 ctrlpriv->total_jobrs++;
23774 - /* Check to see if QI present. If so, enable */
23775 - ctrlpriv->qi_present =
23776 - !!(rd_reg32(&ctrl->perfmon.comp_parms_ms) &
23777 - CTPR_MS_QI_MASK);
23778 - if (ctrlpriv->qi_present) {
23779 - ctrlpriv->qi = (struct caam_queue_if __force *)
23780 - ((uint8_t *)ctrl +
23781 + /* Check to see if (DPAA 1.x) QI present. If so, enable */
23782 + ctrlpriv->qi_present = !!(comp_params & CTPR_MS_QI_MASK);
23783 + if (ctrlpriv->qi_present && !caam_dpaa2) {
23784 + ctrlpriv->qi = (struct caam_queue_if __iomem __force *)
23785 + ((__force uint8_t *)ctrl +
23786 BLOCK_OFFSET * QI_BLOCK_NUMBER
23788 /* This is all that's required to physically enable QI */
23789 wr_reg32(&ctrlpriv->qi->qi_control_lo, QICTL_DQEN);
23791 + /* If QMAN driver is present, init CAAM-QI backend */
23792 +#ifdef CONFIG_CAAM_QI
23793 + ret = caam_qi_init(pdev);
23795 + dev_err(dev, "caam qi i/f init failed: %d\n", ret);
23799 /* If no QI and no rings specified, quit and go home */
23800 @@ -666,8 +678,10 @@ static int caam_probe(struct platform_de
23802 * If SEC has RNG version >= 4 and RNG state handle has not been
23803 * already instantiated, do RNG instantiation
23804 + * In case of DPAA 2.x, RNG is managed by MC firmware.
23806 - if ((cha_vid_ls & CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT >= 4) {
23807 + if (!caam_dpaa2 &&
23808 + (cha_vid_ls & CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT >= 4) {
23809 ctrlpriv->rng4_sh_init =
23810 rd_reg32(&ctrl->r4tst[0].rdsta);
23812 @@ -734,78 +748,47 @@ static int caam_probe(struct platform_de
23814 /* Report "alive" for developer to see */
23815 dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
23817 - dev_info(dev, "job rings = %d, qi = %d\n",
23818 - ctrlpriv->total_jobrs, ctrlpriv->qi_present);
23820 + dev_info(dev, "job rings = %d, qi = %d, dpaa2 = %s\n",
23821 + ctrlpriv->total_jobrs, ctrlpriv->qi_present,
23822 + caam_dpaa2 ? "yes" : "no");
23824 #ifdef CONFIG_DEBUG_FS
23826 - * FIXME: needs better naming distinction, as some amalgamation of
23827 - * "caam" and nprop->full_name. The OF name isn't distinctive,
23828 - * but does separate instances
23830 - perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
23832 - ctrlpriv->dfs_root = debugfs_create_dir(dev_name(dev), NULL);
23833 - ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);
23835 - /* Controller-level - performance monitor counters */
23837 - ctrlpriv->ctl_rq_dequeued =
23838 - debugfs_create_file("rq_dequeued",
23839 - S_IRUSR | S_IRGRP | S_IROTH,
23840 - ctrlpriv->ctl, &perfmon->req_dequeued,
23841 - &caam_fops_u64_ro);
23842 - ctrlpriv->ctl_ob_enc_req =
23843 - debugfs_create_file("ob_rq_encrypted",
23844 - S_IRUSR | S_IRGRP | S_IROTH,
23845 - ctrlpriv->ctl, &perfmon->ob_enc_req,
23846 - &caam_fops_u64_ro);
23847 - ctrlpriv->ctl_ib_dec_req =
23848 - debugfs_create_file("ib_rq_decrypted",
23849 - S_IRUSR | S_IRGRP | S_IROTH,
23850 - ctrlpriv->ctl, &perfmon->ib_dec_req,
23851 - &caam_fops_u64_ro);
23852 - ctrlpriv->ctl_ob_enc_bytes =
23853 - debugfs_create_file("ob_bytes_encrypted",
23854 - S_IRUSR | S_IRGRP | S_IROTH,
23855 - ctrlpriv->ctl, &perfmon->ob_enc_bytes,
23856 - &caam_fops_u64_ro);
23857 - ctrlpriv->ctl_ob_prot_bytes =
23858 - debugfs_create_file("ob_bytes_protected",
23859 - S_IRUSR | S_IRGRP | S_IROTH,
23860 - ctrlpriv->ctl, &perfmon->ob_prot_bytes,
23861 - &caam_fops_u64_ro);
23862 - ctrlpriv->ctl_ib_dec_bytes =
23863 - debugfs_create_file("ib_bytes_decrypted",
23864 - S_IRUSR | S_IRGRP | S_IROTH,
23865 - ctrlpriv->ctl, &perfmon->ib_dec_bytes,
23866 - &caam_fops_u64_ro);
23867 - ctrlpriv->ctl_ib_valid_bytes =
23868 - debugfs_create_file("ib_bytes_validated",
23869 - S_IRUSR | S_IRGRP | S_IROTH,
23870 - ctrlpriv->ctl, &perfmon->ib_valid_bytes,
23871 - &caam_fops_u64_ro);
23872 + debugfs_create_file("rq_dequeued", S_IRUSR | S_IRGRP | S_IROTH,
23873 + ctrlpriv->ctl, &perfmon->req_dequeued,
23874 + &caam_fops_u64_ro);
23875 + debugfs_create_file("ob_rq_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
23876 + ctrlpriv->ctl, &perfmon->ob_enc_req,
23877 + &caam_fops_u64_ro);
23878 + debugfs_create_file("ib_rq_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
23879 + ctrlpriv->ctl, &perfmon->ib_dec_req,
23880 + &caam_fops_u64_ro);
23881 + debugfs_create_file("ob_bytes_encrypted", S_IRUSR | S_IRGRP | S_IROTH,
23882 + ctrlpriv->ctl, &perfmon->ob_enc_bytes,
23883 + &caam_fops_u64_ro);
23884 + debugfs_create_file("ob_bytes_protected", S_IRUSR | S_IRGRP | S_IROTH,
23885 + ctrlpriv->ctl, &perfmon->ob_prot_bytes,
23886 + &caam_fops_u64_ro);
23887 + debugfs_create_file("ib_bytes_decrypted", S_IRUSR | S_IRGRP | S_IROTH,
23888 + ctrlpriv->ctl, &perfmon->ib_dec_bytes,
23889 + &caam_fops_u64_ro);
23890 + debugfs_create_file("ib_bytes_validated", S_IRUSR | S_IRGRP | S_IROTH,
23891 + ctrlpriv->ctl, &perfmon->ib_valid_bytes,
23892 + &caam_fops_u64_ro);
23894 /* Controller level - global status values */
23895 - ctrlpriv->ctl_faultaddr =
23896 - debugfs_create_file("fault_addr",
23897 - S_IRUSR | S_IRGRP | S_IROTH,
23898 - ctrlpriv->ctl, &perfmon->faultaddr,
23899 - &caam_fops_u32_ro);
23900 - ctrlpriv->ctl_faultdetail =
23901 - debugfs_create_file("fault_detail",
23902 - S_IRUSR | S_IRGRP | S_IROTH,
23903 - ctrlpriv->ctl, &perfmon->faultdetail,
23904 - &caam_fops_u32_ro);
23905 - ctrlpriv->ctl_faultstatus =
23906 - debugfs_create_file("fault_status",
23907 - S_IRUSR | S_IRGRP | S_IROTH,
23908 - ctrlpriv->ctl, &perfmon->status,
23909 - &caam_fops_u32_ro);
23910 + debugfs_create_file("fault_addr", S_IRUSR | S_IRGRP | S_IROTH,
23911 + ctrlpriv->ctl, &perfmon->faultaddr,
23912 + &caam_fops_u32_ro);
23913 + debugfs_create_file("fault_detail", S_IRUSR | S_IRGRP | S_IROTH,
23914 + ctrlpriv->ctl, &perfmon->faultdetail,
23915 + &caam_fops_u32_ro);
23916 + debugfs_create_file("fault_status", S_IRUSR | S_IRGRP | S_IROTH,
23917 + ctrlpriv->ctl, &perfmon->status,
23918 + &caam_fops_u32_ro);
23920 /* Internal covering keys (useful in non-secure mode only) */
23921 - ctrlpriv->ctl_kek_wrap.data = &ctrlpriv->ctrl->kek[0];
23922 + ctrlpriv->ctl_kek_wrap.data = (__force void *)&ctrlpriv->ctrl->kek[0];
23923 ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
23924 ctrlpriv->ctl_kek = debugfs_create_blob("kek",
23926 @@ -813,7 +796,7 @@ static int caam_probe(struct platform_de
23928 &ctrlpriv->ctl_kek_wrap);
23930 - ctrlpriv->ctl_tkek_wrap.data = &ctrlpriv->ctrl->tkek[0];
23931 + ctrlpriv->ctl_tkek_wrap.data = (__force void *)&ctrlpriv->ctrl->tkek[0];
23932 ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
23933 ctrlpriv->ctl_tkek = debugfs_create_blob("tkek",
23935 @@ -821,7 +804,7 @@ static int caam_probe(struct platform_de
23937 &ctrlpriv->ctl_tkek_wrap);
23939 - ctrlpriv->ctl_tdsk_wrap.data = &ctrlpriv->ctrl->tdsk[0];
23940 + ctrlpriv->ctl_tdsk_wrap.data = (__force void *)&ctrlpriv->ctrl->tdsk[0];
23941 ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
23942 ctrlpriv->ctl_tdsk = debugfs_create_blob("tdsk",
23944 @@ -832,13 +815,17 @@ static int caam_probe(struct platform_de
23948 +#ifdef CONFIG_DEBUG_FS
23949 + debugfs_remove_recursive(ctrlpriv->dfs_root);
23956 disable_caam_emi_slow:
23957 - clk_disable_unprepare(ctrlpriv->caam_emi_slow);
23958 + if (ctrlpriv->caam_emi_slow)
23959 + clk_disable_unprepare(ctrlpriv->caam_emi_slow);
23961 clk_disable_unprepare(ctrlpriv->caam_aclk);
23963 @@ -848,17 +835,6 @@ disable_caam_ipg:
23967 -static struct of_device_id caam_match[] = {
23969 - .compatible = "fsl,sec-v4.0",
23972 - .compatible = "fsl,sec4.0",
23976 -MODULE_DEVICE_TABLE(of, caam_match);
23978 static struct platform_driver caam_driver = {
23981 --- a/drivers/crypto/caam/ctrl.h
23982 +++ b/drivers/crypto/caam/ctrl.h
23984 /* Prototypes for backend-level services exposed to APIs */
23985 int caam_get_era(void);
23987 +extern bool caam_dpaa2;
23989 #endif /* CTRL_H */
23990 --- a/drivers/crypto/caam/desc.h
23991 +++ b/drivers/crypto/caam/desc.h
23993 #define SEC4_SG_LEN_MASK 0x3fffffff /* Excludes EXT and FINAL */
23994 #define SEC4_SG_OFFSET_MASK 0x00001fff
23996 -struct sec4_sg_entry {
24002 /* Max size of any CAAM descriptor in 32-bit words, inclusive of header */
24003 #define MAX_CAAM_DESCSIZE 64
24005 @@ -47,6 +41,7 @@ struct sec4_sg_entry {
24006 #define CMD_SEQ_LOAD (0x03 << CMD_SHIFT)
24007 #define CMD_FIFO_LOAD (0x04 << CMD_SHIFT)
24008 #define CMD_SEQ_FIFO_LOAD (0x05 << CMD_SHIFT)
24009 +#define CMD_MOVEB (0x07 << CMD_SHIFT)
24010 #define CMD_STORE (0x0a << CMD_SHIFT)
24011 #define CMD_SEQ_STORE (0x0b << CMD_SHIFT)
24012 #define CMD_FIFO_STORE (0x0c << CMD_SHIFT)
24013 @@ -90,8 +85,8 @@ struct sec4_sg_entry {
24014 #define HDR_ZRO 0x00008000
24016 /* Start Index or SharedDesc Length */
24017 -#define HDR_START_IDX_MASK 0x3f
24018 #define HDR_START_IDX_SHIFT 16
24019 +#define HDR_START_IDX_MASK (0x3f << HDR_START_IDX_SHIFT)
24021 /* If shared descriptor header, 6-bit length */
24022 #define HDR_DESCLEN_SHR_MASK 0x3f
24023 @@ -121,10 +116,10 @@ struct sec4_sg_entry {
24024 #define HDR_PROP_DNR 0x00000800
24026 /* JobDesc/SharedDesc share property */
24027 -#define HDR_SD_SHARE_MASK 0x03
24028 #define HDR_SD_SHARE_SHIFT 8
24029 -#define HDR_JD_SHARE_MASK 0x07
24030 +#define HDR_SD_SHARE_MASK (0x03 << HDR_SD_SHARE_SHIFT)
24031 #define HDR_JD_SHARE_SHIFT 8
24032 +#define HDR_JD_SHARE_MASK (0x07 << HDR_JD_SHARE_SHIFT)
24034 #define HDR_SHARE_NEVER (0x00 << HDR_SD_SHARE_SHIFT)
24035 #define HDR_SHARE_WAIT (0x01 << HDR_SD_SHARE_SHIFT)
24036 @@ -235,7 +230,7 @@ struct sec4_sg_entry {
24037 #define LDST_SRCDST_WORD_DECO_MATH2 (0x0a << LDST_SRCDST_SHIFT)
24038 #define LDST_SRCDST_WORD_DECO_AAD_SZ (0x0b << LDST_SRCDST_SHIFT)
24039 #define LDST_SRCDST_WORD_DECO_MATH3 (0x0b << LDST_SRCDST_SHIFT)
24040 -#define LDST_SRCDST_WORD_CLASS1_ICV_SZ (0x0c << LDST_SRCDST_SHIFT)
24041 +#define LDST_SRCDST_WORD_CLASS1_IV_SZ (0x0c << LDST_SRCDST_SHIFT)
24042 #define LDST_SRCDST_WORD_ALTDS_CLASS1 (0x0f << LDST_SRCDST_SHIFT)
24043 #define LDST_SRCDST_WORD_PKHA_A_SZ (0x10 << LDST_SRCDST_SHIFT)
24044 #define LDST_SRCDST_WORD_PKHA_B_SZ (0x11 << LDST_SRCDST_SHIFT)
24045 @@ -360,6 +355,7 @@ struct sec4_sg_entry {
24046 #define FIFOLD_TYPE_PK_N (0x08 << FIFOLD_TYPE_SHIFT)
24047 #define FIFOLD_TYPE_PK_A (0x0c << FIFOLD_TYPE_SHIFT)
24048 #define FIFOLD_TYPE_PK_B (0x0d << FIFOLD_TYPE_SHIFT)
24049 +#define FIFOLD_TYPE_IFIFO (0x0f << FIFOLD_TYPE_SHIFT)
24051 /* Other types. Need to OR in last/flush bits as desired */
24052 #define FIFOLD_TYPE_MSG_MASK (0x38 << FIFOLD_TYPE_SHIFT)
24053 @@ -400,7 +396,7 @@ struct sec4_sg_entry {
24054 #define FIFOST_TYPE_PKHA_N (0x08 << FIFOST_TYPE_SHIFT)
24055 #define FIFOST_TYPE_PKHA_A (0x0c << FIFOST_TYPE_SHIFT)
24056 #define FIFOST_TYPE_PKHA_B (0x0d << FIFOST_TYPE_SHIFT)
24057 -#define FIFOST_TYPE_AF_SBOX_JKEK (0x10 << FIFOST_TYPE_SHIFT)
24058 +#define FIFOST_TYPE_AF_SBOX_JKEK (0x20 << FIFOST_TYPE_SHIFT)
24059 #define FIFOST_TYPE_AF_SBOX_TKEK (0x21 << FIFOST_TYPE_SHIFT)
24060 #define FIFOST_TYPE_PKHA_E_JKEK (0x22 << FIFOST_TYPE_SHIFT)
24061 #define FIFOST_TYPE_PKHA_E_TKEK (0x23 << FIFOST_TYPE_SHIFT)
24062 @@ -413,6 +409,7 @@ struct sec4_sg_entry {
24063 #define FIFOST_TYPE_MESSAGE_DATA (0x30 << FIFOST_TYPE_SHIFT)
24064 #define FIFOST_TYPE_RNGSTORE (0x34 << FIFOST_TYPE_SHIFT)
24065 #define FIFOST_TYPE_RNGFIFO (0x35 << FIFOST_TYPE_SHIFT)
24066 +#define FIFOST_TYPE_METADATA (0x3e << FIFOST_TYPE_SHIFT)
24067 #define FIFOST_TYPE_SKIP (0x3f << FIFOST_TYPE_SHIFT)
24070 @@ -449,6 +446,18 @@ struct sec4_sg_entry {
24071 #define OP_PCLID_DSAVERIFY (0x16 << OP_PCLID_SHIFT)
24072 #define OP_PCLID_RSAENC_PUBKEY (0x18 << OP_PCLID_SHIFT)
24073 #define OP_PCLID_RSADEC_PRVKEY (0x19 << OP_PCLID_SHIFT)
24074 +#define OP_PCLID_DKP_MD5 (0x20 << OP_PCLID_SHIFT)
24075 +#define OP_PCLID_DKP_SHA1 (0x21 << OP_PCLID_SHIFT)
24076 +#define OP_PCLID_DKP_SHA224 (0x22 << OP_PCLID_SHIFT)
24077 +#define OP_PCLID_DKP_SHA256 (0x23 << OP_PCLID_SHIFT)
24078 +#define OP_PCLID_DKP_SHA384 (0x24 << OP_PCLID_SHIFT)
24079 +#define OP_PCLID_DKP_SHA512 (0x25 << OP_PCLID_SHIFT)
24080 +#define OP_PCLID_DKP_RIF_MD5 (0x60 << OP_PCLID_SHIFT)
24081 +#define OP_PCLID_DKP_RIF_SHA1 (0x61 << OP_PCLID_SHIFT)
24082 +#define OP_PCLID_DKP_RIF_SHA224 (0x62 << OP_PCLID_SHIFT)
24083 +#define OP_PCLID_DKP_RIF_SHA256 (0x63 << OP_PCLID_SHIFT)
24084 +#define OP_PCLID_DKP_RIF_SHA384 (0x64 << OP_PCLID_SHIFT)
24085 +#define OP_PCLID_DKP_RIF_SHA512 (0x65 << OP_PCLID_SHIFT)
24087 /* Assuming OP_TYPE = OP_TYPE_DECAP_PROTOCOL/ENCAP_PROTOCOL */
24088 #define OP_PCLID_IPSEC (0x01 << OP_PCLID_SHIFT)
24089 @@ -1098,6 +1107,22 @@ struct sec4_sg_entry {
24090 /* MacSec protinfos */
24091 #define OP_PCL_MACSEC 0x0001
24093 +/* Derived Key Protocol (DKP) Protinfo */
24094 +#define OP_PCL_DKP_SRC_SHIFT 14
24095 +#define OP_PCL_DKP_SRC_MASK (3 << OP_PCL_DKP_SRC_SHIFT)
24096 +#define OP_PCL_DKP_SRC_IMM (0 << OP_PCL_DKP_SRC_SHIFT)
24097 +#define OP_PCL_DKP_SRC_SEQ (1 << OP_PCL_DKP_SRC_SHIFT)
24098 +#define OP_PCL_DKP_SRC_PTR (2 << OP_PCL_DKP_SRC_SHIFT)
24099 +#define OP_PCL_DKP_SRC_SGF (3 << OP_PCL_DKP_SRC_SHIFT)
24100 +#define OP_PCL_DKP_DST_SHIFT 12
24101 +#define OP_PCL_DKP_DST_MASK (3 << OP_PCL_DKP_DST_SHIFT)
24102 +#define OP_PCL_DKP_DST_IMM (0 << OP_PCL_DKP_DST_SHIFT)
24103 +#define OP_PCL_DKP_DST_SEQ (1 << OP_PCL_DKP_DST_SHIFT)
24104 +#define OP_PCL_DKP_DST_PTR (2 << OP_PCL_DKP_DST_SHIFT)
24105 +#define OP_PCL_DKP_DST_SGF (3 << OP_PCL_DKP_DST_SHIFT)
24106 +#define OP_PCL_DKP_KEY_SHIFT 0
24107 +#define OP_PCL_DKP_KEY_MASK (0xfff << OP_PCL_DKP_KEY_SHIFT)
24109 /* PKI unidirectional protocol protinfo bits */
24110 #define OP_PCL_PKPROT_TEST 0x0008
24111 #define OP_PCL_PKPROT_DECRYPT 0x0004
24112 @@ -1107,8 +1132,8 @@ struct sec4_sg_entry {
24113 /* For non-protocol/alg-only op commands */
24114 #define OP_ALG_TYPE_SHIFT 24
24115 #define OP_ALG_TYPE_MASK (0x7 << OP_ALG_TYPE_SHIFT)
24116 -#define OP_ALG_TYPE_CLASS1 2
24117 -#define OP_ALG_TYPE_CLASS2 4
24118 +#define OP_ALG_TYPE_CLASS1 (2 << OP_ALG_TYPE_SHIFT)
24119 +#define OP_ALG_TYPE_CLASS2 (4 << OP_ALG_TYPE_SHIFT)
24121 #define OP_ALG_ALGSEL_SHIFT 16
24122 #define OP_ALG_ALGSEL_MASK (0xff << OP_ALG_ALGSEL_SHIFT)
24123 @@ -1249,7 +1274,7 @@ struct sec4_sg_entry {
24124 #define OP_ALG_PKMODE_MOD_PRIMALITY 0x00f
24126 /* PKHA mode copy-memory functions */
24127 -#define OP_ALG_PKMODE_SRC_REG_SHIFT 13
24128 +#define OP_ALG_PKMODE_SRC_REG_SHIFT 17
24129 #define OP_ALG_PKMODE_SRC_REG_MASK (7 << OP_ALG_PKMODE_SRC_REG_SHIFT)
24130 #define OP_ALG_PKMODE_DST_REG_SHIFT 10
24131 #define OP_ALG_PKMODE_DST_REG_MASK (7 << OP_ALG_PKMODE_DST_REG_SHIFT)
24132 @@ -1445,10 +1470,11 @@ struct sec4_sg_entry {
24133 #define MATH_SRC1_REG2 (0x02 << MATH_SRC1_SHIFT)
24134 #define MATH_SRC1_REG3 (0x03 << MATH_SRC1_SHIFT)
24135 #define MATH_SRC1_IMM (0x04 << MATH_SRC1_SHIFT)
24136 -#define MATH_SRC1_DPOVRD (0x07 << MATH_SRC0_SHIFT)
24137 +#define MATH_SRC1_DPOVRD (0x07 << MATH_SRC1_SHIFT)
24138 #define MATH_SRC1_INFIFO (0x0a << MATH_SRC1_SHIFT)
24139 #define MATH_SRC1_OUTFIFO (0x0b << MATH_SRC1_SHIFT)
24140 #define MATH_SRC1_ONE (0x0c << MATH_SRC1_SHIFT)
24141 +#define MATH_SRC1_ZERO (0x0f << MATH_SRC1_SHIFT)
24143 /* Destination selectors */
24144 #define MATH_DEST_SHIFT 8
24145 @@ -1457,6 +1483,7 @@ struct sec4_sg_entry {
24146 #define MATH_DEST_REG1 (0x01 << MATH_DEST_SHIFT)
24147 #define MATH_DEST_REG2 (0x02 << MATH_DEST_SHIFT)
24148 #define MATH_DEST_REG3 (0x03 << MATH_DEST_SHIFT)
24149 +#define MATH_DEST_DPOVRD (0x07 << MATH_DEST_SHIFT)
24150 #define MATH_DEST_SEQINLEN (0x08 << MATH_DEST_SHIFT)
24151 #define MATH_DEST_SEQOUTLEN (0x09 << MATH_DEST_SHIFT)
24152 #define MATH_DEST_VARSEQINLEN (0x0a << MATH_DEST_SHIFT)
24153 @@ -1629,4 +1656,31 @@ struct sec4_sg_entry {
24154 /* Frame Descriptor Command for Replacement Job Descriptor */
24155 #define FD_CMD_REPLACE_JOB_DESC 0x20000000
24157 +/* CHA Control Register bits */
24158 +#define CCTRL_RESET_CHA_ALL 0x1
24159 +#define CCTRL_RESET_CHA_AESA 0x2
24160 +#define CCTRL_RESET_CHA_DESA 0x4
24161 +#define CCTRL_RESET_CHA_AFHA 0x8
24162 +#define CCTRL_RESET_CHA_KFHA 0x10
24163 +#define CCTRL_RESET_CHA_SF8A 0x20
24164 +#define CCTRL_RESET_CHA_PKHA 0x40
24165 +#define CCTRL_RESET_CHA_MDHA 0x80
24166 +#define CCTRL_RESET_CHA_CRCA 0x100
24167 +#define CCTRL_RESET_CHA_RNG 0x200
24168 +#define CCTRL_RESET_CHA_SF9A 0x400
24169 +#define CCTRL_RESET_CHA_ZUCE 0x800
24170 +#define CCTRL_RESET_CHA_ZUCA 0x1000
24171 +#define CCTRL_UNLOAD_PK_A0 0x10000
24172 +#define CCTRL_UNLOAD_PK_A1 0x20000
24173 +#define CCTRL_UNLOAD_PK_A2 0x40000
24174 +#define CCTRL_UNLOAD_PK_A3 0x80000
24175 +#define CCTRL_UNLOAD_PK_B0 0x100000
24176 +#define CCTRL_UNLOAD_PK_B1 0x200000
24177 +#define CCTRL_UNLOAD_PK_B2 0x400000
24178 +#define CCTRL_UNLOAD_PK_B3 0x800000
24179 +#define CCTRL_UNLOAD_PK_N 0x1000000
24180 +#define CCTRL_UNLOAD_PK_A 0x4000000
24181 +#define CCTRL_UNLOAD_PK_B 0x8000000
24182 +#define CCTRL_UNLOAD_SBOX 0x10000000
24184 #endif /* DESC_H */
24185 --- a/drivers/crypto/caam/desc_constr.h
24186 +++ b/drivers/crypto/caam/desc_constr.h
24188 * Copyright 2008-2012 Freescale Semiconductor, Inc.
24191 +#ifndef DESC_CONSTR_H
24192 +#define DESC_CONSTR_H
24197 @@ -33,38 +36,39 @@
24199 extern bool caam_little_end;
24201 -static inline int desc_len(u32 *desc)
24202 +static inline int desc_len(u32 * const desc)
24204 return caam32_to_cpu(*desc) & HDR_DESCLEN_MASK;
24207 -static inline int desc_bytes(void *desc)
24208 +static inline int desc_bytes(void * const desc)
24210 return desc_len(desc) * CAAM_CMD_SZ;
24213 -static inline u32 *desc_end(u32 *desc)
24214 +static inline u32 *desc_end(u32 * const desc)
24216 return desc + desc_len(desc);
24219 -static inline void *sh_desc_pdb(u32 *desc)
24220 +static inline void *sh_desc_pdb(u32 * const desc)
24225 -static inline void init_desc(u32 *desc, u32 options)
24226 +static inline void init_desc(u32 * const desc, u32 options)
24228 *desc = cpu_to_caam32((options | HDR_ONE) + 1);
24231 -static inline void init_sh_desc(u32 *desc, u32 options)
24232 +static inline void init_sh_desc(u32 * const desc, u32 options)
24235 init_desc(desc, CMD_SHARED_DESC_HDR | options);
24238 -static inline void init_sh_desc_pdb(u32 *desc, u32 options, size_t pdb_bytes)
24239 +static inline void init_sh_desc_pdb(u32 * const desc, u32 options,
24240 + size_t pdb_bytes)
24242 u32 pdb_len = (pdb_bytes + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
24244 @@ -72,19 +76,20 @@ static inline void init_sh_desc_pdb(u32
24248 -static inline void init_job_desc(u32 *desc, u32 options)
24249 +static inline void init_job_desc(u32 * const desc, u32 options)
24251 init_desc(desc, CMD_DESC_HDR | options);
24254 -static inline void init_job_desc_pdb(u32 *desc, u32 options, size_t pdb_bytes)
24255 +static inline void init_job_desc_pdb(u32 * const desc, u32 options,
24256 + size_t pdb_bytes)
24258 u32 pdb_len = (pdb_bytes + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
24260 init_job_desc(desc, (((pdb_len + 1) << HDR_START_IDX_SHIFT)) | options);
24263 -static inline void append_ptr(u32 *desc, dma_addr_t ptr)
24264 +static inline void append_ptr(u32 * const desc, dma_addr_t ptr)
24266 dma_addr_t *offset = (dma_addr_t *)desc_end(desc);
24268 @@ -94,8 +99,8 @@ static inline void append_ptr(u32 *desc,
24269 CAAM_PTR_SZ / CAAM_CMD_SZ);
24272 -static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len,
24274 +static inline void init_job_desc_shared(u32 * const desc, dma_addr_t ptr,
24275 + int len, u32 options)
24278 init_job_desc(desc, HDR_SHARED | options |
24279 @@ -103,7 +108,7 @@ static inline void init_job_desc_shared(
24280 append_ptr(desc, ptr);
24283 -static inline void append_data(u32 *desc, void *data, int len)
24284 +static inline void append_data(u32 * const desc, const void *data, int len)
24286 u32 *offset = desc_end(desc);
24288 @@ -114,7 +119,7 @@ static inline void append_data(u32 *desc
24289 (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ);
24292 -static inline void append_cmd(u32 *desc, u32 command)
24293 +static inline void append_cmd(u32 * const desc, u32 command)
24295 u32 *cmd = desc_end(desc);
24297 @@ -125,7 +130,7 @@ static inline void append_cmd(u32 *desc,
24299 #define append_u32 append_cmd
24301 -static inline void append_u64(u32 *desc, u64 data)
24302 +static inline void append_u64(u32 * const desc, u64 data)
24304 u32 *offset = desc_end(desc);
24306 @@ -142,14 +147,14 @@ static inline void append_u64(u32 *desc,
24309 /* Write command without affecting header, and return pointer to next word */
24310 -static inline u32 *write_cmd(u32 *desc, u32 command)
24311 +static inline u32 *write_cmd(u32 * const desc, u32 command)
24313 *desc = cpu_to_caam32(command);
24318 -static inline void append_cmd_ptr(u32 *desc, dma_addr_t ptr, int len,
24319 +static inline void append_cmd_ptr(u32 * const desc, dma_addr_t ptr, int len,
24322 append_cmd(desc, command | len);
24323 @@ -157,7 +162,7 @@ static inline void append_cmd_ptr(u32 *d
24326 /* Write length after pointer, rather than inside command */
24327 -static inline void append_cmd_ptr_extlen(u32 *desc, dma_addr_t ptr,
24328 +static inline void append_cmd_ptr_extlen(u32 * const desc, dma_addr_t ptr,
24329 unsigned int len, u32 command)
24331 append_cmd(desc, command);
24332 @@ -166,7 +171,7 @@ static inline void append_cmd_ptr_extlen
24333 append_cmd(desc, len);
24336 -static inline void append_cmd_data(u32 *desc, void *data, int len,
24337 +static inline void append_cmd_data(u32 * const desc, const void *data, int len,
24340 append_cmd(desc, command | IMMEDIATE | len);
24341 @@ -174,7 +179,7 @@ static inline void append_cmd_data(u32 *
24344 #define APPEND_CMD_RET(cmd, op) \
24345 -static inline u32 *append_##cmd(u32 *desc, u32 options) \
24346 +static inline u32 *append_##cmd(u32 * const desc, u32 options) \
24348 u32 *cmd = desc_end(desc); \
24350 @@ -183,14 +188,15 @@ static inline u32 *append_##cmd(u32 *des
24352 APPEND_CMD_RET(jump, JUMP)
24353 APPEND_CMD_RET(move, MOVE)
24354 +APPEND_CMD_RET(moveb, MOVEB)
24356 -static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd)
24357 +static inline void set_jump_tgt_here(u32 * const desc, u32 *jump_cmd)
24359 *jump_cmd = cpu_to_caam32(caam32_to_cpu(*jump_cmd) |
24360 (desc_len(desc) - (jump_cmd - desc)));
24363 -static inline void set_move_tgt_here(u32 *desc, u32 *move_cmd)
24364 +static inline void set_move_tgt_here(u32 * const desc, u32 *move_cmd)
24366 u32 val = caam32_to_cpu(*move_cmd);
24368 @@ -200,7 +206,7 @@ static inline void set_move_tgt_here(u32
24371 #define APPEND_CMD(cmd, op) \
24372 -static inline void append_##cmd(u32 *desc, u32 options) \
24373 +static inline void append_##cmd(u32 * const desc, u32 options) \
24376 append_cmd(desc, CMD_##op | options); \
24377 @@ -208,7 +214,8 @@ static inline void append_##cmd(u32 *des
24378 APPEND_CMD(operation, OPERATION)
24380 #define APPEND_CMD_LEN(cmd, op) \
24381 -static inline void append_##cmd(u32 *desc, unsigned int len, u32 options) \
24382 +static inline void append_##cmd(u32 * const desc, unsigned int len, \
24386 append_cmd(desc, CMD_##op | len | options); \
24387 @@ -220,8 +227,8 @@ APPEND_CMD_LEN(seq_fifo_load, SEQ_FIFO_L
24388 APPEND_CMD_LEN(seq_fifo_store, SEQ_FIFO_STORE)
24390 #define APPEND_CMD_PTR(cmd, op) \
24391 -static inline void append_##cmd(u32 *desc, dma_addr_t ptr, unsigned int len, \
24393 +static inline void append_##cmd(u32 * const desc, dma_addr_t ptr, \
24394 + unsigned int len, u32 options) \
24397 append_cmd_ptr(desc, ptr, len, CMD_##op | options); \
24398 @@ -231,8 +238,8 @@ APPEND_CMD_PTR(load, LOAD)
24399 APPEND_CMD_PTR(fifo_load, FIFO_LOAD)
24400 APPEND_CMD_PTR(fifo_store, FIFO_STORE)
24402 -static inline void append_store(u32 *desc, dma_addr_t ptr, unsigned int len,
24404 +static inline void append_store(u32 * const desc, dma_addr_t ptr,
24405 + unsigned int len, u32 options)
24409 @@ -249,7 +256,8 @@ static inline void append_store(u32 *des
24412 #define APPEND_SEQ_PTR_INTLEN(cmd, op) \
24413 -static inline void append_seq_##cmd##_ptr_intlen(u32 *desc, dma_addr_t ptr, \
24414 +static inline void append_seq_##cmd##_ptr_intlen(u32 * const desc, \
24415 + dma_addr_t ptr, \
24416 unsigned int len, \
24419 @@ -263,7 +271,7 @@ APPEND_SEQ_PTR_INTLEN(in, IN)
24420 APPEND_SEQ_PTR_INTLEN(out, OUT)
24422 #define APPEND_CMD_PTR_TO_IMM(cmd, op) \
24423 -static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
24424 +static inline void append_##cmd##_as_imm(u32 * const desc, const void *data, \
24425 unsigned int len, u32 options) \
24428 @@ -273,7 +281,7 @@ APPEND_CMD_PTR_TO_IMM(load, LOAD);
24429 APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD);
24431 #define APPEND_CMD_PTR_EXTLEN(cmd, op) \
24432 -static inline void append_##cmd##_extlen(u32 *desc, dma_addr_t ptr, \
24433 +static inline void append_##cmd##_extlen(u32 * const desc, dma_addr_t ptr, \
24434 unsigned int len, u32 options) \
24437 @@ -287,7 +295,7 @@ APPEND_CMD_PTR_EXTLEN(seq_out_ptr, SEQ_O
24438 * the size of its type
24440 #define APPEND_CMD_PTR_LEN(cmd, op, type) \
24441 -static inline void append_##cmd(u32 *desc, dma_addr_t ptr, \
24442 +static inline void append_##cmd(u32 * const desc, dma_addr_t ptr, \
24443 type len, u32 options) \
24446 @@ -304,7 +312,7 @@ APPEND_CMD_PTR_LEN(seq_out_ptr, SEQ_OUT_
24447 * from length of immediate data provided, e.g., split keys
24449 #define APPEND_CMD_PTR_TO_IMM2(cmd, op) \
24450 -static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
24451 +static inline void append_##cmd##_as_imm(u32 * const desc, const void *data, \
24452 unsigned int data_len, \
24453 unsigned int len, u32 options) \
24455 @@ -315,7 +323,7 @@ static inline void append_##cmd##_as_imm
24456 APPEND_CMD_PTR_TO_IMM2(key, KEY);
24458 #define APPEND_CMD_RAW_IMM(cmd, op, type) \
24459 -static inline void append_##cmd##_imm_##type(u32 *desc, type immediate, \
24460 +static inline void append_##cmd##_imm_##type(u32 * const desc, type immediate, \
24464 @@ -426,3 +434,107 @@ do { \
24465 APPEND_MATH_IMM_u64(LSHIFT, desc, dest, src0, src1, data)
24466 #define append_math_rshift_imm_u64(desc, dest, src0, src1, data) \
24467 APPEND_MATH_IMM_u64(RSHIFT, desc, dest, src0, src1, data)
24470 + * struct alginfo - Container for algorithm details
24471 + * @algtype: algorithm selector; for valid values, see documentation of the
24472 + * functions where it is used.
24473 + * @keylen: length of the provided algorithm key, in bytes
24474 + * @keylen_pad: padded length of the provided algorithm key, in bytes
24475 + * @key: address where algorithm key resides; virtual address if key_inline
24476 + * is true, dma (bus) address if key_inline is false.
24477 + * @key_inline: true - key can be inlined in the descriptor; false - key is
24478 + * referenced by the descriptor
24482 + unsigned int keylen;
24483 + unsigned int keylen_pad;
24485 + dma_addr_t key_dma;
24486 + const void *key_virt;
24492 + * desc_inline_query() - Provide indications on which data items can be inlined
24493 + * and which shall be referenced in a shared descriptor.
24494 + * @sd_base_len: Shared descriptor base length - bytes consumed by the commands,
24495 + * excluding the data items to be inlined (or corresponding
24496 + * pointer if an item is not inlined). Each cnstr_* function that
24497 + * generates descriptors should have a define mentioning
24498 + * corresponding length.
24499 + * @jd_len: Maximum length of the job descriptor(s) that will be used
24500 + * together with the shared descriptor.
24501 + * @data_len: Array of lengths of the data items trying to be inlined
24502 + * @inl_mask: 32bit mask with bit x = 1 if data item x can be inlined, 0
24504 + * @count: Number of data items (size of @data_len array); must be <= 32
24506 + * Return: 0 if data can be inlined / referenced, negative value if not. If 0,
24507 + * check @inl_mask for details.
24509 +static inline int desc_inline_query(unsigned int sd_base_len,
24510 + unsigned int jd_len, unsigned int *data_len,
24511 + u32 *inl_mask, unsigned int count)
24513 + int rem_bytes = (int)(CAAM_DESC_BYTES_MAX - sd_base_len - jd_len);
24517 + for (i = 0; (i < count) && (rem_bytes > 0); i++) {
24518 + if (rem_bytes - (int)(data_len[i] +
24519 + (count - i - 1) * CAAM_PTR_SZ) >= 0) {
24520 + rem_bytes -= data_len[i];
24521 + *inl_mask |= (1 << i);
24523 + rem_bytes -= CAAM_PTR_SZ;
24527 + return (rem_bytes >= 0) ? 0 : -1;
24531 + * append_proto_dkp - Derived Key Protocol (DKP): key -> split key
24532 + * @desc: pointer to buffer used for descriptor construction
24533 + * @adata: pointer to authentication transform definitions.
24534 + * keylen should be the length of initial key, while keylen_pad
24535 + * the length of the derived (split) key.
24536 + * Valid algorithm values - one of OP_ALG_ALGSEL_{MD5, SHA1, SHA224,
24537 + * SHA256, SHA384, SHA512}.
24539 +static inline void append_proto_dkp(u32 * const desc, struct alginfo *adata)
24544 + * Quick & dirty translation from OP_ALG_ALGSEL_{MD5, SHA*}
24545 + * to OP_PCLID_DKP_{MD5, SHA*}
24547 + protid = (adata->algtype & OP_ALG_ALGSEL_SUBMASK) |
24548 + (0x20 << OP_ALG_ALGSEL_SHIFT);
24550 + if (adata->key_inline) {
24553 + append_operation(desc, OP_TYPE_UNI_PROTOCOL | protid |
24554 + OP_PCL_DKP_SRC_IMM | OP_PCL_DKP_DST_IMM |
24556 + append_data(desc, adata->key_virt, adata->keylen);
24558 + /* Reserve space in descriptor buffer for the derived key */
24559 + words = (ALIGN(adata->keylen_pad, CAAM_CMD_SZ) -
24560 + ALIGN(adata->keylen, CAAM_CMD_SZ)) / CAAM_CMD_SZ;
24562 + (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + words);
24564 + append_operation(desc, OP_TYPE_UNI_PROTOCOL | protid |
24565 + OP_PCL_DKP_SRC_PTR | OP_PCL_DKP_DST_PTR |
24567 + append_ptr(desc, adata->key_dma);
24571 +#endif /* DESC_CONSTR_H */
24573 +++ b/drivers/crypto/caam/dpseci.c
24576 + * Copyright 2013-2016 Freescale Semiconductor Inc.
24577 + * Copyright 2017 NXP
24579 + * Redistribution and use in source and binary forms, with or without
24580 + * modification, are permitted provided that the following conditions are met:
24581 + * * Redistributions of source code must retain the above copyright
24582 + * notice, this list of conditions and the following disclaimer.
24583 + * * Redistributions in binary form must reproduce the above copyright
24584 + * notice, this list of conditions and the following disclaimer in the
24585 + * documentation and/or other materials provided with the distribution.
24586 + * * Neither the names of the above-listed copyright holders nor the
24587 + * names of any contributors may be used to endorse or promote products
24588 + * derived from this software without specific prior written permission.
24591 + * ALTERNATIVELY, this software may be distributed under the terms of the
24592 + * GNU General Public License ("GPL") as published by the Free Software
24593 + * Foundation, either version 2 of that License or (at your option) any
24596 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24597 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24598 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24599 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24600 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24601 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24602 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24603 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24604 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24605 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24606 + * POSSIBILITY OF SUCH DAMAGE.
24609 +#include "../../../drivers/staging/fsl-mc/include/mc-sys.h"
24610 +#include "../../../drivers/staging/fsl-mc/include/mc-cmd.h"
24611 +#include "../../../drivers/staging/fsl-mc/include/dpopr.h"
24612 +#include "dpseci.h"
24613 +#include "dpseci_cmd.h"
24616 + * dpseci_open() - Open a control session for the specified object
24617 + * @mc_io: Pointer to MC portal's I/O object
24618 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24619 + * @dpseci_id: DPSECI unique ID
24620 + * @token: Returned token; use in subsequent API calls
24622 + * This function can be used to open a control session for an already created
24623 + * object; an object may have been declared in the DPL or by calling the
24624 + * dpseci_create() function.
24625 + * This function returns a unique authentication token, associated with the
24626 + * specific object ID and the specific MC portal; this token must be used in all
24627 + * subsequent commands for this specific object.
24629 + * Return: '0' on success, error code otherwise
24631 +int dpseci_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpseci_id,
24634 + struct mc_command cmd = { 0 };
24635 + struct dpseci_cmd_open *cmd_params;
24638 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
24641 + cmd_params = (struct dpseci_cmd_open *)cmd.params;
24642 + cmd_params->dpseci_id = cpu_to_le32(dpseci_id);
24643 + err = mc_send_command(mc_io, &cmd);
24647 + *token = mc_cmd_hdr_read_token(&cmd);
24653 + * dpseci_close() - Close the control session of the object
24654 + * @mc_io: Pointer to MC portal's I/O object
24655 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24656 + * @token: Token of DPSECI object
24658 + * After this function is called, no further operations are allowed on the
24659 + * object without opening a new control session.
24661 + * Return: '0' on success, error code otherwise
24663 +int dpseci_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
24665 + struct mc_command cmd = { 0 };
24667 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
24670 + return mc_send_command(mc_io, &cmd);
24674 + * dpseci_create() - Create the DPSECI object
24675 + * @mc_io: Pointer to MC portal's I/O object
24676 + * @dprc_token: Parent container token; '0' for default container
24677 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24678 + * @cfg: Configuration structure
24679 + * @obj_id: returned object id
24681 + * Create the DPSECI object, allocate required resources and perform required
24682 + * initialization.
24684 + * The object can be created either by declaring it in the DPL file, or by
24685 + * calling this function.
24687 + * The function accepts an authentication token of a parent container that this
24688 + * object should be assigned to. The token can be '0' so the object will be
24689 + * assigned to the default container.
24690 + * The newly created object can be opened with the returned object id and using
24691 + * the container's associated tokens and MC portals.
24693 + * Return: '0' on success, error code otherwise
24695 +int dpseci_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
24696 + const struct dpseci_cfg *cfg, u32 *obj_id)
24698 + struct mc_command cmd = { 0 };
24699 + struct dpseci_cmd_create *cmd_params;
24702 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CREATE,
24705 + cmd_params = (struct dpseci_cmd_create *)cmd.params;
24706 + for (i = 0; i < 8; i++)
24707 + cmd_params->priorities[i] = cfg->priorities[i];
24708 + cmd_params->num_tx_queues = cfg->num_tx_queues;
24709 + cmd_params->num_rx_queues = cfg->num_rx_queues;
24710 + cmd_params->options = cpu_to_le32(cfg->options);
24711 + err = mc_send_command(mc_io, &cmd);
24715 + *obj_id = mc_cmd_read_object_id(&cmd);
24721 + * dpseci_destroy() - Destroy the DPSECI object and release all its resources
24722 + * @mc_io: Pointer to MC portal's I/O object
24723 + * @dprc_token: Parent container token; '0' for default container
24724 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24725 + * @object_id: The object id; it must be a valid id within the container that
24726 + * created this object
24728 + * The function accepts the authentication token of the parent container that
24729 + * created the object (not the one that currently owns the object). The object
24730 + * is searched within parent using the provided 'object_id'.
24731 + * All tokens to the object must be closed before calling destroy.
24733 + * Return: '0' on success, error code otherwise
24735 +int dpseci_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
24738 + struct mc_command cmd = { 0 };
24739 + struct dpseci_cmd_destroy *cmd_params;
24741 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DESTROY,
24744 + cmd_params = (struct dpseci_cmd_destroy *)cmd.params;
24745 + cmd_params->object_id = cpu_to_le32(object_id);
24747 + return mc_send_command(mc_io, &cmd);
24751 + * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames
24752 + * @mc_io: Pointer to MC portal's I/O object
24753 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24754 + * @token: Token of DPSECI object
24756 + * Return: '0' on success, error code otherwise
24758 +int dpseci_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
24760 + struct mc_command cmd = { 0 };
24762 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
24765 + return mc_send_command(mc_io, &cmd);
24769 + * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames
24770 + * @mc_io: Pointer to MC portal's I/O object
24771 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24772 + * @token: Token of DPSECI object
24774 + * Return: '0' on success, error code otherwise
24776 +int dpseci_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
24778 + struct mc_command cmd = { 0 };
24780 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
24784 + return mc_send_command(mc_io, &cmd);
24788 + * dpseci_is_enabled() - Check if the DPSECI is enabled.
24789 + * @mc_io: Pointer to MC portal's I/O object
24790 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24791 + * @token: Token of DPSECI object
24792 + * @en: Returns '1' if object is enabled; '0' otherwise
24794 + * Return: '0' on success, error code otherwise
24796 +int dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
24799 + struct mc_command cmd = { 0 };
24800 + struct dpseci_rsp_is_enabled *rsp_params;
24803 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
24806 + err = mc_send_command(mc_io, &cmd);
24810 + rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
24811 + *en = le32_to_cpu(rsp_params->is_enabled);
24817 + * dpseci_reset() - Reset the DPSECI, returns the object to initial state.
24818 + * @mc_io: Pointer to MC portal's I/O object
24819 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24820 + * @token: Token of DPSECI object
24822 + * Return: '0' on success, error code otherwise
24824 +int dpseci_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
24826 + struct mc_command cmd = { 0 };
24828 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
24832 + return mc_send_command(mc_io, &cmd);
24836 + * dpseci_get_irq_enable() - Get overall interrupt state
24837 + * @mc_io: Pointer to MC portal's I/O object
24838 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24839 + * @token: Token of DPSECI object
24840 + * @irq_index: The interrupt index to configure
24841 + * @en: Returned Interrupt state - enable = 1, disable = 0
24843 + * Return: '0' on success, error code otherwise
24845 +int dpseci_get_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
24846 + u8 irq_index, u8 *en)
24848 + struct mc_command cmd = { 0 };
24849 + struct dpseci_cmd_irq_enable *cmd_params;
24850 + struct dpseci_rsp_get_irq_enable *rsp_params;
24853 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_IRQ_ENABLE,
24856 + cmd_params = (struct dpseci_cmd_irq_enable *)cmd.params;
24857 + cmd_params->irq_index = irq_index;
24858 + err = mc_send_command(mc_io, &cmd);
24862 + rsp_params = (struct dpseci_rsp_get_irq_enable *)cmd.params;
24863 + *en = rsp_params->enable_state;
24869 + * dpseci_set_irq_enable() - Set overall interrupt state.
24870 + * @mc_io: Pointer to MC portal's I/O object
24871 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24872 + * @token: Token of DPSECI object
24873 + * @irq_index: The interrupt index to configure
24874 + * @en: Interrupt state - enable = 1, disable = 0
24876 + * Allows GPP software to control when interrupts are generated.
24877 + * Each interrupt can have up to 32 causes. The enable/disable control's the
24878 + * overall interrupt state. If the interrupt is disabled no causes will cause
24881 + * Return: '0' on success, error code otherwise
24883 +int dpseci_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
24884 + u8 irq_index, u8 en)
24886 + struct mc_command cmd = { 0 };
24887 + struct dpseci_cmd_irq_enable *cmd_params;
24889 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_IRQ_ENABLE,
24892 + cmd_params = (struct dpseci_cmd_irq_enable *)cmd.params;
24893 + cmd_params->irq_index = irq_index;
24894 + cmd_params->enable_state = en;
24896 + return mc_send_command(mc_io, &cmd);
24900 + * dpseci_get_irq_mask() - Get interrupt mask.
24901 + * @mc_io: Pointer to MC portal's I/O object
24902 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24903 + * @token: Token of DPSECI object
24904 + * @irq_index: The interrupt index to configure
24905 + * @mask: Returned event mask to trigger interrupt
24907 + * Every interrupt can have up to 32 causes and the interrupt model supports
24908 + * masking/unmasking each cause independently.
24910 + * Return: '0' on success, error code otherwise
24912 +int dpseci_get_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
24913 + u8 irq_index, u32 *mask)
24915 + struct mc_command cmd = { 0 };
24916 + struct dpseci_cmd_irq_mask *cmd_params;
24919 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_IRQ_MASK,
24922 + cmd_params = (struct dpseci_cmd_irq_mask *)cmd.params;
24923 + cmd_params->irq_index = irq_index;
24924 + err = mc_send_command(mc_io, &cmd);
24928 + *mask = le32_to_cpu(cmd_params->mask);
24934 + * dpseci_set_irq_mask() - Set interrupt mask.
24935 + * @mc_io: Pointer to MC portal's I/O object
24936 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24937 + * @token: Token of DPSECI object
24938 + * @irq_index: The interrupt index to configure
24939 + * @mask: event mask to trigger interrupt;
24941 + * 0 = ignore event
24942 + * 1 = consider event for asserting IRQ
24944 + * Every interrupt can have up to 32 causes and the interrupt model supports
24945 + * masking/unmasking each cause independently
24947 + * Return: '0' on success, error code otherwise
24949 +int dpseci_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
24950 + u8 irq_index, u32 mask)
24952 + struct mc_command cmd = { 0 };
24953 + struct dpseci_cmd_irq_mask *cmd_params;
24955 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_IRQ_MASK,
24958 + cmd_params = (struct dpseci_cmd_irq_mask *)cmd.params;
24959 + cmd_params->mask = cpu_to_le32(mask);
24960 + cmd_params->irq_index = irq_index;
24962 + return mc_send_command(mc_io, &cmd);
24966 + * dpseci_get_irq_status() - Get the current status of any pending interrupts
24967 + * @mc_io: Pointer to MC portal's I/O object
24968 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
24969 + * @token: Token of DPSECI object
24970 + * @irq_index: The interrupt index to configure
24971 + * @status: Returned interrupts status - one bit per cause:
24972 + * 0 = no interrupt pending
24973 + * 1 = interrupt pending
24975 + * Return: '0' on success, error code otherwise
24977 +int dpseci_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
24978 + u8 irq_index, u32 *status)
24980 + struct mc_command cmd = { 0 };
24981 + struct dpseci_cmd_irq_status *cmd_params;
24984 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_IRQ_STATUS,
24987 + cmd_params = (struct dpseci_cmd_irq_status *)cmd.params;
24988 + cmd_params->status = cpu_to_le32(*status);
24989 + cmd_params->irq_index = irq_index;
24990 + err = mc_send_command(mc_io, &cmd);
24994 + *status = le32_to_cpu(cmd_params->status);
25000 + * dpseci_clear_irq_status() - Clear a pending interrupt's status
25001 + * @mc_io: Pointer to MC portal's I/O object
25002 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25003 + * @token: Token of DPSECI object
25004 + * @irq_index: The interrupt index to configure
25005 + * @status: bits to clear (W1C) - one bit per cause:
25006 + * 0 = don't change
25007 + * 1 = clear status bit
25009 + * Return: '0' on success, error code otherwise
25011 +int dpseci_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25012 + u8 irq_index, u32 status)
25014 + struct mc_command cmd = { 0 };
25015 + struct dpseci_cmd_irq_status *cmd_params;
25017 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLEAR_IRQ_STATUS,
25020 + cmd_params = (struct dpseci_cmd_irq_status *)cmd.params;
25021 + cmd_params->status = cpu_to_le32(status);
25022 + cmd_params->irq_index = irq_index;
25024 + return mc_send_command(mc_io, &cmd);
25028 + * dpseci_get_attributes() - Retrieve DPSECI attributes
25029 + * @mc_io: Pointer to MC portal's I/O object
25030 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25031 + * @token: Token of DPSECI object
25032 + * @attr: Returned object's attributes
25034 + * Return: '0' on success, error code otherwise
25036 +int dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25037 + struct dpseci_attr *attr)
25039 + struct mc_command cmd = { 0 };
25040 + struct dpseci_rsp_get_attributes *rsp_params;
25043 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
25046 + err = mc_send_command(mc_io, &cmd);
25050 + rsp_params = (struct dpseci_rsp_get_attributes *)cmd.params;
25051 + attr->id = le32_to_cpu(rsp_params->id);
25052 + attr->num_tx_queues = rsp_params->num_tx_queues;
25053 + attr->num_rx_queues = rsp_params->num_rx_queues;
25054 + attr->options = le32_to_cpu(rsp_params->options);
25060 + * dpseci_set_rx_queue() - Set Rx queue configuration
25061 + * @mc_io: Pointer to MC portal's I/O object
25062 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25063 + * @token: Token of DPSECI object
25064 + * @queue: Select the queue relative to number of priorities configured at
25065 + * DPSECI creation; use DPSECI_ALL_QUEUES to configure all
25066 + * Rx queues identically.
25067 + * @cfg: Rx queue configuration
25069 + * Return: '0' on success, error code otherwise
25071 +int dpseci_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25072 + u8 queue, const struct dpseci_rx_queue_cfg *cfg)
25074 + struct mc_command cmd = { 0 };
25075 + struct dpseci_cmd_queue *cmd_params;
25077 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
25080 + cmd_params = (struct dpseci_cmd_queue *)cmd.params;
25081 + cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
25082 + cmd_params->priority = cfg->dest_cfg.priority;
25083 + cmd_params->queue = queue;
25084 + cmd_params->dest_type = cfg->dest_cfg.dest_type;
25085 + cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
25086 + cmd_params->options = cpu_to_le32(cfg->options);
25087 + cmd_params->order_preservation_en =
25088 + cpu_to_le32(cfg->order_preservation_en);
25090 + return mc_send_command(mc_io, &cmd);
25094 + * dpseci_get_rx_queue() - Retrieve Rx queue attributes
25095 + * @mc_io: Pointer to MC portal's I/O object
25096 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25097 + * @token: Token of DPSECI object
25098 + * @queue: Select the queue relative to number of priorities configured at
25099 + * DPSECI creation
25100 + * @attr: Returned Rx queue attributes
25102 + * Return: '0' on success, error code otherwise
25104 +int dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25105 + u8 queue, struct dpseci_rx_queue_attr *attr)
25107 + struct mc_command cmd = { 0 };
25108 + struct dpseci_cmd_queue *cmd_params;
25111 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
25114 + cmd_params = (struct dpseci_cmd_queue *)cmd.params;
25115 + cmd_params->queue = queue;
25116 + err = mc_send_command(mc_io, &cmd);
25120 + attr->dest_cfg.dest_id = le32_to_cpu(cmd_params->dest_id);
25121 + attr->dest_cfg.priority = cmd_params->priority;
25122 + attr->dest_cfg.dest_type = cmd_params->dest_type;
25123 + attr->user_ctx = le64_to_cpu(cmd_params->user_ctx);
25124 + attr->fqid = le32_to_cpu(cmd_params->fqid);
25125 + attr->order_preservation_en =
25126 + le32_to_cpu(cmd_params->order_preservation_en);
25132 + * dpseci_get_tx_queue() - Retrieve Tx queue attributes
25133 + * @mc_io: Pointer to MC portal's I/O object
25134 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25135 + * @token: Token of DPSECI object
25136 + * @queue: Select the queue relative to number of priorities configured at
25137 + * DPSECI creation
25138 + * @attr: Returned Tx queue attributes
25140 + * Return: '0' on success, error code otherwise
25142 +int dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25143 + u8 queue, struct dpseci_tx_queue_attr *attr)
25145 + struct mc_command cmd = { 0 };
25146 + struct dpseci_cmd_queue *cmd_params;
25147 + struct dpseci_rsp_get_tx_queue *rsp_params;
25150 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
25153 + cmd_params = (struct dpseci_cmd_queue *)cmd.params;
25154 + cmd_params->queue = queue;
25155 + err = mc_send_command(mc_io, &cmd);
25159 + rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
25160 + attr->fqid = le32_to_cpu(rsp_params->fqid);
25161 + attr->priority = rsp_params->priority;
25167 + * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes
25168 + * @mc_io: Pointer to MC portal's I/O object
25169 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25170 + * @token: Token of DPSECI object
25171 + * @attr: Returned SEC attributes
25173 + * Return: '0' on success, error code otherwise
25175 +int dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25176 + struct dpseci_sec_attr *attr)
25178 + struct mc_command cmd = { 0 };
25179 + struct dpseci_rsp_get_sec_attr *rsp_params;
25182 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
25185 + err = mc_send_command(mc_io, &cmd);
25189 + rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
25190 + attr->ip_id = le16_to_cpu(rsp_params->ip_id);
25191 + attr->major_rev = rsp_params->major_rev;
25192 + attr->minor_rev = rsp_params->minor_rev;
25193 + attr->era = rsp_params->era;
25194 + attr->deco_num = rsp_params->deco_num;
25195 + attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
25196 + attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
25197 + attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
25198 + attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
25199 + attr->crc_acc_num = rsp_params->crc_acc_num;
25200 + attr->pk_acc_num = rsp_params->pk_acc_num;
25201 + attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
25202 + attr->rng_acc_num = rsp_params->rng_acc_num;
25203 + attr->md_acc_num = rsp_params->md_acc_num;
25204 + attr->arc4_acc_num = rsp_params->arc4_acc_num;
25205 + attr->des_acc_num = rsp_params->des_acc_num;
25206 + attr->aes_acc_num = rsp_params->aes_acc_num;
25212 + * dpseci_get_sec_counters() - Retrieve SEC accelerator counters
25213 + * @mc_io: Pointer to MC portal's I/O object
25214 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25215 + * @token: Token of DPSECI object
25216 + * @counters: Returned SEC counters
25218 + * Return: '0' on success, error code otherwise
25220 +int dpseci_get_sec_counters(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25221 + struct dpseci_sec_counters *counters)
25223 + struct mc_command cmd = { 0 };
25224 + struct dpseci_rsp_get_sec_counters *rsp_params;
25227 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_COUNTERS,
25230 + err = mc_send_command(mc_io, &cmd);
25234 + rsp_params = (struct dpseci_rsp_get_sec_counters *)cmd.params;
25235 + counters->dequeued_requests =
25236 + le64_to_cpu(rsp_params->dequeued_requests);
25237 + counters->ob_enc_requests = le64_to_cpu(rsp_params->ob_enc_requests);
25238 + counters->ib_dec_requests = le64_to_cpu(rsp_params->ib_dec_requests);
25239 + counters->ob_enc_bytes = le64_to_cpu(rsp_params->ob_enc_bytes);
25240 + counters->ob_prot_bytes = le64_to_cpu(rsp_params->ob_prot_bytes);
25241 + counters->ib_dec_bytes = le64_to_cpu(rsp_params->ib_dec_bytes);
25242 + counters->ib_valid_bytes = le64_to_cpu(rsp_params->ib_valid_bytes);
25248 + * dpseci_get_api_version() - Get Data Path SEC Interface API version
25249 + * @mc_io: Pointer to MC portal's I/O object
25250 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25251 + * @major_ver: Major version of data path sec API
25252 + * @minor_ver: Minor version of data path sec API
25254 + * Return: '0' on success, error code otherwise
25256 +int dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
25257 + u16 *major_ver, u16 *minor_ver)
25259 + struct mc_command cmd = { 0 };
25260 + struct dpseci_rsp_get_api_version *rsp_params;
25263 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
25265 + err = mc_send_command(mc_io, &cmd);
25269 + rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
25270 + *major_ver = le16_to_cpu(rsp_params->major);
25271 + *minor_ver = le16_to_cpu(rsp_params->minor);
25277 + * dpseci_set_opr() - Set Order Restoration configuration
25278 + * @mc_io: Pointer to MC portal's I/O object
25279 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25280 + * @token: Token of DPSECI object
25281 + * @index: The queue index
25282 + * @options: Configuration mode options; can be OPR_OPT_CREATE or
25284 + * @cfg: Configuration options for the OPR
25286 + * Return: '0' on success, error code otherwise
25288 +int dpseci_set_opr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u8 index,
25289 + u8 options, struct opr_cfg *cfg)
25291 + struct mc_command cmd = { 0 };
25292 + struct dpseci_cmd_opr *cmd_params;
25294 + cmd.header = mc_encode_cmd_header(
25295 + DPSECI_CMDID_SET_OPR,
25298 + cmd_params = (struct dpseci_cmd_opr *)cmd.params;
25299 + cmd_params->index = index;
25300 + cmd_params->options = options;
25301 + cmd_params->oloe = cfg->oloe;
25302 + cmd_params->oeane = cfg->oeane;
25303 + cmd_params->olws = cfg->olws;
25304 + cmd_params->oa = cfg->oa;
25305 + cmd_params->oprrws = cfg->oprrws;
25307 + return mc_send_command(mc_io, &cmd);
25311 + * dpseci_get_opr() - Retrieve Order Restoration config and query
25312 + * @mc_io: Pointer to MC portal's I/O object
25313 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25314 + * @token: Token of DPSECI object
25315 + * @index: The queue index
25316 + * @cfg: Returned OPR configuration
25317 + * @qry: Returned OPR query
25319 + * Return: '0' on success, error code otherwise
25321 +int dpseci_get_opr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u8 index,
25322 + struct opr_cfg *cfg, struct opr_qry *qry)
25324 + struct mc_command cmd = { 0 };
25325 + struct dpseci_cmd_opr *cmd_params;
25326 + struct dpseci_rsp_get_opr *rsp_params;
25329 + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_OPR,
25332 + cmd_params = (struct dpseci_cmd_opr *)cmd.params;
25333 + cmd_params->index = index;
25334 + err = mc_send_command(mc_io, &cmd);
25338 + rsp_params = (struct dpseci_rsp_get_opr *)cmd.params;
25339 + qry->rip = dpseci_get_field(rsp_params->rip_enable, OPR_RIP);
25340 + qry->enable = dpseci_get_field(rsp_params->rip_enable, OPR_ENABLE);
25341 + cfg->oloe = rsp_params->oloe;
25342 + cfg->oeane = rsp_params->oeane;
25343 + cfg->olws = rsp_params->olws;
25344 + cfg->oa = rsp_params->oa;
25345 + cfg->oprrws = rsp_params->oprrws;
25346 + qry->nesn = le16_to_cpu(rsp_params->nesn);
25347 + qry->ndsn = le16_to_cpu(rsp_params->ndsn);
25348 + qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
25349 + qry->tseq_nlis = dpseci_get_field(rsp_params->tseq_nlis, OPR_TSEQ_NLIS);
25350 + qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
25351 + qry->hseq_nlis = dpseci_get_field(rsp_params->tseq_nlis, OPR_HSEQ_NLIS);
25352 + qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
25353 + qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
25354 + qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
25355 + qry->opr_id = le16_to_cpu(rsp_params->opr_id);
25361 + * dpseci_set_congestion_notification() - Set congestion group
25362 + * notification configuration
25363 + * @mc_io: Pointer to MC portal's I/O object
25364 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25365 + * @token: Token of DPSECI object
25366 + * @cfg: congestion notification configuration
25368 + * Return: '0' on success, error code otherwise
25370 +int dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
25371 + u16 token, const struct dpseci_congestion_notification_cfg *cfg)
25373 + struct mc_command cmd = { 0 };
25374 + struct dpseci_cmd_congestion_notification *cmd_params;
25376 + cmd.header = mc_encode_cmd_header(
25377 + DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
25380 + cmd_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
25381 + cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
25382 + cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
25383 + cmd_params->priority = cfg->dest_cfg.priority;
25384 + dpseci_set_field(cmd_params->options, CGN_DEST_TYPE,
25385 + cfg->dest_cfg.dest_type);
25386 + dpseci_set_field(cmd_params->options, CGN_UNITS, cfg->units);
25387 + cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
25388 + cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
25389 + cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
25390 + cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
25392 + return mc_send_command(mc_io, &cmd);
25396 + * dpseci_get_congestion_notification() - Get congestion group notification
25398 + * @mc_io: Pointer to MC portal's I/O object
25399 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
25400 + * @token: Token of DPSECI object
25401 + * @cfg: congestion notification configuration
25403 + * Return: '0' on success, error code otherwise
25405 +int dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
25406 + u16 token, struct dpseci_congestion_notification_cfg *cfg)
25408 + struct mc_command cmd = { 0 };
25409 + struct dpseci_cmd_congestion_notification *rsp_params;
25412 + cmd.header = mc_encode_cmd_header(
25413 + DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
25416 + err = mc_send_command(mc_io, &cmd);
25420 + rsp_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
25421 + cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
25422 + cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
25423 + cfg->dest_cfg.priority = rsp_params->priority;
25424 + cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->options,
25426 + cfg->units = dpseci_get_field(rsp_params->options, CGN_UNITS);
25427 + cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
25428 + cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
25429 + cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
25430 + cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
25435 +++ b/drivers/crypto/caam/dpseci.h
25438 + * Copyright 2013-2016 Freescale Semiconductor Inc.
25439 + * Copyright 2017 NXP
25441 + * Redistribution and use in source and binary forms, with or without
25442 + * modification, are permitted provided that the following conditions are met:
25443 + * * Redistributions of source code must retain the above copyright
25444 + * notice, this list of conditions and the following disclaimer.
25445 + * * Redistributions in binary form must reproduce the above copyright
25446 + * notice, this list of conditions and the following disclaimer in the
25447 + * documentation and/or other materials provided with the distribution.
25448 + * * Neither the names of the above-listed copyright holders nor the
25449 + * names of any contributors may be used to endorse or promote products
25450 + * derived from this software without specific prior written permission.
25453 + * ALTERNATIVELY, this software may be distributed under the terms of the
25454 + * GNU General Public License ("GPL") as published by the Free Software
25455 + * Foundation, either version 2 of that License or (at your option) any
25458 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25459 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25460 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25461 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25462 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25463 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25464 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25465 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25466 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25467 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25468 + * POSSIBILITY OF SUCH DAMAGE.
25470 +#ifndef _DPSECI_H_
25471 +#define _DPSECI_H_
25474 + * Data Path SEC Interface API
25475 + * Contains initialization APIs and runtime control APIs for DPSECI
25483 + * General DPSECI macros
25487 + * Maximum number of Tx/Rx priorities per DPSECI object
25489 +#define DPSECI_PRIO_NUM 8
25492 + * All queues considered; see dpseci_set_rx_queue()
25494 +#define DPSECI_ALL_QUEUES (u8)(-1)
25496 +int dpseci_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpseci_id,
25499 +int dpseci_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
25502 + * Enable the Congestion Group support
25504 +#define DPSECI_OPT_HAS_CG 0x000020
25507 + * Enable the Order Restoration support
25509 +#define DPSECI_OPT_HAS_OPR 0x000040
25512 + * Order Point Records are shared for the entire DPSECI
25514 +#define DPSECI_OPT_OPR_SHARED 0x000080
25517 + * struct dpseci_cfg - Structure representing DPSECI configuration
25518 + * @options: Any combination of the following options:
25519 + * DPSECI_OPT_HAS_CG
25520 + * DPSECI_OPT_HAS_OPR
25521 + * DPSECI_OPT_OPR_SHARED
25522 + * @num_tx_queues: num of queues towards the SEC
25523 + * @num_rx_queues: num of queues back from the SEC
25524 + * @priorities: Priorities for the SEC hardware processing;
25525 + * each place in the array is the priority of the tx queue
25526 + * towards the SEC;
25527 + * valid priorities are configured with values 1-8;
25529 +struct dpseci_cfg {
25531 + u8 num_tx_queues;
25532 + u8 num_rx_queues;
25533 + u8 priorities[DPSECI_PRIO_NUM];
25536 +int dpseci_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
25537 + const struct dpseci_cfg *cfg, u32 *obj_id);
25539 +int dpseci_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
25542 +int dpseci_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
25544 +int dpseci_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
25546 +int dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25549 +int dpseci_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
25551 +int dpseci_get_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25552 + u8 irq_index, u8 *en);
25554 +int dpseci_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25555 + u8 irq_index, u8 en);
25557 +int dpseci_get_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25558 + u8 irq_index, u32 *mask);
25560 +int dpseci_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25561 + u8 irq_index, u32 mask);
25563 +int dpseci_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25564 + u8 irq_index, u32 *status);
25566 +int dpseci_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25567 + u8 irq_index, u32 status);
25570 + * struct dpseci_attr - Structure representing DPSECI attributes
25571 + * @id: DPSECI object ID
25572 + * @num_tx_queues: number of queues towards the SEC
25573 + * @num_rx_queues: number of queues back from the SEC
25574 + * @options: any combination of the following options:
25575 + * DPSECI_OPT_HAS_CG
25576 + * DPSECI_OPT_HAS_OPR
25577 + * DPSECI_OPT_OPR_SHARED
25579 +struct dpseci_attr {
25581 + u8 num_tx_queues;
25582 + u8 num_rx_queues;
25586 +int dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25587 + struct dpseci_attr *attr);
25590 + * enum dpseci_dest - DPSECI destination types
25591 + * @DPSECI_DEST_NONE: Unassigned destination; The queue is set in parked mode
25592 + * and does not generate FQDAN notifications; user is expected to dequeue
25593 + * from the queue based on polling or other user-defined method
25594 + * @DPSECI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
25595 + * notifications to the specified DPIO; user is expected to dequeue from
25596 + * the queue only after notification is received
25597 + * @DPSECI_DEST_DPCON: The queue is set in schedule mode and does not generate
25598 + * FQDAN notifications, but is connected to the specified DPCON object;
25599 + * user is expected to dequeue from the DPCON channel
25601 +enum dpseci_dest {
25602 + DPSECI_DEST_NONE = 0,
25603 + DPSECI_DEST_DPIO,
25604 + DPSECI_DEST_DPCON
25608 + * struct dpseci_dest_cfg - Structure representing DPSECI destination parameters
25609 + * @dest_type: Destination type
25610 + * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
25611 + * @priority: Priority selection within the DPIO or DPCON channel; valid values
25612 + * are 0-1 or 0-7, depending on the number of priorities in that channel;
25613 + * not relevant for 'DPSECI_DEST_NONE' option
25615 +struct dpseci_dest_cfg {
25616 + enum dpseci_dest dest_type;
25622 + * DPSECI queue modification options
25626 + * Select to modify the user's context associated with the queue
25628 +#define DPSECI_QUEUE_OPT_USER_CTX 0x00000001
25631 + * Select to modify the queue's destination
25633 +#define DPSECI_QUEUE_OPT_DEST 0x00000002
25636 + * Select to modify the queue's order preservation
25638 +#define DPSECI_QUEUE_OPT_ORDER_PRESERVATION 0x00000004
25641 + * struct dpseci_rx_queue_cfg - DPSECI RX queue configuration
25642 + * @options: Flags representing the suggested modifications to the queue;
25643 + * Use any combination of 'DPSECI_QUEUE_OPT_<X>' flags
25644 + * @order_preservation_en: order preservation configuration for the rx queue
25645 + * valid only if 'DPSECI_QUEUE_OPT_ORDER_PRESERVATION' is contained in 'options'
25646 + * @user_ctx: User context value provided in the frame descriptor of each
25647 + * dequeued frame; valid only if 'DPSECI_QUEUE_OPT_USER_CTX' is contained
25649 + * @dest_cfg: Queue destination parameters; valid only if
25650 + * 'DPSECI_QUEUE_OPT_DEST' is contained in 'options'
25652 +struct dpseci_rx_queue_cfg {
25654 + int order_preservation_en;
25656 + struct dpseci_dest_cfg dest_cfg;
25659 +int dpseci_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25660 + u8 queue, const struct dpseci_rx_queue_cfg *cfg);
25663 + * struct dpseci_rx_queue_attr - Structure representing attributes of Rx queues
25664 + * @user_ctx: User context value provided in the frame descriptor of each
25666 + * @order_preservation_en: Status of the order preservation configuration on the
25668 + * @dest_cfg: Queue destination configuration
25669 + * @fqid: Virtual FQID value to be used for dequeue operations
25671 +struct dpseci_rx_queue_attr {
25673 + int order_preservation_en;
25674 + struct dpseci_dest_cfg dest_cfg;
25678 +int dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25679 + u8 queue, struct dpseci_rx_queue_attr *attr);
25682 + * struct dpseci_tx_queue_attr - Structure representing attributes of Tx queues
25683 + * @fqid: Virtual FQID to be used for sending frames to SEC hardware
25684 + * @priority: SEC hardware processing priority for the queue
25686 +struct dpseci_tx_queue_attr {
25691 +int dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25692 + u8 queue, struct dpseci_tx_queue_attr *attr);
25695 + * struct dpseci_sec_attr - Structure representing attributes of the SEC
25696 + * hardware accelerator
25697 + * @ip_id: ID for SEC
25698 + * @major_rev: Major revision number for SEC
25699 + * @minor_rev: Minor revision number for SEC
25701 + * @deco_num: The number of copies of the DECO that are implemented in this
25703 + * @zuc_auth_acc_num: The number of copies of ZUCA that are implemented in this
25705 + * @zuc_enc_acc_num: The number of copies of ZUCE that are implemented in this
25707 + * @snow_f8_acc_num: The number of copies of the SNOW-f8 module that are
25708 + * implemented in this version of SEC
25709 + * @snow_f9_acc_num: The number of copies of the SNOW-f9 module that are
25710 + * implemented in this version of SEC
25711 + * @crc_acc_num: The number of copies of the CRC module that are implemented in
25712 + * this version of SEC
25713 + * @pk_acc_num: The number of copies of the Public Key module that are
25714 + * implemented in this version of SEC
25715 + * @kasumi_acc_num: The number of copies of the Kasumi module that are
25716 + * implemented in this version of SEC
25717 + * @rng_acc_num: The number of copies of the Random Number Generator that are
25718 + * implemented in this version of SEC
25719 + * @md_acc_num: The number of copies of the MDHA (Hashing module) that are
25720 + * implemented in this version of SEC
25721 + * @arc4_acc_num: The number of copies of the ARC4 module that are implemented
25722 + * in this version of SEC
25723 + * @des_acc_num: The number of copies of the DES module that are implemented in
25724 + * this version of SEC
25725 + * @aes_acc_num: The number of copies of the AES module that are implemented in
25726 + * this version of SEC
25728 +struct dpseci_sec_attr {
25734 + u8 zuc_auth_acc_num;
25735 + u8 zuc_enc_acc_num;
25736 + u8 snow_f8_acc_num;
25737 + u8 snow_f9_acc_num;
25740 + u8 kasumi_acc_num;
25748 +int dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25749 + struct dpseci_sec_attr *attr);
25752 + * struct dpseci_sec_counters - Structure representing global SEC counters and
25753 + * not per dpseci counters
25754 + * @dequeued_requests: Number of Requests Dequeued
25755 + * @ob_enc_requests: Number of Outbound Encrypt Requests
25756 + * @ib_dec_requests: Number of Inbound Decrypt Requests
25757 + * @ob_enc_bytes: Number of Outbound Bytes Encrypted
25758 + * @ob_prot_bytes: Number of Outbound Bytes Protected
25759 + * @ib_dec_bytes: Number of Inbound Bytes Decrypted
25760 + * @ib_valid_bytes: Number of Inbound Bytes Validated
25762 +struct dpseci_sec_counters {
25763 + u64 dequeued_requests;
25764 + u64 ob_enc_requests;
25765 + u64 ib_dec_requests;
25766 + u64 ob_enc_bytes;
25767 + u64 ob_prot_bytes;
25768 + u64 ib_dec_bytes;
25769 + u64 ib_valid_bytes;
25772 +int dpseci_get_sec_counters(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25773 + struct dpseci_sec_counters *counters);
25775 +int dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
25776 + u16 *major_ver, u16 *minor_ver);
25778 +int dpseci_set_opr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u8 index,
25779 + u8 options, struct opr_cfg *cfg);
25781 +int dpseci_get_opr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u8 index,
25782 + struct opr_cfg *cfg, struct opr_qry *qry);
25785 + * enum dpseci_congestion_unit - DPSECI congestion units
25786 + * @DPSECI_CONGESTION_UNIT_BYTES: bytes units
25787 + * @DPSECI_CONGESTION_UNIT_FRAMES: frames units
25789 +enum dpseci_congestion_unit {
25790 + DPSECI_CONGESTION_UNIT_BYTES = 0,
25791 + DPSECI_CONGESTION_UNIT_FRAMES
25794 +#define DPSECI_CGN_MODE_WRITE_MEM_ON_ENTER 0x00000001
25795 +#define DPSECI_CGN_MODE_WRITE_MEM_ON_EXIT 0x00000002
25796 +#define DPSECI_CGN_MODE_COHERENT_WRITE 0x00000004
25797 +#define DPSECI_CGN_MODE_NOTIFY_DEST_ON_ENTER 0x00000008
25798 +#define DPSECI_CGN_MODE_NOTIFY_DEST_ON_EXIT 0x00000010
25799 +#define DPSECI_CGN_MODE_INTR_COALESCING_DISABLED 0x00000020
25802 + * struct dpseci_congestion_notification_cfg - congestion notification
25804 + * @units: units type
25805 + * @threshold_entry: above this threshold we enter a congestion state.
25806 + * set it to '0' to disable it
25807 + * @threshold_exit: below this threshold we exit the congestion state.
25808 + * @message_ctx: The context that will be part of the CSCN message
25809 + * @message_iova: I/O virtual address (must be in DMA-able memory),
25810 + * must be 16B aligned;
25811 + * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
25812 + * @notification_mode: Mask of available options; use 'DPSECI_CGN_MODE_<X>'
25815 +struct dpseci_congestion_notification_cfg {
25816 + enum dpseci_congestion_unit units;
25817 + u32 threshold_entry;
25818 + u32 threshold_exit;
25820 + u64 message_iova;
25821 + struct dpseci_dest_cfg dest_cfg;
25822 + u16 notification_mode;
25825 +int dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
25826 + u16 token, const struct dpseci_congestion_notification_cfg *cfg);
25828 +int dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
25829 + u16 token, struct dpseci_congestion_notification_cfg *cfg);
25831 +#endif /* _DPSECI_H_ */
25833 +++ b/drivers/crypto/caam/dpseci_cmd.h
25836 + * Copyright 2013-2016 Freescale Semiconductor Inc.
25837 + * Copyright 2017 NXP
25839 + * Redistribution and use in source and binary forms, with or without
25840 + * modification, are permitted provided that the following conditions are met:
25841 + * * Redistributions of source code must retain the above copyright
25842 + * notice, this list of conditions and the following disclaimer.
25843 + * * Redistributions in binary form must reproduce the above copyright
25844 + * notice, this list of conditions and the following disclaimer in the
25845 + * documentation and/or other materials provided with the distribution.
25846 + * * Neither the names of the above-listed copyright holders nor the
25847 + * names of any contributors may be used to endorse or promote products
25848 + * derived from this software without specific prior written permission.
25851 + * ALTERNATIVELY, this software may be distributed under the terms of the
25852 + * GNU General Public License ("GPL") as published by the Free Software
25853 + * Foundation, either version 2 of that License or (at your option) any
25856 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25857 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25858 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25859 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25860 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25861 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25862 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25863 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25864 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25865 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25866 + * POSSIBILITY OF SUCH DAMAGE.
25869 +#ifndef _DPSECI_CMD_H_
25870 +#define _DPSECI_CMD_H_
25872 +/* DPSECI Version */
25873 +#define DPSECI_VER_MAJOR 5
25874 +#define DPSECI_VER_MINOR 1
25876 +#define DPSECI_VER(maj, min) (((maj) << 16) | (min))
25877 +#define DPSECI_VERSION DPSECI_VER(DPSECI_VER_MAJOR, DPSECI_VER_MINOR)
25881 +#define DPSECI_CMDID_CLOSE 0x8001
25882 +#define DPSECI_CMDID_OPEN 0x8091
25883 +#define DPSECI_CMDID_CREATE 0x9092
25884 +#define DPSECI_CMDID_DESTROY 0x9891
25885 +#define DPSECI_CMDID_GET_API_VERSION 0xa091
25887 +#define DPSECI_CMDID_ENABLE 0x0021
25888 +#define DPSECI_CMDID_DISABLE 0x0031
25889 +#define DPSECI_CMDID_GET_ATTR 0x0041
25890 +#define DPSECI_CMDID_RESET 0x0051
25891 +#define DPSECI_CMDID_IS_ENABLED 0x0061
25893 +#define DPSECI_CMDID_SET_IRQ_ENABLE 0x0121
25894 +#define DPSECI_CMDID_GET_IRQ_ENABLE 0x0131
25895 +#define DPSECI_CMDID_SET_IRQ_MASK 0x0141
25896 +#define DPSECI_CMDID_GET_IRQ_MASK 0x0151
25897 +#define DPSECI_CMDID_GET_IRQ_STATUS 0x0161
25898 +#define DPSECI_CMDID_CLEAR_IRQ_STATUS 0x0171
25900 +#define DPSECI_CMDID_SET_RX_QUEUE 0x1941
25901 +#define DPSECI_CMDID_GET_RX_QUEUE 0x1961
25902 +#define DPSECI_CMDID_GET_TX_QUEUE 0x1971
25903 +#define DPSECI_CMDID_GET_SEC_ATTR 0x1981
25904 +#define DPSECI_CMDID_GET_SEC_COUNTERS 0x1991
25905 +#define DPSECI_CMDID_SET_OPR 0x19A1
25906 +#define DPSECI_CMDID_GET_OPR 0x19B1
25908 +#define DPSECI_CMDID_SET_CONGESTION_NOTIFICATION 0x1701
25909 +#define DPSECI_CMDID_GET_CONGESTION_NOTIFICATION 0x1711
25911 +/* Macros for accessing command fields smaller than 1 byte */
25912 +#define DPSECI_MASK(field) \
25913 + GENMASK(DPSECI_##field##_SHIFT + DPSECI_##field##_SIZE - 1, \
25914 + DPSECI_##field##_SHIFT)
25916 +#define dpseci_set_field(var, field, val) \
25917 + ((var) |= (((val) << DPSECI_##field##_SHIFT) & DPSECI_MASK(field)))
25919 +#define dpseci_get_field(var, field) \
25920 + (((var) & DPSECI_MASK(field)) >> DPSECI_##field##_SHIFT)
25922 +struct dpseci_cmd_open {
25923 + __le32 dpseci_id;
25926 +struct dpseci_cmd_create {
25927 + u8 priorities[8];
25928 + u8 num_tx_queues;
25929 + u8 num_rx_queues;
25934 +struct dpseci_cmd_destroy {
25935 + __le32 object_id;
25938 +struct dpseci_rsp_is_enabled {
25939 + __le32 is_enabled;
25942 +struct dpseci_cmd_irq_enable {
25948 +struct dpseci_rsp_get_irq_enable {
25952 +struct dpseci_cmd_irq_mask {
25957 +struct dpseci_cmd_irq_status {
25962 +struct dpseci_rsp_get_attributes {
25965 + u8 num_tx_queues;
25966 + u8 num_rx_queues;
25971 +struct dpseci_cmd_queue {
25982 + __le32 order_preservation_en;
25985 +struct dpseci_rsp_get_tx_queue {
25991 +struct dpseci_rsp_get_sec_attr {
25998 + u8 zuc_auth_acc_num;
25999 + u8 zuc_enc_acc_num;
26001 + u8 snow_f8_acc_num;
26002 + u8 snow_f9_acc_num;
26006 + u8 kasumi_acc_num;
26015 +struct dpseci_rsp_get_sec_counters {
26016 + __le64 dequeued_requests;
26017 + __le64 ob_enc_requests;
26018 + __le64 ib_dec_requests;
26019 + __le64 ob_enc_bytes;
26020 + __le64 ob_prot_bytes;
26021 + __le64 ib_dec_bytes;
26022 + __le64 ib_valid_bytes;
26025 +struct dpseci_rsp_get_api_version {
26030 +struct dpseci_cmd_opr {
26042 +#define DPSECI_OPR_RIP_SHIFT 0
26043 +#define DPSECI_OPR_RIP_SIZE 1
26044 +#define DPSECI_OPR_ENABLE_SHIFT 1
26045 +#define DPSECI_OPR_ENABLE_SIZE 1
26046 +#define DPSECI_OPR_TSEQ_NLIS_SHIFT 1
26047 +#define DPSECI_OPR_TSEQ_NLIS_SIZE 1
26048 +#define DPSECI_OPR_HSEQ_NLIS_SHIFT 1
26049 +#define DPSECI_OPR_HSEQ_NLIS_SIZE 1
26051 +struct dpseci_rsp_get_opr {
26079 +#define DPSECI_CGN_DEST_TYPE_SHIFT 0
26080 +#define DPSECI_CGN_DEST_TYPE_SIZE 4
26081 +#define DPSECI_CGN_UNITS_SHIFT 4
26082 +#define DPSECI_CGN_UNITS_SIZE 2
26084 +struct dpseci_cmd_congestion_notification {
26086 + __le16 notification_mode;
26089 + __le64 message_iova;
26090 + __le64 message_ctx;
26091 + __le32 threshold_entry;
26092 + __le32 threshold_exit;
26095 +#endif /* _DPSECI_CMD_H_ */
26096 --- a/drivers/crypto/caam/error.c
26097 +++ b/drivers/crypto/caam/error.c
26100 #include "compat.h"
26102 -#include "intern.h"
26109 +#include <linux/highmem.h>
26111 +void caam_dump_sg(const char *level, const char *prefix_str, int prefix_type,
26112 + int rowsize, int groupsize, struct scatterlist *sg,
26113 + size_t tlen, bool ascii)
26115 + struct scatterlist *it;
26120 + for (it = sg; it && tlen > 0 ; it = sg_next(sg)) {
26122 + * make sure the scatterlist's page
26123 + * has a valid virtual memory mapping
26125 + it_page = kmap_atomic(sg_page(it));
26126 + if (unlikely(!it_page)) {
26127 + pr_err("caam_dump_sg: kmap failed\n");
26131 + buf = it_page + it->offset;
26132 + len = min_t(size_t, tlen, it->length);
26133 + print_hex_dump(level, prefix_str, prefix_type, rowsize,
26134 + groupsize, buf, len, ascii);
26137 + kunmap_atomic(it_page);
26143 +void caam_dump_sg(const char *level, const char *prefix_str, int prefix_type,
26144 + int rowsize, int groupsize, struct scatterlist *sg,
26145 + size_t tlen, bool ascii)
26150 +EXPORT_SYMBOL(caam_dump_sg);
26152 static const struct {
26154 const char *error_text;
26155 @@ -69,6 +112,54 @@ static const struct {
26156 { 0xF1, "3GPP HFN matches or exceeds the Threshold" },
26159 +static const struct {
26161 + const char *error_text;
26162 +} qi_error_list[] = {
26163 + { 0x1F, "Job terminated by FQ or ICID flush" },
26164 + { 0x20, "FD format error"},
26165 + { 0x21, "FD command format error"},
26166 + { 0x23, "FL format error"},
26167 + { 0x25, "CRJD specified in FD, but not enabled in FLC"},
26168 + { 0x30, "Max. buffer size too small"},
26169 + { 0x31, "DHR exceeds max. buffer size (allocate mode, S/G format)"},
26170 + { 0x32, "SGT exceeds max. buffer size (allocate mode, S/G format"},
26171 + { 0x33, "Size over/underflow (allocate mode)"},
26172 + { 0x34, "Size over/underflow (reuse mode)"},
26173 + { 0x35, "Length exceeds max. short length (allocate mode, S/G/ format)"},
26174 + { 0x36, "Memory footprint exceeds max. value (allocate mode, S/G/ format)"},
26175 + { 0x41, "SBC frame format not supported (allocate mode)"},
26176 + { 0x42, "Pool 0 invalid / pool 1 size < pool 0 size (allocate mode)"},
26177 + { 0x43, "Annotation output enabled but ASAR = 0 (allocate mode)"},
26178 + { 0x44, "Unsupported or reserved frame format or SGHR = 1 (reuse mode)"},
26179 + { 0x45, "DHR correction underflow (reuse mode, single buffer format)"},
26180 + { 0x46, "Annotation length exceeds offset (reuse mode)"},
26181 + { 0x48, "Annotation output enabled but ASA limited by ASAR (reuse mode)"},
26182 + { 0x49, "Data offset correction exceeds input frame data length (reuse mode)"},
26183 + { 0x4B, "Annotation output enabled but ASA cannote be expanded (frame list)"},
26184 + { 0x51, "Unsupported IF reuse mode"},
26185 + { 0x52, "Unsupported FL use mode"},
26186 + { 0x53, "Unsupported RJD use mode"},
26187 + { 0x54, "Unsupported inline descriptor use mode"},
26188 + { 0xC0, "Table buffer pool 0 depletion"},
26189 + { 0xC1, "Table buffer pool 1 depletion"},
26190 + { 0xC2, "Data buffer pool 0 depletion, no OF allocated"},
26191 + { 0xC3, "Data buffer pool 1 depletion, no OF allocated"},
26192 + { 0xC4, "Data buffer pool 0 depletion, partial OF allocated"},
26193 + { 0xC5, "Data buffer pool 1 depletion, partial OF allocated"},
26194 + { 0xD0, "FLC read error"},
26195 + { 0xD1, "FL read error"},
26196 + { 0xD2, "FL write error"},
26197 + { 0xD3, "OF SGT write error"},
26198 + { 0xD4, "PTA read error"},
26199 + { 0xD5, "PTA write error"},
26200 + { 0xD6, "OF SGT F-bit write error"},
26201 + { 0xD7, "ASA write error"},
26202 + { 0xE1, "FLC[ICR]=0 ICID error"},
26203 + { 0xE2, "FLC[ICR]=1 ICID error"},
26204 + { 0xE4, "source of ICID flush not trusted (BDI = 0)"},
26207 static const char * const cha_id_list[] = {
26210 @@ -146,10 +237,9 @@ static void report_ccb_status(struct dev
26211 strlen(rng_err_id_list[err_id])) {
26212 /* RNG-only error */
26213 err_str = rng_err_id_list[err_id];
26214 - } else if (err_id < ARRAY_SIZE(err_id_list))
26216 err_str = err_id_list[err_id];
26218 - snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
26222 * CCB ICV check failures are part of normal operation life;
26223 @@ -198,6 +288,27 @@ static void report_deco_status(struct de
26224 status, error, idx_str, idx, err_str, err_err_code);
26227 +static void report_qi_status(struct device *qidev, const u32 status,
26228 + const char *error)
26230 + u8 err_id = status & JRSTA_QIERR_ERROR_MASK;
26231 + const char *err_str = "unidentified error value 0x";
26232 + char err_err_code[3] = { 0 };
26235 + for (i = 0; i < ARRAY_SIZE(qi_error_list); i++)
26236 + if (qi_error_list[i].value == err_id)
26239 + if (i != ARRAY_SIZE(qi_error_list) && qi_error_list[i].error_text)
26240 + err_str = qi_error_list[i].error_text;
26242 + snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
26244 + dev_err(qidev, "%08x: %s: %s%s\n",
26245 + status, error, err_str, err_err_code);
26248 static void report_jr_status(struct device *jrdev, const u32 status,
26251 @@ -212,7 +323,7 @@ static void report_cond_code_status(stru
26252 status, error, __func__);
26255 -void caam_jr_strstatus(struct device *jrdev, u32 status)
26256 +void caam_strstatus(struct device *jrdev, u32 status, bool qi_v2)
26258 static const struct stat_src {
26259 void (*report_ssed)(struct device *jrdev, const u32 status,
26260 @@ -224,7 +335,7 @@ void caam_jr_strstatus(struct device *jr
26261 { report_ccb_status, "CCB" },
26262 { report_jump_status, "Jump" },
26263 { report_deco_status, "DECO" },
26264 - { NULL, "Queue Manager Interface" },
26265 + { report_qi_status, "Queue Manager Interface" },
26266 { report_jr_status, "Job Ring" },
26267 { report_cond_code_status, "Condition Code" },
26269 @@ -250,4 +361,4 @@ void caam_jr_strstatus(struct device *jr
26271 dev_err(jrdev, "%d: unknown error source\n", ssrc);
26273 -EXPORT_SYMBOL(caam_jr_strstatus);
26274 +EXPORT_SYMBOL(caam_strstatus);
26275 --- a/drivers/crypto/caam/error.h
26276 +++ b/drivers/crypto/caam/error.h
26278 #ifndef CAAM_ERROR_H
26279 #define CAAM_ERROR_H
26280 #define CAAM_ERROR_STR_MAX 302
26281 -void caam_jr_strstatus(struct device *jrdev, u32 status);
26283 +void caam_strstatus(struct device *dev, u32 status, bool qi_v2);
26285 +#define caam_jr_strstatus(jrdev, status) caam_strstatus(jrdev, status, false)
26286 +#define caam_qi2_strstatus(qidev, status) caam_strstatus(qidev, status, true)
26288 +void caam_dump_sg(const char *level, const char *prefix_str, int prefix_type,
26289 + int rowsize, int groupsize, struct scatterlist *sg,
26290 + size_t tlen, bool ascii);
26291 #endif /* CAAM_ERROR_H */
26292 --- a/drivers/crypto/caam/intern.h
26293 +++ b/drivers/crypto/caam/intern.h
26294 @@ -64,10 +64,9 @@ struct caam_drv_private_jr {
26295 * Driver-private storage for a single CAAM block instance
26297 struct caam_drv_private {
26299 - struct device *dev;
26300 - struct platform_device **jrpdev; /* Alloc'ed array per sub-device */
26301 - struct platform_device *pdev;
26302 +#ifdef CONFIG_CAAM_QI
26303 + struct device *qidev;
26306 /* Physical-presence section */
26307 struct caam_ctrl __iomem *ctrl; /* controller region */
26308 @@ -84,6 +83,7 @@ struct caam_drv_private {
26309 u8 qi_present; /* Nonzero if QI present in device */
26310 int secvio_irq; /* Security violation interrupt number */
26311 int virt_en; /* Virtualization enabled in CAAM */
26312 + int era; /* CAAM Era (internal HW revision) */
26314 #define RNG4_MAX_HANDLES 2
26316 @@ -103,11 +103,6 @@ struct caam_drv_private {
26317 #ifdef CONFIG_DEBUG_FS
26318 struct dentry *dfs_root;
26319 struct dentry *ctl; /* controller dir */
26320 - struct dentry *ctl_rq_dequeued, *ctl_ob_enc_req, *ctl_ib_dec_req;
26321 - struct dentry *ctl_ob_enc_bytes, *ctl_ob_prot_bytes;
26322 - struct dentry *ctl_ib_dec_bytes, *ctl_ib_valid_bytes;
26323 - struct dentry *ctl_faultaddr, *ctl_faultdetail, *ctl_faultstatus;
26325 struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap;
26326 struct dentry *ctl_kek, *ctl_tkek, *ctl_tdsk;
26328 @@ -115,4 +110,22 @@ struct caam_drv_private {
26330 void caam_jr_algapi_init(struct device *dev);
26331 void caam_jr_algapi_remove(struct device *dev);
26333 +#ifdef CONFIG_DEBUG_FS
26334 +static int caam_debugfs_u64_get(void *data, u64 *val)
26336 + *val = caam64_to_cpu(*(u64 *)data);
26340 +static int caam_debugfs_u32_get(void *data, u64 *val)
26342 + *val = caam32_to_cpu(*(u32 *)data);
26346 +DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u32_ro, caam_debugfs_u32_get, NULL, "%llu\n");
26347 +DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u64_ro, caam_debugfs_u64_get, NULL, "%llu\n");
26350 #endif /* INTERN_H */
26351 --- a/drivers/crypto/caam/jr.c
26352 +++ b/drivers/crypto/caam/jr.c
26354 #include <linux/of_address.h>
26356 #include "compat.h"
26361 @@ -22,6 +23,14 @@ struct jr_driver_data {
26363 static struct jr_driver_data driver_data;
26365 +static int jr_driver_probed;
26367 +int caam_jr_driver_probed(void)
26369 + return jr_driver_probed;
26371 +EXPORT_SYMBOL(caam_jr_driver_probed);
26373 static int caam_reset_hw_jr(struct device *dev)
26375 struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
26376 @@ -118,6 +127,8 @@ static int caam_jr_remove(struct platfor
26377 dev_err(jrdev, "Failed to shut down job ring\n");
26378 irq_dispose_mapping(jrpriv->irq);
26380 + jr_driver_probed--;
26385 @@ -280,6 +291,36 @@ struct device *caam_jr_alloc(void)
26386 EXPORT_SYMBOL(caam_jr_alloc);
26389 + * caam_jridx_alloc() - Alloc a specific job ring based on its index.
26391 + * returns : pointer to the newly allocated physical
26392 + * JobR dev can be written to if successful.
26394 +struct device *caam_jridx_alloc(int idx)
26396 + struct caam_drv_private_jr *jrpriv;
26397 + struct device *dev = ERR_PTR(-ENODEV);
26399 + spin_lock(&driver_data.jr_alloc_lock);
26401 + if (list_empty(&driver_data.jr_list))
26404 + list_for_each_entry(jrpriv, &driver_data.jr_list, list_node) {
26405 + if (jrpriv->ridx == idx) {
26406 + atomic_inc(&jrpriv->tfm_count);
26407 + dev = jrpriv->dev;
26413 + spin_unlock(&driver_data.jr_alloc_lock);
26416 +EXPORT_SYMBOL(caam_jridx_alloc);
26419 * caam_jr_free() - Free the Job Ring
26420 * @rdev - points to the dev that identifies the Job ring to
26422 @@ -496,15 +537,28 @@ static int caam_jr_probe(struct platform
26426 - jrpriv->rregs = (struct caam_job_ring __force *)ctrl;
26427 + jrpriv->rregs = (struct caam_job_ring __iomem __force *)ctrl;
26429 - if (sizeof(dma_addr_t) == sizeof(u64))
26430 - if (of_device_is_compatible(nprop, "fsl,sec-v5.0-job-ring"))
26431 - dma_set_mask_and_coherent(jrdev, DMA_BIT_MASK(40));
26432 + if (sizeof(dma_addr_t) == sizeof(u64)) {
26434 + error = dma_set_mask_and_coherent(jrdev,
26435 + DMA_BIT_MASK(49));
26436 + else if (of_device_is_compatible(nprop,
26437 + "fsl,sec-v5.0-job-ring"))
26438 + error = dma_set_mask_and_coherent(jrdev,
26439 + DMA_BIT_MASK(40));
26441 - dma_set_mask_and_coherent(jrdev, DMA_BIT_MASK(36));
26443 - dma_set_mask_and_coherent(jrdev, DMA_BIT_MASK(32));
26444 + error = dma_set_mask_and_coherent(jrdev,
26445 + DMA_BIT_MASK(36));
26447 + error = dma_set_mask_and_coherent(jrdev, DMA_BIT_MASK(32));
26450 + dev_err(jrdev, "dma_set_mask_and_coherent failed (%d)\n",
26456 /* Identify the interrupt */
26457 jrpriv->irq = irq_of_parse_and_map(nprop, 0);
26458 @@ -524,10 +578,12 @@ static int caam_jr_probe(struct platform
26460 atomic_set(&jrpriv->tfm_count, 0);
26462 + jr_driver_probed++;
26467 -static struct of_device_id caam_jr_match[] = {
26468 +static const struct of_device_id caam_jr_match[] = {
26470 .compatible = "fsl,sec-v4.0-job-ring",
26472 --- a/drivers/crypto/caam/jr.h
26473 +++ b/drivers/crypto/caam/jr.h
26477 /* Prototypes for backend-level services exposed to APIs */
26478 +int caam_jr_driver_probed(void);
26479 struct device *caam_jr_alloc(void);
26480 +struct device *caam_jridx_alloc(int idx);
26481 void caam_jr_free(struct device *rdev);
26482 int caam_jr_enqueue(struct device *dev, u32 *desc,
26483 void (*cbk)(struct device *dev, u32 *desc, u32 status,
26484 --- a/drivers/crypto/caam/key_gen.c
26485 +++ b/drivers/crypto/caam/key_gen.c
26486 @@ -41,15 +41,29 @@ Split key generation--------------------
26487 [06] 0x64260028 fifostr: class2 mdsplit-jdk len=40
26490 -int gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
26491 - int split_key_pad_len, const u8 *key_in, u32 keylen,
26493 +int gen_split_key(struct device *jrdev, u8 *key_out,
26494 + struct alginfo * const adata, const u8 *key_in, u32 keylen,
26498 struct split_key_result result;
26499 dma_addr_t dma_addr_in, dma_addr_out;
26502 + adata->keylen = split_key_len(adata->algtype & OP_ALG_ALGSEL_MASK);
26503 + adata->keylen_pad = split_key_pad_len(adata->algtype &
26504 + OP_ALG_ALGSEL_MASK);
26507 + dev_err(jrdev, "split keylen %d split keylen padded %d\n",
26508 + adata->keylen, adata->keylen_pad);
26509 + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ",
26510 + DUMP_PREFIX_ADDRESS, 16, 4, key_in, keylen, 1);
26513 + if (adata->keylen_pad > max_keylen)
26516 desc = kmalloc(CAAM_CMD_SZ * 6 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA);
26518 dev_err(jrdev, "unable to allocate key input memory\n");
26519 @@ -63,7 +77,7 @@ int gen_split_key(struct device *jrdev,
26523 - dma_addr_out = dma_map_single(jrdev, key_out, split_key_pad_len,
26524 + dma_addr_out = dma_map_single(jrdev, key_out, adata->keylen_pad,
26526 if (dma_mapping_error(jrdev, dma_addr_out)) {
26527 dev_err(jrdev, "unable to map key output memory\n");
26528 @@ -74,7 +88,9 @@ int gen_split_key(struct device *jrdev,
26529 append_key(desc, dma_addr_in, keylen, CLASS_2 | KEY_DEST_CLASS_REG);
26531 /* Sets MDHA up into an HMAC-INIT */
26532 - append_operation(desc, alg_op | OP_ALG_DECRYPT | OP_ALG_AS_INIT);
26533 + append_operation(desc, (adata->algtype & OP_ALG_ALGSEL_MASK) |
26534 + OP_ALG_AAI_HMAC | OP_TYPE_CLASS2_ALG | OP_ALG_DECRYPT |
26538 * do a FIFO_LOAD of zero, this will trigger the internal key expansion
26539 @@ -87,7 +103,7 @@ int gen_split_key(struct device *jrdev,
26540 * FIFO_STORE with the explicit split-key content store
26541 * (0x26 output type)
26543 - append_fifo_store(desc, dma_addr_out, split_key_len,
26544 + append_fifo_store(desc, dma_addr_out, adata->keylen,
26545 LDST_CLASS_2_CCB | FIFOST_TYPE_SPLIT_KEK);
26548 @@ -108,11 +124,11 @@ int gen_split_key(struct device *jrdev,
26550 print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
26551 DUMP_PREFIX_ADDRESS, 16, 4, key_out,
26552 - split_key_pad_len, 1);
26553 + adata->keylen_pad, 1);
26557 - dma_unmap_single(jrdev, dma_addr_out, split_key_pad_len,
26558 + dma_unmap_single(jrdev, dma_addr_out, adata->keylen_pad,
26561 dma_unmap_single(jrdev, dma_addr_in, keylen, DMA_TO_DEVICE);
26562 --- a/drivers/crypto/caam/key_gen.h
26563 +++ b/drivers/crypto/caam/key_gen.h
26569 + * split_key_len - Compute MDHA split key length for a given algorithm
26570 + * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1,
26571 + * SHA224, SHA384, SHA512.
26573 + * Return: MDHA split key length
26575 +static inline u32 split_key_len(u32 hash)
26577 + /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */
26578 + static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 };
26581 + idx = (hash & OP_ALG_ALGSEL_SUBMASK) >> OP_ALG_ALGSEL_SHIFT;
26583 + return (u32)(mdpadlen[idx] * 2);
26587 + * split_key_pad_len - Compute MDHA split key pad length for a given algorithm
26588 + * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1,
26589 + * SHA224, SHA384, SHA512.
26591 + * Return: MDHA split key pad length
26593 +static inline u32 split_key_pad_len(u32 hash)
26595 + return ALIGN(split_key_len(hash), 16);
26598 struct split_key_result {
26599 struct completion completion;
26601 @@ -12,6 +42,6 @@ struct split_key_result {
26603 void split_key_done(struct device *dev, u32 *desc, u32 err, void *context);
26605 -int gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
26606 - int split_key_pad_len, const u8 *key_in, u32 keylen,
26608 +int gen_split_key(struct device *jrdev, u8 *key_out,
26609 + struct alginfo * const adata, const u8 *key_in, u32 keylen,
26611 --- a/drivers/crypto/caam/pdb.h
26612 +++ b/drivers/crypto/caam/pdb.h
26613 @@ -483,6 +483,8 @@ struct dsa_verify_pdb {
26614 #define RSA_PDB_E_MASK (0xFFF << RSA_PDB_E_SHIFT)
26615 #define RSA_PDB_D_SHIFT 12
26616 #define RSA_PDB_D_MASK (0xFFF << RSA_PDB_D_SHIFT)
26617 +#define RSA_PDB_Q_SHIFT 12
26618 +#define RSA_PDB_Q_MASK (0xFFF << RSA_PDB_Q_SHIFT)
26620 #define RSA_PDB_SGF_F (0x8 << RSA_PDB_SGF_SHIFT)
26621 #define RSA_PDB_SGF_G (0x4 << RSA_PDB_SGF_SHIFT)
26622 @@ -490,6 +492,8 @@ struct dsa_verify_pdb {
26623 #define RSA_PRIV_PDB_SGF_G (0x8 << RSA_PDB_SGF_SHIFT)
26625 #define RSA_PRIV_KEY_FRM_1 0
26626 +#define RSA_PRIV_KEY_FRM_2 1
26627 +#define RSA_PRIV_KEY_FRM_3 2
26630 * RSA Encrypt Protocol Data Block
26631 @@ -525,4 +529,62 @@ struct rsa_priv_f1_pdb {
26636 + * RSA Decrypt PDB - Private Key Form #2
26637 + * @sgf : scatter-gather field
26638 + * @g_dma : dma address of encrypted input data
26639 + * @f_dma : dma address of output data
26640 + * @d_dma : dma address of RSA private exponent
26641 + * @p_dma : dma address of RSA prime factor p of RSA modulus n
26642 + * @q_dma : dma address of RSA prime factor q of RSA modulus n
26643 + * @tmp1_dma: dma address of temporary buffer. CAAM uses this temporary buffer
26644 + * as internal state buffer. It is assumed to be as long as p.
26645 + * @tmp2_dma: dma address of temporary buffer. CAAM uses this temporary buffer
26646 + * as internal state buffer. It is assumed to be as long as q.
26647 + * @p_q_len : length in bytes of first two prime factors of the RSA modulus n
26649 +struct rsa_priv_f2_pdb {
26651 + dma_addr_t g_dma;
26652 + dma_addr_t f_dma;
26653 + dma_addr_t d_dma;
26654 + dma_addr_t p_dma;
26655 + dma_addr_t q_dma;
26656 + dma_addr_t tmp1_dma;
26657 + dma_addr_t tmp2_dma;
26662 + * RSA Decrypt PDB - Private Key Form #3
26663 + * This is the RSA Chinese Reminder Theorem (CRT) form for two prime factors of
26664 + * the RSA modulus.
26665 + * @sgf : scatter-gather field
26666 + * @g_dma : dma address of encrypted input data
26667 + * @f_dma : dma address of output data
26668 + * @c_dma : dma address of RSA CRT coefficient
26669 + * @p_dma : dma address of RSA prime factor p of RSA modulus n
26670 + * @q_dma : dma address of RSA prime factor q of RSA modulus n
26671 + * @dp_dma : dma address of RSA CRT exponent of RSA prime factor p
26672 + * @dp_dma : dma address of RSA CRT exponent of RSA prime factor q
26673 + * @tmp1_dma: dma address of temporary buffer. CAAM uses this temporary buffer
26674 + * as internal state buffer. It is assumed to be as long as p.
26675 + * @tmp2_dma: dma address of temporary buffer. CAAM uses this temporary buffer
26676 + * as internal state buffer. It is assumed to be as long as q.
26677 + * @p_q_len : length in bytes of first two prime factors of the RSA modulus n
26679 +struct rsa_priv_f3_pdb {
26681 + dma_addr_t g_dma;
26682 + dma_addr_t f_dma;
26683 + dma_addr_t c_dma;
26684 + dma_addr_t p_dma;
26685 + dma_addr_t q_dma;
26686 + dma_addr_t dp_dma;
26687 + dma_addr_t dq_dma;
26688 + dma_addr_t tmp1_dma;
26689 + dma_addr_t tmp2_dma;
26694 --- a/drivers/crypto/caam/pkc_desc.c
26695 +++ b/drivers/crypto/caam/pkc_desc.c
26696 @@ -34,3 +34,39 @@ void init_rsa_priv_f1_desc(u32 *desc, st
26697 append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
26698 RSA_PRIV_KEY_FRM_1);
26701 +/* Descriptor for RSA Private operation - Private Key Form #2 */
26702 +void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb)
26704 + init_job_desc_pdb(desc, 0, sizeof(*pdb));
26705 + append_cmd(desc, pdb->sgf);
26706 + append_ptr(desc, pdb->g_dma);
26707 + append_ptr(desc, pdb->f_dma);
26708 + append_ptr(desc, pdb->d_dma);
26709 + append_ptr(desc, pdb->p_dma);
26710 + append_ptr(desc, pdb->q_dma);
26711 + append_ptr(desc, pdb->tmp1_dma);
26712 + append_ptr(desc, pdb->tmp2_dma);
26713 + append_cmd(desc, pdb->p_q_len);
26714 + append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
26715 + RSA_PRIV_KEY_FRM_2);
26718 +/* Descriptor for RSA Private operation - Private Key Form #3 */
26719 +void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb)
26721 + init_job_desc_pdb(desc, 0, sizeof(*pdb));
26722 + append_cmd(desc, pdb->sgf);
26723 + append_ptr(desc, pdb->g_dma);
26724 + append_ptr(desc, pdb->f_dma);
26725 + append_ptr(desc, pdb->c_dma);
26726 + append_ptr(desc, pdb->p_dma);
26727 + append_ptr(desc, pdb->q_dma);
26728 + append_ptr(desc, pdb->dp_dma);
26729 + append_ptr(desc, pdb->dq_dma);
26730 + append_ptr(desc, pdb->tmp1_dma);
26731 + append_ptr(desc, pdb->tmp2_dma);
26732 + append_cmd(desc, pdb->p_q_len);
26733 + append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
26734 + RSA_PRIV_KEY_FRM_3);
26737 +++ b/drivers/crypto/caam/qi.c
26740 + * CAAM/SEC 4.x QI transport/backend driver
26741 + * Queue Interface backend functionality
26743 + * Copyright 2013-2016 Freescale Semiconductor, Inc.
26744 + * Copyright 2016-2017 NXP
26747 +#include <linux/cpumask.h>
26748 +#include <linux/kthread.h>
26749 +#include <linux/fsl_qman.h>
26754 +#include "intern.h"
26755 +#include "desc_constr.h"
26757 +#define PREHDR_RSLS_SHIFT 31
26760 + * Use a reasonable backlog of frames (per CPU) as congestion threshold,
26761 + * so that resources used by the in-flight buffers do not become a memory hog.
26763 +#define MAX_RSP_FQ_BACKLOG_PER_CPU 256
26765 +#define CAAM_QI_ENQUEUE_RETRIES 10000
26767 +#define CAAM_NAPI_WEIGHT 63
26770 + * caam_napi - struct holding CAAM NAPI-related params
26771 + * @irqtask: IRQ task for QI backend
26772 + * @p: QMan portal
26774 +struct caam_napi {
26775 + struct napi_struct irqtask;
26776 + struct qman_portal *p;
26780 + * caam_qi_pcpu_priv - percpu private data structure to main list of pending
26781 + * responses expected on each cpu.
26782 + * @caam_napi: CAAM NAPI params
26783 + * @net_dev: netdev used by NAPI
26784 + * @rsp_fq: response FQ from CAAM
26786 +struct caam_qi_pcpu_priv {
26787 + struct caam_napi caam_napi;
26788 + struct net_device net_dev;
26789 + struct qman_fq *rsp_fq;
26790 +} ____cacheline_aligned;
26792 +static DEFINE_PER_CPU(struct caam_qi_pcpu_priv, pcpu_qipriv);
26793 +static DEFINE_PER_CPU(int, last_cpu);
26796 + * caam_qi_priv - CAAM QI backend private params
26797 + * @cgr: QMan congestion group
26798 + * @qi_pdev: platform device for QI backend
26800 +struct caam_qi_priv {
26801 + struct qman_cgr cgr;
26802 + struct platform_device *qi_pdev;
26805 +static struct caam_qi_priv qipriv ____cacheline_aligned;
26808 + * This is written by only one core - the one that initialized the CGR - and
26809 + * read by multiple cores (all the others).
26811 +bool caam_congested __read_mostly;
26812 +EXPORT_SYMBOL(caam_congested);
26814 +#ifdef CONFIG_DEBUG_FS
26816 + * This is a counter for the number of times the congestion group (where all
26817 + * the request and response queueus are) reached congestion. Incremented
26818 + * each time the congestion callback is called with congested == true.
26820 +static u64 times_congested;
26824 + * CPU from where the module initialised. This is required because QMan driver
26825 + * requires CGRs to be removed from same CPU from where they were originally
26828 +static int mod_init_cpu;
26831 + * This is a a cache of buffers, from which the users of CAAM QI driver
26832 + * can allocate short (CAAM_QI_MEMCACHE_SIZE) buffers. It's faster than
26833 + * doing malloc on the hotpath.
26834 + * NOTE: A more elegant solution would be to have some headroom in the frames
26835 + * being processed. This could be added by the dpaa-ethernet driver.
26836 + * This would pose a problem for userspace application processing which
26837 + * cannot know of this limitation. So for now, this will work.
26838 + * NOTE: The memcache is SMP-safe. No need to handle spinlocks in-here
26840 +static struct kmem_cache *qi_cache;
26842 +int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req)
26846 + int num_retries = 0;
26849 + fd.format = qm_fd_compound;
26850 + fd.cong_weight = caam32_to_cpu(req->fd_sgt[1].length);
26851 + fd.addr = dma_map_single(qidev, req->fd_sgt, sizeof(req->fd_sgt),
26852 + DMA_BIDIRECTIONAL);
26853 + if (dma_mapping_error(qidev, fd.addr)) {
26854 + dev_err(qidev, "DMA mapping error for QI enqueue request\n");
26859 + ret = qman_enqueue(req->drv_ctx->req_fq, &fd, 0);
26860 + if (likely(!ret))
26863 + if (ret != -EBUSY)
26866 + } while (num_retries < CAAM_QI_ENQUEUE_RETRIES);
26868 + dev_err(qidev, "qman_enqueue failed: %d\n", ret);
26872 +EXPORT_SYMBOL(caam_qi_enqueue);
26874 +static void caam_fq_ern_cb(struct qman_portal *qm, struct qman_fq *fq,
26875 + const struct qm_mr_entry *msg)
26877 + const struct qm_fd *fd;
26878 + struct caam_drv_req *drv_req;
26879 + struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev);
26881 + fd = &msg->ern.fd;
26883 + if (fd->format != qm_fd_compound) {
26884 + dev_err(qidev, "Non-compound FD from CAAM\n");
26888 + drv_req = (struct caam_drv_req *)phys_to_virt(qm_fd_addr_get64(fd));
26891 + "Can't find original request for CAAM response\n");
26895 + dma_unmap_single(drv_req->drv_ctx->qidev, qm_fd_addr(fd),
26896 + sizeof(drv_req->fd_sgt), DMA_BIDIRECTIONAL);
26898 + drv_req->cbk(drv_req, -EIO);
26901 +static struct qman_fq *create_caam_req_fq(struct device *qidev,
26902 + struct qman_fq *rsp_fq,
26903 + dma_addr_t hwdesc,
26904 + int fq_sched_flag)
26907 + struct qman_fq *req_fq;
26908 + struct qm_mcc_initfq opts;
26910 + req_fq = kzalloc(sizeof(*req_fq), GFP_ATOMIC);
26912 + return ERR_PTR(-ENOMEM);
26914 + req_fq->cb.ern = caam_fq_ern_cb;
26915 + req_fq->cb.fqs = NULL;
26917 + ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID |
26918 + QMAN_FQ_FLAG_TO_DCPORTAL | QMAN_FQ_FLAG_LOCKED,
26921 + dev_err(qidev, "Failed to create session req FQ\n");
26922 + goto create_req_fq_fail;
26925 + opts.we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_DESTWQ |
26926 + QM_INITFQ_WE_CONTEXTB | QM_INITFQ_WE_CONTEXTA |
26927 + QM_INITFQ_WE_CGID;
26928 + opts.fqd.fq_ctrl = QM_FQCTRL_CPCSTASH | QM_FQCTRL_CGE;
26929 + opts.fqd.dest.channel = qm_channel_caam;
26930 + opts.fqd.dest.wq = 2;
26931 + opts.fqd.context_b = qman_fq_fqid(rsp_fq);
26932 + opts.fqd.context_a.hi = upper_32_bits(hwdesc);
26933 + opts.fqd.context_a.lo = lower_32_bits(hwdesc);
26934 + opts.fqd.cgid = qipriv.cgr.cgrid;
26936 + ret = qman_init_fq(req_fq, fq_sched_flag, &opts);
26938 + dev_err(qidev, "Failed to init session req FQ\n");
26939 + goto init_req_fq_fail;
26942 + dev_dbg(qidev, "Allocated request FQ %u for CPU %u\n", req_fq->fqid,
26943 + smp_processor_id());
26947 + qman_destroy_fq(req_fq, 0);
26948 +create_req_fq_fail:
26950 + return ERR_PTR(ret);
26953 +static int empty_retired_fq(struct device *qidev, struct qman_fq *fq)
26957 + ret = qman_volatile_dequeue(fq, QMAN_VOLATILE_FLAG_WAIT_INT |
26958 + QMAN_VOLATILE_FLAG_FINISH,
26959 + QM_VDQCR_PRECEDENCE_VDQCR |
26960 + QM_VDQCR_NUMFRAMES_TILLEMPTY);
26962 + dev_err(qidev, "Volatile dequeue fail for FQ: %u\n", fq->fqid);
26967 + struct qman_portal *p;
26969 + p = qman_get_affine_portal(smp_processor_id());
26970 + qman_p_poll_dqrr(p, 16);
26971 + } while (fq->flags & QMAN_FQ_STATE_NE);
26976 +static int kill_fq(struct device *qidev, struct qman_fq *fq)
26981 + ret = qman_retire_fq(fq, &flags);
26983 + dev_err(qidev, "qman_retire_fq failed: %d\n", ret);
26990 + /* Async FQ retirement condition */
26992 + /* Retry till FQ gets in retired state */
26995 + } while (fq->state != qman_fq_state_retired);
26997 + WARN_ON(fq->flags & QMAN_FQ_STATE_BLOCKOOS);
26998 + WARN_ON(fq->flags & QMAN_FQ_STATE_ORL);
27002 + if (fq->flags & QMAN_FQ_STATE_NE) {
27003 + ret = empty_retired_fq(qidev, fq);
27005 + dev_err(qidev, "empty_retired_fq fail for FQ: %u\n",
27011 + ret = qman_oos_fq(fq);
27013 + dev_err(qidev, "OOS of FQID: %u failed\n", fq->fqid);
27015 + qman_destroy_fq(fq, 0);
27021 +static int empty_caam_fq(struct qman_fq *fq)
27024 + struct qm_mcr_queryfq_np np;
27026 + /* Wait till the older CAAM FQ get empty */
27028 + ret = qman_query_fq_np(fq, &np);
27039 + * Give extra time for pending jobs from this FQ in holding tanks
27040 + * to get processed
27046 +int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc)
27050 + struct qman_fq *new_fq, *old_fq;
27051 + struct device *qidev = drv_ctx->qidev;
27053 + num_words = desc_len(sh_desc);
27054 + if (num_words > MAX_SDLEN) {
27055 + dev_err(qidev, "Invalid descriptor len: %d words\n", num_words);
27059 + /* Note down older req FQ */
27060 + old_fq = drv_ctx->req_fq;
27062 + /* Create a new req FQ in parked state */
27063 + new_fq = create_caam_req_fq(drv_ctx->qidev, drv_ctx->rsp_fq,
27064 + drv_ctx->context_a, 0);
27065 + if (unlikely(IS_ERR_OR_NULL(new_fq))) {
27066 + dev_err(qidev, "FQ allocation for shdesc update failed\n");
27067 + return PTR_ERR(new_fq);
27070 + /* Hook up new FQ to context so that new requests keep queuing */
27071 + drv_ctx->req_fq = new_fq;
27073 + /* Empty and remove the older FQ */
27074 + ret = empty_caam_fq(old_fq);
27076 + dev_err(qidev, "Old CAAM FQ empty failed: %d\n", ret);
27078 + /* We can revert to older FQ */
27079 + drv_ctx->req_fq = old_fq;
27081 + if (kill_fq(qidev, new_fq))
27082 + dev_warn(qidev, "New CAAM FQ kill failed\n");
27088 + * Re-initialise pre-header. Set RSLS and SDLEN.
27089 + * Update the shared descriptor for driver context.
27091 + drv_ctx->prehdr[0] = cpu_to_caam32((1 << PREHDR_RSLS_SHIFT) |
27093 + memcpy(drv_ctx->sh_desc, sh_desc, desc_bytes(sh_desc));
27094 + dma_sync_single_for_device(qidev, drv_ctx->context_a,
27095 + sizeof(drv_ctx->sh_desc) +
27096 + sizeof(drv_ctx->prehdr),
27097 + DMA_BIDIRECTIONAL);
27099 + /* Put the new FQ in scheduled state */
27100 + ret = qman_schedule_fq(new_fq);
27102 + dev_err(qidev, "Fail to sched new CAAM FQ, ecode = %d\n", ret);
27105 + * We can kill new FQ and revert to old FQ.
27106 + * Since the desc is already modified, it is success case
27109 + drv_ctx->req_fq = old_fq;
27111 + if (kill_fq(qidev, new_fq))
27112 + dev_warn(qidev, "New CAAM FQ kill failed\n");
27113 + } else if (kill_fq(qidev, old_fq)) {
27114 + dev_warn(qidev, "Old CAAM FQ kill failed\n");
27119 +EXPORT_SYMBOL(caam_drv_ctx_update);
27121 +struct caam_drv_ctx *caam_drv_ctx_init(struct device *qidev,
27127 + dma_addr_t hwdesc;
27128 + struct caam_drv_ctx *drv_ctx;
27129 + const cpumask_t *cpus = qman_affine_cpus();
27131 + num_words = desc_len(sh_desc);
27132 + if (num_words > MAX_SDLEN) {
27133 + dev_err(qidev, "Invalid descriptor len: %d words\n",
27135 + return ERR_PTR(-EINVAL);
27138 + drv_ctx = kzalloc(sizeof(*drv_ctx), GFP_ATOMIC);
27140 + return ERR_PTR(-ENOMEM);
27143 + * Initialise pre-header - set RSLS and SDLEN - and shared descriptor
27144 + * and dma-map them.
27146 + drv_ctx->prehdr[0] = cpu_to_caam32((1 << PREHDR_RSLS_SHIFT) |
27148 + memcpy(drv_ctx->sh_desc, sh_desc, desc_bytes(sh_desc));
27149 + size = sizeof(drv_ctx->prehdr) + sizeof(drv_ctx->sh_desc);
27150 + hwdesc = dma_map_single(qidev, drv_ctx->prehdr, size,
27151 + DMA_BIDIRECTIONAL);
27152 + if (dma_mapping_error(qidev, hwdesc)) {
27153 + dev_err(qidev, "DMA map error for preheader + shdesc\n");
27155 + return ERR_PTR(-ENOMEM);
27157 + drv_ctx->context_a = hwdesc;
27159 + /* If given CPU does not own the portal, choose another one that does */
27160 + if (!cpumask_test_cpu(*cpu, cpus)) {
27161 + int *pcpu = &get_cpu_var(last_cpu);
27163 + *pcpu = cpumask_next(*pcpu, cpus);
27164 + if (*pcpu >= nr_cpu_ids)
27165 + *pcpu = cpumask_first(cpus);
27168 + put_cpu_var(last_cpu);
27170 + drv_ctx->cpu = *cpu;
27172 + /* Find response FQ hooked with this CPU */
27173 + drv_ctx->rsp_fq = per_cpu(pcpu_qipriv.rsp_fq, drv_ctx->cpu);
27175 + /* Attach request FQ */
27176 + drv_ctx->req_fq = create_caam_req_fq(qidev, drv_ctx->rsp_fq, hwdesc,
27177 + QMAN_INITFQ_FLAG_SCHED);
27178 + if (unlikely(IS_ERR_OR_NULL(drv_ctx->req_fq))) {
27179 + dev_err(qidev, "create_caam_req_fq failed\n");
27180 + dma_unmap_single(qidev, hwdesc, size, DMA_BIDIRECTIONAL);
27182 + return ERR_PTR(-ENOMEM);
27185 + drv_ctx->qidev = qidev;
27188 +EXPORT_SYMBOL(caam_drv_ctx_init);
27190 +void *qi_cache_alloc(gfp_t flags)
27192 + return kmem_cache_alloc(qi_cache, flags);
27194 +EXPORT_SYMBOL(qi_cache_alloc);
27196 +void qi_cache_free(void *obj)
27198 + kmem_cache_free(qi_cache, obj);
27200 +EXPORT_SYMBOL(qi_cache_free);
27202 +static int caam_qi_poll(struct napi_struct *napi, int budget)
27204 + struct caam_napi *np = container_of(napi, struct caam_napi, irqtask);
27206 + int cleaned = qman_p_poll_dqrr(np->p, budget);
27208 + if (cleaned < budget) {
27209 + napi_complete(napi);
27210 + qman_p_irqsource_add(np->p, QM_PIRQ_DQRI);
27216 +void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx)
27218 + if (IS_ERR_OR_NULL(drv_ctx))
27221 + /* Remove request FQ */
27222 + if (kill_fq(drv_ctx->qidev, drv_ctx->req_fq))
27223 + dev_err(drv_ctx->qidev, "Crypto session req FQ kill failed\n");
27225 + dma_unmap_single(drv_ctx->qidev, drv_ctx->context_a,
27226 + sizeof(drv_ctx->sh_desc) + sizeof(drv_ctx->prehdr),
27227 + DMA_BIDIRECTIONAL);
27230 +EXPORT_SYMBOL(caam_drv_ctx_rel);
27232 +int caam_qi_shutdown(struct device *qidev)
27235 + struct caam_qi_priv *priv = dev_get_drvdata(qidev);
27236 + const cpumask_t *cpus = qman_affine_cpus();
27237 + struct cpumask old_cpumask = current->cpus_allowed;
27239 + for_each_cpu(i, cpus) {
27240 + struct napi_struct *irqtask;
27242 + irqtask = &per_cpu_ptr(&pcpu_qipriv.caam_napi, i)->irqtask;
27243 + napi_disable(irqtask);
27244 + netif_napi_del(irqtask);
27246 + if (kill_fq(qidev, per_cpu(pcpu_qipriv.rsp_fq, i)))
27247 + dev_err(qidev, "Rsp FQ kill failed, cpu: %d\n", i);
27251 + * QMan driver requires CGRs to be deleted from same CPU from where they
27252 + * were instantiated. Hence we get the module removal execute from the
27253 + * same CPU from where it was originally inserted.
27255 + set_cpus_allowed_ptr(current, get_cpu_mask(mod_init_cpu));
27257 + ret = qman_delete_cgr(&priv->cgr);
27259 + dev_err(qidev, "Deletion of CGR failed: %d\n", ret);
27261 + qman_release_cgrid(priv->cgr.cgrid);
27263 + kmem_cache_destroy(qi_cache);
27265 + /* Now that we're done with the CGRs, restore the cpus allowed mask */
27266 + set_cpus_allowed_ptr(current, &old_cpumask);
27268 + platform_device_unregister(priv->qi_pdev);
27272 +static void cgr_cb(struct qman_portal *qm, struct qman_cgr *cgr, int congested)
27274 + caam_congested = congested;
27277 +#ifdef CONFIG_DEBUG_FS
27278 + times_congested++;
27280 + pr_debug_ratelimited("CAAM entered congestion\n");
27283 + pr_debug_ratelimited("CAAM exited congestion\n");
27287 +static int caam_qi_napi_schedule(struct qman_portal *p, struct caam_napi *np)
27290 + * In case of threaded ISR, for RT kernels in_irq() does not return
27291 + * appropriate value, so use in_serving_softirq to distinguish between
27292 + * softirq and irq contexts.
27294 + if (unlikely(in_irq() || !in_serving_softirq())) {
27295 + /* Disable QMan IRQ source and invoke NAPI */
27296 + qman_p_irqsource_remove(p, QM_PIRQ_DQRI);
27298 + napi_schedule(&np->irqtask);
27304 +static enum qman_cb_dqrr_result caam_rsp_fq_dqrr_cb(struct qman_portal *p,
27305 + struct qman_fq *rsp_fq,
27306 + const struct qm_dqrr_entry *dqrr)
27308 + struct caam_napi *caam_napi = raw_cpu_ptr(&pcpu_qipriv.caam_napi);
27309 + struct caam_drv_req *drv_req;
27310 + const struct qm_fd *fd;
27311 + struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev);
27313 + if (caam_qi_napi_schedule(p, caam_napi))
27314 + return qman_cb_dqrr_stop;
27317 + if (unlikely(fd->status))
27318 + dev_err(qidev, "Error: %#x in CAAM response FD\n", fd->status);
27320 + if (unlikely(fd->format != fd->format)) {
27321 + dev_err(qidev, "Non-compound FD from CAAM\n");
27322 + return qman_cb_dqrr_consume;
27325 + drv_req = (struct caam_drv_req *)phys_to_virt(fd->addr);
27326 + if (unlikely(!drv_req)) {
27328 + "Can't find original request for caam response\n");
27329 + return qman_cb_dqrr_consume;
27332 + dma_unmap_single(drv_req->drv_ctx->qidev, qm_fd_addr(fd),
27333 + sizeof(drv_req->fd_sgt), DMA_BIDIRECTIONAL);
27335 + drv_req->cbk(drv_req, fd->status);
27336 + return qman_cb_dqrr_consume;
27339 +static int alloc_rsp_fq_cpu(struct device *qidev, unsigned int cpu)
27341 + struct qm_mcc_initfq opts;
27342 + struct qman_fq *fq;
27345 + fq = kzalloc(sizeof(*fq), GFP_KERNEL | GFP_DMA);
27349 + fq->cb.dqrr = caam_rsp_fq_dqrr_cb;
27351 + ret = qman_create_fq(0, QMAN_FQ_FLAG_NO_ENQUEUE |
27352 + QMAN_FQ_FLAG_DYNAMIC_FQID, fq);
27354 + dev_err(qidev, "Rsp FQ create failed\n");
27359 + opts.we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_DESTWQ |
27360 + QM_INITFQ_WE_CONTEXTB | QM_INITFQ_WE_CONTEXTA |
27361 + QM_INITFQ_WE_CGID;
27362 + opts.fqd.fq_ctrl = QM_FQCTRL_CTXASTASHING | QM_FQCTRL_CPCSTASH |
27364 + opts.fqd.dest.channel = qman_affine_channel(cpu);
27365 + opts.fqd.dest.wq = 3;
27366 + opts.fqd.cgid = qipriv.cgr.cgrid;
27367 + opts.fqd.context_a.stashing.exclusive = QM_STASHING_EXCL_CTX |
27368 + QM_STASHING_EXCL_DATA;
27369 + opts.fqd.context_a.stashing.data_cl = 1;
27370 + opts.fqd.context_a.stashing.context_cl = 1;
27372 + ret = qman_init_fq(fq, QMAN_INITFQ_FLAG_SCHED, &opts);
27374 + dev_err(qidev, "Rsp FQ init failed\n");
27379 + per_cpu(pcpu_qipriv.rsp_fq, cpu) = fq;
27381 + dev_dbg(qidev, "Allocated response FQ %u for CPU %u", fq->fqid, cpu);
27385 +static int init_cgr(struct device *qidev)
27388 + struct qm_mcc_initcgr opts;
27389 + const u64 cpus = *(u64 *)qman_affine_cpus();
27390 + const int num_cpus = hweight64(cpus);
27391 + const u64 val = num_cpus * MAX_RSP_FQ_BACKLOG_PER_CPU;
27393 + ret = qman_alloc_cgrid(&qipriv.cgr.cgrid);
27395 + dev_err(qidev, "CGR alloc failed for rsp FQs: %d\n", ret);
27399 + qipriv.cgr.cb = cgr_cb;
27400 + memset(&opts, 0, sizeof(opts));
27401 + opts.we_mask = QM_CGR_WE_CSCN_EN | QM_CGR_WE_CS_THRES | QM_CGR_WE_MODE;
27402 + opts.cgr.cscn_en = QM_CGR_EN;
27403 + opts.cgr.mode = QMAN_CGR_MODE_FRAME;
27404 + qm_cgr_cs_thres_set64(&opts.cgr.cs_thres, val, 1);
27406 + ret = qman_create_cgr(&qipriv.cgr, QMAN_CGR_FLAG_USE_INIT, &opts);
27408 + dev_err(qidev, "Error %d creating CAAM CGRID: %u\n", ret,
27409 + qipriv.cgr.cgrid);
27413 + dev_dbg(qidev, "Congestion threshold set to %llu\n", val);
27417 +static int alloc_rsp_fqs(struct device *qidev)
27420 + const cpumask_t *cpus = qman_affine_cpus();
27422 + /*Now create response FQs*/
27423 + for_each_cpu(i, cpus) {
27424 + ret = alloc_rsp_fq_cpu(qidev, i);
27426 + dev_err(qidev, "CAAM rsp FQ alloc failed, cpu: %u", i);
27434 +static void free_rsp_fqs(void)
27437 + const cpumask_t *cpus = qman_affine_cpus();
27439 + for_each_cpu(i, cpus)
27440 + kfree(per_cpu(pcpu_qipriv.rsp_fq, i));
27443 +int caam_qi_init(struct platform_device *caam_pdev)
27446 + struct platform_device *qi_pdev;
27447 + struct device *ctrldev = &caam_pdev->dev, *qidev;
27448 + struct caam_drv_private *ctrlpriv;
27449 + const cpumask_t *cpus = qman_affine_cpus();
27450 + struct cpumask old_cpumask = current->cpus_allowed;
27451 + static struct platform_device_info qi_pdev_info = {
27452 + .name = "caam_qi",
27453 + .id = PLATFORM_DEVID_NONE
27457 + * QMAN requires CGRs to be removed from same CPU+portal from where it
27458 + * was originally allocated. Hence we need to note down the
27459 + * initialisation CPU and use the same CPU for module exit.
27460 + * We select the first CPU to from the list of portal owning CPUs.
27461 + * Then we pin module init to this CPU.
27463 + mod_init_cpu = cpumask_first(cpus);
27464 + set_cpus_allowed_ptr(current, get_cpu_mask(mod_init_cpu));
27466 + qi_pdev_info.parent = ctrldev;
27467 + qi_pdev_info.dma_mask = dma_get_mask(ctrldev);
27468 + qi_pdev = platform_device_register_full(&qi_pdev_info);
27469 + if (IS_ERR(qi_pdev))
27470 + return PTR_ERR(qi_pdev);
27471 + arch_setup_dma_ops(&qi_pdev->dev, 0, 0, NULL, true);
27473 + ctrlpriv = dev_get_drvdata(ctrldev);
27474 + qidev = &qi_pdev->dev;
27476 + qipriv.qi_pdev = qi_pdev;
27477 + dev_set_drvdata(qidev, &qipriv);
27479 + /* Initialize the congestion detection */
27480 + err = init_cgr(qidev);
27482 + dev_err(qidev, "CGR initialization failed: %d\n", err);
27483 + platform_device_unregister(qi_pdev);
27487 + /* Initialise response FQs */
27488 + err = alloc_rsp_fqs(qidev);
27490 + dev_err(qidev, "Can't allocate CAAM response FQs: %d\n", err);
27492 + platform_device_unregister(qi_pdev);
27497 + * Enable the NAPI contexts on each of the core which has an affine
27500 + for_each_cpu(i, cpus) {
27501 + struct caam_qi_pcpu_priv *priv = per_cpu_ptr(&pcpu_qipriv, i);
27502 + struct caam_napi *caam_napi = &priv->caam_napi;
27503 + struct napi_struct *irqtask = &caam_napi->irqtask;
27504 + struct net_device *net_dev = &priv->net_dev;
27506 + net_dev->dev = *qidev;
27507 + INIT_LIST_HEAD(&net_dev->napi_list);
27509 + netif_napi_add(net_dev, irqtask, caam_qi_poll,
27510 + CAAM_NAPI_WEIGHT);
27512 + napi_enable(irqtask);
27515 + /* Hook up QI device to parent controlling caam device */
27516 + ctrlpriv->qidev = qidev;
27518 + qi_cache = kmem_cache_create("caamqicache", CAAM_QI_MEMCACHE_SIZE, 0,
27519 + SLAB_CACHE_DMA, NULL);
27521 + dev_err(qidev, "Can't allocate CAAM cache\n");
27523 + platform_device_unregister(qi_pdev);
27527 + /* Done with the CGRs; restore the cpus allowed mask */
27528 + set_cpus_allowed_ptr(current, &old_cpumask);
27529 +#ifdef CONFIG_DEBUG_FS
27530 + debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
27531 + ×_congested, &caam_fops_u64_ro);
27533 + dev_info(qidev, "Linux CAAM Queue I/F driver initialised\n");
27537 +++ b/drivers/crypto/caam/qi.h
27540 + * Public definitions for the CAAM/QI (Queue Interface) backend.
27542 + * Copyright 2013-2016 Freescale Semiconductor, Inc.
27543 + * Copyright 2016-2017 NXP
27549 +#include <linux/fsl_qman.h>
27550 +#include "compat.h"
27552 +#include "desc_constr.h"
27555 + * CAAM hardware constructs a job descriptor which points to a shared descriptor
27556 + * (as pointed by context_a of to-CAAM FQ).
27557 + * When the job descriptor is executed by DECO, the whole job descriptor
27558 + * together with shared descriptor gets loaded in DECO buffer, which is
27559 + * 64 words (each 32-bit) long.
27561 + * The job descriptor constructed by CAAM hardware has the following layout:
27563 + * HEADER (1 word)
27564 + * Shdesc ptr (1 or 2 words)
27565 + * SEQ_OUT_PTR (1 word)
27566 + * Out ptr (1 or 2 words)
27567 + * Out length (1 word)
27568 + * SEQ_IN_PTR (1 word)
27569 + * In ptr (1 or 2 words)
27570 + * In length (1 word)
27572 + * The shdesc ptr is used to fetch shared descriptor contents into DECO buffer.
27574 + * Apart from shdesc contents, the total number of words that get loaded in DECO
27575 + * buffer are '8' or '11'. The remaining words in DECO buffer can be used for
27576 + * storing shared descriptor.
27578 +#define MAX_SDLEN ((CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN) / CAAM_CMD_SZ)
27580 +/* Length of a single buffer in the QI driver memory cache */
27581 +#define CAAM_QI_MEMCACHE_SIZE 768
27583 +extern bool caam_congested __read_mostly;
27586 + * This is the request structure the driver application should fill while
27587 + * submitting a job to driver.
27589 +struct caam_drv_req;
27592 + * caam_qi_cbk - application's callback function invoked by the driver when the
27593 + * request has been successfully processed.
27594 + * @drv_req: original request that was submitted
27595 + * @status: completion status of request (0 - success, non-zero - error code)
27597 +typedef void (*caam_qi_cbk)(struct caam_drv_req *drv_req, u32 status);
27607 + * caam_drv_ctx - CAAM/QI backend driver context
27609 + * The jobs are processed by the driver against a driver context.
27610 + * With every cryptographic context, a driver context is attached.
27611 + * The driver context contains data for private use by driver.
27612 + * For the applications, this is an opaque structure.
27614 + * @prehdr: preheader placed before shrd desc
27615 + * @sh_desc: shared descriptor
27616 + * @context_a: shared descriptor dma address
27617 + * @req_fq: to-CAAM request frame queue
27618 + * @rsp_fq: from-CAAM response frame queue
27619 + * @cpu: cpu on which to receive CAAM response
27620 + * @op_type: operation type
27621 + * @qidev: device pointer for CAAM/QI backend
27623 +struct caam_drv_ctx {
27625 + u32 sh_desc[MAX_SDLEN];
27626 + dma_addr_t context_a;
27627 + struct qman_fq *req_fq;
27628 + struct qman_fq *rsp_fq;
27630 + enum optype op_type;
27631 + struct device *qidev;
27632 +} ____cacheline_aligned;
27635 + * caam_drv_req - The request structure the driver application should fill while
27636 + * submitting a job to driver.
27637 + * @fd_sgt: QMan S/G pointing to output (fd_sgt[0]) and input (fd_sgt[1])
27639 + * @cbk: callback function to invoke when job is completed
27640 + * @app_ctx: arbitrary context attached with request by the application
27642 + * The fields mentioned below should not be used by application.
27643 + * These are for private use by driver.
27645 + * @hdr__: linked list header to maintain list of outstanding requests to CAAM
27646 + * @hwaddr: DMA address for the S/G table.
27648 +struct caam_drv_req {
27649 + struct qm_sg_entry fd_sgt[2];
27650 + struct caam_drv_ctx *drv_ctx;
27653 +} ____cacheline_aligned;
27656 + * caam_drv_ctx_init - Initialise a CAAM/QI driver context
27658 + * A CAAM/QI driver context must be attached with each cryptographic context.
27659 + * This function allocates memory for CAAM/QI context and returns a handle to
27660 + * the application. This handle must be submitted along with each enqueue
27661 + * request to the driver by the application.
27663 + * @cpu: CPU where the application prefers to the driver to receive CAAM
27664 + * responses. The request completion callback would be issued from this
27666 + * @sh_desc: shared descriptor pointer to be attached with CAAM/QI driver
27669 + * Returns a driver context on success or negative error code on failure.
27671 +struct caam_drv_ctx *caam_drv_ctx_init(struct device *qidev, int *cpu,
27675 + * caam_qi_enqueue - Submit a request to QI backend driver.
27677 + * The request structure must be properly filled as described above.
27679 + * @qidev: device pointer for QI backend
27680 + * @req: CAAM QI request structure
27682 + * Returns 0 on success or negative error code on failure.
27684 +int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req);
27687 + * caam_drv_ctx_busy - Check if there are too many jobs pending with CAAM
27688 + * or too many CAAM responses are pending to be processed.
27689 + * @drv_ctx: driver context for which job is to be submitted
27691 + * Returns caam congestion status 'true/false'
27693 +bool caam_drv_ctx_busy(struct caam_drv_ctx *drv_ctx);
27696 + * caam_drv_ctx_update - Update QI driver context
27698 + * Invoked when shared descriptor is required to be change in driver context.
27700 + * @drv_ctx: driver context to be updated
27701 + * @sh_desc: new shared descriptor pointer to be updated in QI driver context
27703 + * Returns 0 on success or negative error code on failure.
27705 +int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc);
27708 + * caam_drv_ctx_rel - Release a QI driver context
27709 + * @drv_ctx: context to be released
27711 +void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx);
27713 +int caam_qi_init(struct platform_device *pdev);
27714 +int caam_qi_shutdown(struct device *dev);
27717 + * qi_cache_alloc - Allocate buffers from CAAM-QI cache
27719 + * Invoked when a user of the CAAM-QI (i.e. caamalg-qi) needs data which has
27720 + * to be allocated on the hotpath. Instead of using malloc, one can use the
27721 + * services of the CAAM QI memory cache (backed by kmem_cache). The buffers
27722 + * will have a size of 256B, which is sufficient for hosting 16 SG entries.
27724 + * @flags: flags that would be used for the equivalent malloc(..) call
27726 + * Returns a pointer to a retrieved buffer on success or NULL on failure.
27728 +void *qi_cache_alloc(gfp_t flags);
27731 + * qi_cache_free - Frees buffers allocated from CAAM-QI cache
27733 + * Invoked when a user of the CAAM-QI (i.e. caamalg-qi) no longer needs
27734 + * the buffer previously allocated by a qi_cache_alloc call.
27735 + * No checking is being done, the call is a passthrough call to
27736 + * kmem_cache_free(...)
27738 + * @obj: object previously allocated using qi_cache_alloc()
27740 +void qi_cache_free(void *obj);
27742 +#endif /* __QI_H__ */
27743 --- a/drivers/crypto/caam/regs.h
27744 +++ b/drivers/crypto/caam/regs.h
27746 * CAAM hardware register-level view
27748 * Copyright 2008-2011 Freescale Semiconductor, Inc.
27749 + * Copyright 2017 NXP
27756 extern bool caam_little_end;
27757 +extern bool caam_imx;
27759 #define caam_to_cpu(len) \
27760 static inline u##len caam##len ## _to_cpu(u##len val) \
27761 @@ -154,13 +156,10 @@ static inline u64 rd_reg64(void __iomem
27762 #else /* CONFIG_64BIT */
27763 static inline void wr_reg64(void __iomem *reg, u64 data)
27765 -#ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX
27766 - if (caam_little_end) {
27767 + if (!caam_imx && caam_little_end) {
27768 wr_reg32((u32 __iomem *)(reg) + 1, data >> 32);
27769 wr_reg32((u32 __iomem *)(reg), data);
27774 wr_reg32((u32 __iomem *)(reg), data >> 32);
27775 wr_reg32((u32 __iomem *)(reg) + 1, data);
27777 @@ -168,41 +167,40 @@ static inline void wr_reg64(void __iomem
27779 static inline u64 rd_reg64(void __iomem *reg)
27781 -#ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX
27782 - if (caam_little_end)
27783 + if (!caam_imx && caam_little_end)
27784 return ((u64)rd_reg32((u32 __iomem *)(reg) + 1) << 32 |
27785 (u64)rd_reg32((u32 __iomem *)(reg)));
27788 - return ((u64)rd_reg32((u32 __iomem *)(reg)) << 32 |
27789 - (u64)rd_reg32((u32 __iomem *)(reg) + 1));
27791 + return ((u64)rd_reg32((u32 __iomem *)(reg)) << 32 |
27792 + (u64)rd_reg32((u32 __iomem *)(reg) + 1));
27794 #endif /* CONFIG_64BIT */
27796 +static inline u64 cpu_to_caam_dma64(dma_addr_t value)
27799 + return (((u64)cpu_to_caam32(lower_32_bits(value)) << 32) |
27800 + (u64)cpu_to_caam32(upper_32_bits(value)));
27802 + return cpu_to_caam64(value);
27805 +static inline u64 caam_dma64_to_cpu(u64 value)
27808 + return (((u64)caam32_to_cpu(lower_32_bits(value)) << 32) |
27809 + (u64)caam32_to_cpu(upper_32_bits(value)));
27811 + return caam64_to_cpu(value);
27814 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
27815 -#ifdef CONFIG_SOC_IMX7D
27816 -#define cpu_to_caam_dma(value) \
27817 - (((u64)cpu_to_caam32(lower_32_bits(value)) << 32) | \
27818 - (u64)cpu_to_caam32(upper_32_bits(value)))
27819 -#define caam_dma_to_cpu(value) \
27820 - (((u64)caam32_to_cpu(lower_32_bits(value)) << 32) | \
27821 - (u64)caam32_to_cpu(upper_32_bits(value)))
27823 -#define cpu_to_caam_dma(value) cpu_to_caam64(value)
27824 -#define caam_dma_to_cpu(value) caam64_to_cpu(value)
27825 -#endif /* CONFIG_SOC_IMX7D */
27826 +#define cpu_to_caam_dma(value) cpu_to_caam_dma64(value)
27827 +#define caam_dma_to_cpu(value) caam_dma64_to_cpu(value)
27829 #define cpu_to_caam_dma(value) cpu_to_caam32(value)
27830 #define caam_dma_to_cpu(value) caam32_to_cpu(value)
27831 -#endif /* CONFIG_ARCH_DMA_ADDR_T_64BIT */
27833 -#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX
27834 -#define cpu_to_caam_dma64(value) \
27835 - (((u64)cpu_to_caam32(lower_32_bits(value)) << 32) | \
27836 - (u64)cpu_to_caam32(upper_32_bits(value)))
27838 -#define cpu_to_caam_dma64(value) cpu_to_caam64(value)
27840 +#endif /* CONFIG_ARCH_DMA_ADDR_T_64BIT */
27844 @@ -293,6 +291,7 @@ struct caam_perfmon {
27845 u32 cha_rev_ls; /* CRNR - CHA Rev No. Least significant half*/
27846 #define CTPR_MS_QI_SHIFT 25
27847 #define CTPR_MS_QI_MASK (0x1ull << CTPR_MS_QI_SHIFT)
27848 +#define CTPR_MS_DPAA2 BIT(13)
27849 #define CTPR_MS_VIRT_EN_INCL 0x00000001
27850 #define CTPR_MS_VIRT_EN_POR 0x00000002
27851 #define CTPR_MS_PG_SZ_MASK 0x10
27852 @@ -628,6 +627,8 @@ struct caam_job_ring {
27853 #define JRSTA_DECOERR_INVSIGN 0x86
27854 #define JRSTA_DECOERR_DSASIGN 0x87
27856 +#define JRSTA_QIERR_ERROR_MASK 0x00ff
27858 #define JRSTA_CCBERR_JUMP 0x08000000
27859 #define JRSTA_CCBERR_INDEX_MASK 0xff00
27860 #define JRSTA_CCBERR_INDEX_SHIFT 8
27862 +++ b/drivers/crypto/caam/sg_sw_qm.h
27865 + * Copyright 2013-2016 Freescale Semiconductor, Inc.
27866 + * Copyright 2016-2017 NXP
27868 + * Redistribution and use in source and binary forms, with or without
27869 + * modification, are permitted provided that the following conditions are met:
27870 + * * Redistributions of source code must retain the above copyright
27871 + * notice, this list of conditions and the following disclaimer.
27872 + * * Redistributions in binary form must reproduce the above copyright
27873 + * notice, this list of conditions and the following disclaimer in the
27874 + * documentation and/or other materials provided with the distribution.
27875 + * * Neither the name of Freescale Semiconductor nor the
27876 + * names of its contributors may be used to endorse or promote products
27877 + * derived from this software without specific prior written permission.
27880 + * ALTERNATIVELY, this software may be distributed under the terms of the
27881 + * GNU General Public License ("GPL") as published by the Free Software
27882 + * Foundation, either version 2 of that License or (at your option) any
27885 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
27886 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27887 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27888 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27889 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27890 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27891 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27892 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27893 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27894 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27897 +#ifndef __SG_SW_QM_H
27898 +#define __SG_SW_QM_H
27900 +#include <linux/fsl_qman.h>
27903 +static inline void cpu_to_hw_sg(struct qm_sg_entry *qm_sg_ptr)
27905 + dma_addr_t addr = qm_sg_ptr->opaque;
27907 + qm_sg_ptr->opaque = cpu_to_caam64(addr);
27908 + qm_sg_ptr->sgt_efl = cpu_to_caam32(qm_sg_ptr->sgt_efl);
27911 +static inline void __dma_to_qm_sg(struct qm_sg_entry *qm_sg_ptr, dma_addr_t dma,
27912 + u32 len, u16 offset)
27914 + qm_sg_ptr->addr = dma;
27915 + qm_sg_ptr->length = len;
27916 + qm_sg_ptr->__reserved2 = 0;
27917 + qm_sg_ptr->bpid = 0;
27918 + qm_sg_ptr->__reserved3 = 0;
27919 + qm_sg_ptr->offset = offset & QM_SG_OFFSET_MASK;
27921 + cpu_to_hw_sg(qm_sg_ptr);
27924 +static inline void dma_to_qm_sg_one(struct qm_sg_entry *qm_sg_ptr,
27925 + dma_addr_t dma, u32 len, u16 offset)
27927 + qm_sg_ptr->extension = 0;
27928 + qm_sg_ptr->final = 0;
27929 + __dma_to_qm_sg(qm_sg_ptr, dma, len, offset);
27932 +static inline void dma_to_qm_sg_one_last(struct qm_sg_entry *qm_sg_ptr,
27933 + dma_addr_t dma, u32 len, u16 offset)
27935 + qm_sg_ptr->extension = 0;
27936 + qm_sg_ptr->final = 1;
27937 + __dma_to_qm_sg(qm_sg_ptr, dma, len, offset);
27940 +static inline void dma_to_qm_sg_one_ext(struct qm_sg_entry *qm_sg_ptr,
27941 + dma_addr_t dma, u32 len, u16 offset)
27943 + qm_sg_ptr->extension = 1;
27944 + qm_sg_ptr->final = 0;
27945 + __dma_to_qm_sg(qm_sg_ptr, dma, len, offset);
27948 +static inline void dma_to_qm_sg_one_last_ext(struct qm_sg_entry *qm_sg_ptr,
27949 + dma_addr_t dma, u32 len,
27952 + qm_sg_ptr->extension = 1;
27953 + qm_sg_ptr->final = 1;
27954 + __dma_to_qm_sg(qm_sg_ptr, dma, len, offset);
27958 + * convert scatterlist to h/w link table format
27959 + * but does not have final bit; instead, returns last entry
27961 +static inline struct qm_sg_entry *
27962 +sg_to_qm_sg(struct scatterlist *sg, int sg_count,
27963 + struct qm_sg_entry *qm_sg_ptr, u16 offset)
27965 + while (sg_count && sg) {
27966 + dma_to_qm_sg_one(qm_sg_ptr, sg_dma_address(sg),
27967 + sg_dma_len(sg), offset);
27969 + sg = sg_next(sg);
27972 + return qm_sg_ptr - 1;
27976 + * convert scatterlist to h/w link table format
27977 + * scatterlist must have been previously dma mapped
27979 +static inline void sg_to_qm_sg_last(struct scatterlist *sg, int sg_count,
27980 + struct qm_sg_entry *qm_sg_ptr, u16 offset)
27982 + qm_sg_ptr = sg_to_qm_sg(sg, sg_count, qm_sg_ptr, offset);
27984 + qm_sg_ptr->sgt_efl = caam32_to_cpu(qm_sg_ptr->sgt_efl);
27985 + qm_sg_ptr->final = 1;
27986 + qm_sg_ptr->sgt_efl = cpu_to_caam32(qm_sg_ptr->sgt_efl);
27989 +#endif /* __SG_SW_QM_H */
27991 +++ b/drivers/crypto/caam/sg_sw_qm2.h
27994 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
27995 + * Copyright 2017 NXP
27997 + * Redistribution and use in source and binary forms, with or without
27998 + * modification, are permitted provided that the following conditions are met:
27999 + * * Redistributions of source code must retain the above copyright
28000 + * notice, this list of conditions and the following disclaimer.
28001 + * * Redistributions in binary form must reproduce the above copyright
28002 + * notice, this list of conditions and the following disclaimer in the
28003 + * documentation and/or other materials provided with the distribution.
28004 + * * Neither the names of the above-listed copyright holders nor the
28005 + * names of any contributors may be used to endorse or promote products
28006 + * derived from this software without specific prior written permission.
28009 + * ALTERNATIVELY, this software may be distributed under the terms of the
28010 + * GNU General Public License ("GPL") as published by the Free Software
28011 + * Foundation, either version 2 of that License or (at your option) any
28014 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28015 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28016 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28017 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
28018 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28019 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28020 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28021 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28022 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28023 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28024 + * POSSIBILITY OF SUCH DAMAGE.
28027 +#ifndef _SG_SW_QM2_H_
28028 +#define _SG_SW_QM2_H_
28030 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
28032 +static inline void dma_to_qm_sg_one(struct dpaa2_sg_entry *qm_sg_ptr,
28033 + dma_addr_t dma, u32 len, u16 offset)
28035 + dpaa2_sg_set_addr(qm_sg_ptr, dma);
28036 + dpaa2_sg_set_format(qm_sg_ptr, dpaa2_sg_single);
28037 + dpaa2_sg_set_final(qm_sg_ptr, false);
28038 + dpaa2_sg_set_len(qm_sg_ptr, len);
28039 + dpaa2_sg_set_bpid(qm_sg_ptr, 0);
28040 + dpaa2_sg_set_offset(qm_sg_ptr, offset);
28044 + * convert scatterlist to h/w link table format
28045 + * but does not have final bit; instead, returns last entry
28047 +static inline struct dpaa2_sg_entry *
28048 +sg_to_qm_sg(struct scatterlist *sg, int sg_count,
28049 + struct dpaa2_sg_entry *qm_sg_ptr, u16 offset)
28051 + while (sg_count && sg) {
28052 + dma_to_qm_sg_one(qm_sg_ptr, sg_dma_address(sg),
28053 + sg_dma_len(sg), offset);
28055 + sg = sg_next(sg);
28058 + return qm_sg_ptr - 1;
28062 + * convert scatterlist to h/w link table format
28063 + * scatterlist must have been previously dma mapped
28065 +static inline void sg_to_qm_sg_last(struct scatterlist *sg, int sg_count,
28066 + struct dpaa2_sg_entry *qm_sg_ptr,
28069 + qm_sg_ptr = sg_to_qm_sg(sg, sg_count, qm_sg_ptr, offset);
28070 + dpaa2_sg_set_final(qm_sg_ptr, true);
28073 +#endif /* _SG_SW_QM2_H_ */
28074 --- a/drivers/crypto/caam/sg_sw_sec4.h
28075 +++ b/drivers/crypto/caam/sg_sw_sec4.h
28080 +#ifndef _SG_SW_SEC4_H_
28081 +#define _SG_SW_SEC4_H_
28085 +#include "sg_sw_qm2.h"
28086 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
28088 -struct sec4_sg_entry;
28089 +struct sec4_sg_entry {
28096 * convert single dma address to h/w link table format
28097 @@ -15,9 +25,15 @@ struct sec4_sg_entry;
28098 static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
28099 dma_addr_t dma, u32 len, u16 offset)
28101 - sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma);
28102 - sec4_sg_ptr->len = cpu_to_caam32(len);
28103 - sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset & SEC4_SG_OFFSET_MASK);
28104 + if (caam_dpaa2) {
28105 + dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len,
28108 + sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma);
28109 + sec4_sg_ptr->len = cpu_to_caam32(len);
28110 + sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset &
28111 + SEC4_SG_OFFSET_MASK);
28114 print_hex_dump(KERN_ERR, "sec4_sg_ptr@: ",
28115 DUMP_PREFIX_ADDRESS, 16, 4, sec4_sg_ptr,
28116 @@ -43,6 +59,14 @@ sg_to_sec4_sg(struct scatterlist *sg, in
28117 return sec4_sg_ptr - 1;
28120 +static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
28123 + dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
28125 + sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
28129 * convert scatterlist to h/w link table format
28130 * scatterlist must have been previously dma mapped
28131 @@ -52,31 +76,7 @@ static inline void sg_to_sec4_sg_last(st
28134 sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset);
28135 - sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
28138 -static inline struct sec4_sg_entry *sg_to_sec4_sg_len(
28139 - struct scatterlist *sg, unsigned int total,
28140 - struct sec4_sg_entry *sec4_sg_ptr)
28143 - unsigned int len = min(sg_dma_len(sg), total);
28145 - dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg), len, 0);
28147 - sg = sg_next(sg);
28150 - return sec4_sg_ptr - 1;
28151 + sg_to_sec4_set_last(sec4_sg_ptr);
28154 -/* derive number of elements in scatterlist, but return 0 for 1 */
28155 -static inline int sg_count(struct scatterlist *sg_list, int nbytes)
28157 - int sg_nents = sg_nents_for_len(sg_list, nbytes);
28159 - if (likely(sg_nents == 1))
28164 +#endif /* _SG_SW_SEC4_H_ */
28165 --- a/drivers/net/wireless/rsi/rsi_91x_usb.c
28166 +++ b/drivers/net/wireless/rsi/rsi_91x_usb.c
28167 @@ -516,7 +516,7 @@ err:
28170 * rsi_disconnect() - This function performs the reverse of the probe function,
28171 - * it deintialize the driver structure.
28172 + * it deinitialize the driver structure.
28173 * @pfunction: Pointer to the USB interface structure.
28176 --- a/drivers/staging/wilc1000/linux_wlan.c
28177 +++ b/drivers/staging/wilc1000/linux_wlan.c
28178 @@ -211,7 +211,7 @@ static void deinit_irq(struct net_device
28179 vif = netdev_priv(dev);
28182 - /* Deintialize IRQ */
28183 + /* Deinitialize IRQ */
28184 if (wilc->dev_irq_num) {
28185 free_irq(wilc->dev_irq_num, wilc);
28186 gpio_free(wilc->gpio);
28187 --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
28188 +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
28189 @@ -2359,7 +2359,7 @@ int wilc_deinit_host_int(struct net_devi
28190 del_timer_sync(&wilc_during_ip_timer);
28193 - netdev_err(net, "Error while deintializing host interface\n");
28194 + netdev_err(net, "Error while deinitializing host interface\n");
28199 +++ b/include/crypto/acompress.h
28202 + * Asynchronous Compression operations
28204 + * Copyright (c) 2016, Intel Corporation
28205 + * Authors: Weigang Li <weigang.li@intel.com>
28206 + * Giovanni Cabiddu <giovanni.cabiddu@intel.com>
28208 + * This program is free software; you can redistribute it and/or modify it
28209 + * under the terms of the GNU General Public License as published by the Free
28210 + * Software Foundation; either version 2 of the License, or (at your option)
28211 + * any later version.
28214 +#ifndef _CRYPTO_ACOMP_H
28215 +#define _CRYPTO_ACOMP_H
28216 +#include <linux/crypto.h>
28218 +#define CRYPTO_ACOMP_ALLOC_OUTPUT 0x00000001
28221 + * struct acomp_req - asynchronous (de)compression request
28223 + * @base: Common attributes for asynchronous crypto requests
28224 + * @src: Source Data
28225 + * @dst: Destination data
28226 + * @slen: Size of the input buffer
28227 + * @dlen: Size of the output buffer and number of bytes produced
28228 + * @flags: Internal flags
28229 + * @__ctx: Start of private context data
28231 +struct acomp_req {
28232 + struct crypto_async_request base;
28233 + struct scatterlist *src;
28234 + struct scatterlist *dst;
28235 + unsigned int slen;
28236 + unsigned int dlen;
28238 + void *__ctx[] CRYPTO_MINALIGN_ATTR;
28242 + * struct crypto_acomp - user-instantiated objects which encapsulate
28243 + * algorithms and core processing logic
28245 + * @compress: Function performs a compress operation
28246 + * @decompress: Function performs a de-compress operation
28247 + * @dst_free: Frees destination buffer if allocated inside the
28249 + * @reqsize: Context size for (de)compression requests
28250 + * @base: Common crypto API algorithm data structure
28252 +struct crypto_acomp {
28253 + int (*compress)(struct acomp_req *req);
28254 + int (*decompress)(struct acomp_req *req);
28255 + void (*dst_free)(struct scatterlist *dst);
28256 + unsigned int reqsize;
28257 + struct crypto_tfm base;
28261 + * struct acomp_alg - asynchronous compression algorithm
28263 + * @compress: Function performs a compress operation
28264 + * @decompress: Function performs a de-compress operation
28265 + * @dst_free: Frees destination buffer if allocated inside the algorithm
28266 + * @init: Initialize the cryptographic transformation object.
28267 + * This function is used to initialize the cryptographic
28268 + * transformation object. This function is called only once at
28269 + * the instantiation time, right after the transformation context
28270 + * was allocated. In case the cryptographic hardware has some
28271 + * special requirements which need to be handled by software, this
28272 + * function shall check for the precise requirement of the
28273 + * transformation and put any software fallbacks in place.
28274 + * @exit: Deinitialize the cryptographic transformation object. This is a
28275 + * counterpart to @init, used to remove various changes set in
28278 + * @reqsize: Context size for (de)compression requests
28279 + * @base: Common crypto API algorithm data structure
28281 +struct acomp_alg {
28282 + int (*compress)(struct acomp_req *req);
28283 + int (*decompress)(struct acomp_req *req);
28284 + void (*dst_free)(struct scatterlist *dst);
28285 + int (*init)(struct crypto_acomp *tfm);
28286 + void (*exit)(struct crypto_acomp *tfm);
28287 + unsigned int reqsize;
28288 + struct crypto_alg base;
28292 + * DOC: Asynchronous Compression API
28294 + * The Asynchronous Compression API is used with the algorithms of type
28295 + * CRYPTO_ALG_TYPE_ACOMPRESS (listed as type "acomp" in /proc/crypto)
28299 + * crypto_alloc_acomp() -- allocate ACOMPRESS tfm handle
28300 + * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
28301 + * compression algorithm e.g. "deflate"
28302 + * @type: specifies the type of the algorithm
28303 + * @mask: specifies the mask for the algorithm
28305 + * Allocate a handle for a compression algorithm. The returned struct
28306 + * crypto_acomp is the handle that is required for any subsequent
28307 + * API invocation for the compression operations.
28309 + * Return: allocated handle in case of success; IS_ERR() is true in case
28310 + * of an error, PTR_ERR() returns the error code.
28312 +struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
28315 +static inline struct crypto_tfm *crypto_acomp_tfm(struct crypto_acomp *tfm)
28317 + return &tfm->base;
28320 +static inline struct acomp_alg *__crypto_acomp_alg(struct crypto_alg *alg)
28322 + return container_of(alg, struct acomp_alg, base);
28325 +static inline struct crypto_acomp *__crypto_acomp_tfm(struct crypto_tfm *tfm)
28327 + return container_of(tfm, struct crypto_acomp, base);
28330 +static inline struct acomp_alg *crypto_acomp_alg(struct crypto_acomp *tfm)
28332 + return __crypto_acomp_alg(crypto_acomp_tfm(tfm)->__crt_alg);
28335 +static inline unsigned int crypto_acomp_reqsize(struct crypto_acomp *tfm)
28337 + return tfm->reqsize;
28340 +static inline void acomp_request_set_tfm(struct acomp_req *req,
28341 + struct crypto_acomp *tfm)
28343 + req->base.tfm = crypto_acomp_tfm(tfm);
28346 +static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req)
28348 + return __crypto_acomp_tfm(req->base.tfm);
28352 + * crypto_free_acomp() -- free ACOMPRESS tfm handle
28354 + * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp()
28356 +static inline void crypto_free_acomp(struct crypto_acomp *tfm)
28358 + crypto_destroy_tfm(tfm, crypto_acomp_tfm(tfm));
28361 +static inline int crypto_has_acomp(const char *alg_name, u32 type, u32 mask)
28363 + type &= ~CRYPTO_ALG_TYPE_MASK;
28364 + type |= CRYPTO_ALG_TYPE_ACOMPRESS;
28365 + mask |= CRYPTO_ALG_TYPE_MASK;
28367 + return crypto_has_alg(alg_name, type, mask);
28371 + * acomp_request_alloc() -- allocates asynchronous (de)compression request
28373 + * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp()
28375 + * Return: allocated handle in case of success or NULL in case of an error
28377 +struct acomp_req *acomp_request_alloc(struct crypto_acomp *tfm);
28380 + * acomp_request_free() -- zeroize and free asynchronous (de)compression
28381 + * request as well as the output buffer if allocated
28382 + * inside the algorithm
28384 + * @req: request to free
28386 +void acomp_request_free(struct acomp_req *req);
28389 + * acomp_request_set_callback() -- Sets an asynchronous callback
28391 + * Callback will be called when an asynchronous operation on a given
28392 + * request is finished.
28394 + * @req: request that the callback will be set for
28395 + * @flgs: specify for instance if the operation may backlog
28396 + * @cmlp: callback which will be called
28397 + * @data: private data used by the caller
28399 +static inline void acomp_request_set_callback(struct acomp_req *req,
28401 + crypto_completion_t cmpl,
28404 + req->base.complete = cmpl;
28405 + req->base.data = data;
28406 + req->base.flags = flgs;
28410 + * acomp_request_set_params() -- Sets request parameters
28412 + * Sets parameters required by an acomp operation
28414 + * @req: asynchronous compress request
28415 + * @src: pointer to input buffer scatterlist
28416 + * @dst: pointer to output buffer scatterlist. If this is NULL, the
28417 + * acomp layer will allocate the output memory
28418 + * @slen: size of the input buffer
28419 + * @dlen: size of the output buffer. If dst is NULL, this can be used by
28420 + * the user to specify the maximum amount of memory to allocate
28422 +static inline void acomp_request_set_params(struct acomp_req *req,
28423 + struct scatterlist *src,
28424 + struct scatterlist *dst,
28425 + unsigned int slen,
28426 + unsigned int dlen)
28430 + req->slen = slen;
28431 + req->dlen = dlen;
28434 + req->flags |= CRYPTO_ACOMP_ALLOC_OUTPUT;
28438 + * crypto_acomp_compress() -- Invoke asynchronous compress operation
28440 + * Function invokes the asynchronous compress operation
28442 + * @req: asynchronous compress request
28444 + * Return: zero on success; error code in case of error
28446 +static inline int crypto_acomp_compress(struct acomp_req *req)
28448 + struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
28450 + return tfm->compress(req);
28454 + * crypto_acomp_decompress() -- Invoke asynchronous decompress operation
28456 + * Function invokes the asynchronous decompress operation
28458 + * @req: asynchronous compress request
28460 + * Return: zero on success; error code in case of error
28462 +static inline int crypto_acomp_decompress(struct acomp_req *req)
28464 + struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
28466 + return tfm->decompress(req);
28471 +++ b/include/crypto/internal/acompress.h
28474 + * Asynchronous Compression operations
28476 + * Copyright (c) 2016, Intel Corporation
28477 + * Authors: Weigang Li <weigang.li@intel.com>
28478 + * Giovanni Cabiddu <giovanni.cabiddu@intel.com>
28480 + * This program is free software; you can redistribute it and/or modify it
28481 + * under the terms of the GNU General Public License as published by the Free
28482 + * Software Foundation; either version 2 of the License, or (at your option)
28483 + * any later version.
28486 +#ifndef _CRYPTO_ACOMP_INT_H
28487 +#define _CRYPTO_ACOMP_INT_H
28488 +#include <crypto/acompress.h>
28491 + * Transform internal helpers.
28493 +static inline void *acomp_request_ctx(struct acomp_req *req)
28495 + return req->__ctx;
28498 +static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm)
28500 + return tfm->base.__crt_ctx;
28503 +static inline void acomp_request_complete(struct acomp_req *req,
28506 + req->base.complete(&req->base, err);
28509 +static inline const char *acomp_alg_name(struct crypto_acomp *tfm)
28511 + return crypto_acomp_tfm(tfm)->__crt_alg->cra_name;
28514 +static inline struct acomp_req *__acomp_request_alloc(struct crypto_acomp *tfm)
28516 + struct acomp_req *req;
28518 + req = kzalloc(sizeof(*req) + crypto_acomp_reqsize(tfm), GFP_KERNEL);
28520 + acomp_request_set_tfm(req, tfm);
28524 +static inline void __acomp_request_free(struct acomp_req *req)
28530 + * crypto_register_acomp() -- Register asynchronous compression algorithm
28532 + * Function registers an implementation of an asynchronous
28533 + * compression algorithm
28535 + * @alg: algorithm definition
28537 + * Return: zero on success; error code in case of error
28539 +int crypto_register_acomp(struct acomp_alg *alg);
28542 + * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm
28544 + * Function unregisters an implementation of an asynchronous
28545 + * compression algorithm
28547 + * @alg: algorithm definition
28549 + * Return: zero on success; error code in case of error
28551 +int crypto_unregister_acomp(struct acomp_alg *alg);
28555 +++ b/include/crypto/internal/scompress.h
28558 + * Synchronous Compression operations
28560 + * Copyright 2015 LG Electronics Inc.
28561 + * Copyright (c) 2016, Intel Corporation
28562 + * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
28564 + * This program is free software; you can redistribute it and/or modify it
28565 + * under the terms of the GNU General Public License as published by the Free
28566 + * Software Foundation; either version 2 of the License, or (at your option)
28567 + * any later version.
28570 +#ifndef _CRYPTO_SCOMP_INT_H
28571 +#define _CRYPTO_SCOMP_INT_H
28572 +#include <linux/crypto.h>
28574 +#define SCOMP_SCRATCH_SIZE 131072
28576 +struct crypto_scomp {
28577 + struct crypto_tfm base;
28581 + * struct scomp_alg - synchronous compression algorithm
28583 + * @alloc_ctx: Function allocates algorithm specific context
28584 + * @free_ctx: Function frees context allocated with alloc_ctx
28585 + * @compress: Function performs a compress operation
28586 + * @decompress: Function performs a de-compress operation
28587 + * @init: Initialize the cryptographic transformation object.
28588 + * This function is used to initialize the cryptographic
28589 + * transformation object. This function is called only once at
28590 + * the instantiation time, right after the transformation context
28591 + * was allocated. In case the cryptographic hardware has some
28592 + * special requirements which need to be handled by software, this
28593 + * function shall check for the precise requirement of the
28594 + * transformation and put any software fallbacks in place.
28595 + * @exit: Deinitialize the cryptographic transformation object. This is a
28596 + * counterpart to @init, used to remove various changes set in
28598 + * @base: Common crypto API algorithm data structure
28600 +struct scomp_alg {
28601 + void *(*alloc_ctx)(struct crypto_scomp *tfm);
28602 + void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
28603 + int (*compress)(struct crypto_scomp *tfm, const u8 *src,
28604 + unsigned int slen, u8 *dst, unsigned int *dlen,
28606 + int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
28607 + unsigned int slen, u8 *dst, unsigned int *dlen,
28609 + struct crypto_alg base;
28612 +static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
28614 + return container_of(alg, struct scomp_alg, base);
28617 +static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
28619 + return container_of(tfm, struct crypto_scomp, base);
28622 +static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
28624 + return &tfm->base;
28627 +static inline void crypto_free_scomp(struct crypto_scomp *tfm)
28629 + crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
28632 +static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
28634 + return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
28637 +static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
28639 + return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
28642 +static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
28645 + return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
28648 +static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
28649 + const u8 *src, unsigned int slen,
28650 + u8 *dst, unsigned int *dlen, void *ctx)
28652 + return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
28655 +static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
28656 + const u8 *src, unsigned int slen,
28657 + u8 *dst, unsigned int *dlen,
28660 + return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
28664 +int crypto_init_scomp_ops_async(struct crypto_tfm *tfm);
28665 +struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req);
28666 +void crypto_acomp_scomp_free_ctx(struct acomp_req *req);
28669 + * crypto_register_scomp() -- Register synchronous compression algorithm
28671 + * Function registers an implementation of a synchronous
28672 + * compression algorithm
28674 + * @alg: algorithm definition
28676 + * Return: zero on success; error code in case of error
28678 +int crypto_register_scomp(struct scomp_alg *alg);
28681 + * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
28683 + * Function unregisters an implementation of a synchronous
28684 + * compression algorithm
28686 + * @alg: algorithm definition
28688 + * Return: zero on success; error code in case of error
28690 +int crypto_unregister_scomp(struct scomp_alg *alg);
28693 --- a/include/linux/crypto.h
28694 +++ b/include/linux/crypto.h
28696 #define CRYPTO_ALG_TYPE_SKCIPHER 0x00000005
28697 #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006
28698 #define CRYPTO_ALG_TYPE_KPP 0x00000008
28699 +#define CRYPTO_ALG_TYPE_ACOMPRESS 0x0000000a
28700 +#define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000b
28701 #define CRYPTO_ALG_TYPE_RNG 0x0000000c
28702 #define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d
28703 #define CRYPTO_ALG_TYPE_DIGEST 0x0000000e
28705 #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
28706 #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000e
28707 #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
28708 +#define CRYPTO_ALG_TYPE_ACOMPRESS_MASK 0x0000000e
28710 #define CRYPTO_ALG_LARVAL 0x00000010
28711 #define CRYPTO_ALG_DEAD 0x00000020
28712 --- a/include/uapi/linux/cryptouser.h
28713 +++ b/include/uapi/linux/cryptouser.h
28714 @@ -46,6 +46,7 @@ enum crypto_attr_type_t {
28715 CRYPTOCFGA_REPORT_CIPHER, /* struct crypto_report_cipher */
28716 CRYPTOCFGA_REPORT_AKCIPHER, /* struct crypto_report_akcipher */
28717 CRYPTOCFGA_REPORT_KPP, /* struct crypto_report_kpp */
28718 + CRYPTOCFGA_REPORT_ACOMP, /* struct crypto_report_acomp */
28721 #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1)
28722 @@ -112,5 +113,9 @@ struct crypto_report_kpp {
28723 char type[CRYPTO_MAX_NAME];
28726 +struct crypto_report_acomp {
28727 + char type[CRYPTO_MAX_NAME];
28730 #define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + \
28731 sizeof(struct crypto_report_blkcipher))
28732 --- a/scripts/spelling.txt
28733 +++ b/scripts/spelling.txt
28734 @@ -305,6 +305,9 @@ defintion||definition
28735 defintions||definitions
28738 +deintializing||deinitializing
28739 +deintialize||deinitialize
28740 +deintialized||deinitialized
28744 --- a/sound/soc/amd/acp-pcm-dma.c
28745 +++ b/sound/soc/amd/acp-pcm-dma.c
28746 @@ -506,7 +506,7 @@ static int acp_init(void __iomem *acp_mm
28750 -/* Deintialize ACP */
28751 +/* Deinitialize ACP */
28752 static int acp_deinit(void __iomem *acp_mmio)