[flash_ctrl] Hook-up lfsr in flash_ctrl

- currently only used for rma entry

Signed-off-by: Timothy Chen <timothytim@google.com>
diff --git a/hw/ip/flash_ctrl/dv/tb/flash_ctrl_wrapper.sv b/hw/ip/flash_ctrl/dv/tb/flash_ctrl_wrapper.sv
index c86f42d..e4facd1 100644
--- a/hw/ip/flash_ctrl/dv/tb/flash_ctrl_wrapper.sv
+++ b/hw/ip/flash_ctrl/dv/tb/flash_ctrl_wrapper.sv
@@ -18,6 +18,7 @@
   input        flash_ctrl_pkg::otp_flash_t otp_i,
   input        flash_ctrl_pkg::lc_flash_req_t lc_i,
   input        flash_ctrl_pkg::pwrmgr_flash_t pwrmgr_i,
+  input        flash_ctrl_pkg::edn_entropy_t edn_i,
 
   // Interrupts
   output logic intr_prog_empty_o, // Program fifo is empty
@@ -50,6 +51,7 @@
     .otp_i    (otp_i),
     .lc_i     (lc_i),
     .pwrmgr_i (pwrmgr_i),
+    .edn_i    (edn_i),
 
     .clk_i    (clk_i),
     .rst_ni   (rst_ni)
diff --git a/hw/ip/flash_ctrl/dv/tb/tb.sv b/hw/ip/flash_ctrl/dv/tb/tb.sv
index 15735a6..fa564df 100644
--- a/hw/ip/flash_ctrl/dv/tb/tb.sv
+++ b/hw/ip/flash_ctrl/dv/tb/tb.sv
@@ -47,6 +47,7 @@
     .otp_i              (flash_ctrl_pkg::OTP_FLASH_DEFAULT),
     .lc_i               (flash_ctrl_pkg::LC_FLASH_REQ_DEFAULT),
     .pwrmgr_i           (flash_ctrl_pkg::PWRMGR_FLASH_DEFAULT),
+    .edn_i              (flash_ctrl_pkg::EDN_ENTROPY_DEFAULT),
 
     .intr_prog_empty_o  (intr_prog_empty),
     .intr_prog_lvl_o    (intr_prog_lvl  ),
diff --git a/hw/ip/flash_ctrl/flash_ctrl.core b/hw/ip/flash_ctrl/flash_ctrl.core
index f0ad240..2280904 100644
--- a/hw/ip/flash_ctrl/flash_ctrl.core
+++ b/hw/ip/flash_ctrl/flash_ctrl.core
@@ -11,6 +11,7 @@
       - lowrisc:ip:tlul
       - lowrisc:prim:all
       - lowrisc:prim:secded
+      - lowrisc:prim:lfsr
       - lowrisc:prim:flash
       - lowrisc:prim:gf_mult
       - lowrisc:ip:flash_ctrl_pkg
diff --git a/hw/ip/flash_ctrl/rtl/flash_ctrl.sv b/hw/ip/flash_ctrl/rtl/flash_ctrl.sv
index c3162c1..aacc643 100644
--- a/hw/ip/flash_ctrl/rtl/flash_ctrl.sv
+++ b/hw/ip/flash_ctrl/rtl/flash_ctrl.sv
@@ -25,6 +25,7 @@
   input        lc_flash_req_t lc_i,
   output       lc_flash_rsp_t lc_o,
   input        pwrmgr_flash_t pwrmgr_i,
+  input        edn_entropy_t edn_i,
 
   // Interrupts
   output logic intr_prog_empty_o, // Program fifo is empty
@@ -153,6 +154,25 @@
   logic sw_wen;
   logic sw_wready;
 
+  // lfsr for local entropy usage
+  logic [31:0] rand_val;
+  logic lfsr_en;
+
+  prim_lfsr #(
+    .DefaultSeed(),
+    .EntropyDw(4),
+    .LfsrDw(32),
+    .StateOutDw(32)
+  ) u_lfsr (
+    .clk_i,
+    .rst_ni,
+    .seed_en_i('0),
+    .seed_i('0),
+    .lfsr_en_i(lfsr_en),
+    .entropy_i(edn_i.valid ? edn_i.entropy : '0),
+    .state_o(rand_val)
+  );
+
   // flash control arbitration between softawre / harware interfaces
   flash_ctrl_arb u_ctrl_arb (
     .clk_i,
@@ -218,7 +238,10 @@
     .phase_o(phase),
 
     // indication that sw has been selected
-    .sel_o(if_sel)
+    .sel_o(if_sel),
+
+    // enable lfsr
+    .lfsr_en_o(lfsr_en)
   );
 
   assign op_start      = muxed_ctrl.start.q;
@@ -270,7 +293,7 @@
     .rma_rsp_o(lc_o.rma_ack),
 
     // random value
-    .rand_i('0),
+    .rand_i(rand_val),
 
     // outgoing seeds
     .seeds_o(),
diff --git a/hw/ip/flash_ctrl/rtl/flash_ctrl_arb.sv b/hw/ip/flash_ctrl/rtl/flash_ctrl_arb.sv
index 7cd5278..181588d 100644
--- a/hw/ip/flash_ctrl/rtl/flash_ctrl_arb.sv
+++ b/hw/ip/flash_ctrl/rtl/flash_ctrl_arb.sv
@@ -70,7 +70,10 @@
   output flash_lcmgr_phase_e phase_o,
 
   // indication that sw has been selected
-  output flash_sel_e sel_o
+  output flash_sel_e sel_o,
+
+  // enable lfsr
+  output logic lfsr_en_o
 );
 
   // arbitration FSM
@@ -96,12 +99,15 @@
   end
 
   always_comb begin
+
     func_sel = NoneSel;
     fifo_clr_o = 1'b0;
     state_d = state_q;
+    lfsr_en_o = 1'b1;
 
     unique case (state_q)
       StReset: begin
+        lfsr_en_o = 1'b0;
         // until the flash phy is done with its own iniitlization,
         // no flash controller activity is allowed to commence
         if (!flash_phy_busy_i) begin
diff --git a/hw/ip/flash_ctrl/rtl/flash_ctrl_pkg.sv b/hw/ip/flash_ctrl/rtl/flash_ctrl_pkg.sv
index 0ed379e..e7f23e1 100644
--- a/hw/ip/flash_ctrl/rtl/flash_ctrl_pkg.sv
+++ b/hw/ip/flash_ctrl/rtl/flash_ctrl_pkg.sv
@@ -287,6 +287,12 @@
     logic init;
   } pwrmgr_flash_t;
 
+  // place holder for interface to EDN, replace with real one later
+  typedef struct packed {
+    logic valid;
+    logic [3:0] entropy;
+  } edn_entropy_t;
+
   // default value of otp_flash_t
   // These are hardwired default values that should never be used.
   // Real values are individualized and supplied from OTP.
@@ -307,6 +313,9 @@
     init: 1'b1
   };
 
-
+  parameter edn_entropy_t EDN_ENTROPY_DEFAULT = '{
+    valid: 1'b1,
+    entropy: '0
+  };
 
 endpackage : flash_ctrl_pkg