hwrng: cn10k - Optimize random number generator driver
Subsystems (2)
cover hwrng: cn10k - Optimize random number generator driver
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(-)
PATCH 1/2 hwrng: cn10k - Optimize cn10k_rng_read()
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.
--- drivers/char/hw_random/cn10k-rng.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/char/hw_random/cn10k-rng.c +10 -6
@@ -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;
Signature · 1 line
2.35.1
PATCH 2/2 hwrng: cn10k - Make check_rng_health() return an error code
In reply to Vladis DronovCurrently check_rng_health() returns zero unconditionally. Make it to output an error code and return it.
--- drivers/char/hw_random/cn10k-rng.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/char/hw_random/cn10k-rng.c +7 -8
@@ -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 ;
Signature · 1 line
2.35.1
Herbert Xu
maintainerQuoted 6 lines · Vladis Dronov
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.
Quoted 6 lines
Vladis Dronov (2):
hwrng: cn10k - Optimizecn10k_rng_read()
hwrng: cn10k - Makecheck_rng_health()return an error codedrivers/char/hw_random/cn10k-rng.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 2 lines · Herbert Xu
All applied. Thanks.
Thanks a ton, Herber!
Best regards,
Vladis