Skip to content

Commit

Permalink
[sw] Rename dif for writing to entropy_src FIFO
Browse files Browse the repository at this point in the history
This DIF is actually writing bytes to the FIFO the feeds into the
preconditioner when in firmware override mode, not to the observe FIFO.

Signed-off-by: James Wainwright <[email protected]>
  • Loading branch information
jwnrt committed Mar 1, 2024
1 parent 8f1e7d9 commit 9d098dd
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion sw/device/lib/dif/dif_entropy_src.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ dif_result_t dif_entropy_src_observe_fifo_nonblocking_read(
return kDifOk;
}

dif_result_t dif_entropy_src_observe_fifo_write(
dif_result_t dif_entropy_src_fw_ov_data_write(
const dif_entropy_src_t *entropy_src, const uint32_t *buf, size_t len,
size_t *written) {
if (entropy_src == NULL || buf == NULL) {
Expand Down
14 changes: 7 additions & 7 deletions sw/device/lib/dif/dif_entropy_src.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ typedef enum dif_entropy_src_main_fsm {
*/
typedef struct dif_entropy_src_fw_override_config {
/**
* Enables firmware to insert entropy bits back into the pre-conditioner block
* via `dif_entropy_fifo_write()` calls. This feature is useful when the
* firmware is required to implement additional health checks, and to perform
* known answer tests of the preconditioner function.
* Enables firmware to insert entropy bits back into the pre-conditioner FIFO
* via `dif_entropy_src_fw_ov_data_write()` calls. This feature is useful when
* the firmware is required to implement additional health checks, and to
* perform known answer tests of the conditioner.
*
* To take effect, this requires the firmware override feature to be enabled.
*/
Expand Down Expand Up @@ -698,7 +698,7 @@ dif_result_t dif_entropy_src_observe_fifo_nonblocking_read(
const dif_entropy_src_t *entropy_src, uint32_t *buf, size_t *len);

/**
* Performs a write to the entropy pipeline through the observe FIFO.
* Performs a write to the entropy pipeline through the firmware override FIFO.
*
* Entropy source must be configured with firmware override and insert mode
* enabled, otherwise the function will return `kDifError`.
Expand All @@ -710,14 +710,14 @@ dif_result_t dif_entropy_src_observe_fifo_nonblocking_read(
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_entropy_src_observe_fifo_write(
dif_result_t dif_entropy_src_fw_ov_data_write(
const dif_entropy_src_t *entropy_src, const uint32_t *buf, size_t len,
size_t *written);

/**
* Starts conditioner operation.
*
* Initializes the conditioner. Use the `dif_entropy_src_observe_fifo_write()`
* Initializes the conditioner. Use the `dif_entropy_src_fw_ov_data_write()`
* function to send data to the conditioner, and
* `dif_entropy_src_conditioner_stop()` once ready to stop the conditioner
* operation.
Expand Down
15 changes: 7 additions & 8 deletions sw/device/lib/dif/dif_entropy_src_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,11 @@ class ObserveFifoWriteTest : public EntropySrcTest {};

TEST_F(ObserveFifoWriteTest, NullArgs) {
uint32_t buf[8] = {0};
EXPECT_DIF_BADARG(dif_entropy_src_fw_ov_data_write(nullptr, buf, 8, nullptr));
EXPECT_DIF_BADARG(
dif_entropy_src_observe_fifo_write(nullptr, buf, 8, nullptr));
dif_entropy_src_fw_ov_data_write(&entropy_src_, nullptr, 8, nullptr));
EXPECT_DIF_BADARG(
dif_entropy_src_observe_fifo_write(&entropy_src_, nullptr, 8, nullptr));
EXPECT_DIF_BADARG(
dif_entropy_src_observe_fifo_write(nullptr, nullptr, 8, nullptr));
dif_entropy_src_fw_ov_data_write(nullptr, nullptr, 8, nullptr));
}

TEST_F(ObserveFifoWriteTest, BadConfig) {
Expand All @@ -608,7 +607,7 @@ TEST_F(ObserveFifoWriteTest, BadConfig) {
{{ENTROPY_SRC_FW_OV_CONTROL_FW_OV_ENTROPY_INSERT_OFFSET,
kMultiBitBool4False},
{ENTROPY_SRC_FW_OV_CONTROL_FW_OV_MODE_OFFSET, kMultiBitBool4False}});
EXPECT_EQ(dif_entropy_src_observe_fifo_write(&entropy_src_, buf, 8, nullptr),
EXPECT_EQ(dif_entropy_src_fw_ov_data_write(&entropy_src_, buf, 8, nullptr),
kDifError);

// Entropy insert mode not set.
Expand All @@ -617,7 +616,7 @@ TEST_F(ObserveFifoWriteTest, BadConfig) {
{{ENTROPY_SRC_FW_OV_CONTROL_FW_OV_ENTROPY_INSERT_OFFSET,
kMultiBitBool4False},
{ENTROPY_SRC_FW_OV_CONTROL_FW_OV_MODE_OFFSET, kMultiBitBool4True}});
EXPECT_EQ(dif_entropy_src_observe_fifo_write(&entropy_src_, buf, 8, nullptr),
EXPECT_EQ(dif_entropy_src_fw_ov_data_write(&entropy_src_, buf, 8, nullptr),
kDifError);
}

Expand All @@ -630,7 +629,7 @@ TEST_F(ObserveFifoWriteTest, FifoFull) {
kMultiBitBool4True},
{ENTROPY_SRC_FW_OV_CONTROL_FW_OV_MODE_OFFSET, kMultiBitBool4True}});
EXPECT_READ32(ENTROPY_SRC_FW_OV_WR_FIFO_FULL_REG_OFFSET, 1);
EXPECT_EQ(dif_entropy_src_observe_fifo_write(&entropy_src_, buf, 4, &written),
EXPECT_EQ(dif_entropy_src_fw_ov_data_write(&entropy_src_, buf, 4, &written),
kDifIpFifoFull);
EXPECT_EQ(written, 0);
}
Expand All @@ -648,7 +647,7 @@ TEST_F(ObserveFifoWriteTest, Success) {
EXPECT_WRITE32(ENTROPY_SRC_FW_OV_WR_DATA_REG_OFFSET, i + 1);
}
EXPECT_DIF_OK(
dif_entropy_src_observe_fifo_write(&entropy_src_, buf, 4, &written));
dif_entropy_src_fw_ov_data_write(&entropy_src_, buf, 4, &written));
EXPECT_EQ(written, 4);
}

Expand Down
2 changes: 1 addition & 1 deletion sw/device/tests/entropy_src_fw_ovr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void test_firmware_override(dif_entropy_src_t *entropy) {
for (size_t i = 0; i < kEntropyFifoBufferSize; ++i) {
CHECK(buf[i] != 0);
}
CHECK_DIF_OK(dif_entropy_src_observe_fifo_write(
CHECK_DIF_OK(dif_entropy_src_fw_ov_data_write(
entropy, buf, kEntropyFifoBufferSize, NULL));
word_count += kEntropyFifoBufferSize;
} while (dif_entropy_src_is_entropy_available(entropy) == kDifUnavailable);
Expand Down
2 changes: 1 addition & 1 deletion sw/device/tests/entropy_src_kat_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void entropy_src_kat_test(dif_entropy_src_t *entropy_src) {

// Load the input data.
do {
op_result = dif_entropy_src_observe_fifo_write(
op_result = dif_entropy_src_fw_ov_data_write(
entropy_src, kInputMsg + total, ARRAYSIZE(kInputMsg) - total, &count);
total += count;
if (op_result == kDifIpFifoFull) {
Expand Down
2 changes: 1 addition & 1 deletion sw/device/tests/sim_dv/csrng_lc_hw_debug_en_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void fw_override_conditioner_write(
uint32_t total = 0;
do {
uint32_t count;
dif_result_t op_result = dif_entropy_src_observe_fifo_write(
dif_result_t op_result = dif_entropy_src_fw_ov_data_write(
entropy_src, kInputMsg + total, ARRAYSIZE(kInputMsg) - total, &count);
total += count;
if (op_result == kDifIpFifoFull) {
Expand Down

0 comments on commit 9d098dd

Please sign in to comment.