ctrl.c 20.0 KB
Newer Older
1 2 3 4
/*
 * CAAM control-plane driver backend
 * Controller-level driver, kernel property detection, initialization
 *
5
 * Copyright 2008-2012 Freescale Semiconductor, Inc.
6 7
 */

8
#include <linux/device.h>
9 10 11
#include <linux/of_address.h>
#include <linux/of_irq.h>

12 13 14 15
#include "compat.h"
#include "regs.h"
#include "intern.h"
#include "jr.h"
16 17
#include "desc_constr.h"
#include "error.h"
18

19 20 21 22
/*
 * Descriptor to instantiate RNG State Handle 0 in normal mode and
 * load the JDKEK, TDKEK and TDSK registers
 */
23
static void build_instantiation_desc(u32 *desc, int handle, int do_sk)
24
{
25
	u32 *jump_cmd, op_flags;
26 27 28

	init_job_desc(desc, 0);

29 30 31
	op_flags = OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
			(handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT;

32
	/* INIT RNG in non-test mode */
33
	append_operation(desc, op_flags);
34

35 36 37 38
	if (!handle && do_sk) {
		/*
		 * For SH0, Secure Keys must be generated as well
		 */
39

40 41 42
		/* wait for done */
		jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
		set_jump_tgt_here(desc, jump_cmd);
43

44 45 46 47 48 49 50 51 52 53
		/*
		 * load 1 to clear written reg:
		 * resets the done interrrupt and returns the RNG to idle.
		 */
		append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);

		/* Initialize State Handle  */
		append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
				 OP_ALG_AAI_RNG4_SK);
	}
54

55
	append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
56 57
}

58
/* Descriptor for deinstantiation of State Handle 0 of the RNG block. */
59
static void build_deinstantiation_desc(u32 *desc, int handle)
60 61
{
	init_job_desc(desc, 0);
62

63
	/* Uninstantiate State Handle 0 */
64
	append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
65
			 (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INITFINAL);
66 67

	append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
68 69
}

70 71 72 73
/*
 * run_descriptor_deco0 - runs a descriptor on DECO0, under direct control of
 *			  the software (no JR/QI used).
 * @ctrldev - pointer to device
74 75
 * @status - descriptor status, after being run
 *
76 77 78 79
 * Return: - 0 if no error occurred
 *	   - -ENODEV if the DECO couldn't be acquired
 *	   - -EAGAIN if an error occurred while executing the descriptor
 */
80 81
static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
					u32 *status)
82
{
83 84 85
	struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
	struct caam_full __iomem *topregs;
	unsigned int timeout = 100000;
86
	u32 deco_dbg_reg, flags;
87
	int i;
88 89 90

	/* Set the bit to request direct access to DECO0 */
	topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
91 92 93 94 95 96 97 98

	if (ctrlpriv->virt_en == 1)
		setbits32(&topregs->ctrl.deco_rsr, DECORSR_JR0);

	while (!(rd_reg32(&topregs->ctrl.deco_rsr) & DECORSR_VALID) &&
	       --timeout)
		cpu_relax();

99 100 101 102 103 104 105 106
	setbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);

	while (!(rd_reg32(&topregs->ctrl.deco_rq) & DECORR_DEN0) &&
								 --timeout)
		cpu_relax();

	if (!timeout) {
		dev_err(ctrldev, "failed to acquire DECO 0\n");
107 108
		clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
		return -ENODEV;
109 110
	}

111
	for (i = 0; i < desc_len(desc); i++)
112
		wr_reg32(&topregs->deco.descbuf[i], *(desc + i));
113

114 115 116 117 118 119 120 121 122 123
	flags = DECO_JQCR_WHL;
	/*
	 * If the descriptor length is longer than 4 words, then the
	 * FOUR bit in JRCTRL register must be set.
	 */
	if (desc_len(desc) >= 4)
		flags |= DECO_JQCR_FOUR;

	/* Instruct the DECO to execute it */
	wr_reg32(&topregs->deco.jr_ctl_hi, flags);
124 125

	timeout = 10000000;
126 127 128 129 130 131 132 133 134
	do {
		deco_dbg_reg = rd_reg32(&topregs->deco.desc_dbg);
		/*
		 * If an error occured in the descriptor, then
		 * the DECO status field will be set to 0x0D
		 */
		if ((deco_dbg_reg & DESC_DBG_DECO_STAT_MASK) ==
		    DESC_DBG_DECO_STAT_HOST_ERR)
			break;
135
		cpu_relax();
136
	} while ((deco_dbg_reg & DESC_DBG_DECO_STAT_VALID) && --timeout);
137

138 139
	*status = rd_reg32(&topregs->deco.op_status_hi) &
		  DECO_OP_STATUS_HI_ERR_MASK;
140

141 142 143
	if (ctrlpriv->virt_en == 1)
		clrbits32(&topregs->ctrl.deco_rsr, DECORSR_JR0);

144
	/* Mark the DECO as free */
145
	clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
146 147 148 149 150 151 152 153 154 155 156

	if (!timeout)
		return -EAGAIN;

	return 0;
}

/*
 * instantiate_rng - builds and executes a descriptor on DECO0,
 *		     which initializes the RNG block.
 * @ctrldev - pointer to device
157 158 159 160 161 162 163 164
 * @state_handle_mask - bitmask containing the instantiation status
 *			for the RNG4 state handles which exist in
 *			the RNG4 block: 1 if it's been instantiated
 *			by an external entry, 0 otherwise.
 * @gen_sk  - generate data to be loaded into the JDKEK, TDKEK and TDSK;
 *	      Caution: this can be done only once; if the keys need to be
 *	      regenerated, a POR is required
 *
165 166 167 168 169 170 171
 * Return: - 0 if no error occurred
 *	   - -ENOMEM if there isn't enough memory to allocate the descriptor
 *	   - -ENODEV if DECO0 couldn't be acquired
 *	   - -EAGAIN if an error occurred when executing the descriptor
 *	      f.i. there was a RNG hardware error due to not "good enough"
 *	      entropy being aquired.
 */
172 173
static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
			   int gen_sk)
174
{
175 176 177 178 179 180 181 182
	struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
	struct caam_full __iomem *topregs;
	struct rng4tst __iomem *r4tst;
	u32 *desc, status, rdsta_val;
	int ret = 0, sh_idx;

	topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
	r4tst = &topregs->ctrl.r4tst[0];
183 184 185 186 187

	desc = kmalloc(CAAM_CMD_SZ * 7, GFP_KERNEL);
	if (!desc)
		return -ENOMEM;

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
		/*
		 * If the corresponding bit is set, this state handle
		 * was initialized by somebody else, so it's left alone.
		 */
		if ((1 << sh_idx) & state_handle_mask)
			continue;

		/* Create the descriptor for instantiating RNG State Handle */
		build_instantiation_desc(desc, sh_idx, gen_sk);

		/* Try to run it through DECO0 */
		ret = run_descriptor_deco0(ctrldev, desc, &status);

		/*
		 * If ret is not 0, or descriptor status is not 0, then
		 * something went wrong. No need to try the next state
		 * handle (if available), bail out here.
		 * Also, if for some reason, the State Handle didn't get
		 * instantiated although the descriptor has finished
		 * without any error (HW optimizations for later
		 * CAAM eras), then try again.
		 */
		rdsta_val =
			rd_reg32(&topregs->ctrl.r4tst[0].rdsta) & RDSTA_IFMASK;
		if (status || !(rdsta_val & (1 << sh_idx)))
			ret = -EAGAIN;
		if (ret)
			break;

		dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx);
		/* Clear the contents before recreating the descriptor */
		memset(desc, 0x00, CAAM_CMD_SZ * 7);
	}
222

223
	kfree(desc);
224

225 226 227 228
	return ret;
}

/*
229 230 231
 * deinstantiate_rng - builds and executes a descriptor on DECO0,
 *		       which deinitializes the RNG block.
 * @ctrldev - pointer to device
232 233 234
 * @state_handle_mask - bitmask containing the instantiation status
 *			for the RNG4 state handles which exist in
 *			the RNG4 block: 1 if it's been instantiated
235 236 237 238 239
 *
 * Return: - 0 if no error occurred
 *	   - -ENOMEM if there isn't enough memory to allocate the descriptor
 *	   - -ENODEV if DECO0 couldn't be acquired
 *	   - -EAGAIN if an error occurred when executing the descriptor
240
 */
241
static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask)
242
{
243 244
	u32 *desc, status;
	int sh_idx, ret = 0;
245 246 247 248 249

	desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
	if (!desc)
		return -ENOMEM;

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
	for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) {
		/*
		 * If the corresponding bit is set, then it means the state
		 * handle was initialized by us, and thus it needs to be
		 * deintialized as well
		 */
		if ((1 << sh_idx) & state_handle_mask) {
			/*
			 * Create the descriptor for deinstantating this state
			 * handle
			 */
			build_deinstantiation_desc(desc, sh_idx);

			/* Try to run it through DECO0 */
			ret = run_descriptor_deco0(ctrldev, desc, &status);

			if (ret || status) {
				dev_err(ctrldev,
					"Failed to deinstantiate RNG4 SH%d\n",
					sh_idx);
				break;
			}
			dev_info(ctrldev, "Deinstantiated RNG4 SH%d\n", sh_idx);
		}
	}
275 276 277 278 279 280

	kfree(desc);

	return ret;
}

281 282 283 284 285 286 287 288 289 290 291
static int caam_remove(struct platform_device *pdev)
{
	struct device *ctrldev;
	struct caam_drv_private *ctrlpriv;
	struct caam_full __iomem *topregs;
	int ring, ret = 0;

	ctrldev = &pdev->dev;
	ctrlpriv = dev_get_drvdata(ctrldev);
	topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;

292
	/* Remove platform devices for JobRs */
293
	for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) {
294 295
		if (ctrlpriv->jrpdev[ring])
			of_device_unregister(ctrlpriv->jrpdev[ring]);
296 297
	}

298 299 300
	/* De-initialize RNG state handles initialized by this driver. */
	if (ctrlpriv->rng4_sh_init)
		deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init);
301

302 303 304 305 306 307 308 309
	/* Shut down debug views */
#ifdef CONFIG_DEBUG_FS
	debugfs_remove_recursive(ctrlpriv->dfs_root);
#endif

	/* Unmap controller region */
	iounmap(&topregs->ctrl);

310 311 312 313
	return ret;
}

/*
314 315 316 317
 * kick_trng - sets the various parameters for enabling the initialization
 *	       of the RNG4 block in CAAM
 * @pdev - pointer to the platform device
 * @ent_delay - Defines the length (in system clocks) of each entropy sample.
318
 */
319
static void kick_trng(struct platform_device *pdev, int ent_delay)
320 321 322 323 324 325 326 327 328 329 330 331
{
	struct device *ctrldev = &pdev->dev;
	struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
	struct caam_full __iomem *topregs;
	struct rng4tst __iomem *r4tst;
	u32 val;

	topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
	r4tst = &topregs->ctrl.r4tst[0];

	/* put RNG4 into program mode */
	setbits32(&r4tst->rtmctl, RTMCTL_PRGM);
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348

	/*
	 * Performance-wise, it does not make sense to
	 * set the delay to a value that is lower
	 * than the last one that worked (i.e. the state handles
	 * were instantiated properly. Thus, instead of wasting
	 * time trying to set the values controlling the sample
	 * frequency, the function simply returns.
	 */
	val = (rd_reg32(&r4tst->rtsdctl) & RTSDCTL_ENT_DLY_MASK)
	      >> RTSDCTL_ENT_DLY_SHIFT;
	if (ent_delay <= val) {
		/* put RNG4 into run mode */
		clrbits32(&r4tst->rtmctl, RTMCTL_PRGM);
		return;
	}

349
	val = rd_reg32(&r4tst->rtsdctl);
350 351
	val = (val & ~RTSDCTL_ENT_DLY_MASK) |
	      (ent_delay << RTSDCTL_ENT_DLY_SHIFT);
352
	wr_reg32(&r4tst->rtsdctl, val);
353 354 355 356
	/* min. freq. count, equal to 1/4 of the entropy sample length */
	wr_reg32(&r4tst->rtfrqmin, ent_delay >> 2);
	/* max. freq. count, equal to 8 times the entropy sample length */
	wr_reg32(&r4tst->rtfrqmax, ent_delay << 3);
357 358 359 360
	/* put RNG4 into run mode */
	clrbits32(&r4tst->rtmctl, RTMCTL_PRGM);
}

361 362
/**
 * caam_get_era() - Return the ERA of the SEC on SoC, based
363
 * on "sec-era" propery in the DTS. This property is updated by u-boot.
364
 **/
365
int caam_get_era(void)
366
{
367 368 369 370 371 372 373
	struct device_node *caam_node;
	for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") {
		const uint32_t *prop = (uint32_t *)of_get_property(caam_node,
				"fsl,sec-era",
				NULL);
		return prop ? *prop : -ENOTSUPP;
	}
374 375 376 377 378

	return -ENOTSUPP;
}
EXPORT_SYMBOL(caam_get_era);

379
/* Probe routine for CAAM top (controller) level */
380
static int caam_probe(struct platform_device *pdev)
381
{
382
	int ret, ring, rspec, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
383
	u64 caam_id;
384 385 386 387 388
	struct device *dev;
	struct device_node *nprop, *np;
	struct caam_ctrl __iomem *ctrl;
	struct caam_full __iomem *topregs;
	struct caam_drv_private *ctrlpriv;
389 390 391
#ifdef CONFIG_DEBUG_FS
	struct caam_perfmon *perfmon;
#endif
392
	u32 scfgr, comp_params;
393
	u32 cha_vid_ls;
394

395 396
	ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(struct caam_drv_private),
				GFP_KERNEL);
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
	if (!ctrlpriv)
		return -ENOMEM;

	dev = &pdev->dev;
	dev_set_drvdata(dev, ctrlpriv);
	ctrlpriv->pdev = pdev;
	nprop = pdev->dev.of_node;

	/* Get configuration properties from device tree */
	/* First, get register page */
	ctrl = of_iomap(nprop, 0);
	if (ctrl == NULL) {
		dev_err(dev, "caam: of_iomap() failed\n");
		return -ENOMEM;
	}
	ctrlpriv->ctrl = (struct caam_ctrl __force *)ctrl;

	/* topregs used to derive pointers to CAAM sub-blocks only */
	topregs = (struct caam_full __iomem *)ctrl;

	/* Get the IRQ of the controller (for security violations only) */
418
	ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0);
419 420 421

	/*
	 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
422
	 * long pointers in master configuration register
423 424 425 426
	 */
	setbits32(&topregs->ctrl.mcr, MCFGR_WDENABLE |
		  (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0));

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
	/*
	 *  Read the Compile Time paramters and SCFGR to determine
	 * if Virtualization is enabled for this platform
	 */
	comp_params = rd_reg32(&topregs->ctrl.perfmon.comp_parms_ms);
	scfgr = rd_reg32(&topregs->ctrl.scfgr);

	ctrlpriv->virt_en = 0;
	if (comp_params & CTPR_MS_VIRT_EN_INCL) {
		/* VIRT_EN_INCL = 1 & VIRT_EN_POR = 1 or
		 * VIRT_EN_INCL = 1 & VIRT_EN_POR = 0 & SCFGR_VIRT_EN = 1
		 */
		if ((comp_params & CTPR_MS_VIRT_EN_POR) ||
		    (!(comp_params & CTPR_MS_VIRT_EN_POR) &&
		       (scfgr & SCFGR_VIRT_EN)))
				ctrlpriv->virt_en = 1;
	} else {
		/* VIRT_EN_INCL = 0 && VIRT_EN_POR_VALUE = 1 */
		if (comp_params & CTPR_MS_VIRT_EN_POR)
				ctrlpriv->virt_en = 1;
	}

	if (ctrlpriv->virt_en == 1)
		setbits32(&topregs->ctrl.jrstart, JRSTART_JR0_START |
			  JRSTART_JR1_START | JRSTART_JR2_START |
			  JRSTART_JR3_START);

454
	if (sizeof(dma_addr_t) == sizeof(u64))
455 456 457 458 459 460
		if (of_device_is_compatible(nprop, "fsl,sec-v5.0"))
			dma_set_mask(dev, DMA_BIT_MASK(40));
		else
			dma_set_mask(dev, DMA_BIT_MASK(36));
	else
		dma_set_mask(dev, DMA_BIT_MASK(32));
461 462 463 464 465 466 467

	/*
	 * Detect and enable JobRs
	 * First, find out how many ring spec'ed, allocate references
	 * for all, then go probe each one.
	 */
	rspec = 0;
468 469 470
	for_each_available_child_of_node(nprop, np)
		if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
		    of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
471 472
			rspec++;

473 474 475
	ctrlpriv->jrpdev = devm_kzalloc(&pdev->dev,
					sizeof(struct platform_device *) * rspec,
					GFP_KERNEL);
476
	if (ctrlpriv->jrpdev == NULL) {
477 478 479 480 481 482
		iounmap(&topregs->ctrl);
		return -ENOMEM;
	}

	ring = 0;
	ctrlpriv->total_jobrs = 0;
483 484 485
	for_each_available_child_of_node(nprop, np)
		if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
		    of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
486 487 488 489 490 491 492
			ctrlpriv->jrpdev[ring] =
				of_platform_device_create(np, NULL, dev);
			if (!ctrlpriv->jrpdev[ring]) {
				pr_warn("JR%d Platform device creation error\n",
					ring);
				continue;
			}
493 494 495
			ctrlpriv->total_jobrs++;
			ring++;
		}
496 497

	/* Check to see if QI present. If so, enable */
498 499 500
	ctrlpriv->qi_present =
			!!(rd_reg32(&topregs->ctrl.perfmon.comp_parms_ms) &
			   CTPR_MS_QI_MASK);
501 502 503 504 505 506 507 508 509 510 511 512 513
	if (ctrlpriv->qi_present) {
		ctrlpriv->qi = (struct caam_queue_if __force *)&topregs->qi;
		/* This is all that's required to physically enable QI */
		wr_reg32(&topregs->qi.qi_control_lo, QICTL_DQEN);
	}

	/* If no QI and no rings specified, quit and go home */
	if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
		dev_err(dev, "no queues configured, terminating\n");
		caam_remove(pdev);
		return -ENOMEM;
	}

514
	cha_vid_ls = rd_reg32(&topregs->ctrl.perfmon.cha_id_ls);
515

516
	/*
517
	 * If SEC has RNG version >= 4 and RNG state handle has not been
518
	 * already instantiated, do RNG instantiation
519
	 */
520
	if ((cha_vid_ls & CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT >= 4) {
521 522 523 524 525 526 527 528 529 530
		ctrlpriv->rng4_sh_init =
			rd_reg32(&topregs->ctrl.r4tst[0].rdsta);
		/*
		 * If the secure keys (TDKEK, JDKEK, TDSK), were already
		 * generated, signal this to the function that is instantiating
		 * the state handles. An error would occur if RNG4 attempts
		 * to regenerate these keys before the next POR.
		 */
		gen_sk = ctrlpriv->rng4_sh_init & RDSTA_SKVN ? 0 : 1;
		ctrlpriv->rng4_sh_init &= RDSTA_IFMASK;
531
		do {
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
			int inst_handles =
				rd_reg32(&topregs->ctrl.r4tst[0].rdsta) &
								RDSTA_IFMASK;
			/*
			 * If either SH were instantiated by somebody else
			 * (e.g. u-boot) then it is assumed that the entropy
			 * parameters are properly set and thus the function
			 * setting these (kick_trng(...)) is skipped.
			 * Also, if a handle was instantiated, do not change
			 * the TRNG parameters.
			 */
			if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
				kick_trng(pdev, ent_delay);
				ent_delay += 400;
			}
			/*
			 * if instantiate_rng(...) fails, the loop will rerun
			 * and the kick_trng(...) function will modfiy the
			 * upper and lower limits of the entropy sampling
			 * interval, leading to a sucessful initialization of
			 * the RNG.
			 */
			ret = instantiate_rng(dev, inst_handles,
					      gen_sk);
556
		} while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
557
		if (ret) {
558
			dev_err(dev, "failed to instantiate RNG");
559 560 561
			caam_remove(pdev);
			return ret;
		}
562 563 564 565 566
		/*
		 * Set handles init'ed by this module as the complement of the
		 * already initialized ones
		 */
		ctrlpriv->rng4_sh_init = ~ctrlpriv->rng4_sh_init & RDSTA_IFMASK;
567 568 569

		/* Enable RDB bit so that RNG works faster */
		setbits32(&topregs->ctrl.scfgr, SCFGR_RDBENABLE);
570 571
	}

572 573
	/* NOTE: RTIC detection ought to go here, around Si time */

574 575
	caam_id = (u64)rd_reg32(&topregs->ctrl.perfmon.caam_id_ms) << 32 |
		  (u64)rd_reg32(&topregs->ctrl.perfmon.caam_id_ls);
576

577
	/* Report "alive" for developer to see */
578
	dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
579
		 caam_get_era());
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
	dev_info(dev, "job rings = %d, qi = %d\n",
		 ctrlpriv->total_jobrs, ctrlpriv->qi_present);

#ifdef CONFIG_DEBUG_FS
	/*
	 * FIXME: needs better naming distinction, as some amalgamation of
	 * "caam" and nprop->full_name. The OF name isn't distinctive,
	 * but does separate instances
	 */
	perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;

	ctrlpriv->dfs_root = debugfs_create_dir("caam", NULL);
	ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);

	/* Controller-level - performance monitor counters */
	ctrlpriv->ctl_rq_dequeued =
		debugfs_create_u64("rq_dequeued",
597
				   S_IRUSR | S_IRGRP | S_IROTH,
598 599 600
				   ctrlpriv->ctl, &perfmon->req_dequeued);
	ctrlpriv->ctl_ob_enc_req =
		debugfs_create_u64("ob_rq_encrypted",
601
				   S_IRUSR | S_IRGRP | S_IROTH,
602 603 604
				   ctrlpriv->ctl, &perfmon->ob_enc_req);
	ctrlpriv->ctl_ib_dec_req =
		debugfs_create_u64("ib_rq_decrypted",
605
				   S_IRUSR | S_IRGRP | S_IROTH,
606 607 608
				   ctrlpriv->ctl, &perfmon->ib_dec_req);
	ctrlpriv->ctl_ob_enc_bytes =
		debugfs_create_u64("ob_bytes_encrypted",
609
				   S_IRUSR | S_IRGRP | S_IROTH,
610 611 612
				   ctrlpriv->ctl, &perfmon->ob_enc_bytes);
	ctrlpriv->ctl_ob_prot_bytes =
		debugfs_create_u64("ob_bytes_protected",
613
				   S_IRUSR | S_IRGRP | S_IROTH,
614 615 616
				   ctrlpriv->ctl, &perfmon->ob_prot_bytes);
	ctrlpriv->ctl_ib_dec_bytes =
		debugfs_create_u64("ib_bytes_decrypted",
617
				   S_IRUSR | S_IRGRP | S_IROTH,
618 619 620
				   ctrlpriv->ctl, &perfmon->ib_dec_bytes);
	ctrlpriv->ctl_ib_valid_bytes =
		debugfs_create_u64("ib_bytes_validated",
621
				   S_IRUSR | S_IRGRP | S_IROTH,
622 623 624 625 626
				   ctrlpriv->ctl, &perfmon->ib_valid_bytes);

	/* Controller level - global status values */
	ctrlpriv->ctl_faultaddr =
		debugfs_create_u64("fault_addr",
627
				   S_IRUSR | S_IRGRP | S_IROTH,
628 629 630
				   ctrlpriv->ctl, &perfmon->faultaddr);
	ctrlpriv->ctl_faultdetail =
		debugfs_create_u32("fault_detail",
631
				   S_IRUSR | S_IRGRP | S_IROTH,
632 633 634
				   ctrlpriv->ctl, &perfmon->faultdetail);
	ctrlpriv->ctl_faultstatus =
		debugfs_create_u32("fault_status",
635
				   S_IRUSR | S_IRGRP | S_IROTH,
636 637 638 639 640 641
				   ctrlpriv->ctl, &perfmon->status);

	/* Internal covering keys (useful in non-secure mode only) */
	ctrlpriv->ctl_kek_wrap.data = &ctrlpriv->ctrl->kek[0];
	ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
	ctrlpriv->ctl_kek = debugfs_create_blob("kek",
642
						S_IRUSR |
643 644 645 646 647 648 649
						S_IRGRP | S_IROTH,
						ctrlpriv->ctl,
						&ctrlpriv->ctl_kek_wrap);

	ctrlpriv->ctl_tkek_wrap.data = &ctrlpriv->ctrl->tkek[0];
	ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
	ctrlpriv->ctl_tkek = debugfs_create_blob("tkek",
650
						 S_IRUSR |
651 652 653 654 655 656 657
						 S_IRGRP | S_IROTH,
						 ctrlpriv->ctl,
						 &ctrlpriv->ctl_tkek_wrap);

	ctrlpriv->ctl_tdsk_wrap.data = &ctrlpriv->ctrl->tdsk[0];
	ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
	ctrlpriv->ctl_tdsk = debugfs_create_blob("tdsk",
658
						 S_IRUSR |
659 660 661 662 663 664 665 666 667
						 S_IRGRP | S_IROTH,
						 ctrlpriv->ctl,
						 &ctrlpriv->ctl_tdsk_wrap);
#endif
	return 0;
}

static struct of_device_id caam_match[] = {
	{
668
		.compatible = "fsl,sec-v4.0",
669
	},
670 671 672
	{
		.compatible = "fsl,sec4.0",
	},
673 674 675 676
	{},
};
MODULE_DEVICE_TABLE(of, caam_match);

677
static struct platform_driver caam_driver = {
678 679 680 681 682 683
	.driver = {
		.name = "caam",
		.owner = THIS_MODULE,
		.of_match_table = caam_match,
	},
	.probe       = caam_probe,
684
	.remove      = caam_remove,
685 686
};

687
module_platform_driver(caam_driver);
688 689 690 691

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("FSL CAAM request backend");
MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");