treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / char / hw_random / cavium-rng.c
blob63d6e68c24d2fc979f54345c2f71ad2e58b36236
1 /*
2 * Hardware Random Number Generator support for Cavium Inc.
3 * Thunder processor family.
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
9 * Copyright (C) 2016 Cavium, Inc.
12 #include <linux/hw_random.h>
13 #include <linux/io.h>
14 #include <linux/module.h>
15 #include <linux/pci.h>
16 #include <linux/pci_ids.h>
18 #define THUNDERX_RNM_ENT_EN 0x1
19 #define THUNDERX_RNM_RNG_EN 0x2
21 struct cavium_rng_pf {
22 void __iomem *control_status;
25 /* Enable the RNG hardware and activate the VF */
26 static int cavium_rng_probe(struct pci_dev *pdev,
27 const struct pci_device_id *id)
29 struct cavium_rng_pf *rng;
30 int iov_err;
32 rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
33 if (!rng)
34 return -ENOMEM;
36 /*Map the RNG control */
37 rng->control_status = pcim_iomap(pdev, 0, 0);
38 if (!rng->control_status) {
39 dev_err(&pdev->dev,
40 "Error iomap failed retrieving control_status.\n");
41 return -ENOMEM;
44 /* Enable the RNG hardware and entropy source */
45 writeq(THUNDERX_RNM_RNG_EN | THUNDERX_RNM_ENT_EN,
46 rng->control_status);
48 pci_set_drvdata(pdev, rng);
50 /* Enable the Cavium RNG as a VF */
51 iov_err = pci_enable_sriov(pdev, 1);
52 if (iov_err != 0) {
53 /* Disable the RNG hardware and entropy source */
54 writeq(0, rng->control_status);
55 dev_err(&pdev->dev,
56 "Error initializing RNG virtual function,(%i).\n",
57 iov_err);
58 return iov_err;
61 return 0;
64 /* Disable VF and RNG Hardware */
65 static void cavium_rng_remove(struct pci_dev *pdev)
67 struct cavium_rng_pf *rng;
69 rng = pci_get_drvdata(pdev);
71 /* Remove the VF */
72 pci_disable_sriov(pdev);
74 /* Disable the RNG hardware and entropy source */
75 writeq(0, rng->control_status);
78 static const struct pci_device_id cavium_rng_pf_id_table[] = {
79 { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa018), 0, 0, 0}, /* Thunder RNM */
80 {0,},
83 MODULE_DEVICE_TABLE(pci, cavium_rng_pf_id_table);
85 static struct pci_driver cavium_rng_pf_driver = {
86 .name = "cavium_rng_pf",
87 .id_table = cavium_rng_pf_id_table,
88 .probe = cavium_rng_probe,
89 .remove = cavium_rng_remove,
92 module_pci_driver(cavium_rng_pf_driver);
93 MODULE_AUTHOR("Omer Khaliq <okhaliq@caviumnetworks.com>");
94 MODULE_LICENSE("GPL");