diff --git a/libraries/io/eth/src/vhdl/eth_hdr.vhd b/libraries/io/eth/src/vhdl/eth_hdr.vhd new file mode 100644 index 0000000000000000000000000000000000000000..cf8e08a1cbea4a2f9b98ebfe1f395a0c3a174800 --- /dev/null +++ b/libraries/io/eth/src/vhdl/eth_hdr.vhd @@ -0,0 +1,171 @@ +------------------------------------------------------------------------------- +-- +-- Copyright (C) 2010 +-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/> +-- JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/> +-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. +-- +------------------------------------------------------------------------------- + +LIBRARY IEEE, common_lib, dp_lib; +USE IEEE.std_logic_1164.ALL; +USE IEEE.numeric_std.ALL; +USE common_lib.common_pkg.ALL; +USE dp_lib.dp_stream_pkg.ALL; +USE common_lib.eth_layers_pkg.ALL; +USE work.eth_pkg.ALL; + +-- Description: +-- . Store the 11 word header and make the header info available for monitoring +-- . Direct snk to src via g_header_store_and_forward = FALSE +-- . Store and forward the header via g_header_store_and_forward = TRUE to allow: +-- 1) IP header checksum insertion for IP frames when g_ip_header_checksum_calculate = TRUE +-- 2) Discard frames that are shorter than 11 words (the minimal header size) +-- 3) Support option to discard frames based on their header info + +ENTITY eth_hdr IS + GENERIC ( + g_header_store_and_forward : BOOLEAN := TRUE; + g_ip_header_checksum_calculate : BOOLEAN := TRUE + ); + PORT ( + -- Clocks and reset + rst : IN STD_LOGIC; -- reset synchronous with clk + clk : IN STD_LOGIC; -- packet stream clock + + -- Streaming Sink + snk_in : IN t_dp_sosi; + snk_out : OUT t_dp_siso; + + -- Streaming Source + src_in : IN t_dp_siso := c_dp_siso_rdy; + src_out : OUT t_dp_sosi; + + -- Frame control + frm_discard : IN STD_LOGIC := '0'; + + -- Header info + hdr_words : OUT t_eth_total_header_arr; + hdr_words_val : OUT STD_LOGIC_VECTOR(0 TO c_eth_total_header_nof_words-1); + hdr_fields : OUT t_eth_total_header; + hdr_fields_val : OUT STD_LOGIC_VECTOR(0 TO c_eth_total_header_nof_words-1); + hdr_data : OUT STD_LOGIC_VECTOR(c_word_w-1 DOWNTO 0); + hdr_data_val : OUT STD_LOGIC; + hdr_status : OUT t_eth_hdr_status + ); +END eth_hdr; + + +ARCHITECTURE str OF eth_hdr IS + + -- Internal sink ready latency and source ready latency of this component + CONSTANT c_this_snk_latency : NATURAL := 1; + CONSTANT c_this_src_latency : NATURAL := 1; + + SIGNAL snk_in_word_cnt : NATURAL RANGE 0 TO c_eth_total_header_nof_words; + + -- Extract total header + SIGNAL i_hdr_words : t_eth_total_header_arr; + SIGNAL i_hdr_words_val : STD_LOGIC_VECTOR(0 TO c_eth_total_header_nof_words-1); + SIGNAL i_hdr_fields : t_eth_total_header; + SIGNAL i_hdr_fields_val : STD_LOGIC_VECTOR(0 TO c_eth_total_header_nof_words-1); + SIGNAL i_hdr_data : STD_LOGIC_VECTOR(c_word_w-1 DOWNTO 0); + SIGNAL i_hdr_data_val : STD_LOGIC; + SIGNAL i_hdr_status : t_eth_hdr_status; + +BEGIN + + -- Make all header info available + hdr_words <= i_hdr_words; + hdr_words_val <= i_hdr_words_val ; + hdr_fields <= i_hdr_fields; + hdr_fields_val <= i_hdr_fields_val; + hdr_data <= i_hdr_data; + hdr_data_val <= i_hdr_data_val; + hdr_status <= i_hdr_status; + + ------------------------------------------------------------------------------ + -- IP header checksum control + ------------------------------------------------------------------------------ + + gen_ctrl : IF g_header_store_and_forward=TRUE GENERATE + -- Replace IP header checksum with the calculated checksum in case of IPv4, else pass on unchanged but discard frames shorter than 11 words + u_ip_hdr_ctrl : ENTITY work.eth_hdr_ctrl + PORT MAP ( + -- Clocks and reset + rst => rst, + clk => clk, + + -- Stored header + hdr_words => i_hdr_words, + hdr_status => i_hdr_status, + + -- ST interface + snk_in_word_cnt => snk_in_word_cnt, + snk_in => snk_in, + snk_out => snk_out, + src_in => src_in, + src_out => src_out + ); + END GENERATE; + + no_ctrl : IF g_header_store_and_forward=FALSE GENERATE + -- Avoid the store and forward logic of eth_hdr_ctrl if it is not needed, although it would work OK to use it + src_out <= snk_in; + snk_out <= src_in; + END GENERATE; + + ------------------------------------------------------------------------------ + -- Extract total header + ------------------------------------------------------------------------------ + + -- Store 11 header words + u_hdr_store : ENTITY work.eth_hdr_store + PORT MAP ( + rst => rst, + clk => clk, + -- Streaming Sink + snk_in => snk_in, + snk_in_word_cnt => snk_in_word_cnt, + -- Total header + hdr_words => i_hdr_words, + hdr_words_val => i_hdr_words_val, + hdr_fields => i_hdr_fields, + hdr_fields_val => i_hdr_fields_val, + hdr_data => i_hdr_data, + hdr_data_val => i_hdr_data_val + ); + + -- Determine header status + u_hdr_status : ENTITY work.eth_hdr_status + GENERIC MAP ( + g_ip_header_checksum_calculate => g_ip_header_checksum_calculate + ) + PORT MAP ( + rst => rst, + clk => clk, + -- Total header + hdr_words => i_hdr_words, + hdr_words_val => i_hdr_words_val, + hdr_fields => i_hdr_fields, + hdr_fields_val => i_hdr_fields_val, + hdr_data => i_hdr_data, + hdr_data_val => i_hdr_data_val, + -- Header status + hdr_status => i_hdr_status + ); + +END str;