New Generic HW RNG (#3)
Subsystems (6)
cover New Generic HW RNG (#3)
This patch series replaces the old non-generic Hardware Random Number Generator support by a fully generic RNG API.
This makes it possible to register additional RNGs from modules. With this patch series applied, Laptops with a bcm43xx chip (PowerBook) have a HW RNG available now.
Additionally two new RNG drivers are added for the "ixp4xx" and "omap" devices. (Written by Deepak Saxena). This patch series includes the old patches by Deepak Saxena.
The old x86-rng driver has beed splitted.
The userspace RNG daemon can later be updated to select the RNG through /sys/class/misc/hw_random/ for convenience. For now it is sufficient to use cat and echo -n on the sysfs attributes.
Please apply to -mm for testing.
PATCH 1/9 Remove old HW RNG support
drivers/char/Kconfig +0 -15
@@ -670,21 +670,6 @@ If you're not sure, say N. -config HW_RANDOM - tristate "Intel/AMD/VIA HW Random Number Generator support" - depends on (X86 || IA64) && PCI - ---help--- - This driver provides kernel-side support for the Random Number - Generator hardware found on Intel i8xx-based motherboards, - AMD 76x-based motherboards, and Via Nehemiah CPUs. - - Provides a character driver, used to read() entropy data. - - To compile this driver as a module, choose M here: the - module will be called hw_random. - - If unsure, say N. - config NVRAM tristate "/dev/nvram support" depends on ATARI || X86 || ARM || GENERIC_NVRAM
drivers/char/Makefile +0 -1
@@ -75,7 +75,6 @@ obj-$(CONFIG_TOSHIBA) += toshiba.o obj-$(CONFIG_I8K) += i8k.o obj-$(CONFIG_DS1620) += ds1620.o -obj-$(CONFIG_HW_RANDOM) += hw_random.o obj-$(CONFIG_FTAPE) += ftape/ obj-$(CONFIG_COBALT_LCD) += lcd.o obj-$(CONFIG_PPDEV) += ppdev.o
drivers/char/hw_random.c deleted +0 -698
698 lines not on this page · raw message
--
PATCH 2/9 Add new generic HW RNG core
In reply to [email protected]drivers/char/Kconfig +2 -0
@@ -670,6 +670,8 @@ If you're not sure, say N. +source "drivers/char/hw_random/Kconfig" + config NVRAM tristate "/dev/nvram support" depends on ATARI || X86 || ARM || GENERIC_NVRAM
drivers/char/Makefile +1 -0
@@ -75,6 +75,7 @@ obj-$(CONFIG_TOSHIBA) += toshiba.o obj-$(CONFIG_I8K) += i8k.o obj-$(CONFIG_DS1620) += ds1620.o +obj-$(CONFIG_HW_RANDOM) += hw_random/ obj-$(CONFIG_FTAPE) += ftape/ obj-$(CONFIG_COBALT_LCD) += lcd.o obj-$(CONFIG_PPDEV) += ppdev.o
drivers/char/hw_random/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# +# Hardware Random Number Generator (RNG) configuration +# + +config HW_RANDOM + bool "Hardware Random Number Generator Core support" + default y + ---help--- + Hardware Random Number Generator Core infrastructure. + + If unsure, say Y.
drivers/char/hw_random/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for HW Random Number Generator (RNG) device drivers. +# + +obj-$(CONFIG_HW_RANDOM) += core.o
drivers/char/hw_random/core.c new file +364 -0
364 lines not on this page · raw message
include/linux/hw_random.h new file +50 -0
50 lines not on this page · raw message
--
PATCH 3/9 Add Intel HW RNG driver
In reply to [email protected]drivers/char/hw_random/Kconfig +13 -0
@@ -9,3 +9,16 @@ Hardware Random Number Generator Core infrastructure. If unsure, say Y. + +config HW_RANDOM_INTEL + tristate "Intel HW Random Number Generator support" + depends on HW_RANDOM && (X86 || IA64) && PCI + default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on Intel i8xx-based motherboards. + + To compile this driver as a module, choose M here: the + module will be called intel-rng. + + If unsure, say Y.
drivers/char/hw_random/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_HW_RANDOM) += core.o +obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o
drivers/char/hw_random/intel-rng.c new file +198 -0
198 lines not on this page · raw message
--
Re: [patch 3/9] Add Intel HW RNG driver
Quoted 55 lines · Michael Buesch
Index:
hwrng/drivers/char/hw_random/intel-rng.c
===================================================================drivers/char/hw_random/intel-rng.c new file +50
-0@@ -0,0 +1,198 @@ +/* +* RNG driver for Intel RNGs +* +* Copyright 2005 (c) MontaVista Software, Inc. +* +* with the majority of the code coming from: +* +* Hardware driver for the Intel/AMD/VIA Random Number Generators (RNG) +* (c) Copyright 2003 Red Hat Inc <[email protected]> +* +* derived from +* +* Hardware driver for the AMD 768 Random Number Generator (RNG) +* (c) Copyright 2001 Red Hat Inc <[email protected]> +* +* derived from +* +* Hardware driver for Intel i810 Random Number Generator (RNG) +* Copyright 2000,2001 Jeff Garzik <[email protected]> +* Copyright 2000,2001 Philipp Rumpf <[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/pci.h> +#include <linux/hw_random.h> +#include <asm/io.h> + + +#define PFX KBUILD_MODNAME ": " + +/* +* RNG registers +*/ +#define INTEL_RNG_HW_STATUS 0 +#define INTEL_RNG_PRESENT 0x40 +#define INTEL_RNG_ENABLED 0x01 +#define INTEL_RNG_STATUS 1 +#define INTEL_RNG_DATA_PRESENT 0x01 +#define INTEL_RNG_DATA 2 + +/* +* Magic address at which Intel PCI bridges locate the RNG +*/ +#define INTEL_RNG_ADDR 0xFFBC015F +#define INTEL_RNG_ADDR_LEN 3
drivers/char/hw_random/intel-rng.c line 60
Quoted 10 lines
drivers/char/hw_random/intel-rng.c new file +10
-0+ +/* +* Data for PCI driver interface +* +* This data only exists for exporting the supported +* PCI ids via MODULE_DEVICE_TABLE. We do not actually +* register a pci_driver, because someone else might one day +* want to register another driver on the same PCI id. +*/ +static struct pci_device_id pci_tbl[] = {
Should be const.
Quoted 85 lines
drivers/char/hw_random/intel-rng.c new file +85
-0+ { 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, + { 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, + { 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, + { 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, + { 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, + { 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, + { 0, }, /* terminate list */ +}; +MODULE_DEVICE_TABLE (pci, pci_tbl); + + +static inline u8 hwstatus_get (void __iomem *mem) +{ +return readb (mem +INTEL_RNG_HW_STATUS ); +} + +static inline u8 hwstatus_set (void __iomem *mem, +u8 hw_status) +{ +writeb (hw_status, mem +INTEL_RNG_HW_STATUS ); +return hwstatus_get (mem); +} + +static int intel_rng_data_present (struct hwrng *rng) +{ +void __iomem *mem = (void __iomem *)rng->priv; + +return !!(readb (mem +INTEL_RNG_STATUS ) &INTEL_RNG_DATA_PRESENT ); +} + +static int intel_rng_data_read (struct hwrng *rng,u32 *data) +{ +void __iomem *mem = (void __iomem *)rng->priv; + + *data =readb (mem +INTEL_RNG_DATA ); + +return 1 ; +} + +static int intel_rng_init (struct hwrng *rng) +{ +void __iomem *mem = (void __iomem *)rng->priv; +u8 hw_status; +int err = -EIO ; + + hw_status =hwstatus_get (mem); +/* turn RNG h/w on, if it's off */ +if ((hw_status &INTEL_RNG_ENABLED ) ==0 ) + hw_status =hwstatus_set (mem, hw_status |INTEL_RNG_ENABLED ); +if ((hw_status &INTEL_RNG_ENABLED ) ==0 ) { + printk(KERN_ERR PFX "cannot enable RNG, aborting\n"); + goto out; + } + err =0 ; +out: +return err; +} + +static void intel_rng_cleanup (struct hwrng *rng) +{ +void __iomem *mem = (void __iomem *)rng->priv; +u8 hw_status; + + hw_status =hwstatus_get (mem); +if (hw_status &INTEL_RNG_ENABLED ) +hwstatus_set (mem, hw_status & ~INTEL_RNG_ENABLED ); +else + printk(KERN_WARNING PFX "unusual: RNG already disabled\n"); +} + + +static struct hwrng intel_rng = { + .name ="intel" , + .init = intel_rng_init, + .cleanup = intel_rng_cleanup, + .data_present = intel_rng_data_present, + .data_read = intel_rng_data_read, +}; + + +static int __init mod_init (void ) +{ +int err = -ENODEV ; +struct pci_dev *pdev =NULL ; +const struct pci_device_id *ent;
drivers/char/hw_random/intel-rng.c line 155
Quoted 10 lines
drivers/char/hw_random/intel-rng.c new file +10
-0+void __iomem *mem; +u8 hw_status; + +for_each_pci_dev (pdev) { + ent =pci_match_id (pci_tbl, pdev); +if (ent) + goto found; + } +/* Device not found. */ + goto out;
if (!pci_dev_present(pci_tbl)) goto out;
Quoted 10 lines
drivers/char/hw_random/intel-rng.c new file +10
-0+ +found: + err = -ENOMEM ; + mem =ioremap (INTEL_RNG_ADDR ,INTEL_RNG_ADDR_LEN ); +if (!mem) + goto out; + intel_rng.priv = (unsigned long )mem; + +/* Check for Intel 82802 */ + err = -ENODEV ;
drivers/char/hw_random/intel-rng.c line 175
Quoted 10 lines
drivers/char/hw_random/intel-rng.c new file +10
-0+ hw_status =hwstatus_get (mem); +if ((hw_status &INTEL_RNG_PRESENT ) ==0 ) + goto err_unmap; + +printk (KERN_INFO "Intel 82802 RNG detected\n" ); + err =hwrng_register (&intel_rng); +if (err) { + printk(KERN_ERR PFX "RNG registering failed (%d)\n", + err); + goto out;
goto err_unmap;
Quoted 25 lines
drivers/char/hw_random/intel-rng.c new file +23
-1+ } +out: +return err; + +err_unmap: +iounmap (mem); + goto out; +} + +static void __exit mod_exit(void) +{ +void __iomem *mem = (void __iomem *)intel_rng.priv; + +hwrng_unregister (&intel_rng); +iounmap (mem); +} + +subsys_initcall (mod_init); +module_exit (mod_exit); + +MODULE_AUTHOR ("The Linux Kernel team" ); +MODULE_DESCRIPTION ("H/W RNG driver for Intel chipsets" ); +MODULE_LICENSE ("GPL" ); --
Re: [patch 3/9] Add Intel HW RNG driver
Quoted 3 lines · you
Quoted 1 line
+static struct
pci_device_idpci_tbl[] = {Should be const.
Sure, will fix that for every driver.
Quoted 10 lines
drivers/char/hw_random/intel-rng.c line 155
Quoted 7 lines
drivers/char/hw_random/intel-rng.c new file +7
-0+for_each_pci_dev (pdev) { + ent =pci_match_id (pci_tbl, pdev); +if (ent) + goto found; + } +/* Device not found. */ + goto out;if (!pci_dev_present(pci_tbl)) goto out;
Good idea. I just copied the code from the old driver.
Quoted 7 lines
drivers/char/hw_random/intel-rng.c line 175
Quoted 5 lines
drivers/char/hw_random/intel-rng.c new file +5
-0+ err =hwrng_register (&intel_rng); +if (err) { + printk(KERN_ERR PFX "RNG registering failed (%d)\n", + err); + goto out;goto err_unmap;
oops.
Signature · 1 line
Greetings Michael.
PATCH 4/9 Add AMD HW RNG driver
In reply to [email protected]drivers/char/hw_random/amd-rng.c new file +152 -0
@@ -0,0 +1,152 @@ +/* +* RNG driver for AMD RNGs +* +* Copyright 2005 (c) MontaVista Software, Inc. +* +* with the majority of the code coming from: +* +* Hardware driver for the Intel/AMD/VIA Random Number Generators (RNG) +* (c) Copyright 2003 Red Hat Inc <[email protected]> +* +* derived from +* +* Hardware driver for the AMD 768 Random Number Generator (RNG) +* (c) Copyright 2001 Red Hat Inc <[email protected]> +* +* derived from +* +* Hardware driver for Intel i810 Random Number Generator (RNG) +* Copyright 2000,2001 Jeff Garzik <[email protected]> +* Copyright 2000,2001 Philipp Rumpf <[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/pci.h> +#include <linux/hw_random.h> +#include <asm/io.h> + + +#define PFX KBUILD_MODNAME ": " + + +/* +* Data for PCI driver interface +* +* This data only exists for exporting the supported +* PCI ids via MODULE_DEVICE_TABLE. We do not actually +* register a pci_driver, because someone else might one day +* want to register another driver on the same PCI id. +*/ +static struct pci_device_id pci_tbl[] = { + {0x1022 ,0x7443 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,0 , }, + {0x1022 ,0x746b ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,0 , }, + {0 , },/* terminate list */ +}; +MODULE_DEVICE_TABLE (pci, pci_tbl); + +static struct pci_dev *amd_pdev; + + +static int amd_rng_data_present (struct hwrng *rng) +{ +u32 pmbase = (u32 )rng->priv; + +return !!(inl (pmbase +0xF4 ) &1 ); +} + +static int amd_rng_data_read (struct hwrng *rng,u32 *data) +{ +u32 pmbase = (u32 )rng->priv; + + *data =inl (pmbase +0xF0 ); + +return 4 ; +} + +static int amd_rng_init (struct hwrng *rng) +{ +u8 rnen; + +pci_read_config_byte (amd_pdev,0x40 , &rnen); + rnen |= (1 <<7 );/* RNG on */ +pci_write_config_byte (amd_pdev,0x40 , rnen); + +pci_read_config_byte (amd_pdev,0x41 , &rnen); + rnen |= (1 <<7 );/* PMIO enable */ +pci_write_config_byte (amd_pdev,0x41 , rnen); + +return 0 ; +} + +static void amd_rng_cleanup (struct hwrng *rng) +{ +u8 rnen; + +pci_read_config_byte (amd_pdev,0x40 , &rnen); + rnen &= ~(1 <<7 );/* RNG off */ +pci_write_config_byte (amd_pdev,0x40 , rnen); +} + + +static struct hwrng amd_rng = { + .name ="amd" , + .init = amd_rng_init, + .cleanup = amd_rng_cleanup, + .data_present = amd_rng_data_present, + .data_read = amd_rng_data_read, +}; + + +static int __init mod_init (void ) +{ +int err = -ENODEV ; +struct pci_dev *pdev =NULL ; +const struct pci_device_id *ent; +u32 pmbase; + +for_each_pci_dev (pdev) { + ent =pci_match_id (pci_tbl, pdev); +if (ent) + goto found; + } +/* Device not found. */ + goto out; + +found: + err =pci_read_config_dword (pdev,0x58 , &pmbase); +if (err) + goto out; + err = -EIO ; + pmbase &=0x0000FF00 ; +if (pmbase ==0 ) + goto out; + amd_rng.priv = (unsigned long )pmbase; + amd_pdev = pdev; + +printk (KERN_INFO "AMD768 RNG detected\n" ); + err =hwrng_register (&amd_rng); +if (err) { + printk(KERN_ERR PFX "RNG registering failed (%d)\n", + err); + goto out; + } +out: +return err; +} + +static void __exit mod_exit(void) +{ +hwrng_unregister (&amd_rng); +} + +subsys_initcall (mod_init); +module_exit (mod_exit); + +MODULE_AUTHOR ("The Linux Kernel team" ); +MODULE_DESCRIPTION ("H/W RNG driver for AMD chipsets" ); +MODULE_LICENSE ("GPL" );
drivers/char/hw_random/Kconfig +13 -0
@@ -22,3 +22,16 @@ module will be called intel-rng. If unsure, say Y. + +config HW_RANDOM_AMD + tristate "AMD HW Random Number Generator support" + depends on HW_RANDOM && (X86 || IA64) && PCI + default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on AMD 76x-based motherboards. + + To compile this driver as a module, choose M here: the + module will be called amd-rng. + + If unsure, say Y.
drivers/char/hw_random/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_HW_RANDOM) += core.o obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o +obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o
--
PATCH 5/9 Add Geode HW RNG driver
In reply to [email protected]drivers/char/hw_random/Kconfig +13 -0
@@ -35,3 +35,16 @@ module will be called amd-rng. If unsure, say Y. + +config HW_RANDOM_GEODE + tristate "AMD Geode HW Random Number Generator support" + depends on HW_RANDOM && (X86 || IA64) && PCI + default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on AMD Geode based motherboards. + + To compile this driver as a module, choose M here: the + module will be called geode-rng. + + If unsure, say Y.
drivers/char/hw_random/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_HW_RANDOM) += core.o obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o +obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
drivers/char/hw_random/geode-rng.c new file +129 -0
129 lines not on this page · raw message
--
Re: [patch 5/9] Add Geode HW RNG driver
drivers/char/hw_random/Kconfig line 41
Quoted 13 lines · [email protected] wrote:
Signed-off-by Michael Buesch <[email protected]>Index: hwrng/drivers/char/hw_random/Kconfig
===================================================================drivers/char/hw_random/Kconfig +4
-0@@ -35,3 +35,16 @@ module will be called amd-rng. If unsure, say Y. + +config HW_RANDOM_GEODE + tristate "AMD Geode HW Random Number Generator support" + depends on HW_RANDOM && (X86 || IA64) && PCI
^^^^^^^
IA64?
drivers/char/hw_random/Kconfig line 48
Quoted 7 lines
drivers/char/hw_random/Kconfig +7
-0+ default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on AMD Geode based motherboards. + + To compile this driver as a module, choose M here: the + module will be called geode-rng.
You need to state which members of the Geode family have this hardware.
e.g., Is it only the Geode LX CPUs?
David Vrabel
Re: [patch 5/9] Add Geode HW RNG driver
Quoted 9 lines · you
Quoted 8 lines · [email protected] wrote:
Signed-off-by Michael Buesch <[email protected]>Index: hwrng/drivers/char/hw_random/Kconfig
===================================================================drivers/char/hw_random/Kconfig +0
-0@@ -35,3 +35,16 @@ module will be called amd-rng.
Quoted 7 lines
drivers/char/hw_random/Kconfig line 41
Quoted 5 lines
drivers/char/hw_random/Kconfig +4
-0If unsure, say Y. + +config HW_RANDOM_GEODE + tristate "AMD Geode HW Random Number Generator support" + depends on HW_RANDOM && (X86 || IA64) && PCI^^^^^^^IA64?
I have no idea. I neither wrote the driver, nor do I have the device. So, drop IA64?
Quoted 10 lines
drivers/char/hw_random/Kconfig line 48
Quoted 7 lines
drivers/char/hw_random/Kconfig +7
-0+ default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on AMD Geode based motherboards. + + To compile this driver as a module, choose M here: the + module will be called geode-rng.You need to state which members of the Geode family have this hardware.
e.g., Is it only the Geode LX CPUs?
Well, no idea. It was not stated in the existing old help text either.
Signature · 1 line
Greetings Michael.
Re: [patch 5/9] Add Geode HW RNG driver
Quoted 18 lines · Michael Buesch
Quoted 9 lines · you
Quoted 8 lines · [email protected] wrote:
Signed-off-by Michael Buesch <[email protected]>Index: hwrng/drivers/char/hw_random/Kconfig
===================================================================drivers/char/hw_random/Kconfig +0
-0@@ -35,3 +35,16 @@ module will be called amd-rng.Quoted 7 lines
drivers/char/hw_random/Kconfig line 41
Quoted 5 lines
drivers/char/hw_random/Kconfig +4
-0If unsure, say Y. + +config HW_RANDOM_GEODE + tristate "AMD Geode HW Random Number Generator support" + depends on HW_RANDOM && (X86 || IA64) && PCI^^^^^^^IA64?
Quoted 2 lines
I have no idea. I neither wrote the driver, nor do I have the device. So, drop IA64?
Yes, the AMD Geode CPUs are all x86.
Quoted 11 lines
Quoted 9 lines
drivers/char/hw_random/Kconfig line 48
Quoted 7 lines
drivers/char/hw_random/Kconfig +7
-0+ default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on AMD Geode based motherboards. + + To compile this driver as a module, choose M here: the + module will be called geode-rng.You need to state which members of the Geode family have this hardware.
e.g., Is it only the Geode LX CPUs?Well, no idea. It was not stated in the existing old help text either.
I checked the datasheets for the Geode GX, Geode LX and Geode NX and only the Geode LX has an on-chip random number generator. So this driver must be for the Geode LX only.
David Vrabel
Re: Add Geode HW RNG driver
In reply to Michael BueschQuoted 18 lines · Michael Buesch
Quoted 9 lines · you
Quoted 8 lines · [email protected] wrote:
Signed-off-by Michael Buesch <[email protected]>Index: hwrng/drivers/char/hw_random/Kconfig
===================================================================drivers/char/hw_random/Kconfig +0
-0@@ -35,3 +35,16 @@ module will be called amd-rng.Quoted 7 lines
drivers/char/hw_random/Kconfig line 41
Quoted 5 lines
drivers/char/hw_random/Kconfig +4
-0If unsure, say Y. + +config HW_RANDOM_GEODE + tristate "AMD Geode HW Random Number Generator support" + depends on HW_RANDOM && (X86 || IA64) && PCI^^^^^^^IA64?
Quoted 2 lines
I have no idea. I neither wrote the driver, nor do I have the device. So, drop IA64?
Wow - where did that come from? Yeah, drop it!
Quoted 11 lines
Quoted 10 lines
drivers/char/hw_random/Kconfig line 48
Quoted 7 lines
drivers/char/hw_random/Kconfig +7
-0+ default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on AMD Geode based motherboards. + + To compile this driver as a module, choose M here: the + module will be called geode-rng.You need to state which members of the Geode family have this hardware.
e.g., Is it only the Geode LX CPUs?
Quoted 1 line
Well, no idea. It was not stated in the existing old help text either.
Its just the Geode LX - that help text should be more specific in that regard.
Regards,
Jordan
--
Jordan Crouse
Senior Linux Engineer
AMD - Personal Connectivity Solutions Group
<www.amd.com/embeddedprocessors>
PATCH 6/9 Add VIA HW RNG driver
In reply to [email protected]drivers/char/hw_random/Kconfig +13 -0
@@ -48,3 +48,16 @@ module will be called geode-rng. If unsure, say Y. + +config HW_RANDOM_VIA + tristate "VIA HW Random Number Generator support" + depends on HW_RANDOM && X86 + default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on VIA based motherboards. + + To compile this driver as a module, choose M here: the + module will be called via-rng. + + If unsure, say Y.
drivers/char/hw_random/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o +obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
drivers/char/hw_random/via-rng.c new file +184 -0
184 lines not on this page · raw message
--
PATCH 7/9 Add ixp4xx HW RNG driver
In reply to [email protected]drivers/char/hw_random/Kconfig +13 -0
@@ -61,3 +61,16 @@ module will be called via-rng. If unsure, say Y. + +config HW_RANDOM_IXP4XX + tristate "Intel IXP4xx NPU HW Random Number Generator support" + depends on HW_RANDOM && ARCH_IXP4XX + default y + ---help--- + This driver provides kernel-side support for the Random + Number Generator hardware found on the Intel IXP4xx NPU. + + To compile this driver as a module, choose M here: the + module will be called ixp4xx-rng. + + If unsure, say Y.
drivers/char/hw_random/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o +obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
drivers/char/hw_random/ixp4xx-rng.c new file +73 -0
73 lines not on this page · raw message
--
PATCH 8/9 Add TI OMAP CPU family HW RNG driver
In reply to [email protected]drivers/char/hw_random/Kconfig +14 -0
@@ -74,3 +74,17 @@ module will be called ixp4xx-rng. If unsure, say Y. + +config HW_RANDOM_OMAP + tristate "OMAP Random Number Generator support" + depends on HW_RANDOM && (ARCH_OMAP16XX || ARCH_OMAP24XX) + default y + ---help--- + This driver provides kernel-side support for the Random Number + Generator hardware found on OMAP16xx and OMAP24xx multimedia + processors. + + To compile this driver as a module, choose M here: the + module will be called omap-rng. + + If unsure, say Y.
drivers/char/hw_random/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o +obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
drivers/char/hw_random/omap-rng.c new file +208 -0
208 lines not on this page · raw message
--
PATCH 9/9 Add bcm43xx HW RNG support
In reply to [email protected]drivers/net/wireless/bcm43xx/Kconfig +1 -0
@@ -2,6 +2,7 @@ tristate "Broadcom BCM43xx wireless support" depends on PCI && IEEE80211 && IEEE80211_SOFTMAC && NET_RADIO && EXPERIMENTAL select FW_LOADER + select HW_RANDOM ---help--- This is an experimental driver for the Broadcom 43xx wireless chip, found in the Apple Airport Extreme and various other devices.
drivers/net/wireless/bcm43xx/bcm43xx.h +6 -0
@@ -1,6 +1,7 @@#ifndef BCM43xx_H_#define BCM43xx_H_ +#include <linux/hw_random.h> #include <linux/version.h> #include <linux/kernel.h> #include <linux/spinlock.h>
@@ -82,6 +83,7 @@#define BCM43xx_MMIO_TSF_1 0x634/* core rev < 3 only */ #define BCM43xx_MMIO_TSF_2 0x636/* core rev < 3 only */ #define BCM43xx_MMIO_TSF_3 0x638/* core rev < 3 only */ +#define BCM43xx_MMIO_RNG 0x65A#define BCM43xx_MMIO_POWERUP_DELAY 0x6A8/* SPROM offsets. */
@@ -741,6 +743,10 @@const struct firmware *initvals0;const struct firmware *initvals1; +/* Random Number Generator. */ +struct hwrng rng; +char rng_name[20 +1 ]; +/* Debugging stuff follows. */ #ifdef CONFIG_BCM43XX_DEBUG struct bcm43xx_dfsentry *dfsentry;
drivers/net/wireless/bcm43xx/bcm43xx_main.c +37 -0
@@ -3152,6 +3152,39 @@bcm43xx_clear_keys (bcm); } +static int bcm43xx_rng_read (struct hwrng *rng,u32 *data) +{ +struct bcm43xx_private *bcm = (struct bcm43xx_private *)rng->priv; +unsigned long flags; + +bcm43xx_lock (bcm, flags); + *data =bcm43xx_read16 (bcm, BCM43xx_MMIO_RNG); +bcm43xx_unlock (bcm, flags); + +return (sizeof (u16)); +} + +static void bcm43xx_rng_exit (struct bcm43xx_private *bcm) +{ +hwrng_unregister (&bcm->rng); +} + +static int bcm43xx_rng_init (struct bcm43xx_private *bcm) +{ +int err; + +snprintf (bcm->rng_name,ARRAY_SIZE (bcm->rng_name), +"%s_%s" ,KBUILD_MODNAME , bcm->net_dev->name); + bcm->rng.name = bcm->rng_name; + bcm->rng.data_read = bcm43xx_rng_read; + bcm->rng.priv = (unsigned long )bcm; + err =hwrng_register (&bcm->rng); +if (err) + printk(KERN_ERR PFX "RNG init failed (%d)\n", err); + +return err; +} +/* This is the opposite of bcm43xx_init_board() */ static void bcm43xx_free_board (struct bcm43xx_private *bcm) {
@@ -3167,6 +3200,7 @@ bcm->shutting_down =1 ;bcm43xx_unlock (bcm, flags); +bcm43xx_rng_exit (bcm);for (i =0 ; i < BCM43xx_MAX_80211_CORES; i++) {if (!bcm->core_80211[i].available)continue ;
@@ -3248,6 +3282,9 @@bcm43xx_switch_core (bcm, &bcm->core_80211[0 ]);bcm43xx_mac_enable (bcm); } + err =bcm43xx_rng_init (bcm); +if (err) + goto err_80211_unwind;bcm43xx_macfilter_clear (bcm, BCM43xx_MACFILTER_ASSOC);bcm43xx_macfilter_set (bcm, BCM43xx_MACFILTER_SELF, (u8 *)(bcm->net_dev->dev_addr)); dprintk(KERN_INFO PFX "80211 cores initialized\n");
--
Re: [patch 9/9] Add bcm43xx HW RNG support
drivers/net/wireless/bcm43xx/bcm43xx_main.c line 3161
Quoted 7 lines · Michael Buesch
drivers/net/wireless/bcm43xx/bcm43xx_main.c +7
-0+static int bcm43xx_rng_read (struct hwrng *rng,u32 *data) +{ +struct bcm43xx_private *bcm = (struct bcm43xx_private *)rng->priv; +unsigned long flags; + +bcm43xx_lock (bcm, flags); + *data =bcm43xx_read16 (bcm, BCM43xx_MMIO_RNG);
You are storing random 16-bit value _and_ 16 zero bits into 32-bit memory location. Probably not a problem for little-endian machine (you return 2, indicating that there are only 2 bytes of randomness), but on big endian?
Didn't you mean
*(u16*)data = bcm43xx_read16(bcm, BCM43xx_MMIO_RNG); ?
drivers/net/wireless/bcm43xx/bcm43xx_main.c line 3165
Quoted 4 lines
drivers/net/wireless/bcm43xx/bcm43xx_main.c +4
-0+bcm43xx_unlock (bcm, flags); + +return (sizeof (u16)); +}
--
vda
Johannes Berg
maintainerRe: [patch 9/9] Add bcm43xx HW RNG support
Quoted 8 lines · Denis Vlasenko
Didn't you mean
*(u16*)data = bcm43xx_read16(bcm, BCM43xx_MMIO_RNG); ?drivers/net/wireless/bcm43xx/bcm43xx_main.c line 3165
Quoted 4 lines
drivers/net/wireless/bcm43xx/bcm43xx_main.c +4
-0+bcm43xx_unlock (bcm, flags); + +return (sizeof (u16)); +}
I'm not the expert, but looking at patch 2 I'd say no, because one byte is copied out and then the value is right-shifted, so it is always treated as a u32 where only 'size' bytes are valid starting with the lower bytes.
johannes
Re: [patch 9/9] Add bcm43xx HW RNG support
In reply to Denis VlasenkoQuoted 14 lines · Denis Vlasenko
drivers/net/wireless/bcm43xx/bcm43xx_main.c line 3161
Quoted 7 lines · Michael Buesch
drivers/net/wireless/bcm43xx/bcm43xx_main.c +7
-0+static int bcm43xx_rng_read (struct hwrng *rng,u32 *data) +{ +struct bcm43xx_private *bcm = (struct bcm43xx_private *)rng->priv; +unsigned long flags; + +bcm43xx_lock (bcm, flags); + *data =bcm43xx_read16 (bcm, BCM43xx_MMIO_RNG);You are storing random 16-bit value _and_ 16 zero bits into 32-bit memory location. Probably not a problem for little-endian machine (you return 2, indicating that there are only 2 bytes of randomness), but on big endian?
Quoted 3 lines
Didn't you mean
*(u16*)data = bcm43xx_read16(bcm, BCM43xx_MMIO_RNG); ?
Nope, the code is correct.
Signature · 1 line
Greetings Michael.