aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto
diff options
context:
space:
mode:
authorRuchika Gupta <ruchika.gupta@freescale.com>2013-07-04 01:56:03 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2013-07-31 20:50:21 -0400
commit997ad2900ac13b8afcfc45ce79bf662551a501eb (patch)
tree2e82d8c7446e98cee33dd44bf8fae45d343198e0 /drivers/crypto
parentaa2faec1a05f1ebc2856be911f83e696f8dc2122 (diff)
crypto: caam - RNG instantiation by directly programming DECO
Remove the dependency of RNG instantiation on Job Ring. Now RNG instantiation for devices with RNG version > 4 is done by directly programming DECO 0. Signed-off-by: Ruchika Gupta <ruchika.gupta@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/caam/ctrl.c74
-rw-r--r--drivers/crypto/caam/regs.h12
2 files changed, 47 insertions, 39 deletions
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index f5d6deced1cb..86c96009faad 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -75,55 +75,53 @@ static void build_instantiation_desc(u32 *desc)
75 OP_ALG_RNG4_SK); 75 OP_ALG_RNG4_SK);
76} 76}
77 77
78struct instantiate_result { 78static int instantiate_rng(struct device *ctrldev)
79 struct completion completion;
80 int err;
81};
82
83static void rng4_init_done(struct device *dev, u32 *desc, u32 err,
84 void *context)
85{ 79{
86 struct instantiate_result *instantiation = context; 80 struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
87 81 struct caam_full __iomem *topregs;
88 if (err) { 82 unsigned int timeout = 100000;
89 char tmp[CAAM_ERROR_STR_MAX];
90
91 dev_err(dev, "%08x: %s\n", err, caam_jr_strstatus(tmp, err));
92 }
93
94 instantiation->err = err;
95 complete(&instantiation->completion);
96}
97
98static int instantiate_rng(struct device *jrdev)
99{
100 struct instantiate_result instantiation;
101
102 dma_addr_t desc_dma;
103 u32 *desc; 83 u32 *desc;
104 int ret; 84 int i, ret = 0;
105 85
106 desc = kmalloc(CAAM_CMD_SZ * 6, GFP_KERNEL | GFP_DMA); 86 desc = kmalloc(CAAM_CMD_SZ * 6, GFP_KERNEL | GFP_DMA);
107 if (!desc) { 87 if (!desc) {
108 dev_err(jrdev, "cannot allocate RNG init descriptor memory\n"); 88 dev_err(ctrldev, "can't allocate RNG init descriptor memory\n");
109 return -ENOMEM; 89 return -ENOMEM;
110 } 90 }
111
112 build_instantiation_desc(desc); 91 build_instantiation_desc(desc);
113 desc_dma = dma_map_single(jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE); 92
114 init_completion(&instantiation.completion); 93 /* Set the bit to request direct access to DECO0 */
115 ret = caam_jr_enqueue(jrdev, desc, rng4_init_done, &instantiation); 94 topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
116 if (!ret) { 95 setbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
117 wait_for_completion_interruptible(&instantiation.completion); 96
118 ret = instantiation.err; 97 while (!(rd_reg32(&topregs->ctrl.deco_rq) & DECORR_DEN0) &&
119 if (ret) 98 --timeout)
120 dev_err(jrdev, "unable to instantiate RNG\n"); 99 cpu_relax();
100
101 if (!timeout) {
102 dev_err(ctrldev, "failed to acquire DECO 0\n");
103 ret = -EIO;
104 goto out;
121 } 105 }
122 106
123 dma_unmap_single(jrdev, desc_dma, desc_bytes(desc), DMA_TO_DEVICE); 107 for (i = 0; i < desc_len(desc); i++)
108 topregs->deco.descbuf[i] = *(desc + i);
124 109
125 kfree(desc); 110 wr_reg32(&topregs->deco.jr_ctl_hi, DECO_JQCR_WHL | DECO_JQCR_FOUR);
111
112 timeout = 10000000;
113 while ((rd_reg32(&topregs->deco.desc_dbg) & DECO_DBG_VALID) &&
114 --timeout)
115 cpu_relax();
126 116
117 if (!timeout) {
118 dev_err(ctrldev, "failed to instantiate RNG\n");
119 ret = -EIO;
120 }
121
122 clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
123out:
124 kfree(desc);
127 return ret; 125 return ret;
128} 126}
129 127
@@ -303,7 +301,7 @@ static int caam_probe(struct platform_device *pdev)
303 if ((cha_vid & CHA_ID_RNG_MASK) >> CHA_ID_RNG_SHIFT >= 4 && 301 if ((cha_vid & CHA_ID_RNG_MASK) >> CHA_ID_RNG_SHIFT >= 4 &&
304 !(rd_reg32(&topregs->ctrl.r4tst[0].rdsta) & RDSTA_IF0)) { 302 !(rd_reg32(&topregs->ctrl.r4tst[0].rdsta) & RDSTA_IF0)) {
305 kick_trng(pdev); 303 kick_trng(pdev);
306 ret = instantiate_rng(ctrlpriv->jrdev[0]); 304 ret = instantiate_rng(dev);
307 if (ret) { 305 if (ret) {
308 caam_remove(pdev); 306 caam_remove(pdev);
309 return ret; 307 return ret;
diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index c09142fc13e3..4455396918de 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -341,6 +341,8 @@ struct caam_ctrl {
341#define MCFGR_DMA_RESET 0x10000000 341#define MCFGR_DMA_RESET 0x10000000
342#define MCFGR_LONG_PTR 0x00010000 /* Use >32-bit desc addressing */ 342#define MCFGR_LONG_PTR 0x00010000 /* Use >32-bit desc addressing */
343#define SCFGR_RDBENABLE 0x00000400 343#define SCFGR_RDBENABLE 0x00000400
344#define DECORR_RQD0ENABLE 0x00000001 /* Enable DECO0 for direct access */
345#define DECORR_DEN0 0x00010000 /* DECO0 available for access*/
344 346
345/* AXI read cache control */ 347/* AXI read cache control */
346#define MCFGR_ARCACHE_SHIFT 12 348#define MCFGR_ARCACHE_SHIFT 12
@@ -703,9 +705,16 @@ struct caam_deco {
703 struct deco_sg_table sctr_tbl[4]; /* DxSTR - Scatter Tables */ 705 struct deco_sg_table sctr_tbl[4]; /* DxSTR - Scatter Tables */
704 u32 rsvd29[48]; 706 u32 rsvd29[48];
705 u32 descbuf[64]; /* DxDESB - Descriptor buffer */ 707 u32 descbuf[64]; /* DxDESB - Descriptor buffer */
706 u32 rsvd30[320]; 708 u32 rscvd30[193];
709 u32 desc_dbg; /* DxDDR - DECO Debug Register */
710 u32 rsvd31[126];
707}; 711};
708 712
713/* DECO DBG Register Valid Bit*/
714#define DECO_DBG_VALID 0x80000000
715#define DECO_JQCR_WHL 0x20000000
716#define DECO_JQCR_FOUR 0x10000000
717
709/* 718/*
710 * Current top-level view of memory map is: 719 * Current top-level view of memory map is:
711 * 720 *
@@ -733,6 +742,7 @@ struct caam_full {
733 u64 rsvd[512]; 742 u64 rsvd[512];
734 struct caam_assurance assure; 743 struct caam_assurance assure;
735 struct caam_queue_if qi; 744 struct caam_queue_if qi;
745 struct caam_deco deco;
736}; 746};
737 747
738#endif /* REGS_H */ 748#endif /* REGS_H */