Lines Matching +full:triple +full:- +full:channel

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Support for OMAP DES and Triple DES HW acceleration.
26 #include <linux/dma-mapping.h>
41 #include "omap-crypto.h"
47 #define _calc_walked(inout) (dd->inout##_walk.offset - dd->inout##_sg->offset)
49 #define DES_REG_KEY(dd, x) ((dd)->pdata->key_ofs - \
52 #define DES_REG_IV(dd, x) ((dd)->pdata->iv_ofs + ((x) * 0x04))
54 #define DES_REG_CTRL(dd) ((dd)->pdata->ctrl_ofs)
61 #define DES_REG_DATA_N(dd, x) ((dd)->pdata->data_ofs + ((x) * 0x04))
63 #define DES_REG_REV(dd) ((dd)->pdata->rev_ofs)
65 #define DES_REG_MASK(dd) ((dd)->pdata->mask_ofs)
69 #define DES_REG_IRQ_STATUS(dd) ((dd)->pdata->irq_status_ofs)
70 #define DES_REG_IRQ_ENABLE(dd) ((dd)->pdata->irq_enable_ofs)
178 _read_ret = __raw_readl(dd->io_base + offset); \
186 return __raw_readl(dd->io_base + offset); in omap_des_read()
195 __raw_writel(value, dd->io_base + offset); \
201 __raw_writel(value, dd->io_base + offset); in omap_des_write()
219 for (; count--; value++, offset += 4) in omap_des_write_n()
232 err = pm_runtime_resume_and_get(dd->dev); in omap_des_hw_init()
234 dev_err(dd->dev, "%s: failed to get_sync(%d)\n", __func__, err); in omap_des_hw_init()
238 if (!(dd->flags & FLAGS_INIT)) { in omap_des_hw_init()
239 dd->flags |= FLAGS_INIT; in omap_des_hw_init()
240 dd->err = 0; in omap_des_hw_init()
256 key32 = dd->ctx->keylen / sizeof(u32); in omap_des_write_ctrl()
261 __le32_to_cpu(dd->ctx->key[i])); in omap_des_write_ctrl()
264 if ((dd->flags & FLAGS_CBC) && dd->req->iv) in omap_des_write_ctrl()
265 omap_des_write_n(dd, DES_REG_IV(dd, 0), (void *)dd->req->iv, 2); in omap_des_write_ctrl()
267 if (dd->flags & FLAGS_CBC) in omap_des_write_ctrl()
269 if (dd->flags & FLAGS_ENCRYPT) in omap_des_write_ctrl()
287 val = dd->pdata->dma_start; in omap_des_dma_trigger_omap4()
289 if (dd->dma_lch_out != NULL) in omap_des_dma_trigger_omap4()
290 val |= dd->pdata->dma_enable_out; in omap_des_dma_trigger_omap4()
291 if (dd->dma_lch_in != NULL) in omap_des_dma_trigger_omap4()
292 val |= dd->pdata->dma_enable_in; in omap_des_dma_trigger_omap4()
294 mask = dd->pdata->dma_enable_out | dd->pdata->dma_enable_in | in omap_des_dma_trigger_omap4()
295 dd->pdata->dma_start; in omap_des_dma_trigger_omap4()
304 mask = dd->pdata->dma_enable_out | dd->pdata->dma_enable_in | in omap_des_dma_stop()
305 dd->pdata->dma_start; in omap_des_dma_stop()
315 if (!ctx->dd) { in omap_des_find_dev()
321 ctx->dd = dd; in omap_des_find_dev()
324 dd = ctx->dd; in omap_des_find_dev()
335 /* dma_lch_out - completed */ in omap_des_dma_out_callback()
336 tasklet_schedule(&dd->done_task); in omap_des_dma_out_callback()
343 dd->dma_lch_out = NULL; in omap_des_dma_init()
344 dd->dma_lch_in = NULL; in omap_des_dma_init()
346 dd->dma_lch_in = dma_request_chan(dd->dev, "rx"); in omap_des_dma_init()
347 if (IS_ERR(dd->dma_lch_in)) { in omap_des_dma_init()
348 dev_err(dd->dev, "Unable to request in DMA channel\n"); in omap_des_dma_init()
349 return PTR_ERR(dd->dma_lch_in); in omap_des_dma_init()
352 dd->dma_lch_out = dma_request_chan(dd->dev, "tx"); in omap_des_dma_init()
353 if (IS_ERR(dd->dma_lch_out)) { in omap_des_dma_init()
354 dev_err(dd->dev, "Unable to request out DMA channel\n"); in omap_des_dma_init()
355 err = PTR_ERR(dd->dma_lch_out); in omap_des_dma_init()
362 dma_release_channel(dd->dma_lch_in); in omap_des_dma_init()
369 if (dd->pio_only) in omap_des_dma_cleanup()
372 dma_release_channel(dd->dma_lch_out); in omap_des_dma_cleanup()
373 dma_release_channel(dd->dma_lch_in); in omap_des_dma_cleanup()
381 struct omap_des_dev *dd = ctx->dd; in omap_des_crypt_dma()
386 if (dd->pio_only) { in omap_des_crypt_dma()
387 scatterwalk_start(&dd->in_walk, dd->in_sg); in omap_des_crypt_dma()
388 scatterwalk_start(&dd->out_walk, dd->out_sg); in omap_des_crypt_dma()
396 dma_sync_sg_for_device(dd->dev, dd->in_sg, in_sg_len, DMA_TO_DEVICE); in omap_des_crypt_dma()
400 cfg.src_addr = dd->phys_base + DES_REG_DATA_N(dd, 0); in omap_des_crypt_dma()
401 cfg.dst_addr = dd->phys_base + DES_REG_DATA_N(dd, 0); in omap_des_crypt_dma()
408 ret = dmaengine_slave_config(dd->dma_lch_in, &cfg); in omap_des_crypt_dma()
410 dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n", in omap_des_crypt_dma()
415 tx_in = dmaengine_prep_slave_sg(dd->dma_lch_in, in_sg, in_sg_len, in omap_des_crypt_dma()
419 dev_err(dd->dev, "IN prep_slave_sg() failed\n"); in omap_des_crypt_dma()
420 return -EINVAL; in omap_des_crypt_dma()
424 tx_in->callback_param = dd; in omap_des_crypt_dma()
427 ret = dmaengine_slave_config(dd->dma_lch_out, &cfg); in omap_des_crypt_dma()
429 dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n", in omap_des_crypt_dma()
434 tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg, out_sg_len, in omap_des_crypt_dma()
438 dev_err(dd->dev, "OUT prep_slave_sg() failed\n"); in omap_des_crypt_dma()
439 return -EINVAL; in omap_des_crypt_dma()
442 tx_out->callback = omap_des_dma_out_callback; in omap_des_crypt_dma()
443 tx_out->callback_param = dd; in omap_des_crypt_dma()
448 dma_async_issue_pending(dd->dma_lch_in); in omap_des_crypt_dma()
449 dma_async_issue_pending(dd->dma_lch_out); in omap_des_crypt_dma()
452 dd->pdata->trigger(dd, dd->total); in omap_des_crypt_dma()
460 crypto_skcipher_reqtfm(dd->req)); in omap_des_crypt_dma_start()
463 pr_debug("total: %zd\n", dd->total); in omap_des_crypt_dma_start()
465 if (!dd->pio_only) { in omap_des_crypt_dma_start()
466 err = dma_map_sg(dd->dev, dd->in_sg, dd->in_sg_len, in omap_des_crypt_dma_start()
469 dev_err(dd->dev, "dma_map_sg() error\n"); in omap_des_crypt_dma_start()
470 return -EINVAL; in omap_des_crypt_dma_start()
473 err = dma_map_sg(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_crypt_dma_start()
476 dev_err(dd->dev, "dma_map_sg() error\n"); in omap_des_crypt_dma_start()
477 return -EINVAL; in omap_des_crypt_dma_start()
481 err = omap_des_crypt_dma(tfm, dd->in_sg, dd->out_sg, dd->in_sg_len, in omap_des_crypt_dma_start()
482 dd->out_sg_len); in omap_des_crypt_dma_start()
483 if (err && !dd->pio_only) { in omap_des_crypt_dma_start()
484 dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE); in omap_des_crypt_dma_start()
485 dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_crypt_dma_start()
494 struct skcipher_request *req = dd->req; in omap_des_finish_req()
498 crypto_finalize_skcipher_request(dd->engine, req, err); in omap_des_finish_req()
500 pm_runtime_mark_last_busy(dd->dev); in omap_des_finish_req()
501 pm_runtime_put_autosuspend(dd->dev); in omap_des_finish_req()
506 pr_debug("total: %zd\n", dd->total); in omap_des_crypt_dma_stop()
510 dmaengine_terminate_all(dd->dma_lch_in); in omap_des_crypt_dma_stop()
511 dmaengine_terminate_all(dd->dma_lch_out); in omap_des_crypt_dma_stop()
520 return crypto_transfer_skcipher_request_to_engine(dd->engine, req); in omap_des_handle_queue()
537 return -ENODEV; in omap_des_prepare_req()
540 dd->req = req; in omap_des_prepare_req()
541 dd->total = req->cryptlen; in omap_des_prepare_req()
542 dd->total_save = req->cryptlen; in omap_des_prepare_req()
543 dd->in_sg = req->src; in omap_des_prepare_req()
544 dd->out_sg = req->dst; in omap_des_prepare_req()
545 dd->orig_out = req->dst; in omap_des_prepare_req()
548 if (req->src == req->dst) in omap_des_prepare_req()
551 ret = omap_crypto_align_sg(&dd->in_sg, dd->total, DES_BLOCK_SIZE, in omap_des_prepare_req()
552 &dd->in_sgl, flags, in omap_des_prepare_req()
553 FLAGS_IN_DATA_ST_SHIFT, &dd->flags); in omap_des_prepare_req()
557 ret = omap_crypto_align_sg(&dd->out_sg, dd->total, DES_BLOCK_SIZE, in omap_des_prepare_req()
558 &dd->out_sgl, 0, in omap_des_prepare_req()
559 FLAGS_OUT_DATA_ST_SHIFT, &dd->flags); in omap_des_prepare_req()
563 dd->in_sg_len = sg_nents_for_len(dd->in_sg, dd->total); in omap_des_prepare_req()
564 if (dd->in_sg_len < 0) in omap_des_prepare_req()
565 return dd->in_sg_len; in omap_des_prepare_req()
567 dd->out_sg_len = sg_nents_for_len(dd->out_sg, dd->total); in omap_des_prepare_req()
568 if (dd->out_sg_len < 0) in omap_des_prepare_req()
569 return dd->out_sg_len; in omap_des_prepare_req()
573 rctx->mode &= FLAGS_MODE_MASK; in omap_des_prepare_req()
574 dd->flags = (dd->flags & ~FLAGS_MODE_MASK) | rctx->mode; in omap_des_prepare_req()
576 dd->ctx = ctx; in omap_des_prepare_req()
577 ctx->dd = dd; in omap_des_prepare_req()
591 return -ENODEV; in omap_des_crypt_req()
603 if (!dd->pio_only) { in omap_des_done_task()
604 dma_sync_sg_for_device(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_done_task()
606 dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE); in omap_des_done_task()
607 dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_done_task()
612 omap_crypto_cleanup(&dd->in_sgl, NULL, 0, dd->total_save, in omap_des_done_task()
613 FLAGS_IN_DATA_ST_SHIFT, dd->flags); in omap_des_done_task()
615 omap_crypto_cleanup(&dd->out_sgl, dd->orig_out, 0, dd->total_save, in omap_des_done_task()
616 FLAGS_OUT_DATA_ST_SHIFT, dd->flags); in omap_des_done_task()
618 if ((dd->flags & FLAGS_CBC) && dd->req->iv) in omap_des_done_task()
620 ((u32 *)dd->req->iv)[i] = in omap_des_done_task()
635 pr_debug("nbytes: %d, enc: %d, cbc: %d\n", req->cryptlen, in omap_des_crypt()
639 if (!req->cryptlen) in omap_des_crypt()
642 if (!IS_ALIGNED(req->cryptlen, DES_BLOCK_SIZE)) in omap_des_crypt()
643 return -EINVAL; in omap_des_crypt()
647 return -ENODEV; in omap_des_crypt()
649 rctx->mode = mode; in omap_des_crypt()
668 memcpy(ctx->key, key, keylen); in omap_des_setkey()
669 ctx->keylen = keylen; in omap_des_setkey()
686 memcpy(ctx->key, key, keylen); in omap_des3_setkey()
687 ctx->keylen = keylen; in omap_des3_setkey()
725 ctx->enginectx.op.prepare_request = omap_des_prepare_req; in omap_des_init_tfm()
726 ctx->enginectx.op.unprepare_request = NULL; in omap_des_init_tfm()
727 ctx->enginectx.op.do_one_request = omap_des_crypt_req; in omap_des_init_tfm()
737 .base.cra_driver_name = "ecb-des-omap",
754 .base.cra_driver_name = "cbc-des-omap",
772 .base.cra_driver_name = "ecb-des3-omap",
789 .base.cra_driver_name = "cbc-des3-omap",
845 BUG_ON(!dd->in_sg); in omap_des_irq()
847 BUG_ON(_calc_walked(in) > dd->in_sg->length); in omap_des_irq()
849 src = sg_virt(dd->in_sg) + _calc_walked(in); in omap_des_irq()
854 scatterwalk_advance(&dd->in_walk, 4); in omap_des_irq()
855 if (dd->in_sg->length == _calc_walked(in)) { in omap_des_irq()
856 dd->in_sg = sg_next(dd->in_sg); in omap_des_irq()
857 if (dd->in_sg) { in omap_des_irq()
858 scatterwalk_start(&dd->in_walk, in omap_des_irq()
859 dd->in_sg); in omap_des_irq()
860 src = sg_virt(dd->in_sg) + in omap_des_irq()
878 BUG_ON(!dd->out_sg); in omap_des_irq()
880 BUG_ON(_calc_walked(out) > dd->out_sg->length); in omap_des_irq()
882 dst = sg_virt(dd->out_sg) + _calc_walked(out); in omap_des_irq()
886 scatterwalk_advance(&dd->out_walk, 4); in omap_des_irq()
887 if (dd->out_sg->length == _calc_walked(out)) { in omap_des_irq()
888 dd->out_sg = sg_next(dd->out_sg); in omap_des_irq()
889 if (dd->out_sg) { in omap_des_irq()
890 scatterwalk_start(&dd->out_walk, in omap_des_irq()
891 dd->out_sg); in omap_des_irq()
892 dst = sg_virt(dd->out_sg) + in omap_des_irq()
900 BUG_ON(dd->total < DES_BLOCK_SIZE); in omap_des_irq()
902 dd->total -= DES_BLOCK_SIZE; in omap_des_irq()
908 if (!dd->total) in omap_des_irq()
910 tasklet_schedule(&dd->done_task); in omap_des_irq()
921 .compatible = "ti,omap4-des",
932 dd->pdata = of_device_get_match_data(&pdev->dev); in omap_des_get_of()
933 if (!dd->pdata) { in omap_des_get_of()
934 dev_err(&pdev->dev, "no compatible OF match\n"); in omap_des_get_of()
935 return -EINVAL; in omap_des_get_of()
944 return -EINVAL; in omap_des_get_of()
951 /* non-DT devices get pdata from pdev */ in omap_des_get_pdev()
952 dd->pdata = pdev->dev.platform_data; in omap_des_get_pdev()
959 struct device *dev = &pdev->dev; in omap_des_probe()
963 int err = -ENOMEM, i, j, irq = -1; in omap_des_probe()
971 dd->dev = dev; in omap_des_probe()
980 err = (dev->of_node) ? omap_des_get_of(dd, pdev) : in omap_des_probe()
985 dd->io_base = devm_ioremap_resource(dev, res); in omap_des_probe()
986 if (IS_ERR(dd->io_base)) { in omap_des_probe()
987 err = PTR_ERR(dd->io_base); in omap_des_probe()
990 dd->phys_base = res->start; in omap_des_probe()
998 dev_err(dd->dev, "%s: failed to get_sync(%d)\n", __func__, err); in omap_des_probe()
1009 (reg & dd->pdata->major_mask) >> dd->pdata->major_shift, in omap_des_probe()
1010 (reg & dd->pdata->minor_mask) >> dd->pdata->minor_shift); in omap_des_probe()
1012 tasklet_init(&dd->done_task, omap_des_done_task, (unsigned long)dd); in omap_des_probe()
1015 if (err == -EPROBE_DEFER) { in omap_des_probe()
1018 dd->pio_only = 1; in omap_des_probe()
1029 dev_err(dev, "Unable to grab omap-des IRQ\n"); in omap_des_probe()
1035 INIT_LIST_HEAD(&dd->list); in omap_des_probe()
1037 list_add_tail(&dd->list, &dev_list); in omap_des_probe()
1041 dd->engine = crypto_engine_alloc_init(dev, 1); in omap_des_probe()
1042 if (!dd->engine) { in omap_des_probe()
1043 err = -ENOMEM; in omap_des_probe()
1047 err = crypto_engine_start(dd->engine); in omap_des_probe()
1051 for (i = 0; i < dd->pdata->algs_info_size; i++) { in omap_des_probe()
1052 for (j = 0; j < dd->pdata->algs_info[i].size; j++) { in omap_des_probe()
1053 algp = &dd->pdata->algs_info[i].algs_list[j]; in omap_des_probe()
1055 pr_debug("reg alg: %s\n", algp->base.cra_name); in omap_des_probe()
1061 dd->pdata->algs_info[i].registered++; in omap_des_probe()
1068 for (i = dd->pdata->algs_info_size - 1; i >= 0; i--) in omap_des_probe()
1069 for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--) in omap_des_probe()
1071 &dd->pdata->algs_info[i].algs_list[j]); in omap_des_probe()
1074 if (dd->engine) in omap_des_probe()
1075 crypto_engine_exit(dd->engine); in omap_des_probe()
1079 tasklet_kill(&dd->done_task); in omap_des_probe()
1095 list_del(&dd->list); in omap_des_remove()
1098 for (i = dd->pdata->algs_info_size - 1; i >= 0; i--) in omap_des_remove()
1099 for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--) in omap_des_remove()
1101 &dd->pdata->algs_info[i].algs_list[j]); in omap_des_remove()
1103 tasklet_kill(&dd->done_task); in omap_des_remove()
1105 pm_runtime_disable(dd->dev); in omap_des_remove()
1136 .name = "omap-des",