Skip to content

Commit 63ee04c

Browse files
Gilad Ben-Yossefherbertx
authored andcommitted
crypto: ccree - add skcipher support
Add CryptoCell skcipher support Signed-off-by: Gilad Ben-Yossef <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 4c3f972 commit 63ee04c

File tree

7 files changed

+1339
-2
lines changed

7 files changed

+1339
-2
lines changed

drivers/crypto/ccree/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
obj-$(CONFIG_CRYPTO_DEV_CCREE) := ccree.o
4-
ccree-y := cc_driver.o cc_buffer_mgr.o cc_request_mgr.o cc_ivgen.o cc_sram_mgr.o
4+
ccree-y := cc_driver.o cc_buffer_mgr.o cc_request_mgr.o cc_cipher.o cc_ivgen.o cc_sram_mgr.o
55
ccree-$(CONFIG_DEBUG_FS) += cc_debugfs.o
66
ccree-$(CONFIG_PM) += cc_pm.o

drivers/crypto/ccree/cc_buffer_mgr.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "cc_buffer_mgr.h"
1010
#include "cc_lli_defs.h"
11+
#include "cc_cipher.h"
1112

1213
enum dma_buffer_type {
1314
DMA_NULL_TYPE = -1,
@@ -347,6 +348,130 @@ static int cc_map_sg(struct device *dev, struct scatterlist *sg,
347348
return 0;
348349
}
349350

351+
void cc_unmap_cipher_request(struct device *dev, void *ctx,
352+
unsigned int ivsize, struct scatterlist *src,
353+
struct scatterlist *dst)
354+
{
355+
struct cipher_req_ctx *req_ctx = (struct cipher_req_ctx *)ctx;
356+
357+
if (req_ctx->gen_ctx.iv_dma_addr) {
358+
dev_dbg(dev, "Unmapped iv: iv_dma_addr=%pad iv_size=%u\n",
359+
&req_ctx->gen_ctx.iv_dma_addr, ivsize);
360+
dma_unmap_single(dev, req_ctx->gen_ctx.iv_dma_addr,
361+
ivsize,
362+
req_ctx->is_giv ? DMA_BIDIRECTIONAL :
363+
DMA_TO_DEVICE);
364+
}
365+
/* Release pool */
366+
if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI &&
367+
req_ctx->mlli_params.mlli_virt_addr) {
368+
dma_pool_free(req_ctx->mlli_params.curr_pool,
369+
req_ctx->mlli_params.mlli_virt_addr,
370+
req_ctx->mlli_params.mlli_dma_addr);
371+
}
372+
373+
dma_unmap_sg(dev, src, req_ctx->in_nents, DMA_BIDIRECTIONAL);
374+
dev_dbg(dev, "Unmapped req->src=%pK\n", sg_virt(src));
375+
376+
if (src != dst) {
377+
dma_unmap_sg(dev, dst, req_ctx->out_nents, DMA_BIDIRECTIONAL);
378+
dev_dbg(dev, "Unmapped req->dst=%pK\n", sg_virt(dst));
379+
}
380+
}
381+
382+
int cc_map_cipher_request(struct cc_drvdata *drvdata, void *ctx,
383+
unsigned int ivsize, unsigned int nbytes,
384+
void *info, struct scatterlist *src,
385+
struct scatterlist *dst, gfp_t flags)
386+
{
387+
struct cipher_req_ctx *req_ctx = (struct cipher_req_ctx *)ctx;
388+
struct mlli_params *mlli_params = &req_ctx->mlli_params;
389+
struct buff_mgr_handle *buff_mgr = drvdata->buff_mgr_handle;
390+
struct device *dev = drvdata_to_dev(drvdata);
391+
struct buffer_array sg_data;
392+
u32 dummy = 0;
393+
int rc = 0;
394+
u32 mapped_nents = 0;
395+
396+
req_ctx->dma_buf_type = CC_DMA_BUF_DLLI;
397+
mlli_params->curr_pool = NULL;
398+
sg_data.num_of_buffers = 0;
399+
400+
/* Map IV buffer */
401+
if (ivsize) {
402+
dump_byte_array("iv", (u8 *)info, ivsize);
403+
req_ctx->gen_ctx.iv_dma_addr =
404+
dma_map_single(dev, (void *)info,
405+
ivsize,
406+
req_ctx->is_giv ? DMA_BIDIRECTIONAL :
407+
DMA_TO_DEVICE);
408+
if (dma_mapping_error(dev, req_ctx->gen_ctx.iv_dma_addr)) {
409+
dev_err(dev, "Mapping iv %u B at va=%pK for DMA failed\n",
410+
ivsize, info);
411+
return -ENOMEM;
412+
}
413+
dev_dbg(dev, "Mapped iv %u B at va=%pK to dma=%pad\n",
414+
ivsize, info, &req_ctx->gen_ctx.iv_dma_addr);
415+
} else {
416+
req_ctx->gen_ctx.iv_dma_addr = 0;
417+
}
418+
419+
/* Map the src SGL */
420+
rc = cc_map_sg(dev, src, nbytes, DMA_BIDIRECTIONAL, &req_ctx->in_nents,
421+
LLI_MAX_NUM_OF_DATA_ENTRIES, &dummy, &mapped_nents);
422+
if (rc) {
423+
rc = -ENOMEM;
424+
goto cipher_exit;
425+
}
426+
if (mapped_nents > 1)
427+
req_ctx->dma_buf_type = CC_DMA_BUF_MLLI;
428+
429+
if (src == dst) {
430+
/* Handle inplace operation */
431+
if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI) {
432+
req_ctx->out_nents = 0;
433+
cc_add_sg_entry(dev, &sg_data, req_ctx->in_nents, src,
434+
nbytes, 0, true,
435+
&req_ctx->in_mlli_nents);
436+
}
437+
} else {
438+
/* Map the dst sg */
439+
if (cc_map_sg(dev, dst, nbytes, DMA_BIDIRECTIONAL,
440+
&req_ctx->out_nents, LLI_MAX_NUM_OF_DATA_ENTRIES,
441+
&dummy, &mapped_nents)) {
442+
rc = -ENOMEM;
443+
goto cipher_exit;
444+
}
445+
if (mapped_nents > 1)
446+
req_ctx->dma_buf_type = CC_DMA_BUF_MLLI;
447+
448+
if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI) {
449+
cc_add_sg_entry(dev, &sg_data, req_ctx->in_nents, src,
450+
nbytes, 0, true,
451+
&req_ctx->in_mlli_nents);
452+
cc_add_sg_entry(dev, &sg_data, req_ctx->out_nents, dst,
453+
nbytes, 0, true,
454+
&req_ctx->out_mlli_nents);
455+
}
456+
}
457+
458+
if (req_ctx->dma_buf_type == CC_DMA_BUF_MLLI) {
459+
mlli_params->curr_pool = buff_mgr->mlli_buffs_pool;
460+
rc = cc_generate_mlli(dev, &sg_data, mlli_params, flags);
461+
if (rc)
462+
goto cipher_exit;
463+
}
464+
465+
dev_dbg(dev, "areq_ctx->dma_buf_type = %s\n",
466+
cc_dma_buf_type(req_ctx->dma_buf_type));
467+
468+
return 0;
469+
470+
cipher_exit:
471+
cc_unmap_cipher_request(dev, req_ctx, ivsize, src, dst);
472+
return rc;
473+
}
474+
350475
int cc_buffer_mgr_init(struct cc_drvdata *drvdata)
351476
{
352477
struct buff_mgr_handle *buff_mgr_handle;

drivers/crypto/ccree/cc_buffer_mgr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ int cc_buffer_mgr_init(struct cc_drvdata *drvdata);
4040

4141
int cc_buffer_mgr_fini(struct cc_drvdata *drvdata);
4242

43+
int cc_map_cipher_request(struct cc_drvdata *drvdata, void *ctx,
44+
unsigned int ivsize, unsigned int nbytes,
45+
void *info, struct scatterlist *src,
46+
struct scatterlist *dst, gfp_t flags);
47+
48+
void cc_unmap_cipher_request(struct device *dev, void *ctx, unsigned int ivsize,
49+
struct scatterlist *src, struct scatterlist *dst);
50+
4351
int cc_map_hash_request_final(struct cc_drvdata *drvdata, void *ctx,
4452
struct scatterlist *src, unsigned int nbytes,
4553
bool do_update, gfp_t flags);

0 commit comments

Comments
 (0)