From 655cda61299c4166ee6bd7c6ba4b0719ee32430b Mon Sep 17 00:00:00 2001 From: Michael Boehmer Date: Fri, 4 Nov 2022 08:35:44 +0100 Subject: [PATCH] working point. DHCP, ARP, PING, SCTRL seem to work. --- gbe_trb/base/gbe_frame_constr.vhd | 709 +++++++++--------- gbe_trb/base/gbe_frame_receiver.vhd | 155 ++-- gbe_trb/base/gbe_logic_wrapper.vhd | 60 +- gbe_trb/base/gbe_main_control.vhd | 11 +- gbe_trb/base/gbe_receive_control.vhd | 4 - gbe_trb/base/gbe_wrapper_fifo.vhd | 1 - .../gbe_response_constructor_ARP.vhd | 37 +- .../gbe_response_constructor_DHCP.vhd | 270 ++++--- 8 files changed, 603 insertions(+), 644 deletions(-) diff --git a/gbe_trb/base/gbe_frame_constr.vhd b/gbe_trb/base/gbe_frame_constr.vhd index 80fd234..497cdd1 100644 --- a/gbe_trb/base/gbe_frame_constr.vhd +++ b/gbe_trb/base/gbe_frame_constr.vhd @@ -47,403 +47,400 @@ end entity gbe_frame_constr; architecture gbe_frame_constr_arch of gbe_frame_constr is -attribute syn_encoding : string; - -type constructStates is (IDLE, DEST_MAC_ADDR, SRC_MAC_ADDR, FRAME_TYPE_S, VERSION, - 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 headers_int_counter : integer range 0 to 6; -signal fpf_data : std_logic_vector(7 downto 0); -signal fpf_wr_en : std_logic; -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 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 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; - -signal mon_sent_frames : unsigned(31 downto 0); -signal mon_sent_bytes : unsigned(31 downto 0); + attribute syn_encoding : string; + + type constructStates is (IDLE, DEST_MAC_ADDR, SRC_MAC_ADDR, FRAME_TYPE_S, VERSION, + 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 headers_int_counter : integer range 0 to 6; + signal fpf_data : std_logic_vector(7 downto 0); + signal fpf_wr_en : std_logic; + 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 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 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; + + signal mon_sent_frames : unsigned(31 downto 0); + signal mon_sent_bytes : unsigned(31 downto 0); begin --- No checksum test needed -udp_checksum <= x"0000"; + -- No checksum test needed + udp_checksum <= x"0000"; --- frame constructor ready -THE_READY_PROC: process( CLK ) -begin -if( rising_edge(CLK) )then - if( constructCurrentState = IDLE ) then - ready <= '1'; - else - ready <= '0'; - end if; - - if( constructCurrentState = SAVE_DATA ) then - headers_ready <= '1'; - else - headers_ready <= '0'; - end if; -end if; -end process; + -- frame constructor ready + PROC_READY: process( CLK ) + begin + if( rising_edge(CLK) )then + if( constructCurrentState = IDLE ) then + ready <= '1'; + else + ready <= '0'; + end if; --- Calculate UDP and IP sizes -THE_SIZE_PROC: process( CLK ) -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"; + if( constructCurrentState = SAVE_DATA ) then + headers_ready <= '1'; else - ip_size <= IP_F_SIZE_IN + x"14"; - udp_size <= UDP_P_SIZE_IN; + headers_ready <= '0'; end if; end if; -end process THE_SIZE_PROC; + end process PROC_READY; + + -- Calculate UDP and IP sizes + PROC_SIZE: process( CLK ) + 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"; + else + ip_size <= IP_F_SIZE_IN + x"14"; + udp_size <= UDP_P_SIZE_IN; + end if; + end if; + end process PROC_SIZE; -THE_IP_CS_PROC : process( CLK ) -begin - if( rising_edge(CLK) ) then - if( constructCurrentState = IDLE ) then - ip_checksum <= x"00000000"; - else + PROC_IP_CS : process( CLK ) + begin + if( rising_edge(CLK) ) then + if( constructCurrentState = IDLE ) then + ip_checksum <= x"00000000"; + else + case constructCurrentState 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); + when 1 => + ip_checksum <= ip_checksum + 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); + when 3 => + ip_checksum <= ip_checksum + 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); + when 5 => + ip_checksum <= ip_checksum + 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); + when 1 => + ip_checksum <= ip_checksum + DEST_IP_ADDRESS_IN(31 downto 24); + when 2 => + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + IHL_VERSION_IN; + when 3 => + ip_checksum <= ip_checksum + TOS_IN; + when 4 => + ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + ip_size(15 downto 8); + when 5 => + ip_checksum <= ip_checksum + ip_size(7 downto 0); + when others => null; + 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); + end if; + when TOS_S => + if( headers_int_counter = 0 ) then + ip_checksum <= ip_checksum + 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); + elsif headers_int_counter = 1 then + ip_checksum <= ip_checksum + 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; + elsif headers_int_counter = 1 then + ip_checksum <= ip_checksum + PROTOCOL_IN; + end if; + -- gk 29.03.10 corrected the bug with bad checksums when sum larger than 16b + when FLAGS => + if ( headers_int_counter = 0 ) then + ip_cs_temp_right <= ip_checksum(31 downto 16); + elsif( headers_int_counter = 1 ) then + ip_checksum(31 downto 16) <= (others => '0'); + end if; + when TTL_S => + if( headers_int_counter = 0 ) then + ip_checksum <= ip_checksum + ip_cs_temp_right; + end if; + when PROTO => + if( headers_int_counter = 0 ) then + ip_checksum(15 downto 0) <= ip_checksum(15 downto 0) + ip_checksum(31 downto 16); + end if; + when others => null; + end case; + end if; + end if; + end process PROC_IP_CS; + + + PROC_CONSTRUCT: process( CLK, RESET ) + begin + if ( RESET = '1' ) then + constructCurrentState <= IDLE; + elsif( rising_edge(CLK) ) then + constructCurrentState <= constructNextState; + 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, + END_OF_DATA_IN, headers_int_counter, put_udp_headers, CUR_MAX, + FRAME_TYPE_IN, DEST_UDP_PORT_IN) + begin + constructNextState <= constructCurrentState; + if( headers_int_counter = cur_max ) then --can be checked everytime - if not in use, counter and cur_max are 0 case constructCurrentState is + when IDLE => + if( START_OF_DATA_IN = '1' ) then + constructNextState <= DEST_MAC_ADDR; + end if; 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); - when 1 => - ip_checksum <= ip_checksum + 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); - when 3 => - ip_checksum <= ip_checksum + 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); - when 5 => - ip_checksum <= ip_checksum + DEST_IP_ADDRESS_IN(15 downto 8); - when others => null; - end case; + constructNextState <= SRC_MAC_ADDR; 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); - when 1 => - ip_checksum <= ip_checksum + DEST_IP_ADDRESS_IN(31 downto 24); - when 2 => - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + IHL_VERSION_IN; - when 3 => - ip_checksum <= ip_checksum + TOS_IN; - when 4 => - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + ip_size(15 downto 8); - when 5 => - ip_checksum <= ip_checksum + ip_size(7 downto 0); - when others => null; - 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); + constructNextState <= FRAME_TYPE_S; + when FRAME_TYPE_S => + if( FRAME_TYPE_IN = x"0008" ) then + constructNextState <= VERSION; + else -- otherwise transmit data as pure ethernet frame + constructNextState <= SAVE_DATA; end if; + when VERSION => + constructNextState <= TOS_S; when TOS_S => - if( headers_int_counter = 0 ) then - ip_checksum <= ip_checksum + IDENTIFICATION_IN(15 downto 8); - end if; + constructNextState <= IP_LENGTH; 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); - elsif headers_int_counter = 1 then - ip_checksum <= ip_checksum + FLAGS_OFFSET_IN(7 downto 0); - end if; + constructNextState <= IDENT; when IDENT => - if headers_int_counter = 0 then - ip_checksum(31 downto 8) <= ip_checksum(31 downto 8) + TTL_IN; - elsif headers_int_counter = 1 then - ip_checksum <= ip_checksum + PROTOCOL_IN; - end if; - -- gk 29.03.10 corrected the bug with bad checksums when sum larger than 16b + constructNextState <= FLAGS; when FLAGS => - if ( headers_int_counter = 0 ) then - ip_cs_temp_right <= ip_checksum(31 downto 16); - elsif( headers_int_counter = 1 ) then - ip_checksum(31 downto 16) <= (others => '0'); - end if; + constructNextState <= TTL_S; when TTL_S => - if( headers_int_counter = 0 ) then - ip_checksum <= ip_checksum + ip_cs_temp_right; - end if; + constructNextState <= PROTO; when PROTO => - if( headers_int_counter = 0 ) then - ip_checksum(15 downto 0) <= ip_checksum(15 downto 0) + ip_checksum(31 downto 16); + constructNextState <= HEADER_CS; + when HEADER_CS => + constructNextState <= SRC_IP_ADDR; + when SRC_IP_ADDR => + constructNextState <= DEST_IP_ADDR; + when DEST_IP_ADDR => + if( (put_udp_headers = '1') and (DEST_UDP_PORT_IN /= x"0000") ) then + constructNextState <= SRC_PORT; + else + constructNextState <= SAVE_DATA; + end if; + when SRC_PORT => + constructNextState <= DEST_PORT; + when DEST_PORT => + constructNextState <= UDP_LENGTH; + when UDP_LENGTH => + constructNextState <= UDP_CS; + when UDP_CS => + constructNextState <= SAVE_DATA; + when SAVE_DATA => + if( END_OF_DATA_IN = '1' ) then + constructNextState <= CLEANUP; end if; - when others => null; + when CLEANUP => + constructNextState <= DELAY; + when DELAY => + if (delay_ctr = FRAME_DELAY_IN) then + constructNextState <= IDLE; + else + constructNextState <= DELAY; + end if; + + when others => + constructNextState <= IDLE; end case; end if; - end if; -end process THE_IP_CS_PROC; - + 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; -THE_CONSTRUCT_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - if( RESET = '1' ) then - constructCurrentState <= IDLE; - else - constructCurrentState <= constructNextState; + frame_delay_reg <= FRAME_DELAY_IN; end if; - end if; -end process THE_CONSTRUCT_PROC; + end process PROC_DELAY_CTR; ---find next state of construct machine -constructMachine: process( constructCurrentState, 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) -begin - constructNextState <= constructCurrentState; - if( headers_int_counter = cur_max ) then --can be checked everytime - if not in use, counter and cur_max are 0 + PROC_BSM_CONSTR: process( constructCurrentState ) + begin + --find maximum time in each state & set state bits case constructCurrentState is - when IDLE => - if( START_OF_DATA_IN = '1' ) then - constructNextState <= DEST_MAC_ADDR; - end if; - when DEST_MAC_ADDR => - constructNextState <= SRC_MAC_ADDR; - when SRC_MAC_ADDR => - constructNextState <= FRAME_TYPE_S; - when FRAME_TYPE_S => - if( FRAME_TYPE_IN = x"0008" ) then - constructNextState <= VERSION; - else -- otherwise transmit data as pure ethernet frame - constructNextState <= SAVE_DATA; - end if; - when VERSION => - constructNextState <= TOS_S; - when TOS_S => - constructNextState <= IP_LENGTH; - when IP_LENGTH => - constructNextState <= IDENT; - when IDENT => - constructNextState <= FLAGS; - when FLAGS => - constructNextState <= TTL_S; - when TTL_S => - constructNextState <= PROTO; - when PROTO => - constructNextState <= HEADER_CS; - when HEADER_CS => - constructNextState <= SRC_IP_ADDR; - when SRC_IP_ADDR => - constructNextState <= DEST_IP_ADDR; - when DEST_IP_ADDR => - if( (put_udp_headers = '1') and (DEST_UDP_PORT_IN /= x"0000") ) then - constructNextState <= SRC_PORT; - else - constructNextState <= SAVE_DATA; - end if; - when SRC_PORT => - constructNextState <= DEST_PORT; - when DEST_PORT => - constructNextState <= UDP_LENGTH; - when UDP_LENGTH => - constructNextState <= UDP_CS; - when UDP_CS => - constructNextState <= SAVE_DATA; - when SAVE_DATA => - if( END_OF_DATA_IN = '1' ) then - constructNextState <= CLEANUP; - end if; - when CLEANUP => - constructNextState <= DELAY; - when DELAY => - if (delay_ctr = FRAME_DELAY_IN) then - constructNextState <= IDLE; + when IDLE => cur_max <= 0; + when DEST_MAC_ADDR => cur_max <= 5; + when SRC_MAC_ADDR => cur_max <= 5; + when FRAME_TYPE_S => cur_max <= 1; + when VERSION => cur_max <= 0; + when TOS_S => cur_max <= 0; + when IP_LENGTH => cur_max <= 1; + when IDENT => cur_max <= 1; + when FLAGS => cur_max <= 1; + when TTL_S => cur_max <= 0; + when PROTO => cur_max <= 0; + when HEADER_CS => cur_max <= 1; + when SRC_IP_ADDR => cur_max <= 3; + when DEST_IP_ADDR => cur_max <= 3; + when SRC_PORT => cur_max <= 1; + when DEST_PORT => cur_max <= 1; + when UDP_LENGTH => cur_max <= 1; + when UDP_CS => cur_max <= 1; + when SAVE_DATA => cur_max <= 0; + when CLEANUP => cur_max <= 0; + when DELAY => cur_max <= 0; + when others => cur_max <= 0; + end case; + end process PROC_BSM_CONSTR; + + PROC_HEADERS_INT: process( CLK ) + begin + if( rising_edge(CLK) ) then + if( constructCurrentState = IDLE ) then + headers_int_counter <= 0; + else + if( headers_int_counter = cur_max ) then + headers_int_counter <= 0; else - constructNextState <= DELAY; + headers_int_counter <= headers_int_counter + 1; end if; - - when others => - constructNextState <= IDLE; - end case; - end if; -end process constructMachine; - -THE_DELAY_CTR_PROC: 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 if; -end process THE_DELAY_CTR_PROC; + end process PROC_HEADERS_INT; -THE_BSM_CONSTR_PROC: process( constructCurrentState ) -begin ---find maximum time in each state & set state bits - case constructCurrentState is - when IDLE => cur_max <= 0; - when DEST_MAC_ADDR => cur_max <= 5; - when SRC_MAC_ADDR => cur_max <= 5; - when FRAME_TYPE_S => cur_max <= 1; - when VERSION => cur_max <= 0; - when TOS_S => cur_max <= 0; - when IP_LENGTH => cur_max <= 1; - when IDENT => cur_max <= 1; - when FLAGS => cur_max <= 1; - when TTL_S => cur_max <= 0; - when PROTO => cur_max <= 0; - when HEADER_CS => cur_max <= 1; - when SRC_IP_ADDR => cur_max <= 3; - when DEST_IP_ADDR => cur_max <= 3; - when SRC_PORT => cur_max <= 1; - when DEST_PORT => cur_max <= 1; - when UDP_LENGTH => cur_max <= 1; - when UDP_CS => cur_max <= 1; - when SAVE_DATA => cur_max <= 0; - when CLEANUP => cur_max <= 0; - when DELAY => cur_max <= 0; - when others => cur_max <= 0; -end case; -end process THE_BSM_CONSTR_PROC; - -THE_HEADERS_INT_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - if( constructCurrentState = IDLE ) then - headers_int_counter <= 0; - else - if( headers_int_counter = cur_max ) then - headers_int_counter <= 0; + PROC_PUT_UDP_HEADERS: process( CLK ) + begin + if( rising_edge(CLK) ) then + if( FLAGS_OFFSET_IN(12 downto 0) = "0000000000000" ) then + put_udp_headers <= '1'; else - headers_int_counter <= headers_int_counter + 1; + put_udp_headers <= '0'; end if; end if; -end if; -end process THE_HEADERS_INT_PROC; + end process PROC_PUT_UDP_HEADERS; -THE_PUT_UDP_HEADERS_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - if( FLAGS_OFFSET_IN(12 downto 0) = "0000000000000" ) then - put_udp_headers <= '1'; + PROC_FPF_WREN: process( constructCurrentState, 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 + fpf_wr_en <= '1'; + elsif( (constructCurrentState = SAVE_DATA) and (WR_EN_IN = '1') ) then + fpf_wr_en <= '1'; else - put_udp_headers <= '0'; + fpf_wr_en <= '0'; end if; - end if; -end process THE_PUT_UDP_HEADERS_PROC; - -THE_FPF_WREN_PROC : process( constructCurrentState, 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 - fpf_wr_en <= '1'; - elsif( (constructCurrentState = SAVE_DATA) and (WR_EN_IN = '1') ) then - fpf_wr_en <= '1'; - else - fpf_wr_en <= '0'; - end if; -end process THE_FPF_WREN_PROC; + end process PROC_FPF_WREN; -THE_FPF_DATA_PROC: process( constructCurrentState, 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 - 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); - when FRAME_TYPE_S => fpf_data <= FRAME_TYPE_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); - when VERSION => fpf_data <= IHL_VERSION_IN; - when TOS_S => fpf_data <= TOS_IN; - when IP_LENGTH => fpf_data <= ip_size(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); - when IDENT => fpf_data <= IDENTIFICATION_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); - 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 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); - when DEST_PORT => fpf_data <= DEST_UDP_PORT_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); - when UDP_LENGTH => fpf_data <= udp_size(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); - when UDP_CS => fpf_data <= udp_checksum(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); - when SAVE_DATA => fpf_data <= DATA_IN; - when CLEANUP => fpf_data <= x"ab"; - when DELAY => fpf_data <= x"ac"; - when others => fpf_data <= x"00"; - end case; -end process THE_FPF_DATA_PROC; - -THE_SYNC_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - fpf_data_q <= fpf_data; - fpf_wr_en_q <= fpf_wr_en; - fpf_eod_q <= END_OF_DATA_IN; - end if; -end process THE_SYNC_PROC; - --- count bytes sent -THE_MON_SENT_BYTES_PROC: process( CLK ) -begin - if( rising_edge(CLK) ) then - if( LINK_OK_IN = '0' ) then - mon_sent_bytes <= (others => '0'); - elsif( fpf_rd_en = '1' ) then - mon_sent_bytes <= mon_sent_bytes + 1; - else - mon_sent_bytes <= mon_sent_bytes; + PROC_FPF_DATA: process( constructCurrentState, 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 + 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); + when FRAME_TYPE_S => fpf_data <= FRAME_TYPE_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); + when VERSION => fpf_data <= IHL_VERSION_IN; + when TOS_S => fpf_data <= TOS_IN; + when IP_LENGTH => fpf_data <= ip_size(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); + when IDENT => fpf_data <= IDENTIFICATION_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); + 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 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); + when DEST_PORT => fpf_data <= DEST_UDP_PORT_IN(headers_int_counter * 8 + 7 downto headers_int_counter * 8); + when UDP_LENGTH => fpf_data <= udp_size(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); + when UDP_CS => fpf_data <= udp_checksum(15 - headers_int_counter * 8 downto 8 - headers_int_counter * 8); + when SAVE_DATA => fpf_data <= DATA_IN; + when CLEANUP => fpf_data <= x"ab"; + when DELAY => fpf_data <= x"ac"; + when others => fpf_data <= x"00"; + end case; + end process PROC_FPF_DATA; + + PROC_SYNC: process( CLK ) + begin + if( rising_edge(CLK) ) then + fpf_data_q <= fpf_data; + fpf_wr_en_q <= fpf_wr_en; + fpf_eod_q <= END_OF_DATA_IN; end if; - end if; -end process THE_MON_SENT_BYTES_PROC; - --- count frames sent -THE_MON_SENT_FRAMES_PROC: process( CLK ) -begin - if( rising_edge(CLK) )then - if ( LINK_OK_IN = '0' ) then - mon_sent_frames <= (others => '0'); - elsif( (fpf_wr_en_q = '1') and (fpf_eod_q = '1') ) then -- TO BE TESTED - mon_sent_frames <= mon_sent_frames + 1; - else - mon_sent_frames <= mon_sent_frames; + end process PROC_SYNC; + + -- count bytes sent + PROC_MON_SENT_BYTES: process( CLK ) + begin + if( rising_edge(CLK) ) then + if( LINK_OK_IN = '0' ) then + mon_sent_bytes <= (others => '0'); + elsif( fpf_rd_en = '1' ) then + mon_sent_bytes <= mon_sent_bytes + 1; + else + mon_sent_bytes <= mon_sent_bytes; + end if; end if; - end if; -end process THE_MON_SENT_FRAMES_PROC; - --- Outputs + end process PROC_MON_SENT_BYTES; + + -- count frames sent + PROC_MON_SENT_FRAMES: process( CLK ) + begin + if( rising_edge(CLK) )then + if ( LINK_OK_IN = '0' ) then + mon_sent_frames <= (others => '0'); + elsif( (fpf_wr_en_q = '1') and (fpf_eod_q = '1') ) then -- TO BE TESTED + mon_sent_frames <= mon_sent_frames + 1; + else + mon_sent_frames <= mon_sent_frames; + end if; + end if; + end process PROC_MON_SENT_FRAMES; -FT_TX_DATA_OUT(7 downto 0) <= fpf_data_q; -FT_TX_DATA_OUT(8) <= fpf_eod_q; -FT_TX_WR_OUT <= fpf_wr_en_q; + -- Outputs + FT_TX_DATA_OUT(7 downto 0) <= fpf_data_q; + FT_TX_DATA_OUT(8) <= fpf_eod_q; + FT_TX_WR_OUT <= fpf_wr_en_q; -READY_OUT <= ready; -HEADERS_READY_OUT <= headers_ready; + READY_OUT <= ready; + HEADERS_READY_OUT <= headers_ready; -MONITOR_TX_BYTES_OUT <= std_logic_vector(mon_sent_bytes); -MONITOR_TX_FRAMES_OUT <= std_logic_vector(mon_sent_frames); + MONITOR_TX_BYTES_OUT <= std_logic_vector(mon_sent_bytes); + MONITOR_TX_FRAMES_OUT <= std_logic_vector(mon_sent_frames); end gbe_frame_constr_arch; diff --git a/gbe_trb/base/gbe_frame_receiver.vhd b/gbe_trb/base/gbe_frame_receiver.vhd index 1f07d0f..73b5b73 100644 --- a/gbe_trb/base/gbe_frame_receiver.vhd +++ b/gbe_trb/base/gbe_frame_receiver.vhd @@ -79,8 +79,8 @@ architecture gbe_frame_receiver_arch of gbe_frame_receiver is attribute syn_encoding : string; type filter_states is (IDLE, REMOVE_DEST, REMOVE_SRC, REMOVE_TYPE, SAVE_FRAME, DROP_FRAME, REMOVE_IP, REMOVE_UDP, DELAY, CLEANUP); - signal filter_current_state, filter_next_state : filter_states; - attribute syn_encoding of filter_current_state : signal is "onehot"; + signal FILTER_CS, FILTER_NS : filter_states; + attribute syn_encoding of FILTER_CS : signal is "onehot"; signal fifo_wr_en : std_logic; signal rx_bytes_ctr : std_logic_vector(15 downto 0); @@ -141,7 +141,8 @@ architecture gbe_frame_receiver_arch of gbe_frame_receiver is begin -- Debug lines - DEBUG_OUT(31 downto 26) <= (others => '0'); + DEBUG_OUT(31 downto 28) <= state; + DEBUG_OUT(27 downto 16) <= (others => '0'); DEBUG_OUT(15) <= frame_valid_q; DEBUG_OUT(14) <= fifo_wr_en; @@ -172,28 +173,28 @@ begin PROC_FILTER_FSM: process( CLK, RESET ) begin if ( RESET = '1' ) then - filter_current_state <= IDLE; + FILTER_CS <= IDLE; oob_select <= '0'; elsif( rising_edge(CLK) ) then - filter_current_state <= filter_next_state; + FILTER_CS <= FILTER_NS; oob_select <= oob_select_x; end if; end process PROC_FILTER_FSM; - PROC_FILTER_TRANSITIONS : process( filter_current_state, saved_frame_type, LINK_OK_IN, saved_proto, MY_MAC_IN, + PROC_FILTER_TRANSITIONS : process( FILTER_CS, saved_frame_type, LINK_OK_IN, saved_proto, MY_MAC_IN, saved_dest_mac, remove_ctr, new_frame, MAC_RX_EOF_IN, frame_type_valid, ALLOW_RX_IN) begin set_proto_x <= (others => '0'); oob_select_x <= '0'; - case filter_current_state is + case FILTER_CS is when IDLE => state <= x"1"; if( (new_frame = '1') and (ALLOW_RX_IN = '1') and (LINK_OK_IN = '1') ) then - filter_next_state <= REMOVE_DEST; + FILTER_NS <= REMOVE_DEST; else - filter_next_state <= IDLE; + FILTER_NS <= IDLE; end if; -- frames arrive without preamble! @@ -202,21 +203,21 @@ begin if( remove_ctr = x"03" ) then -- counter starts with a delay that's why only 3 -- destination MAC address filtering here if( (saved_dest_mac = MY_MAC_IN) or (saved_dest_mac = x"ffffffffffff") ) then -- must accept broadcasts for ARP - filter_next_state <= REMOVE_SRC; + FILTER_NS <= REMOVE_SRC; else - filter_next_state <= DROP_FRAME; -- wrong MAC, were are done + FILTER_NS <= DROP_FRAME; -- wrong MAC, were are done -- could be done in REMOVE_SRC to gain some clock cycles end if; else - filter_next_state <= REMOVE_DEST; + FILTER_NS <= REMOVE_DEST; end if; when REMOVE_SRC => state <= x"4"; if( remove_ctr = x"09" ) then - filter_next_state <= REMOVE_TYPE; + FILTER_NS <= REMOVE_TYPE; else - filter_next_state <= REMOVE_SRC; + FILTER_NS <= REMOVE_SRC; end if; when REMOVE_TYPE => @@ -225,17 +226,17 @@ begin case saved_frame_type is when x"0800" => -- IPv4 frame, to be investigated - filter_next_state <= REMOVE_IP; + FILTER_NS <= REMOVE_IP; when x"0806" => -- ARP frame, to be stored - filter_next_state <= DELAY; + FILTER_NS <= DELAY; set_proto_x(0) <= '1'; -- NB: first two bytes of ARP frame are dropped silently when others => - filter_next_state <= DROP_FRAME; + FILTER_NS <= DROP_FRAME; end case; else - filter_next_state <= REMOVE_TYPE; + FILTER_NS <= REMOVE_TYPE; end if; when REMOVE_IP => @@ -246,16 +247,16 @@ begin case saved_proto is when x"11" => -- UDP, to be investigated - filter_next_state <= REMOVE_UDP; + FILTER_NS <= REMOVE_UDP; when x"01" => -- ICMP, to be stored - filter_next_state <= DELAY; + FILTER_NS <= DELAY; set_proto_x(4) <= '1'; when others => - filter_next_state <= DROP_FRAME; + FILTER_NS <= DROP_FRAME; end case; else - filter_next_state <= REMOVE_IP; + FILTER_NS <= REMOVE_IP; end if; when REMOVE_UDP => @@ -264,43 +265,43 @@ begin case saved_dest_udp is when x"0044" => -- DHCP frame, to be stored - filter_next_state <= DELAY; + FILTER_NS <= DELAY; set_proto_x(1) <= '1'; when x"6590" => -- SCTRL frame, to be stored - filter_next_state <= DELAY; + FILTER_NS <= DELAY; set_proto_x(2) <= '1'; when others => - filter_next_state <= DROP_FRAME; + FILTER_NS <= DROP_FRAME; oob_select_x <= '1'; end case; else - filter_next_state <= REMOVE_UDP; + FILTER_NS <= REMOVE_UDP; end if; when DELAY => state <= x"6"; - filter_next_state <= SAVE_FRAME; + FILTER_NS <= SAVE_FRAME; when SAVE_FRAME => state <= x"7"; if( MAC_RX_EOF_IN = '1' ) then - filter_next_state <= CLEANUP; + FILTER_NS <= CLEANUP; else - filter_next_state <= SAVE_FRAME; + FILTER_NS <= SAVE_FRAME; end if; when DROP_FRAME => state <= x"8"; if( MAC_RX_EOF_IN = '1' ) then - filter_next_state <= CLEANUP; + FILTER_NS <= CLEANUP; else - filter_next_state <= DROP_FRAME; + FILTER_NS <= DROP_FRAME; end if; when CLEANUP => state <= x"9"; - filter_next_state <= IDLE; + FILTER_NS <= IDLE; when others => null; @@ -316,7 +317,7 @@ begin for I in c_MAX_PROTOCOLS - 1 downto 0 loop if ( set_proto_x(I) = '1' ) then proto_select(I) <= '1'; - elsif( filter_current_state = CLEANUP ) then + elsif( FILTER_CS = CLEANUP ) then proto_select(I) <= '0'; end if; end loop; @@ -327,10 +328,10 @@ begin PROC_REMOVE_CTR: process( CLK ) begin if( rising_edge(CLK) ) then - if ( (filter_current_state = IDLE) or - ((filter_current_state = REMOVE_TYPE) and (remove_ctr = x"0b")) ) then + if ( (FILTER_CS = IDLE) or + ((FILTER_CS = REMOVE_TYPE) and (remove_ctr = x"0b")) ) then remove_ctr <= (others => '1'); - elsif( (MAC_RX_EN_IN = '1') and (filter_current_state /= IDLE) ) then + elsif( (MAC_RX_EN_IN = '1') and (FILTER_CS /= IDLE) ) then remove_ctr <= remove_ctr + 1; end if; end if; @@ -340,9 +341,9 @@ begin PROC_SAVED_PROTO: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_proto <= (others => '0'); - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"07") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"07") ) then saved_proto <= MAC_RXD_IN; end if; end if; @@ -352,19 +353,19 @@ begin PROC_SAVED_DEST_MAC: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_dest_mac <= (others => '0'); - elsif( (filter_current_state = IDLE) and (MAC_RX_EN_IN = '1') and (new_frame = '0') ) then + elsif( (FILTER_CS = IDLE) and (MAC_RX_EN_IN = '1') and (new_frame = '0') ) then saved_dest_mac(7 downto 0) <= MAC_RXD_IN; - elsif( (filter_current_state = IDLE) and (new_frame = '1') and (ALLOW_RX_IN = '1') ) then + elsif( (FILTER_CS = IDLE) and (new_frame = '1') and (ALLOW_RX_IN = '1') ) then saved_dest_mac(15 downto 8) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_DEST) and (remove_ctr = x"FF") ) then + elsif( (FILTER_CS = REMOVE_DEST) and (remove_ctr = x"FF") ) then saved_dest_mac(23 downto 16) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_DEST) and (remove_ctr = x"00") ) then + elsif( (FILTER_CS = REMOVE_DEST) and (remove_ctr = x"00") ) then saved_dest_mac(31 downto 24) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_DEST) and (remove_ctr = x"01") ) then + elsif( (FILTER_CS = REMOVE_DEST) and (remove_ctr = x"01") ) then saved_dest_mac(39 downto 32) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_DEST) and (remove_ctr = x"02") ) then + elsif( (FILTER_CS = REMOVE_DEST) and (remove_ctr = x"02") ) then saved_dest_mac(47 downto 40) <= MAC_RXD_IN; end if; end if; @@ -374,19 +375,19 @@ begin PROC_SAVED_SRC_MAC: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_src_mac <= (others => '0'); - elsif( (filter_current_state = REMOVE_DEST) and (remove_ctr = x"03") )then + elsif( (FILTER_CS = REMOVE_DEST) and (remove_ctr = x"03") )then saved_src_mac(7 downto 0) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_SRC) and (remove_ctr = x"04") ) then + elsif( (FILTER_CS = REMOVE_SRC) and (remove_ctr = x"04") ) then saved_src_mac(15 downto 8) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_SRC) and (remove_ctr = x"05") ) then + elsif( (FILTER_CS = REMOVE_SRC) and (remove_ctr = x"05") ) then saved_src_mac(23 downto 16) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_SRC) and (remove_ctr = x"06") ) then + elsif( (FILTER_CS = REMOVE_SRC) and (remove_ctr = x"06") ) then saved_src_mac(31 downto 24) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_SRC) and (remove_ctr = x"07") ) then + elsif( (FILTER_CS = REMOVE_SRC) and (remove_ctr = x"07") ) then saved_src_mac(39 downto 32) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_SRC) and (remove_ctr = x"08") ) then + elsif( (FILTER_CS = REMOVE_SRC) and (remove_ctr = x"08") ) then saved_src_mac(47 downto 40) <= MAC_RXD_IN; end if; end if; @@ -396,11 +397,11 @@ begin PROC_SAVED_FRAME_TYPE: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_frame_type <= (others => '0'); - elsif( (filter_current_state = REMOVE_SRC) and (remove_ctr = x"09") ) then + elsif( (FILTER_CS = REMOVE_SRC) and (remove_ctr = x"09") ) then saved_frame_type(15 downto 8) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_TYPE) and (remove_ctr = x"0a") ) then + elsif( (FILTER_CS = REMOVE_TYPE) and (remove_ctr = x"0a") ) then saved_frame_type(7 downto 0) <= MAC_RXD_IN; end if; end if; @@ -409,15 +410,15 @@ begin PROC_SAVED_SRC_IP: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_src_ip <= (others => '0'); - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"0a") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"0a") ) then saved_src_ip(7 downto 0) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"0b") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"0b") ) then saved_src_ip(15 downto 8) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"0c") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"0c") ) then saved_src_ip(23 downto 16) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"0d") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"0d") ) then saved_src_ip(31 downto 24) <= MAC_RXD_IN; end if; end if; @@ -426,15 +427,15 @@ begin PROC_SAVED_DEST_IP: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_dest_ip <= (others => '0'); - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"0e") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"0e") ) then saved_dest_ip(7 downto 0) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"0f") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"0f") ) then saved_dest_ip(15 downto 8) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"10") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"10") ) then saved_dest_ip(23 downto 16) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_IP) and (remove_ctr = x"11") ) then + elsif( (FILTER_CS = REMOVE_IP) and (remove_ctr = x"11") ) then saved_dest_ip(31 downto 24) <= MAC_RXD_IN; end if; end if; @@ -443,11 +444,11 @@ begin PROC_SAVED_SRC_UDP: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_src_udp <= (others => '0'); - elsif( (filter_current_state = REMOVE_UDP) and (remove_ctr = x"12") ) then + elsif( (FILTER_CS = REMOVE_UDP) and (remove_ctr = x"12") ) then saved_src_udp(15 downto 8) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_UDP) and (remove_ctr = x"13") ) then + elsif( (FILTER_CS = REMOVE_UDP) and (remove_ctr = x"13") ) then saved_src_udp(7 downto 0) <= MAC_RXD_IN; end if; end if; @@ -456,11 +457,11 @@ begin PROC_SAVED_DEST_UDP: process( CLK ) begin if( rising_edge(CLK) ) then - if ( filter_current_state = CLEANUP ) then + if ( FILTER_CS = CLEANUP ) then saved_dest_udp <= (others => '0'); - elsif( (filter_current_state = REMOVE_UDP) and (remove_ctr = x"14") ) then + elsif( (FILTER_CS = REMOVE_UDP) and (remove_ctr = x"14") ) then saved_dest_udp(15 downto 8) <= MAC_RXD_IN; - elsif( (filter_current_state = REMOVE_UDP) and (remove_ctr = x"15") ) then + elsif( (FILTER_CS = REMOVE_UDP) and (remove_ctr = x"15") ) then saved_dest_udp(7 downto 0) <= MAC_RXD_IN; end if; end if; @@ -471,9 +472,9 @@ begin if ( RESET = '1' ) then frame_type_valid <= '0'; elsif( rising_edge(CLK) ) then - if ( filter_current_state = SAVE_FRAME ) then + if ( FILTER_CS = SAVE_FRAME ) then frame_type_valid <= '1'; - elsif( filter_current_state = CLEANUP ) then + elsif( FILTER_CS = CLEANUP ) then frame_type_valid <= '0'; end if; end if; @@ -497,7 +498,7 @@ begin PROC_KILLER_PING: process( CLK ) begin if( rising_edge(CLK) ) then - if( (filter_current_state = SAVE_FRAME) and + if( (FILTER_CS = SAVE_FRAME) and (saved_proto = x"01") and (saved_frame_type = x"0800") and (rx_bytes_ctr = x"001A") and @@ -553,9 +554,9 @@ begin rx_data(7 downto 0) <= MAC_RXD_IN; if( MAC_RX_EN_IN = '1' ) then - if ( filter_current_state = SAVE_FRAME ) then + if ( FILTER_CS = SAVE_FRAME ) then fifo_wr_en <= '1'; - elsif( (filter_current_state = DELAY) ) then + elsif( (FILTER_CS = DELAY) ) then fifo_wr_en <= '1'; else fifo_wr_en <= '0'; @@ -694,7 +695,7 @@ begin if ( RESET = '1' ) then dbg_drp_frames <= (others => '0'); elsif( rising_edge(CLK) ) then - if( (filter_current_state = DELAY) and (frame_type_valid = '0') ) then + if( (FILTER_CS = DELAY) and (frame_type_valid = '0') ) then dbg_drp_frames <= dbg_drp_frames + 1; end if; end if; diff --git a/gbe_trb/base/gbe_logic_wrapper.vhd b/gbe_trb/base/gbe_logic_wrapper.vhd index 5a28c0c..8d8e075 100644 --- a/gbe_trb/base/gbe_logic_wrapper.vhd +++ b/gbe_trb/base/gbe_logic_wrapper.vhd @@ -7,12 +7,12 @@ 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'; - 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'; + SLOWCTRL_BUFFER_SIZE : integer range 1 to 4 := 1 ); port( CLK_125_IN : in std_logic; @@ -107,7 +107,6 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is signal fr_get_frame : std_logic; signal mc_transmit_done : std_logic; --- signal fr_frame_proto : std_logic_vector(15 downto 0); signal rc_frame_proto : std_logic_vector(c_MAX_PROTOCOLS - 1 downto 0); signal mc_type : std_logic_vector(15 downto 0); @@ -138,9 +137,6 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is signal fc_src_ip : std_logic_vector(31 downto 0); signal fc_src_udp : std_logic_vector(15 downto 0); signal fc_type : std_logic_vector(15 downto 0); - signal fc_ihl_version : std_logic_vector(7 downto 0); - signal fc_tos : std_logic_vector(7 downto 0); - signal fc_ttl : std_logic_vector(7 downto 0); signal fc_protocol : std_logic_vector(7 downto 0); signal ft_data : std_logic_vector(8 downto 0); @@ -153,13 +149,8 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is signal link_ok : std_logic; signal dhcp_done : std_logic; - signal monitor_tx_packets : std_logic_vector(31 downto 0); - signal monitor_rx_bytes : std_logic_vector(31 downto 0); - signal monitor_rx_frames : std_logic_vector(31 downto 0); - signal monitor_tx_bytes : std_logic_vector(31 downto 0); - signal monitor_tx_frames : std_logic_vector(31 downto 0); - signal monitor_dropped : std_logic_vector(31 downto 0); - + signal debug_fr : std_logic_vector(31 downto 0); + signal make_reset : std_logic; signal frame_pause : std_logic_vector(31 downto 0); @@ -193,14 +184,11 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is -- DEBUG_OUT(7 downto 0) <= rc_q(7 downto 0); --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- + DEBUG_OUT(31 downto 28) <= debug_fr(31 downto 28); DEBUG_OUT(27 downto 0) <= debug_main(27 downto 0); --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- - fc_ihl_version <= x"45"; - fc_tos <= x"10"; - fc_ttl <= x"ff"; - DHCP_DONE_OUT <= dhcp_done; THE_GBE_MAIN_CONTROL: entity work.gbe_main_control @@ -323,7 +311,7 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is SRC_MAC_ADDRESS_OUT => fc_src_mac, SRC_IP_ADDRESS_OUT => fc_src_ip, SRC_UDP_PORT_OUT => fc_src_udp, - MONITOR_TX_PACKETS_OUT => monitor_tx_packets + MONITOR_TX_PACKETS_OUT => MONITOR_TX_PACKETS_OUT ); THE_FRAME_CONSTR: entity work.gbe_frame_constr @@ -346,21 +334,20 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is SRC_IP_ADDRESS_IN => fc_src_ip, SRC_UDP_PORT_IN => fc_src_udp, FRAME_TYPE_IN => fc_type, - IHL_VERSION_IN => fc_ihl_version, - TOS_IN => fc_tos, + IHL_VERSION_IN => x"45", --fc_ihl_version, + TOS_IN => x"10", --fc_tos, IDENTIFICATION_IN => fc_ident, FLAGS_OFFSET_IN => fc_flags_offset, - TTL_IN => fc_ttl, + TTL_IN => x"ff", --fc_ttl, PROTOCOL_IN => fc_protocol, FRAME_DELAY_IN => frame_pause, FT_TX_DATA_OUT => FT_TX_DATA_OUT, FT_TX_WR_OUT => FT_TX_WR_OUT, FT_TX_FIFOFULL_IN => FT_TX_FIFOFULL_IN, - MONITOR_TX_BYTES_OUT => monitor_tx_bytes, - MONITOR_TX_FRAMES_OUT => monitor_tx_frames + MONITOR_TX_BYTES_OUT => MONITOR_TX_BYTES_OUT, + MONITOR_TX_FRAMES_OUT => MONITOR_TX_FRAMES_OUT ); --- frame_pause <= x"0000" & CFG_THROTTLE_PAUSE_IN; -- TAKE CARE!!! frame_pause <= x"0000" & x"0000"; -- TAKE CARE!!! THE_RECEIVE_CONTROL: entity work.gbe_receive_control @@ -434,20 +421,11 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is OOB_REGISTER_2_OUT => OOB_REGISTER_2_OUT, OOB_REGISTER_3_OUT => OOB_REGISTER_3_OUT, -- - MONITOR_RX_BYTES_OUT => monitor_rx_bytes, - MONITOR_RX_FRAMES_OUT => monitor_rx_frames, - MONITOR_DROPPED_OUT => monitor_dropped, + MONITOR_RX_BYTES_OUT => MONITOR_RX_BYTES_OUT, + MONITOR_RX_FRAMES_OUT => MONITOR_RX_FRAMES_OUT, + MONITOR_DROPPED_OUT => MONITOR_DROPPED_OUT, -- - DEBUG_OUT(15 downto 0) => open, - DEBUG_OUT(31 downto 16) => open + DEBUG_OUT => debug_fr --open ); - MONITOR_RX_FRAMES_OUT <= monitor_rx_frames; - MONITOR_RX_BYTES_OUT <= monitor_rx_bytes; - MONITOR_TX_FRAMES_OUT <= monitor_tx_frames; - MONITOR_TX_BYTES_OUT <= monitor_tx_bytes; - MONITOR_TX_PACKETS_OUT <= monitor_tx_packets; - MONITOR_DROPPED_OUT <= monitor_dropped; - - end architecture gbe_logic_wrapper_arch; diff --git a/gbe_trb/base/gbe_main_control.vhd b/gbe_trb/base/gbe_main_control.vhd index ceaa086..2d668f4 100644 --- a/gbe_trb/base/gbe_main_control.vhd +++ b/gbe_trb/base/gbe_main_control.vhd @@ -337,7 +337,7 @@ begin end if; end process PROC_FLOW_FSM; - PROC_FLOW_TRANSITIONS: process(FLOW_CS, TC_TRANSMIT_DONE_IN, ps_response_ready, tc_data) + PROC_FLOW_TRANSITIONS: process( FLOW_CS, TC_TRANSMIT_DONE_IN, ps_response_ready, tc_data ) begin flow_state <= x"0"; @@ -448,11 +448,8 @@ begin GSC_REPLY_READ_OUT => GSC_REPLY_READ_OUT, GSC_BUSY_IN => GSC_BUSY_IN, MAKE_RESET_OUT => MAKE_RESET_OUT, - MY_TRBNET_ADDRESS_IN => MY_TRBNET_ADDRESS_IN, - CFG_MAX_REPLY_SIZE_IN => CFG_MAX_REPLY_SIZE_IN, - FWD_DST_MAC_IN => FWD_DST_MAC_IN, FWD_DST_IP_IN => FWD_DST_IP_IN, FWD_DST_UDP_IN => FWD_DST_UDP_IN, @@ -462,7 +459,6 @@ begin FWD_EOP_IN => FWD_EOP_IN, FWD_READY_OUT => FWD_READY_OUT, FWD_FULL_OUT => FWD_FULL_OUT, - -- input for statistics from outside MONITOR_SELECT_REC_OUT => MONITOR_SELECT_REC_OUT, MONITOR_SELECT_REC_BYTES_OUT => MONITOR_SELECT_REC_BYTES_OUT, @@ -481,11 +477,10 @@ begin end if; end process PROC_SYNC; - PROC_LOADING_DONE: process( CLK ) begin if rising_edge(CLK) then - if (RC_DATA_IN(8) = '1' and ps_wr_en_q = '1') then + if ((RC_DATA_IN(8) = '1') and (ps_wr_en_q = '1') ) then RC_LOADING_DONE_OUT <= '1'; else RC_LOADING_DONE_OUT <= '0'; @@ -505,7 +500,7 @@ begin PROC_LOADED_BYTES_CTR: process( CLK ) begin if rising_edge(CLK) then - if ( REDIRECT_CS = IDLE) then + if ( REDIRECT_CS = IDLE ) then loaded_bytes_ctr <= (others => '0'); elsif( ((REDIRECT_CS = LOAD) or (REDIRECT_CS = DROP)) ) then loaded_bytes_ctr <= loaded_bytes_ctr + 1; diff --git a/gbe_trb/base/gbe_receive_control.vhd b/gbe_trb/base/gbe_receive_control.vhd index 53948c2..f364d75 100644 --- a/gbe_trb/base/gbe_receive_control.vhd +++ b/gbe_trb/base/gbe_receive_control.vhd @@ -60,8 +60,6 @@ architecture gbe_receive_control_arch of gbe_receive_control is signal state : std_logic_vector(3 downto 0); signal proto_code : std_logic_vector(c_MAX_PROTOCOLS - 1 downto 0); signal reset_prioritizer : std_logic; - - -- debug only signal saved_proto : std_logic_vector(c_MAX_PROTOCOLS - 1 downto 0); begin @@ -176,8 +174,6 @@ begin else saved_proto <= (others => '0'); end if; - else - saved_proto <= saved_proto; end if; end if; end process SAVED_PROTO_PROC; diff --git a/gbe_trb/base/gbe_wrapper_fifo.vhd b/gbe_trb/base/gbe_wrapper_fifo.vhd index 8f0d475..569a6ed 100644 --- a/gbe_trb/base/gbe_wrapper_fifo.vhd +++ b/gbe_trb/base/gbe_wrapper_fifo.vhd @@ -16,7 +16,6 @@ entity gbe_wrapper_fifo is port( CLK_125_IN : in std_logic; RESET : in std_logic; - GSR_N : in std_logic; -- we connect to FIFO interface directly -- FIFO interface TX (send frames) FIFO_DATA_OUT : out std_logic_vector(8 downto 0); diff --git a/gbe_trb/protocols/gbe_response_constructor_ARP.vhd b/gbe_trb/protocols/gbe_response_constructor_ARP.vhd index 4e988c4..1384dd3 100644 --- a/gbe_trb/protocols/gbe_response_constructor_ARP.vhd +++ b/gbe_trb/protocols/gbe_response_constructor_ARP.vhd @@ -45,7 +45,7 @@ end gbe_response_constructor_ARP; architecture gbe_response_constructor_ARP_arch of gbe_response_constructor_ARP is - attribute syn_encoding : string; + attribute syn_encoding: string; type dissect_states is (IDLE, READ_FRAME, DECIDE, LOAD_FRAME, WAIT_FOR_LOAD, CLEANUP); signal dissect_current_state, dissect_next_state : dissect_states; @@ -102,7 +102,7 @@ begin when IDLE => state <= x"1"; - if (PS_WR_EN_IN = '1' and PS_ACTIVATE_IN = '1') then + if( (PS_WR_EN_IN = '1') and (PS_ACTIVATE_IN = '1') ) then dissect_next_state <= READ_FRAME; else dissect_next_state <= IDLE; @@ -110,7 +110,7 @@ begin when READ_FRAME => state <= x"2"; - if (PS_DATA_IN(8) = '1') then + if( PS_DATA_IN(8) = '1' ) then dissect_next_state <= DECIDE; else dissect_next_state <= READ_FRAME; @@ -118,16 +118,16 @@ begin when DECIDE => state <= x"3"; - if (saved_target_ip = MY_IP_IN) then + if( saved_target_ip = MY_IP_IN ) then dissect_next_state <= WAIT_FOR_LOAD; - -- in case the request is not for me, drop it + -- in case the request is not for me, drop it else dissect_next_state <= IDLE; end if; when WAIT_FOR_LOAD => state <= x"4"; - if (PS_SELECTED_IN = '1') then + if( PS_SELECTED_IN = '1' ) then dissect_next_state <= LOAD_FRAME; else dissect_next_state <= WAIT_FOR_LOAD; @@ -135,7 +135,7 @@ begin when LOAD_FRAME => state <= x"5"; - if (data_ctr = 28) then + if( data_ctr = 28 ) then dissect_next_state <= CLEANUP; else dissect_next_state <= LOAD_FRAME; @@ -157,13 +157,13 @@ begin if ( (dissect_current_state = IDLE) and (PS_WR_EN_IN = '0') ) then data_ctr <= 0; -- data_ctr <= 1; - elsif( dissect_current_state = WAIT_FOR_LOAD ) then + elsif( (dissect_current_state = WAIT_FOR_LOAD) ) then data_ctr <= 1; - elsif( dissect_current_state = IDLE and PS_WR_EN_IN = '1' and PS_ACTIVATE_IN = '1' ) then + elsif( (dissect_current_state = IDLE) and (PS_WR_EN_IN = '1') and (PS_ACTIVATE_IN = '1') ) then data_ctr <= data_ctr + 1; - elsif( dissect_current_state = READ_FRAME and PS_WR_EN_IN = '1' and PS_ACTIVATE_IN = '1' ) then -- in case of saving data from incoming frame + elsif( (dissect_current_state = READ_FRAME) and (PS_WR_EN_IN = '1') and (PS_ACTIVATE_IN = '1') ) then -- in case of saving data from incoming frame data_ctr <= data_ctr + 1; - elsif( dissect_current_state = LOAD_FRAME and PS_SELECTED_IN = '1' and TC_RD_EN_IN = '1' ) then -- in case of constructing response + elsif( (dissect_current_state = LOAD_FRAME) and (PS_SELECTED_IN = '1') and (TC_RD_EN_IN = '1') ) then -- in case of constructing response data_ctr <= data_ctr + 1; end if; end if; @@ -176,11 +176,11 @@ begin saved_sender_ip <= (others => '0'); saved_target_ip <= (others => '0'); elsif( rising_edge(CLK) ) then - if (dissect_current_state = READ_FRAME) then - case (data_ctr) is + if( dissect_current_state = READ_FRAME ) then + case data_ctr is when 6 => - saved_opcode(7 downto 0) <= PS_DATA_IN(7 downto 0); + saved_opcode(7 downto 0) <= PS_DATA_IN(7 downto 0); when 7 => saved_opcode(15 downto 8) <= PS_DATA_IN(7 downto 0); when 13 => @@ -211,12 +211,12 @@ begin if( rising_edge(CLK) ) then tc_data(8) <= '0'; - if (dissect_current_state = LOAD_FRAME) then + if( dissect_current_state = LOAD_FRAME ) then for i in 0 to 7 loop tc_data(i) <= values((data_ctr - 1) * 8 + i); end loop; -- mark the last byte - if (data_ctr = 28) then + if( data_ctr = 28 ) then tc_data(8) <= '1'; end if; else @@ -231,7 +231,7 @@ begin PROC_PS_RESPONSE_SYNC: process( CLK ) begin if( rising_edge(CLK) ) then - if( dissect_current_state = WAIT_FOR_LOAD or dissect_current_state = LOAD_FRAME or dissect_current_state = CLEANUP ) then + if( (dissect_current_state = WAIT_FOR_LOAD) or (dissect_current_state = LOAD_FRAME) or (dissect_current_state = CLEANUP) ) then PS_RESPONSE_READY_OUT <= '1'; else PS_RESPONSE_READY_OUT <= '0'; @@ -246,7 +246,6 @@ begin end process PROC_PS_RESPONSE_SYNC; TC_FRAME_SIZE_OUT <= x"001c"; -- fixed frame size - TC_FRAME_TYPE_OUT <= x"0608"; TC_DEST_MAC_OUT <= PS_SRC_MAC_ADDRESS_IN; TC_DEST_IP_OUT <= x"00000000"; -- doesnt matter @@ -258,5 +257,3 @@ begin TC_IDENT_OUT <= (others => '0'); -- doesn't matter end gbe_response_constructor_ARP_arch; - - diff --git a/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd b/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd index 45f1162..f7c82c9 100644 --- a/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd +++ b/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd @@ -52,20 +52,20 @@ architecture gbe_response_constructor_DHCP_arch of gbe_response_constructor_DHCP attribute syn_encoding : string; type main_states is (BOOTING, DELAY, SENDING_DISCOVER, WAITING_FOR_OFFER, SENDING_REQUEST, WAITING_FOR_ACK, ESTABLISHED); - signal main_current_state, main_next_state : main_states; - attribute syn_encoding of main_current_state: signal is "onehot"; + signal MAIN_CS, MAIN_NS : main_states; + attribute syn_encoding of MAIN_CS: signal is "onehot"; type receive_states is (IDLE, DISCARD, CLEANUP, SAVE_VALUES); - signal receive_current_state, receive_next_state : receive_states; - attribute syn_encoding of receive_current_state: signal is "onehot"; + signal RECEIVE_CS, RECEIVE_NS : receive_states; + attribute syn_encoding of RECEIVE_CS: signal is "onehot"; type discover_states is (IDLE, WAIT_FOR_LOAD, BOOTP_HEADERS, CLIENT_IP, YOUR_IP, ZEROS1, MY_MAC, ZEROS2, VENDOR_VALS, VENDOR_VALS2, TERMINATION, CLEANUP); - signal construct_current_state, construct_next_state : discover_states; - attribute syn_encoding of construct_current_state: signal is "onehot"; + signal CONSTRUCT_CS, CONSTRUCT_NS : discover_states; + attribute syn_encoding of CONSTRUCT_CS: signal is "onehot"; - type stats_states is (IDLE, LOAD_SENT, LOAD_RECEIVED, LOAD_DISCARDED, CLEANUP); - signal stats_current_state, stats_next_state : stats_states; - attribute syn_encoding of stats_current_state : signal is "onehot"; +-- type stats_states is (IDLE, LOAD_SENT, LOAD_RECEIVED, LOAD_DISCARDED, CLEANUP); +-- signal STATS_CS, STATS_NS : stats_states; +-- attribute syn_encoding of STATS_CS : signal is "onehot"; signal state : std_logic_vector(3 downto 0); signal rec_frames : std_logic_vector(15 downto 0); @@ -103,17 +103,15 @@ architecture gbe_response_constructor_DHCP_arch of gbe_response_constructor_DHCP signal wait_value : unsigned(31 downto 0); - signal my_ip : std_logic_vector(31 downto 0); - begin -- **** -- fixing the constant values for DHCP request headers - TC_DEST_MAC_OUT <= x"ffffffffffff" when (main_current_state = BOOTING or main_current_state = SENDING_DISCOVER) else saved_server_mac; - TC_DEST_IP_OUT <= x"ffffffff" when (main_current_state = BOOTING or main_current_state = SENDING_DISCOVER) else saved_server_ip; + TC_DEST_MAC_OUT <= x"ffffffffffff" when (MAIN_CS = BOOTING or MAIN_CS = SENDING_DISCOVER) else saved_server_mac; + TC_DEST_IP_OUT <= x"ffffffff" when (MAIN_CS = BOOTING or MAIN_CS = SENDING_DISCOVER) else saved_server_ip; TC_DEST_UDP_OUT <= x"4300"; TC_SRC_MAC_OUT <= MY_MAC_IN; - TC_SRC_IP_OUT <= x"00000000" when (main_current_state = BOOTING or main_current_state = SENDING_DISCOVER) else saved_proposed_ip; + TC_SRC_IP_OUT <= x"00000000" when (MAIN_CS = BOOTING or MAIN_CS = SENDING_DISCOVER) else saved_proposed_ip; TC_SRC_UDP_OUT <= x"4400"; TC_IP_PROTOCOL_OUT <= x"11"; -- udp bootp_hdr(7 downto 0) <= x"01"; -- message type(request) @@ -124,7 +122,7 @@ begin bootp_hdr(95 downto 64) <= x"0000_0000"; -- seconds elapsed/flags transaction_id <= x"cefa" & MY_MAC_IN(47 downto 40) & MY_MAC_IN(23 downto 16); vendor_values(31 downto 0) <= x"63538263"; -- magic cookie (dhcp message) - vendor_values(55 downto 32) <= x"010135" when (main_current_state = BOOTING or main_current_state = SENDING_DISCOVER) else x"030135"; -- dhcp discover, then dhcp request + vendor_values(55 downto 32) <= x"010135" when (MAIN_CS = BOOTING or MAIN_CS = SENDING_DISCOVER) else x"030135"; -- dhcp discover, then dhcp request vendor_values(79 downto 56) <= x"01073d"; -- client identifier vendor_values(127 downto 80) <= MY_MAC_IN; -- client identifier vendor_values(143 downto 128) <= x"040c"; -- client name @@ -135,106 +133,104 @@ begin --***************** -- setting of global variable for IP address - my_ip <= saved_true_ip when main_current_state = ESTABLISHED else (others => '0'); - MY_IP_OUT <= my_ip; - -- + MY_IP_OUT <= saved_true_ip when (MAIN_CS) = ESTABLISHED else (others => '0'); --***************** PROC_SAVE_SERVER_ADDR: process( CLK ) begin if( rising_edge(CLK) ) then - if ( main_current_state = BOOTING ) then + if ( MAIN_CS = BOOTING ) then saved_server_mac <= (others => '0'); saved_server_ip <= (others => '0'); - elsif( (main_current_state = WAITING_FOR_OFFER) and (receive_current_state = SAVE_VALUES and save_ctr = 1) ) then + elsif( (MAIN_CS = WAITING_FOR_OFFER) and (RECEIVE_CS = SAVE_VALUES and save_ctr = 1) ) then saved_server_mac <= PS_SRC_MAC_ADDRESS_IN; saved_server_ip <= PS_SRC_IP_ADDRESS_IN; end if; end if; end process PROC_SAVE_SERVER_ADDR; - -- **** MAIN MACHINE PART PROC_MAIN_FSM: process( CLK, RESET) begin if ( RESET = '1' ) then - main_current_state <= BOOTING; + MAIN_CS <= BOOTING; elsif( rising_edge(CLK) ) then - main_current_state <= main_next_state; + MAIN_CS <= MAIN_NS; end if; end process PROC_MAIN_FSM; wait_value <= x"2000_0000"; -- wait_value <= x"0000_2000"; - PROC_MAIN_TRANSITIONS : process(main_current_state, DHCP_START_IN, construct_current_state, wait_ctr, receive_current_state, PS_DATA_IN, wait_value) + PROC_MAIN_TRANSITIONS : process( MAIN_CS, DHCP_START_IN, CONSTRUCT_CS, wait_ctr, RECEIVE_CS, PS_DATA_IN, wait_value ) begin state2 <= x"0"; - case (main_current_state) is + case (MAIN_CS) is when BOOTING => state2 <= x"1"; - if (DHCP_START_IN = '1') then - main_next_state <= DELAY; + if( DHCP_START_IN = '1' ) then + MAIN_NS <= DELAY; else - main_next_state <= BOOTING; + MAIN_NS <= BOOTING; end if; when DELAY => state2 <= x"2"; - if (wait_ctr = wait_value) then - main_next_state <= SENDING_DISCOVER; + if( wait_ctr = wait_value ) then + MAIN_NS <= SENDING_DISCOVER; else - main_next_state <= DELAY; + MAIN_NS <= DELAY; end if; when SENDING_DISCOVER => state2 <= x"3"; - if (construct_current_state = CLEANUP) then - main_next_state <= WAITING_FOR_OFFER; + if( CONSTRUCT_CS = CLEANUP ) then + MAIN_NS <= WAITING_FOR_OFFER; else - main_next_state <= SENDING_DISCOVER; + MAIN_NS <= SENDING_DISCOVER; end if; when WAITING_FOR_OFFER => state2 <= x"4"; - if (receive_current_state = SAVE_VALUES) and (PS_DATA_IN(8) = '1') then - main_next_state <= SENDING_REQUEST; - elsif (wait_ctr = x"2000_0000") then - main_next_state <= BOOTING; + if( (RECEIVE_CS = SAVE_VALUES) and (PS_DATA_IN(8) = '1') ) then + MAIN_NS <= SENDING_REQUEST; + elsif( wait_ctr = x"2000_0000" ) then + MAIN_NS <= BOOTING; else - main_next_state <= WAITING_FOR_OFFER; + MAIN_NS <= WAITING_FOR_OFFER; end if; when SENDING_REQUEST => state2 <= x"5"; - if (construct_current_state = CLEANUP) then - main_next_state <= WAITING_FOR_ACK; + if( CONSTRUCT_CS = CLEANUP ) then + MAIN_NS <= WAITING_FOR_ACK; else - main_next_state <= SENDING_REQUEST; + MAIN_NS <= SENDING_REQUEST; end if; when WAITING_FOR_ACK => state2 <= x"6"; - if (receive_current_state = SAVE_VALUES) and (PS_DATA_IN(8) = '1') then - main_next_state <= ESTABLISHED; - elsif (wait_ctr = x"2000_0000") then - main_next_state <= BOOTING; + if( (RECEIVE_CS = SAVE_VALUES) and (PS_DATA_IN(8) = '1') ) then + MAIN_NS <= ESTABLISHED; + elsif( wait_ctr = x"2000_0000" ) then + MAIN_NS <= BOOTING; else - main_next_state <= WAITING_FOR_ACK; + MAIN_NS <= WAITING_FOR_ACK; end if; when ESTABLISHED => state2 <= x"7"; if( DHCP_START_IN = '0' ) then - main_next_state <= BOOTING; + MAIN_NS <= BOOTING; else - main_next_state <= ESTABLISHED; + MAIN_NS <= ESTABLISHED; end if; - when others => main_next_state <= BOOTING; + when others => + MAIN_NS <= BOOTING; end case; @@ -243,82 +239,83 @@ begin PROC_WAIT_CTR: process( CLK ) begin if( rising_edge(CLK) ) then - if ( main_current_state = SENDING_DISCOVER or main_current_state = SENDING_REQUEST or main_current_state = BOOTING ) then + if ( (MAIN_CS = SENDING_DISCOVER) or (MAIN_CS = SENDING_REQUEST) or (MAIN_CS = BOOTING) ) then wait_ctr <= (others => '0'); - elsif( main_current_state = WAITING_FOR_ACK and receive_current_state = SAVE_VALUES and PS_DATA_IN(8) = '1' ) then + elsif( (MAIN_CS = WAITING_FOR_ACK) and (RECEIVE_CS = SAVE_VALUES) and (PS_DATA_IN(8) = '1') ) then wait_ctr <= (others => '0'); - elsif( main_current_state = WAITING_FOR_ACK or main_current_state = WAITING_FOR_OFFER or main_current_state = DELAY or main_current_state = ESTABLISHED ) then + elsif( (MAIN_CS = WAITING_FOR_ACK) or (MAIN_CS = WAITING_FOR_OFFER) or (MAIN_CS = DELAY) or (MAIN_CS = ESTABLISHED) ) then wait_ctr <= wait_ctr + 1; end if; end if; end process PROC_WAIT_CTR; - DHCP_DONE_OUT <= '1' when main_current_state = ESTABLISHED else '0'; + DHCP_DONE_OUT <= '1' when MAIN_CS = ESTABLISHED else '0'; -- **** MESSAGES RECEIVING PART PROC_RECEIVE_FSM: process( CLK, RESET ) begin if ( RESET = '1' ) then - receive_current_state <= IDLE; + RECEIVE_CS <= IDLE; elsif( rising_edge(CLK) ) then - receive_current_state <= receive_next_state; + RECEIVE_CS <= RECEIVE_NS; end if; end process PROC_RECEIVE_FSM; - PROC_RECEIVE_TRANSITIONS: process( receive_current_state, main_current_state, bootp_hdr, saved_dhcp_type, saved_transaction_id, + PROC_RECEIVE_TRANSITIONS: process( RECEIVE_CS, MAIN_CS, bootp_hdr, saved_dhcp_type, saved_transaction_id, PS_DATA_IN, PS_DEST_MAC_ADDRESS_IN, MY_MAC_IN, PS_ACTIVATE_IN, PS_WR_EN_IN, save_ctr ) begin state3 <= x"0"; - case receive_current_state is + case RECEIVE_CS is when IDLE => state3 <= x"1"; - if (PS_ACTIVATE_IN = '1' and PS_WR_EN_IN = '1') then - if (main_current_state = WAITING_FOR_OFFER or main_current_state = WAITING_FOR_ACK) then -- ready to receive dhcp frame - if (PS_DEST_MAC_ADDRESS_IN = MY_MAC_IN) then -- check if i'm the addressee (discards broadcasts also) - receive_next_state <= SAVE_VALUES; + if( (PS_ACTIVATE_IN = '1') and (PS_WR_EN_IN = '1') ) then + if( (MAIN_CS = WAITING_FOR_OFFER) or (MAIN_CS = WAITING_FOR_ACK) ) then -- ready to receive dhcp frame + if( PS_DEST_MAC_ADDRESS_IN = MY_MAC_IN ) then -- check if i'm the addressee (discards broadcasts also) + RECEIVE_NS <= SAVE_VALUES; else - receive_next_state <= DISCARD; -- discard if the frame is not for me + RECEIVE_NS <= DISCARD; -- discard if the frame is not for me end if; else - receive_next_state <= DISCARD; -- discard if the frame arrived at wrong time + RECEIVE_NS <= DISCARD; -- discard if the frame arrived at wrong time end if; else - receive_next_state <= IDLE; + RECEIVE_NS <= IDLE; end if; when SAVE_VALUES => state3 <= x"2"; - if (PS_DATA_IN(8) = '1') then - receive_next_state <= CLEANUP; + if ( PS_DATA_IN(8) = '1' ) then + RECEIVE_NS <= CLEANUP; -- check if the same transaction - elsif (save_ctr = 9) and (saved_transaction_id /= bootp_hdr(63 downto 32)) then - receive_next_state <= DISCARD; + elsif( (save_ctr = 9) and (saved_transaction_id /= bootp_hdr(63 downto 32)) ) then + RECEIVE_NS <= DISCARD; -- if the wrong message at the wrong time - elsif (main_current_state = WAITING_FOR_OFFER) and (save_ctr = 242) and (saved_dhcp_type /= x"020135") then - receive_next_state <= DISCARD; + elsif( (MAIN_CS = WAITING_FOR_OFFER) and (save_ctr = 242) and (saved_dhcp_type /= x"020135") ) then + RECEIVE_NS <= DISCARD; -- if the wrong message at the wrong time - elsif (main_current_state = WAITING_FOR_ACK) and (save_ctr = 242) and (saved_dhcp_type /= x"050135") then - receive_next_state <= DISCARD; + elsif( (MAIN_CS = WAITING_FOR_ACK) and (save_ctr = 242) and (saved_dhcp_type /= x"050135") ) then + RECEIVE_NS <= DISCARD; else - receive_next_state <= SAVE_VALUES; + RECEIVE_NS <= SAVE_VALUES; end if; when DISCARD => state3 <= x"3"; - if (PS_DATA_IN(8) = '1') then - receive_next_state <= CLEANUP; + if( PS_DATA_IN(8) = '1' ) then + RECEIVE_NS <= CLEANUP; else - receive_next_state <= DISCARD; + RECEIVE_NS <= DISCARD; end if; when CLEANUP => state3 <= x"4"; - receive_next_state <= IDLE; + RECEIVE_NS <= IDLE; - when others => receive_next_state <= IDLE; + when others => + RECEIVE_NS <= IDLE; end case; @@ -327,9 +324,9 @@ begin PROC_SAVE_CTR: process( CLK ) begin if( rising_edge(CLK) ) then - if ( receive_current_state = IDLE ) then + if ( RECEIVE_CS = IDLE ) then save_ctr <= 0; - elsif( receive_current_state = SAVE_VALUES and PS_WR_EN_IN = '1' and PS_ACTIVATE_IN = '1' ) then + elsif( (RECEIVE_CS = SAVE_VALUES) and (PS_WR_EN_IN = '1') and (PS_ACTIVATE_IN = '1') ) then save_ctr <= save_ctr + 1; end if; end if; @@ -338,13 +335,13 @@ begin PROC_SAVE_VALUES: process( CLK ) begin if( rising_edge(CLK) ) then - if ( main_current_state = BOOTING ) then + if ( MAIN_CS = BOOTING ) then saved_transaction_id <= (others => '0'); saved_proposed_ip <= (others => '0'); saved_true_ip <= (others => '0'); saved_dhcp_type <= (others => '0'); -- dissection of DHCP Offer message - elsif( main_current_state = WAITING_FOR_OFFER and receive_current_state = SAVE_VALUES ) then + elsif( (MAIN_CS = WAITING_FOR_OFFER) and (RECEIVE_CS = SAVE_VALUES) ) then saved_true_ip <= saved_true_ip; @@ -389,7 +386,7 @@ begin end case; -- dissection on DHCP Ack message - elsif( main_current_state = WAITING_FOR_ACK and receive_current_state = SAVE_VALUES ) then + elsif( (MAIN_CS = WAITING_FOR_ACK) and (RECEIVE_CS = SAVE_VALUES) ) then saved_proposed_ip <= saved_proposed_ip; @@ -407,7 +404,6 @@ begin when 6 => saved_transaction_id(31 downto 24) <= PS_DATA_IN(7 downto 0); - when 15 => saved_true_ip(7 downto 0) <= PS_DATA_IN(7 downto 0); @@ -420,7 +416,6 @@ begin when 18 => saved_true_ip(31 downto 24) <= PS_DATA_IN(7 downto 0); - when 239 => saved_dhcp_type(7 downto 0) <= PS_DATA_IN(7 downto 0); @@ -430,7 +425,8 @@ begin when 241 => saved_dhcp_type(23 downto 16) <= PS_DATA_IN(7 downto 0); - when others => null; + when others => + null; end case; end if; @@ -442,118 +438,118 @@ begin PROC_CONSTRUCT_FSM: process( CLK, RESET ) begin if ( RESET = '1' ) then - construct_current_state <= IDLE; + CONSTRUCT_CS <= IDLE; elsif( rising_edge(CLK) ) then - if( main_current_state = BOOTING ) then - construct_current_state <= IDLE; + if( MAIN_CS = BOOTING ) then + CONSTRUCT_CS <= IDLE; else - construct_current_state <= construct_next_state; + CONSTRUCT_CS <= CONSTRUCT_NS; end if; end if; end process PROC_CONSTRUCT_FSM; - PROC_CONSTRUCT_TRANSITIONS: process( construct_current_state, main_current_state, load_ctr, PS_SELECTED_IN ) + PROC_CONSTRUCT_TRANSITIONS: process( CONSTRUCT_CS, MAIN_CS, load_ctr, PS_SELECTED_IN ) begin state <= x"0"; - case construct_current_state is + case CONSTRUCT_CS is when IDLE => state <= x"1"; - if (main_current_state = SENDING_DISCOVER) or (main_current_state = SENDING_REQUEST) then - construct_next_state <= WAIT_FOR_LOAD; + if( (MAIN_CS = SENDING_DISCOVER) or (MAIN_CS = SENDING_REQUEST) ) then + CONSTRUCT_NS <= WAIT_FOR_LOAD; else - construct_next_state <= IDLE; + CONSTRUCT_NS <= IDLE; end if; when WAIT_FOR_LOAD => state <= x"2"; - if (PS_SELECTED_IN = '1') then - construct_next_state <= BOOTP_HEADERS; + if( PS_SELECTED_IN = '1' ) then + CONSTRUCT_NS <= BOOTP_HEADERS; else - construct_next_state <= WAIT_FOR_LOAD; + CONSTRUCT_NS <= WAIT_FOR_LOAD; end if; - when BOOTP_HEADERS => state <= x"3"; - if (load_ctr = 11) then - construct_next_state <= CLIENT_IP; + if( load_ctr = 11 ) then + CONSTRUCT_NS <= CLIENT_IP; else - construct_next_state <= BOOTP_HEADERS; + CONSTRUCT_NS <= BOOTP_HEADERS; end if; when CLIENT_IP => state <= x"4"; - if (load_ctr = 15) then - construct_next_state <= YOUR_IP; + if( load_ctr = 15 ) then + CONSTRUCT_NS <= YOUR_IP; else - construct_next_state <= CLIENT_IP; + CONSTRUCT_NS <= CLIENT_IP; end if; when YOUR_IP => state <= x"5"; - if (load_ctr = 19) then - construct_next_state <= ZEROS1; + if( load_ctr = 19 ) then + CONSTRUCT_NS <= ZEROS1; else - construct_next_state <= YOUR_IP; + CONSTRUCT_NS <= YOUR_IP; end if; when ZEROS1 => state <= x"6"; - if (load_ctr = 27) then - construct_next_state <= MY_MAC; + if( load_ctr = 27 ) then + CONSTRUCT_NS <= MY_MAC; else - construct_next_state <= ZEROS1; + CONSTRUCT_NS <= ZEROS1; end if; when MY_MAC => state <= x"7"; - if (load_ctr = 33) then - construct_next_state <= ZEROS2; + if( load_ctr = 33 ) then + CONSTRUCT_NS <= ZEROS2; else - construct_next_state <= MY_MAC; + CONSTRUCT_NS <= MY_MAC; end if; when ZEROS2 => state <= x"8"; - if (load_ctr = 235) then - construct_next_state <= VENDOR_VALS; + if( load_ctr = 235 ) then + CONSTRUCT_NS <= VENDOR_VALS; else - construct_next_state <= ZEROS2; + CONSTRUCT_NS <= ZEROS2; end if; when VENDOR_VALS => state <= x"9"; - if (load_ctr = 257) then + if( load_ctr = 257 ) then -- for discover it's enough of values - if (main_current_state = SENDING_DISCOVER) then - construct_next_state <= TERMINATION; + if( MAIN_CS = SENDING_DISCOVER ) then + CONSTRUCT_NS <= TERMINATION; -- for request there is some more values needed else - construct_next_state <= VENDOR_VALS2; + CONSTRUCT_NS <= VENDOR_VALS2; end if; else - construct_next_state <= VENDOR_VALS; + CONSTRUCT_NS <= VENDOR_VALS; end if; when VENDOR_VALS2 => state <= x"a"; - if (load_ctr = 263) then - construct_next_state <= TERMINATION; + if( load_ctr = 263 ) then + CONSTRUCT_NS <= TERMINATION; else - construct_next_state <= VENDOR_VALS2; + CONSTRUCT_NS <= VENDOR_VALS2; end if; when TERMINATION => state <= x"b"; - construct_next_state <= CLEANUP; + CONSTRUCT_NS <= CLEANUP; when CLEANUP => state <= x"c"; - construct_next_state <= IDLE; + CONSTRUCT_NS <= IDLE; - when others => construct_next_state <= IDLE; + when others => + CONSTRUCT_NS <= IDLE; end case; end process PROC_CONSTRUCT_TRANSITIONS; @@ -561,7 +557,7 @@ begin PROC_LOAD_CTR: process( CLK ) begin if( rising_edge(CLK) ) then - if ( construct_current_state = IDLE ) then + if ( CONSTRUCT_CS = IDLE ) then load_ctr <= 0; elsif( (TC_RD_EN_IN = '1') and (PS_SELECTED_IN = '1') ) then load_ctr <= load_ctr + 1; @@ -572,7 +568,7 @@ begin PROC_TC_DATA: process( CLK ) begin if( rising_edge(CLK) ) then - case (construct_current_state) is + case (CONSTRUCT_CS) is when BOOTP_HEADERS => for i in 0 to 7 loop @@ -581,9 +577,9 @@ begin tc_data(8) <= '0'; when CLIENT_IP => - if (main_current_state = SENDING_DISCOVER) then + if ( MAIN_CS = SENDING_DISCOVER ) then tc_data(7 downto 0) <= x"00"; - elsif (main_current_state = SENDING_REQUEST) then + elsif( MAIN_CS = SENDING_REQUEST ) then for i in 0 to 7 loop tc_data(i) <= saved_proposed_ip((load_ctr - 12) * 8 + i); end loop; @@ -639,13 +635,13 @@ begin PROC_PS_RESPONSE_SYNC: process( CLK ) begin if( rising_edge(CLK) ) then - if( construct_current_state = IDLE or construct_current_state = CLEANUP ) then + if( (CONSTRUCT_CS = IDLE) or (CONSTRUCT_CS = CLEANUP) ) then PS_RESPONSE_READY_OUT <= '0'; else PS_RESPONSE_READY_OUT <= '1'; end if; - if( construct_current_state = IDLE ) then + if( CONSTRUCT_CS = IDLE ) then PS_BUSY_OUT <= '0'; else PS_BUSY_OUT <= '1'; @@ -654,7 +650,7 @@ begin end process PROC_PS_RESPONSE_SYNC; -- fixed sizes for discover and request messages - TC_FRAME_SIZE_OUT <= x"0103" when (main_current_state = SENDING_DISCOVER) else x"0109"; + TC_FRAME_SIZE_OUT <= x"0103" when (MAIN_CS = SENDING_DISCOVER) else x"0109"; TC_FRAME_TYPE_OUT <= x"0008"; -- frame type: ip TC_IDENT_OUT <= x"1" & std_logic_vector(sent_frames(11 downto 0)); @@ -663,7 +659,7 @@ begin if ( RESET = '1') then sent_frames <= (others => '0'); elsif( rising_edge(CLK) ) then - if( construct_current_state = CLEANUP ) then + if( CONSTRUCT_CS = CLEANUP ) then sent_frames <= sent_frames + 1; end if; end if; -- 2.43.0