From f0334694e3abd3e0affe76cfb0aad221937ce12c Mon Sep 17 00:00:00 2001 From: Eric Kooistra <kooistra@astron.nl> Date: Tue, 15 Nov 2022 15:26:58 +0100 Subject: [PATCH] Move func_eth_tester_gn_index_*() functions from tb to component package. --- libraries/io/eth/src/vhdl/eth_tester_pkg.vhd | 68 ++++++++++++++++++- .../io/eth/tb/vhdl/tb_eth_tester_pkg.vhd | 20 ------ 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/libraries/io/eth/src/vhdl/eth_tester_pkg.vhd b/libraries/io/eth/src/vhdl/eth_tester_pkg.vhd index a60dc6c2e3..207728be05 100644 --- a/libraries/io/eth/src/vhdl/eth_tester_pkg.vhd +++ b/libraries/io/eth/src/vhdl/eth_tester_pkg.vhd @@ -35,6 +35,11 @@ PACKAGE eth_tester_pkg is CONSTANT c_eth_tester_rx_block_len_max : NATURAL := c_network_eth_payload_jumbo_max + c_network_eth_crc_len; -- 9004 octets CONSTANT c_eth_tester_eth_packet_len_max : NATURAL := c_network_eth_word_align_len + c_network_eth_frame_jumbo_max; -- 9020 octets = 2 word align + 14 header + 9000 + 4 crc + -- Support maximum (2**31-1)/200e6 = 10.7 s BG sync interval for sync timeout + -- in BSN monitors, assuming st_clk at 200 MHz and with maximum NATURAL value + -- of c_natural_high = 2**31 - 1. + CONSTANT c_eth_tester_sync_timeout : NATURAL := c_natural_high; + -- hdr_field_sel bit selects where the hdr_field value is set: -- . 0 = data path controlled, value is set in data path, so field_default() -- is not used. @@ -92,7 +97,7 @@ PACKAGE eth_tester_pkg is CONSTANT c_eth_tester_app_hdr_len : NATURAL := 12; -- octets - -- Destinations: + -- Source ETH MAC/IP/UDP: -- . MAC address 00:22:86:08:pp:qq = UNB_ETH_SRC_MAC_BASE in -- libraries/unb_osy/unbos_eth.h, pp = backplane ID, qq = node ID -- . IP address 10.99.xx.yy = g_base_ip in ctrl_unb2#_board.vhd used in @@ -116,6 +121,15 @@ PACKAGE eth_tester_pkg is app : t_eth_tester_app_header; END RECORD; + -- Map global node index on UniBoard2 to node src MAC, IP and UDP port + FUNCTION func_eth_tester_gn_index_to_mac_15_0(gn_index : NATURAL; eth_port_index : NATURAL) RETURN STD_LOGIC_VECTOR; + FUNCTION func_eth_tester_gn_index_to_mac_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR; -- default use 1GbE port I + FUNCTION func_eth_tester_gn_index_to_ip_15_0(gn_index : NATURAL; eth_port_index : NATURAL) RETURN STD_LOGIC_VECTOR; + FUNCTION func_eth_tester_gn_index_to_ip_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR; -- default use 1GbE port I + FUNCTION func_eth_tester_gn_index_to_udp_7_0(gn_index : NATURAL; eth_port_index : NATURAL) RETURN STD_LOGIC_VECTOR; + FUNCTION func_eth_tester_gn_index_to_udp_7_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR; -- default use 1GbE port I + + -- Map packet header fields to t_eth_tester_header record FUNCTION func_eth_tester_map_header(hdr_fields_raw : STD_LOGIC_VECTOR) RETURN t_eth_tester_header; END eth_tester_pkg; @@ -123,6 +137,58 @@ END eth_tester_pkg; PACKAGE BODY eth_tester_pkg IS + FUNCTION func_eth_tester_gn_index_to_mac_15_0(gn_index : NATURAL; eth_port_index : NATURAL) RETURN STD_LOGIC_VECTOR IS + -- Assume gn_index < 256. + -- Use default address for 1GbE II (eth_port_index = 0) and + -- an address offset for 1GbE II (eth_port_index = 1) + CONSTANT c_unb_nr : NATURAL := gn_index / c_4; -- 4 PN per Uniboard2 + CONSTANT c_node_nr : NATURAL := gn_index MOD c_4; + CONSTANT c_offset : NATURAL := eth_port_index * c_4; + CONSTANT c_mac_15_0 : STD_LOGIC_VECTOR(15 DOWNTO 0) := TO_UVEC(c_unb_nr, 8) & TO_UVEC(c_node_nr + c_offset, 8); + BEGIN + RETURN c_mac_15_0; + END func_eth_tester_gn_index_to_mac_15_0; + + FUNCTION func_eth_tester_gn_index_to_mac_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR IS + BEGIN + RETURN func_eth_tester_gn_index_to_mac_15_0(gn_index, 0); -- default use 1GbE port I + END func_eth_tester_gn_index_to_mac_15_0; + + + FUNCTION func_eth_tester_gn_index_to_ip_15_0(gn_index : NATURAL; eth_port_index : NATURAL) RETURN STD_LOGIC_VECTOR IS + -- Assume gn_index < 256. + -- Use default address for 1GbE II (eth_port_index = 0) and + -- an address offset for 1GbE II (eth_port_index = 1) + CONSTANT c_unb_nr : NATURAL := gn_index / c_4; -- 4 PN per Uniboard2 + CONSTANT c_node_nr : NATURAL := gn_index MOD c_4; + CONSTANT c_offset : NATURAL := eth_port_index * c_4; + CONSTANT c_ip_15_0 : STD_LOGIC_VECTOR(15 DOWNTO 0) := TO_UVEC(c_unb_nr, 8) & TO_UVEC(c_node_nr + 1 + c_offset, 8); -- +1 to avoid IP = *.*.*.0 + BEGIN + RETURN c_ip_15_0; + END func_eth_tester_gn_index_to_ip_15_0; + + FUNCTION func_eth_tester_gn_index_to_ip_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR IS + BEGIN + RETURN func_eth_tester_gn_index_to_ip_15_0(gn_index, 0); -- default use 1GbE port I + END func_eth_tester_gn_index_to_ip_15_0; + + + FUNCTION func_eth_tester_gn_index_to_udp_7_0(gn_index : NATURAL; eth_port_index : NATURAL) RETURN STD_LOGIC_VECTOR IS + -- Assume gn_index < 128. + -- Use default udp port for 1GbE I (eth_port_index = 0) and + -- an increment udp port for 1GbE II (eth_port_index = 1) + CONSTANT c_offset : NATURAL := eth_port_index * c_128; -- MSbit 7 + CONSTANT c_udp_7_0 : STD_LOGIC_VECTOR(7 DOWNTO 0) := TO_UVEC(gn_index + c_offset, 8); + BEGIN + RETURN c_udp_7_0; + END func_eth_tester_gn_index_to_udp_7_0; + + FUNCTION func_eth_tester_gn_index_to_udp_7_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR IS + BEGIN + RETURN func_eth_tester_gn_index_to_udp_7_0(gn_index, 0); -- default use 1GbE port I + END func_eth_tester_gn_index_to_udp_7_0; + + FUNCTION func_eth_tester_map_header(hdr_fields_raw : STD_LOGIC_VECTOR) RETURN t_eth_tester_header IS VARIABLE v : t_eth_tester_header; BEGIN diff --git a/libraries/io/eth/tb/vhdl/tb_eth_tester_pkg.vhd b/libraries/io/eth/tb/vhdl/tb_eth_tester_pkg.vhd index e0fd29ce23..4705b6f018 100644 --- a/libraries/io/eth/tb/vhdl/tb_eth_tester_pkg.vhd +++ b/libraries/io/eth/tb/vhdl/tb_eth_tester_pkg.vhd @@ -39,10 +39,6 @@ PACKAGE tb_eth_tester_pkg is CONSTANT c_eth_tester_ip_dst_addr : STD_LOGIC_VECTOR(31 DOWNTO 0) := x"0A6300FE"; -- 0A6300FE = '10.99.0.254' = DOP36-enp2s0 CONSTANT c_eth_tester_udp_dst_port : STD_LOGIC_VECTOR(15 DOWNTO 0) := TO_UVEC(6001, 16); -- 0x1771 = 6001 - -- Map global node index on UniBoard2 to node MAC address and node IP address - FUNCTION func_eth_tester_gn_index_to_mac_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR; - FUNCTION func_eth_tester_gn_index_to_ip_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR; - -- Ethernet packet length in octets inclduing eth header and CRC FUNCTION func_eth_tester_eth_packet_length(block_len : NATURAL) RETURN NATURAL; @@ -54,22 +50,6 @@ END tb_eth_tester_pkg; PACKAGE BODY tb_eth_tester_pkg IS - FUNCTION func_eth_tester_gn_index_to_mac_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR IS - CONSTANT c_unb_nr : NATURAL := gn_index / 4; -- 4 PN per Uniboard2 - CONSTANT c_node_nr : NATURAL := gn_index MOD 4; - CONSTANT c_mac_15_0 : STD_LOGIC_VECTOR(15 DOWNTO 0) := TO_UVEC(c_unb_nr, 8) & TO_UVEC(c_node_nr, 8); - BEGIN - RETURN c_mac_15_0; - END func_eth_tester_gn_index_to_mac_15_0; - - FUNCTION func_eth_tester_gn_index_to_ip_15_0(gn_index : NATURAL) RETURN STD_LOGIC_VECTOR IS - CONSTANT c_unb_nr : NATURAL := gn_index / 4; -- 4 PN per Uniboard2 - CONSTANT c_node_nr : NATURAL := gn_index MOD 4; - CONSTANT c_ip_15_0 : STD_LOGIC_VECTOR(15 DOWNTO 0) := TO_UVEC(c_unb_nr, 8) & TO_UVEC(c_node_nr+1, 8); -- +1 to avoid IP = *.*.*.0 - BEGIN - RETURN c_ip_15_0; - END func_eth_tester_gn_index_to_ip_15_0; - FUNCTION func_eth_tester_eth_packet_length(block_len : NATURAL) RETURN NATURAL IS CONSTANT c_app_len : NATURAL := c_eth_tester_app_hdr_len + block_len; CONSTANT c_udp_len : NATURAL := c_network_udp_header_len + c_app_len; -- GitLab