* [PATCH 1/2] hwrng: cn10k - Optimize cn10k_rng_read()
2022-04-13 14:16 [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver Vladis Dronov
@ 2022-04-13 14:16 ` Vladis Dronov
2022-04-13 14:16 ` [PATCH 2/2] hwrng: cn10k - Make check_rng_health() return an error code Vladis Dronov
2022-04-21 10:00 ` [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver Herbert Xu
2 siblings, 0 replies; 5+ messages in thread
From: Vladis Dronov @ 2022-04-13 14:16 UTC (permalink / raw)
To: vdronov, Sunil Goutham, Bharat Bhushan, Joseph Longever,
Herbert Xu, linux-crypto, linux-kernel
This function assumes that sizeof(void) is 1 and arithmetic works for
void pointers. This is a GNU C extention and may not work with other
compilers. Change this by using an u8 pointer.
Also move cn10k_read_trng() out of a loop thus saving some cycles.
Fixes: 38e9791a0209 ("hwrng: cn10k - Add random number generator support")
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
---
drivers/char/hw_random/cn10k-rng.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/char/hw_random/cn10k-rng.c b/drivers/char/hw_random/cn10k-rng.c
index 35001c63648b..dd226630b67d 100644
--- a/drivers/char/hw_random/cn10k-rng.c
+++ b/drivers/char/hw_random/cn10k-rng.c
@@ -90,6 +90,7 @@ static int cn10k_rng_read(struct hwrng *hwrng, void *data,
{
struct cn10k_rng *rng = (struct cn10k_rng *)hwrng->priv;
unsigned int size;
+ u8 *pos = data;
int err = 0;
u64 value;
@@ -102,17 +103,20 @@ static int cn10k_rng_read(struct hwrng *hwrng, void *data,
while (size >= 8) {
cn10k_read_trng(rng, &value);
- *((u64 *)data) = (u64)value;
+ *((u64 *)pos) = value;
size -= 8;
- data += 8;
+ pos += 8;
}
- while (size > 0) {
+ if (size > 0) {
cn10k_read_trng(rng, &value);
- *((u8 *)data) = (u8)value;
- size--;
- data++;
+ while (size > 0) {
+ *pos = (u8)value;
+ value >>= 8;
+ size--;
+ pos++;
+ }
}
return max - size;
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] hwrng: cn10k - Make check_rng_health() return an error code
2022-04-13 14:16 [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver Vladis Dronov
2022-04-13 14:16 ` [PATCH 1/2] hwrng: cn10k - Optimize cn10k_rng_read() Vladis Dronov
@ 2022-04-13 14:16 ` Vladis Dronov
2022-04-21 10:00 ` [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver Herbert Xu
2 siblings, 0 replies; 5+ messages in thread
From: Vladis Dronov @ 2022-04-13 14:16 UTC (permalink / raw)
To: vdronov, Sunil Goutham, Bharat Bhushan, Joseph Longever,
Herbert Xu, linux-crypto, linux-kernel
Currently check_rng_health() returns zero unconditionally.
Make it to output an error code and return it.
Fixes: 38e9791a0209 ("hwrng: cn10k - Add random number generator support")
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
---
drivers/char/hw_random/cn10k-rng.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/char/hw_random/cn10k-rng.c b/drivers/char/hw_random/cn10k-rng.c
index dd226630b67d..a01e9307737c 100644
--- a/drivers/char/hw_random/cn10k-rng.c
+++ b/drivers/char/hw_random/cn10k-rng.c
@@ -31,26 +31,23 @@ struct cn10k_rng {
#define PLAT_OCTEONTX_RESET_RNG_EBG_HEALTH_STATE 0xc2000b0f
-static int reset_rng_health_state(struct cn10k_rng *rng)
+static unsigned long reset_rng_health_state(struct cn10k_rng *rng)
{
struct arm_smccc_res res;
/* Send SMC service call to reset EBG health state */
arm_smccc_smc(PLAT_OCTEONTX_RESET_RNG_EBG_HEALTH_STATE, 0, 0, 0, 0, 0, 0, 0, &res);
- if (res.a0 != 0UL)
- return -EIO;
-
- return 0;
+ return res.a0;
}
static int check_rng_health(struct cn10k_rng *rng)
{
u64 status;
- int err;
+ unsigned long err;
/* Skip checking health */
if (!rng->reg_base)
- return 0;
+ return -ENODEV;
status = readq(rng->reg_base + RNM_PF_EBG_HEALTH);
if (status & BIT_ULL(20)) {
@@ -58,7 +55,9 @@ static int check_rng_health(struct cn10k_rng *rng)
if (err) {
dev_err(&rng->pdev->dev, "HWRNG: Health test failed (status=%llx)\n",
status);
- dev_err(&rng->pdev->dev, "HWRNG: error during reset\n");
+ dev_err(&rng->pdev->dev, "HWRNG: error during reset (error=%lx)\n",
+ err);
+ return -EIO;
}
}
return 0;
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver
2022-04-13 14:16 [PATCH 0/2] hwrng: cn10k - Optimize random number generator driver Vladis Dronov
2022-04-13 14:16 ` [PATCH 1/2] hwrng: cn10k - Optimize cn10k_rng_read() Vladis Dronov
2022-04-13 14:16 ` [PATCH 2/2] hwrng: cn10k - Make check_rng_health() return an error code Vladis Dronov
@ 2022-04-21 10:00 ` Herbert Xu
2022-04-21 10:03 ` Vlad Dronov
2 siblings, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2022-04-21 10:00 UTC (permalink / raw)
To: Vladis Dronov
Cc: Sunil Goutham, Bharat Bhushan, Joseph Longever, linux-crypto,
linux-kernel
On Wed, Apr 13, 2022 at 04:16:04PM +0200, Vladis Dronov wrote:
> Hi,
>
> I'm suggesting couple of tweaks and fixes for the CN10K Random Number Generator
> driver. Main points are: fix a logic, optimize a loop and make an error message
> more informative.
>
> Vladis Dronov (2):
> hwrng: cn10k - Optimize cn10k_rng_read()
> hwrng: cn10k - Make check_rng_health() return an error code
>
> drivers/char/hw_random/cn10k-rng.c | 31 +++++++++++++++++--------------
> 1 file changed, 17 insertions(+), 14 deletions(-)
All applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread