blob: 29cbec18a3a8d416afdbfc7b3aa72f48302c122e [file] [log] [blame]
Kim Phillips8e8ec592011-03-13 16:54:26 +08001/*
2 * CAAM control-plane driver backend
3 * Controller-level driver, kernel property detection, initialization
4 *
Kim Phillips281922a2012-06-22 19:48:52 -05005 * Copyright 2008-2012 Freescale Semiconductor, Inc.
Kim Phillips8e8ec592011-03-13 16:54:26 +08006 */
7
8#include "compat.h"
9#include "regs.h"
10#include "intern.h"
11#include "jr.h"
Kim Phillips281922a2012-06-22 19:48:52 -050012#include "desc_constr.h"
13#include "error.h"
Alex Porosanu82c2f962012-07-11 11:06:11 +080014#include "ctrl.h"
Kim Phillips8e8ec592011-03-13 16:54:26 +080015
Kim Phillips281922a2012-06-22 19:48:52 -050016/*
17 * Descriptor to instantiate RNG State Handle 0 in normal mode and
18 * load the JDKEK, TDKEK and TDSK registers
19 */
20static void build_instantiation_desc(u32 *desc)
21{
22 u32 *jump_cmd;
23
24 init_job_desc(desc, 0);
25
26 /* INIT RNG in non-test mode */
27 append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
28 OP_ALG_AS_INIT);
29
30 /* wait for done */
31 jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
32 set_jump_tgt_here(desc, jump_cmd);
33
34 /*
35 * load 1 to clear written reg:
Masanari Iidacf2fbdd2013-03-16 20:53:05 +090036 * resets the done interrupt and returns the RNG to idle.
Kim Phillips281922a2012-06-22 19:48:52 -050037 */
38 append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);
39
40 /* generate secure keys (non-test) */
41 append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
Alex Porosanuf1157a52013-09-09 18:56:33 +030042 OP_ALG_AAI_RNG4_SK);
Alex Porosanud5e4e992013-09-09 18:56:28 +030043
44 append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
Kim Phillips281922a2012-06-22 19:48:52 -050045}
46
Alex Porosanub1f996e02013-09-09 18:56:32 +030047/* Descriptor for deinstantiation of State Handle 0 of the RNG block. */
48static void build_deinstantiation_desc(u32 *desc)
49{
50 init_job_desc(desc, 0);
51
52 /* Uninstantiate State Handle 0 */
53 append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
54 OP_ALG_AS_INITFINAL);
55
56 append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
57}
Alex Porosanu04cddbf2013-09-09 18:56:31 +030058
59/*
60 * run_descriptor_deco0 - runs a descriptor on DECO0, under direct control of
61 * the software (no JR/QI used).
62 * @ctrldev - pointer to device
63 * Return: - 0 if no error occurred
64 * - -ENODEV if the DECO couldn't be acquired
65 * - -EAGAIN if an error occurred while executing the descriptor
66 */
67static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc)
Kim Phillips281922a2012-06-22 19:48:52 -050068{
Ruchika Gupta997ad292013-07-04 11:26:03 +053069 struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
70 struct caam_full __iomem *topregs;
71 unsigned int timeout = 100000;
Alex Porosanu04cddbf2013-09-09 18:56:31 +030072 u32 deco_dbg_reg, flags;
Alex Porosanub1f996e02013-09-09 18:56:32 +030073 int i;
Kim Phillips281922a2012-06-22 19:48:52 -050074
Ruchika Gupta997ad292013-07-04 11:26:03 +053075 /* Set the bit to request direct access to DECO0 */
76 topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
77 setbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
78
79 while (!(rd_reg32(&topregs->ctrl.deco_rq) & DECORR_DEN0) &&
80 --timeout)
81 cpu_relax();
82
83 if (!timeout) {
84 dev_err(ctrldev, "failed to acquire DECO 0\n");
Alex Porosanu04cddbf2013-09-09 18:56:31 +030085 clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
86 return -ENODEV;
Kim Phillips281922a2012-06-22 19:48:52 -050087 }
88
Ruchika Gupta997ad292013-07-04 11:26:03 +053089 for (i = 0; i < desc_len(desc); i++)
Alex Porosanu04cddbf2013-09-09 18:56:31 +030090 wr_reg32(&topregs->deco.descbuf[i], *(desc + i));
Kim Phillips281922a2012-06-22 19:48:52 -050091
Alex Porosanu04cddbf2013-09-09 18:56:31 +030092 flags = DECO_JQCR_WHL;
93 /*
94 * If the descriptor length is longer than 4 words, then the
95 * FOUR bit in JRCTRL register must be set.
96 */
97 if (desc_len(desc) >= 4)
98 flags |= DECO_JQCR_FOUR;
99
100 /* Instruct the DECO to execute it */
101 wr_reg32(&topregs->deco.jr_ctl_hi, flags);
Ruchika Gupta997ad292013-07-04 11:26:03 +0530102
103 timeout = 10000000;
Alex Porosanu84cf4822013-09-09 18:56:30 +0300104 do {
105 deco_dbg_reg = rd_reg32(&topregs->deco.desc_dbg);
106 /*
107 * If an error occured in the descriptor, then
108 * the DECO status field will be set to 0x0D
109 */
110 if ((deco_dbg_reg & DESC_DBG_DECO_STAT_MASK) ==
111 DESC_DBG_DECO_STAT_HOST_ERR)
112 break;
Ruchika Gupta997ad292013-07-04 11:26:03 +0530113 cpu_relax();
Alex Porosanu84cf4822013-09-09 18:56:30 +0300114 } while ((deco_dbg_reg & DESC_DBG_DECO_STAT_VALID) && --timeout);
Ruchika Gupta997ad292013-07-04 11:26:03 +0530115
Alex Porosanu04cddbf2013-09-09 18:56:31 +0300116 /* Mark the DECO as free */
Ruchika Gupta997ad292013-07-04 11:26:03 +0530117 clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
Alex Porosanu04cddbf2013-09-09 18:56:31 +0300118
119 if (!timeout)
120 return -EAGAIN;
121
122 return 0;
123}
124
125/*
126 * instantiate_rng - builds and executes a descriptor on DECO0,
127 * which initializes the RNG block.
128 * @ctrldev - pointer to device
129 * Return: - 0 if no error occurred
130 * - -ENOMEM if there isn't enough memory to allocate the descriptor
131 * - -ENODEV if DECO0 couldn't be acquired
132 * - -EAGAIN if an error occurred when executing the descriptor
133 * f.i. there was a RNG hardware error due to not "good enough"
134 * entropy being aquired.
135 */
136static int instantiate_rng(struct device *ctrldev)
137{
138 u32 *desc;
139 int ret = 0;
140
141 desc = kmalloc(CAAM_CMD_SZ * 7, GFP_KERNEL);
142 if (!desc)
143 return -ENOMEM;
144 /* Create the descriptor for instantiating RNG State Handle 0 */
145 build_instantiation_desc(desc);
146
147 /* Try to run it through DECO0 */
148 ret = run_descriptor_deco0(ctrldev, desc);
149
Kim Phillips281922a2012-06-22 19:48:52 -0500150 kfree(desc);
Alex Porosanu04cddbf2013-09-09 18:56:31 +0300151
152 return ret;
153}
154
Alex Porosanub1f996e02013-09-09 18:56:32 +0300155/*
156 * deinstantiate_rng - builds and executes a descriptor on DECO0,
157 * which deinitializes the RNG block.
158 * @ctrldev - pointer to device
159 *
160 * Return: - 0 if no error occurred
161 * - -ENOMEM if there isn't enough memory to allocate the descriptor
162 * - -ENODEV if DECO0 couldn't be acquired
163 * - -EAGAIN if an error occurred when executing the descriptor
164 */
165static int deinstantiate_rng(struct device *ctrldev)
166{
167 u32 *desc;
168 int i, ret = 0;
169
170 desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
171 if (!desc)
172 return -ENOMEM;
173
174 /* Create the descriptor for deinstantating RNG State Handle 0 */
175 build_deinstantiation_desc(desc);
176
177 /* Try to run it through DECO0 */
178 ret = run_descriptor_deco0(ctrldev, desc);
179
180 if (ret)
181 dev_err(ctrldev, "failed to deinstantiate RNG\n");
182
183 kfree(desc);
184
185 return ret;
186}
187
Alex Porosanu04cddbf2013-09-09 18:56:31 +0300188static int caam_remove(struct platform_device *pdev)
189{
190 struct device *ctrldev;
191 struct caam_drv_private *ctrlpriv;
192 struct caam_drv_private_jr *jrpriv;
193 struct caam_full __iomem *topregs;
194 int ring, ret = 0;
195
196 ctrldev = &pdev->dev;
197 ctrlpriv = dev_get_drvdata(ctrldev);
198 topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
199
200 /* shut down JobRs */
201 for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) {
202 ret |= caam_jr_shutdown(ctrlpriv->jrdev[ring]);
203 jrpriv = dev_get_drvdata(ctrlpriv->jrdev[ring]);
204 irq_dispose_mapping(jrpriv->irq);
205 }
206
Alex Porosanub1f996e02013-09-09 18:56:32 +0300207 /* De-initialize RNG if it was initialized by this driver. */
208 if (ctrlpriv->rng4_init)
209 deinstantiate_rng(ctrldev);
210
Alex Porosanu04cddbf2013-09-09 18:56:31 +0300211 /* Shut down debug views */
212#ifdef CONFIG_DEBUG_FS
213 debugfs_remove_recursive(ctrlpriv->dfs_root);
214#endif
215
216 /* Unmap controller region */
217 iounmap(&topregs->ctrl);
218
219 kfree(ctrlpriv->jrdev);
220 kfree(ctrlpriv);
221
Kim Phillips281922a2012-06-22 19:48:52 -0500222 return ret;
223}
224
225/*
Alex Porosanu84cf4822013-09-09 18:56:30 +0300226 * kick_trng - sets the various parameters for enabling the initialization
227 * of the RNG4 block in CAAM
228 * @pdev - pointer to the platform device
229 * @ent_delay - Defines the length (in system clocks) of each entropy sample.
Kim Phillips281922a2012-06-22 19:48:52 -0500230 */
Alex Porosanu84cf4822013-09-09 18:56:30 +0300231static void kick_trng(struct platform_device *pdev, int ent_delay)
Kim Phillips281922a2012-06-22 19:48:52 -0500232{
233 struct device *ctrldev = &pdev->dev;
234 struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
235 struct caam_full __iomem *topregs;
236 struct rng4tst __iomem *r4tst;
237 u32 val;
238
239 topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
240 r4tst = &topregs->ctrl.r4tst[0];
241
242 /* put RNG4 into program mode */
243 setbits32(&r4tst->rtmctl, RTMCTL_PRGM);
Alex Porosanu84cf4822013-09-09 18:56:30 +0300244
245 /*
246 * Performance-wise, it does not make sense to
247 * set the delay to a value that is lower
248 * than the last one that worked (i.e. the state handles
249 * were instantiated properly. Thus, instead of wasting
250 * time trying to set the values controlling the sample
251 * frequency, the function simply returns.
252 */
253 val = (rd_reg32(&r4tst->rtsdctl) & RTSDCTL_ENT_DLY_MASK)
254 >> RTSDCTL_ENT_DLY_SHIFT;
255 if (ent_delay <= val) {
256 /* put RNG4 into run mode */
257 clrbits32(&r4tst->rtmctl, RTMCTL_PRGM);
258 return;
259 }
260
Kim Phillips281922a2012-06-22 19:48:52 -0500261 val = rd_reg32(&r4tst->rtsdctl);
Alex Porosanu84cf4822013-09-09 18:56:30 +0300262 val = (val & ~RTSDCTL_ENT_DLY_MASK) |
263 (ent_delay << RTSDCTL_ENT_DLY_SHIFT);
Kim Phillips281922a2012-06-22 19:48:52 -0500264 wr_reg32(&r4tst->rtsdctl, val);
Alex Porosanu84cf4822013-09-09 18:56:30 +0300265 /* min. freq. count, equal to 1/4 of the entropy sample length */
266 wr_reg32(&r4tst->rtfrqmin, ent_delay >> 2);
267 /* max. freq. count, equal to 8 times the entropy sample length */
268 wr_reg32(&r4tst->rtfrqmax, ent_delay << 3);
Kim Phillips281922a2012-06-22 19:48:52 -0500269 /* put RNG4 into run mode */
270 clrbits32(&r4tst->rtmctl, RTMCTL_PRGM);
271}
272
Alex Porosanu82c2f962012-07-11 11:06:11 +0800273/**
274 * caam_get_era() - Return the ERA of the SEC on SoC, based
275 * on the SEC_VID register.
276 * Returns the ERA number (1..4) or -ENOTSUPP if the ERA is unknown.
277 * @caam_id - the value of the SEC_VID register
278 **/
279int caam_get_era(u64 caam_id)
280{
281 struct sec_vid *sec_vid = (struct sec_vid *)&caam_id;
282 static const struct {
283 u16 ip_id;
284 u8 maj_rev;
285 u8 era;
286 } caam_eras[] = {
287 {0x0A10, 1, 1},
288 {0x0A10, 2, 2},
289 {0x0A12, 1, 3},
290 {0x0A14, 1, 3},
291 {0x0A14, 2, 4},
292 {0x0A16, 1, 4},
293 {0x0A11, 1, 4}
294 };
295 int i;
296
297 for (i = 0; i < ARRAY_SIZE(caam_eras); i++)
298 if (caam_eras[i].ip_id == sec_vid->ip_id &&
299 caam_eras[i].maj_rev == sec_vid->maj_rev)
300 return caam_eras[i].era;
301
302 return -ENOTSUPP;
303}
304EXPORT_SYMBOL(caam_get_era);
305
Kim Phillips8e8ec592011-03-13 16:54:26 +0800306/* Probe routine for CAAM top (controller) level */
Kim Phillips2930d492011-05-14 22:07:55 -0500307static int caam_probe(struct platform_device *pdev)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800308{
Alex Porosanu84cf4822013-09-09 18:56:30 +0300309 int ret, ring, rspec, ent_delay = RTSDCTL_ENT_DLY_MIN;
Alex Porosanu82c2f962012-07-11 11:06:11 +0800310 u64 caam_id;
Kim Phillips8e8ec592011-03-13 16:54:26 +0800311 struct device *dev;
312 struct device_node *nprop, *np;
313 struct caam_ctrl __iomem *ctrl;
314 struct caam_full __iomem *topregs;
315 struct caam_drv_private *ctrlpriv;
Kim Phillips23457bc2011-06-05 16:42:54 -0500316#ifdef CONFIG_DEBUG_FS
317 struct caam_perfmon *perfmon;
318#endif
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530319 u64 cha_vid;
Kim Phillips8e8ec592011-03-13 16:54:26 +0800320
321 ctrlpriv = kzalloc(sizeof(struct caam_drv_private), GFP_KERNEL);
322 if (!ctrlpriv)
323 return -ENOMEM;
324
325 dev = &pdev->dev;
326 dev_set_drvdata(dev, ctrlpriv);
327 ctrlpriv->pdev = pdev;
328 nprop = pdev->dev.of_node;
329
330 /* Get configuration properties from device tree */
331 /* First, get register page */
332 ctrl = of_iomap(nprop, 0);
333 if (ctrl == NULL) {
334 dev_err(dev, "caam: of_iomap() failed\n");
335 return -ENOMEM;
336 }
337 ctrlpriv->ctrl = (struct caam_ctrl __force *)ctrl;
338
339 /* topregs used to derive pointers to CAAM sub-blocks only */
340 topregs = (struct caam_full __iomem *)ctrl;
341
342 /* Get the IRQ of the controller (for security violations only) */
343 ctrlpriv->secvio_irq = of_irq_to_resource(nprop, 0, NULL);
344
345 /*
346 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
Kim Phillipse13af182012-06-22 19:48:51 -0500347 * long pointers in master configuration register
Kim Phillips8e8ec592011-03-13 16:54:26 +0800348 */
349 setbits32(&topregs->ctrl.mcr, MCFGR_WDENABLE |
350 (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0));
351
352 if (sizeof(dma_addr_t) == sizeof(u64))
Kim Phillipse13af182012-06-22 19:48:51 -0500353 if (of_device_is_compatible(nprop, "fsl,sec-v5.0"))
354 dma_set_mask(dev, DMA_BIT_MASK(40));
355 else
356 dma_set_mask(dev, DMA_BIT_MASK(36));
357 else
358 dma_set_mask(dev, DMA_BIT_MASK(32));
Kim Phillips8e8ec592011-03-13 16:54:26 +0800359
Kim Phillips8e8ec592011-03-13 16:54:26 +0800360 /*
361 * Detect and enable JobRs
362 * First, find out how many ring spec'ed, allocate references
363 * for all, then go probe each one.
364 */
365 rspec = 0;
Kim Phillips54e198d2011-03-23 21:15:44 +0800366 for_each_compatible_node(np, NULL, "fsl,sec-v4.0-job-ring")
Kim Phillips8e8ec592011-03-13 16:54:26 +0800367 rspec++;
Shengzhou Liua0ea0f62012-03-21 14:09:10 +0800368 if (!rspec) {
369 /* for backward compatible with device trees */
370 for_each_compatible_node(np, NULL, "fsl,sec4.0-job-ring")
371 rspec++;
372 }
373
Kim Phillips8e8ec592011-03-13 16:54:26 +0800374 ctrlpriv->jrdev = kzalloc(sizeof(struct device *) * rspec, GFP_KERNEL);
375 if (ctrlpriv->jrdev == NULL) {
376 iounmap(&topregs->ctrl);
377 return -ENOMEM;
378 }
379
380 ring = 0;
381 ctrlpriv->total_jobrs = 0;
Kim Phillips54e198d2011-03-23 21:15:44 +0800382 for_each_compatible_node(np, NULL, "fsl,sec-v4.0-job-ring") {
Kim Phillips8e8ec592011-03-13 16:54:26 +0800383 caam_jr_probe(pdev, np, ring);
384 ctrlpriv->total_jobrs++;
385 ring++;
386 }
Shengzhou Liua0ea0f62012-03-21 14:09:10 +0800387 if (!ring) {
388 for_each_compatible_node(np, NULL, "fsl,sec4.0-job-ring") {
389 caam_jr_probe(pdev, np, ring);
390 ctrlpriv->total_jobrs++;
391 ring++;
392 }
393 }
Kim Phillips8e8ec592011-03-13 16:54:26 +0800394
395 /* Check to see if QI present. If so, enable */
396 ctrlpriv->qi_present = !!(rd_reg64(&topregs->ctrl.perfmon.comp_parms) &
397 CTPR_QI_MASK);
398 if (ctrlpriv->qi_present) {
399 ctrlpriv->qi = (struct caam_queue_if __force *)&topregs->qi;
400 /* This is all that's required to physically enable QI */
401 wr_reg32(&topregs->qi.qi_control_lo, QICTL_DQEN);
402 }
403
404 /* If no QI and no rings specified, quit and go home */
405 if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
406 dev_err(dev, "no queues configured, terminating\n");
407 caam_remove(pdev);
408 return -ENOMEM;
409 }
410
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530411 cha_vid = rd_reg64(&topregs->ctrl.perfmon.cha_id);
412
Kim Phillips281922a2012-06-22 19:48:52 -0500413 /*
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530414 * If SEC has RNG version >= 4 and RNG state handle has not been
Alex Porosanu84cf4822013-09-09 18:56:30 +0300415 * already instantiated, do RNG instantiation
Kim Phillips281922a2012-06-22 19:48:52 -0500416 */
Ruchika Gupta986dfbc2013-04-26 15:44:54 +0530417 if ((cha_vid & CHA_ID_RNG_MASK) >> CHA_ID_RNG_SHIFT >= 4 &&
418 !(rd_reg32(&topregs->ctrl.r4tst[0].rdsta) & RDSTA_IF0)) {
Alex Porosanu84cf4822013-09-09 18:56:30 +0300419 do {
420 kick_trng(pdev, ent_delay);
421 ret = instantiate_rng(dev);
422 ent_delay += 400;
Alex Porosanu04cddbf2013-09-09 18:56:31 +0300423 } while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
Kim Phillips281922a2012-06-22 19:48:52 -0500424 if (ret) {
Alex Porosanu84cf4822013-09-09 18:56:30 +0300425 dev_err(dev, "failed to instantiate RNG");
Kim Phillips281922a2012-06-22 19:48:52 -0500426 caam_remove(pdev);
427 return ret;
428 }
Vakul Garg575c1bd2013-03-12 13:55:21 +0530429
Alex Porosanub1f996e02013-09-09 18:56:32 +0300430 ctrlpriv->rng4_init = 1;
431
Vakul Garg575c1bd2013-03-12 13:55:21 +0530432 /* Enable RDB bit so that RNG works faster */
433 setbits32(&topregs->ctrl.scfgr, SCFGR_RDBENABLE);
Kim Phillips281922a2012-06-22 19:48:52 -0500434 }
435
Kim Phillips8e8ec592011-03-13 16:54:26 +0800436 /* NOTE: RTIC detection ought to go here, around Si time */
437
Alex Porosanu82c2f962012-07-11 11:06:11 +0800438 caam_id = rd_reg64(&topregs->ctrl.perfmon.caam_id);
439
Kim Phillips8e8ec592011-03-13 16:54:26 +0800440 /* Report "alive" for developer to see */
Alex Porosanu82c2f962012-07-11 11:06:11 +0800441 dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
442 caam_get_era(caam_id));
Kim Phillips8e8ec592011-03-13 16:54:26 +0800443 dev_info(dev, "job rings = %d, qi = %d\n",
444 ctrlpriv->total_jobrs, ctrlpriv->qi_present);
445
446#ifdef CONFIG_DEBUG_FS
447 /*
448 * FIXME: needs better naming distinction, as some amalgamation of
449 * "caam" and nprop->full_name. The OF name isn't distinctive,
450 * but does separate instances
451 */
452 perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
453
454 ctrlpriv->dfs_root = debugfs_create_dir("caam", NULL);
455 ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);
456
457 /* Controller-level - performance monitor counters */
458 ctrlpriv->ctl_rq_dequeued =
459 debugfs_create_u64("rq_dequeued",
Al Viroeda65cc2011-07-24 04:32:53 -0400460 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800461 ctrlpriv->ctl, &perfmon->req_dequeued);
462 ctrlpriv->ctl_ob_enc_req =
463 debugfs_create_u64("ob_rq_encrypted",
Al Viroeda65cc2011-07-24 04:32:53 -0400464 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800465 ctrlpriv->ctl, &perfmon->ob_enc_req);
466 ctrlpriv->ctl_ib_dec_req =
467 debugfs_create_u64("ib_rq_decrypted",
Al Viroeda65cc2011-07-24 04:32:53 -0400468 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800469 ctrlpriv->ctl, &perfmon->ib_dec_req);
470 ctrlpriv->ctl_ob_enc_bytes =
471 debugfs_create_u64("ob_bytes_encrypted",
Al Viroeda65cc2011-07-24 04:32:53 -0400472 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800473 ctrlpriv->ctl, &perfmon->ob_enc_bytes);
474 ctrlpriv->ctl_ob_prot_bytes =
475 debugfs_create_u64("ob_bytes_protected",
Al Viroeda65cc2011-07-24 04:32:53 -0400476 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800477 ctrlpriv->ctl, &perfmon->ob_prot_bytes);
478 ctrlpriv->ctl_ib_dec_bytes =
479 debugfs_create_u64("ib_bytes_decrypted",
Al Viroeda65cc2011-07-24 04:32:53 -0400480 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800481 ctrlpriv->ctl, &perfmon->ib_dec_bytes);
482 ctrlpriv->ctl_ib_valid_bytes =
483 debugfs_create_u64("ib_bytes_validated",
Al Viroeda65cc2011-07-24 04:32:53 -0400484 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800485 ctrlpriv->ctl, &perfmon->ib_valid_bytes);
486
487 /* Controller level - global status values */
488 ctrlpriv->ctl_faultaddr =
489 debugfs_create_u64("fault_addr",
Al Viroeda65cc2011-07-24 04:32:53 -0400490 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800491 ctrlpriv->ctl, &perfmon->faultaddr);
492 ctrlpriv->ctl_faultdetail =
493 debugfs_create_u32("fault_detail",
Al Viroeda65cc2011-07-24 04:32:53 -0400494 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800495 ctrlpriv->ctl, &perfmon->faultdetail);
496 ctrlpriv->ctl_faultstatus =
497 debugfs_create_u32("fault_status",
Al Viroeda65cc2011-07-24 04:32:53 -0400498 S_IRUSR | S_IRGRP | S_IROTH,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800499 ctrlpriv->ctl, &perfmon->status);
500
501 /* Internal covering keys (useful in non-secure mode only) */
502 ctrlpriv->ctl_kek_wrap.data = &ctrlpriv->ctrl->kek[0];
503 ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
504 ctrlpriv->ctl_kek = debugfs_create_blob("kek",
Al Viroeda65cc2011-07-24 04:32:53 -0400505 S_IRUSR |
Kim Phillips8e8ec592011-03-13 16:54:26 +0800506 S_IRGRP | S_IROTH,
507 ctrlpriv->ctl,
508 &ctrlpriv->ctl_kek_wrap);
509
510 ctrlpriv->ctl_tkek_wrap.data = &ctrlpriv->ctrl->tkek[0];
511 ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
512 ctrlpriv->ctl_tkek = debugfs_create_blob("tkek",
Al Viroeda65cc2011-07-24 04:32:53 -0400513 S_IRUSR |
Kim Phillips8e8ec592011-03-13 16:54:26 +0800514 S_IRGRP | S_IROTH,
515 ctrlpriv->ctl,
516 &ctrlpriv->ctl_tkek_wrap);
517
518 ctrlpriv->ctl_tdsk_wrap.data = &ctrlpriv->ctrl->tdsk[0];
519 ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
520 ctrlpriv->ctl_tdsk = debugfs_create_blob("tdsk",
Al Viroeda65cc2011-07-24 04:32:53 -0400521 S_IRUSR |
Kim Phillips8e8ec592011-03-13 16:54:26 +0800522 S_IRGRP | S_IROTH,
523 ctrlpriv->ctl,
524 &ctrlpriv->ctl_tdsk_wrap);
525#endif
526 return 0;
527}
528
529static struct of_device_id caam_match[] = {
530 {
Kim Phillips54e198d2011-03-23 21:15:44 +0800531 .compatible = "fsl,sec-v4.0",
Kim Phillips8e8ec592011-03-13 16:54:26 +0800532 },
Shengzhou Liua0ea0f62012-03-21 14:09:10 +0800533 {
534 .compatible = "fsl,sec4.0",
535 },
Kim Phillips8e8ec592011-03-13 16:54:26 +0800536 {},
537};
538MODULE_DEVICE_TABLE(of, caam_match);
539
Kim Phillips2930d492011-05-14 22:07:55 -0500540static struct platform_driver caam_driver = {
Kim Phillips8e8ec592011-03-13 16:54:26 +0800541 .driver = {
542 .name = "caam",
543 .owner = THIS_MODULE,
544 .of_match_table = caam_match,
545 },
546 .probe = caam_probe,
Greg Kroah-Hartman49cfe4d2012-12-21 13:14:09 -0800547 .remove = caam_remove,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800548};
549
Axel Lin741e8c22011-11-26 21:26:19 +0800550module_platform_driver(caam_driver);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800551
552MODULE_LICENSE("GPL");
553MODULE_DESCRIPTION("FSL CAAM request backend");
554MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");