caamrng.c (2a267e7c41aa88215de2b542de797d03d16ecdfd) | caamrng.c (1b46c90c8e002028dc622bf7bd8cf89efcaab274) |
---|---|
1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * caam - Freescale FSL CAAM support for hw_random 4 * 5 * Copyright 2011 Freescale Semiconductor, Inc. | 1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * caam - Freescale FSL CAAM support for hw_random 4 * 5 * Copyright 2011 Freescale Semiconductor, Inc. |
6 * Copyright 2018 NXP | 6 * Copyright 2018-2019 NXP |
7 * 8 * Based on caamalg.c crypto API driver. 9 * 10 * relationship between job descriptors to shared descriptors: 11 * 12 * --------------- -------------- 13 * | JobDesc #0 |-------------------->| ShareDesc | 14 * | *(buffer 0) | |------------->| (generate) | --- 276 unchanged lines hidden (view full) --- 291} 292 293static struct hwrng caam_rng = { 294 .name = "rng-caam", 295 .cleanup = caam_cleanup, 296 .read = caam_read, 297}; 298 | 7 * 8 * Based on caamalg.c crypto API driver. 9 * 10 * relationship between job descriptors to shared descriptors: 11 * 12 * --------------- -------------- 13 * | JobDesc #0 |-------------------->| ShareDesc | 14 * | *(buffer 0) | |------------->| (generate) | --- 276 unchanged lines hidden (view full) --- 291} 292 293static struct hwrng caam_rng = { 294 .name = "rng-caam", 295 .cleanup = caam_cleanup, 296 .read = caam_read, 297}; 298 |
299static void __exit caam_rng_exit(void) | 299void caam_rng_exit(void) |
300{ 301 caam_jr_free(rng_ctx->jrdev); 302 hwrng_unregister(&caam_rng); 303 kfree(rng_ctx); 304} 305 | 300{ 301 caam_jr_free(rng_ctx->jrdev); 302 hwrng_unregister(&caam_rng); 303 kfree(rng_ctx); 304} 305 |
306static int __init caam_rng_init(void) | 306int caam_rng_init(struct device *ctrldev) |
307{ 308 struct device *dev; | 307{ 308 struct device *dev; |
309 struct device_node *dev_node; 310 struct platform_device *pdev; 311 struct caam_drv_private *priv; | |
312 u32 rng_inst; | 309 u32 rng_inst; |
310 struct caam_drv_private *priv = dev_get_drvdata(ctrldev); |
|
313 int err; 314 | 311 int err; 312 |
315 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); 316 if (!dev_node) { 317 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0"); 318 if (!dev_node) 319 return -ENODEV; 320 } 321 322 pdev = of_find_device_by_node(dev_node); 323 if (!pdev) { 324 of_node_put(dev_node); 325 return -ENODEV; 326 } 327 328 priv = dev_get_drvdata(&pdev->dev); 329 of_node_put(dev_node); 330 331 /* 332 * If priv is NULL, it's probably because the caam driver wasn't 333 * properly initialized (e.g. RNG4 init failed). Thus, bail out here. 334 */ 335 if (!priv) { 336 err = -ENODEV; 337 goto out_put_dev; 338 } 339 | |
340 /* Check for an instantiated RNG before registration */ 341 if (priv->era < 10) 342 rng_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & 343 CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT; 344 else 345 rng_inst = rd_reg32(&priv->ctrl->vreg.rng) & CHA_VER_NUM_MASK; 346 | 313 /* Check for an instantiated RNG before registration */ 314 if (priv->era < 10) 315 rng_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & 316 CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT; 317 else 318 rng_inst = rd_reg32(&priv->ctrl->vreg.rng) & CHA_VER_NUM_MASK; 319 |
347 if (!rng_inst) { 348 err = -ENODEV; 349 goto out_put_dev; 350 } | 320 if (!rng_inst) 321 return 0; |
351 352 dev = caam_jr_alloc(); 353 if (IS_ERR(dev)) { 354 pr_err("Job Ring Device allocation for transform failed\n"); | 322 323 dev = caam_jr_alloc(); 324 if (IS_ERR(dev)) { 325 pr_err("Job Ring Device allocation for transform failed\n"); |
355 err = PTR_ERR(dev); 356 goto out_put_dev; | 326 return PTR_ERR(dev); |
357 } 358 rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA | GFP_KERNEL); 359 if (!rng_ctx) { 360 err = -ENOMEM; 361 goto free_caam_alloc; 362 } 363 err = caam_init_rng(rng_ctx, dev); 364 if (err) 365 goto free_rng_ctx; 366 | 327 } 328 rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA | GFP_KERNEL); 329 if (!rng_ctx) { 330 err = -ENOMEM; 331 goto free_caam_alloc; 332 } 333 err = caam_init_rng(rng_ctx, dev); 334 if (err) 335 goto free_rng_ctx; 336 |
367 put_device(&pdev->dev); | |
368 dev_info(dev, "registering rng-caam\n"); 369 return hwrng_register(&caam_rng); 370 371free_rng_ctx: 372 kfree(rng_ctx); 373free_caam_alloc: 374 caam_jr_free(dev); | 337 dev_info(dev, "registering rng-caam\n"); 338 return hwrng_register(&caam_rng); 339 340free_rng_ctx: 341 kfree(rng_ctx); 342free_caam_alloc: 343 caam_jr_free(dev); |
375out_put_dev: 376 put_device(&pdev->dev); | |
377 return err; 378} | 344 return err; 345} |
379 380module_init(caam_rng_init); 381module_exit(caam_rng_exit); 382 383MODULE_LICENSE("GPL"); 384MODULE_DESCRIPTION("FSL CAAM support for hw_random API"); 385MODULE_AUTHOR("Freescale Semiconductor - NMG"); | |