[dv/kmac] Fix err_code regression error

This PR fixes err_code regression error because we removed the cycle
accurate model. Now we do not know which sha3 state from design so I
masked these bits when checking the readout value.
However, I will create some direct sequence test to make sure design
reflects the correct error bits regarding the sha3 states.

Signed-off-by: Cindy Chen <chencindy@opentitan.org>
diff --git a/hw/ip/kmac/dv/env/kmac_env_pkg.sv b/hw/ip/kmac/dv/env/kmac_env_pkg.sv
index 1e30517..d40f625 100644
--- a/hw/ip/kmac/dv/env/kmac_env_pkg.sv
+++ b/hw/ip/kmac/dv/env/kmac_env_pkg.sv
@@ -63,6 +63,7 @@
   // `right_encode()` or `left_encode()`.
   parameter int MAX_ENCODE_WIDTH = 2040;
 
+  parameter uint HASH_CNT_WIDTH = 10;
   // alerts
   parameter uint NUM_ALERTS = 2;
   parameter string LIST_OF_ALERTS[] = {"recov_operation_err", "fatal_fault_err"};
diff --git a/hw/ip/kmac/dv/env/kmac_scoreboard.sv b/hw/ip/kmac/dv/env/kmac_scoreboard.sv
index 0f8f300..b7b33f6 100644
--- a/hw/ip/kmac/dv/env/kmac_scoreboard.sv
+++ b/hw/ip/kmac/dv/env/kmac_scoreboard.sv
@@ -321,6 +321,7 @@
             if (`KMAC_APP_VALID_TRANS(AppKeymgr)) begin
               app_mode = AppKeymgr;
               strength = sha3_pkg::L256;
+              incr_and_predict_hash_cnt();
             end else if (`KMAC_APP_VALID_TRANS(AppLc)) begin
               app_mode = AppLc;
               strength = sha3_pkg::L128;
@@ -752,6 +753,10 @@
         // TODO - handle error cases
         if (addr_phase_write) begin
           bit [KmacCmdIdx:0] kmac_cmd = item.a_data[KmacCmdIdx:0];
+
+          // Handle hash_cnt_clr bit
+          if (item.a_data[KmacHashCntClrIdx]) void'(ral.entropy_refresh_hash_cnt.predict(0));
+
           if (app_fsm_active) begin
             // As per designer comment in https://github.com/lowRISC/opentitan/issues/7716,
             // if CmdStart is sent during an active App operation, KMAC will throw
@@ -801,6 +806,10 @@
 
                   void'(ral.cfg_regwen.predict(.value(0)));
 
+                  // If masking on and it is a KMAC transaction with secret keys, increment the
+                  // entropy count.
+                  if (cfg.enable_masking && kmac_en) incr_and_predict_hash_cnt();
+
                   if (kmac_en && function_name_6B != kmac_pkg::EncodedStringKMAC) begin
                     kmac_err.valid  = 1;
                     kmac_err.code   = kmac_pkg::ErrIncorrectFunctionName;
@@ -825,7 +834,6 @@
                 if (checked_kmac_cmd == CmdStart) begin
                   // kmac will now compute the digest
                   unchecked_kmac_cmd = CmdProcess;
-
                 end else begin // SW sent wrong command
                   kmac_err.valid = 1;
                   kmac_err.code  = kmac_pkg::ErrSwCmdSequence;
@@ -963,7 +971,6 @@
           end
         end
       end
-      // TODO - entropy csrs
       default: begin
         // regex match the key_share csrs
         string full_idx;
@@ -1130,7 +1137,7 @@
         `DV_CHECK_EQ(csr.get_mirrored_value(), item.d_data,
                      $sformatf("reg name: %0s", csr.get_full_name()))
       end
-      void'(csr.predict(.value(item.d_data), .kind(UVM_PREDICT_READ)));
+      csr.predict(.value(item.d_data), .kind(UVM_PREDICT_READ)));
     end
   endtask : process_tl_access
 
@@ -1615,6 +1622,13 @@
     return err_info;
   endfunction
 
+  function void incr_and_predict_hash_cnt();
+    bit [HASH_CNT_WIDTH-1:0] curr_hash_cnt_val = `gmv(ral.entropy_refresh_hash_cnt);
+    if (curr_hash_cnt_val != '1) begin
+      void'(ral.entropy_refresh_hash_cnt.predict(++curr_hash_cnt_val));
+    end
+  endfunction
+
   function void check_phase(uvm_phase phase);
     super.check_phase(phase);
     // post test checks - ensure that all local fifos and queues are empty
diff --git a/hw/ip/kmac/dv/env/seq_lib/kmac_base_vseq.sv b/hw/ip/kmac/dv/env/seq_lib/kmac_base_vseq.sv
index c4e2196..facb562 100644
--- a/hw/ip/kmac/dv/env/seq_lib/kmac_base_vseq.sv
+++ b/hw/ip/kmac/dv/env/seq_lib/kmac_base_vseq.sv
@@ -125,6 +125,10 @@
 
   bit do_kmac_init = 1'b1;
 
+  constraint hash_cnt_clr_c{
+    hash_cnt_clr dist {0 :/ 9, 1 :/ 1};
+  }
+
   // constrain xof_en to 0 if not in kmac mode
   constraint xof_en_c {
     (!kmac_en) -> (xof_en == 1'b0);
@@ -885,4 +889,8 @@
 
   endtask
 
+  virtual task check_hash_cnt();
+    bit [TL_DW-1:0] val;
+    csr_rd(.ptr(ral.entropy_refresh_hash_cnt), .value(val));
+  endtask
 endclass : kmac_base_vseq
diff --git a/hw/ip/kmac/dv/env/seq_lib/kmac_smoke_vseq.sv b/hw/ip/kmac/dv/env/seq_lib/kmac_smoke_vseq.sv
index 4a2857e..9680b20 100644
--- a/hw/ip/kmac/dv/env/seq_lib/kmac_smoke_vseq.sv
+++ b/hw/ip/kmac/dv/env/seq_lib/kmac_smoke_vseq.sv
@@ -296,6 +296,8 @@
       // read out intr_state and status, scb will check
       check_state();
 
+      check_hash_cnt();
+
       // Read the output digest, scb will check digest
       //
       // If performing a KMAC_APP operation, digest will be sent directly to the m_kmac_app_agent,