From 4828f068055c4f9c7e9eb4b34776ef7a78f20a7e Mon Sep 17 00:00:00 2001 From: Michael Boehmer Date: Sun, 13 Nov 2022 23:22:01 +0100 Subject: [PATCH] cleanup ongoing --- gbe_trb/base/gbe_frame_constr.vhd | 190 +++++------ gbe_trb/base/gbe_logic_wrapper.vhd | 23 +- gbe_trb/base/gbe_protocol_selector.vhd | 21 +- gbe_trb/base/gbe_receive_control.vhd | 11 +- gbe_trb/base/gbe_transmit_control.vhd | 424 +++++++++++++------------ gbe_trb/base/gbe_wrapper_fifo.vhd | 4 +- 6 files changed, 338 insertions(+), 335 deletions(-) diff --git a/gbe_trb/base/gbe_frame_constr.vhd b/gbe_trb/base/gbe_frame_constr.vhd index 497cdd1..50fe120 100644 --- a/gbe_trb/base/gbe_frame_constr.vhd +++ b/gbe_trb/base/gbe_frame_constr.vhd @@ -1,10 +1,9 @@ library IEEE; -use IEEE.std_logic_1164.ALL; -use IEEE.numeric_std.ALL; -use IEEE.std_logic_UNSIGNED.ALL; - + use IEEE.std_logic_1164.all; + use IEEE.numeric_std.all; + library work; -use work.trb_net_std.all; +-- use work.trb_net_std.all; entity gbe_frame_constr is port( @@ -53,8 +52,8 @@ architecture gbe_frame_constr_arch of gbe_frame_constr is TOS_S, IP_LENGTH, IDENT, FLAGS, TTL_S, PROTO, HEADER_CS, SRC_IP_ADDR, DEST_IP_ADDR, SRC_PORT, DEST_PORT, UDP_LENGTH, UDP_CS, SAVE_DATA, CLEANUP, DELAY); - signal constructCurrentState, constructNextState : constructStates; - attribute syn_encoding of constructCurrentState: signal is "onehot"; + signal CONSTRUCT_CS, CONSTRUCT_NS : constructStates; + attribute syn_encoding of CONSTRUCT_CS: signal is "onehot"; signal headers_int_counter : integer range 0 to 6; signal fpf_data : std_logic_vector(7 downto 0); @@ -62,20 +61,20 @@ architecture gbe_frame_constr_arch of gbe_frame_constr is signal fpf_rd_en : std_logic; signal fpf_rd_en_q : std_logic; signal fpf_q : std_logic_vector(8 downto 0); - signal ip_size : std_logic_vector(15 downto 0); - signal ip_checksum : std_logic_vector(31 downto 0); - signal udp_size : std_logic_vector(15 downto 0); - signal udp_checksum : std_logic_vector(15 downto 0); + signal ip_size : unsigned(15 downto 0); + signal ip_checksum : unsigned(31 downto 0); + signal udp_size : unsigned(15 downto 0); + signal udp_checksum : unsigned(15 downto 0); signal put_udp_headers : std_logic; signal ready : std_logic; signal headers_ready : std_logic; signal cur_max : integer range 0 to 10; - signal ip_cs_temp_right : std_logic_vector(15 downto 0); + signal ip_cs_temp_right : unsigned(15 downto 0); - signal delay_ctr : std_logic_vector(31 downto 0); - signal frame_delay_reg : std_logic_vector(31 downto 0); +-- signal delay_ctr : std_logic_vector(31 downto 0); +-- signal frame_delay_reg : std_logic_vector(31 downto 0); signal fpf_data_q : std_logic_vector(7 downto 0); signal fpf_wr_en_q : std_logic; signal fpf_eod_q : std_logic; @@ -92,13 +91,13 @@ begin PROC_READY: process( CLK ) begin if( rising_edge(CLK) )then - if( constructCurrentState = IDLE ) then + if( CONSTRUCT_CS = IDLE ) then ready <= '1'; else ready <= '0'; end if; - if( constructCurrentState = SAVE_DATA ) then + if( CONSTRUCT_CS = SAVE_DATA ) then headers_ready <= '1'; else headers_ready <= '0'; @@ -111,11 +110,11 @@ begin begin if( rising_edge(CLK) ) then if( (put_udp_headers = '1') and (DEST_UDP_PORT_IN /= x"0000") ) then - ip_size <= IP_F_SIZE_IN + x"14" + x"8"; - udp_size <= UDP_P_SIZE_IN + x"8"; + ip_size <= unsigned(IP_F_SIZE_IN) + x"14" + x"8"; + udp_size <= unsigned(UDP_P_SIZE_IN) + x"8"; else - ip_size <= IP_F_SIZE_IN + x"14"; - udp_size <= UDP_P_SIZE_IN; + ip_size <= unsigned(IP_F_SIZE_IN) + x"14"; + udp_size <= unsigned(UDP_P_SIZE_IN); end if; end if; end process PROC_SIZE; @@ -123,36 +122,36 @@ begin PROC_IP_CS : process( CLK ) begin if( rising_edge(CLK) ) then - if( constructCurrentState = IDLE ) then + if( CONSTRUCT_CS = IDLE ) then ip_checksum <= x"00000000"; else - case constructCurrentState is + case CONSTRUCT_CS is when DEST_MAC_ADDR => case headers_int_counter is when 0 => - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + SRC_IP_ADDRESS_IN(7 downto 0); + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(SRC_IP_ADDRESS_IN(7 downto 0)); when 1 => - ip_checksum <= ip_checksum + SRC_IP_ADDRESS_IN(15 downto 8); + ip_checksum <= ip_checksum + unsigned(SRC_IP_ADDRESS_IN(15 downto 8)); when 2 => - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + SRC_IP_ADDRESS_IN(23 downto 16); + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(SRC_IP_ADDRESS_IN(23 downto 16)); when 3 => - ip_checksum <= ip_checksum + SRC_IP_ADDRESS_IN(31 downto 24); + ip_checksum <= ip_checksum + unsigned(SRC_IP_ADDRESS_IN(31 downto 24)); when 4 => - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + DEST_IP_ADDRESS_IN(7 downto 0); + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(DEST_IP_ADDRESS_IN(7 downto 0)); when 5 => - ip_checksum <= ip_checksum + DEST_IP_ADDRESS_IN(15 downto 8); + ip_checksum <= ip_checksum + unsigned(DEST_IP_ADDRESS_IN(15 downto 8)); when others => null; end case; when SRC_MAC_ADDR => case headers_int_counter is when 0 => - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + DEST_IP_ADDRESS_IN(23 downto 16); + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(DEST_IP_ADDRESS_IN(23 downto 16)); when 1 => - ip_checksum <= ip_checksum + DEST_IP_ADDRESS_IN(31 downto 24); + ip_checksum <= ip_checksum + unsigned(DEST_IP_ADDRESS_IN(31 downto 24)); when 2 => - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + IHL_VERSION_IN; + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(IHL_VERSION_IN); when 3 => - ip_checksum <= ip_checksum + TOS_IN; + ip_checksum <= ip_checksum + unsigned(TOS_IN); when 4 => ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + ip_size(15 downto 8); when 5 => @@ -161,23 +160,23 @@ begin end case; when VERSION => if( headers_int_counter = 0 ) then - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + IDENTIFICATION_IN(7 downto 0); + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(IDENTIFICATION_IN(7 downto 0)); end if; when TOS_S => if( headers_int_counter = 0 ) then - ip_checksum <= ip_checksum + IDENTIFICATION_IN(15 downto 8); + ip_checksum <= ip_checksum + unsigned(IDENTIFICATION_IN(15 downto 8)); end if; when IP_LENGTH => if( headers_int_counter = 0 ) then - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + FLAGS_OFFSET_IN(15 downto 8); + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(FLAGS_OFFSET_IN(15 downto 8)); elsif headers_int_counter = 1 then - ip_checksum <= ip_checksum + FLAGS_OFFSET_IN(7 downto 0); + ip_checksum <= ip_checksum + unsigned(FLAGS_OFFSET_IN(7 downto 0)); end if; when IDENT => if headers_int_counter = 0 then - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + TTL_IN; + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + unsigned(TTL_IN); elsif headers_int_counter = 1 then - ip_checksum <= ip_checksum + PROTOCOL_IN; + ip_checksum <= ip_checksum + unsigned(PROTOCOL_IN); end if; -- gk 29.03.10 corrected the bug with bad checksums when sum larger than 16b when FLAGS => @@ -200,106 +199,109 @@ begin end if; end process PROC_IP_CS; - PROC_CONSTRUCT: process( CLK, RESET ) begin if ( RESET = '1' ) then - constructCurrentState <= IDLE; + CONSTRUCT_CS <= IDLE; elsif( rising_edge(CLK) ) then - constructCurrentState <= constructNextState; + CONSTRUCT_CS <= CONSTRUCT_NS; end if; end process PROC_CONSTRUCT; --find next state of construct machine - PROC_CONSTRUCT_TRANSITIONS: process( constructCurrentState, delay_ctr, FRAME_DELAY_IN, START_OF_DATA_IN, +-- PROC_CONSTRUCT_TRANSITIONS: process( CONSTRUCT_CS, delay_ctr, FRAME_DELAY_IN, START_OF_DATA_IN, +-- END_OF_DATA_IN, headers_int_counter, put_udp_headers, CUR_MAX, +-- FRAME_TYPE_IN, DEST_UDP_PORT_IN) + PROC_CONSTRUCT_TRANSITIONS: process( CONSTRUCT_CS, START_OF_DATA_IN, END_OF_DATA_IN, headers_int_counter, put_udp_headers, CUR_MAX, FRAME_TYPE_IN, DEST_UDP_PORT_IN) begin - constructNextState <= constructCurrentState; + CONSTRUCT_NS <= CONSTRUCT_CS; if( headers_int_counter = cur_max ) then --can be checked everytime - if not in use, counter and cur_max are 0 - case constructCurrentState is + case CONSTRUCT_CS is when IDLE => if( START_OF_DATA_IN = '1' ) then - constructNextState <= DEST_MAC_ADDR; + CONSTRUCT_NS <= DEST_MAC_ADDR; end if; when DEST_MAC_ADDR => - constructNextState <= SRC_MAC_ADDR; + CONSTRUCT_NS <= SRC_MAC_ADDR; when SRC_MAC_ADDR => - constructNextState <= FRAME_TYPE_S; + CONSTRUCT_NS <= FRAME_TYPE_S; when FRAME_TYPE_S => if( FRAME_TYPE_IN = x"0008" ) then - constructNextState <= VERSION; + CONSTRUCT_NS <= VERSION; else -- otherwise transmit data as pure ethernet frame - constructNextState <= SAVE_DATA; + CONSTRUCT_NS <= SAVE_DATA; end if; when VERSION => - constructNextState <= TOS_S; + CONSTRUCT_NS <= TOS_S; when TOS_S => - constructNextState <= IP_LENGTH; + CONSTRUCT_NS <= IP_LENGTH; when IP_LENGTH => - constructNextState <= IDENT; + CONSTRUCT_NS <= IDENT; when IDENT => - constructNextState <= FLAGS; + CONSTRUCT_NS <= FLAGS; when FLAGS => - constructNextState <= TTL_S; + CONSTRUCT_NS <= TTL_S; when TTL_S => - constructNextState <= PROTO; + CONSTRUCT_NS <= PROTO; when PROTO => - constructNextState <= HEADER_CS; + CONSTRUCT_NS <= HEADER_CS; when HEADER_CS => - constructNextState <= SRC_IP_ADDR; + CONSTRUCT_NS <= SRC_IP_ADDR; when SRC_IP_ADDR => - constructNextState <= DEST_IP_ADDR; + CONSTRUCT_NS <= DEST_IP_ADDR; when DEST_IP_ADDR => if( (put_udp_headers = '1') and (DEST_UDP_PORT_IN /= x"0000") ) then - constructNextState <= SRC_PORT; + CONSTRUCT_NS <= SRC_PORT; else - constructNextState <= SAVE_DATA; + CONSTRUCT_NS <= SAVE_DATA; end if; when SRC_PORT => - constructNextState <= DEST_PORT; + CONSTRUCT_NS <= DEST_PORT; when DEST_PORT => - constructNextState <= UDP_LENGTH; + CONSTRUCT_NS <= UDP_LENGTH; when UDP_LENGTH => - constructNextState <= UDP_CS; + CONSTRUCT_NS <= UDP_CS; when UDP_CS => - constructNextState <= SAVE_DATA; + CONSTRUCT_NS <= SAVE_DATA; when SAVE_DATA => if( END_OF_DATA_IN = '1' ) then - constructNextState <= CLEANUP; + CONSTRUCT_NS <= CLEANUP; end if; when CLEANUP => - constructNextState <= DELAY; + CONSTRUCT_NS <= DELAY; when DELAY => - if (delay_ctr = FRAME_DELAY_IN) then - constructNextState <= IDLE; - else - constructNextState <= DELAY; - end if; + CONSTRUCT_NS <= IDLE; +-- if (delay_ctr = FRAME_DELAY_IN) then +-- CONSTRUCT_NS <= IDLE; +-- else +-- CONSTRUCT_NS <= DELAY; +-- end if; when others => - constructNextState <= IDLE; + CONSTRUCT_NS <= IDLE; end case; end if; end process PROC_CONSTRUCT_TRANSITIONS; - PROC_DELAY_CTR: process( CLK ) - begin - if( rising_edge(CLK) ) then - if ( (constructCurrentState = IDLE) or (constructCurrentState = CLEANUP) ) then - delay_ctr <= (others => '0'); - elsif( constructCurrentState = DELAY ) then - delay_ctr <= delay_ctr + x"1"; - end if; - - frame_delay_reg <= FRAME_DELAY_IN; - end if; - end process PROC_DELAY_CTR; - - PROC_BSM_CONSTR: process( constructCurrentState ) +-- PROC_DELAY_CTR: process( CLK ) +-- begin +-- if( rising_edge(CLK) ) then +-- if ( (CONSTRUCT_CS = IDLE) or (CONSTRUCT_CS = CLEANUP) ) then +-- delay_ctr <= (others => '0'); +-- elsif( CONSTRUCT_CS = DELAY ) then +-- delay_ctr <= delay_ctr + x"1"; +-- end if; +-- +-- frame_delay_reg <= FRAME_DELAY_IN; +-- end if; +-- end process PROC_DELAY_CTR; + + PROC_BSM_CONSTR: process( CONSTRUCT_CS ) begin --find maximum time in each state & set state bits - case constructCurrentState is + case CONSTRUCT_CS is when IDLE => cur_max <= 0; when DEST_MAC_ADDR => cur_max <= 5; when SRC_MAC_ADDR => cur_max <= 5; @@ -328,7 +330,7 @@ begin PROC_HEADERS_INT: process( CLK ) begin if( rising_edge(CLK) ) then - if( constructCurrentState = IDLE ) then + if( CONSTRUCT_CS = IDLE ) then headers_int_counter <= 0; else if( headers_int_counter = cur_max ) then @@ -351,25 +353,25 @@ begin end if; end process PROC_PUT_UDP_HEADERS; - PROC_FPF_WREN: process( constructCurrentState, WR_EN_IN, LINK_OK_IN ) + PROC_FPF_WREN: process( CONSTRUCT_CS, WR_EN_IN, LINK_OK_IN ) begin if ( LINK_OK_IN = '0' ) then fpf_wr_en <= '0'; - elsif( (constructCurrentState /= IDLE) and (constructCurrentState /= CLEANUP) and (constructCurrentState /= SAVE_DATA) and (constructCurrentState /= DELAY) ) then + elsif( (CONSTRUCT_CS /= IDLE) and (CONSTRUCT_CS /= CLEANUP) and (CONSTRUCT_CS /= SAVE_DATA) and (CONSTRUCT_CS /= DELAY) ) then fpf_wr_en <= '1'; - elsif( (constructCurrentState = SAVE_DATA) and (WR_EN_IN = '1') ) then + elsif( (CONSTRUCT_CS = SAVE_DATA) and (WR_EN_IN = '1') ) then fpf_wr_en <= '1'; else fpf_wr_en <= '0'; end if; end process PROC_FPF_WREN; - PROC_FPF_DATA: process( constructCurrentState, DEST_MAC_ADDRESS_IN, SRC_MAC_ADDRESS_IN, FRAME_TYPE_IN, IHL_VERSION_IN, + PROC_FPF_DATA: process( CONSTRUCT_CS, DEST_MAC_ADDRESS_IN, SRC_MAC_ADDRESS_IN, FRAME_TYPE_IN, IHL_VERSION_IN, TOS_IN, ip_size, IDENTIFICATION_IN, FLAGS_OFFSET_IN, TTL_IN, PROTOCOL_IN, ip_checksum, SRC_IP_ADDRESS_IN, DEST_IP_ADDRESS_IN, SRC_UDP_PORT_IN, DEST_UDP_PORT_IN, udp_size, udp_checksum, headers_int_counter, DATA_IN ) begin - case constructCurrentState is + case CONSTRUCT_CS is when IDLE => fpf_data <= DEST_MAC_ADDRESS_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); when DEST_MAC_ADDR => fpf_data <= DEST_MAC_ADDRESS_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); when SRC_MAC_ADDR => fpf_data <= SRC_MAC_ADDRESS_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); @@ -381,7 +383,7 @@ begin when FLAGS => fpf_data <= FLAGS_OFFSET_IN(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); when TTL_S => fpf_data <= TTL_IN; when PROTO => fpf_data <= PROTOCOL_IN; - when HEADER_CS => fpf_data <= x"ff" - ip_checksum(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); + when HEADER_CS => fpf_data <= std_logic_vector(x"ff" - ip_checksum(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8)); when SRC_IP_ADDR => fpf_data <= SRC_IP_ADDRESS_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); when DEST_IP_ADDR => fpf_data <= DEST_IP_ADDRESS_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); when SRC_PORT => fpf_data <= SRC_UDP_PORT_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); diff --git a/gbe_trb/base/gbe_logic_wrapper.vhd b/gbe_trb/base/gbe_logic_wrapper.vhd index f2eae3a..26bed21 100644 --- a/gbe_trb/base/gbe_logic_wrapper.vhd +++ b/gbe_trb/base/gbe_logic_wrapper.vhd @@ -7,13 +7,13 @@ library work; entity gbe_logic_wrapper is generic( - INCLUDE_SLOWCTRL : std_logic := '0'; - INCLUDE_DHCP : std_logic := '0'; - INCLUDE_ARP : std_logic := '0'; - INCLUDE_PING : std_logic := '0'; - INCLUDE_FWD : std_logic := '0'; - INCLUDE_DISCOVERY : std_logic := '0'; - SLOWCTRL_BUFFER_SIZE : integer range 1 to 4 := 1 + INCLUDE_SLOWCTRL : std_logic := '0'; + INCLUDE_DHCP : std_logic := '0'; + INCLUDE_ARP : std_logic := '0'; + INCLUDE_PING : std_logic := '0'; + INCLUDE_FWD : std_logic := '0'; + INCLUDE_DISCOVERY : std_logic := '0'; + SLOWCTRL_BUFFER_SIZE : integer range 1 to 4 := 1 ); port( CLK_125_IN : in std_logic; @@ -190,9 +190,6 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- - DHCP_DONE_OUT <= dhcp_done; - MY_IP_OUT <= my_ip; - THE_GBE_MAIN_CONTROL: entity work.gbe_main_control generic map( INCLUDE_SLOWCTRL => INCLUDE_SLOWCTRL, @@ -274,7 +271,9 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is ); MAKE_RESET_OUT <= make_reset; - + DHCP_DONE_OUT <= dhcp_done; + MY_IP_OUT <= my_ip; + THE_TRANSMIT_CONTROL: entity work.gbe_transmit_control port map( CLK => CLK_125_IN, @@ -341,7 +340,7 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is TOS_IN => x"10", IDENTIFICATION_IN => fc_ident, FLAGS_OFFSET_IN => fc_flags_offset, - TTL_IN => x"ff", + TTL_IN => x"40", PROTOCOL_IN => fc_protocol, FRAME_DELAY_IN => frame_pause, FT_TX_DATA_OUT => FT_TX_DATA_OUT, diff --git a/gbe_trb/base/gbe_protocol_selector.vhd b/gbe_trb/base/gbe_protocol_selector.vhd index 7534b36..c49cf88 100644 --- a/gbe_trb/base/gbe_protocol_selector.vhd +++ b/gbe_trb/base/gbe_protocol_selector.vhd @@ -3,7 +3,7 @@ library ieee; use ieee.numeric_std.all; library work; - use work.gbe_protocols.all; +-- use work.gbe_protocols.all; entity gbe_protocol_selector is generic( @@ -223,7 +223,6 @@ begin DEBUG_OUT => debug_dhcp ); --- PROC_SELECT_IP: process( DHCP_DISABLE_IN, my_dhcp_ip, MY_STATIC_IP_IN ) PROC_SELECT_IP: process( CLK ) begin if( rising_edge(CLK) ) then @@ -469,14 +468,14 @@ begin end if; end process PROC_SELECT_MACHINE; - PROC_SELECT_TRANSITIONS: process(select_current_state, MC_BUSY_IN, resp_ready, index, zeros, busy) + PROC_SELECT_TRANSITIONS: process( select_current_state, MC_BUSY_IN, resp_ready, index, zeros, busy ) begin select_state <= x"0"; case (select_current_state) is when IDLE => select_state <= x"1"; - if (MC_BUSY_IN = '0') then + if( MC_BUSY_IN = '0' ) then select_next_state <= LOOP_OVER; else select_next_state <= IDLE; @@ -484,10 +483,10 @@ begin when LOOP_OVER => select_state <= x"2"; - if (resp_ready /= zeros) then - if (resp_ready(index) = '1') then + if( resp_ready /= zeros ) then + if( resp_ready(index) = '1' ) then select_next_state <= SELECT_ONE; - elsif (index = 8) then + elsif( index = 8 ) then select_next_state <= CLEANUP; else select_next_state <= LOOP_OVER; @@ -498,7 +497,7 @@ begin when SELECT_ONE => select_state <= x"3"; - if (MC_BUSY_IN = '1') then + if( MC_BUSY_IN = '1' ) then select_next_state <= PROCESS_REQUEST; else select_next_state <= SELECT_ONE; @@ -506,7 +505,7 @@ begin when PROCESS_REQUEST => select_state <= x"4"; - if (busy(index) = '0') then + if( busy(index) = '0' ) then select_next_state <= CLEANUP; else select_next_state <= PROCESS_REQUEST; @@ -516,7 +515,9 @@ begin select_state <= x"5"; select_next_state <= IDLE; - when others => select_next_state <= IDLE; + when others => + select_state <= x"f"; + select_next_state <= IDLE; end case; end process PROC_SELECT_TRANSITIONS; diff --git a/gbe_trb/base/gbe_receive_control.vhd b/gbe_trb/base/gbe_receive_control.vhd index 5fbb6fd..a1b368a 100644 --- a/gbe_trb/base/gbe_receive_control.vhd +++ b/gbe_trb/base/gbe_receive_control.vhd @@ -1,11 +1,10 @@ -LIBRARY IEEE; -USE IEEE.std_logic_1164.ALL; -USE IEEE.numeric_std.ALL; -USE IEEE.std_logic_UNSIGNED.ALL; +library IEEE; + use IEEE.std_logic_1164.all; + use IEEE.numeric_std.all; library work; -use work.trb_net_std.all; -use work.gbe_protocols.all; +-- use work.trb_net_std.all; +-- use work.gbe_protocols.all; -- BUG: use (not FIFO_EMPTY) from gbe_frame_receiver to indicate -- frames in queue. diff --git a/gbe_trb/base/gbe_transmit_control.vhd b/gbe_trb/base/gbe_transmit_control.vhd index 20394b8..4bddddc 100644 --- a/gbe_trb/base/gbe_transmit_control.vhd +++ b/gbe_trb/base/gbe_transmit_control.vhd @@ -1,11 +1,10 @@ -LIBRARY IEEE; -USE IEEE.std_logic_1164.ALL; -USE IEEE.numeric_std.ALL; -USE IEEE.std_logic_UNSIGNED.ALL; +library IEEE; + use IEEE.std_logic_1164.all; + use IEEE.numeric_std.all; library work; -use work.trb_net_std.all; -use work.gbe_protocols.all; +-- use work.trb_net_std.all; +-- use work.gbe_protocols.all; entity gbe_transmit_control is port ( @@ -56,246 +55,249 @@ end gbe_transmit_control; architecture gbe_transmit_control_arch of gbe_transmit_control is -attribute syn_encoding : string; + attribute syn_encoding : string; -type transmit_states is (IDLE, PREPARE_HEADERS, WAIT_FOR_H, TRANSMIT, SEND_ONE, SEND_TWO, CLOSE, WAIT_FOR_TRANS, DIVIDE, CLEANUP); -signal transmit_current_state, transmit_next_state : transmit_states; -attribute syn_encoding of transmit_current_state : signal is "onehot"; + type transmit_states is (IDLE, PREPARE_HEADERS, WAIT_FOR_H, TRANSMIT, SEND_ONE, SEND_TWO, CLOSE, WAIT_FOR_TRANS, DIVIDE, CLEANUP); + signal TRANSMIT_CS, TRANSMIT_NS : transmit_states; + attribute syn_encoding of TRANSMIT_CS : signal is "onehot"; -signal tc_rd, tc_rd_q, tc_rd_qq : std_logic; -signal local_end : std_logic_vector(15 downto 0); + signal tc_rd : std_logic; + signal tc_rd_q : std_logic; + signal tc_rd_qq : std_logic; + signal local_end : unsigned(15 downto 0); -signal actual_frame_bytes, full_packet_size, ip_size, packet_loaded_bytes : std_logic_vector(15 downto 0); -signal go_to_divide, more_fragments : std_logic; -signal first_frame : std_logic; -signal mon_packets_sent_ctr : std_logic_vector(31 downto 0); -signal state : std_logic_vector(3 downto 0); + signal actual_frame_bytes : unsigned(15 downto 0); + signal full_packet_size : unsigned(15 downto 0); + signal ip_size : unsigned(15 downto 0); + signal packet_loaded_bytes : unsigned(15 downto 0); + signal go_to_divide : std_logic; + signal more_fragments : std_logic; + signal first_frame : std_logic; + signal mon_packets_sent_ctr : unsigned(31 downto 0); + signal state : std_logic_vector(3 downto 0); begin -TRANSMIT_MACHINE_PROC : process( CLK, RESET ) -begin - if ( RESET = '1' ) then - transmit_current_state <= IDLE; - elsif( rising_edge(CLK) ) then - transmit_current_state <= transmit_next_state; - end if; -end process TRANSMIT_MACHINE_PROC; - -TRANSMIT_MACHINE : process(transmit_current_state, FC_H_READY_IN, TC_DATAREADY_IN, FC_READY_IN, local_end, TC_MAX_FRAME_IN, actual_frame_bytes, go_to_divide) -begin - state <= x"0"; - case transmit_current_state is - - when IDLE => - state <= x"1"; - if (TC_DATAREADY_IN = '1') then - transmit_next_state <= PREPARE_HEADERS; - else - transmit_next_state <= IDLE; - end if; - - when PREPARE_HEADERS => - state <= x"2"; - transmit_next_state<= WAIT_FOR_H; + PROC_TRANSMIT_MACHINE: process( CLK, RESET ) + begin + if ( RESET = '1' ) then + TRANSMIT_CS <= IDLE; + elsif( rising_edge(CLK) ) then + TRANSMIT_CS <= TRANSMIT_NS; + end if; + end process PROC_TRANSMIT_MACHINE; - when WAIT_FOR_H => - state <= x"3"; - if (FC_H_READY_IN = '1') then - transmit_next_state <= TRANSMIT; - else - transmit_next_state <= WAIT_FOR_H; - end if; + PROC_TRANSMIT_TRANSITIONS: process( TRANSMIT_CS, FC_H_READY_IN, TC_DATAREADY_IN, FC_READY_IN, local_end, TC_MAX_FRAME_IN, actual_frame_bytes, go_to_divide ) + begin + state <= x"0"; + case TRANSMIT_CS is - when TRANSMIT => - state <= x"4"; - if (local_end = x"0000") then - transmit_next_state <= SEND_ONE; - else - if (actual_frame_bytes = TC_MAX_FRAME_IN - x"1") then - transmit_next_state <= SEND_ONE; + when IDLE => + state <= x"1"; + if( TC_DATAREADY_IN = '1' ) then + TRANSMIT_NS <= PREPARE_HEADERS; else - transmit_next_state <= TRANSMIT; + TRANSMIT_NS <= IDLE; end if; - end if; - when SEND_ONE => - state <= x"5"; - transmit_next_state <= SEND_TWO; + when PREPARE_HEADERS => + state <= x"2"; + TRANSMIT_NS<= WAIT_FOR_H; - when SEND_TWO => - state <= x"6"; - transmit_next_state <= CLOSE; - - when CLOSE => - state <= x"7"; - transmit_next_state <= WAIT_FOR_TRANS; + when WAIT_FOR_H => + state <= x"3"; + if( FC_H_READY_IN = '1' ) then + TRANSMIT_NS <= TRANSMIT; + else + TRANSMIT_NS <= WAIT_FOR_H; + end if; - when WAIT_FOR_TRANS => - state <= x"8"; - if (FC_READY_IN = '1') then - if (go_to_divide = '1') then - transmit_next_state <= DIVIDE; + when TRANSMIT => + state <= x"4"; + if( local_end = x"0000" ) then + TRANSMIT_NS <= SEND_ONE; else - transmit_next_state <= CLEANUP; + if( actual_frame_bytes = unsigned(TC_MAX_FRAME_IN) - 1 ) then + TRANSMIT_NS <= SEND_ONE; + else + TRANSMIT_NS <= TRANSMIT; + end if; end if; - else - transmit_next_state <= WAIT_FOR_TRANS; - end if; - when DIVIDE => - state <= x"9"; - transmit_next_state <= PREPARE_HEADERS; + when SEND_ONE => + state <= x"5"; + TRANSMIT_NS <= SEND_TWO; + + when SEND_TWO => + state <= x"6"; + TRANSMIT_NS <= CLOSE; + + when CLOSE => + state <= x"7"; + TRANSMIT_NS <= WAIT_FOR_TRANS; + + when WAIT_FOR_TRANS => + state <= x"8"; + if( FC_READY_IN = '1' ) then + if( go_to_divide = '1' ) then + TRANSMIT_NS <= DIVIDE; + else + TRANSMIT_NS <= CLEANUP; + end if; + else + TRANSMIT_NS <= WAIT_FOR_TRANS; + end if; - when CLEANUP => - state <= x"a"; - transmit_next_state <= IDLE; + when DIVIDE => + state <= x"9"; + TRANSMIT_NS <= PREPARE_HEADERS; - end case; -end process TRANSMIT_MACHINE; + when CLEANUP => + state <= x"a"; + TRANSMIT_NS <= IDLE; -tc_rd <= '1' when transmit_current_state = TRANSMIT else '0'; + end case; + end process PROC_TRANSMIT_TRANSITIONS; -TC_RD_EN_OUT <= tc_rd; + tc_rd <= '1' when TRANSMIT_CS = TRANSMIT else '0'; + TC_RD_EN_OUT <= tc_rd; -SYNC_PROC : process( CLK ) -begin - if( rising_edge(CLK) ) then - tc_rd_q <= tc_rd; - tc_rd_qq <= tc_rd_q; - FC_WR_EN_OUT <= tc_rd_qq; - end if; -end process SYNC_PROC; - -ACTUAL_FRAME_BYTES_PROC : process( CLK ) -begin - if( rising_edge(CLK) ) then - if ( transmit_current_state = IDLE or transmit_current_state = DIVIDE ) then - actual_frame_bytes <= (others => '0'); - elsif( transmit_current_state = TRANSMIT ) then - actual_frame_bytes <= actual_frame_bytes + x"1"; + PROC_SYNC: process( CLK ) + begin + if( rising_edge(CLK) ) then + tc_rd_q <= tc_rd; + tc_rd_qq <= tc_rd_q; + FC_WR_EN_OUT <= tc_rd_qq; end if; - end if; -end process ACTUAL_FRAME_BYTES_PROC; - -GO_TO_DIVIDE_PROC : process( CLK ) -begin - if( rising_edge(CLK) ) then - if ( transmit_current_state = IDLE or transmit_current_state = DIVIDE ) then - go_to_divide <= '0'; - elsif( transmit_current_state = TRANSMIT and actual_frame_bytes = TC_MAX_FRAME_IN - x"1" ) then - go_to_divide <= '1'; - elsif( transmit_current_state = SEND_ONE and full_packet_size = packet_loaded_bytes ) then - go_to_divide <= '0'; + end process PROC_SYNC; + + PROC_ACTUAL_FRAME_BYTES: process( CLK ) + begin + if( rising_edge(CLK) ) then + if ( (TRANSMIT_CS = IDLE) or (TRANSMIT_CS = DIVIDE) ) then + actual_frame_bytes <= (others => '0'); + elsif( TRANSMIT_CS = TRANSMIT ) then + actual_frame_bytes <= actual_frame_bytes + 1; + end if; end if; - end if; -end process GO_TO_DIVIDE_PROC; - -LOCAL_END_PROC : process( CLK ) -begin - if( rising_edge(CLK) ) then - if ( transmit_current_state = IDLE and TC_DATAREADY_IN = '1' ) then - local_end <= TC_FRAME_SIZE_IN - x"1"; - full_packet_size <= TC_FRAME_SIZE_IN; - elsif( transmit_current_state = TRANSMIT ) then - local_end <= local_end - x"1"; - full_packet_size <= full_packet_size; + end process PROC_ACTUAL_FRAME_BYTES; + + PROC_GO_TO_DIVIDE: process( CLK ) + begin + if( rising_edge(CLK) ) then + if ( (TRANSMIT_CS = IDLE) or (TRANSMIT_CS = DIVIDE) ) then + go_to_divide <= '0'; + elsif( (TRANSMIT_CS = TRANSMIT) and (actual_frame_bytes = unsigned(TC_MAX_FRAME_IN) - 1) ) then + go_to_divide <= '1'; + elsif( (TRANSMIT_CS = SEND_ONE) and (full_packet_size = packet_loaded_bytes) ) then + go_to_divide <= '0'; + end if; end if; - end if; -end process LOCAL_END_PROC; - -FC_DATA_OUT <= TC_DATA_IN; -FC_SOD_OUT <= '1' when transmit_current_state = WAIT_FOR_H else '0'; -FC_EOD_OUT <= '1' when transmit_current_state = CLOSE else '0'; - -process( CLK ) -begin - if( rising_edge(CLK) ) then - if( transmit_current_state = PREPARE_HEADERS ) then - if( local_end >= TC_MAX_FRAME_IN ) then - ip_size <= TC_MAX_FRAME_IN; - else - ip_size <= local_end + x"1"; + end process PROC_GO_TO_DIVIDE; + + PROC_LOCAL_END: process( CLK ) + begin + if( rising_edge(CLK) ) then + if ( (TRANSMIT_CS = IDLE) and (TC_DATAREADY_IN = '1') ) then + local_end <= unsigned(TC_FRAME_SIZE_IN) - 1; + full_packet_size <= TC_FRAME_SIZE_IN; + elsif( TRANSMIT_CS = TRANSMIT ) then + local_end <= local_end - 1; + full_packet_size <= full_packet_size; end if; - else - ip_size <= ip_size; end if; - end if; -end process; -FC_IP_SIZE_OUT <= ip_size; -FC_UDP_SIZE_OUT <= full_packet_size; - -FC_FLAGS_OFFSET_OUT(15 downto 14) <= "00"; -FC_FLAGS_OFFSET_OUT(13) <= more_fragments; - -MORE_FRAGMENTS_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - if( transmit_current_state = PREPARE_HEADERS ) then - if( local_end >= TC_MAX_FRAME_IN ) then - more_fragments <= '1'; + end process PROC_LOCAL_END; + + FC_DATA_OUT <= TC_DATA_IN; + FC_SOD_OUT <= '1' when TRANSMIT_CS = WAIT_FOR_H else '0'; + FC_EOD_OUT <= '1' when TRANSMIT_CS = CLOSE else '0'; + + PROC_IP_SIZE: process( CLK ) + begin + if( rising_edge(CLK) ) then + if( TRANSMIT_CS = PREPARE_HEADERS ) then + if( local_end >= unsigned(TC_MAX_FRAME_IN) ) then + ip_size <= TC_MAX_FRAME_IN; + else + ip_size <= local_end + 1; + end if; else - more_fragments <= '0'; + ip_size <= ip_size; + end if; + end if; + end process PROC_IP_SIZE; + + FC_IP_SIZE_OUT <= ip_size; + FC_UDP_SIZE_OUT <= full_packet_size; + + FC_FLAGS_OFFSET_OUT(15 downto 14) <= "00"; + FC_FLAGS_OFFSET_OUT(13) <= more_fragments; + + PROC_MORE_FRAGMENTS: process( CLK ) + begin + if( rising_edge(CLK) ) then + if( TRANSMIT_CS = PREPARE_HEADERS ) then + if( local_end >= unsigned(TC_MAX_FRAME_IN) ) then + more_fragments <= '1'; + else + more_fragments <= '0'; + end if; end if; end if; - end if; -end process MORE_FRAGMENTS_PROC; + end process PROC_MORE_FRAGMENTS; -FC_FLAGS_OFFSET_OUT(12 downto 0) <= ('0' & x"000") when first_frame = '1' else (packet_loaded_bytes(15 downto 3) + x"1"); + FC_FLAGS_OFFSET_OUT(12 downto 0) <= ('0' & x"000") when (first_frame = '1') else std_logic_vector((packet_loaded_bytes(15 downto 3) + 1)); -PACKET_LOADED_BYTES_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - if ( transmit_current_state = IDLE ) then - packet_loaded_bytes <= x"0000"; - elsif( transmit_current_state = TRANSMIT ) then - packet_loaded_bytes <= packet_loaded_bytes + x"1"; + PROC_PACKET_LOADED_BYTES: process( CLK ) + begin + if( rising_edge(CLK) ) then + if ( TRANSMIT_CS = IDLE ) then + packet_loaded_bytes <= x"0000"; + elsif( TRANSMIT_CS = TRANSMIT ) then + packet_loaded_bytes <= packet_loaded_bytes + x"1"; + end if; end if; - end if; -end process PACKET_LOADED_BYTES_PROC; - -FIRST_FRAME_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - if ( transmit_current_state = IDLE ) then - first_frame <= '1'; - elsif( transmit_current_state = DIVIDE ) then - first_frame <= '0'; + end process PROC_PACKET_LOADED_BYTES; + + PROC_FIRST_FRAME: process( CLK ) + begin + if( rising_edge(CLK) ) then + if ( TRANSMIT_CS = IDLE ) then + first_frame <= '1'; + elsif( TRANSMIT_CS = DIVIDE ) then + first_frame <= '0'; + end if; end if; - end if; -end process FIRST_FRAME_PROC; - - -TC_TRANSMISSION_DONE_OUT <= '1' when transmit_current_state = CLEANUP else '0'; - -FC_FRAME_TYPE_OUT <= TC_FRAME_TYPE_IN; -FC_IP_PROTOCOL_OUT <= TC_IP_PROTOCOL_IN; -DEST_MAC_ADDRESS_OUT <= TC_DEST_MAC_IN; -DEST_IP_ADDRESS_OUT <= TC_DEST_IP_IN; -DEST_UDP_PORT_OUT <= TC_DEST_UDP_IN; -SRC_MAC_ADDRESS_OUT <= TC_SRC_MAC_IN; -SRC_IP_ADDRESS_OUT <= TC_SRC_IP_IN; -SRC_UDP_PORT_OUT <= TC_SRC_UDP_IN; -FC_IDENT_OUT <= TC_IDENT_IN; - --- monitoring - -process( CLK, RESET ) -begin - if ( RESET = '1' ) then - mon_packets_sent_ctr <= (others => '0'); - elsif( rising_edge(CLK) ) then - if( transmit_current_state = CLEANUP ) then - mon_packets_sent_ctr <= mon_packets_sent_ctr + x"1"; + end process PROC_FIRST_FRAME; + + TC_TRANSMISSION_DONE_OUT <= '1' when (TRANSMIT_CS = CLEANUP) else '0'; + + FC_FRAME_TYPE_OUT <= TC_FRAME_TYPE_IN; + FC_IP_PROTOCOL_OUT <= TC_IP_PROTOCOL_IN; + DEST_MAC_ADDRESS_OUT <= TC_DEST_MAC_IN; + DEST_IP_ADDRESS_OUT <= TC_DEST_IP_IN; + DEST_UDP_PORT_OUT <= TC_DEST_UDP_IN; + SRC_MAC_ADDRESS_OUT <= TC_SRC_MAC_IN; + SRC_IP_ADDRESS_OUT <= TC_SRC_IP_IN; + SRC_UDP_PORT_OUT <= TC_SRC_UDP_IN; + FC_IDENT_OUT <= TC_IDENT_IN; + + -- monitoring + + PROC_PACKETS_SENT: process( CLK, RESET ) + begin + if ( RESET = '1' ) then + mon_packets_sent_ctr <= (others => '0'); + elsif( rising_edge(CLK) ) then + if( TRANSMIT_CS = CLEANUP ) then + mon_packets_sent_ctr <= mon_packets_sent_ctr + x"1"; + end if; end if; - end if; -end process; + end process PROC_PACKETS_SENT; -MONITOR_TX_PACKETS_OUT <= mon_packets_sent_ctr; + MONITOR_TX_PACKETS_OUT <= mon_packets_sent_ctr; -DEBUG_OUT(3 downto 0) <= state; -DEBUG_OUT(4) <= FC_READY_IN; + DEBUG_OUT(3 downto 0) <= state; + DEBUG_OUT(4) <= FC_READY_IN; end gbe_transmit_control_arch; - - diff --git a/gbe_trb/base/gbe_wrapper_fifo.vhd b/gbe_trb/base/gbe_wrapper_fifo.vhd index ae56c10..1337a10 100644 --- a/gbe_trb/base/gbe_wrapper_fifo.vhd +++ b/gbe_trb/base/gbe_wrapper_fifo.vhd @@ -3,7 +3,7 @@ library ieee; use ieee.numeric_std.all; library work; - use work.gbe_protocols.all; +-- use work.gbe_protocols.all; entity gbe_wrapper_fifo is generic( @@ -95,7 +95,7 @@ architecture gbe_wrapper_fifo_arch of gbe_wrapper_fifo is signal monitor_dropped : std_logic_vector(31 downto 0); signal make_reset : std_logic := '0'; - signal monitor_gen_dbg : std_logic_vector(c_MAX_PROTOCOLS * 64 - 1 downto 0); + signal monitor_gen_dbg : std_logic_vector(8 * 64 - 1 downto 0); signal issue_reboot : std_logic; signal my_ip : std_logic_vector(127 downto 0); -- 2.43.0