move entropy.h to drivers/entropy.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit introduces usage of likely()/unlikely() macros in order
to speed up the entropy_get_entropy_isr() API.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
The entropy_nrf_get_entropy_isr(), which is specific to this driver,
is in fact equivalent of generic entropy_get_entropy_isr(..., 0).
This commit removes the entropy_nrf_get_entropy_isr() function
and replaces its usage by call to generic entropy API.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commit optimizes access to device data using direct reference
instead of relying on the driver_data field in the device structure.
Such approach saves few cycles on time-critical paths.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
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 changes the argument passed to ISR to the pointer
to device data structure, removing one dereference in the interrupt
handler.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commint replaces function names by more accurate ones.
For example, the isr(), was renamed to rng_pool_put(), which
clerarly indicates what this function is doing.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
The entropy_nrf5_get_entropy_isr(..., ENTROPY_BUSYWAIT)
unconditionally started and stopped hardware random number generator
disrupting management of random data pools implemented by the driver.
Moreover, simultaneous call to mentioned function from different
priorities led to hangup of lower priority call as hardware was
stopped by higher priority call while the other one waited for data.
This commit solves mentioned problems by moving the responsibility
for stopping hardware to the interrupt handler. As result hardware
is stopped only when there is no blocking calls to the
entropy_nrf5_get_entropy_isr() as well as all random data pools
are full.
This commit also fixes interrupt management in the mentioned
function, as previous implementation unconditionally enabled
interrupt causing problems similar to the described above.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
Neither entropy_nrf5_get_entropy_isr() nor isr() protected
access to hardware. As result in some situations a random value
could be "stolen" by a higher priority call interrupting one
of the mentioned functions.
This commit solves this problem by introducing random_byte_get()
which accesses hardware atomically.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
The nrf_rng HAL uses barriers on SoCs which need them to ensure
that all register writes will reach the peripheral immediately.
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
Missing clear pending RNG_IRQn when generating multiple
random numbers caused CPU to hang at __WFE call in the
loop waiting for new value.
This fixes commit ddb7f88f9e ("drivers: entropy: nrf5: Fix
ENTROPY_BUSYWAIT implementation")
Fixes#9523.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Fixed the ENTROPY_BUSYWAIT implementation from vectoring to
RNG ISR which was preventing the busywait loop to hang
waiting on the VALRDY event which was getting cleared in the
ISR.
Fixes#9356.
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Implement the new entropy_get_entropy_isr() function to allow the kernel
to collect entropy before the scheduler and kernel data structures are
ready. Switch to an nrf-specific version for high-performance
requirements in the BLE Link Layer.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Improve the documentation of entropy_nrf5.c by adding a comment that
clarifies it's characteristics.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Remove unnecessary header inclusion in nordic's nrf5 random
driver which added a dependency to ext/hal/nordic.
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
After porting the rand driver to drivers/entropy, replace the usage of
the old, Buetooth-specific driver with the generic entropy one.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
The rand driver present in the BLE Link Layer is able to provide
entropy for both threads and ISRs, and so it is more suited to be used
as a generic nRF5x entropy driver instead of the current one. This will
allow applications and the Link Layer to use the same driver without
duplicating it.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>