Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2/*
 3 * Hardware Random Number Generator support.
 4 * Cavium Thunder, Marvell OcteonTx/Tx2 processor families.
 
 
 
 
 5 *
 6 * Copyright (C) 2016 Cavium, Inc.
 7 */
 8
 9#include <linux/hw_random.h>
10#include <linux/io.h>
11#include <linux/module.h>
12#include <linux/pci.h>
13#include <linux/pci_ids.h>
14
15#define THUNDERX_RNM_ENT_EN     0x1
16#define THUNDERX_RNM_RNG_EN     0x2
17
18struct cavium_rng_pf {
19	void __iomem *control_status;
20};
21
22/* Enable the RNG hardware and activate the VF */
23static int cavium_rng_probe(struct pci_dev *pdev,
24			const struct pci_device_id *id)
25{
26	struct	cavium_rng_pf *rng;
27	int	iov_err;
28
29	rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
30	if (!rng)
31		return -ENOMEM;
32
33	/*Map the RNG control */
34	rng->control_status = pcim_iomap(pdev, 0, 0);
35	if (!rng->control_status) {
36		dev_err(&pdev->dev,
37			"Error iomap failed retrieving control_status.\n");
38		return -ENOMEM;
39	}
40
41	/* Enable the RNG hardware and entropy source */
42	writeq(THUNDERX_RNM_RNG_EN | THUNDERX_RNM_ENT_EN,
43		rng->control_status);
44
45	pci_set_drvdata(pdev, rng);
46
47	/* Enable the Cavium RNG as a VF */
48	iov_err = pci_enable_sriov(pdev, 1);
49	if (iov_err != 0) {
50		/* Disable the RNG hardware and entropy source */
51		writeq(0, rng->control_status);
52		dev_err(&pdev->dev,
53			"Error initializing RNG virtual function,(%i).\n",
54			iov_err);
55		return iov_err;
56	}
57
58	return 0;
59}
60
61/* Disable VF and RNG Hardware */
62static void cavium_rng_remove(struct pci_dev *pdev)
63{
64	struct cavium_rng_pf *rng;
65
66	rng = pci_get_drvdata(pdev);
67
68	/* Remove the VF */
69	pci_disable_sriov(pdev);
70
71	/* Disable the RNG hardware and entropy source */
72	writeq(0, rng->control_status);
73}
74
75static const struct pci_device_id cavium_rng_pf_id_table[] = {
76	{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa018), 0, 0, 0}, /* Thunder RNM */
77	{0,},
78};
79
80MODULE_DEVICE_TABLE(pci, cavium_rng_pf_id_table);
81
82static struct pci_driver cavium_rng_pf_driver = {
83	.name		= "cavium_rng_pf",
84	.id_table	= cavium_rng_pf_id_table,
85	.probe		= cavium_rng_probe,
86	.remove		= cavium_rng_remove,
87};
88
89module_pci_driver(cavium_rng_pf_driver);
90MODULE_AUTHOR("Omer Khaliq <okhaliq@caviumnetworks.com>");
91MODULE_LICENSE("GPL v2");
v5.14.15
 
 1/*
 2 * Hardware Random Number Generator support for Cavium Inc.
 3 * Thunder processor family.
 4 *
 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.
 8 *
 9 * Copyright (C) 2016 Cavium, Inc.
10 */
11
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>
17
18#define THUNDERX_RNM_ENT_EN     0x1
19#define THUNDERX_RNM_RNG_EN     0x2
20
21struct cavium_rng_pf {
22	void __iomem *control_status;
23};
24
25/* Enable the RNG hardware and activate the VF */
26static int cavium_rng_probe(struct pci_dev *pdev,
27			const struct pci_device_id *id)
28{
29	struct	cavium_rng_pf *rng;
30	int	iov_err;
31
32	rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
33	if (!rng)
34		return -ENOMEM;
35
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;
42	}
43
44	/* Enable the RNG hardware and entropy source */
45	writeq(THUNDERX_RNM_RNG_EN | THUNDERX_RNM_ENT_EN,
46		rng->control_status);
47
48	pci_set_drvdata(pdev, rng);
49
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;
59	}
60
61	return 0;
62}
63
64/* Disable VF and RNG Hardware */
65static void cavium_rng_remove(struct pci_dev *pdev)
66{
67	struct cavium_rng_pf *rng;
68
69	rng = pci_get_drvdata(pdev);
70
71	/* Remove the VF */
72	pci_disable_sriov(pdev);
73
74	/* Disable the RNG hardware and entropy source */
75	writeq(0, rng->control_status);
76}
77
78static 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,},
81};
82
83MODULE_DEVICE_TABLE(pci, cavium_rng_pf_id_table);
84
85static 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,
90};
91
92module_pci_driver(cavium_rng_pf_driver);
93MODULE_AUTHOR("Omer Khaliq <okhaliq@caviumnetworks.com>");
94MODULE_LICENSE("GPL");