drivers: entropy: nrf5: Replace random number pool implementation

The old algorithm managing random number pools was inefficient and
prone to race conditions. Moreover, its behaviour was not compatible
with the API (provided buffers were filled from the end, leaving
beggining of the buffer untouched if there was not enough random data).

The new implementation is a bit faster and it is race-free as long as
all callers of the entropy_get_entropy_isr() are executed in
"run-to-completion" mode.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commit is contained in:
Piotr Zięcik 2018-10-04 13:11:37 +02:00 committed by Carles Cufí
commit c24aca0229
2 changed files with 125 additions and 157 deletions

View file

@ -25,8 +25,17 @@ config ENTROPY_NRF5_BIAS_CORRECTION
uniform distribution of 0 and 1. When this option is enabled, the time
to generate a byte cannot be guaranteed.
config ENTROPY_NRF5_THR_POOL_SIZE
int "Thread-mode random number pool size"
range ENTROPY_NRF5_THR_THRESHOLD 256
default 8
help
Buffer length in bytes used to store entropy bytes generated by the
hardware to make them ready for thread mode consumers.
Please note, that size of the pool must be a power of 2.
config ENTROPY_NRF5_THR_THRESHOLD
int "Thread-mode low-water threshold"
int "Thread-mode random number pool low-water threshold"
range 4 255
help
Low water-mark threshold in bytes to trigger entropy generation for
@ -34,8 +43,17 @@ config ENTROPY_NRF5_THR_THRESHOLD
buffer goes below this number hardware entropy generation will be
started.
config ENTROPY_NRF5_ISR_POOL_SIZE
int "ISR-mode random number pool size"
range ENTROPY_NRF5_ISR_THRESHOLD 256
default 16
help
Buffer length in bytes used to store entropy bytes generated by the
hardware to make them ready for ISR consumers.
Please note, that size of the pool must be a power of 2.
config ENTROPY_NRF5_ISR_THRESHOLD
int "ISR low-water threshold"
int "ISR-mode random number pool low-water threshold"
range 12 255
help
Low water-mark threshold in bytes to trigger entropy generation for
@ -43,19 +61,6 @@ config ENTROPY_NRF5_ISR_THRESHOLD
buffer goes below this number hardware entropy generation will be
started.
config ENTROPY_NRF5_THR_BUF_LEN
int "Thread-mode buffer length"
range ENTROPY_NRF5_THR_THRESHOLD 255
help
Buffer length in bytes used to store entropy bytes generated by the
hardware to make them ready for thread mode consumers.
config ENTROPY_NRF5_ISR_BUF_LEN
int "ISR buffer length"
range ENTROPY_NRF5_ISR_THRESHOLD 255
help
Buffer length in bytes used to store entropy bytes generated by the
hardware to make them ready for ISR consumers.
config ENTROPY_NRF5_PRI
int "RNG interrupt priority"