From: Michael Boehmer Date: Mon, 7 Nov 2022 19:41:40 +0000 (+0100) Subject: DHCP works now with ne frame receiver. Bug fixed: pauses in MAC data stream not handled. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=8420f00626ade96b5f96bee92526aee723a7c5a9;p=trbnet.git DHCP works now with ne frame receiver. Bug fixed: pauses in MAC data stream not handled. --- diff --git a/gbe_trb/base/gbe_frame_receiver.vhd b/gbe_trb/base/gbe_frame_receiver.vhd index c212058..a805030 100644 --- a/gbe_trb/base/gbe_frame_receiver.vhd +++ b/gbe_trb/base/gbe_frame_receiver.vhd @@ -83,7 +83,7 @@ architecture gbe_frame_receiver_arch of gbe_frame_receiver is signal stored_src_port : std_logic_vector(15 downto 0); signal stored_dst_port : std_logic_vector(15 downto 0); - signal fifo_pl_wr_x : std_logic; +-- signal fifo_pl_wr_x : std_logic; signal fifo_pl_wr : std_logic; signal fifo_hd_wr_x : std_logic; signal fifo_hd_wr : std_logic; @@ -117,6 +117,8 @@ architecture gbe_frame_receiver_arch of gbe_frame_receiver is signal drop_frame_x : std_logic; signal drop_frame : std_logic; + signal fifo_wr_en : std_logic; + begin -- buffer incoming signals @@ -132,13 +134,13 @@ begin begin if ( RESET = '1' ) then DECODE_CS <= IDLE; - fifo_pl_wr <= '0'; +-- fifo_pl_wr <= '0'; fifo_hd_wr <= '0'; drop_frame <= '0'; rst_bytes <= '1'; elsif( rising_edge(CLK) ) then DECODE_CS <= DECODE_NS; - fifo_pl_wr <= fifo_pl_wr_x; +-- fifo_pl_wr <= fifo_pl_wr_x; fifo_hd_wr <= fifo_hd_wr_x; drop_frame <= drop_frame_x; rst_bytes <= rst_bytes_x; @@ -149,7 +151,7 @@ begin is_my_mac_x, is_broadcast_x, is_arp_x, is_ipv4_x, is_udp_x, is_version_x, is_sctrl_x, is_icmp_x ) begin - fifo_pl_wr_x <= '0'; +-- fifo_pl_wr_x <= '0'; fifo_hd_wr_x <= '0'; drop_frame_x <= '0'; rst_bytes_x <= '0'; @@ -181,7 +183,7 @@ begin if( (mac_rx_eof_q = '0') ) then -- payload available, store it DECODE_NS <= STORE_FRAME; - fifo_pl_wr_x <= '1'; +-- fifo_pl_wr_x <= '1'; else -- empty payload, must never happen with ARP, so we drop it DECODE_NS <= LAST_BYTE; @@ -196,7 +198,7 @@ begin if( (mac_rx_eof_q = '0') ) then -- payload available DECODE_NS <= STORE_FRAME; - fifo_pl_wr_x <= '1'; +-- fifo_pl_wr_x <= '1'; else -- empty payload, must never happen with ICMP, so we drop it DECODE_NS <= LAST_BYTE; @@ -214,7 +216,7 @@ begin if( (mac_rx_eof_q = '0') ) then -- payload available DECODE_NS <= STORE_FRAME; - fifo_pl_wr_x <= '1'; +-- fifo_pl_wr_x <= '1'; else -- empty payload, store raw frame, check that later? DECODE_NS <= LAST_BYTE; @@ -255,7 +257,7 @@ begin when STORE_FRAME => decode_fsm <= x"3"; - fifo_pl_wr_x <= '1'; +-- fifo_pl_wr_x <= '1'; if( MAC_RX_EOF_IN = '1' ) then DECODE_NS <= LAST_BYTE; fifo_hd_wr_x <= '1'; @@ -285,19 +287,51 @@ begin end case; end process PROC_DECODE_TRANSITIONS; - -- counter for decoding the byte stream - PROC_DECODE_CTR: process( CLK, RESET ) - begin - if ( RESET = '1' ) then - decode_ctr <= (others => '0'); +-- -- counter for decoding the byte stream +-- PROC_DECODE_CTR: process( CLK, RESET ) +-- begin +-- if ( RESET = '1' ) then +-- decode_ctr <= (others => '0'); +-- elsif( rising_edge(CLK) ) then +-- if( (DECODE_CS = STORE_HEADER) or (DECODE_CS = STORE_FRAME) ) then +-- decode_ctr <= decode_ctr + 1; +-- else +-- decode_ctr <= (others => '0'); +-- end if; +-- end if; +-- end process PROC_DECODE_CTR; + + -- counter for decoding the byte stream + PROC_DECODE_CTR: process( CLK, RESET ) + begin + if ( RESET = '1' ) then + decode_ctr <= (others => '0'); elsif( rising_edge(CLK) ) then - if( (DECODE_CS = STORE_HEADER) or (DECODE_CS = STORE_FRAME) ) then - decode_ctr <= decode_ctr + 1; - else - decode_ctr <= (others => '0'); - end if; - end if; - end process PROC_DECODE_CTR; + if ( (DECODE_CS /= STORE_HEADER) and (DECODE_CS /= STORE_FRAME) ) then + decode_ctr <= (others => '0'); + elsif( ((DECODE_CS = STORE_HEADER) or (DECODE_CS = STORE_FRAME)) and (MAC_RX_EN_IN = '1') ) then + decode_ctr <= decode_ctr + 1; + end if; + end if; + end process PROC_DECODE_CTR; + + -- write only if data stream is available! + PROC_RX_FIFO_SYNC: process( CLK ) + begin + if( rising_edge(CLK) ) then + if( MAC_RX_EN_IN = '1' ) then + if ( DECODE_NS = STORE_FRAME ) then + fifo_pl_wr <= '1'; + elsif( (DECODE_CS = STORE_FRAME) and (DECODE_NS = LAST_BYTE) ) then + fifo_pl_wr <= '1'; + else + fifo_pl_wr <= '0'; + end if; + else + fifo_pl_wr <= '0'; + end if; + end if; + end process PROC_RX_FIFO_SYNC; -- storing the relevant parts of headers for decision and further usage PROC_STORE_INFO: process( CLK, RESET ) @@ -313,13 +347,14 @@ begin stored_src_port <= (others => '0'); stored_dst_port <= (others => '0'); elsif( rising_edge(CLK) ) then - if( (MAC_RX_EN_IN = '1') and (mac_rx_en_q = '0') ) then - -- early bird - stored_dst_mac(7 downto 0) <= MAC_RXD_IN; - end if; +-- if( (MAC_RX_EN_IN = '1') and (mac_rx_en_q = '0') ) then +-- -- early bird +-- stored_dst_mac(7 downto 0) <= MAC_RXD_IN; -- FUCKING BUG!!!! +-- end if; if( (mac_rx_en_q = '1') and (DECODE_CS = STORE_HEADER) ) then case decode_ctr is when x"00" => stored_dst_mac(15 downto 8) <= MAC_RXD_IN; + stored_dst_mac(7 downto 0) <= mac_rxd_q; when x"01" => stored_dst_mac(23 downto 16) <= MAC_RXD_IN; when x"02" => stored_dst_mac(31 downto 24) <= MAC_RXD_IN; when x"03" => stored_dst_mac(39 downto 32) <= MAC_RXD_IN; @@ -425,7 +460,7 @@ begin -- CAVEAT: writing to FIFO and reading needs some clock cycles? -- Three is fine, two fails - data arrives late. -- Happens when main control tries to read a frame directly when it was written. - + -- FIFO for header information THE_FIRST_FIFO: entity work.fifo_512x72 port map( diff --git a/gbe_trb/base/gbe_logic_wrapper.vhd b/gbe_trb/base/gbe_logic_wrapper.vhd index deab0cf..5fa5cc8 100644 --- a/gbe_trb/base/gbe_logic_wrapper.vhd +++ b/gbe_trb/base/gbe_logic_wrapper.vhd @@ -162,24 +162,25 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --- DEBUG_OUT(31 downto 0) <= (others => '0'); - DEBUG_OUT(31 downto 28) <= debug_fr(31 downto 28); -- frame receiver state - DEBUG_OUT(27 downto 24) <= debug_rc(3 downto 0); -- receive control state - DEBUG_OUT(23 downto 20) <= debug_main(23 downto 20); -- redirect state - DEBUG_OUT(19 downto 16) <= fr_ps_int(3 downto 0); --debug_main(27 downto 24); -- link state - DEBUG_OUT(15) <= rc_loading_done; - DEBUG_OUT(14) <= rc_frame_ready; - DEBUG_OUT(13) <= fr_ps_int(4); --rc_frame_proto(4); -- ICMP - DEBUG_OUT(12) <= fr_ps_int(1); --rc_frame_proto(1); -- DHCP - DEBUG_OUT(11) <= fr_ps_int(0); --rc_frame_proto(0); -- ARP - DEBUG_OUT(10) <= fr_get_frame; - DEBUG_OUT(9) <= fr_frame_valid; - DEBUG_OUT(8) <= fr_rd_en; - DEBUG_OUT(7 downto 0) <= rc_q(7 downto 0); +---- DEBUG_OUT(31 downto 0) <= (others => '0'); +-- DEBUG_OUT(31 downto 28) <= debug_fr(31 downto 28); -- frame receiver state +-- DEBUG_OUT(27 downto 24) <= debug_rc(3 downto 0); -- receive control state +-- DEBUG_OUT(23 downto 20) <= debug_main(23 downto 20); -- redirect state +-- DEBUG_OUT(19 downto 16) <= fr_ps_int(3 downto 0); --debug_main(27 downto 24); -- link state +-- DEBUG_OUT(15) <= rc_loading_done; +-- DEBUG_OUT(14) <= rc_frame_ready; +-- DEBUG_OUT(13) <= fr_ps_int(4); --rc_frame_proto(4); -- ICMP +-- DEBUG_OUT(12) <= fr_ps_int(1); --rc_frame_proto(1); -- DHCP +-- DEBUG_OUT(11) <= fr_ps_int(0); --rc_frame_proto(0); -- ARP +-- DEBUG_OUT(10) <= fr_get_frame; +-- DEBUG_OUT(9) <= fr_frame_valid; +-- DEBUG_OUT(8) <= fr_rd_en; +-- 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); + DEBUG_OUT(31 downto 0) <= debug_main(31 downto 0); --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- diff --git a/gbe_trb/base/gbe_main_control.vhd b/gbe_trb/base/gbe_main_control.vhd index 2d668f4..bc61143 100644 --- a/gbe_trb/base/gbe_main_control.vhd +++ b/gbe_trb/base/gbe_main_control.vhd @@ -149,12 +149,13 @@ begin ----------------------------------------------------------------------- -- Debug signals ----------------------------------------------------------------------- - DEBUG_OUT(63 downto 28) <= (others => '0'); - - DEBUG_OUT(27 downto 24) <= link_state; - DEBUG_OUT(23 downto 20) <= redirect_state; - DEBUG_OUT(19 downto 16) <= flow_state; - DEBUG_OUT(15 downto 0) <= selector_debug(15 downto 0); +-- DEBUG_OUT(63 downto 28) <= (others => '0'); +-- DEBUG_OUT(27 downto 24) <= link_state; +-- DEBUG_OUT(23 downto 20) <= redirect_state; +-- DEBUG_OUT(19 downto 16) <= flow_state; +-- DEBUG_OUT(15 downto 0) <= selector_debug(15 downto 0); + DEBUG_OUT(63 downto 32) <= (others => '0'); + DEBUG_OUT(31 downto 0) <= selector_debug(31 downto 0); ----------------------------------------------------------------------- -- Link state machine, high level. Handles DHCP basically diff --git a/gbe_trb/base/gbe_protocol_selector.vhd b/gbe_trb/base/gbe_protocol_selector.vhd index 27cb48a..86b6c6d 100644 --- a/gbe_trb/base/gbe_protocol_selector.vhd +++ b/gbe_trb/base/gbe_protocol_selector.vhd @@ -133,9 +133,11 @@ begin MY_IP_OUT <= my_ip; -- Debug lines - DEBUG_OUT(63 downto 16) <= (others => '0'); - DEBUG_OUT(15 downto 12) <= state; -- selector state - DEBUG_OUT(11 downto 0) <= debug_dhcp(11 downto 0); -- FSM states DHCP +-- DEBUG_OUT(63 downto 16) <= (others => '0'); +-- DEBUG_OUT(15 downto 12) <= state; -- selector state +-- DEBUG_OUT(11 downto 0) <= debug_dhcp(11 downto 0); -- FSM states DHCP + DEBUG_OUT(63 downto 32) <= (others => '0'); + DEBUG_OUT(31 downto 0) <= debug_dhcp(31 downto 0); ARP_GEN: if( INCLUDE_ARP = '1' ) generate -- protocol Nr. 1 ARP diff --git a/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd b/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd index f7c82c9..55ea20e 100644 --- a/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd +++ b/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd @@ -63,11 +63,7 @@ architecture gbe_response_constructor_DHCP_arch of gbe_response_constructor_DHCP 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_CS, STATS_NS : stats_states; --- attribute syn_encoding of STATS_CS : signal is "onehot"; - - signal state : std_logic_vector(3 downto 0); + signal cons_state : std_logic_vector(3 downto 0); signal rec_frames : std_logic_vector(15 downto 0); signal sent_frames : unsigned(15 downto 0); @@ -88,8 +84,8 @@ architecture gbe_response_constructor_DHCP_arch of gbe_response_constructor_DHCP signal your_ip_reg : std_logic_vector(31 downto 0); signal saved_server_mac : std_logic_vector(47 downto 0); signal saved_server_ip : std_logic_vector(31 downto 0); - signal state2 : std_logic_vector(3 downto 0); - signal state3 : std_logic_vector(3 downto 0); + signal main_state : std_logic_vector(3 downto 0); + signal recv_state : std_logic_vector(3 downto 0); signal vendor_values2 : std_logic_vector(47 downto 0); signal discarded_ctr : std_logic_vector(15 downto 0); @@ -98,13 +94,22 @@ architecture gbe_response_constructor_DHCP_arch of gbe_response_constructor_DHCP attribute syn_preserve : boolean; attribute syn_keep : boolean; - attribute syn_keep of state, state2 : signal is true; - attribute syn_preserve of state, state2 : signal is true; + attribute syn_keep of cons_state, main_state, recv_state : signal is true; + attribute syn_preserve of cons_state, main_state, recv_state : signal is true; signal wait_value : unsigned(31 downto 0); begin + DEBUG_OUT(31 downto 28) <= main_state; + DEBUG_OUT(27 downto 24) <= recv_state; + DEBUG_OUT(23 downto 20) <= cons_state; + DEBUG_OUT(19 downto 12) <= PS_DEST_MAC_ADDRESS_IN(7 downto 0); + DEBUG_OUT(11) <= '0'; + DEBUG_OUT(10) <= PS_WR_EN_IN; + DEBUG_OUT(9) <= PS_ACTIVATE_IN; + DEBUG_OUT(8 downto 0) <= PS_DATA_IN; + -- **** -- fixing the constant values for DHCP request headers TC_DEST_MAC_OUT <= x"ffffffffffff" when (MAIN_CS = BOOTING or MAIN_CS = SENDING_DISCOVER) else saved_server_mac; @@ -165,12 +170,12 @@ begin PROC_MAIN_TRANSITIONS : process( MAIN_CS, DHCP_START_IN, CONSTRUCT_CS, wait_ctr, RECEIVE_CS, PS_DATA_IN, wait_value ) begin - state2 <= x"0"; + main_state <= x"0"; case (MAIN_CS) is when BOOTING => - state2 <= x"1"; + main_state <= x"1"; if( DHCP_START_IN = '1' ) then MAIN_NS <= DELAY; else @@ -178,7 +183,7 @@ begin end if; when DELAY => - state2 <= x"2"; + main_state <= x"2"; if( wait_ctr = wait_value ) then MAIN_NS <= SENDING_DISCOVER; else @@ -186,7 +191,7 @@ begin end if; when SENDING_DISCOVER => - state2 <= x"3"; + main_state <= x"3"; if( CONSTRUCT_CS = CLEANUP ) then MAIN_NS <= WAITING_FOR_OFFER; else @@ -194,7 +199,7 @@ begin end if; when WAITING_FOR_OFFER => - state2 <= x"4"; + main_state <= x"4"; if( (RECEIVE_CS = SAVE_VALUES) and (PS_DATA_IN(8) = '1') ) then MAIN_NS <= SENDING_REQUEST; elsif( wait_ctr = x"2000_0000" ) then @@ -204,7 +209,7 @@ begin end if; when SENDING_REQUEST => - state2 <= x"5"; + main_state <= x"5"; if( CONSTRUCT_CS = CLEANUP ) then MAIN_NS <= WAITING_FOR_ACK; else @@ -212,7 +217,7 @@ begin end if; when WAITING_FOR_ACK => - state2 <= x"6"; + main_state <= x"6"; if( (RECEIVE_CS = SAVE_VALUES) and (PS_DATA_IN(8) = '1') ) then MAIN_NS <= ESTABLISHED; elsif( wait_ctr = x"2000_0000" ) then @@ -222,7 +227,7 @@ begin end if; when ESTABLISHED => - state2 <= x"7"; + main_state <= x"7"; if( DHCP_START_IN = '0' ) then MAIN_NS <= BOOTING; else @@ -265,12 +270,12 @@ begin 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"; + recv_state <= x"0"; case RECEIVE_CS is when IDLE => - state3 <= x"1"; + recv_state <= x"1"; 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) @@ -286,7 +291,7 @@ begin end if; when SAVE_VALUES => - state3 <= x"2"; + recv_state <= x"2"; if ( PS_DATA_IN(8) = '1' ) then RECEIVE_NS <= CLEANUP; -- check if the same transaction @@ -303,7 +308,7 @@ begin end if; when DISCARD => - state3 <= x"3"; + recv_state <= x"3"; if( PS_DATA_IN(8) = '1' ) then RECEIVE_NS <= CLEANUP; else @@ -311,7 +316,7 @@ begin end if; when CLEANUP => - state3 <= x"4"; + recv_state <= x"4"; RECEIVE_NS <= IDLE; when others => @@ -450,12 +455,12 @@ begin PROC_CONSTRUCT_TRANSITIONS: process( CONSTRUCT_CS, MAIN_CS, load_ctr, PS_SELECTED_IN ) begin - state <= x"0"; + cons_state <= x"0"; case CONSTRUCT_CS is when IDLE => - state <= x"1"; + cons_state <= x"1"; if( (MAIN_CS = SENDING_DISCOVER) or (MAIN_CS = SENDING_REQUEST) ) then CONSTRUCT_NS <= WAIT_FOR_LOAD; else @@ -463,7 +468,7 @@ begin end if; when WAIT_FOR_LOAD => - state <= x"2"; + cons_state <= x"2"; if( PS_SELECTED_IN = '1' ) then CONSTRUCT_NS <= BOOTP_HEADERS; else @@ -471,7 +476,7 @@ begin end if; when BOOTP_HEADERS => - state <= x"3"; + cons_state <= x"3"; if( load_ctr = 11 ) then CONSTRUCT_NS <= CLIENT_IP; else @@ -479,7 +484,7 @@ begin end if; when CLIENT_IP => - state <= x"4"; + cons_state <= x"4"; if( load_ctr = 15 ) then CONSTRUCT_NS <= YOUR_IP; else @@ -487,7 +492,7 @@ begin end if; when YOUR_IP => - state <= x"5"; + cons_state <= x"5"; if( load_ctr = 19 ) then CONSTRUCT_NS <= ZEROS1; else @@ -495,7 +500,7 @@ begin end if; when ZEROS1 => - state <= x"6"; + cons_state <= x"6"; if( load_ctr = 27 ) then CONSTRUCT_NS <= MY_MAC; else @@ -503,7 +508,7 @@ begin end if; when MY_MAC => - state <= x"7"; + cons_state <= x"7"; if( load_ctr = 33 ) then CONSTRUCT_NS <= ZEROS2; else @@ -511,7 +516,7 @@ begin end if; when ZEROS2 => - state <= x"8"; + cons_state <= x"8"; if( load_ctr = 235 ) then CONSTRUCT_NS <= VENDOR_VALS; else @@ -519,7 +524,7 @@ begin end if; when VENDOR_VALS => - state <= x"9"; + cons_state <= x"9"; if( load_ctr = 257 ) then -- for discover it's enough of values if( MAIN_CS = SENDING_DISCOVER ) then @@ -533,7 +538,7 @@ begin end if; when VENDOR_VALS2 => - state <= x"a"; + cons_state <= x"a"; if( load_ctr = 263 ) then CONSTRUCT_NS <= TERMINATION; else @@ -541,11 +546,11 @@ begin end if; when TERMINATION => - state <= x"b"; + cons_state <= x"b"; CONSTRUCT_NS <= CLEANUP; when CLEANUP => - state <= x"c"; + cons_state <= x"c"; CONSTRUCT_NS <= IDLE; when others => @@ -669,9 +674,9 @@ begin -- PROC_DEBUG: process( CLK ) -- begin -- if( rising_edge(CLK) ) then - DEBUG_OUT(3 downto 0) <= state; - DEBUG_OUT(7 downto 4) <= state2; - DEBUG_OUT(11 downto 8) <= state3; +-- DEBUG_OUT(3 downto 0) <= cons_state; +-- DEBUG_OUT(7 downto 4) <= main_state; +-- DEBUG_OUT(11 downto 8) <= recv_state; -- end if; -- end process PROC_DEBUG; diff --git a/gbe_trb/protocols/gbe_response_constructor_Forward.vhd b/gbe_trb/protocols/gbe_response_constructor_Forward.vhd index 62bb918..fbc41fc 100644 --- a/gbe_trb/protocols/gbe_response_constructor_Forward.vhd +++ b/gbe_trb/protocols/gbe_response_constructor_Forward.vhd @@ -57,7 +57,7 @@ entity gbe_response_constructor_Forward is FWD_READY_OUT : out std_logic; FWD_FULL_OUT : out std_logic; -- debug - DEBUG_OUT : out std_logic_vector(31 downto 0) + DEBUG_OUT : out std_logic_vector(63 downto 0) ); end gbe_response_constructor_Forward; @@ -242,7 +242,7 @@ architecture gbe_response_constructor_Forward_arch of gbe_response_constructor_F DEBUG_OUT(15 downto 8) <= ff_q(7 downto 0); DEBUG_OUT(16) <= ff_q(8); DEBUG_OUT(17) <= local_eop; - DEBUG_OUT(31 downto 18) <= (others => '0'); + DEBUG_OUT(63 downto 18) <= (others => '0'); -- **** end gbe_response_constructor_Forward_arch;