[aes/dv] Fixed some minor bugs after re-enabling back to back transactions

Signed-off-by: Rasmus Madsen <rasmus.madsen@wdc.com>
diff --git a/hw/ip/aes/dv/cov/aes_cov_bind.sv b/hw/ip/aes/dv/cov/aes_cov_bind.sv
index 37f9fdf..d1c16e1 100644
--- a/hw/ip/aes/dv/cov/aes_cov_bind.sv
+++ b/hw/ip/aes/dv/cov/aes_cov_bind.sv
@@ -6,7 +6,7 @@
 module aes_cov_bind;
 
   bind aes aes_cov_if u_aes_cov_if (
-    .clk_i      (clk_i)
+    .clk_i           (clk_i)
   );
 
 endmodule
diff --git a/hw/ip/aes/dv/cov/aes_cov_if.sv b/hw/ip/aes/dv/cov/aes_cov_if.sv
index 2bb26e0..2a2d416 100644
--- a/hw/ip/aes/dv/cov/aes_cov_if.sv
+++ b/hw/ip/aes/dv/cov/aes_cov_if.sv
@@ -6,7 +6,7 @@
 
 interface aes_cov_if
   (
-   input logic clk_i // not sure I will use this yet
+   input logic clk_i
    );
 
   import uvm_pkg::*;
@@ -115,6 +115,11 @@
 
 
   ///////////////////////////////////
+  // transition coverage           //
+  ///////////////////////////////////
+
+
+  ///////////////////////////////////
   // Instantiation Macros          //
   ///////////////////////////////////
 
diff --git a/hw/ip/aes/dv/env/aes_env_cfg.sv b/hw/ip/aes/dv/env/aes_env_cfg.sv
index 2f6558d..4978501 100644
--- a/hw/ip/aes/dv/env/aes_env_cfg.sv
+++ b/hw/ip/aes/dv/env/aes_env_cfg.sv
@@ -146,8 +146,9 @@
       VeryFast: begin
         m_tl_agent_cfg.d_ready_delay_min = 0;
         m_tl_agent_cfg.d_ready_delay_max = 0;
+        zero_delays                      = 1;
       end
-    endcase
+    endcase // case (host_resp_speed)
 
     if (config_error_type[0] == 1'b1) num_corrupt_messages += 1;
   endfunction
diff --git a/hw/ip/aes/dv/env/aes_scoreboard.sv b/hw/ip/aes/dv/env/aes_scoreboard.sv
index 89f645d..24b01dc 100644
--- a/hw/ip/aes/dv/env/aes_scoreboard.sv
+++ b/hw/ip/aes/dv/env/aes_scoreboard.sv
@@ -37,7 +37,6 @@
   // once an operation is started the item is put here to wait for the resuting output
   aes_seq_item                      rcv_item_q[$];
 
-
   function void build_phase(uvm_phase phase);
     super.build_phase(phase);
     msg_fifo    = new();
@@ -461,6 +460,7 @@
     aes_seq_item       full_item;
     aes_message_stat_t msg_state = MSG_START;
 
+
     message = new();
 
     fork
@@ -622,8 +622,11 @@
     while (item_fifo.try_get(seq_item));
     while (msg_fifo.try_get(msg_item));
 
-    skipped_cnt = 0;
-    good_cnt    = 0;
+    skipped_cnt   = 0;
+    good_cnt      = 0;
+    cfg.split_cnt = 0;
+    // if split is set before reset make sure to cancel
+    input_item.split_item = 0;
     // reset compare task to start
     reset_compare = 1;
   endfunction
diff --git a/hw/ip/aes/dv/env/aes_seq_item.sv b/hw/ip/aes/dv/env/aes_seq_item.sv
index d27f2b2..e939537 100644
--- a/hw/ip/aes/dv/env/aes_seq_item.sv
+++ b/hw/ip/aes/dv/env/aes_seq_item.sv
@@ -34,6 +34,7 @@
   bit [3:0]       iv_vld;
   aes_mode_e      mode;
   bit             en_b2b_transactions  = 1;
+  int             b2b_pct              = 80;
 
   // percentage of items that will// clear one or more registers
   int             clear_reg_pct = 0;
@@ -112,6 +113,15 @@
 
   }
 
+  constraint back2back_c {
+    if (en_b2b_transactions) {
+      do_b2b dist { 0 :/ (100-b2b_pct),
+                    1 :/ b2b_pct };
+    } else {
+      do_b2b == 0
+    };
+  }
+
 
   function new( string name="aes_sequence_item");
     super.new(name);
@@ -135,7 +145,6 @@
       endcase // case (key_len)
     end
 
-    if (!en_b2b_transactions) do_b2b = 0;
 
     // mask unused data bits
     if (data_len != 0) begin
@@ -283,6 +292,7 @@
     clear_reg_w_rand = rhs_.clear_reg_w_rand;
     key_mask         = rhs_.key_mask;
     aes_mode         = rhs_.aes_mode;
+    do_b2b           = rhs_.do_b2b;
     clear_reg        = rhs_.clear_reg;
     start_item       = rhs_.start_item;
     split_item       = rhs_.split_item;
diff --git a/hw/ip/aes/dv/env/seq_lib/aes_alert_reset_vseq.sv b/hw/ip/aes/dv/env/seq_lib/aes_alert_reset_vseq.sv
index 93ce898..ef95cc4 100644
--- a/hw/ip/aes/dv/env/seq_lib/aes_alert_reset_vseq.sv
+++ b/hw/ip/aes/dv/env/seq_lib/aes_alert_reset_vseq.sv
@@ -46,7 +46,6 @@
             end else if (cfg.error_types.reset && (cfg.flip_rst == Pull_reset)) begin
               // only do reset injection if we are not already
               // injecting other errors (which will pull reset anyway)
-
               aes_reset();
               #10ps;
               wait(!cfg.under_reset);
@@ -60,6 +59,7 @@
         // make sure we don't wait for a reset that never comes
         // in case the inject happened efter test finished
         wait (finished_all_msgs);
+        wait_no_outstanding_access();
         disable fork;
       end // fork
     join
diff --git a/hw/ip/aes/dv/env/seq_lib/aes_base_vseq.sv b/hw/ip/aes/dv/env/seq_lib/aes_base_vseq.sv
index e3a331b..84603d8 100644
--- a/hw/ip/aes/dv/env/seq_lib/aes_base_vseq.sv
+++ b/hw/ip/aes/dv/env/seq_lib/aes_base_vseq.sv
@@ -29,7 +29,7 @@
     aes_message_init();
     `uvm_info(`gfn, $sformatf("\n TL delay: [%d:%d] \n zero delay %d",
               cfg.m_tl_agent_cfg.d_ready_delay_min,cfg.m_tl_agent_cfg.d_ready_delay_max,
-              cfg.zero_delays  ), UVM_HIGH)
+              cfg.zero_delays  ), UVM_MEDIUM)
   endtask
 
   virtual task dut_shutdown();
@@ -91,10 +91,8 @@
 
 
   virtual task set_operation(bit operation);
-    if (ral.ctrl_shadowed.operation.get_mirrored_value() != operation) begin
       ral.ctrl_shadowed.operation.set(operation);
       csr_update(.csr(ral.ctrl_shadowed), .en_shadow_wr(1'b1), .blocking(1));
-    end
   endtask // set_operation
 
 
@@ -190,10 +188,10 @@
 
     `uvm_info(`gfn, $sformatf("\n\t ----| READ OUTPUT DATA"), UVM_MEDIUM)
     `uvm_info(`gfn, $sformatf("\n\t ----| DATA FROM DUT %h ", cypher_txt), UVM_HIGH)
-    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_0: %h ", cypher_txt[0][31:0]), UVM_HIGH)
-    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_1: %h ", cypher_txt[1][31:0]), UVM_HIGH)
-    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_2: %h ", cypher_txt[2][31:0]), UVM_HIGH)
-    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_3: %h ", cypher_txt[3][31:0]), UVM_HIGH)
+    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_0: %h ", cypher_txt[0][31:0]), UVM_MEDIUM)
+    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_1: %h ", cypher_txt[1][31:0]), UVM_MEDIUM)
+    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_2: %h ", cypher_txt[2][31:0]), UVM_MEDIUM)
+    `uvm_info(`gfn, $sformatf("\n\t ----| DATA_OUT_3: %h ", cypher_txt[3][31:0]), UVM_MEDIUM)
   endtask
 
 
@@ -296,6 +294,7 @@
         interleave_queue.shuffle();
     end
 
+    txt = {txt, $sformatf("\n\t IS blocking %b", is_blocking) };
 
     foreach (interleave_queue[i]) begin
       txt = {txt, $sformatf("\n\t ----| \t %s", interleave_queue[i]) };
@@ -364,8 +363,7 @@
     rst_set  = 0;
     cfg_item = aes_item_queue.pop_back();
 
-    // TODO when dut is updated to flag output overwritten
-    // the manual operation should be included in the unbalanced =1 also
+
     if (new_msg) setup_dut(cfg_item);
     if (unbalanced == 0 || manual_operation) begin
        data_item = new();
@@ -382,23 +380,27 @@
       end
     end else begin
 
-      data_item = new();
       while (((aes_item_queue.size() > 0) || (read_queue.size() > 0)) && !rst_set) begin
         // get the status to make sure we can provide data - but don't wait for output //
+        if (aes_item_queue.size() > 0 ) data_item = new();
         status_fsm(cfg_item, data_item, new_msg, manual_operation, 0, status, rst_set);
-        read = $urandom_range(0, 100)  <= read_prob;
-        write = $urandom_range(0, 100) <= write_prob;
 
-        if (status.input_ready && (aes_item_queue.size() > 0)) begin
-          `uvm_info(`gfn, $sformatf("\n send_queue_size %d", aes_item_queue.size()), UVM_MEDIUM)
+        read  = ($urandom_range(0, 100) <= read_prob);
+        write = ($urandom_range(0, 100) <= write_prob);
+
+        if ( (($countones(cfg_item.mode) != 1) || cfg_item.mode == AES_NONE)
+            && (aes_item_queue.size() > 0)) begin
+          // just write the data - don't expect and output
+          data_item = aes_item_queue.pop_back();
+          config_and_transmit(cfg_item, data_item, new_msg, manual_operation, 0, rst_set);
+        end else if (status.input_ready && (aes_item_queue.size() > 0) && write) begin
           data_item = aes_item_queue.pop_back();
           config_and_transmit(cfg_item, data_item, new_msg, manual_operation, 0, rst_set);
           `downcast(clone_item, data_item.clone());
           read_queue.push_back(clone_item);
-          new_msg = 0;
         end
-        if (status.output_valid) begin
-          `uvm_info(`gfn, $sformatf("\n read_queue_size %d", read_queue.size()), UVM_MEDIUM)
+        new_msg = 0;
+        if (status.output_valid && read) begin
           if (read_queue.size() > 0)  begin
             read_item = read_queue.pop_front();
             read_data(read_item.data_out, cfg_item.do_b2b);
@@ -432,14 +434,13 @@
       ref  bit     rst_set           // reset was forced - restart message
       );
 
+    bit                   is_blocking = ~cfg_item.do_b2b;
     status_t              status;
-    bit                   is_blocking = cfg_item.do_b2b;
-
     rst_set = 0;
     if (new_msg) begin
       write_data_key_iv(cfg_item, data_item.data_in);
     end else begin
-      add_data(data_item.data_in, is_blocking);
+      add_data(data_item.data_in, cfg_item.do_b2b);
     end
     if (manual_operation) trigger();
     if (read_output) begin
@@ -483,13 +484,13 @@
 
     // enable get status when provided with an empty Item.
     if (data_item.mode === 'X) begin
-      csr_rd(.ptr(ral.status), .value(status), .blocking(is_blocking));
+      csr_rd(.ptr(ral.status), .value(status), .blocking(1));
     end
 
-    while(!done && (data_item.mode != AES_NONE) && !global_reset) begin
+    while(!done && (cfg_item.mode != AES_NONE) && !global_reset) begin
       //read the status register to see that we have triggered the operation
       wait(!cfg.under_reset)
-      csr_rd(.ptr(ral.status), .value(status), .blocking(is_blocking));
+      csr_rd(.ptr(ral.status), .value(status), .blocking(1));
       txt = {txt, "\n ----|reading STATUS", status2string(status)};
       // check status and act accordingly //
       if (status.alert_fatal_fault) begin
@@ -499,7 +500,7 @@
                     $sformatf("\n\t ----| Saw expected Fatal alert - trying to recover \n\t ----| %s",
                               status2string(status)), UVM_MEDIUM)
           try_recover(cfg_item, data_item, manual_operation);
-          csr_rd(.ptr(ral.status), .value(status), .blocking(is_blocking));
+          csr_rd(.ptr(ral.status), .value(status), .blocking(1));
           if ( !status.alert_fatal_fault) begin
             `uvm_fatal(`gfn, $sformatf("\n\t WAS able to clear FATAL ALERT without reset \n\t %s",
                        status2string(status)))
@@ -563,6 +564,7 @@
               `uvm_fatal(`gfn, $sformatf("AES REPORTED NOT IDLE - NOT READY - NOT STALLING for 100 consecutive reads"))
             end
           end
+          if (!read_output) done = 1;
           // else DUT is in operation wait for new output
           txt = {txt, $sformatf("\n\t ----| status state 3 ")};
 
@@ -582,7 +584,7 @@
       rst_set = 1;
     end
     `uvm_info(`gfn, $sformatf("\n\t %s",txt), UVM_MEDIUM)
-  endtask // transmit_fsm
+  endtask
 
 
   virtual task try_recover(
@@ -596,7 +598,7 @@
     status_t              status;         // the current AES status
     bit                   is_blocking = ~cfg_item.do_b2b;
 
-    csr_rd(.ptr(ral.ctrl_shadowed), .value(ctrl), .blocking(is_blocking));
+    csr_rd(.ptr(ral.ctrl_shadowed), .value(ctrl), .blocking(1));
     ral.ctrl_shadowed.operation.set(cfg_item.operation);
     ral.ctrl_shadowed.mode.set(cfg_item.mode);
     ral.ctrl_shadowed.key_len.set(cfg_item.key_len);
@@ -605,7 +607,7 @@
     // the clear options into a single bit)
     clear_regs(2'b11);
     // check for fatal
-    csr_rd(.ptr(ral.status), .value(status), .blocking(is_blocking));
+    csr_rd(.ptr(ral.status), .value(status), .blocking(1));
     if (!status.alert_fatal_fault) begin
       // wait for idle
       if (!status.idle)  csr_spinwait(.ptr(ral.status.idle), .exp_data(1'b1));
@@ -617,7 +619,7 @@
     end
     write_key(cfg_item.key, is_blocking);
     write_iv(cfg_item.iv, is_blocking);
-    add_data(data_item.data_in, is_blocking);
+    add_data(data_item.data_in, cfg_item.do_b2b);
     if (manual_operation) trigger();
   endtask // try_recover
 
@@ -630,8 +632,8 @@
     // variables
     aes_message_item my_message;
     bit  rst_set = 0;
-    int  dbg_cnt = 0;
     while (message_queue.size() > 0 ) begin
+      `uvm_info(`gfn, $sformatf("Starting New Message - messages left %d",message_queue.size() ), UVM_MEDIUM)
       my_message = new();
       my_message = message_queue.pop_back();
       generate_aes_item_queue(my_message);
@@ -643,7 +645,6 @@
         // everything still works
         cfg.num_messages = 2;
         generate_message_queue();
-        dbg_cnt = 0;
         // if process was halted from the outside //
         if (global_reset) begin
           global_reset = 0;
diff --git a/hw/ip/aes/dv/tests/aes_alert_reset_test.sv b/hw/ip/aes/dv/tests/aes_alert_reset_test.sv
index bf6bcce..bd534f0 100644
--- a/hw/ip/aes/dv/tests/aes_alert_reset_test.sv
+++ b/hw/ip/aes/dv/tests/aes_alert_reset_test.sv
@@ -19,7 +19,7 @@
     cfg.flip_rst_split_pct       = 60;
     cfg.num_messages_min         = 3;
     cfg.num_messages_max         = 6;
-    cfg.unbalanced               = 1;
+    cfg.unbalanced               = 0;
     // message related knobs
     cfg.ecb_weight               = 10;
     cfg.cbc_weight               = 10;
diff --git a/hw/ip/aes/dv/tests/aes_b2b_test.sv b/hw/ip/aes/dv/tests/aes_b2b_test.sv
index e2162e8..546d03b 100644
--- a/hw/ip/aes/dv/tests/aes_b2b_test.sv
+++ b/hw/ip/aes/dv/tests/aes_b2b_test.sv
@@ -10,17 +10,16 @@
    virtual function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      configure_env();
-     `DV_CHECK_RANDOMIZE_FATAL(cfg)
+     `DV_CHECK_RANDOMIZE_WITH_FATAL(cfg, cfg.host_resp_speed == VeryFast;)
   endfunction
 
   virtual function void configure_env();
-    //   cfg.ref_model          = OpenSSL;
-    // env related knobs
-
-    // TODO fix manual mode so we can randomize speeds
-
     cfg.num_messages_min         = 1;
-    cfg.num_messages_max         = 5;
+    cfg.num_messages_max         = 10;
+    //enable writing as fast as DUT permits
+    cfg.unbalanced               = 1;
+    cfg.write_prob               = 100;
+    cfg.read_prob                = 100;
     // message related knobs
     cfg.ecb_weight               = 10;
     cfg.cbc_weight               = 10;
@@ -45,5 +44,6 @@
     cfg.random_data_key_iv_order = 1;
 
     cfg.manual_operation_pct     = 0;
+
   endfunction // configure_env
 endclass : aes_b2b_test
diff --git a/hw/ip/aes/dv/tests/aes_clear_test.sv b/hw/ip/aes/dv/tests/aes_clear_test.sv
index 28f5387..3e59494 100644
--- a/hw/ip/aes/dv/tests/aes_clear_test.sv
+++ b/hw/ip/aes/dv/tests/aes_clear_test.sv
@@ -26,7 +26,7 @@
     cfg.ofb_weight               = 10;
     cfg.cfb_weight               = 10;
 
-    cfg.message_len_min          = 1;
+    cfg.message_len_min          = 17;
     cfg.message_len_max          = 317;
     cfg.manual_operation_pct     = 30;
     cfg.use_key_mask             = 0;