[sw] Software updates for lfsr removal

- Also update entropy_src_smoketest to match

Signed-off-by: Timothy Chen <timothytim@google.com>
diff --git a/hw/ip/entropy_src/rtl/entropy_src_core.sv b/hw/ip/entropy_src/rtl/entropy_src_core.sv
index ec4a678..73545d6 100644
--- a/hw/ip/entropy_src/rtl/entropy_src_core.sv
+++ b/hw/ip/entropy_src/rtl/entropy_src_core.sv
@@ -390,7 +390,6 @@
   logic                    unused_entropy_data;
   logic                    unused_fw_ov_rd_data;
 
-
   // flops
   logic [RngBusWidth-1:0] ht_esbus_dly_q, ht_esbus_dly_d;
   logic        ht_esbus_vld_dly_q, ht_esbus_vld_dly_d;
diff --git a/hw/top_englishbreakfast/util/sw_sources.patch b/hw/top_englishbreakfast/util/sw_sources.patch
index 995948b..fd83f61 100644
--- a/hw/top_englishbreakfast/util/sw_sources.patch
+++ b/hw/top_englishbreakfast/util/sw_sources.patch
@@ -5,7 +5,7 @@
 @@ -81,19 +81,6 @@ _reset_start:
  _start:
    .globl _start
- 
+
 -  // Enable entropy complex - this is not the full enable
 -  li   a0, TOP_EARLGREY_ENTROPY_SRC_BASE_ADDR
 -  li   t0, 0x55505a
@@ -58,7 +58,7 @@
 @@ -198,18 +198,13 @@ int main(void) {
    sca_init(kScaTriggerSourceAes, kScaPeripheralAes);
    sca_get_uart(&uart1);
- 
+
 -  LOG_INFO("Running AES serial");
 -
 -  LOG_INFO("Initializing simple serial interface to capture board.");
@@ -66,10 +66,10 @@
    simple_serial_register_handler('k', aes_serial_set_key);
    simple_serial_register_handler('p', aes_serial_single_encrypt);
    simple_serial_register_handler('b', aes_serial_batch_encrypt);
- 
+
 -  LOG_INFO("Initializing AES unit.");
    init_aes();
- 
+
 -  LOG_INFO("Starting simple serial packet handling.");
    while (true) {
      simple_serial_process_packet();
@@ -81,14 +81,14 @@
 @@ -56,7 +56,6 @@ enum {
    kRvTimerHart = kTopEarlgreyPlicTargetIbex0,
  };
- 
+
 -static dif_uart_t uart0;
  static dif_uart_t uart1;
  static dif_gpio_t gpio;
  static dif_rv_timer_t timer;
 @@ -75,13 +74,9 @@ static void sca_init_uart(void) {
    };
- 
+
    IGNORE_RESULT(dif_uart_init(
 -      mmio_region_from_addr(TOP_EARLGREY_UART0_BASE_ADDR), &uart0));
 -  IGNORE_RESULT(dif_uart_configure(&uart0, uart_config));
@@ -100,7 +100,7 @@
    IGNORE_RESULT(dif_uart_configure(&uart1, uart_config));
 +  base_uart_stdout(&uart1);
  }
- 
+
  /**
 @@ -148,29 +143,10 @@ void handler_irq_timer(void) {
   * @param disable Set of peripherals to disable.
@@ -163,12 +163,12 @@
  #include "sw/device/lib/testing/check.h"
 -#include "sw/device/lib/testing/entropy_testutils.h"
  #include "sw/device/lib/testing/test_framework/test_main.h"
- 
+
  #include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
 @@ -66,9 +65,6 @@ bool test_main(void) {
- 
+
    LOG_INFO("Running AES test");
- 
+
 -  // First of all, we need to get the entropy complex up and running.
 -  entropy_testutils_boot_mode_init();
 -
diff --git a/sw/device/lib/dif/dif_entropy_src.c b/sw/device/lib/dif/dif_entropy_src.c
index 3f94380..c6cdee6 100644
--- a/sw/device/lib/dif/dif_entropy_src.c
+++ b/sw/device/lib/dif/dif_entropy_src.c
@@ -37,6 +37,10 @@
   reg = bitfield_field32_write(reg, ENTROPY_SRC_CONF_RNG_BIT_SEL_FIELD,
                                rng_bit_sel);
 
+  uint32_t sw_rd_en = config->route_to_firmware ? 0xa : 0x5;
+  reg = bitfield_field32_write(
+      reg, ENTROPY_SRC_CONF_ENTROPY_DATA_REG_ENABLE_FIELD, sw_rd_en);
+
   // Enable configuration
   uint32_t enable_val = config->mode != kDifEntropySrcModeDisabled ? 0xa : 0x5;
   reg = bitfield_field32_write(reg, ENTROPY_SRC_CONF_ENABLE_FIELD, enable_val);
@@ -58,7 +62,6 @@
     return kDifBadArg;
   }
 
-
   // Conditioning bypass is hardcoded to enabled. Bypass is not intended as
   // a regular mode of operation.
   uint32_t es_route_val = config.route_to_firmware ? 0xa : 0x5;
diff --git a/sw/device/lib/dif/dif_entropy_src.h b/sw/device/lib/dif/dif_entropy_src.h
index edf140c..691e1eb 100644
--- a/sw/device/lib/dif/dif_entropy_src.h
+++ b/sw/device/lib/dif/dif_entropy_src.h
@@ -231,6 +231,7 @@
    * Configuration parameters for health tests.
    */
   dif_entropy_src_test_config_t test_config;
+
 } dif_entropy_src_config_t;
 
 /**
diff --git a/sw/device/lib/dif/dif_entropy_src_unittest.cc b/sw/device/lib/dif/dif_entropy_src_unittest.cc
index ac56336..14a2354 100644
--- a/sw/device/lib/dif/dif_entropy_src_unittest.cc
+++ b/sw/device/lib/dif/dif_entropy_src_unittest.cc
@@ -38,7 +38,7 @@
       .reset_health_test_registers = false,
       .single_bit_mode = kDifEntropySrcSingleBitModeDisabled,
       .route_to_firmware = false,
-      .fips_mode = false,1
+      .fips_mode = false,
       .test_config = {0},
   };
 };
@@ -47,7 +47,6 @@
   EXPECT_EQ(dif_entropy_src_configure(nullptr, {}), kDifBadArg);
 }
 
-
 struct ConfigParams {
   dif_entropy_src_mode_t mode;
   dif_entropy_src_single_bit_mode_t single_bit_mode;
@@ -76,15 +75,13 @@
                       (uint32_t)(test_param.route_to_firmware ? 0xa : 0x5)},
                      {ENTROPY_SRC_ENTROPY_CONTROL_ES_TYPE_OFFSET, 0x5},
                  });
-  EXPECT_WRITE32(ENTROPY_SRC_FW_OV_CONTROL_REG_OFFSET, 0);
+  EXPECT_WRITE32(ENTROPY_SRC_FW_OV_CONTROL_REG_OFFSET, 0x55);
 
   // Current dif does not perform a read modified write
   // EXPECT_READ32(ENTROPY_SRC_CONF_REG_OFFSET, 0);
 
   uint32_t rng_bit_enable = test_param.expected_rng_bit_en ? 0xa : 0x5;
-  // Current dif does not set these fields
-
-  // uint32_t route_to_fw = test_param.route_to_firmware ? 0xa : 0x5;
+  uint32_t route_to_fw = test_param.route_to_firmware ? 0xa : 0x5;
   uint32_t enable =
       test_param.expected_mode != kDifEntropySrcModeDisabled ? 0xa : 0x5;
   uint32_t reset_ht = test_param.reset_health_test_registers ? 0xa : 0x5;
@@ -95,8 +92,7 @@
           {ENTROPY_SRC_CONF_RNG_BIT_ENABLE_OFFSET, rng_bit_enable},
           {ENTROPY_SRC_CONF_HEALTH_TEST_CLR_OFFSET, reset_ht},
           {ENTROPY_SRC_CONF_BOOT_BYPASS_DISABLE_OFFSET, 0x5},
-          // Current dif doesn ot set these fields
-          //{ENTROPY_SRC_CONF_ENTROPY_DATA_REG_ENABLE_OFFSET, route_to_fw},
+          {ENTROPY_SRC_CONF_ENTROPY_DATA_REG_ENABLE_OFFSET, route_to_fw},
           {ENTROPY_SRC_CONF_ENABLE_OFFSET, enable},
       });
 
@@ -125,14 +121,14 @@
                      kDifEntropySrcSingleBitModeDisabled, true, true, 2, false,
                      0, 4},
         // Test single_bit_mode
-        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode0, true,
-                     true, 2, true, 0, 4},
-        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode1, true,
-                     true, 2, true, 1, 4},
-        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode2, true,
-                     true, 2, true, 2, 4},
-        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode3, true,
-                     true, 2, true, 3, 4}));
+        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode0,
+                     true, true, 2, true, 0, 4},
+        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode1,
+                     true, true, 2, true, 1, 4},
+        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode2,
+                     true, true, 2, true, 2, 4},
+        ConfigParams{kDifEntropySrcModePtrng, kDifEntropySrcSingleBitMode3,
+                     true, true, 2, true, 3, 4}));
 
 class ReadTest : public DifEntropySrcTest {};
 
diff --git a/sw/device/lib/testing/entropy_testutils.c b/sw/device/lib/testing/entropy_testutils.c
index def6e5b..1d1939a 100644
--- a/sw/device/lib/testing/entropy_testutils.c
+++ b/sw/device/lib/testing/entropy_testutils.c
@@ -19,7 +19,7 @@
   CHECK_DIF_OK(dif_entropy_src_disable(&entropy_src));
 
   const dif_entropy_src_config_t config = {
-      .mode = kDifEntropySrcModeLfsr,
+      .mode = kDifEntropySrcModePtrng,
       .tests =
           {
               [kDifEntropySrcTestRepCount] = false,
@@ -33,8 +33,6 @@
       .reset_health_test_registers = false,
       .single_bit_mode = kDifEntropySrcSingleBitModeDisabled,
       .route_to_firmware = false,
-      .sample_rate = 2,
-      .lfsr_seed = 0,
   };
   CHECK_DIF_OK(dif_entropy_src_configure(&entropy_src, config));
 }
diff --git a/sw/device/tests/entropy_src_smoketest.c b/sw/device/tests/entropy_src_smoketest.c
index 089b390..55e6bdb 100644
--- a/sw/device/tests/entropy_src_smoketest.c
+++ b/sw/device/tests/entropy_src_smoketest.c
@@ -16,8 +16,8 @@
 const size_t kEntropyDataNumWords = 12;
 
 const uint32_t kExpectedEntropyData[] = {
-    0xa8f49c0d, 0x148ca619, 0xd1818b93, 0x25f2397d, 0x32955611, 0x0aca4b8e,
-    0xc0956655, 0x80735507, 0x4cf2b852, 0x97e50e09, 0x39649525, 0x6a2795f0,
+    0xdaf90306, 0x0466d674, 0x9691df54, 0xd2e3c93f, 0xdcbc993e, 0x64bfd173,
+    0xaba04e99, 0xf8ae1105, 0xd01dc17a, 0x608c5480, 0x373c5dcc, 0xc4e6cd55,
 };
 
 bool test_main() {
@@ -29,7 +29,7 @@
   CHECK_DIF_OK(dif_entropy_src_disable(&entropy_src));
 
   const dif_entropy_src_config_t config = {
-      .mode = kDifEntropySrcModeLfsr,
+      .mode = kDifEntropySrcModePtrng,
       .tests =
           {
               [kDifEntropySrcTestRepCount] = false,
@@ -42,10 +42,7 @@
       // this field needs to manually toggled by software.  Disable for now
       .reset_health_test_registers = false,
       .single_bit_mode = kDifEntropySrcSingleBitModeDisabled,
-      .route_to_firmware = true,
-      .sample_rate = 2,
-      .lfsr_seed = 2,
-  };
+      .route_to_firmware = true};
   CHECK_DIF_OK(dif_entropy_src_configure(&entropy_src, config));
 
   uint32_t entropy_data[kEntropyDataNumWords];