Re: [PATCH 2/2] n2rng: Combine substrings for two messages in n2rng_probe()
On 4/19/2017 2:11 AM, SF Markus Elfring wrote: From: Markus Elfring <elfr...@users.sourceforge.net> Date: Wed, 19 Apr 2017 10:50:04 +0200 The script "checkpatch.pl" pointed information out like the following. WARNING: quoted string split across lines Thus fix the affected source code places. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> Thanks Markus. Acked-by: Shannon Nelson <shannon.nel...@oracle.com> --- drivers/char/hw_random/n2-drv.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index 92dd4e925315..f3e67c768101 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -723,16 +723,16 @@ static int n2rng_probe(struct platform_device *op) if (sun4v_hvapi_register(HV_GRP_RNG, np->hvapi_major, >hvapi_minor)) { - dev_err(>dev, "Cannot register suitable " - "HVAPI version.\n"); + dev_err(>dev, + "Cannot register suitable HVAPI version.\n"); goto out; } } if (np->flags & N2RNG_FLAG_MULTI) { if (np->hvapi_major < 2) { - dev_err(>dev, "multi-unit-capable RNG requires " - "HVAPI major version 2 or later, got %lu\n", + dev_err(>dev, + "multi-unit-capable RNG requires HVAPI major version 2 or later, got %lu\n", np->hvapi_major); goto out_hvapi_unregister; }
Re: [PATCH 1/2] n2rng: Use devm_kcalloc() in n2rng_probe()
On 4/19/2017 2:10 AM, SF Markus Elfring wrote: From: Markus Elfring <elfr...@users.sourceforge.net> Date: Wed, 19 Apr 2017 10:30:47 +0200 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kcalloc". * Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> Thanks Markus. Acked-by: Shannon Nelson <shannon.nel...@oracle.com> --- drivers/char/hw_random/n2-drv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index 31cbdbbaebfc..92dd4e925315 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -748,9 +748,7 @@ static int n2rng_probe(struct platform_device *op) dev_info(>dev, "Registered RNG HVAPI major %lu minor %lu\n", np->hvapi_major, np->hvapi_minor); - - np->units = devm_kzalloc(>dev, -sizeof(struct n2rng_unit) * np->num_units, + np->units = devm_kcalloc(>dev, np->num_units, sizeof(*np->units), GFP_KERNEL); err = -ENOMEM; if (!np->units)
[PATCH 0/4] n2rng: add support for m5/m7 rng register layout
Commit c1e9b3b0eea1 ("hwrng: n2 - Attach on T5/M5, T7/M7 SPARC CPUs") added config strings to enable the random number generator in the sparc m5 and m7 platforms. This worked fine for client LDoms, but not for the primary LDom, or running on bare metal, because the actual rng hardware layout changed and self-test would now fail, continually spewing error messages on the console. This patch series adds correct support for the new rng register layout, and adds a limiter to the spewing of error messages. Orabug: 25127795 Shannon Nelson (4): n2rng: limit error spewage when self-test fails n2rng: add device data descriptions n2rng: support new hardware register layout n2rng: update version info drivers/char/hw_random/n2-drv.c | 204 +-- drivers/char/hw_random/n2rng.h | 51 -- 2 files changed, 196 insertions(+), 59 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/4] n2rng: update version info
Signed-off-by: Shannon Nelson <shannon.nel...@oracle.com> --- drivers/char/hw_random/n2-drv.c |8 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index f0bd5ee..31cbdbb 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -21,11 +21,11 @@ #define DRV_MODULE_NAME"n2rng" #define PFX DRV_MODULE_NAME": " -#define DRV_MODULE_VERSION "0.2" -#define DRV_MODULE_RELDATE "July 27, 2011" +#define DRV_MODULE_VERSION "0.3" +#define DRV_MODULE_RELDATE "Jan 7, 2017" static char version[] = - DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; + DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; MODULE_AUTHOR("David S. Miller (da...@davemloft.net)"); MODULE_DESCRIPTION("Niagara2 RNG driver"); @@ -765,7 +765,7 @@ static int n2rng_probe(struct platform_device *op) "multi-unit-capable" : "single-unit"), np->num_units); - np->hwrng.name = "n2rng"; + np->hwrng.name = DRV_MODULE_NAME; np->hwrng.data_read = n2rng_data_read; np->hwrng.priv = (unsigned long) np; -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/4] n2rng: limit error spewage when self-test fails
If the self-test fails, it probably won't actually suddenly start working. Currently, this causes an endless spew of error messages on the console and in the logs, so this patch adds a limiter to the test. Reported-by: Sowmini Varadhan <sowmini.varad...@oracle.com> Signed-off-by: Shannon Nelson <shannon.nel...@oracle.com> --- drivers/char/hw_random/n2-drv.c |5 - 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index 3b06c1d..102560f 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -589,6 +589,7 @@ static void n2rng_work(struct work_struct *work) { struct n2rng *np = container_of(work, struct n2rng, work.work); int err = 0; + static int retries = 4; if (!(np->flags & N2RNG_FLAG_CONTROL)) { err = n2rng_guest_check(np); @@ -606,7 +607,9 @@ static void n2rng_work(struct work_struct *work) dev_info(>op->dev, "RNG ready\n"); } - if (err && !(np->flags & N2RNG_FLAG_SHUTDOWN)) + if (--retries == 0) + dev_err(>op->dev, "Self-test retries failed, RNG not ready\n"); + else if (err && !(np->flags & N2RNG_FLAG_SHUTDOWN)) schedule_delayed_work(>work, HZ * 2); } -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/4] n2rng: add device data descriptions
Since we're going to need to keep track of more than just one attribute of the hardware, we'll change the use of the data field from the match struct from a single flag to a struct pointer. This patch adds the struct template and initial descriptions. Signed-off-by: Shannon Nelson <shannon.nel...@oracle.com> --- drivers/char/hw_random/n2-drv.c | 47 -- drivers/char/hw_random/n2rng.h | 15 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index 102560f..74c26c7 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -625,24 +625,23 @@ static void n2rng_driver_version(void) static int n2rng_probe(struct platform_device *op) { const struct of_device_id *match; - int multi_capable; int err = -ENOMEM; struct n2rng *np; match = of_match_device(n2rng_match, >dev); if (!match) return -EINVAL; - multi_capable = (match->data != NULL); n2rng_driver_version(); np = devm_kzalloc(>dev, sizeof(*np), GFP_KERNEL); if (!np) goto out; np->op = op; + np->data = (struct n2rng_template *)match->data; INIT_DELAYED_WORK(>work, n2rng_work); - if (multi_capable) + if (np->data->multi_capable) np->flags |= N2RNG_FLAG_MULTI; err = -ENODEV; @@ -673,8 +672,9 @@ static int n2rng_probe(struct platform_device *op) dev_err(>dev, "VF RNG lacks rng-#units property\n"); goto out_hvapi_unregister; } - } else + } else { np->num_units = 1; + } dev_info(>dev, "Registered RNG HVAPI major %lu minor %lu\n", np->hvapi_major, np->hvapi_minor); @@ -731,30 +731,61 @@ static int n2rng_remove(struct platform_device *op) return 0; } +static struct n2rng_template n2_template = { + .id = N2_n2_rng, + .multi_capable = 0, + .chip_version = 1, +}; + +static struct n2rng_template vf_template = { + .id = N2_vf_rng, + .multi_capable = 1, + .chip_version = 1, +}; + +static struct n2rng_template kt_template = { + .id = N2_kt_rng, + .multi_capable = 1, + .chip_version = 1, +}; + +static struct n2rng_template m4_template = { + .id = N2_m4_rng, + .multi_capable = 1, + .chip_version = 2, +}; + +static struct n2rng_template m7_template = { + .id = N2_m7_rng, + .multi_capable = 1, + .chip_version = 2, +}; + static const struct of_device_id n2rng_match[] = { { .name = "random-number-generator", .compatible = "SUNW,n2-rng", + .data = _template, }, { .name = "random-number-generator", .compatible = "SUNW,vf-rng", - .data = (void *) 1, + .data = _template, }, { .name = "random-number-generator", .compatible = "SUNW,kt-rng", - .data = (void *) 1, + .data = _template, }, { .name = "random-number-generator", .compatible = "ORCL,m4-rng", - .data = (void *) 1, + .data = _template, }, { .name = "random-number-generator", .compatible = "ORCL,m7-rng", - .data = (void *) 1, + .data = _template, }, {}, }; diff --git a/drivers/char/hw_random/n2rng.h b/drivers/char/hw_random/n2rng.h index f244ac8..e41e55a 100644 --- a/drivers/char/hw_random/n2rng.h +++ b/drivers/char/hw_random/n2rng.h @@ -60,6 +60,20 @@ extern unsigned long sun4v_rng_data_read_diag_v2(unsigned long data_ra, extern unsigned long sun4v_rng_data_read(unsigned long data_ra, unsigned long *tick_delta); +enum n2rng_compat_id { + N2_n2_rng, + N2_vf_rng, + N2_kt_rng, + N2_m4_rng, + N2_m7_rng, +}; + +struct n2rng_template { + enum n2rng_compat_id id; + int multi_capable; + int chip_version; +}; + struct n2rng_unit { u64 control[HV_RNG_NUM_CONTROL]; }; @@ -74,6 +88,7 @@ struct n2rng { #define N2RNG_FLAG_SHUTDOWN0x0010 /* Driver unregistering*/ #define N2RNG_FLAG_BUFFER_VALID0x0020 /* u32 buffer holds valid data */ + struct n2rng_template *data; int num_units; struct n2rng_unit
[PATCH 3/4] n2rng: support new hardware register layout
Add the new register layout constants and the requisite logic for using them. Signed-off-by: Shannon Nelson <shannon.nel...@oracle.com> --- drivers/char/hw_random/n2-drv.c | 144 +-- drivers/char/hw_random/n2rng.h | 36 +++--- 2 files changed, 134 insertions(+), 46 deletions(-) diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index 74c26c7..f0bd5ee 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -302,26 +302,57 @@ static int n2rng_try_read_ctl(struct n2rng *np) return n2rng_hv_err_trans(hv_err); } -#define CONTROL_DEFAULT_BASE \ - ((2 << RNG_CTL_ASEL_SHIFT) |\ -(N2RNG_ACCUM_CYCLES_DEFAULT << RNG_CTL_WAIT_SHIFT) | \ -RNG_CTL_LFSR) - -#define CONTROL_DEFAULT_0 \ - (CONTROL_DEFAULT_BASE | \ -(1 << RNG_CTL_VCO_SHIFT) | \ -RNG_CTL_ES1) -#define CONTROL_DEFAULT_1 \ - (CONTROL_DEFAULT_BASE | \ -(2 << RNG_CTL_VCO_SHIFT) | \ -RNG_CTL_ES2) -#define CONTROL_DEFAULT_2 \ - (CONTROL_DEFAULT_BASE | \ -(3 << RNG_CTL_VCO_SHIFT) | \ -RNG_CTL_ES3) -#define CONTROL_DEFAULT_3 \ - (CONTROL_DEFAULT_BASE | \ -RNG_CTL_ES1 | RNG_CTL_ES2 | RNG_CTL_ES3) +static u64 n2rng_control_default(struct n2rng *np, int ctl) +{ + u64 val = 0; + + if (np->data->chip_version == 1) { + val = ((2 << RNG_v1_CTL_ASEL_SHIFT) | + (N2RNG_ACCUM_CYCLES_DEFAULT << RNG_v1_CTL_WAIT_SHIFT) | +RNG_CTL_LFSR); + + switch (ctl) { + case 0: + val |= (1 << RNG_v1_CTL_VCO_SHIFT) | RNG_CTL_ES1; + break; + case 1: + val |= (2 << RNG_v1_CTL_VCO_SHIFT) | RNG_CTL_ES2; + break; + case 2: + val |= (3 << RNG_v1_CTL_VCO_SHIFT) | RNG_CTL_ES3; + break; + case 3: + val |= RNG_CTL_ES1 | RNG_CTL_ES2 | RNG_CTL_ES3; + break; + default: + break; + } + + } else { + val = ((2 << RNG_v2_CTL_ASEL_SHIFT) | + (N2RNG_ACCUM_CYCLES_DEFAULT << RNG_v2_CTL_WAIT_SHIFT) | +RNG_CTL_LFSR); + + switch (ctl) { + case 0: + val |= (1 << RNG_v2_CTL_VCO_SHIFT) | RNG_CTL_ES1; + break; + case 1: + val |= (2 << RNG_v2_CTL_VCO_SHIFT) | RNG_CTL_ES2; + break; + case 2: + val |= (3 << RNG_v2_CTL_VCO_SHIFT) | RNG_CTL_ES3; + break; + case 3: + val |= RNG_CTL_ES1 | RNG_CTL_ES2 | RNG_CTL_ES3; + break; + default: + break; + } + } + + return val; +} static void n2rng_control_swstate_init(struct n2rng *np) { @@ -336,10 +367,10 @@ static void n2rng_control_swstate_init(struct n2rng *np) for (i = 0; i < np->num_units; i++) { struct n2rng_unit *up = >units[i]; - up->control[0] = CONTROL_DEFAULT_0; - up->control[1] = CONTROL_DEFAULT_1; - up->control[2] = CONTROL_DEFAULT_2; - up->control[3] = CONTROL_DEFAULT_3; + up->control[0] = n2rng_control_default(np, 0); + up->control[1] = n2rng_control_default(np, 1); + up->control[2] = n2rng_control_default(np, 2); + up->control[3] = n2rng_control_default(np, 3); } np->hv_state = HV_RNG_STATE_UNCONFIGURED; @@ -399,6 +430,7 @@ static int n2rng_data_read(struct hwrng *rng, u32 *data) } else { int err = n2rng_generic_read_data(ra); if (!err) { + np->flags |= N2RNG_FLAG_BUFFER_VALID; np->buffer = np->test_data >> 32; *data = np->test_data & 0x; len = 4; @@ -487,9 +519,21 @@ static void n2rng_dump_test_buffer(struct n2rng *np) static int n2rng_check_selftest_buffer(struct n2rng *np, unsigned long unit) { - u64 val = SELFTEST_VAL; + u64 val; int err, matches, limit; + switch (np->data->id) { + case N2_n2_rng: + case N2_vf_rng: + case N2_kt_rng: + case N2_m4_rng: /* yes, m4 uses the old value */ + val = RNG_v1_SELFTEST_VAL; + break; + default: + val
Re: console noise after commit c1e9b3b0eea
Resurrecting an old thread, pulled out of http://www.spinics.net/lists/linux-crypto/msg19192.html On Wed, Apr 20, 2016 at 9:18 AM, Anatoly Pugachevwrote: On Wed, Apr 20, 2016 at 1:33 AM, Sowmini Varadhan wrote: Hi Anatoly, after commit c1e9b3b0eea1 ("hwrng: n2 - Attach on T5/M5, T7/M7 SPARC CPUs") I get a *lot* of console noise on my T5-2, of the form: n2rng f028f21c: Selftest failed on unit 0 n2rng f028f21c: Test buffer slot 0 [0x] n2rng f028f21c: Test buffer slot 1 [0xe63f56d6a22eb116] n2rng f028f21c: Test buffer slot 2 [0xe63f56d6a22eb116] n2rng f028f21c: Test buffer slot 3 [0xe63f56d6a22eb116] n2rng f028f21c: Test buffer slot 4 [0xe63f56d6a22eb116] n2rng f028f21c: Test buffer slot 5 [0xe63f56d6a22eb116] n2rng f028f21c: Test buffer slot 6 [0xe63f56d6a22eb116] n2rng f028f21c: Test buffer slot 7 [0xe63f56d6a22eb116] Why/when is your commit needed on my T5-2? I'm not sure how this was tested, but if you need to revise it and test on sparc, please let me know- I think it needs more work on sparc. Sowmini, the patch/commit is actually quite trivial, it just adds device_id matches for newer T5/M7 CPUs to n2rng_match structure. Without this patch, n2rng does not work on this newer CPUs. Works well on my T5-2 LDOM (tested with rng-tools and gpg --gen-key). I don't have M7 Anatoly, I think your LDOM is why you don't see the problem. Yes, your patch works just fine when running in a client LDOM, but we see a problem when running this on sparc "bare metal". Did you test this on the bare metal so that the self-test would run? It seems there's an issue with the self-test in the newer hardware and the driver will never stop trying to retest the hardware. I'm contemplating a patch to limit the self-test attempts, at least until we can figure out what is the root of the issue. sln machine to test it with. Why the n2rng selftest fails on your machine - I've no idea... Just to silence it, you can blacklist this module, since it does not work your hardware anyway. Can you please send me "prtconf -pv" output from your machine, as well information on how do you run linux as LDOM container or baremetal T5-2 ? Mine T5-2 is one of the last firmware releases (run from solaris 11.3 control domain): root@deimos:/home/sysadmin# prtdiag -v FW Version Sun System Firmware 9.5.3 2015/11/25 09:50 sysadmin@deimos:~$ ldm -V Logical Domains Manager (v 3.3.0.0.17) Hypervisor control protocol v 1.12 Using Hypervisor MD v 1.4 System PROM: Hostconfig v. 1.6.3@(#)Hostconfig 1.6.3 2015/11/25 08:57 Hypervisor v. 1.15.3 @(#)Hypervisor 1.15.3 2015/11/11 17:15 OpenBootv. 4.38.3 @(#)OpenBoot 4.38.3 2015/11/11 10:38 Can you please check what firmware release if yours T5-2 server and probably update? I'm not sure it would help, but anyway. -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html