From 8e836f6c3686f3387851f5a26b586839e9558551 Mon Sep 17 00:00:00 2001
From: Reinier van der Walle <walle@astron.nl>
Date: Thu, 1 Jun 2023 13:55:57 +0200
Subject: [PATCH] cleanup

---
 libraries/base/dp/src/vhdl/dp_field_blk.vhd   |  7 +-
 libraries/io/eth/src/vhdl/eth_tester_tx.vhd   | 11 ++-
 .../io/eth/tb/vhdl/tb_eth_tester_high_bw.vhd  | 98 ++++++++-----------
 .../eth/tb/vhdl/tb_tb_eth_tester_high_bw.vhd  | 34 +++----
 4 files changed, 68 insertions(+), 82 deletions(-)

diff --git a/libraries/base/dp/src/vhdl/dp_field_blk.vhd b/libraries/base/dp/src/vhdl/dp_field_blk.vhd
index 2607451870..b9d431d6c5 100644
--- a/libraries/base/dp/src/vhdl/dp_field_blk.vhd
+++ b/libraries/base/dp/src/vhdl/dp_field_blk.vhd
@@ -35,7 +35,12 @@ USE work.dp_stream_pkg.ALL;
 --   if override = '0' the field is taken from snk_in.data.
 -- . The initial (default) values of the override bits are passed via g_field_sel(one bit per field);
 -- . Both the SLV as the override (ovr) fields can be read back via MM;
-
+-- . g_mode can be used to select in which mode dp_field_blk should work. Most of the time, the
+--   default g_mode = 0 can be used. Forcing either source or sink mode could be done when the
+--   data sosi data length is larger than the field block.
+--   . g_mode = 0: auto select mode based on g_snk_data_w and g_src_data_w.
+--   . g_mode = 1: use dp_field_blk in source mode regardless of g_*_data_w.
+--   . g_mode = 2: use dp_field_blk in sink mode regardless of g_*_data_w.
 
 -- The diagrams below show dp_field_blk in source and sink configuration. For simplicity, the 5
 -- fields are defined as follows (fields do not need to respect word boundaries):
diff --git a/libraries/io/eth/src/vhdl/eth_tester_tx.vhd b/libraries/io/eth/src/vhdl/eth_tester_tx.vhd
index e3f673dbf1..e044f20cb2 100644
--- a/libraries/io/eth/src/vhdl/eth_tester_tx.vhd
+++ b/libraries/io/eth/src/vhdl/eth_tester_tx.vhd
@@ -25,12 +25,13 @@
 -- [1] https://support.astron.nl/confluence/display/L2M/L6+FWLIB+Design+Document%3A+ETH+tester+unit+for+1GbE
 -- 
 -- Remarks:
--- . multiple bg can be used to generate more than 1 byte per clock cycle, this
---   can be configured with g_nof_octet_generate. Note that each block gen has
---   the same counter such that the generated data are duplicate bytes. e.g.
---   when set to 2, the data will be 0x0000 0x0101 0x0202 0x0303 ....
+-- . g_nof_octet_generate can be set to increase the amount of bytes generated
+--   per clock cycle by the BG. This is done by duplicating the one byte 
+--   g_nof_octet_generate times using a generate statement.
 -- . g_nof_octet_output determines the output data width, e.g. 
---   when set to 4, the output sosi containt 4 * 8 = 32 bits of generated data
+--   when set to 4, the output sosi containis 4 * 8 = 32 bits of generated data.
+--   This should be the same or a multiple of g_nof_octet_generate such that
+--   it can be repacked.
 
 LIBRARY IEEE, common_lib, dp_lib, diag_lib;
 USE IEEE.std_logic_1164.ALL;
diff --git a/libraries/io/eth/tb/vhdl/tb_eth_tester_high_bw.vhd b/libraries/io/eth/tb/vhdl/tb_eth_tester_high_bw.vhd
index ec90678d19..3eaeb1b903 100644
--- a/libraries/io/eth/tb/vhdl/tb_eth_tester_high_bw.vhd
+++ b/libraries/io/eth/tb/vhdl/tb_eth_tester_high_bw.vhd
@@ -1,6 +1,6 @@
 -------------------------------------------------------------------------------
 --
--- Copyright 2022
+-- Copyright 2023
 -- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
 -- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
 --
@@ -17,23 +17,20 @@
 -- limitations under the License.
 --
 -------------------------------------------------------------------------------
--- AUthor: E. Kooistra
--- Purpose: Test bench for eth_tester
--- Description: See detailed design in [1]
+-- Author: R. vd Walle
+-- Purpose: Test bench for eth_tester using high bandwidth generic configuration
+-- Description: Similar to the 1GbE testbench [1] for the eth tester but using generic
+-- values for usage with high bandwidth, e.g. 10 / 100 GbE.
 --   The g_nof_streams >= 1 are tested independently, using g_bg_ctrl_first for
 --   BG in stream 0 and g_bg_ctrl_others for all other streams.
 --
 -- Usage:
 -- > as 8
 -- # * E.g. view sosi/data signals in dut/gen_streams/u_rx and u_tx
--- # * Cannot use run -a when g_loopback_eth=TRUE and g_eth_sim_level=0,
--- #   because the TSE IP model remains active internally after tb_end
--- > run 100 us  # when g_loopback_eth=TRUE and g_eth_sim_level=0, else:
 -- > run -a
 --
 -- References:
 -- [1] https://support.astron.nl/confluence/display/L2M/L6+FWLIB+Design+Document%3A+ETH+tester+unit+for+1GbE
--- [2] https://support.astron.nl/confluence/display/L2M/L4+SDPFW+Decision%3A+Application+header+size+in+Ethernet+packets
 
 LIBRARY IEEE, common_lib, dp_lib, diag_lib, technology_lib, tech_tse_lib;
 USE IEEE.std_logic_1164.ALL;
@@ -58,8 +55,7 @@ ENTITY tb_eth_tester_high_bw IS
   GENERIC (
     g_tb_index           : NATURAL := 0;  -- use to incremental delay logging from tb instances in tb_tb
     g_nof_sync           : NATURAL := 2;  -- number of BG sync intervals to set c_run_time
-    g_nof_streams        : NATURAL := 1;  -- <= c_eth_nof_udp_ports = 4 when g_loopback_tx_rx = 1
-    g_corrupted_en       : BOOLEAN := FALSE;  -- when TRUE cause a corrupted Rx packet, when tech_tse is used
+    g_nof_streams        : NATURAL := 1;  
     g_nof_octet_output   : NATURAL := 96; -- maximum = 96 bytes as max dp.data field = 768 bits.
     g_nof_octet_generate : NATURAL := 96;
 
@@ -72,8 +68,6 @@ ENTITY tb_eth_tester_high_bw IS
     --   nat: mem_low_adrs
     --   nat: mem_high_adrs
     --   nat: bsn_init
-    --g_bg_ctrl_first    : t_diag_block_gen_integer := ('1', '1', 50, 3, 100, 0, c_diag_bg_mem_max_adr, 0);  -- for first stream
-    --g_bg_ctrl_others   : t_diag_block_gen_integer := ('1', '1', 30, 3, 10, 0, c_diag_bg_mem_max_adr, 0)   -- for other streams
     g_bg_ctrl_first      : t_diag_block_gen_integer := ('1', '1', 500, 3, 200, 0, c_diag_bg_mem_max_adr, 0);  -- for first stream
     g_bg_ctrl_others     : t_diag_block_gen_integer := ('1', '1', 300, 3, 10, 0, c_diag_bg_mem_max_adr, 0)   -- for other streams
   );
@@ -235,9 +229,6 @@ BEGIN
     rx_exp_total_count_nof_valid_arr(0) <= c_nof_sync_first * c_total_count_nof_valid_per_sync_first;
 
     rx_exp_total_count_nof_corrupted_arr <= (OTHERS => 0);  -- default no Rx errors
-    IF g_corrupted_en = TRUE THEN
-      rx_exp_total_count_nof_corrupted_arr(0) <= 1;
-    END IF;
     WAIT;
   END PROCESS;
 
@@ -370,49 +361,40 @@ BEGIN
           ", nof_corrupted = " & NATURAL'IMAGE(rx_total_count_nof_corrupted_arr(I)));
 
       -- Verify, only log when wrong
-      IF g_corrupted_en = FALSE THEN
-        IF c_bg_nof_bps_total < 10.0**9 THEN
-          ASSERT tx_total_count_nof_packet_arr(I) = exp_total_count_nof_packet_arr(I) REPORT c_tb_str &
-              "Wrong Tx total nof packets count(" & NATURAL'IMAGE(I) &
-              "), Tx count = " & NATURAL'IMAGE(tx_total_count_nof_packet_arr(I)) &
-              " /= " & NATURAL'IMAGE(exp_total_count_nof_packet_arr(I)) &
-              " = Expected count" SEVERITY ERROR;
-
-          ASSERT rx_total_count_nof_packet_arr(I) = exp_total_count_nof_packet_arr(I) REPORT c_tb_str &
-              "Wrong Rx total nof packets count(" & NATURAL'IMAGE(I) &
-              "), Rx count = " & NATURAL'IMAGE(rx_total_count_nof_packet_arr(I)) &
-              " /= " & NATURAL'IMAGE(exp_total_count_nof_packet_arr(I)) &
-              " = Expected count" SEVERITY ERROR;
-
-          ASSERT rx_total_count_nof_valid_arr(I) = rx_exp_total_count_nof_valid_arr(I) REPORT c_tb_str &
-              "Wrong Rx total nof valids count(" & NATURAL'IMAGE(I) &
-              "), Rx count = " & NATURAL'IMAGE(rx_total_count_nof_valid_arr(I)) &
-              " /= " & NATURAL'IMAGE(rx_exp_total_count_nof_valid_arr(I)) &
-              " = Expected count" SEVERITY ERROR;
-
-          ASSERT rx_total_count_nof_corrupted_arr(I) = rx_exp_total_count_nof_corrupted_arr(I) REPORT c_tb_str &
-              "Wrong Rx total nof corrupted count(" & NATURAL'IMAGE(I) &
-              "), Rx count = " & NATURAL'IMAGE(rx_total_count_nof_corrupted_arr(I)) &
-              " /= " & NATURAL'IMAGE(rx_exp_total_count_nof_corrupted_arr(I)) &
-              " = Expected count" SEVERITY ERROR;
-        ELSE
-          -- Verify that Tx total nof packets = Rx total nof packets, also when
-          -- BG experiences siso.xon block level flow control, to stay below
-          -- 1 Gbps of the 1GbE link rate.
-          ASSERT tx_total_count_nof_packet_arr(I) = rx_total_count_nof_packet_arr(I) REPORT c_tb_str &
-              "Wrong Tx-Rx total nof packets count(" & NATURAL'IMAGE(I) &
-              "), Tx count = " & NATURAL'IMAGE(tx_total_count_nof_packet_arr(I)) &
-              " /= " & NATURAL'IMAGE(rx_total_count_nof_packet_arr(I)) &
-              " = Rx count" SEVERITY ERROR;
-         END IF;
-       ELSE
-          -- g_corrupted_en = TRUE
-          ASSERT rx_total_count_nof_corrupted_arr(I) = rx_exp_total_count_nof_corrupted_arr(I) REPORT c_tb_str &
-              "Wrong Rx total nof corrupted count(" & NATURAL'IMAGE(I) &
-              "), Rx count = " & NATURAL'IMAGE(rx_total_count_nof_corrupted_arr(I)) &
-              " /= " & NATURAL'IMAGE(rx_exp_total_count_nof_corrupted_arr(I)) &
-              " = Expected count" SEVERITY ERROR;
-       END IF;
+      IF c_bg_nof_bps_total < 10.0**9 THEN
+        ASSERT tx_total_count_nof_packet_arr(I) = exp_total_count_nof_packet_arr(I) REPORT c_tb_str &
+            "Wrong Tx total nof packets count(" & NATURAL'IMAGE(I) &
+            "), Tx count = " & NATURAL'IMAGE(tx_total_count_nof_packet_arr(I)) &
+            " /= " & NATURAL'IMAGE(exp_total_count_nof_packet_arr(I)) &
+            " = Expected count" SEVERITY ERROR;
+
+        ASSERT rx_total_count_nof_packet_arr(I) = exp_total_count_nof_packet_arr(I) REPORT c_tb_str &
+            "Wrong Rx total nof packets count(" & NATURAL'IMAGE(I) &
+            "), Rx count = " & NATURAL'IMAGE(rx_total_count_nof_packet_arr(I)) &
+            " /= " & NATURAL'IMAGE(exp_total_count_nof_packet_arr(I)) &
+            " = Expected count" SEVERITY ERROR;
+
+        ASSERT rx_total_count_nof_valid_arr(I) = rx_exp_total_count_nof_valid_arr(I) REPORT c_tb_str &
+            "Wrong Rx total nof valids count(" & NATURAL'IMAGE(I) &
+            "), Rx count = " & NATURAL'IMAGE(rx_total_count_nof_valid_arr(I)) &
+            " /= " & NATURAL'IMAGE(rx_exp_total_count_nof_valid_arr(I)) &
+            " = Expected count" SEVERITY ERROR;
+
+        ASSERT rx_total_count_nof_corrupted_arr(I) = rx_exp_total_count_nof_corrupted_arr(I) REPORT c_tb_str &
+            "Wrong Rx total nof corrupted count(" & NATURAL'IMAGE(I) &
+            "), Rx count = " & NATURAL'IMAGE(rx_total_count_nof_corrupted_arr(I)) &
+            " /= " & NATURAL'IMAGE(rx_exp_total_count_nof_corrupted_arr(I)) &
+            " = Expected count" SEVERITY ERROR;
+      ELSE
+        -- Verify that Tx total nof packets = Rx total nof packets, also when
+        -- BG experiences siso.xon block level flow control, to stay below
+        -- 1 Gbps of the 1GbE link rate.
+        ASSERT tx_total_count_nof_packet_arr(I) = rx_total_count_nof_packet_arr(I) REPORT c_tb_str &
+            "Wrong Tx-Rx total nof packets count(" & NATURAL'IMAGE(I) &
+            "), Tx count = " & NATURAL'IMAGE(tx_total_count_nof_packet_arr(I)) &
+            " /= " & NATURAL'IMAGE(rx_total_count_nof_packet_arr(I)) &
+            " = Rx count" SEVERITY ERROR;
+      END IF;
     END LOOP;
 
     -------------------------------------------------------------------------
diff --git a/libraries/io/eth/tb/vhdl/tb_tb_eth_tester_high_bw.vhd b/libraries/io/eth/tb/vhdl/tb_tb_eth_tester_high_bw.vhd
index dfc4fc0cda..036d1641b5 100644
--- a/libraries/io/eth/tb/vhdl/tb_tb_eth_tester_high_bw.vhd
+++ b/libraries/io/eth/tb/vhdl/tb_tb_eth_tester_high_bw.vhd
@@ -1,6 +1,6 @@
 -------------------------------------------------------------------------------
 --
--- Copyright 2022
+-- Copyright 2023
 -- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
 -- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
 --
@@ -17,18 +17,17 @@
 -- limitations under the License.
 --
 -------------------------------------------------------------------------------
--- Author: E. Kooistra
--- Purpose: Multi test bench for eth_tester
--- Description: See detailed design in [1]
+-- Author: R. vd Walle
+-- Purpose: Multi test bench for eth_tester for high bandwidths.
+-- Description: Similar to the 1GbE TB as described in [1] but for 10 / 100 GbE.
 --
 -- References:
 -- [1] https://support.astron.nl/confluence/display/L2M/L6+FWLIB+Design+Document%3A+ETH+tester+unit+for+1GbE
--- [2] https://support.astron.nl/confluence/display/L2M/L4+SDPFW+Decision%3A+Application+header+size+in+Ethernet+packets
 --
 -- Usage:
 --   > as 8
 --   > run -all
---   Takes about 25 m
+--   Takes about 10 m
 
 LIBRARY IEEE, diag_lib;
 USE IEEE.std_logic_1164.ALL;
@@ -98,7 +97,6 @@ BEGIN
 --  g_tb_index         : NATURAL := 0;  -- use to incremental delay logging from tb instances in tb_tb
 --  g_nof_sync         : NATURAL := 3;  -- number of BG sync intervals to set c_run_time
 --  g_nof_streams      : NATURAL := 2;
---  g_corrupted_en     : BOOLEAN := FALSE;  -- when TRUE cause a corrupted Rx packet
 --  g_nof_octet_output   : NATURAL := 96; -- maximum = 96 bytes as max dp.data field = 768 bits.
 --  g_nof_octet_generate : NATURAL := 96;
 --
@@ -122,18 +120,18 @@ BEGIN
   -- Single stream
   -----------------------------------------------------------------------------
   -- Try different loopback interfaces
-  u_st_10g      : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (0, c_nof_sync, 1, FALSE, 8, 8, c_bg_ctrl_one, c_bg_ctrl_rst) PORT MAP (tb_end_vec(0)); -- 8 byte wide
-  u_st_100g     : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (1, c_nof_sync, 1, FALSE, 64, 64, c_bg_ctrl_one, c_bg_ctrl_rst) PORT MAP (tb_end_vec(1)); -- 64 byte wide
-  u_st_max      : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (2, c_nof_sync, 1, FALSE, 96, 96, c_bg_ctrl_one, c_bg_ctrl_rst) PORT MAP (tb_end_vec(2)); -- 96 byte wide as max dp.data width = 96*8=768 bits.
+  u_st_10g      : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (0, c_nof_sync, 1, 8, 8, c_bg_ctrl_one, c_bg_ctrl_rst) PORT MAP (tb_end_vec(0)); -- 8 byte wide
+  u_st_100g     : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (1, c_nof_sync, 1, 64, 64, c_bg_ctrl_one, c_bg_ctrl_rst) PORT MAP (tb_end_vec(1)); -- 64 byte wide
+  u_st_max      : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (2, c_nof_sync, 1, 96, 96, c_bg_ctrl_one, c_bg_ctrl_rst) PORT MAP (tb_end_vec(2)); -- 96 byte wide as max dp.data width = 96*8=768 bits.
 
   -- Try large block size and nof blocks_per_sync = 1
-  u_st_jumbo1   : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (10, c_nof_sync, 1, FALSE, 96, 96,
+  u_st_jumbo1   : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (10, c_nof_sync, 1, 96, 96,
                                                          ('1', '1', c_block_len_jumbo, 1, c_zero_gap, 0, c_high, 0),
                                                          c_bg_ctrl_rst)
                                             PORT MAP (tb_end_vec(10));
 
   -- Try large block sizes
-  u_st_jumbo2   : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (11, c_nof_sync, 1, FALSE, 64, 64,
+  u_st_jumbo2   : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (11, c_nof_sync, 1, 64, 64,
                                                          ('1', '1', c_block_len_jumbo, 2, c_zero_gap, 0, c_high, 0),
                                                          c_bg_ctrl_rst)
                                             PORT MAP (tb_end_vec(11));
@@ -144,23 +142,23 @@ BEGIN
   -- . BG supports samples_per_packet >= 2, BG treats samples_per_packet = 1 as 2
   -- . ETH MAC pads samples_per_packet <= 6 to 6, to have minimum packet length of 64 octets,
   --   because hdr = 14 + 20 + 8 + 12 and crc = 4 have 58 octets.
-  u_st_len2 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (20, c_nof_sync, 1, FALSE, 64, 64,
+  u_st_len2 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (20, c_nof_sync, 1, 64, 64,
                                                      ('1', '1', 2, c_nof_blk, c_gap_len, 0, c_high, 0),
                                                      c_bg_ctrl_rst)
                                         PORT MAP (tb_end_vec(20));
 
 
   -- Try different BG block lengths and data widths to verify sosi.empty nof octets in last word and repack.
-  u_st_bg_len_0 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (30, c_nof_sync, 1, FALSE, 64,  8, c_bg_ctrl_len_0, c_bg_ctrl_rst) PORT MAP (tb_end_vec(30));
-  u_st_bg_len_1 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (31, c_nof_sync, 1, FALSE, 8,   1, c_bg_ctrl_len_1, c_bg_ctrl_rst) PORT MAP (tb_end_vec(31));
-  u_st_bg_len_2 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (32, c_nof_sync, 1, FALSE, 8,   4, c_bg_ctrl_len_2, c_bg_ctrl_rst) PORT MAP (tb_end_vec(32));
-  u_st_bg_len_3 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (33, c_nof_sync, 1, FALSE, 64, 64, c_bg_ctrl_len_3, c_bg_ctrl_rst) PORT MAP (tb_end_vec(33));
+  u_st_bg_len_0 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (30, c_nof_sync, 1, 64,  8, c_bg_ctrl_len_0, c_bg_ctrl_rst) PORT MAP (tb_end_vec(30));
+  u_st_bg_len_1 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (31, c_nof_sync, 1, 8,   1, c_bg_ctrl_len_1, c_bg_ctrl_rst) PORT MAP (tb_end_vec(31));
+  u_st_bg_len_2 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (32, c_nof_sync, 1, 8,   4, c_bg_ctrl_len_2, c_bg_ctrl_rst) PORT MAP (tb_end_vec(32));
+  u_st_bg_len_3 : ENTITY work.tb_eth_tester_high_bw GENERIC MAP (33, c_nof_sync, 1, 64, 64, c_bg_ctrl_len_3, c_bg_ctrl_rst) PORT MAP (tb_end_vec(33));
 
   -----------------------------------------------------------------------------
   -- Multiple streams
   -----------------------------------------------------------------------------
   u_st_multiple_streams : ENTITY work.tb_eth_tester_high_bw
-                          GENERIC MAP (80, c_nof_sync, c_nof_streams, FALSE, 8, 8,
+                          GENERIC MAP (80, c_nof_sync, c_nof_streams, 8, 8,
                                        c_bg_ctrl_multiple_first,
                                        c_bg_ctrl_multiple_others)
                           PORT MAP (tb_end_vec(80));
-- 
GitLab