• Home
  • Raw
  • Download

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_get_sync(dd->dev); in omap_des_hw_init()
234 pm_runtime_put_noidle(dd->dev); in omap_des_hw_init()
235 dev_err(dd->dev, "%s: failed to get_sync(%d)\n", __func__, err); in omap_des_hw_init()
239 if (!(dd->flags & FLAGS_INIT)) { in omap_des_hw_init()
240 dd->flags |= FLAGS_INIT; in omap_des_hw_init()
241 dd->err = 0; in omap_des_hw_init()
257 key32 = dd->ctx->keylen / sizeof(u32); in omap_des_write_ctrl()
262 __le32_to_cpu(dd->ctx->key[i])); in omap_des_write_ctrl()
265 if ((dd->flags & FLAGS_CBC) && dd->req->iv) in omap_des_write_ctrl()
266 omap_des_write_n(dd, DES_REG_IV(dd, 0), (void *)dd->req->iv, 2); in omap_des_write_ctrl()
268 if (dd->flags & FLAGS_CBC) in omap_des_write_ctrl()
270 if (dd->flags & FLAGS_ENCRYPT) in omap_des_write_ctrl()
288 val = dd->pdata->dma_start; in omap_des_dma_trigger_omap4()
290 if (dd->dma_lch_out != NULL) in omap_des_dma_trigger_omap4()
291 val |= dd->pdata->dma_enable_out; in omap_des_dma_trigger_omap4()
292 if (dd->dma_lch_in != NULL) in omap_des_dma_trigger_omap4()
293 val |= dd->pdata->dma_enable_in; in omap_des_dma_trigger_omap4()
295 mask = dd->pdata->dma_enable_out | dd->pdata->dma_enable_in | in omap_des_dma_trigger_omap4()
296 dd->pdata->dma_start; in omap_des_dma_trigger_omap4()
305 mask = dd->pdata->dma_enable_out | dd->pdata->dma_enable_in | in omap_des_dma_stop()
306 dd->pdata->dma_start; in omap_des_dma_stop()
316 if (!ctx->dd) { in omap_des_find_dev()
322 ctx->dd = dd; in omap_des_find_dev()
325 dd = ctx->dd; in omap_des_find_dev()
336 /* dma_lch_out - completed */ in omap_des_dma_out_callback()
337 tasklet_schedule(&dd->done_task); in omap_des_dma_out_callback()
344 dd->dma_lch_out = NULL; in omap_des_dma_init()
345 dd->dma_lch_in = NULL; in omap_des_dma_init()
347 dd->dma_lch_in = dma_request_chan(dd->dev, "rx"); in omap_des_dma_init()
348 if (IS_ERR(dd->dma_lch_in)) { in omap_des_dma_init()
349 dev_err(dd->dev, "Unable to request in DMA channel\n"); in omap_des_dma_init()
350 return PTR_ERR(dd->dma_lch_in); in omap_des_dma_init()
353 dd->dma_lch_out = dma_request_chan(dd->dev, "tx"); in omap_des_dma_init()
354 if (IS_ERR(dd->dma_lch_out)) { in omap_des_dma_init()
355 dev_err(dd->dev, "Unable to request out DMA channel\n"); in omap_des_dma_init()
356 err = PTR_ERR(dd->dma_lch_out); in omap_des_dma_init()
363 dma_release_channel(dd->dma_lch_in); in omap_des_dma_init()
370 if (dd->pio_only) in omap_des_dma_cleanup()
373 dma_release_channel(dd->dma_lch_out); in omap_des_dma_cleanup()
374 dma_release_channel(dd->dma_lch_in); in omap_des_dma_cleanup()
382 struct omap_des_dev *dd = ctx->dd; in omap_des_crypt_dma()
387 if (dd->pio_only) { in omap_des_crypt_dma()
388 scatterwalk_start(&dd->in_walk, dd->in_sg); in omap_des_crypt_dma()
389 scatterwalk_start(&dd->out_walk, dd->out_sg); in omap_des_crypt_dma()
397 dma_sync_sg_for_device(dd->dev, dd->in_sg, in_sg_len, DMA_TO_DEVICE); in omap_des_crypt_dma()
401 cfg.src_addr = dd->phys_base + DES_REG_DATA_N(dd, 0); in omap_des_crypt_dma()
402 cfg.dst_addr = dd->phys_base + DES_REG_DATA_N(dd, 0); in omap_des_crypt_dma()
409 ret = dmaengine_slave_config(dd->dma_lch_in, &cfg); in omap_des_crypt_dma()
411 dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n", in omap_des_crypt_dma()
416 tx_in = dmaengine_prep_slave_sg(dd->dma_lch_in, in_sg, in_sg_len, in omap_des_crypt_dma()
420 dev_err(dd->dev, "IN prep_slave_sg() failed\n"); in omap_des_crypt_dma()
421 return -EINVAL; in omap_des_crypt_dma()
425 tx_in->callback_param = dd; in omap_des_crypt_dma()
428 ret = dmaengine_slave_config(dd->dma_lch_out, &cfg); in omap_des_crypt_dma()
430 dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n", in omap_des_crypt_dma()
435 tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg, out_sg_len, in omap_des_crypt_dma()
439 dev_err(dd->dev, "OUT prep_slave_sg() failed\n"); in omap_des_crypt_dma()
440 return -EINVAL; in omap_des_crypt_dma()
443 tx_out->callback = omap_des_dma_out_callback; in omap_des_crypt_dma()
444 tx_out->callback_param = dd; in omap_des_crypt_dma()
449 dma_async_issue_pending(dd->dma_lch_in); in omap_des_crypt_dma()
450 dma_async_issue_pending(dd->dma_lch_out); in omap_des_crypt_dma()
453 dd->pdata->trigger(dd, dd->total); in omap_des_crypt_dma()
461 crypto_skcipher_reqtfm(dd->req)); in omap_des_crypt_dma_start()
464 pr_debug("total: %zd\n", dd->total); in omap_des_crypt_dma_start()
466 if (!dd->pio_only) { in omap_des_crypt_dma_start()
467 err = dma_map_sg(dd->dev, dd->in_sg, dd->in_sg_len, in omap_des_crypt_dma_start()
470 dev_err(dd->dev, "dma_map_sg() error\n"); in omap_des_crypt_dma_start()
471 return -EINVAL; in omap_des_crypt_dma_start()
474 err = dma_map_sg(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_crypt_dma_start()
477 dev_err(dd->dev, "dma_map_sg() error\n"); in omap_des_crypt_dma_start()
478 return -EINVAL; in omap_des_crypt_dma_start()
482 err = omap_des_crypt_dma(tfm, dd->in_sg, dd->out_sg, dd->in_sg_len, in omap_des_crypt_dma_start()
483 dd->out_sg_len); in omap_des_crypt_dma_start()
484 if (err && !dd->pio_only) { in omap_des_crypt_dma_start()
485 dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE); in omap_des_crypt_dma_start()
486 dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_crypt_dma_start()
495 struct skcipher_request *req = dd->req; in omap_des_finish_req()
499 crypto_finalize_skcipher_request(dd->engine, req, err); in omap_des_finish_req()
501 pm_runtime_mark_last_busy(dd->dev); in omap_des_finish_req()
502 pm_runtime_put_autosuspend(dd->dev); in omap_des_finish_req()
507 pr_debug("total: %zd\n", dd->total); in omap_des_crypt_dma_stop()
511 dmaengine_terminate_all(dd->dma_lch_in); in omap_des_crypt_dma_stop()
512 dmaengine_terminate_all(dd->dma_lch_out); in omap_des_crypt_dma_stop()
521 return crypto_transfer_skcipher_request_to_engine(dd->engine, req); in omap_des_handle_queue()
538 return -ENODEV; in omap_des_prepare_req()
541 dd->req = req; in omap_des_prepare_req()
542 dd->total = req->cryptlen; in omap_des_prepare_req()
543 dd->total_save = req->cryptlen; in omap_des_prepare_req()
544 dd->in_sg = req->src; in omap_des_prepare_req()
545 dd->out_sg = req->dst; in omap_des_prepare_req()
546 dd->orig_out = req->dst; in omap_des_prepare_req()
549 if (req->src == req->dst) in omap_des_prepare_req()
552 ret = omap_crypto_align_sg(&dd->in_sg, dd->total, DES_BLOCK_SIZE, in omap_des_prepare_req()
553 &dd->in_sgl, flags, in omap_des_prepare_req()
554 FLAGS_IN_DATA_ST_SHIFT, &dd->flags); in omap_des_prepare_req()
558 ret = omap_crypto_align_sg(&dd->out_sg, dd->total, DES_BLOCK_SIZE, in omap_des_prepare_req()
559 &dd->out_sgl, 0, in omap_des_prepare_req()
560 FLAGS_OUT_DATA_ST_SHIFT, &dd->flags); in omap_des_prepare_req()
564 dd->in_sg_len = sg_nents_for_len(dd->in_sg, dd->total); in omap_des_prepare_req()
565 if (dd->in_sg_len < 0) in omap_des_prepare_req()
566 return dd->in_sg_len; in omap_des_prepare_req()
568 dd->out_sg_len = sg_nents_for_len(dd->out_sg, dd->total); in omap_des_prepare_req()
569 if (dd->out_sg_len < 0) in omap_des_prepare_req()
570 return dd->out_sg_len; in omap_des_prepare_req()
574 rctx->mode &= FLAGS_MODE_MASK; in omap_des_prepare_req()
575 dd->flags = (dd->flags & ~FLAGS_MODE_MASK) | rctx->mode; in omap_des_prepare_req()
577 dd->ctx = ctx; in omap_des_prepare_req()
578 ctx->dd = dd; in omap_des_prepare_req()
592 return -ENODEV; in omap_des_crypt_req()
604 if (!dd->pio_only) { in omap_des_done_task()
605 dma_sync_sg_for_device(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_done_task()
607 dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE); in omap_des_done_task()
608 dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len, in omap_des_done_task()
613 omap_crypto_cleanup(&dd->in_sgl, NULL, 0, dd->total_save, in omap_des_done_task()
614 FLAGS_IN_DATA_ST_SHIFT, dd->flags); in omap_des_done_task()
616 omap_crypto_cleanup(&dd->out_sgl, dd->orig_out, 0, dd->total_save, in omap_des_done_task()
617 FLAGS_OUT_DATA_ST_SHIFT, dd->flags); in omap_des_done_task()
619 if ((dd->flags & FLAGS_CBC) && dd->req->iv) in omap_des_done_task()
621 ((u32 *)dd->req->iv)[i] = in omap_des_done_task()
636 pr_debug("nbytes: %d, enc: %d, cbc: %d\n", req->cryptlen, in omap_des_crypt()
640 if (!req->cryptlen) in omap_des_crypt()
643 if (!IS_ALIGNED(req->cryptlen, DES_BLOCK_SIZE)) in omap_des_crypt()
644 return -EINVAL; in omap_des_crypt()
648 return -ENODEV; in omap_des_crypt()
650 rctx->mode = mode; in omap_des_crypt()
669 memcpy(ctx->key, key, keylen); in omap_des_setkey()
670 ctx->keylen = keylen; in omap_des_setkey()
687 memcpy(ctx->key, key, keylen); in omap_des3_setkey()
688 ctx->keylen = keylen; in omap_des3_setkey()
726 ctx->enginectx.op.prepare_request = omap_des_prepare_req; in omap_des_init_tfm()
727 ctx->enginectx.op.unprepare_request = NULL; in omap_des_init_tfm()
728 ctx->enginectx.op.do_one_request = omap_des_crypt_req; in omap_des_init_tfm()
738 .base.cra_driver_name = "ecb-des-omap",
755 .base.cra_driver_name = "cbc-des-omap",
773 .base.cra_driver_name = "ecb-des3-omap",
790 .base.cra_driver_name = "cbc-des3-omap",
846 BUG_ON(!dd->in_sg); in omap_des_irq()
848 BUG_ON(_calc_walked(in) > dd->in_sg->length); in omap_des_irq()
850 src = sg_virt(dd->in_sg) + _calc_walked(in); in omap_des_irq()
855 scatterwalk_advance(&dd->in_walk, 4); in omap_des_irq()
856 if (dd->in_sg->length == _calc_walked(in)) { in omap_des_irq()
857 dd->in_sg = sg_next(dd->in_sg); in omap_des_irq()
858 if (dd->in_sg) { in omap_des_irq()
859 scatterwalk_start(&dd->in_walk, in omap_des_irq()
860 dd->in_sg); in omap_des_irq()
861 src = sg_virt(dd->in_sg) + in omap_des_irq()
879 BUG_ON(!dd->out_sg); in omap_des_irq()
881 BUG_ON(_calc_walked(out) > dd->out_sg->length); in omap_des_irq()
883 dst = sg_virt(dd->out_sg) + _calc_walked(out); in omap_des_irq()
887 scatterwalk_advance(&dd->out_walk, 4); in omap_des_irq()
888 if (dd->out_sg->length == _calc_walked(out)) { in omap_des_irq()
889 dd->out_sg = sg_next(dd->out_sg); in omap_des_irq()
890 if (dd->out_sg) { in omap_des_irq()
891 scatterwalk_start(&dd->out_walk, in omap_des_irq()
892 dd->out_sg); in omap_des_irq()
893 dst = sg_virt(dd->out_sg) + in omap_des_irq()
901 BUG_ON(dd->total < DES_BLOCK_SIZE); in omap_des_irq()
903 dd->total -= DES_BLOCK_SIZE; in omap_des_irq()
909 if (!dd->total) in omap_des_irq()
911 tasklet_schedule(&dd->done_task); in omap_des_irq()
922 .compatible = "ti,omap4-des",
933 dd->pdata = of_device_get_match_data(&pdev->dev); in omap_des_get_of()
934 if (!dd->pdata) { in omap_des_get_of()
935 dev_err(&pdev->dev, "no compatible OF match\n"); in omap_des_get_of()
936 return -EINVAL; in omap_des_get_of()
945 return -EINVAL; in omap_des_get_of()
952 /* non-DT devices get pdata from pdev */ in omap_des_get_pdev()
953 dd->pdata = pdev->dev.platform_data; in omap_des_get_pdev()
960 struct device *dev = &pdev->dev; in omap_des_probe()
964 int err = -ENOMEM, i, j, irq = -1; in omap_des_probe()
972 dd->dev = dev; in omap_des_probe()
981 err = (dev->of_node) ? omap_des_get_of(dd, pdev) : in omap_des_probe()
986 dd->io_base = devm_ioremap_resource(dev, res); in omap_des_probe()
987 if (IS_ERR(dd->io_base)) { in omap_des_probe()
988 err = PTR_ERR(dd->io_base); in omap_des_probe()
991 dd->phys_base = res->start; in omap_des_probe()
1000 dev_err(dd->dev, "%s: failed to get_sync(%d)\n", __func__, err); in omap_des_probe()
1011 (reg & dd->pdata->major_mask) >> dd->pdata->major_shift, in omap_des_probe()
1012 (reg & dd->pdata->minor_mask) >> dd->pdata->minor_shift); in omap_des_probe()
1014 tasklet_init(&dd->done_task, omap_des_done_task, (unsigned long)dd); in omap_des_probe()
1017 if (err == -EPROBE_DEFER) { in omap_des_probe()
1020 dd->pio_only = 1; in omap_des_probe()
1031 dev_err(dev, "Unable to grab omap-des IRQ\n"); in omap_des_probe()
1037 INIT_LIST_HEAD(&dd->list); in omap_des_probe()
1039 list_add_tail(&dd->list, &dev_list); in omap_des_probe()
1043 dd->engine = crypto_engine_alloc_init(dev, 1); in omap_des_probe()
1044 if (!dd->engine) { in omap_des_probe()
1045 err = -ENOMEM; in omap_des_probe()
1049 err = crypto_engine_start(dd->engine); in omap_des_probe()
1053 for (i = 0; i < dd->pdata->algs_info_size; i++) { in omap_des_probe()
1054 for (j = 0; j < dd->pdata->algs_info[i].size; j++) { in omap_des_probe()
1055 algp = &dd->pdata->algs_info[i].algs_list[j]; in omap_des_probe()
1057 pr_debug("reg alg: %s\n", algp->base.cra_name); in omap_des_probe()
1063 dd->pdata->algs_info[i].registered++; in omap_des_probe()
1070 for (i = dd->pdata->algs_info_size - 1; i >= 0; i--) in omap_des_probe()
1071 for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--) in omap_des_probe()
1073 &dd->pdata->algs_info[i].algs_list[j]); in omap_des_probe()
1076 if (dd->engine) in omap_des_probe()
1077 crypto_engine_exit(dd->engine); in omap_des_probe()
1081 tasklet_kill(&dd->done_task); in omap_des_probe()
1097 return -ENODEV; in omap_des_remove()
1100 list_del(&dd->list); in omap_des_remove()
1103 for (i = dd->pdata->algs_info_size - 1; i >= 0; i--) in omap_des_remove()
1104 for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--) in omap_des_remove()
1106 &dd->pdata->algs_info[i].algs_list[j]); in omap_des_remove()
1108 tasklet_kill(&dd->done_task); in omap_des_remove()
1110 pm_runtime_disable(dd->dev); in omap_des_remove()
1143 .name = "omap-des",