21 #include <linux/kernel.h>
24 #include <linux/random.h>
31 #include <linux/slab.h>
34 #include <asm/cacheflush.h>
35 #include <crypto/aes.h>
36 #include <crypto/sha.h>
41 #define PPC4XX_SEC_VERSION_STR "0.5"
59 pe_dma_cfg.
bf.bo_sgpd_en = 1;
60 pe_dma_cfg.
bf.bo_data_en = 0;
61 pe_dma_cfg.
bf.bo_sa_en = 1;
62 pe_dma_cfg.
bf.bo_pd_en = 1;
63 pe_dma_cfg.
bf.dynamic_sa_en = 1;
64 pe_dma_cfg.
bf.reset_sg = 1;
65 pe_dma_cfg.
bf.reset_pdr = 1;
66 pe_dma_cfg.
bf.reset_pe = 1;
69 pe_dma_cfg.
bf.pe_mode = 0;
70 pe_dma_cfg.
bf.reset_sg = 0;
71 pe_dma_cfg.
bf.reset_pdr = 0;
72 pe_dma_cfg.
bf.reset_pe = 0;
73 pe_dma_cfg.
bf.bo_td_en = 0;
110 pe_dma_cfg.
bf.pe_mode = 1;
111 pe_dma_cfg.
bf.reset_sg = 0;
112 pe_dma_cfg.
bf.reset_pdr = 0;
113 pe_dma_cfg.
bf.reset_pe = 0;
114 pe_dma_cfg.
bf.bo_td_en = 0;
221 pd_uinfo = (
struct pd_uinfo *) (dev->
pdr_uinfo +
222 sizeof(
struct pd_uinfo) *
i);
242 sizeof(
struct ce_pd) * PPC4XX_NUM_PD,
261 tmp = (dev->
pdr_head + 1) % PPC4XX_NUM_PD;
273 struct pd_uinfo *pd_uinfo;
276 pd_uinfo = (
struct pd_uinfo *)(dev->
pdr_uinfo +
277 sizeof(
struct pd_uinfo) *
idx);
284 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
336 if (tmp < dev->gdr_head && tmp >= dev->
gdr_tail)
339 if (tmp < dev->gdr_head || tmp >= dev->
gdr_tail)
353 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
362 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
383 struct ce_sd *sd_array;
443 if (tmp < dev->sdr_head && tmp >= dev->
sdr_tail)
446 if (tmp < dev->sdr_head || tmp >= dev->
sdr_tail)
460 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
467 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
500 }
else if (*length < dev->scatter_buffer_size) {
538 struct pd_uinfo *pd_uinfo,
562 while (crypto4xx_fill_one_page(dev, &addr, &len,
563 &this_sd, &offset, &nbytes))
572 while (crypto4xx_fill_one_page(dev, &addr, &len,
573 &this_sd, &offset, &nbytes))
580 while (crypto4xx_fill_one_page(dev, &addr,
581 &sg_len, &this_sd, &offset, &nbytes))
589 static u32 crypto4xx_copy_digest_to_dst(
struct pd_uinfo *pd_uinfo,
597 memcpy((
void *) pd_uinfo->
dest_va, state_record->save_digest,
605 struct pd_uinfo *pd_uinfo)
609 for (i = 0; i < pd_uinfo->
num_gd; i++)
610 crypto4xx_put_gd_to_gdr(dev);
615 for (i = 0; i < pd_uinfo->
num_sd; i++)
616 crypto4xx_put_sd_to_sdr(dev);
624 struct pd_uinfo *pd_uinfo,
632 ablk_req = ablkcipher_request_cast(pd_uinfo->
async_req);
633 ctx = crypto_tfm_ctx(ablk_req->
base.tfm);
636 crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo, ablk_req->
nbytes,
643 crypto4xx_ret_sg_desc(dev, pd_uinfo);
644 if (ablk_req->
base.complete !=
NULL)
645 ablk_req->
base.complete(&ablk_req->
base, 0);
651 struct pd_uinfo *pd_uinfo)
656 ahash_req = ahash_request_cast(pd_uinfo->
async_req);
657 ctx = crypto_tfm_ctx(ahash_req->
base.tfm);
659 crypto4xx_copy_digest_to_dst(pd_uinfo,
660 crypto_tfm_ctx(ahash_req->
base.tfm));
661 crypto4xx_ret_sg_desc(dev, pd_uinfo);
663 if (ahash_req->
base.complete !=
NULL)
664 ahash_req->
base.complete(&ahash_req->
base, 0);
672 struct pd_uinfo *pd_uinfo;
675 pd_uinfo = dev->
pdr_uinfo +
sizeof(
struct pd_uinfo)*
idx;
676 if (crypto_tfm_alg_type(pd_uinfo->
async_req->tfm) ==
678 return crypto4xx_ablkcipher_done(dev, pd_uinfo, pd);
680 return crypto4xx_ahash_done(dev, pd_uinfo);
687 const unsigned char *
buf,
691 for (; len >= 4; buf += 4, len -= 4)
721 crypto4xx_destroy_pdr(core_dev->
dev);
722 crypto4xx_destroy_gdr(core_dev->
dev);
723 crypto4xx_destroy_sdr(core_dev->
dev);
732 struct pd_uinfo *pd_uinfo)
769 static u32 get_next_sd(
u32 current)
782 void *
iv,
u32 iv_len)
791 u32 fst_gd = 0xffffffff;
792 u32 fst_sd = 0xffffffff;
795 struct pd_uinfo *pd_uinfo =
NULL;
797 unsigned int ivlen = 0;
801 num_gd = get_sg_count(src, datalen);
828 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
833 fst_sd = crypto4xx_get_n_sd(dev, num_sd);
837 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
841 pd_entry = crypto4xx_get_pd_from_pdr_nolock(dev);
847 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
850 spin_unlock_irqrestore(&dev->
core_dev->lock, flags);
852 pd_uinfo = (
struct pd_uinfo *)(dev->
pdr_uinfo +
853 sizeof(
struct pd_uinfo) * pd_entry);
854 pd = crypto4xx_get_pdp(dev, &pd_dma, pd_entry);
869 &pd_uinfo->
sr_pa, 4);
887 pd_uinfo->
num_gd = num_gd;
888 gd = crypto4xx_get_gdp(dev, &gd_dma, gd_idx);
906 gd_idx = get_next_gd(gd_idx);
907 gd = crypto4xx_get_gdp(dev, &gd_dma, gd_idx);
938 sg_page(dst), dst->
offset,
948 pd_uinfo->
num_sd = num_sd;
949 sd = crypto4xx_get_sdp(dev, &sd_dma, sd_idx);
961 sd_idx = get_next_sd(sd_idx);
962 sd = crypto4xx_get_sdp(dev, &sd_dma, sd_idx);
990 static int crypto4xx_alg_init(
struct crypto_tfm *tfm)
993 struct crypto4xx_alg *amcc_alg = crypto_alg_to_crypto4xx_alg(alg);
1008 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
1016 static void crypto4xx_alg_exit(
struct crypto_tfm *tfm)
1032 for (i = 0; i < array_size; i++) {
1037 alg->
alg = crypto_alg[
i];
1040 switch (alg->
alg.type) {
1067 switch (alg->
alg.type) {
1079 static void crypto4xx_bh_tasklet_cb(
unsigned long data)
1083 struct pd_uinfo *pd_uinfo;
1087 while (core_dev->
dev->pdr_head != core_dev->
dev->pdr_tail) {
1088 tail = core_dev->
dev->pdr_tail;
1089 pd_uinfo = core_dev->
dev->pdr_uinfo +
1090 sizeof(
struct pd_uinfo)*
tail;
1096 crypto4xx_pd_done(core_dev->
dev, tail);
1097 crypto4xx_put_pd_to_pdr(core_dev->
dev, tail);
1109 static irqreturn_t crypto4xx_ce_interrupt_handler(
int irq,
void *data)
1114 if (core_dev->
dev->ce_base == 0)
1119 tasklet_schedule(&core_dev->
tasklet);
1130 .cra_name =
"cbc(aes)",
1131 .cra_driver_name =
"cbc-aes-ppc4xx",
1137 .cra_init = crypto4xx_alg_init,
1138 .cra_exit = crypto4xx_alg_exit,
1173 "amcc,ppc405ex-crypto")) {
1179 "amcc,ppc460sx-crypto")) {
1199 core_dev->
dev->core_dev = core_dev;
1202 INIT_LIST_HEAD(&core_dev->
dev->alg_list);
1203 rc = crypto4xx_build_pdr(core_dev->
dev);
1207 rc = crypto4xx_build_gdr(core_dev->
dev);
1211 rc = crypto4xx_build_sdr(core_dev->
dev);
1217 (
unsigned long) dev);
1221 rc =
request_irq(core_dev->
irq, crypto4xx_ce_interrupt_handler, 0,
1222 core_dev->
dev->name, dev);
1224 goto err_request_irq;
1227 if (!core_dev->
dev->ce_base) {
1228 dev_err(dev,
"failed to of_iomap\n");
1234 crypto4xx_hw_init(core_dev->
dev);
1251 crypto4xx_destroy_sdr(core_dev->
dev);
1253 crypto4xx_destroy_gdr(core_dev->
dev);
1255 crypto4xx_destroy_pdr(core_dev->
dev);
1274 crypto4xx_unregister_alg(core_dev->
dev);
1276 crypto4xx_stop_all(core_dev);
1282 { .compatible =
"amcc,ppc4xx-crypto",},
1288 .name =
"crypto4xx",
1290 .of_match_table = crypto4xx_match,
1292 .probe = crypto4xx_probe,
1293 .remove = crypto4xx_remove,