2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-02-05 13:18:13 +08:00
|
|
|
/**
|
|
|
|
* AMCC SoC PPC4xx Crypto Driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Applied Micro Circuits Corporation.
|
|
|
|
* All rights reserved. James Hsiao <jhsiao@amcc.com>
|
|
|
|
*
|
|
|
|
* This file implements AMCC crypto offload Linux device driver for use with
|
|
|
|
* Linux CryptoAPI.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/spinlock_types.h>
|
|
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/scatterlist.h>
|
|
|
|
#include <linux/crypto.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/init.h>
|
2013-11-11 13:19:08 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
2009-02-05 13:18:13 +08:00
|
|
|
#include <linux/of_platform.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-02-05 13:18:13 +08:00
|
|
|
#include <asm/dcr.h>
|
|
|
|
#include <asm/dcr-regs.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2017-10-04 07:00:15 +08:00
|
|
|
#include <crypto/aead.h>
|
2009-02-05 13:18:13 +08:00
|
|
|
#include <crypto/aes.h>
|
2017-08-25 21:47:21 +08:00
|
|
|
#include <crypto/ctr.h>
|
2017-10-04 07:00:17 +08:00
|
|
|
#include <crypto/gcm.h>
|
2020-11-13 13:20:21 +08:00
|
|
|
#include <crypto/sha1.h>
|
2018-12-23 09:16:13 +08:00
|
|
|
#include <crypto/rng.h>
|
2017-08-25 21:47:22 +08:00
|
|
|
#include <crypto/scatterwalk.h>
|
2018-04-20 00:41:52 +08:00
|
|
|
#include <crypto/skcipher.h>
|
2017-10-04 07:00:15 +08:00
|
|
|
#include <crypto/internal/aead.h>
|
2018-12-23 09:16:13 +08:00
|
|
|
#include <crypto/internal/rng.h>
|
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 07:00:09 +08:00
|
|
|
#include <crypto/internal/skcipher.h>
|
2009-02-05 13:18:13 +08:00
|
|
|
#include "crypto4xx_reg_def.h"
|
|
|
|
#include "crypto4xx_core.h"
|
|
|
|
#include "crypto4xx_sa.h"
|
2016-04-18 18:57:41 +08:00
|
|
|
#include "crypto4xx_trng.h"
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
#define PPC4XX_SEC_VERSION_STR "0.5"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PPC4xx Crypto Engine Initialization Routine
|
|
|
|
*/
|
|
|
|
static void crypto4xx_hw_init(struct crypto4xx_device *dev)
|
|
|
|
{
|
|
|
|
union ce_ring_size ring_size;
|
2017-04-21 19:13:49 +08:00
|
|
|
union ce_ring_control ring_ctrl;
|
2009-02-05 13:18:13 +08:00
|
|
|
union ce_part_ring_size part_ring_size;
|
|
|
|
union ce_io_threshold io_threshold;
|
|
|
|
u32 rand_num;
|
|
|
|
union ce_pe_dma_cfg pe_dma_cfg;
|
2011-06-27 15:39:07 +08:00
|
|
|
u32 device_ctrl;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
writel(PPC4XX_BYTE_ORDER, dev->ce_base + CRYPTO4XX_BYTE_ORDER_CFG);
|
|
|
|
/* setup pe dma, include reset sg, pdr and pe, then release reset */
|
|
|
|
pe_dma_cfg.w = 0;
|
|
|
|
pe_dma_cfg.bf.bo_sgpd_en = 1;
|
|
|
|
pe_dma_cfg.bf.bo_data_en = 0;
|
|
|
|
pe_dma_cfg.bf.bo_sa_en = 1;
|
|
|
|
pe_dma_cfg.bf.bo_pd_en = 1;
|
|
|
|
pe_dma_cfg.bf.dynamic_sa_en = 1;
|
|
|
|
pe_dma_cfg.bf.reset_sg = 1;
|
|
|
|
pe_dma_cfg.bf.reset_pdr = 1;
|
|
|
|
pe_dma_cfg.bf.reset_pe = 1;
|
|
|
|
writel(pe_dma_cfg.w, dev->ce_base + CRYPTO4XX_PE_DMA_CFG);
|
|
|
|
/* un reset pe,sg and pdr */
|
|
|
|
pe_dma_cfg.bf.pe_mode = 0;
|
|
|
|
pe_dma_cfg.bf.reset_sg = 0;
|
|
|
|
pe_dma_cfg.bf.reset_pdr = 0;
|
|
|
|
pe_dma_cfg.bf.reset_pe = 0;
|
|
|
|
pe_dma_cfg.bf.bo_td_en = 0;
|
|
|
|
writel(pe_dma_cfg.w, dev->ce_base + CRYPTO4XX_PE_DMA_CFG);
|
|
|
|
writel(dev->pdr_pa, dev->ce_base + CRYPTO4XX_PDR_BASE);
|
|
|
|
writel(dev->pdr_pa, dev->ce_base + CRYPTO4XX_RDR_BASE);
|
|
|
|
writel(PPC4XX_PRNG_CTRL_AUTO_EN, dev->ce_base + CRYPTO4XX_PRNG_CTRL);
|
|
|
|
get_random_bytes(&rand_num, sizeof(rand_num));
|
|
|
|
writel(rand_num, dev->ce_base + CRYPTO4XX_PRNG_SEED_L);
|
|
|
|
get_random_bytes(&rand_num, sizeof(rand_num));
|
|
|
|
writel(rand_num, dev->ce_base + CRYPTO4XX_PRNG_SEED_H);
|
|
|
|
ring_size.w = 0;
|
|
|
|
ring_size.bf.ring_offset = PPC4XX_PD_SIZE;
|
|
|
|
ring_size.bf.ring_size = PPC4XX_NUM_PD;
|
|
|
|
writel(ring_size.w, dev->ce_base + CRYPTO4XX_RING_SIZE);
|
|
|
|
ring_ctrl.w = 0;
|
|
|
|
writel(ring_ctrl.w, dev->ce_base + CRYPTO4XX_RING_CTRL);
|
2011-06-27 15:39:07 +08:00
|
|
|
device_ctrl = readl(dev->ce_base + CRYPTO4XX_DEVICE_CTRL);
|
|
|
|
device_ctrl |= PPC4XX_DC_3DES_EN;
|
|
|
|
writel(device_ctrl, dev->ce_base + CRYPTO4XX_DEVICE_CTRL);
|
2009-02-05 13:18:13 +08:00
|
|
|
writel(dev->gdr_pa, dev->ce_base + CRYPTO4XX_GATH_RING_BASE);
|
|
|
|
writel(dev->sdr_pa, dev->ce_base + CRYPTO4XX_SCAT_RING_BASE);
|
|
|
|
part_ring_size.w = 0;
|
|
|
|
part_ring_size.bf.sdr_size = PPC4XX_SDR_SIZE;
|
|
|
|
part_ring_size.bf.gdr_size = PPC4XX_GDR_SIZE;
|
|
|
|
writel(part_ring_size.w, dev->ce_base + CRYPTO4XX_PART_RING_SIZE);
|
|
|
|
writel(PPC4XX_SD_BUFFER_SIZE, dev->ce_base + CRYPTO4XX_PART_RING_CFG);
|
|
|
|
io_threshold.w = 0;
|
|
|
|
io_threshold.bf.output_threshold = PPC4XX_OUTPUT_THRESHOLD;
|
|
|
|
io_threshold.bf.input_threshold = PPC4XX_INPUT_THRESHOLD;
|
|
|
|
writel(io_threshold.w, dev->ce_base + CRYPTO4XX_IO_THRESHOLD);
|
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_PDR_BASE_UADDR);
|
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_RDR_BASE_UADDR);
|
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_PKT_SRC_UADDR);
|
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_PKT_DEST_UADDR);
|
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_SA_UADDR);
|
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_GATH_RING_BASE_UADDR);
|
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_SCAT_RING_BASE_UADDR);
|
|
|
|
/* un reset pe,sg and pdr */
|
|
|
|
pe_dma_cfg.bf.pe_mode = 1;
|
|
|
|
pe_dma_cfg.bf.reset_sg = 0;
|
|
|
|
pe_dma_cfg.bf.reset_pdr = 0;
|
|
|
|
pe_dma_cfg.bf.reset_pe = 0;
|
|
|
|
pe_dma_cfg.bf.bo_td_en = 0;
|
|
|
|
writel(pe_dma_cfg.w, dev->ce_base + CRYPTO4XX_PE_DMA_CFG);
|
|
|
|
/*clear all pending interrupt*/
|
|
|
|
writel(PPC4XX_INTERRUPT_CLR, dev->ce_base + CRYPTO4XX_INT_CLR);
|
|
|
|
writel(PPC4XX_INT_DESCR_CNT, dev->ce_base + CRYPTO4XX_INT_DESCR_CNT);
|
|
|
|
writel(PPC4XX_INT_DESCR_CNT, dev->ce_base + CRYPTO4XX_INT_DESCR_CNT);
|
|
|
|
writel(PPC4XX_INT_CFG, dev->ce_base + CRYPTO4XX_INT_CFG);
|
2017-12-23 04:18:36 +08:00
|
|
|
if (dev->is_revb) {
|
|
|
|
writel(PPC4XX_INT_TIMEOUT_CNT_REVB << 10,
|
|
|
|
dev->ce_base + CRYPTO4XX_INT_TIMEOUT_CNT);
|
|
|
|
writel(PPC4XX_PD_DONE_INT | PPC4XX_TMO_ERR_INT,
|
|
|
|
dev->ce_base + CRYPTO4XX_INT_EN);
|
|
|
|
} else {
|
|
|
|
writel(PPC4XX_PD_DONE_INT, dev->ce_base + CRYPTO4XX_INT_EN);
|
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size)
|
|
|
|
{
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:03:40 +08:00
|
|
|
ctx->sa_in = kcalloc(size, 4, GFP_ATOMIC);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (ctx->sa_in == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:03:40 +08:00
|
|
|
ctx->sa_out = kcalloc(size, 4, GFP_ATOMIC);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (ctx->sa_out == NULL) {
|
2017-10-04 07:00:14 +08:00
|
|
|
kfree(ctx->sa_in);
|
|
|
|
ctx->sa_in = NULL;
|
2009-02-05 13:18:13 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->sa_len = size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void crypto4xx_free_sa(struct crypto4xx_ctx *ctx)
|
|
|
|
{
|
2017-10-04 07:00:14 +08:00
|
|
|
kfree(ctx->sa_in);
|
|
|
|
ctx->sa_in = NULL;
|
|
|
|
kfree(ctx->sa_out);
|
|
|
|
ctx->sa_out = NULL;
|
2009-02-05 13:18:13 +08:00
|
|
|
ctx->sa_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* alloc memory for the gather ring
|
|
|
|
* no need to alloc buf for the ring
|
|
|
|
* gdr_tail, gdr_head and gdr_count are initialized by this function
|
|
|
|
*/
|
|
|
|
static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
dev->pdr = dma_alloc_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct ce_pd) * PPC4XX_NUM_PD,
|
2020-01-02 06:27:02 +08:00
|
|
|
&dev->pdr_pa, GFP_KERNEL);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (!dev->pdr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:03:40 +08:00
|
|
|
dev->pdr_uinfo = kcalloc(PPC4XX_NUM_PD, sizeof(struct pd_uinfo),
|
|
|
|
GFP_KERNEL);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (!dev->pdr_uinfo) {
|
|
|
|
dma_free_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct ce_pd) * PPC4XX_NUM_PD,
|
|
|
|
dev->pdr,
|
|
|
|
dev->pdr_pa);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
dev->shadow_sa_pool = dma_alloc_coherent(dev->core_dev->device,
|
2017-08-25 21:47:25 +08:00
|
|
|
sizeof(union shadow_sa_buf) * PPC4XX_NUM_PD,
|
2009-02-05 13:18:13 +08:00
|
|
|
&dev->shadow_sa_pool_pa,
|
2020-01-02 06:27:02 +08:00
|
|
|
GFP_KERNEL);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (!dev->shadow_sa_pool)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dev->shadow_sr_pool = dma_alloc_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct sa_state_record) * PPC4XX_NUM_PD,
|
2020-01-02 06:27:02 +08:00
|
|
|
&dev->shadow_sr_pool_pa, GFP_KERNEL);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (!dev->shadow_sr_pool)
|
|
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < PPC4XX_NUM_PD; i++) {
|
2017-10-04 07:00:11 +08:00
|
|
|
struct ce_pd *pd = &dev->pdr[i];
|
|
|
|
struct pd_uinfo *pd_uinfo = &dev->pdr_uinfo[i];
|
|
|
|
|
|
|
|
pd->sa = dev->shadow_sa_pool_pa +
|
|
|
|
sizeof(union shadow_sa_buf) * i;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
/* alloc 256 bytes which is enough for any kind of dynamic sa */
|
2017-08-25 21:47:25 +08:00
|
|
|
pd_uinfo->sa_va = &dev->shadow_sa_pool[i].sa;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
/* alloc state record */
|
2017-08-25 21:47:25 +08:00
|
|
|
pd_uinfo->sr_va = &dev->shadow_sr_pool[i];
|
2009-02-05 13:18:13 +08:00
|
|
|
pd_uinfo->sr_pa = dev->shadow_sr_pool_pa +
|
|
|
|
sizeof(struct sa_state_record) * i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_destroy_pdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
2017-08-25 21:47:24 +08:00
|
|
|
if (dev->pdr)
|
2009-02-05 13:18:13 +08:00
|
|
|
dma_free_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct ce_pd) * PPC4XX_NUM_PD,
|
|
|
|
dev->pdr, dev->pdr_pa);
|
2017-08-25 21:47:24 +08:00
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
if (dev->shadow_sa_pool)
|
2017-08-25 21:47:25 +08:00
|
|
|
dma_free_coherent(dev->core_dev->device,
|
|
|
|
sizeof(union shadow_sa_buf) * PPC4XX_NUM_PD,
|
|
|
|
dev->shadow_sa_pool, dev->shadow_sa_pool_pa);
|
2017-08-25 21:47:24 +08:00
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
if (dev->shadow_sr_pool)
|
|
|
|
dma_free_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct sa_state_record) * PPC4XX_NUM_PD,
|
|
|
|
dev->shadow_sr_pool, dev->shadow_sr_pool_pa);
|
|
|
|
|
|
|
|
kfree(dev->pdr_uinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 crypto4xx_get_pd_from_pdr_nolock(struct crypto4xx_device *dev)
|
|
|
|
{
|
|
|
|
u32 retval;
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
retval = dev->pdr_head;
|
|
|
|
tmp = (dev->pdr_head + 1) % PPC4XX_NUM_PD;
|
|
|
|
|
|
|
|
if (tmp == dev->pdr_tail)
|
|
|
|
return ERING_WAS_FULL;
|
|
|
|
|
|
|
|
dev->pdr_head = tmp;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 crypto4xx_put_pd_to_pdr(struct crypto4xx_device *dev, u32 idx)
|
|
|
|
{
|
2017-08-25 21:47:25 +08:00
|
|
|
struct pd_uinfo *pd_uinfo = &dev->pdr_uinfo[idx];
|
2017-10-04 07:00:13 +08:00
|
|
|
u32 tail;
|
2009-02-05 13:18:13 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->core_dev->lock, flags);
|
2017-10-04 07:00:13 +08:00
|
|
|
pd_uinfo->state = PD_ENTRY_FREE;
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
if (dev->pdr_tail != PPC4XX_LAST_PD)
|
|
|
|
dev->pdr_tail++;
|
|
|
|
else
|
|
|
|
dev->pdr_tail = 0;
|
2017-10-04 07:00:13 +08:00
|
|
|
tail = dev->pdr_tail;
|
2009-02-05 13:18:13 +08:00
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
|
2017-10-04 07:00:13 +08:00
|
|
|
return tail;
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* alloc memory for the gather ring
|
|
|
|
* no need to alloc buf for the ring
|
|
|
|
* gdr_tail, gdr_head and gdr_count are initialized by this function
|
|
|
|
*/
|
|
|
|
static u32 crypto4xx_build_gdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
dev->gdr = dma_alloc_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct ce_gd) * PPC4XX_NUM_GD,
|
2020-01-02 06:27:02 +08:00
|
|
|
&dev->gdr_pa, GFP_KERNEL);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (!dev->gdr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void crypto4xx_destroy_gdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
2020-01-02 06:27:01 +08:00
|
|
|
if (dev->gdr)
|
|
|
|
dma_free_coherent(dev->core_dev->device,
|
2009-02-05 13:18:13 +08:00
|
|
|
sizeof(struct ce_gd) * PPC4XX_NUM_GD,
|
|
|
|
dev->gdr, dev->gdr_pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* when this function is called.
|
|
|
|
* preemption or interrupt must be disabled
|
|
|
|
*/
|
2017-10-04 07:00:12 +08:00
|
|
|
static u32 crypto4xx_get_n_gd(struct crypto4xx_device *dev, int n)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
u32 retval;
|
|
|
|
u32 tmp;
|
2017-10-04 07:00:12 +08:00
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
if (n >= PPC4XX_NUM_GD)
|
|
|
|
return ERING_WAS_FULL;
|
|
|
|
|
|
|
|
retval = dev->gdr_head;
|
|
|
|
tmp = (dev->gdr_head + n) % PPC4XX_NUM_GD;
|
|
|
|
if (dev->gdr_head > dev->gdr_tail) {
|
|
|
|
if (tmp < dev->gdr_head && tmp >= dev->gdr_tail)
|
|
|
|
return ERING_WAS_FULL;
|
|
|
|
} else if (dev->gdr_head < dev->gdr_tail) {
|
|
|
|
if (tmp < dev->gdr_head || tmp >= dev->gdr_tail)
|
|
|
|
return ERING_WAS_FULL;
|
|
|
|
}
|
|
|
|
dev->gdr_head = tmp;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 crypto4xx_put_gd_to_gdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->core_dev->lock, flags);
|
|
|
|
if (dev->gdr_tail == dev->gdr_head) {
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->gdr_tail != PPC4XX_LAST_GD)
|
|
|
|
dev->gdr_tail++;
|
|
|
|
else
|
|
|
|
dev->gdr_tail = 0;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct ce_gd *crypto4xx_get_gdp(struct crypto4xx_device *dev,
|
|
|
|
dma_addr_t *gd_dma, u32 idx)
|
|
|
|
{
|
|
|
|
*gd_dma = dev->gdr_pa + sizeof(struct ce_gd) * idx;
|
|
|
|
|
2017-08-25 21:47:25 +08:00
|
|
|
return &dev->gdr[idx];
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* alloc memory for the scatter ring
|
|
|
|
* need to alloc buf for the ring
|
|
|
|
* sdr_tail, sdr_head and sdr_count are initialized by this function
|
|
|
|
*/
|
|
|
|
static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dev->scatter_buffer_va =
|
|
|
|
dma_alloc_coherent(dev->core_dev->device,
|
2017-08-25 21:47:23 +08:00
|
|
|
PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD,
|
2020-01-02 06:27:02 +08:00
|
|
|
&dev->scatter_buffer_pa, GFP_KERNEL);
|
2019-11-01 00:14:38 +08:00
|
|
|
if (!dev->scatter_buffer_va)
|
2009-02-05 13:18:13 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2020-01-02 06:27:01 +08:00
|
|
|
/* alloc memory for scatter descriptor ring */
|
|
|
|
dev->sdr = dma_alloc_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct ce_sd) * PPC4XX_NUM_SD,
|
2020-01-02 06:27:02 +08:00
|
|
|
&dev->sdr_pa, GFP_KERNEL);
|
2020-01-02 06:27:01 +08:00
|
|
|
if (!dev->sdr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
for (i = 0; i < PPC4XX_NUM_SD; i++) {
|
2017-08-25 21:47:25 +08:00
|
|
|
dev->sdr[i].ptr = dev->scatter_buffer_pa +
|
2017-08-25 21:47:23 +08:00
|
|
|
PPC4XX_SD_BUFFER_SIZE * i;
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_destroy_sdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
2017-08-25 21:47:24 +08:00
|
|
|
if (dev->sdr)
|
2009-02-05 13:18:13 +08:00
|
|
|
dma_free_coherent(dev->core_dev->device,
|
|
|
|
sizeof(struct ce_sd) * PPC4XX_NUM_SD,
|
|
|
|
dev->sdr, dev->sdr_pa);
|
|
|
|
|
2017-08-25 21:47:24 +08:00
|
|
|
if (dev->scatter_buffer_va)
|
2009-02-05 13:18:13 +08:00
|
|
|
dma_free_coherent(dev->core_dev->device,
|
2017-08-25 21:47:23 +08:00
|
|
|
PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD,
|
2009-02-05 13:18:13 +08:00
|
|
|
dev->scatter_buffer_va,
|
|
|
|
dev->scatter_buffer_pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* when this function is called.
|
|
|
|
* preemption or interrupt must be disabled
|
|
|
|
*/
|
|
|
|
static u32 crypto4xx_get_n_sd(struct crypto4xx_device *dev, int n)
|
|
|
|
{
|
|
|
|
u32 retval;
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
if (n >= PPC4XX_NUM_SD)
|
|
|
|
return ERING_WAS_FULL;
|
|
|
|
|
|
|
|
retval = dev->sdr_head;
|
|
|
|
tmp = (dev->sdr_head + n) % PPC4XX_NUM_SD;
|
|
|
|
if (dev->sdr_head > dev->gdr_tail) {
|
|
|
|
if (tmp < dev->sdr_head && tmp >= dev->sdr_tail)
|
|
|
|
return ERING_WAS_FULL;
|
|
|
|
} else if (dev->sdr_head < dev->sdr_tail) {
|
|
|
|
if (tmp < dev->sdr_head || tmp >= dev->sdr_tail)
|
|
|
|
return ERING_WAS_FULL;
|
|
|
|
} /* the head = tail, or empty case is already take cared */
|
|
|
|
dev->sdr_head = tmp;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 crypto4xx_put_sd_to_sdr(struct crypto4xx_device *dev)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->core_dev->lock, flags);
|
|
|
|
if (dev->sdr_tail == dev->sdr_head) {
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (dev->sdr_tail != PPC4XX_LAST_SD)
|
|
|
|
dev->sdr_tail++;
|
|
|
|
else
|
|
|
|
dev->sdr_tail = 0;
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct ce_sd *crypto4xx_get_sdp(struct crypto4xx_device *dev,
|
|
|
|
dma_addr_t *sd_dma, u32 idx)
|
|
|
|
{
|
|
|
|
*sd_dma = dev->sdr_pa + sizeof(struct ce_sd) * idx;
|
|
|
|
|
2017-08-25 21:47:25 +08:00
|
|
|
return &dev->sdr[idx];
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_copy_pkt_to_dst(struct crypto4xx_device *dev,
|
|
|
|
struct ce_pd *pd,
|
|
|
|
struct pd_uinfo *pd_uinfo,
|
|
|
|
u32 nbytes,
|
|
|
|
struct scatterlist *dst)
|
|
|
|
{
|
2017-08-25 21:47:22 +08:00
|
|
|
unsigned int first_sd = pd_uinfo->first_sd;
|
|
|
|
unsigned int last_sd;
|
|
|
|
unsigned int overflow = 0;
|
|
|
|
unsigned int to_copy;
|
|
|
|
unsigned int dst_start = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because the scatter buffers are all neatly organized in one
|
|
|
|
* big continuous ringbuffer; scatterwalk_map_and_copy() can
|
|
|
|
* be instructed to copy a range of buffers in one go.
|
|
|
|
*/
|
|
|
|
|
|
|
|
last_sd = (first_sd + pd_uinfo->num_sd);
|
|
|
|
if (last_sd > PPC4XX_LAST_SD) {
|
|
|
|
last_sd = PPC4XX_LAST_SD;
|
|
|
|
overflow = last_sd % PPC4XX_NUM_SD;
|
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
while (nbytes) {
|
2017-08-25 21:47:22 +08:00
|
|
|
void *buf = dev->scatter_buffer_va +
|
|
|
|
first_sd * PPC4XX_SD_BUFFER_SIZE;
|
|
|
|
|
|
|
|
to_copy = min(nbytes, PPC4XX_SD_BUFFER_SIZE *
|
|
|
|
(1 + last_sd - first_sd));
|
|
|
|
scatterwalk_map_and_copy(buf, dst, dst_start, to_copy, 1);
|
|
|
|
nbytes -= to_copy;
|
|
|
|
|
|
|
|
if (overflow) {
|
|
|
|
first_sd = 0;
|
|
|
|
last_sd = overflow;
|
|
|
|
dst_start += to_copy;
|
|
|
|
overflow = 0;
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 07:00:11 +08:00
|
|
|
static void crypto4xx_copy_digest_to_dst(void *dst,
|
|
|
|
struct pd_uinfo *pd_uinfo,
|
2009-02-05 13:18:13 +08:00
|
|
|
struct crypto4xx_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct dynamic_sa_ctl *sa = (struct dynamic_sa_ctl *) ctx->sa_in;
|
|
|
|
|
|
|
|
if (sa->sa_command_0.bf.hash_alg == SA_HASH_ALG_SHA1) {
|
2017-10-04 07:00:11 +08:00
|
|
|
memcpy(dst, pd_uinfo->sr_va->save_digest,
|
2009-02-05 13:18:13 +08:00
|
|
|
SA_HASH_ALG_SHA1_DIGEST_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_ret_sg_desc(struct crypto4xx_device *dev,
|
|
|
|
struct pd_uinfo *pd_uinfo)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (pd_uinfo->num_gd) {
|
|
|
|
for (i = 0; i < pd_uinfo->num_gd; i++)
|
|
|
|
crypto4xx_put_gd_to_gdr(dev);
|
|
|
|
pd_uinfo->first_gd = 0xffffffff;
|
|
|
|
pd_uinfo->num_gd = 0;
|
|
|
|
}
|
|
|
|
if (pd_uinfo->num_sd) {
|
|
|
|
for (i = 0; i < pd_uinfo->num_sd; i++)
|
|
|
|
crypto4xx_put_sd_to_sdr(dev);
|
|
|
|
|
|
|
|
pd_uinfo->first_sd = 0xffffffff;
|
|
|
|
pd_uinfo->num_sd = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 00:41:52 +08:00
|
|
|
static void crypto4xx_cipher_done(struct crypto4xx_device *dev,
|
2009-02-05 13:18:13 +08:00
|
|
|
struct pd_uinfo *pd_uinfo,
|
|
|
|
struct ce_pd *pd)
|
|
|
|
{
|
2018-04-20 00:41:52 +08:00
|
|
|
struct skcipher_request *req;
|
2009-02-05 13:18:13 +08:00
|
|
|
struct scatterlist *dst;
|
|
|
|
dma_addr_t addr;
|
|
|
|
|
2018-04-20 00:41:52 +08:00
|
|
|
req = skcipher_request_cast(pd_uinfo->async_req);
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2019-04-22 19:26:01 +08:00
|
|
|
if (pd_uinfo->sa_va->sa_command_0.bf.scatter) {
|
2018-04-20 00:41:52 +08:00
|
|
|
crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo,
|
|
|
|
req->cryptlen, req->dst);
|
2009-02-05 13:18:13 +08:00
|
|
|
} else {
|
|
|
|
dst = pd_uinfo->dest_va;
|
|
|
|
addr = dma_map_page(dev->core_dev->device, sg_page(dst),
|
|
|
|
dst->offset, dst->length, DMA_FROM_DEVICE);
|
|
|
|
}
|
2018-04-20 00:41:55 +08:00
|
|
|
|
|
|
|
if (pd_uinfo->sa_va->sa_command_0.bf.save_iv == SA_SAVE_IV) {
|
|
|
|
struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
|
|
|
|
|
|
|
|
crypto4xx_memcpy_from_le32((u32 *)req->iv,
|
|
|
|
pd_uinfo->sr_va->save_iv,
|
|
|
|
crypto_skcipher_ivsize(skcipher));
|
|
|
|
}
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
crypto4xx_ret_sg_desc(dev, pd_uinfo);
|
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 07:00:09 +08:00
|
|
|
|
|
|
|
if (pd_uinfo->state & PD_ENTRY_BUSY)
|
2018-04-20 00:41:52 +08:00
|
|
|
skcipher_request_complete(req, -EINPROGRESS);
|
|
|
|
skcipher_request_complete(req, 0);
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
static void crypto4xx_ahash_done(struct crypto4xx_device *dev,
|
2009-02-05 13:18:13 +08:00
|
|
|
struct pd_uinfo *pd_uinfo)
|
|
|
|
{
|
|
|
|
struct crypto4xx_ctx *ctx;
|
|
|
|
struct ahash_request *ahash_req;
|
|
|
|
|
|
|
|
ahash_req = ahash_request_cast(pd_uinfo->async_req);
|
|
|
|
ctx = crypto_tfm_ctx(ahash_req->base.tfm);
|
|
|
|
|
2017-10-04 07:00:11 +08:00
|
|
|
crypto4xx_copy_digest_to_dst(ahash_req->result, pd_uinfo,
|
2009-02-05 13:18:13 +08:00
|
|
|
crypto_tfm_ctx(ahash_req->base.tfm));
|
|
|
|
crypto4xx_ret_sg_desc(dev, pd_uinfo);
|
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 07:00:09 +08:00
|
|
|
|
|
|
|
if (pd_uinfo->state & PD_ENTRY_BUSY)
|
|
|
|
ahash_request_complete(ahash_req, -EINPROGRESS);
|
|
|
|
ahash_request_complete(ahash_req, 0);
|
2017-10-04 07:00:15 +08:00
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
static void crypto4xx_aead_done(struct crypto4xx_device *dev,
|
|
|
|
struct pd_uinfo *pd_uinfo,
|
|
|
|
struct ce_pd *pd)
|
|
|
|
{
|
2017-12-24 02:45:46 +08:00
|
|
|
struct aead_request *aead_req = container_of(pd_uinfo->async_req,
|
|
|
|
struct aead_request, base);
|
2017-10-04 07:00:15 +08:00
|
|
|
struct scatterlist *dst = pd_uinfo->dest_va;
|
2017-12-24 02:45:46 +08:00
|
|
|
size_t cp_len = crypto_aead_authsize(
|
|
|
|
crypto_aead_reqtfm(aead_req));
|
2018-04-20 00:41:51 +08:00
|
|
|
u32 icv[AES_BLOCK_SIZE];
|
2017-10-04 07:00:15 +08:00
|
|
|
int err = 0;
|
|
|
|
|
2019-04-22 19:26:01 +08:00
|
|
|
if (pd_uinfo->sa_va->sa_command_0.bf.scatter) {
|
2017-10-04 07:00:15 +08:00
|
|
|
crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo,
|
|
|
|
pd->pd_ctl_len.bf.pkt_len,
|
|
|
|
dst);
|
|
|
|
} else {
|
2018-12-17 01:19:46 +08:00
|
|
|
dma_unmap_page(dev->core_dev->device, pd->dest, dst->length,
|
2017-10-04 07:00:15 +08:00
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pd_uinfo->sa_va->sa_command_0.bf.dir == DIR_OUTBOUND) {
|
|
|
|
/* append icv at the end */
|
|
|
|
crypto4xx_memcpy_from_le32(icv, pd_uinfo->sr_va->save_digest,
|
2018-04-20 00:41:51 +08:00
|
|
|
sizeof(icv));
|
2017-10-04 07:00:15 +08:00
|
|
|
|
|
|
|
scatterwalk_map_and_copy(icv, dst, aead_req->cryptlen,
|
|
|
|
cp_len, 1);
|
2017-12-24 02:45:46 +08:00
|
|
|
} else {
|
|
|
|
/* check icv at the end */
|
|
|
|
scatterwalk_map_and_copy(icv, aead_req->src,
|
|
|
|
aead_req->assoclen + aead_req->cryptlen -
|
|
|
|
cp_len, cp_len, 0);
|
|
|
|
|
2018-04-20 00:41:51 +08:00
|
|
|
crypto4xx_memcpy_from_le32(icv, icv, sizeof(icv));
|
2017-12-24 02:45:46 +08:00
|
|
|
|
|
|
|
if (crypto_memneq(icv, pd_uinfo->sr_va->save_digest, cp_len))
|
|
|
|
err = -EBADMSG;
|
2017-10-04 07:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
crypto4xx_ret_sg_desc(dev, pd_uinfo);
|
|
|
|
|
|
|
|
if (pd->pd_ctl.bf.status & 0xff) {
|
2017-12-24 02:45:46 +08:00
|
|
|
if (!__ratelimit(&dev->aead_ratelimit)) {
|
|
|
|
if (pd->pd_ctl.bf.status & 2)
|
|
|
|
pr_err("pad fail error\n");
|
|
|
|
if (pd->pd_ctl.bf.status & 4)
|
|
|
|
pr_err("seqnum fail\n");
|
|
|
|
if (pd->pd_ctl.bf.status & 8)
|
|
|
|
pr_err("error _notify\n");
|
|
|
|
pr_err("aead return err status = 0x%02x\n",
|
|
|
|
pd->pd_ctl.bf.status & 0xff);
|
|
|
|
pr_err("pd pad_ctl = 0x%08x\n",
|
|
|
|
pd->pd_ctl.bf.pd_pad_ctl);
|
2017-10-04 07:00:15 +08:00
|
|
|
}
|
2017-12-24 02:45:46 +08:00
|
|
|
err = -EINVAL;
|
2017-10-04 07:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pd_uinfo->state & PD_ENTRY_BUSY)
|
|
|
|
aead_request_complete(aead_req, -EINPROGRESS);
|
|
|
|
|
|
|
|
aead_request_complete(aead_req, err);
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
static void crypto4xx_pd_done(struct crypto4xx_device *dev, u32 idx)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
2017-08-25 21:47:25 +08:00
|
|
|
struct ce_pd *pd = &dev->pdr[idx];
|
|
|
|
struct pd_uinfo *pd_uinfo = &dev->pdr_uinfo[idx];
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
switch (crypto_tfm_alg_type(pd_uinfo->async_req->tfm)) {
|
2018-04-20 00:41:52 +08:00
|
|
|
case CRYPTO_ALG_TYPE_SKCIPHER:
|
|
|
|
crypto4xx_cipher_done(dev, pd_uinfo, pd);
|
2017-10-04 07:00:15 +08:00
|
|
|
break;
|
|
|
|
case CRYPTO_ALG_TYPE_AEAD:
|
|
|
|
crypto4xx_aead_done(dev, pd_uinfo, pd);
|
|
|
|
break;
|
|
|
|
case CRYPTO_ALG_TYPE_AHASH:
|
|
|
|
crypto4xx_ahash_done(dev, pd_uinfo);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_stop_all(struct crypto4xx_core_device *core_dev)
|
|
|
|
{
|
|
|
|
crypto4xx_destroy_pdr(core_dev->dev);
|
|
|
|
crypto4xx_destroy_gdr(core_dev->dev);
|
|
|
|
crypto4xx_destroy_sdr(core_dev->dev);
|
|
|
|
iounmap(core_dev->dev->ce_base);
|
|
|
|
kfree(core_dev->dev);
|
|
|
|
kfree(core_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 get_next_gd(u32 current)
|
|
|
|
{
|
|
|
|
if (current != PPC4XX_LAST_GD)
|
|
|
|
return current + 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 get_next_sd(u32 current)
|
|
|
|
{
|
|
|
|
if (current != PPC4XX_LAST_SD)
|
|
|
|
return current + 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-04 07:00:11 +08:00
|
|
|
int crypto4xx_build_pd(struct crypto_async_request *req,
|
2009-02-05 13:18:13 +08:00
|
|
|
struct crypto4xx_ctx *ctx,
|
|
|
|
struct scatterlist *src,
|
|
|
|
struct scatterlist *dst,
|
2017-10-04 07:00:11 +08:00
|
|
|
const unsigned int datalen,
|
|
|
|
const __le32 *iv, const u32 iv_len,
|
|
|
|
const struct dynamic_sa_ctl *req_sa,
|
2017-10-04 07:00:15 +08:00
|
|
|
const unsigned int sa_len,
|
2018-04-20 00:41:57 +08:00
|
|
|
const unsigned int assoclen,
|
|
|
|
struct scatterlist *_dst)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
struct crypto4xx_device *dev = ctx->dev;
|
|
|
|
struct dynamic_sa_ctl *sa;
|
|
|
|
struct ce_gd *gd;
|
|
|
|
struct ce_pd *pd;
|
|
|
|
u32 num_gd, num_sd;
|
|
|
|
u32 fst_gd = 0xffffffff;
|
|
|
|
u32 fst_sd = 0xffffffff;
|
|
|
|
u32 pd_entry;
|
|
|
|
unsigned long flags;
|
2017-10-04 07:00:11 +08:00
|
|
|
struct pd_uinfo *pd_uinfo;
|
|
|
|
unsigned int nbytes = datalen;
|
|
|
|
size_t offset_to_sr_ptr;
|
2009-02-05 13:18:13 +08:00
|
|
|
u32 gd_idx = 0;
|
2017-10-04 07:00:15 +08:00
|
|
|
int tmp;
|
2019-04-22 19:25:59 +08:00
|
|
|
bool is_busy, force_sd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There's a very subtile/disguised "bug" in the hardware that
|
|
|
|
* gets indirectly mentioned in 18.1.3.5 Encryption/Decryption
|
|
|
|
* of the hardware spec:
|
|
|
|
* *drum roll* the AES/(T)DES OFB and CFB modes are listed as
|
|
|
|
* operation modes for >>> "Block ciphers" <<<.
|
|
|
|
*
|
|
|
|
* To workaround this issue and stop the hardware from causing
|
|
|
|
* "overran dst buffer" on crypttexts that are not a multiple
|
|
|
|
* of 16 (AES_BLOCK_SIZE), we force the driver to use the
|
|
|
|
* scatter buffers.
|
|
|
|
*/
|
|
|
|
force_sd = (req_sa->sa_command_1.bf.crypto_mode9_8 == CRYPTO_MODE_CFB
|
|
|
|
|| req_sa->sa_command_1.bf.crypto_mode9_8 == CRYPTO_MODE_OFB)
|
|
|
|
&& (datalen % AES_BLOCK_SIZE);
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
/* figure how many gd are needed */
|
|
|
|
tmp = sg_nents_for_len(src, assoclen + datalen);
|
|
|
|
if (tmp < 0) {
|
2015-11-05 04:13:39 +08:00
|
|
|
dev_err(dev->core_dev->device, "Invalid number of src SG.\n");
|
2017-10-04 07:00:15 +08:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
if (tmp == 1)
|
|
|
|
tmp = 0;
|
|
|
|
num_gd = tmp;
|
|
|
|
|
|
|
|
if (assoclen) {
|
|
|
|
nbytes += assoclen;
|
|
|
|
dst = scatterwalk_ffwd(_dst, dst, assoclen);
|
2015-11-05 04:13:39 +08:00
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
/* figure how many sd are needed */
|
2019-04-22 19:25:59 +08:00
|
|
|
if (sg_is_last(dst) && force_sd == false) {
|
2009-02-05 13:18:13 +08:00
|
|
|
num_sd = 0;
|
|
|
|
} else {
|
|
|
|
if (datalen > PPC4XX_SD_BUFFER_SIZE) {
|
|
|
|
num_sd = datalen / PPC4XX_SD_BUFFER_SIZE;
|
|
|
|
if (datalen % PPC4XX_SD_BUFFER_SIZE)
|
|
|
|
num_sd++;
|
|
|
|
} else {
|
|
|
|
num_sd = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The follow section of code needs to be protected
|
|
|
|
* The gather ring and scatter ring needs to be consecutive
|
|
|
|
* In case of run out of any kind of descriptor, the descriptor
|
|
|
|
* already got must be return the original place.
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&dev->core_dev->lock, flags);
|
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 07:00:09 +08:00
|
|
|
/*
|
|
|
|
* Let the caller know to slow down, once more than 13/16ths = 81%
|
|
|
|
* of the available data contexts are being used simultaneously.
|
|
|
|
*
|
|
|
|
* With PPC4XX_NUM_PD = 256, this will leave a "backlog queue" for
|
|
|
|
* 31 more contexts. Before new requests have to be rejected.
|
|
|
|
*/
|
|
|
|
if (req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG) {
|
|
|
|
is_busy = ((dev->pdr_head - dev->pdr_tail) % PPC4XX_NUM_PD) >=
|
|
|
|
((PPC4XX_NUM_PD * 13) / 16);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* To fix contention issues between ipsec (no blacklog) and
|
|
|
|
* dm-crypto (backlog) reserve 32 entries for "no backlog"
|
|
|
|
* data contexts.
|
|
|
|
*/
|
|
|
|
is_busy = ((dev->pdr_head - dev->pdr_tail) % PPC4XX_NUM_PD) >=
|
|
|
|
((PPC4XX_NUM_PD * 15) / 16);
|
|
|
|
|
|
|
|
if (is_busy) {
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
if (num_gd) {
|
|
|
|
fst_gd = crypto4xx_get_n_gd(dev, num_gd);
|
|
|
|
if (fst_gd == ERING_WAS_FULL) {
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num_sd) {
|
|
|
|
fst_sd = crypto4xx_get_n_sd(dev, num_sd);
|
|
|
|
if (fst_sd == ERING_WAS_FULL) {
|
|
|
|
if (num_gd)
|
|
|
|
dev->gdr_head = fst_gd;
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pd_entry = crypto4xx_get_pd_from_pdr_nolock(dev);
|
|
|
|
if (pd_entry == ERING_WAS_FULL) {
|
|
|
|
if (num_gd)
|
|
|
|
dev->gdr_head = fst_gd;
|
|
|
|
if (num_sd)
|
|
|
|
dev->sdr_head = fst_sd;
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&dev->core_dev->lock, flags);
|
|
|
|
|
2017-10-04 07:00:11 +08:00
|
|
|
pd = &dev->pdr[pd_entry];
|
|
|
|
pd->sa_len = sa_len;
|
|
|
|
|
2017-08-25 21:47:25 +08:00
|
|
|
pd_uinfo = &dev->pdr_uinfo[pd_entry];
|
2009-02-05 13:18:13 +08:00
|
|
|
pd_uinfo->num_gd = num_gd;
|
|
|
|
pd_uinfo->num_sd = num_sd;
|
2019-04-22 19:25:59 +08:00
|
|
|
pd_uinfo->dest_va = dst;
|
|
|
|
pd_uinfo->async_req = req;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2017-10-04 07:00:11 +08:00
|
|
|
if (iv_len)
|
|
|
|
memcpy(pd_uinfo->sr_va->save_iv, iv, iv_len);
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2017-10-04 07:00:11 +08:00
|
|
|
sa = pd_uinfo->sa_va;
|
|
|
|
memcpy(sa, req_sa, sa_len * 4);
|
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
sa->sa_command_1.bf.hash_crypto_offset = (assoclen >> 2);
|
2017-10-04 07:00:11 +08:00
|
|
|
offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(sa);
|
|
|
|
*(u32 *)((unsigned long)sa + offset_to_sr_ptr) = pd_uinfo->sr_pa;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
if (num_gd) {
|
2017-10-04 07:00:11 +08:00
|
|
|
dma_addr_t gd_dma;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
/* get first gd we are going to use */
|
|
|
|
gd_idx = fst_gd;
|
|
|
|
pd_uinfo->first_gd = fst_gd;
|
|
|
|
gd = crypto4xx_get_gdp(dev, &gd_dma, gd_idx);
|
|
|
|
pd->src = gd_dma;
|
|
|
|
/* enable gather */
|
|
|
|
sa->sa_command_0.bf.gather = 1;
|
|
|
|
/* walk the sg, and setup gather array */
|
2017-10-04 07:00:11 +08:00
|
|
|
|
|
|
|
sg = src;
|
2009-02-05 13:18:13 +08:00
|
|
|
while (nbytes) {
|
2017-10-04 07:00:11 +08:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = min(sg->length, nbytes);
|
|
|
|
gd->ptr = dma_map_page(dev->core_dev->device,
|
|
|
|
sg_page(sg), sg->offset, len, DMA_TO_DEVICE);
|
|
|
|
gd->ctl_len.len = len;
|
2009-02-05 13:18:13 +08:00
|
|
|
gd->ctl_len.done = 0;
|
|
|
|
gd->ctl_len.ready = 1;
|
2017-10-04 07:00:11 +08:00
|
|
|
if (len >= nbytes)
|
2009-02-05 13:18:13 +08:00
|
|
|
break;
|
2017-10-04 07:00:11 +08:00
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
nbytes -= sg->length;
|
|
|
|
gd_idx = get_next_gd(gd_idx);
|
|
|
|
gd = crypto4xx_get_gdp(dev, &gd_dma, gd_idx);
|
2017-10-04 07:00:11 +08:00
|
|
|
sg = sg_next(sg);
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pd->src = (u32)dma_map_page(dev->core_dev->device, sg_page(src),
|
2017-10-04 07:00:11 +08:00
|
|
|
src->offset, min(nbytes, src->length),
|
|
|
|
DMA_TO_DEVICE);
|
2009-02-05 13:18:13 +08:00
|
|
|
/*
|
|
|
|
* Disable gather in sa command
|
|
|
|
*/
|
|
|
|
sa->sa_command_0.bf.gather = 0;
|
|
|
|
/*
|
|
|
|
* Indicate gather array is not used
|
|
|
|
*/
|
|
|
|
pd_uinfo->first_gd = 0xffffffff;
|
|
|
|
}
|
2019-04-22 19:25:59 +08:00
|
|
|
if (!num_sd) {
|
2009-02-05 13:18:13 +08:00
|
|
|
/*
|
|
|
|
* we know application give us dst a whole piece of memory
|
|
|
|
* no need to use scatter ring.
|
|
|
|
*/
|
|
|
|
pd_uinfo->first_sd = 0xffffffff;
|
|
|
|
sa->sa_command_0.bf.scatter = 0;
|
2017-10-04 07:00:11 +08:00
|
|
|
pd->dest = (u32)dma_map_page(dev->core_dev->device,
|
|
|
|
sg_page(dst), dst->offset,
|
|
|
|
min(datalen, dst->length),
|
|
|
|
DMA_TO_DEVICE);
|
2009-02-05 13:18:13 +08:00
|
|
|
} else {
|
2017-10-04 07:00:11 +08:00
|
|
|
dma_addr_t sd_dma;
|
2009-02-05 13:18:13 +08:00
|
|
|
struct ce_sd *sd = NULL;
|
2017-10-04 07:00:11 +08:00
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
u32 sd_idx = fst_sd;
|
|
|
|
nbytes = datalen;
|
|
|
|
sa->sa_command_0.bf.scatter = 1;
|
|
|
|
pd_uinfo->first_sd = fst_sd;
|
|
|
|
sd = crypto4xx_get_sdp(dev, &sd_dma, sd_idx);
|
|
|
|
pd->dest = sd_dma;
|
|
|
|
/* setup scatter descriptor */
|
|
|
|
sd->ctl.done = 0;
|
|
|
|
sd->ctl.rdy = 1;
|
|
|
|
/* sd->ptr should be setup by sd_init routine*/
|
|
|
|
if (nbytes >= PPC4XX_SD_BUFFER_SIZE)
|
|
|
|
nbytes -= PPC4XX_SD_BUFFER_SIZE;
|
|
|
|
else
|
|
|
|
nbytes = 0;
|
|
|
|
while (nbytes) {
|
|
|
|
sd_idx = get_next_sd(sd_idx);
|
|
|
|
sd = crypto4xx_get_sdp(dev, &sd_dma, sd_idx);
|
|
|
|
/* setup scatter descriptor */
|
|
|
|
sd->ctl.done = 0;
|
|
|
|
sd->ctl.rdy = 1;
|
2017-10-04 07:00:11 +08:00
|
|
|
if (nbytes >= PPC4XX_SD_BUFFER_SIZE) {
|
2009-02-05 13:18:13 +08:00
|
|
|
nbytes -= PPC4XX_SD_BUFFER_SIZE;
|
2017-10-04 07:00:11 +08:00
|
|
|
} else {
|
2009-02-05 13:18:13 +08:00
|
|
|
/*
|
|
|
|
* SD entry can hold PPC4XX_SD_BUFFER_SIZE,
|
|
|
|
* which is more than nbytes, so done.
|
|
|
|
*/
|
|
|
|
nbytes = 0;
|
2017-10-04 07:00:11 +08:00
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 07:00:13 +08:00
|
|
|
pd->pd_ctl.w = PD_CTL_HOST_READY |
|
2020-11-13 04:07:02 +08:00
|
|
|
((crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AHASH) ||
|
2017-10-04 07:00:13 +08:00
|
|
|
(crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AEAD) ?
|
|
|
|
PD_CTL_HASH_FINAL : 0);
|
2017-10-04 07:00:15 +08:00
|
|
|
pd->pd_ctl_len.w = 0x00400000 | (assoclen + datalen);
|
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 07:00:09 +08:00
|
|
|
pd_uinfo->state = PD_ENTRY_INUSE | (is_busy ? PD_ENTRY_BUSY : 0);
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
wmb();
|
|
|
|
/* write any value to push engine to read a pd */
|
2017-10-04 07:00:13 +08:00
|
|
|
writel(0, dev->ce_base + CRYPTO4XX_INT_DESCR_RD);
|
2009-02-05 13:18:13 +08:00
|
|
|
writel(1, dev->ce_base + CRYPTO4XX_INT_DESCR_RD);
|
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 07:00:09 +08:00
|
|
|
return is_busy ? -EBUSY : -EINPROGRESS;
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Algorithm Registration Functions
|
|
|
|
*/
|
2017-10-04 07:00:15 +08:00
|
|
|
static void crypto4xx_ctx_init(struct crypto4xx_alg *amcc_alg,
|
|
|
|
struct crypto4xx_ctx *ctx)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
ctx->dev = amcc_alg->dev;
|
|
|
|
ctx->sa_in = NULL;
|
|
|
|
ctx->sa_out = NULL;
|
|
|
|
ctx->sa_len = 0;
|
2017-10-04 07:00:15 +08:00
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2018-04-20 00:41:52 +08:00
|
|
|
static int crypto4xx_sk_init(struct crypto_skcipher *sk)
|
2017-10-04 07:00:15 +08:00
|
|
|
{
|
2018-04-20 00:41:52 +08:00
|
|
|
struct skcipher_alg *alg = crypto_skcipher_alg(sk);
|
2017-10-04 07:00:15 +08:00
|
|
|
struct crypto4xx_alg *amcc_alg;
|
2018-04-20 00:41:52 +08:00
|
|
|
struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(sk);
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2018-04-20 00:41:54 +08:00
|
|
|
if (alg->base.cra_flags & CRYPTO_ALG_NEED_FALLBACK) {
|
|
|
|
ctx->sw_cipher.cipher =
|
2019-04-22 19:26:00 +08:00
|
|
|
crypto_alloc_sync_skcipher(alg->base.cra_name, 0,
|
|
|
|
CRYPTO_ALG_NEED_FALLBACK);
|
2018-04-20 00:41:54 +08:00
|
|
|
if (IS_ERR(ctx->sw_cipher.cipher))
|
|
|
|
return PTR_ERR(ctx->sw_cipher.cipher);
|
|
|
|
}
|
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.cipher);
|
|
|
|
crypto4xx_ctx_init(amcc_alg, ctx);
|
2009-02-05 13:18:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
static void crypto4xx_common_exit(struct crypto4xx_ctx *ctx)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
crypto4xx_free_sa(ctx);
|
|
|
|
}
|
|
|
|
|
2018-04-20 00:41:52 +08:00
|
|
|
static void crypto4xx_sk_exit(struct crypto_skcipher *sk)
|
2017-10-04 07:00:15 +08:00
|
|
|
{
|
2018-04-20 00:41:52 +08:00
|
|
|
struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(sk);
|
|
|
|
|
|
|
|
crypto4xx_common_exit(ctx);
|
2018-04-20 00:41:54 +08:00
|
|
|
if (ctx->sw_cipher.cipher)
|
2019-04-22 19:26:00 +08:00
|
|
|
crypto_free_sync_skcipher(ctx->sw_cipher.cipher);
|
2017-10-04 07:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int crypto4xx_aead_init(struct crypto_aead *tfm)
|
|
|
|
{
|
|
|
|
struct aead_alg *alg = crypto_aead_alg(tfm);
|
|
|
|
struct crypto4xx_ctx *ctx = crypto_aead_ctx(tfm);
|
|
|
|
struct crypto4xx_alg *amcc_alg;
|
|
|
|
|
|
|
|
ctx->sw_cipher.aead = crypto_alloc_aead(alg->base.cra_name, 0,
|
|
|
|
CRYPTO_ALG_NEED_FALLBACK |
|
|
|
|
CRYPTO_ALG_ASYNC);
|
|
|
|
if (IS_ERR(ctx->sw_cipher.aead))
|
|
|
|
return PTR_ERR(ctx->sw_cipher.aead);
|
|
|
|
|
|
|
|
amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.aead);
|
|
|
|
crypto4xx_ctx_init(amcc_alg, ctx);
|
2018-04-20 00:41:57 +08:00
|
|
|
crypto_aead_set_reqsize(tfm, max(sizeof(struct aead_request) + 32 +
|
|
|
|
crypto_aead_reqsize(ctx->sw_cipher.aead),
|
|
|
|
sizeof(struct crypto4xx_aead_reqctx)));
|
2017-10-04 07:00:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_aead_exit(struct crypto_aead *tfm)
|
|
|
|
{
|
|
|
|
struct crypto4xx_ctx *ctx = crypto_aead_ctx(tfm);
|
|
|
|
|
|
|
|
crypto4xx_common_exit(ctx);
|
|
|
|
crypto_free_aead(ctx->sw_cipher.aead);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int crypto4xx_register_alg(struct crypto4xx_device *sec_dev,
|
|
|
|
struct crypto4xx_alg_common *crypto_alg,
|
|
|
|
int array_size)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
struct crypto4xx_alg *alg;
|
|
|
|
int i;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < array_size; i++) {
|
|
|
|
alg = kzalloc(sizeof(struct crypto4xx_alg), GFP_KERNEL);
|
|
|
|
if (!alg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
alg->alg = crypto_alg[i];
|
|
|
|
alg->dev = sec_dev;
|
2009-07-14 20:21:46 +08:00
|
|
|
|
|
|
|
switch (alg->alg.type) {
|
2017-10-04 07:00:15 +08:00
|
|
|
case CRYPTO_ALG_TYPE_AEAD:
|
|
|
|
rc = crypto_register_aead(&alg->alg.u.aead);
|
|
|
|
break;
|
|
|
|
|
2009-07-14 20:21:46 +08:00
|
|
|
case CRYPTO_ALG_TYPE_AHASH:
|
|
|
|
rc = crypto_register_ahash(&alg->alg.u.hash);
|
|
|
|
break;
|
|
|
|
|
2018-12-23 09:16:13 +08:00
|
|
|
case CRYPTO_ALG_TYPE_RNG:
|
|
|
|
rc = crypto_register_rng(&alg->alg.u.rng);
|
|
|
|
break;
|
|
|
|
|
2009-07-14 20:21:46 +08:00
|
|
|
default:
|
2018-04-20 00:41:52 +08:00
|
|
|
rc = crypto_register_skcipher(&alg->alg.u.cipher);
|
2009-07-14 20:21:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-25 21:47:14 +08:00
|
|
|
if (rc)
|
2009-02-05 13:18:13 +08:00
|
|
|
kfree(alg);
|
2017-08-25 21:47:14 +08:00
|
|
|
else
|
2009-02-05 13:18:13 +08:00
|
|
|
list_add_tail(&alg->entry, &sec_dev->alg_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_unregister_alg(struct crypto4xx_device *sec_dev)
|
|
|
|
{
|
|
|
|
struct crypto4xx_alg *alg, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(alg, tmp, &sec_dev->alg_list, entry) {
|
|
|
|
list_del(&alg->entry);
|
2009-07-14 20:21:46 +08:00
|
|
|
switch (alg->alg.type) {
|
|
|
|
case CRYPTO_ALG_TYPE_AHASH:
|
|
|
|
crypto_unregister_ahash(&alg->alg.u.hash);
|
|
|
|
break;
|
|
|
|
|
2017-10-04 07:00:15 +08:00
|
|
|
case CRYPTO_ALG_TYPE_AEAD:
|
|
|
|
crypto_unregister_aead(&alg->alg.u.aead);
|
|
|
|
break;
|
|
|
|
|
2018-12-23 09:16:13 +08:00
|
|
|
case CRYPTO_ALG_TYPE_RNG:
|
|
|
|
crypto_unregister_rng(&alg->alg.u.rng);
|
|
|
|
break;
|
|
|
|
|
2009-07-14 20:21:46 +08:00
|
|
|
default:
|
2018-04-20 00:41:52 +08:00
|
|
|
crypto_unregister_skcipher(&alg->alg.u.cipher);
|
2009-07-14 20:21:46 +08:00
|
|
|
}
|
2009-02-05 13:18:13 +08:00
|
|
|
kfree(alg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void crypto4xx_bh_tasklet_cb(unsigned long data)
|
|
|
|
{
|
|
|
|
struct device *dev = (struct device *)data;
|
|
|
|
struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
|
|
|
|
struct pd_uinfo *pd_uinfo;
|
|
|
|
struct ce_pd *pd;
|
2017-10-04 07:00:13 +08:00
|
|
|
u32 tail = core_dev->dev->pdr_tail;
|
|
|
|
u32 head = core_dev->dev->pdr_head;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2017-10-04 07:00:13 +08:00
|
|
|
do {
|
2017-08-25 21:47:25 +08:00
|
|
|
pd_uinfo = &core_dev->dev->pdr_uinfo[tail];
|
|
|
|
pd = &core_dev->dev->pdr[tail];
|
crypto: crypto4xx - add backlog queue support
Previously, If the crypto4xx driver used all available
security contexts, it would simply refuse new requests
with -EAGAIN. CRYPTO_TFM_REQ_MAY_BACKLOG was ignored.
in case of dm-crypt.c's crypt_convert() function this was
causing the following errors to manifest, if the system was
pushed hard enough:
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| EXT4-fs warning (dm-1): ext4_end_bio:314: I/O error -5 writing to ino ..
| JBD2: Detected IO errors while flushing file data on dm-1-8
| Aborting journal on device dm-1-8.
| EXT4-fs error : ext4_journal_check_start:56: Detected aborted journal
| EXT4-fs (dm-1): Remounting filesystem read-only
| EXT4-fs : ext4_writepages: jbd2_start: 2048 pages, inode 498...; err -30
(This did cause corruptions due to failed writes)
To fix this mess, the crypto4xx driver needs to notifiy the
user to slow down. This can be achieved by returning -EBUSY
on requests, once the crypto hardware was falling behind.
Note: -EBUSY has two different meanings. Setting the flag
CRYPTO_TFM_REQ_MAY_BACKLOG implies that the request was
successfully queued, by the crypto driver. To achieve this
requirement, the implementation introduces a threshold check and
adds logic to the completion routines in much the same way as
AMD's Cryptographic Coprocessor (CCP) driver do.
Note2: Tests showed that dm-crypt starved ipsec traffic.
Under load, ipsec links dropped to 0 Kbits/s. This is because
dm-crypt's callback would instantly queue the next request.
In order to not starve ipsec, the driver reserves a small
portion of the available crypto contexts for this purpose.
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-10-04 07:00:09 +08:00
|
|
|
if ((pd_uinfo->state & PD_ENTRY_INUSE) &&
|
2017-10-04 07:00:13 +08:00
|
|
|
((READ_ONCE(pd->pd_ctl.w) &
|
|
|
|
(PD_CTL_PE_DONE | PD_CTL_HOST_READY)) ==
|
|
|
|
PD_CTL_PE_DONE)) {
|
2009-02-05 13:18:13 +08:00
|
|
|
crypto4xx_pd_done(core_dev->dev, tail);
|
2017-10-04 07:00:13 +08:00
|
|
|
tail = crypto4xx_put_pd_to_pdr(core_dev->dev, tail);
|
2009-02-05 13:18:13 +08:00
|
|
|
} else {
|
|
|
|
/* if tail not done, break */
|
|
|
|
break;
|
|
|
|
}
|
2017-10-04 07:00:13 +08:00
|
|
|
} while (head != tail);
|
2009-02-05 13:18:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Top Half of isr.
|
|
|
|
*/
|
2017-12-23 04:18:36 +08:00
|
|
|
static inline irqreturn_t crypto4xx_interrupt_handler(int irq, void *data,
|
|
|
|
u32 clr_val)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
struct device *dev = (struct device *)data;
|
|
|
|
struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
|
|
|
|
|
2017-12-23 04:18:36 +08:00
|
|
|
writel(clr_val, core_dev->dev->ce_base + CRYPTO4XX_INT_CLR);
|
2009-02-05 13:18:13 +08:00
|
|
|
tasklet_schedule(&core_dev->tasklet);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2017-12-23 04:18:36 +08:00
|
|
|
static irqreturn_t crypto4xx_ce_interrupt_handler(int irq, void *data)
|
|
|
|
{
|
|
|
|
return crypto4xx_interrupt_handler(irq, data, PPC4XX_INTERRUPT_CLR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t crypto4xx_ce_interrupt_handler_revb(int irq, void *data)
|
|
|
|
{
|
|
|
|
return crypto4xx_interrupt_handler(irq, data, PPC4XX_INTERRUPT_CLR |
|
|
|
|
PPC4XX_TMO_ERR_INT);
|
|
|
|
}
|
|
|
|
|
2018-12-23 09:16:13 +08:00
|
|
|
static int ppc4xx_prng_data_read(struct crypto4xx_device *dev,
|
|
|
|
u8 *data, unsigned int max)
|
|
|
|
{
|
|
|
|
unsigned int i, curr = 0;
|
|
|
|
u32 val[2];
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* trigger PRN generation */
|
|
|
|
writel(PPC4XX_PRNG_CTRL_AUTO_EN,
|
|
|
|
dev->ce_base + CRYPTO4XX_PRNG_CTRL);
|
|
|
|
|
|
|
|
for (i = 0; i < 1024; i++) {
|
|
|
|
/* usually 19 iterations are enough */
|
|
|
|
if ((readl(dev->ce_base + CRYPTO4XX_PRNG_STAT) &
|
|
|
|
CRYPTO4XX_PRNG_STAT_BUSY))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
val[0] = readl_be(dev->ce_base + CRYPTO4XX_PRNG_RES_0);
|
|
|
|
val[1] = readl_be(dev->ce_base + CRYPTO4XX_PRNG_RES_1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == 1024)
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
|
|
|
if ((max - curr) >= 8) {
|
|
|
|
memcpy(data, &val, 8);
|
|
|
|
data += 8;
|
|
|
|
curr += 8;
|
|
|
|
} else {
|
|
|
|
/* copy only remaining bytes */
|
|
|
|
memcpy(data, &val, max - curr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (curr < max);
|
|
|
|
|
|
|
|
return curr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int crypto4xx_prng_generate(struct crypto_rng *tfm,
|
|
|
|
const u8 *src, unsigned int slen,
|
|
|
|
u8 *dstn, unsigned int dlen)
|
|
|
|
{
|
|
|
|
struct rng_alg *alg = crypto_rng_alg(tfm);
|
|
|
|
struct crypto4xx_alg *amcc_alg;
|
|
|
|
struct crypto4xx_device *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.rng);
|
|
|
|
dev = amcc_alg->dev;
|
|
|
|
|
|
|
|
mutex_lock(&dev->core_dev->rng_lock);
|
|
|
|
ret = ppc4xx_prng_data_read(dev, dstn, dlen);
|
|
|
|
mutex_unlock(&dev->core_dev->rng_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int crypto4xx_prng_seed(struct crypto_rng *tfm, const u8 *seed,
|
|
|
|
unsigned int slen)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
/**
|
|
|
|
* Supported Crypto Algorithms
|
|
|
|
*/
|
2017-10-04 07:00:15 +08:00
|
|
|
static struct crypto4xx_alg_common crypto4xx_alg[] = {
|
2009-02-05 13:18:13 +08:00
|
|
|
/* Crypto AES modes */
|
2018-04-20 00:41:52 +08:00
|
|
|
{ .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
|
|
|
|
.base = {
|
|
|
|
.cra_name = "cbc(aes)",
|
|
|
|
.cra_driver_name = "cbc-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
2018-07-01 06:16:15 +08:00
|
|
|
.cra_flags = CRYPTO_ALG_ASYNC |
|
2018-04-20 00:41:52 +08:00
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
|
|
|
.cra_blocksize = AES_BLOCK_SIZE,
|
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.min_keysize = AES_MIN_KEY_SIZE,
|
|
|
|
.max_keysize = AES_MAX_KEY_SIZE,
|
|
|
|
.ivsize = AES_IV_SIZE,
|
|
|
|
.setkey = crypto4xx_setkey_aes_cbc,
|
2019-05-19 05:28:12 +08:00
|
|
|
.encrypt = crypto4xx_encrypt_iv_block,
|
|
|
|
.decrypt = crypto4xx_decrypt_iv_block,
|
2018-04-20 00:41:52 +08:00
|
|
|
.init = crypto4xx_sk_init,
|
|
|
|
.exit = crypto4xx_sk_exit,
|
2017-08-25 21:47:21 +08:00
|
|
|
} },
|
2018-04-20 00:41:52 +08:00
|
|
|
{ .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
|
|
|
|
.base = {
|
|
|
|
.cra_name = "cfb(aes)",
|
|
|
|
.cra_driver_name = "cfb-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
2018-07-01 06:16:15 +08:00
|
|
|
.cra_flags = CRYPTO_ALG_ASYNC |
|
2018-04-20 00:41:52 +08:00
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
2019-05-19 05:28:11 +08:00
|
|
|
.cra_blocksize = 1,
|
2018-04-20 00:41:52 +08:00
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.min_keysize = AES_MIN_KEY_SIZE,
|
|
|
|
.max_keysize = AES_MAX_KEY_SIZE,
|
|
|
|
.ivsize = AES_IV_SIZE,
|
|
|
|
.setkey = crypto4xx_setkey_aes_cfb,
|
2019-05-19 05:28:12 +08:00
|
|
|
.encrypt = crypto4xx_encrypt_iv_stream,
|
|
|
|
.decrypt = crypto4xx_decrypt_iv_stream,
|
2018-04-20 00:41:52 +08:00
|
|
|
.init = crypto4xx_sk_init,
|
|
|
|
.exit = crypto4xx_sk_exit,
|
2017-08-25 21:47:21 +08:00
|
|
|
} },
|
2018-04-20 00:41:54 +08:00
|
|
|
{ .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
|
|
|
|
.base = {
|
|
|
|
.cra_name = "ctr(aes)",
|
|
|
|
.cra_driver_name = "ctr-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
2018-07-01 06:16:15 +08:00
|
|
|
.cra_flags = CRYPTO_ALG_NEED_FALLBACK |
|
2018-04-20 00:41:54 +08:00
|
|
|
CRYPTO_ALG_ASYNC |
|
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
2019-05-18 05:15:57 +08:00
|
|
|
.cra_blocksize = 1,
|
2018-04-20 00:41:54 +08:00
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.min_keysize = AES_MIN_KEY_SIZE,
|
|
|
|
.max_keysize = AES_MAX_KEY_SIZE,
|
|
|
|
.ivsize = AES_IV_SIZE,
|
|
|
|
.setkey = crypto4xx_setkey_aes_ctr,
|
|
|
|
.encrypt = crypto4xx_encrypt_ctr,
|
|
|
|
.decrypt = crypto4xx_decrypt_ctr,
|
|
|
|
.init = crypto4xx_sk_init,
|
|
|
|
.exit = crypto4xx_sk_exit,
|
|
|
|
} },
|
2018-04-20 00:41:52 +08:00
|
|
|
{ .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
|
|
|
|
.base = {
|
|
|
|
.cra_name = "rfc3686(ctr(aes))",
|
|
|
|
.cra_driver_name = "rfc3686-ctr-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
2018-07-01 06:16:15 +08:00
|
|
|
.cra_flags = CRYPTO_ALG_ASYNC |
|
2018-04-20 00:41:52 +08:00
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
2019-05-18 05:15:57 +08:00
|
|
|
.cra_blocksize = 1,
|
2018-04-20 00:41:52 +08:00
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.min_keysize = AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
|
|
|
|
.max_keysize = AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
|
|
|
|
.ivsize = CTR_RFC3686_IV_SIZE,
|
|
|
|
.setkey = crypto4xx_setkey_rfc3686,
|
|
|
|
.encrypt = crypto4xx_rfc3686_encrypt,
|
|
|
|
.decrypt = crypto4xx_rfc3686_decrypt,
|
|
|
|
.init = crypto4xx_sk_init,
|
|
|
|
.exit = crypto4xx_sk_exit,
|
2017-08-25 21:47:21 +08:00
|
|
|
} },
|
2018-04-20 00:41:52 +08:00
|
|
|
{ .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
|
|
|
|
.base = {
|
|
|
|
.cra_name = "ecb(aes)",
|
|
|
|
.cra_driver_name = "ecb-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
2018-07-01 06:16:15 +08:00
|
|
|
.cra_flags = CRYPTO_ALG_ASYNC |
|
2018-04-20 00:41:52 +08:00
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
|
|
|
.cra_blocksize = AES_BLOCK_SIZE,
|
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.min_keysize = AES_MIN_KEY_SIZE,
|
|
|
|
.max_keysize = AES_MAX_KEY_SIZE,
|
|
|
|
.setkey = crypto4xx_setkey_aes_ecb,
|
2019-05-19 05:28:12 +08:00
|
|
|
.encrypt = crypto4xx_encrypt_noiv_block,
|
|
|
|
.decrypt = crypto4xx_decrypt_noiv_block,
|
2018-04-20 00:41:52 +08:00
|
|
|
.init = crypto4xx_sk_init,
|
|
|
|
.exit = crypto4xx_sk_exit,
|
|
|
|
} },
|
|
|
|
{ .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
|
|
|
|
.base = {
|
|
|
|
.cra_name = "ofb(aes)",
|
|
|
|
.cra_driver_name = "ofb-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
2018-07-01 06:16:15 +08:00
|
|
|
.cra_flags = CRYPTO_ALG_ASYNC |
|
2018-04-20 00:41:52 +08:00
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
2019-05-19 05:28:11 +08:00
|
|
|
.cra_blocksize = 1,
|
2018-04-20 00:41:52 +08:00
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.min_keysize = AES_MIN_KEY_SIZE,
|
|
|
|
.max_keysize = AES_MAX_KEY_SIZE,
|
|
|
|
.ivsize = AES_IV_SIZE,
|
|
|
|
.setkey = crypto4xx_setkey_aes_ofb,
|
2019-05-19 05:28:12 +08:00
|
|
|
.encrypt = crypto4xx_encrypt_iv_stream,
|
|
|
|
.decrypt = crypto4xx_decrypt_iv_stream,
|
2018-04-20 00:41:52 +08:00
|
|
|
.init = crypto4xx_sk_init,
|
|
|
|
.exit = crypto4xx_sk_exit,
|
2017-08-25 21:47:21 +08:00
|
|
|
} },
|
2017-10-04 07:00:16 +08:00
|
|
|
|
|
|
|
/* AEAD */
|
|
|
|
{ .type = CRYPTO_ALG_TYPE_AEAD, .u.aead = {
|
|
|
|
.setkey = crypto4xx_setkey_aes_ccm,
|
|
|
|
.setauthsize = crypto4xx_setauthsize_aead,
|
|
|
|
.encrypt = crypto4xx_encrypt_aes_ccm,
|
|
|
|
.decrypt = crypto4xx_decrypt_aes_ccm,
|
|
|
|
.init = crypto4xx_aead_init,
|
|
|
|
.exit = crypto4xx_aead_exit,
|
|
|
|
.ivsize = AES_BLOCK_SIZE,
|
|
|
|
.maxauthsize = 16,
|
|
|
|
.base = {
|
|
|
|
.cra_name = "ccm(aes)",
|
|
|
|
.cra_driver_name = "ccm-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
|
|
|
.cra_flags = CRYPTO_ALG_ASYNC |
|
|
|
|
CRYPTO_ALG_NEED_FALLBACK |
|
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
|
|
|
.cra_blocksize = 1,
|
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
} },
|
2017-10-04 07:00:17 +08:00
|
|
|
{ .type = CRYPTO_ALG_TYPE_AEAD, .u.aead = {
|
|
|
|
.setkey = crypto4xx_setkey_aes_gcm,
|
|
|
|
.setauthsize = crypto4xx_setauthsize_aead,
|
|
|
|
.encrypt = crypto4xx_encrypt_aes_gcm,
|
|
|
|
.decrypt = crypto4xx_decrypt_aes_gcm,
|
|
|
|
.init = crypto4xx_aead_init,
|
|
|
|
.exit = crypto4xx_aead_exit,
|
|
|
|
.ivsize = GCM_AES_IV_SIZE,
|
|
|
|
.maxauthsize = 16,
|
|
|
|
.base = {
|
|
|
|
.cra_name = "gcm(aes)",
|
|
|
|
.cra_driver_name = "gcm-aes-ppc4xx",
|
|
|
|
.cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
|
|
|
|
.cra_flags = CRYPTO_ALG_ASYNC |
|
|
|
|
CRYPTO_ALG_NEED_FALLBACK |
|
|
|
|
CRYPTO_ALG_KERN_DRIVER_ONLY,
|
|
|
|
.cra_blocksize = 1,
|
|
|
|
.cra_ctxsize = sizeof(struct crypto4xx_ctx),
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
} },
|
2018-12-23 09:16:13 +08:00
|
|
|
{ .type = CRYPTO_ALG_TYPE_RNG, .u.rng = {
|
|
|
|
.base = {
|
|
|
|
.cra_name = "stdrng",
|
|
|
|
.cra_driver_name = "crypto4xx_rng",
|
|
|
|
.cra_priority = 300,
|
|
|
|
.cra_ctxsize = 0,
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.generate = crypto4xx_prng_generate,
|
|
|
|
.seed = crypto4xx_prng_seed,
|
|
|
|
.seedsize = 0,
|
|
|
|
} },
|
2009-02-05 13:18:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module Initialization Routine
|
|
|
|
*/
|
2015-03-10 04:35:39 +08:00
|
|
|
static int crypto4xx_probe(struct platform_device *ofdev)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct resource res;
|
|
|
|
struct device *dev = &ofdev->dev;
|
|
|
|
struct crypto4xx_core_device *core_dev;
|
2017-12-23 04:18:36 +08:00
|
|
|
u32 pvr;
|
|
|
|
bool is_revb = true;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2010-06-03 08:53:18 +08:00
|
|
|
rc = of_address_to_resource(ofdev->dev.of_node, 0, &res);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (rc)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) {
|
|
|
|
mtdcri(SDR0, PPC460EX_SDR0_SRST,
|
|
|
|
mfdcri(SDR0, PPC460EX_SDR0_SRST) | PPC460EX_CE_RESET);
|
|
|
|
mtdcri(SDR0, PPC460EX_SDR0_SRST,
|
|
|
|
mfdcri(SDR0, PPC460EX_SDR0_SRST) & ~PPC460EX_CE_RESET);
|
|
|
|
} else if (of_find_compatible_node(NULL, NULL,
|
|
|
|
"amcc,ppc405ex-crypto")) {
|
|
|
|
mtdcri(SDR0, PPC405EX_SDR0_SRST,
|
|
|
|
mfdcri(SDR0, PPC405EX_SDR0_SRST) | PPC405EX_CE_RESET);
|
|
|
|
mtdcri(SDR0, PPC405EX_SDR0_SRST,
|
|
|
|
mfdcri(SDR0, PPC405EX_SDR0_SRST) & ~PPC405EX_CE_RESET);
|
2017-12-23 04:18:36 +08:00
|
|
|
is_revb = false;
|
2009-02-05 13:18:13 +08:00
|
|
|
} else if (of_find_compatible_node(NULL, NULL,
|
|
|
|
"amcc,ppc460sx-crypto")) {
|
|
|
|
mtdcri(SDR0, PPC460SX_SDR0_SRST,
|
|
|
|
mfdcri(SDR0, PPC460SX_SDR0_SRST) | PPC460SX_CE_RESET);
|
|
|
|
mtdcri(SDR0, PPC460SX_SDR0_SRST,
|
|
|
|
mfdcri(SDR0, PPC460SX_SDR0_SRST) & ~PPC460SX_CE_RESET);
|
|
|
|
} else {
|
|
|
|
printk(KERN_ERR "Crypto Function Not supported!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
core_dev = kzalloc(sizeof(struct crypto4xx_core_device), GFP_KERNEL);
|
|
|
|
if (!core_dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, core_dev);
|
|
|
|
core_dev->ofdev = ofdev;
|
|
|
|
core_dev->dev = kzalloc(sizeof(struct crypto4xx_device), GFP_KERNEL);
|
2017-06-10 20:54:33 +08:00
|
|
|
rc = -ENOMEM;
|
2009-02-05 13:18:13 +08:00
|
|
|
if (!core_dev->dev)
|
|
|
|
goto err_alloc_dev;
|
|
|
|
|
2017-12-23 04:18:36 +08:00
|
|
|
/*
|
|
|
|
* Older version of 460EX/GT have a hardware bug.
|
|
|
|
* Hence they do not support H/W based security intr coalescing
|
|
|
|
*/
|
|
|
|
pvr = mfspr(SPRN_PVR);
|
|
|
|
if (is_revb && ((pvr >> 4) == 0x130218A)) {
|
|
|
|
u32 min = PVR_MIN(pvr);
|
|
|
|
|
|
|
|
if (min < 4) {
|
|
|
|
dev_info(dev, "RevA detected - disable interrupt coalescing\n");
|
|
|
|
is_revb = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
core_dev->dev->core_dev = core_dev;
|
2017-12-23 04:18:36 +08:00
|
|
|
core_dev->dev->is_revb = is_revb;
|
2009-02-05 13:18:13 +08:00
|
|
|
core_dev->device = dev;
|
2018-12-23 09:16:13 +08:00
|
|
|
mutex_init(&core_dev->rng_lock);
|
2009-02-05 13:18:13 +08:00
|
|
|
spin_lock_init(&core_dev->lock);
|
|
|
|
INIT_LIST_HEAD(&core_dev->dev->alg_list);
|
2017-10-04 07:00:15 +08:00
|
|
|
ratelimit_default_init(&core_dev->dev->aead_ratelimit);
|
2020-01-02 06:27:01 +08:00
|
|
|
rc = crypto4xx_build_sdr(core_dev->dev);
|
|
|
|
if (rc)
|
|
|
|
goto err_build_sdr;
|
2009-02-05 13:18:13 +08:00
|
|
|
rc = crypto4xx_build_pdr(core_dev->dev);
|
|
|
|
if (rc)
|
2020-01-02 06:27:01 +08:00
|
|
|
goto err_build_sdr;
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
rc = crypto4xx_build_gdr(core_dev->dev);
|
|
|
|
if (rc)
|
|
|
|
goto err_build_sdr;
|
|
|
|
|
|
|
|
/* Init tasklet for bottom half processing */
|
|
|
|
tasklet_init(&core_dev->tasklet, crypto4xx_bh_tasklet_cb,
|
|
|
|
(unsigned long) dev);
|
|
|
|
|
2010-06-03 08:53:18 +08:00
|
|
|
core_dev->dev->ce_base = of_iomap(ofdev->dev.of_node, 0);
|
2009-02-05 13:18:13 +08:00
|
|
|
if (!core_dev->dev->ce_base) {
|
|
|
|
dev_err(dev, "failed to of_iomap\n");
|
2012-09-18 01:28:27 +08:00
|
|
|
rc = -ENOMEM;
|
2009-02-05 13:18:13 +08:00
|
|
|
goto err_iomap;
|
|
|
|
}
|
|
|
|
|
2017-12-23 04:18:35 +08:00
|
|
|
/* Register for Crypto isr, Crypto Engine IRQ */
|
|
|
|
core_dev->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
|
2017-12-23 04:18:36 +08:00
|
|
|
rc = request_irq(core_dev->irq, is_revb ?
|
|
|
|
crypto4xx_ce_interrupt_handler_revb :
|
|
|
|
crypto4xx_ce_interrupt_handler, 0,
|
2017-12-23 04:18:37 +08:00
|
|
|
KBUILD_MODNAME, dev);
|
2017-12-23 04:18:35 +08:00
|
|
|
if (rc)
|
|
|
|
goto err_request_irq;
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
/* need to setup pdr, rdr, gdr and sdr before this */
|
|
|
|
crypto4xx_hw_init(core_dev->dev);
|
|
|
|
|
|
|
|
/* Register security algorithms with Linux CryptoAPI */
|
|
|
|
rc = crypto4xx_register_alg(core_dev->dev, crypto4xx_alg,
|
|
|
|
ARRAY_SIZE(crypto4xx_alg));
|
|
|
|
if (rc)
|
|
|
|
goto err_start_dev;
|
|
|
|
|
2016-04-18 18:57:41 +08:00
|
|
|
ppc4xx_trng_probe(core_dev);
|
2009-02-05 13:18:13 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_start_dev:
|
|
|
|
free_irq(core_dev->irq, dev);
|
2012-04-15 04:48:41 +08:00
|
|
|
err_request_irq:
|
2009-02-05 13:18:13 +08:00
|
|
|
irq_dispose_mapping(core_dev->irq);
|
2017-12-23 04:18:35 +08:00
|
|
|
iounmap(core_dev->dev->ce_base);
|
|
|
|
err_iomap:
|
2009-02-05 13:18:13 +08:00
|
|
|
tasklet_kill(&core_dev->tasklet);
|
|
|
|
err_build_sdr:
|
2017-08-25 21:47:24 +08:00
|
|
|
crypto4xx_destroy_sdr(core_dev->dev);
|
2009-02-05 13:18:13 +08:00
|
|
|
crypto4xx_destroy_gdr(core_dev->dev);
|
2017-08-25 21:47:24 +08:00
|
|
|
crypto4xx_destroy_pdr(core_dev->dev);
|
2009-02-05 13:18:13 +08:00
|
|
|
kfree(core_dev->dev);
|
|
|
|
err_alloc_dev:
|
|
|
|
kfree(core_dev);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-03-10 04:35:39 +08:00
|
|
|
static int crypto4xx_remove(struct platform_device *ofdev)
|
2009-02-05 13:18:13 +08:00
|
|
|
{
|
|
|
|
struct device *dev = &ofdev->dev;
|
|
|
|
struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
|
|
|
|
|
2016-04-18 18:57:41 +08:00
|
|
|
ppc4xx_trng_remove(core_dev);
|
|
|
|
|
2009-02-05 13:18:13 +08:00
|
|
|
free_irq(core_dev->irq, dev);
|
|
|
|
irq_dispose_mapping(core_dev->irq);
|
|
|
|
|
|
|
|
tasklet_kill(&core_dev->tasklet);
|
|
|
|
/* Un-register with Linux CryptoAPI */
|
|
|
|
crypto4xx_unregister_alg(core_dev->dev);
|
2018-12-23 09:16:13 +08:00
|
|
|
mutex_destroy(&core_dev->rng_lock);
|
2009-02-05 13:18:13 +08:00
|
|
|
/* Free all allocated memory */
|
|
|
|
crypto4xx_stop_all(core_dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-17 18:54:01 +08:00
|
|
|
static const struct of_device_id crypto4xx_match[] = {
|
2009-02-05 13:18:13 +08:00
|
|
|
{ .compatible = "amcc,ppc4xx-crypto",},
|
|
|
|
{ },
|
|
|
|
};
|
2015-08-29 00:43:24 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, crypto4xx_match);
|
2009-02-05 13:18:13 +08:00
|
|
|
|
2011-02-23 10:59:54 +08:00
|
|
|
static struct platform_driver crypto4xx_driver = {
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
2017-12-23 04:18:38 +08:00
|
|
|
.name = KBUILD_MODNAME,
|
2010-04-14 07:13:02 +08:00
|
|
|
.of_match_table = crypto4xx_match,
|
|
|
|
},
|
2009-02-05 13:18:13 +08:00
|
|
|
.probe = crypto4xx_probe,
|
2015-03-10 04:35:39 +08:00
|
|
|
.remove = crypto4xx_remove,
|
2009-02-05 13:18:13 +08:00
|
|
|
};
|
|
|
|
|
2011-11-26 21:26:19 +08:00
|
|
|
module_platform_driver(crypto4xx_driver);
|
2009-02-05 13:18:13 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("James Hsiao <jhsiao@amcc.com>");
|
|
|
|
MODULE_DESCRIPTION("Driver for AMCC PPC4xx crypto accelerator");
|