treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / char / hw_random / pseries-rng.c
blob8038a8a9fb581a457dedcc48353b2a092e0b614e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2010 Michael Neuling IBM Corporation
5 * Driver for the pseries hardware RNG for POWER7+ and above
6 */
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/hw_random.h>
13 #include <asm/vio.h>
16 static int pseries_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
18 u64 buffer[PLPAR_HCALL_BUFSIZE];
19 int rc;
21 rc = plpar_hcall(H_RANDOM, (unsigned long *)buffer);
22 if (rc != H_SUCCESS) {
23 pr_err_ratelimited("H_RANDOM call failed %d\n", rc);
24 return -EIO;
26 memcpy(data, buffer, 8);
28 /* The hypervisor interface returns 64 bits */
29 return 8;
32 /**
33 * pseries_rng_get_desired_dma - Return desired DMA allocate for CMO operations
35 * This is a required function for a driver to operate in a CMO environment
36 * but this device does not make use of DMA allocations, return 0.
38 * Return value:
39 * Number of bytes of IO data the driver will need to perform well -> 0
41 static unsigned long pseries_rng_get_desired_dma(struct vio_dev *vdev)
43 return 0;
46 static struct hwrng pseries_rng = {
47 .name = KBUILD_MODNAME,
48 .read = pseries_rng_read,
51 static int pseries_rng_probe(struct vio_dev *dev,
52 const struct vio_device_id *id)
54 return hwrng_register(&pseries_rng);
57 static int pseries_rng_remove(struct vio_dev *dev)
59 hwrng_unregister(&pseries_rng);
60 return 0;
63 static const struct vio_device_id pseries_rng_driver_ids[] = {
64 { "ibm,random-v1", "ibm,random"},
65 { "", "" }
67 MODULE_DEVICE_TABLE(vio, pseries_rng_driver_ids);
69 static struct vio_driver pseries_rng_driver = {
70 .name = KBUILD_MODNAME,
71 .probe = pseries_rng_probe,
72 .remove = pseries_rng_remove,
73 .get_desired_dma = pseries_rng_get_desired_dma,
74 .id_table = pseries_rng_driver_ids
77 static int __init rng_init(void)
79 pr_info("Registering IBM pSeries RNG driver\n");
80 return vio_register_driver(&pseries_rng_driver);
83 module_init(rng_init);
85 static void __exit rng_exit(void)
87 vio_unregister_driver(&pseries_rng_driver);
89 module_exit(rng_exit);
91 MODULE_LICENSE("GPL");
92 MODULE_AUTHOR("Michael Neuling <mikey@neuling.org>");
93 MODULE_DESCRIPTION("H/W RNG driver for IBM pSeries processors");