aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-11-23 19:18:25 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-23 19:18:25 -0500
commit26b265cd29dde56bf0901c421eabc7ae815f38c4 (patch)
tree83a5418c96ccde8522bda6614063b665fe5e0ec9 /drivers/char
parent2e7babfa892a55588467ef03b545002e32f31528 (diff)
parentf262f0f5cad0c9eca61d1d383e3b67b57dcbe5ea (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto update from Herbert Xu: - Made x86 ablk_helper generic for ARM - Phase out chainiv in favour of eseqiv (affects IPsec) - Fixed aes-cbc IV corruption on s390 - Added constant-time crypto_memneq which replaces memcmp - Fixed aes-ctr in omap-aes - Added OMAP3 ROM RNG support - Add PRNG support for MSM SoC's - Add and use Job Ring API in caam - Misc fixes [ NOTE! This pull request was sent within the merge window, but Herbert has some questionable email sending setup that makes him public enemy #1 as far as gmail is concerned. So most of his emails seem to be trapped by gmail as spam, resulting in me not seeing them. - Linus ] * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (49 commits) crypto: s390 - Fix aes-cbc IV corruption crypto: omap-aes - Fix CTR mode counter length crypto: omap-sham - Add missing modalias padata: make the sequence counter an atomic_t crypto: caam - Modify the interface layers to use JR API's crypto: caam - Add API's to allocate/free Job Rings crypto: caam - Add Platform driver for Job Ring hwrng: msm - Add PRNG support for MSM SoC's ARM: DT: msm: Add Qualcomm's PRNG driver binding document crypto: skcipher - Use eseqiv even on UP machines crypto: talitos - Simplify key parsing crypto: picoxcell - Simplify and harden key parsing crypto: ixp4xx - Simplify and harden key parsing crypto: authencesn - Simplify key parsing crypto: authenc - Export key parsing helper function crypto: mv_cesa: remove deprecated IRQF_DISABLED hwrng: OMAP3 ROM Random Number Generator support crypto: sha256_ssse3 - also test for BMI2 crypto: mv_cesa - Remove redundant of_match_ptr crypto: sahara - Remove redundant of_match_ptr ...
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/hw_random/Kconfig25
-rw-r--r--drivers/char/hw_random/Makefile2
-rw-r--r--drivers/char/hw_random/msm-rng.c197
-rw-r--r--drivers/char/hw_random/omap3-rom-rng.c141
-rw-r--r--drivers/char/hw_random/pseries-rng.c5
-rw-r--r--drivers/char/hw_random/via-rng.c2
6 files changed, 368 insertions, 4 deletions
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index c206de2951f2..2f2b08457c67 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -165,6 +165,19 @@ config HW_RANDOM_OMAP
165 165
166 If unsure, say Y. 166 If unsure, say Y.
167 167
168config HW_RANDOM_OMAP3_ROM
169 tristate "OMAP3 ROM Random Number Generator support"
170 depends on HW_RANDOM && ARCH_OMAP3
171 default HW_RANDOM
172 ---help---
173 This driver provides kernel-side support for the Random Number
174 Generator hardware found on OMAP34xx processors.
175
176 To compile this driver as a module, choose M here: the
177 module will be called omap3-rom-rng.
178
179 If unsure, say Y.
180
168config HW_RANDOM_OCTEON 181config HW_RANDOM_OCTEON
169 tristate "Octeon Random Number Generator support" 182 tristate "Octeon Random Number Generator support"
170 depends on HW_RANDOM && CAVIUM_OCTEON_SOC 183 depends on HW_RANDOM && CAVIUM_OCTEON_SOC
@@ -327,3 +340,15 @@ config HW_RANDOM_TPM
327 module will be called tpm-rng. 340 module will be called tpm-rng.
328 341
329 If unsure, say Y. 342 If unsure, say Y.
343
344config HW_RANDOM_MSM
345 tristate "Qualcomm MSM Random Number Generator support"
346 depends on HW_RANDOM && ARCH_MSM
347 ---help---
348 This driver provides kernel-side support for the Random Number
349 Generator hardware found on Qualcomm MSM SoCs.
350
351 To compile this driver as a module, choose M here. the
352 module will be called msm-rng.
353
354 If unsure, say Y.
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index d7d2435ff7fa..3ae7755a52e7 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -15,6 +15,7 @@ n2-rng-y := n2-drv.o n2-asm.o
15obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o 15obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
16obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o 16obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
17obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o 17obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
18obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
18obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o 19obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
19obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o 20obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
20obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o 21obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
@@ -28,3 +29,4 @@ obj-$(CONFIG_HW_RANDOM_POWERNV) += powernv-rng.o
28obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o 29obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
29obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o 30obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
30obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o 31obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
32obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
diff --git a/drivers/char/hw_random/msm-rng.c b/drivers/char/hw_random/msm-rng.c
new file mode 100644
index 000000000000..148521e51dc6
--- /dev/null
+++ b/drivers/char/hw_random/msm-rng.c
@@ -0,0 +1,197 @@
1/*
2 * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14#include <linux/clk.h>
15#include <linux/err.h>
16#include <linux/hw_random.h>
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/of.h>
20#include <linux/platform_device.h>
21
22/* Device specific register offsets */
23#define PRNG_DATA_OUT 0x0000
24#define PRNG_STATUS 0x0004
25#define PRNG_LFSR_CFG 0x0100
26#define PRNG_CONFIG 0x0104
27
28/* Device specific register masks and config values */
29#define PRNG_LFSR_CFG_MASK 0x0000ffff
30#define PRNG_LFSR_CFG_CLOCKS 0x0000dddd
31#define PRNG_CONFIG_HW_ENABLE BIT(1)
32#define PRNG_STATUS_DATA_AVAIL BIT(0)
33
34#define MAX_HW_FIFO_DEPTH 16
35#define MAX_HW_FIFO_SIZE (MAX_HW_FIFO_DEPTH * 4)
36#define WORD_SZ 4
37
38struct msm_rng {
39 void __iomem *base;
40 struct clk *clk;
41 struct hwrng hwrng;
42};
43
44#define to_msm_rng(p) container_of(p, struct msm_rng, hwrng)
45
46static int msm_rng_enable(struct hwrng *hwrng, int enable)
47{
48 struct msm_rng *rng = to_msm_rng(hwrng);
49 u32 val;
50 int ret;
51
52 ret = clk_prepare_enable(rng->clk);
53 if (ret)
54 return ret;
55
56 if (enable) {
57 /* Enable PRNG only if it is not already enabled */
58 val = readl_relaxed(rng->base + PRNG_CONFIG);
59 if (val & PRNG_CONFIG_HW_ENABLE)
60 goto already_enabled;
61
62 val = readl_relaxed(rng->base + PRNG_LFSR_CFG);
63 val &= ~PRNG_LFSR_CFG_MASK;
64 val |= PRNG_LFSR_CFG_CLOCKS;
65 writel(val, rng->base + PRNG_LFSR_CFG);
66
67 val = readl_relaxed(rng->base + PRNG_CONFIG);
68 val |= PRNG_CONFIG_HW_ENABLE;
69 writel(val, rng->base + PRNG_CONFIG);
70 } else {
71 val = readl_relaxed(rng->base + PRNG_CONFIG);
72 val &= ~PRNG_CONFIG_HW_ENABLE;
73 writel(val, rng->base + PRNG_CONFIG);
74 }
75
76already_enabled:
77 clk_disable_unprepare(rng->clk);
78 return 0;
79}
80
81static int msm_rng_read(struct hwrng *hwrng, void *data, size_t max, bool wait)
82{
83 struct msm_rng *rng = to_msm_rng(hwrng);
84 size_t currsize = 0;
85 u32 *retdata = data;
86 size_t maxsize;
87 int ret;
88 u32 val;
89
90 /* calculate max size bytes to transfer back to caller */
91 maxsize = min_t(size_t, MAX_HW_FIFO_SIZE, max);
92
93 /* no room for word data */
94 if (maxsize < WORD_SZ)
95 return 0;
96
97 ret = clk_prepare_enable(rng->clk);
98 if (ret)
99 return ret;
100
101 /* read random data from hardware */
102 do {
103 val = readl_relaxed(rng->base + PRNG_STATUS);
104 if (!(val & PRNG_STATUS_DATA_AVAIL))
105 break;
106
107 val = readl_relaxed(rng->base + PRNG_DATA_OUT);
108 if (!val)
109 break;
110
111 *retdata++ = val;
112 currsize += WORD_SZ;
113
114 /* make sure we stay on 32bit boundary */
115 if ((maxsize - currsize) < WORD_SZ)
116 break;
117 } while (currsize < maxsize);
118
119 clk_disable_unprepare(rng->clk);
120
121 return currsize;
122}
123
124static int msm_rng_init(struct hwrng *hwrng)
125{
126 return msm_rng_enable(hwrng, 1);
127}
128
129static void msm_rng_cleanup(struct hwrng *hwrng)
130{
131 msm_rng_enable(hwrng, 0);
132}
133
134static int msm_rng_probe(struct platform_device *pdev)
135{
136 struct resource *res;
137 struct msm_rng *rng;
138 int ret;
139
140 rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
141 if (!rng)
142 return -ENOMEM;
143
144 platform_set_drvdata(pdev, rng);
145
146 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
147 rng->base = devm_ioremap_resource(&pdev->dev, res);
148 if (IS_ERR(rng->base))
149 return PTR_ERR(rng->base);
150
151 rng->clk = devm_clk_get(&pdev->dev, "core");
152 if (IS_ERR(rng->clk))
153 return PTR_ERR(rng->clk);
154
155 rng->hwrng.name = KBUILD_MODNAME,
156 rng->hwrng.init = msm_rng_init,
157 rng->hwrng.cleanup = msm_rng_cleanup,
158 rng->hwrng.read = msm_rng_read,
159
160 ret = hwrng_register(&rng->hwrng);
161 if (ret) {
162 dev_err(&pdev->dev, "failed to register hwrng\n");
163 return ret;
164 }
165
166 return 0;
167}
168
169static int msm_rng_remove(struct platform_device *pdev)
170{
171 struct msm_rng *rng = platform_get_drvdata(pdev);
172
173 hwrng_unregister(&rng->hwrng);
174 return 0;
175}
176
177static const struct of_device_id msm_rng_of_match[] = {
178 { .compatible = "qcom,prng", },
179 {}
180};
181MODULE_DEVICE_TABLE(of, msm_rng_of_match);
182
183static struct platform_driver msm_rng_driver = {
184 .probe = msm_rng_probe,
185 .remove = msm_rng_remove,
186 .driver = {
187 .name = KBUILD_MODNAME,
188 .owner = THIS_MODULE,
189 .of_match_table = of_match_ptr(msm_rng_of_match),
190 }
191};
192module_platform_driver(msm_rng_driver);
193
194MODULE_ALIAS("platform:" KBUILD_MODNAME);
195MODULE_AUTHOR("The Linux Foundation");
196MODULE_DESCRIPTION("Qualcomm MSM random number generator driver");
197MODULE_LICENSE("GPL v2");
diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
new file mode 100644
index 000000000000..c853e9e68573
--- /dev/null
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -0,0 +1,141 @@
1/*
2 * omap3-rom-rng.c - RNG driver for TI OMAP3 CPU family
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Juha Yrjola <juha.yrjola@solidboot.com>
6 *
7 * Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/random.h>
19#include <linux/hw_random.h>
20#include <linux/timer.h>
21#include <linux/clk.h>
22#include <linux/err.h>
23#include <linux/platform_device.h>
24
25#define RNG_RESET 0x01
26#define RNG_GEN_PRNG_HW_INIT 0x02
27#define RNG_GEN_HW 0x08
28
29/* param1: ptr, param2: count, param3: flag */
30static u32 (*omap3_rom_rng_call)(u32, u32, u32);
31
32static struct timer_list idle_timer;
33static int rng_idle;
34static struct clk *rng_clk;
35
36static void omap3_rom_rng_idle(unsigned long data)
37{
38 int r;
39
40 r = omap3_rom_rng_call(0, 0, RNG_RESET);
41 if (r != 0) {
42 pr_err("reset failed: %d\n", r);
43 return;
44 }
45 clk_disable_unprepare(rng_clk);
46 rng_idle = 1;
47}
48
49static int omap3_rom_rng_get_random(void *buf, unsigned int count)
50{
51 u32 r;
52 u32 ptr;
53
54 del_timer_sync(&idle_timer);
55 if (rng_idle) {
56 clk_prepare_enable(rng_clk);
57 r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
58 if (r != 0) {
59 clk_disable_unprepare(rng_clk);
60 pr_err("HW init failed: %d\n", r);
61 return -EIO;
62 }
63 rng_idle = 0;
64 }
65
66 ptr = virt_to_phys(buf);
67 r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
68 mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
69 if (r != 0)
70 return -EINVAL;
71 return 0;
72}
73
74static int omap3_rom_rng_data_present(struct hwrng *rng, int wait)
75{
76 return 1;
77}
78
79static int omap3_rom_rng_data_read(struct hwrng *rng, u32 *data)
80{
81 int r;
82
83 r = omap3_rom_rng_get_random(data, 4);
84 if (r < 0)
85 return r;
86 return 4;
87}
88
89static struct hwrng omap3_rom_rng_ops = {
90 .name = "omap3-rom",
91 .data_present = omap3_rom_rng_data_present,
92 .data_read = omap3_rom_rng_data_read,
93};
94
95static int omap3_rom_rng_probe(struct platform_device *pdev)
96{
97 pr_info("initializing\n");
98
99 omap3_rom_rng_call = pdev->dev.platform_data;
100 if (!omap3_rom_rng_call) {
101 pr_err("omap3_rom_rng_call is NULL\n");
102 return -EINVAL;
103 }
104
105 setup_timer(&idle_timer, omap3_rom_rng_idle, 0);
106 rng_clk = clk_get(&pdev->dev, "ick");
107 if (IS_ERR(rng_clk)) {
108 pr_err("unable to get RNG clock\n");
109 return PTR_ERR(rng_clk);
110 }
111
112 /* Leave the RNG in reset state. */
113 clk_prepare_enable(rng_clk);
114 omap3_rom_rng_idle(0);
115
116 return hwrng_register(&omap3_rom_rng_ops);
117}
118
119static int omap3_rom_rng_remove(struct platform_device *pdev)
120{
121 hwrng_unregister(&omap3_rom_rng_ops);
122 clk_disable_unprepare(rng_clk);
123 clk_put(rng_clk);
124 return 0;
125}
126
127static struct platform_driver omap3_rom_rng_driver = {
128 .driver = {
129 .name = "omap3-rom-rng",
130 .owner = THIS_MODULE,
131 },
132 .probe = omap3_rom_rng_probe,
133 .remove = omap3_rom_rng_remove,
134};
135
136module_platform_driver(omap3_rom_rng_driver);
137
138MODULE_ALIAS("platform:omap3-rom-rng");
139MODULE_AUTHOR("Juha Yrjola");
140MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
141MODULE_LICENSE("GPL");
diff --git a/drivers/char/hw_random/pseries-rng.c b/drivers/char/hw_random/pseries-rng.c
index b761459a3436..ab7ffdec0ec3 100644
--- a/drivers/char/hw_random/pseries-rng.c
+++ b/drivers/char/hw_random/pseries-rng.c
@@ -24,7 +24,6 @@
24#include <linux/hw_random.h> 24#include <linux/hw_random.h>
25#include <asm/vio.h> 25#include <asm/vio.h>
26 26
27#define MODULE_NAME "pseries-rng"
28 27
29static int pseries_rng_data_read(struct hwrng *rng, u32 *data) 28static int pseries_rng_data_read(struct hwrng *rng, u32 *data)
30{ 29{
@@ -55,7 +54,7 @@ static unsigned long pseries_rng_get_desired_dma(struct vio_dev *vdev)
55}; 54};
56 55
57static struct hwrng pseries_rng = { 56static struct hwrng pseries_rng = {
58 .name = MODULE_NAME, 57 .name = KBUILD_MODNAME,
59 .data_read = pseries_rng_data_read, 58 .data_read = pseries_rng_data_read,
60}; 59};
61 60
@@ -78,7 +77,7 @@ static struct vio_device_id pseries_rng_driver_ids[] = {
78MODULE_DEVICE_TABLE(vio, pseries_rng_driver_ids); 77MODULE_DEVICE_TABLE(vio, pseries_rng_driver_ids);
79 78
80static struct vio_driver pseries_rng_driver = { 79static struct vio_driver pseries_rng_driver = {
81 .name = MODULE_NAME, 80 .name = KBUILD_MODNAME,
82 .probe = pseries_rng_probe, 81 .probe = pseries_rng_probe,
83 .remove = pseries_rng_remove, 82 .remove = pseries_rng_remove,
84 .get_desired_dma = pseries_rng_get_desired_dma, 83 .get_desired_dma = pseries_rng_get_desired_dma,
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index e737772ad69a..de5a6dcfb3e2 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -221,7 +221,7 @@ static void __exit mod_exit(void)
221module_init(mod_init); 221module_init(mod_init);
222module_exit(mod_exit); 222module_exit(mod_exit);
223 223
224static struct x86_cpu_id via_rng_cpu_id[] = { 224static struct x86_cpu_id __maybe_unused via_rng_cpu_id[] = {
225 X86_FEATURE_MATCH(X86_FEATURE_XSTORE), 225 X86_FEATURE_MATCH(X86_FEATURE_XSTORE),
226 {} 226 {}
227}; 227};