Lines Matching +full:multi +full:- +full:word
1 // SPDX-License-Identifier: GPL-2.0
3 * sun8i-ce-prng.c - hardware cryptographic offloader for
6 * Copyright (C) 2015-2020 Corentin Labbe <clabbe@baylibre.com>
12 #include "sun8i-ce.h"
13 #include <linux/dma-mapping.h>
29 memzero_explicit(ctx->seed, ctx->slen); in sun8i_ce_prng_exit()
30 kfree(ctx->seed); in sun8i_ce_prng_exit()
31 ctx->seed = NULL; in sun8i_ce_prng_exit()
32 ctx->slen = 0; in sun8i_ce_prng_exit()
40 if (ctx->seed && ctx->slen != slen) { in sun8i_ce_prng_seed()
41 memzero_explicit(ctx->seed, ctx->slen); in sun8i_ce_prng_seed()
42 kfree(ctx->seed); in sun8i_ce_prng_seed()
43 ctx->slen = 0; in sun8i_ce_prng_seed()
44 ctx->seed = NULL; in sun8i_ce_prng_seed()
46 if (!ctx->seed) in sun8i_ce_prng_seed()
47 ctx->seed = kmalloc(slen, GFP_KERNEL | GFP_DMA); in sun8i_ce_prng_seed()
48 if (!ctx->seed) in sun8i_ce_prng_seed()
49 return -ENOMEM; in sun8i_ce_prng_seed()
51 memcpy(ctx->seed, seed, slen); in sun8i_ce_prng_seed()
52 ctx->slen = slen; in sun8i_ce_prng_seed()
74 ce = algt->ce; in sun8i_ce_prng_generate()
76 if (ctx->slen == 0) { in sun8i_ce_prng_generate()
77 dev_err(ce->dev, "not seeded\n"); in sun8i_ce_prng_generate()
78 return -EINVAL; in sun8i_ce_prng_generate()
82 todo = dlen + ctx->slen + PRNG_DATA_SIZE * 2; in sun8i_ce_prng_generate()
83 todo -= todo % PRNG_DATA_SIZE; in sun8i_ce_prng_generate()
87 err = -ENOMEM; in sun8i_ce_prng_generate()
91 dev_dbg(ce->dev, "%s PRNG slen=%u dlen=%u todo=%u multi=%u\n", __func__, in sun8i_ce_prng_generate()
95 algt->stat_req++; in sun8i_ce_prng_generate()
96 algt->stat_bytes += todo; in sun8i_ce_prng_generate()
99 dma_iv = dma_map_single(ce->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE); in sun8i_ce_prng_generate()
100 if (dma_mapping_error(ce->dev, dma_iv)) { in sun8i_ce_prng_generate()
101 dev_err(ce->dev, "Cannot DMA MAP IV\n"); in sun8i_ce_prng_generate()
105 dma_dst = dma_map_single(ce->dev, d, todo, DMA_FROM_DEVICE); in sun8i_ce_prng_generate()
106 if (dma_mapping_error(ce->dev, dma_dst)) { in sun8i_ce_prng_generate()
107 dev_err(ce->dev, "Cannot DMA MAP DST\n"); in sun8i_ce_prng_generate()
108 err = -EFAULT; in sun8i_ce_prng_generate()
112 err = pm_runtime_get_sync(ce->dev); in sun8i_ce_prng_generate()
114 pm_runtime_put_noidle(ce->dev); in sun8i_ce_prng_generate()
118 mutex_lock(&ce->rnglock); in sun8i_ce_prng_generate()
119 chan = &ce->chanlist[flow]; in sun8i_ce_prng_generate()
121 cet = &chan->tl[0]; in sun8i_ce_prng_generate()
124 cet->t_id = cpu_to_le32(flow); in sun8i_ce_prng_generate()
125 common = ce->variant->prng | CE_COMM_INT; in sun8i_ce_prng_generate()
126 cet->t_common_ctl = cpu_to_le32(common); in sun8i_ce_prng_generate()
128 /* recent CE (H6) need length in bytes, in word otherwise */ in sun8i_ce_prng_generate()
129 if (ce->variant->prng_t_dlen_in_bytes) in sun8i_ce_prng_generate()
130 cet->t_dlen = cpu_to_le32(todo); in sun8i_ce_prng_generate()
132 cet->t_dlen = cpu_to_le32(todo / 4); in sun8i_ce_prng_generate()
135 cet->t_sym_ctl = cpu_to_le32(sym); in sun8i_ce_prng_generate()
136 cet->t_asym_ctl = 0; in sun8i_ce_prng_generate()
138 cet->t_key = cpu_to_le32(dma_iv); in sun8i_ce_prng_generate()
139 cet->t_iv = cpu_to_le32(dma_iv); in sun8i_ce_prng_generate()
141 cet->t_dst[0].addr = cpu_to_le32(dma_dst); in sun8i_ce_prng_generate()
142 cet->t_dst[0].len = cpu_to_le32(todo / 4); in sun8i_ce_prng_generate()
143 ce->chanlist[flow].timeout = 2000; in sun8i_ce_prng_generate()
146 mutex_unlock(&ce->rnglock); in sun8i_ce_prng_generate()
148 pm_runtime_put(ce->dev); in sun8i_ce_prng_generate()
151 dma_unmap_single(ce->dev, dma_dst, todo, DMA_FROM_DEVICE); in sun8i_ce_prng_generate()
153 dma_unmap_single(ce->dev, dma_iv, ctx->slen, DMA_TO_DEVICE); in sun8i_ce_prng_generate()
157 memcpy(ctx->seed, d + dlen, ctx->slen); in sun8i_ce_prng_generate()