From 4e675f187ab4a63a8169d701e75b633fbfae08f4 Mon Sep 17 00:00:00 2001 From: Michael Boehmer Date: Sun, 13 Nov 2022 20:47:57 +0100 Subject: [PATCH] static IP included. Discovery protocol included in beta version. Some bug fixes. Ping bug still included. --- gbe_trb/base/gbe_frame_receiver.vhd | 40 ++++++++++++------- gbe_trb/base/gbe_logic_wrapper.vhd | 27 ++++++++++--- gbe_trb/base/gbe_main_control.vhd | 16 +++++--- gbe_trb/base/gbe_protocol_selector.vhd | 20 +++++++++- .../gbe_response_constructor_DHCP.vhd | 8 ++-- .../gbe_response_constructor_Discovery.vhd | 24 ++--------- .../gbe_response_constructor_Ping.vhd | 22 +++++----- 7 files changed, 96 insertions(+), 61 deletions(-) diff --git a/gbe_trb/base/gbe_frame_receiver.vhd b/gbe_trb/base/gbe_frame_receiver.vhd index 36fc3dd..7b8b48a 100644 --- a/gbe_trb/base/gbe_frame_receiver.vhd +++ b/gbe_trb/base/gbe_frame_receiver.vhd @@ -11,7 +11,7 @@ entity gbe_frame_receiver is port( CLK : in std_logic; -- system clock RESET : in std_logic; - LINK_OK_IN : in std_logic; + LINK_OK_IN : in std_logic; -- not used ALLOW_RX_IN : in std_logic; MY_MAC_IN : in std_logic_vector(47 downto 0); MY_IP_IN : in std_logic_vector(31 downto 0); @@ -40,6 +40,8 @@ entity gbe_frame_receiver is OOB_REGISTER_1_OUT : out std_logic_vector(31 downto 0); OOB_REGISTER_2_OUT : out std_logic_vector(31 downto 0); OOB_REGISTER_3_OUT : out std_logic_vector(31 downto 0); + DISABLE_DHCP_OUT : out std_logic; + STATIC_IP_OUT : out std_logic_vector(31 downto 0); -- MONITOR_RX_BYTES_OUT : out std_logic_vector(31 downto 0); MONITOR_RX_FRAMES_OUT : out std_logic_vector(31 downto 0); @@ -109,14 +111,16 @@ architecture gbe_frame_receiver_arch of gbe_frame_receiver is signal fr_q : std_logic_vector(8 downto 0); signal fr_info : std_logic_vector(7 downto 0); - signal oob_register_0_int : std_logic_vector(31 downto 0); - signal oob_register_1_int : std_logic_vector(31 downto 0); - signal oob_register_2_int : std_logic_vector(31 downto 0); - signal oob_register_3_int : std_logic_vector(31 downto 0); + signal oob_register_0_int : std_logic_vector(31 downto 0) := (others => '0'); + signal oob_register_1_int : std_logic_vector(31 downto 0) := (others => '0'); + signal oob_register_2_int : std_logic_vector(31 downto 0) := (others => '0'); + signal oob_register_3_int : std_logic_vector(31 downto 0) := (others => '0'); signal oob_write : std_logic; signal drop_frame_x : std_logic; signal drop_frame : std_logic; - + signal oob_ctrl_reg_int : std_logic_vector(31 downto 0); + signal oob_ip_reg_int : std_logic_vector(31 downto 0); + signal fifo_one_q : std_logic_vector(71 downto 0); signal fifo_two_q : std_logic_vector(71 downto 0); @@ -544,9 +548,9 @@ begin if( rising_edge(CLK) ) then if( (drop_frame = '1') and (stored_protocol = x"11") and - (stored_ethertype = x"0800") and - (stored_dst_port = x"d903") and - (stored_src_port = x"2b67") ) then + (stored_ethertype = x"0008") and -- swapped bytes + (stored_dst_port = x"adde") and -- swapped bytes + (stored_src_port = x"efbe") ) then -- swapped bytes oob_write <= '1'; else oob_write <= '0'; @@ -558,11 +562,14 @@ begin begin if( rising_edge(CLK) ) then if( oob_write = '1' ) then - case stored_src_ip(1 downto 0) is - when b"00" => oob_register_0_int <= stored_dst_ip; - when b"01" => oob_register_1_int <= stored_dst_ip; - when b"10" => oob_register_2_int <= stored_dst_ip; - when others => oob_register_3_int <= stored_dst_ip; + case stored_src_ip(2 downto 0) is + when b"000" => oob_register_0_int <= stored_dst_ip; + when b"001" => oob_register_1_int <= stored_dst_ip; + when b"010" => oob_register_2_int <= stored_dst_ip; + when b"011" => oob_register_3_int <= stored_dst_ip; + when b"110" => oob_ctrl_reg_int <= stored_dst_ip; + when b"111" => oob_ip_reg_int <= stored_dst_ip; + when others => null; end case; end if; end if; @@ -573,7 +580,10 @@ begin OOB_REGISTER_2_OUT <= oob_register_2_int; OOB_REGISTER_3_OUT <= oob_register_3_int; - -- killer ping + DISABLE_DHCP_OUT <= oob_ctrl_reg_int(0); + STATIC_IP_OUT <= oob_ip_reg_int; + +-- -- killer ping -- PROC_KILLER_PING: process( CLK ) -- begin -- if( rising_edge(CLK) ) then diff --git a/gbe_trb/base/gbe_logic_wrapper.vhd b/gbe_trb/base/gbe_logic_wrapper.vhd index c2c6aad..f2eae3a 100644 --- a/gbe_trb/base/gbe_logic_wrapper.vhd +++ b/gbe_trb/base/gbe_logic_wrapper.vhd @@ -143,7 +143,6 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is signal link_ok : std_logic; signal dhcp_done : std_logic; - signal my_ip : std_logic_vector(31 downto 0); signal make_reset : std_logic; signal frame_pause : std_logic_vector(31 downto 0); @@ -156,6 +155,15 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is signal debug_fr : std_logic_vector(31 downto 0); signal debug_rc : std_logic_vector(31 downto 0); + signal oob_register_0_int : std_logic_vector(31 downto 0); + signal oob_register_1_int : std_logic_vector(31 downto 0); + signal oob_register_2_int : std_logic_vector(31 downto 0); + signal oob_register_3_int : std_logic_vector(31 downto 0); + + signal my_static_ip : std_logic_vector(31 downto 0); + signal my_ip : std_logic_vector(31 downto 0); + signal disable_dhcp : std_logic; + begin --------------------------------------------------------------------------------------------------- @@ -201,6 +209,8 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is RESET => RESET, MC_LINK_OK_OUT => link_ok, MC_DHCP_DONE_OUT => dhcp_done, + MC_DISABLE_DHCP_IN => disable_dhcp, + MC_STATIC_IP_IN => my_static_ip, MY_IP_OUT => my_ip, MC_MY_MAC_IN => MY_MAC_IN, MY_TRBNET_ADDRESS_IN => MY_TRBNET_ADDRESS_IN, @@ -404,10 +414,12 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is FR_SRC_IP_ADDRESS_OUT => fr_src_ip, FR_SRC_UDP_PORT_OUT => fr_src_udp, -- - OOB_REGISTER_0_OUT => OOB_REGISTER_0_OUT, - OOB_REGISTER_1_OUT => OOB_REGISTER_1_OUT, - OOB_REGISTER_2_OUT => OOB_REGISTER_2_OUT, - OOB_REGISTER_3_OUT => OOB_REGISTER_3_OUT, + OOB_REGISTER_0_OUT => oob_register_0_int, + OOB_REGISTER_1_OUT => oob_register_1_int, + OOB_REGISTER_2_OUT => oob_register_2_int, + OOB_REGISTER_3_OUT => oob_register_3_int, + DISABLE_DHCP_OUT => disable_dhcp, + STATIC_IP_OUT => my_static_ip, -- MONITOR_RX_BYTES_OUT => MONITOR_RX_BYTES_OUT, MONITOR_RX_FRAMES_OUT => MONITOR_RX_FRAMES_OUT, @@ -416,4 +428,9 @@ architecture gbe_logic_wrapper_arch of gbe_logic_wrapper is DEBUG_OUT => debug_fr ); + OOB_REGISTER_0_OUT <= oob_register_0_int; + OOB_REGISTER_1_OUT <= oob_register_1_int; + OOB_REGISTER_2_OUT <= oob_register_2_int; + OOB_REGISTER_3_OUT <= oob_register_3_int; + 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 12043cb..2c4bd74 100644 --- a/gbe_trb/base/gbe_main_control.vhd +++ b/gbe_trb/base/gbe_main_control.vhd @@ -22,8 +22,10 @@ entity gbe_main_control is CLK_125 : in std_logic; RESET : in std_logic; -- - MC_LINK_OK_OUT : out std_logic; -- remark: set to '1' internally + MC_LINK_OK_OUT : out std_logic; MC_DHCP_DONE_OUT : out std_logic; + MC_DISABLE_DHCP_IN : in std_logic; + MC_STATIC_IP_IN : in std_logic_vector(31 downto 0); MY_IP_OUT : out std_logic_vector(31 downto 0); MC_MY_MAC_IN : in std_logic_vector(47 downto 0); MY_TRBNET_ADDRESS_IN : in std_logic_vector(15 downto 0); @@ -170,18 +172,18 @@ begin end if; end process PROC_LINK_STATE_FSM; - PROC_LINK_STATE_TRANSITIONS: process( LINK_STATE_CS, LINK_ACTIVE_IN, dhcp_done, incl_dhcp ) + PROC_LINK_STATE_TRANSITIONS: process( LINK_STATE_CS, LINK_ACTIVE_IN, MC_DISABLE_DHCP_IN, dhcp_done, incl_dhcp ) begin dhcp_start_x <= '0'; case LINK_STATE_CS is when LINK_DOWN => link_state <= x"0"; - if ( (LINK_ACTIVE_IN = '1') and (incl_dhcp = '1') ) then + if ( (LINK_ACTIVE_IN = '1') and (incl_dhcp = '1') and (MC_DISABLE_DHCP_IN = '0') ) then -- PHY and MAC are operational, DHCP is used LINK_STATE_NS <= LINK_ACTIVE; dhcp_start_x <= '1'; - elsif( (LINK_ACTIVE_IN = '0') and (incl_dhcp = '0') ) then + elsif( (LINK_ACTIVE_IN = '1') and ((incl_dhcp = '0') or (MC_DISABLE_DHCP_IN = '1')) ) then -- PHY and MAC are operational, DHCP is not used LINK_STATE_NS <= LINK_UP; else @@ -254,8 +256,8 @@ begin if ( LINK_STATE_CS = LINK_UP ) then -- DHPC done, or fixed IP, so we are fully accepting frames REDIRECT_NS <= CHECK_BUSY; - elsif( (LINK_STATE_CS = LINK_ACTIVE) and (RC_FRAME_PROTO_IN(1 downto 0) = "10") ) then - -- DHCP in progress, so only DHCP frames are accepted + elsif( (LINK_STATE_CS = LINK_ACTIVE) and ((RC_FRAME_PROTO_IN(1) = '1') or (RC_FRAME_PROTO_IN(6) = '1')) ) then + -- DHCP in progress, so only DHCP and Discovery frames are accepted REDIRECT_NS <= CHECK_BUSY; else -- link lost, drop frame @@ -436,6 +438,8 @@ begin MC_BUSY_IN => mc_busy, MY_MAC_IN => MC_MY_MAC_IN, MY_IP_OUT => MY_IP_OUT, + MY_STATIC_IP_IN => MC_STATIC_IP_IN, + DHCP_DISABLE_IN => MC_DISABLE_DHCP_IN, DHCP_START_IN => dhcp_start, DHCP_DONE_OUT => dhcp_done, GSC_CLK_IN => GSC_CLK_IN, diff --git a/gbe_trb/base/gbe_protocol_selector.vhd b/gbe_trb/base/gbe_protocol_selector.vhd index 1172bf2..7534b36 100644 --- a/gbe_trb/base/gbe_protocol_selector.vhd +++ b/gbe_trb/base/gbe_protocol_selector.vhd @@ -46,6 +46,8 @@ entity gbe_protocol_selector is -- misc signals for response constructors MY_MAC_IN : in std_logic_vector(47 downto 0); MY_IP_OUT : out std_logic_vector(31 downto 0); + MY_STATIC_IP_IN : in std_logic_vector(31 downto 0); + DHCP_DISABLE_IN : in std_logic; DHCP_START_IN : in std_logic; DHCP_DONE_OUT : out std_logic; GSC_CLK_IN : in std_logic; @@ -119,6 +121,7 @@ architecture gbe_protocol_selector_arch of gbe_protocol_selector is attribute syn_preserve of state, mult : signal is true; signal my_ip : std_logic_vector(31 downto 0); + signal my_dhcp_ip : std_logic_vector(31 downto 0); signal select_state : std_logic_vector(3 downto 0); signal debug_arp : std_logic_vector(63 downto 0); @@ -190,7 +193,6 @@ begin RESET => RESET, -- INTERFACE MY_MAC_IN => MY_MAC_IN, - MY_IP_IN => my_ip, PS_DATA_IN => PS_DATA_IN, PS_WR_EN_IN => PS_WR_EN_IN, PS_ACTIVATE_IN => PS_PROTO_SELECT_IN(1), @@ -214,16 +216,30 @@ begin TC_SRC_IP_OUT => tc_src_ip(2 * 32 - 1 downto 1 * 32), TC_SRC_UDP_OUT => tc_src_udp(2 * 16 - 1 downto 1 * 16), -- END OF INTERFACE - MY_IP_OUT => my_ip, + MY_IP_OUT => my_dhcp_ip, + DHCP_DISABLE_IN => DHCP_DISABLE_IN, DHCP_START_IN => DHCP_START_IN, DHCP_DONE_OUT => DHCP_DONE_OUT, 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 + case DHCP_DISABLE_IN is + when '0' => my_ip <= my_dhcp_ip; + when others => my_ip <= MY_STATIC_IP_IN; + end case; + end if; + end process PROC_SELECT_IP; + end generate DHCP_GEN; NO_DHCP_GEN: if( INCLUDE_DHCP = '0' ) generate resp_ready(1) <= '0'; busy(1) <= '0'; + my_ip <= MY_STATIC_IP_IN; end generate NO_DHCP_GEN; --------------------------------------------------------------------------------------- diff --git a/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd b/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd index bd8df5f..01606ac 100644 --- a/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd +++ b/gbe_trb/protocols/gbe_response_constructor_DHCP.vhd @@ -11,7 +11,6 @@ entity gbe_response_constructor_DHCP is RESET : in std_logic; -- INTERFACE MY_MAC_IN : in std_logic_vector(47 downto 0); - MY_IP_IN : in std_logic_vector(31 downto 0); PS_DATA_IN : in std_logic_vector(8 downto 0); PS_WR_EN_IN : in std_logic; PS_ACTIVATE_IN : in std_logic; @@ -37,6 +36,7 @@ entity gbe_response_constructor_DHCP is TC_SRC_UDP_OUT : out std_logic_vector(15 downto 0); -- END OF INTERFACE MY_IP_OUT : out std_logic_vector(31 downto 0); + DHCP_DISABLE_IN : in std_logic; DHCP_START_IN : in std_logic; DHCP_DONE_OUT : out std_logic; -- debug @@ -164,7 +164,7 @@ begin end if; end process PROC_MAIN_FSM; - PROC_MAIN_TRANSITIONS : process( MAIN_CS, DHCP_START_IN, CONSTRUCT_CS, wait_ctr, RECEIVE_CS, PS_DATA_IN ) + PROC_MAIN_TRANSITIONS : process( MAIN_CS, DHCP_START_IN, DHCP_DISABLE_IN, CONSTRUCT_CS, wait_ctr, RECEIVE_CS, PS_DATA_IN ) begin main_state <= x"0"; @@ -172,7 +172,7 @@ begin when BOOTING => main_state <= x"1"; - if( DHCP_START_IN = '1' ) then + if( (DHCP_START_IN = '1') and (DHCP_DISABLE_IN = '0') ) then MAIN_NS <= DELAY; else MAIN_NS <= BOOTING; @@ -226,7 +226,7 @@ begin when ESTABLISHED => main_state <= x"7"; - if( DHCP_START_IN = '0' ) then + if( (DHCP_START_IN = '0') or (DHCP_DISABLE_IN = '1') ) then MAIN_NS <= BOOTING; else MAIN_NS <= ESTABLISHED; diff --git a/gbe_trb/protocols/gbe_response_constructor_Discovery.vhd b/gbe_trb/protocols/gbe_response_constructor_Discovery.vhd index 89064ab..68872fa 100644 --- a/gbe_trb/protocols/gbe_response_constructor_Discovery.vhd +++ b/gbe_trb/protocols/gbe_response_constructor_Discovery.vhd @@ -51,21 +51,15 @@ architecture gbe_response_constructor_Discovery_arch of gbe_response_constructor signal stats_current_state, stats_next_state : stats_states; attribute syn_encoding of stats_current_state : signal is "onehot"; - signal saved_opcode : std_logic_vector(15 downto 0); -- NOT USED - signal saved_sender_ip : std_logic_vector(31 downto 0); - signal saved_target_ip : std_logic_vector(31 downto 0); - signal tc_data : std_logic_vector(8 downto 0); - signal dissect_ctr : unsigned(7 downto 0); signal state : std_logic_vector(3 downto 0); --- signal test_ff : std_logic; - attribute syn_preserve : boolean; attribute syn_keep : boolean; attribute syn_keep of state : signal is true; attribute syn_preserve of state : signal is true; + signal dissect_ctr : unsigned(7 downto 0); signal stored_magic : std_logic_vector(31 downto 0); signal stored_opcode : std_logic_vector(7 downto 0); signal stored_random : std_logic_vector(7 downto 0); @@ -75,6 +69,8 @@ architecture gbe_response_constructor_Discovery_arch of gbe_response_constructor signal ps_response_ready : std_logic; signal ps_busy : std_logic; + + signal tc_data : std_logic_vector(8 downto 0); signal tc_data_q : std_logic_vector(8 downto 0); begin @@ -91,18 +87,6 @@ begin DEBUG_OUT(17 downto 9) <= tc_data_q; DEBUG_OUT(8 downto 0) <= PS_DATA_IN; --- -- simple toggle FF for testing --- PROC_TEST_FF: process( CLK, RESET ) --- begin --- if ( RESET = '1' ) then --- test_ff <= '0'; --- elsif( rising_edge(CLK) ) then --- if( DISSECT_CS = DELAY ) then --- test_ff <= not test_ff; --- end if; --- end if; --- end process PROC_TEST_FF; - -- statemachine PROC_DISSECT_FSM: process( CLK, RESET ) begin @@ -114,7 +98,7 @@ begin end process PROC_DISSECT_FSM; PROC_DISSECT_TRANSITIONS : process( DISSECT_CS, MY_IP_IN, PS_WR_EN_IN, PS_ACTIVATE_IN, - PS_DATA_IN, dissect_ctr, PS_SELECTED_IN, saved_target_ip ) + PS_DATA_IN, dissect_ctr, PS_SELECTED_IN ) begin case DISSECT_CS is diff --git a/gbe_trb/protocols/gbe_response_constructor_Ping.vhd b/gbe_trb/protocols/gbe_response_constructor_Ping.vhd index 01c6318..2165d00 100644 --- a/gbe_trb/protocols/gbe_response_constructor_Ping.vhd +++ b/gbe_trb/protocols/gbe_response_constructor_Ping.vhd @@ -5,6 +5,8 @@ library ieee; library work; use work.gbe_protocols.all; +-- BUG: answers always with PING REPLY. No choice on TYPE/CODE is made! + entity gbe_response_constructor_Ping is port( CLK : in std_logic; -- system clock @@ -52,6 +54,8 @@ architecture gbe_response_constructor_Ping_arch of gbe_response_constructor_Ping signal stats_current_state, stats_next_state : stats_states; attribute syn_encoding of stats_current_state : signal is "onehot"; + signal state : std_logic_vector(3 downto 0); + signal sent_frames : unsigned(15 downto 0); signal saved_data : std_logic_vector(447 downto 0); @@ -86,28 +90,28 @@ begin case dissect_current_state is when IDLE => - 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; end if; when READ_FRAME => - if (PS_DATA_IN(8) = '1') then + if( PS_DATA_IN(8) = '1' ) then dissect_next_state <= WAIT_FOR_LOAD; else dissect_next_state <= READ_FRAME; end if; when WAIT_FOR_LOAD => - if (PS_SELECTED_IN = '1') then + if( PS_SELECTED_IN = '1' ) then dissect_next_state <= LOAD_FRAME; else dissect_next_state <= WAIT_FOR_LOAD; end if; when LOAD_FRAME => - if (data_ctr = data_length + 1) then + if( data_ctr = data_length + 1 ) then dissect_next_state <= CLEANUP; else dissect_next_state <= LOAD_FRAME; @@ -126,9 +130,9 @@ begin elsif( rising_edge(CLK) ) then if ( (dissect_current_state = IDLE) or (dissect_current_state = WAIT_FOR_LOAD) ) then data_ctr <= 2; - 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; @@ -187,7 +191,7 @@ begin checksum_rr(15 downto 0) <= (others => '0'); checksum_lll(15 downto 0) <= (others => '0'); checksum_rrr(15 downto 0) <= (others => '0'); - elsif( dissect_current_state = READ_FRAME and data_ctr > 4 ) then + elsif( (dissect_current_state = READ_FRAME) and (data_ctr > 4) ) then if (std_logic_vector(to_unsigned(data_ctr, 1)) = "0") then checksum_l <= checksum_l + unsigned(PS_DATA_IN(7 downto 0)); else @@ -234,7 +238,7 @@ begin end loop; -- mark the last byte - if (data_ctr = data_length + 1) then + if( data_ctr = data_length + 1 ) then tc_data(8) <= '1'; end if; end if; @@ -250,7 +254,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'; -- 2.43.0