From 5982d92b2926b81112d1dfe6ba89718d20433b5d Mon Sep 17 00:00:00 2001 From: hadeshyp Date: Wed, 18 Jul 2012 13:40:45 +0000 Subject: [PATCH] *** empty log message *** --- gbe2_ecp3/trb_net16_gbe_main_control.vhd | 4 +- gbe2_ecp3/trb_net16_gbe_protocol_selector.vhd | 28 ++++ ...rb_net16_gbe_response_constructor_DHCP.vhd | 2 +- ...b_net16_gbe_response_constructor_SCTRL.vhd | 138 +++++++++--------- gbe2_ecp3/trb_net16_gbe_transmit_control.vhd | 4 +- gbe2_ecp3/trb_net_gbe_protocols.vhd | 2 + 6 files changed, 103 insertions(+), 75 deletions(-) diff --git a/gbe2_ecp3/trb_net16_gbe_main_control.vhd b/gbe2_ecp3/trb_net16_gbe_main_control.vhd index 482ba9d..3f078c5 100644 --- a/gbe2_ecp3/trb_net16_gbe_main_control.vhd +++ b/gbe2_ecp3/trb_net16_gbe_main_control.vhd @@ -621,9 +621,11 @@ MC_LINK_OK_OUT <= link_ok; --************* -- GENERATE MAC_ADDRESS -g_MY_MAC <= unique_id(63 downto 48) & x"efbe0000"; +g_MY_MAC <= unique_id(31 downto 8) & x"be0002"; g_MAX_FRAME_SIZE <= x"0578"; + +--g_MAX_PACKET_SIZE <= x"fa00" when g_SIMULATE = 0 else x"0600"; -- --************* diff --git a/gbe2_ecp3/trb_net16_gbe_protocol_selector.vhd b/gbe2_ecp3/trb_net16_gbe_protocol_selector.vhd index 4ce6d0c..91534a7 100644 --- a/gbe2_ecp3/trb_net16_gbe_protocol_selector.vhd +++ b/gbe2_ecp3/trb_net16_gbe_protocol_selector.vhd @@ -119,6 +119,22 @@ signal tc_ip_size : std_logic_vector((c_MAX_PROTOCOLS + 1) * 16 - signal tc_udp_size : std_logic_vector((c_MAX_PROTOCOLS + 1) * 16 - 1 downto 0); signal tc_flags_size : std_logic_vector((c_MAX_PROTOCOLS + 1) * 16 - 1 downto 0); +-- temporary +signal gsc_init_dataready : std_logic; +signal gsc_init_data : std_logic_vector(15 downto 0); +signal gsc_init_packet_num : std_logic_vector(2 downto 0); +signal gsc_init_read : std_logic; +signal gsc_reply_dataready : std_logic; +signal gsc_reply_data : std_logic_vector(15 downto 0); +signal gsc_reply_packet_num : std_logic_vector(2 downto 0); +signal gsc_reply_read : std_logic; +signal gsc_busy : std_logic; + +attribute syn_preserve : boolean; +attribute syn_keep : boolean; +attribute syn_keep of gsc_busy, gsc_reply_read, gsc_reply_packet_num, gsc_reply_data, gsc_init_read, gsc_reply_dataready, gsc_init_packet_num, gsc_init_data, gsc_init_dataready : signal is true; +attribute syn_preserve of gsc_busy, gsc_reply_read, gsc_reply_packet_num, gsc_reply_data, gsc_init_read, gsc_reply_dataready, gsc_init_packet_num, gsc_init_data, gsc_init_dataready : signal is true; + begin -- protocol Nr. 1 ARP @@ -347,6 +363,18 @@ port map ( DEBUG_OUT => PROTOS_DEBUG_OUT(4 * 32 - 1 downto 3 * 32) ); + +--GSC_INIT_DATAREADY_OUT <= gsc_init_dataready; +--GSC_INIT_DATA_OUT <= gsc_init_data; +--GSC_INIT_PACKET_NUM_OUT <= gsc_init_packet_num; +--gsc_init_read <= GSC_INIT_READ_IN; +--gsc_reply_dataready <= GSC_REPLY_DATAREADY_IN; +--gsc_reply_data <= GSC_REPLY_DATA_IN; +--gsc_reply_packet_num <= GSC_REPLY_PACKET_NUM_IN; +--GSC_REPLY_READ_OUT <= gsc_reply_read; +--gsc_busy <= GSC_BUSY_IN; + + --stat_gen : if g_SIMULATE = 0 generate Stat : trb_net16_gbe_response_constructor_Stat generic map( STAT_ADDRESS_BASE => 10 diff --git a/gbe2_ecp3/trb_net16_gbe_response_constructor_DHCP.vhd b/gbe2_ecp3/trb_net16_gbe_response_constructor_DHCP.vhd index f596659..d22f3b5 100644 --- a/gbe2_ecp3/trb_net16_gbe_response_constructor_DHCP.vhd +++ b/gbe2_ecp3/trb_net16_gbe_response_constructor_DHCP.vhd @@ -280,7 +280,7 @@ begin 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 = g_MY_MAC) or (PS_DEST_MAC_ADDRESS_IN = x"ffffffffffff") then -- check if i'm the addressee (discards broadcasts also) + if (PS_DEST_MAC_ADDRESS_IN = g_MY_MAC) then --or (PS_DEST_MAC_ADDRESS_IN = x"ffffffffffff") then -- check if i'm the addressee (discards broadcasts also) receive_next_state <= SAVE_VALUES; else receive_next_state <= DISCARD; -- discard if the frame is not for me diff --git a/gbe2_ecp3/trb_net16_gbe_response_constructor_SCTRL.vhd b/gbe2_ecp3/trb_net16_gbe_response_constructor_SCTRL.vhd index 8d37790..3d8c2c9 100644 --- a/gbe2_ecp3/trb_net16_gbe_response_constructor_SCTRL.vhd +++ b/gbe2_ecp3/trb_net16_gbe_response_constructor_SCTRL.vhd @@ -104,6 +104,7 @@ signal tx_eod, rx_eod : std_logic; signal tx_fifo_q : std_logic_vector(8 downto 0); signal tx_fifo_wr, tx_fifo_rd : std_logic; +signal tx_fifo_reset : std_logic; signal gsc_reply_read : std_logic; signal gsc_init_dataready : std_logic; @@ -112,7 +113,7 @@ signal tx_loaded_ctr : std_logic_vector(15 downto 0); signal tx_frame_loaded : std_logic_vector(15 downto 0); signal packet_num : std_logic_vector(2 downto 0); - + signal init_ctr, reply_ctr : std_logic_vector(15 downto 0); signal rx_empty, tx_empty : std_logic; @@ -126,10 +127,19 @@ signal make_reset : std_logic := '0'; attribute syn_preserve : boolean; attribute syn_keep : boolean; -attribute syn_keep of tx_data_ctr, tx_loaded_ctr : signal is true; -attribute syn_preserve of tx_data_ctr, tx_loaded_ctr : signal is true; +attribute syn_keep of tx_data_ctr, tx_loaded_ctr, state : signal is true; +attribute syn_preserve of tx_data_ctr, tx_loaded_ctr, state : signal is true; signal temp_ctr : std_logic_vector(7 downto 0); + +signal gsc_init_read_q : std_logic; +signal fifo_rd_q : std_logic; + +signal too_much_data : std_logic; + +signal divide_ctr : std_logic_vector(7 downto 0); + +signal temp_src_port : std_logic_vector(15 downto 0); begin @@ -150,22 +160,37 @@ receive_fifo : fifo_2048x8x16 ); rx_fifo_wr <= '1' when PS_WR_EN_IN = '1' and PS_ACTIVATE_IN = '1' else '0'; + rx_fifo_rd <= '1' when (gsc_init_dataready = '1' and dissect_current_state = LOAD_TO_HUB) or (gsc_init_dataready = '1' and dissect_current_state = WAIT_FOR_HUB and GSC_INIT_READ_IN = '1') or (dissect_current_state = READ_FRAME and PS_DATA_IN(8) = '1') else '0'; -- preload first word GSC_INIT_DATA_OUT(7 downto 0) <= rx_fifo_q(16 downto 9); -GSC_INIT_DATA_OUT(15 downto 8) <= rx_fifo_q(7 downto 0); +GSC_INIT_DATA_OUT(15 downto 8) <= rx_fifo_q(7 downto 0); + GSC_INIT_PACKET_NUM_OUT <= packet_num; -gsc_init_dataready <= '1' when (GSC_INIT_READ_IN = '1' and dissect_current_state = LOAD_TO_HUB) or - (dissect_current_state = WAIT_FOR_HUB) else '0'; GSC_INIT_DATAREADY_OUT <= gsc_init_dataready; +gsc_init_dataready <= '1' when (GSC_INIT_READ_IN = '1' and dissect_current_state = LOAD_TO_HUB) or + (dissect_current_state = WAIT_FOR_HUB) else '0'; + +PACKET_NUM_PROC : process(CLK) +begin + if rising_edge(CLK) then + if (RESET = '1') or (dissect_current_state = IDLE) then + packet_num <= "100"; + elsif (GSC_INIT_READ_IN = '1' and gsc_init_dataready = '1' and packet_num = "100") then + packet_num <= "000"; + elsif (rx_fifo_rd = '1' and packet_num /= "100") then + packet_num <= packet_num + "1"; + end if; + end if; +end process PACKET_NUM_PROC; transmit_fifo : fifo_65536x18x9 PORT map( - Reset => RESET, - RPReset => RESET, + Reset => tx_fifo_reset, + RPReset => tx_fifo_reset, WrClock => CLK, RdClock => CLK, Data(7 downto 0) => GSC_REPLY_DATA_IN(15 downto 8), @@ -179,28 +204,16 @@ transmit_fifo : fifo_65536x18x9 Empty => tx_empty ); +tx_fifo_reset <= '1' when (RESET = '1') or (too_much_data = '1' and dissect_current_state = CLEANUP) else '0'; tx_fifo_wr <= '1' when GSC_REPLY_DATAREADY_IN = '1' and gsc_reply_read = '1' else '0'; tx_fifo_rd <= '1' when TC_RD_EN_IN = '1' and dissect_current_state = LOAD_FRAME and (tx_frame_loaded /= g_MAX_FRAME_SIZE) else '0'; ---temp_ctr_proc : process(CLK) ---begin --- if rising_edge(CLK) then --- if RESET = '1' then --- temp_ctr <= (others => '0'); --- elsif tx_fifo_rd = '1' then --- temp_ctr <= temp_ctr + x"1"; --- end if; --- end if; ---end process temp_ctr_proc; - TC_DATA_PROC : process(dissect_current_state, tx_loaded_ctr, tx_data_ctr, tx_frame_loaded, g_MAX_FRAME_SIZE) begin if (dissect_current_state = LOAD_FRAME) then TC_DATA_OUT(7 downto 0) <= tx_fifo_q(7 downto 0); - --TC_DATA_OUT(7 downto 0) <= temp_ctr; - --if (tx_loaded_ctr = tx_data_ctr + x"1" or tx_frame_loaded = g_MAX_FRAME_SIZE + x"1") then if (tx_loaded_ctr = tx_data_ctr or tx_frame_loaded = g_MAX_FRAME_SIZE - x"1") then TC_DATA_OUT(8) <= '1'; else @@ -220,8 +233,7 @@ begin TC_DATA_OUT <= (others => '0'); end if; end process TC_DATA_PROC; ---TC_DATA_OUT(7 downto 0) <= tx_fifo_q(7 downto 0) when dissect_current_state = LOAD_FRAME else (others => '0'); ---TC_DATA_OUT(8) <= '1' when ((tx_loaded_ctr = tx_data_ctr or tx_frame_loaded = g_MAX_FRAME_SIZE - x"1") and dissect_current_state = LOAD_FRAME) else '0'; + GSC_REPLY_READ_OUT <= gsc_reply_read; gsc_reply_read <= '1' when dissect_current_state = WAIT_FOR_RESPONSE or dissect_current_state = SAVE_RESPONSE else '0'; @@ -237,6 +249,26 @@ begin end if; end process TX_DATA_CTR_PROC; +TOO_MUCH_DATA_PROC : process(CLK) +begin + if rising_edge(CLK) then + if (RESET = '1') or (dissect_current_state = IDLE) then + too_much_data <= '0'; + elsif (dissect_current_state = SAVE_RESPONSE) and (tx_data_ctr = x"fa00") then + too_much_data <= '1'; + end if; + end if; +end process TOO_MUCH_DATA_PROC; + +DIVIDE_CTR_PROC : process(CLK) +begin + if (RESET = '1') or (dissect_current_state = IDLE) then + divide_ctr <= (others => '0'); + elsif (dissect_current_state = SAVE_RESPONSE) and (tx_data_ctr(10 downto 0) = b"101_0111_1000") then + divide_ctr <= divide_ctr + x"1"; + end if; +end process DIVIDE_CTR_PROC; + -- total counter of data transported to frame constructor TX_LOADED_CTR_PROC : process(CLK) begin @@ -257,16 +289,14 @@ PS_RESPONSE_READY_OUT <= '1' when (dissect_current_state = WAIT_FOR_LOAD or diss dissect_current_state = CLEANUP or dissect_current_state = WAIT_FOR_LOAD_ACK or dissect_current_state = LOAD_ACK or dissect_current_state = DIVIDE) else '0'; ---PS_RESPONSE_READY_OUT <= '1' when (dissect_current_state = WAIT_FOR_LOAD or dissect_current_state = LOAD_FRAME or --- dissect_current_state = CLEANUP or dissect_current_state = DIVIDE) --- else '0'; ---TC_FRAME_SIZE_OUT <= tx_data_ctr; +temp_src_port <= PS_SRC_UDP_PORT_IN + x"1"; TC_FRAME_TYPE_OUT <= x"0008"; TC_DEST_MAC_OUT <= PS_SRC_MAC_ADDRESS_IN; TC_DEST_IP_OUT <= PS_SRC_IP_ADDRESS_IN; -TC_DEST_UDP_OUT <= x"a861"; +TC_DEST_UDP_OUT(7 downto 0) <= temp_src_port(15 downto 8); --x"a861"; +TC_DEST_UDP_OUT(15 downto 8) <= temp_src_port(7 downto 0); --x"a861"; TC_SRC_MAC_OUT <= g_MY_MAC; TC_SRC_IP_OUT <= g_MY_IP; TC_SRC_UDP_OUT <= x"a861"; @@ -292,24 +322,8 @@ begin end if; end if; end process FRAME_SIZE_PROC; ---TC_FRAME_SIZE_OUT <= tx_data_ctr when (dissect_current_state = WAIT_FOR_LOAD or dissect_current_state = LOAD_FRAME) else x"0010"; - ---IP_SIZE_PROC : process(CLK) ---begin --- if rising_edge(CLK) then --- if (RESET= '1' or dissect_current_state = IDLE) then --- TC_IP_SIZE_OUT <= (others => '0'); --- elsif ((dissect_current_state = DIVIDE and TC_RD_EN_IN = '1' and PS_SELECTED_IN = '1') or (dissect_current_state = WAIT_FOR_LOAD or dissect_current_state = WAIT_FOR_TC)) then --- if (size_left >= g_MAX_FRAME_SIZE) then --- TC_IP_SIZE_OUT <= g_MAX_FRAME_SIZE; --- else --- TC_IP_SIZE_OUT <= size_left(15 downto 0); --- end if; --- end if; --- end if; ---end process IP_SIZE_PROC; -TC_UDP_SIZE_OUT <= tx_data_ctr; +TC_UDP_SIZE_OUT <= tx_data_ctr - divide_ctr(7 downto 1); TC_FLAGS_OFFSET_OUT(15 downto 14) <= "00"; @@ -339,21 +353,6 @@ begin end if; end process OFFSET_PROC; - -PACKET_NUM_PROC : process(CLK) -begin - if rising_edge(CLK) then - if (RESET = '1') or (dissect_current_state = IDLE) then - packet_num <= "100"; - elsif (GSC_INIT_READ_IN = '1' and gsc_init_dataready = '1' and packet_num = "100") then - packet_num <= "000"; - elsif (rx_fifo_rd = '1' and packet_num /= "100") then - packet_num <= packet_num + "1"; - end if; - end if; -end process PACKET_NUM_PROC; - - DISSECT_MACHINE_PROC : process(CLK) begin if rising_edge(CLK) then @@ -369,7 +368,7 @@ begin end if; end process DISSECT_MACHINE_PROC; -DISSECT_MACHINE : process(dissect_current_state, reset_detected, PS_WR_EN_IN, PS_ACTIVATE_IN, PS_DATA_IN, TC_BUSY_IN, data_ctr, PS_SELECTED_IN, GSC_INIT_READ_IN, GSC_REPLY_DATAREADY_IN, tx_loaded_ctr, tx_data_ctr, rx_fifo_q, GSC_BUSY_IN, tx_frame_loaded, g_MAX_FRAME_SIZE) +DISSECT_MACHINE : process(dissect_current_state, reset_detected, too_much_data, PS_WR_EN_IN, PS_ACTIVATE_IN, PS_DATA_IN, TC_BUSY_IN, data_ctr, PS_SELECTED_IN, GSC_INIT_READ_IN, GSC_REPLY_DATAREADY_IN, tx_loaded_ctr, tx_data_ctr, rx_fifo_q, GSC_BUSY_IN, tx_frame_loaded, g_MAX_FRAME_SIZE) begin case dissect_current_state is @@ -440,7 +439,11 @@ begin when SAVE_RESPONSE => state <= x"6"; if (GSC_REPLY_DATAREADY_IN = '0' and GSC_BUSY_IN = '0') then - dissect_next_state <= WAIT_FOR_LOAD; + if (too_much_data = '0') then + dissect_next_state <= WAIT_FOR_LOAD; + else + dissect_next_state <= CLEANUP; + end if; else dissect_next_state <= SAVE_RESPONSE; end if; @@ -458,18 +461,10 @@ begin if (tx_loaded_ctr = tx_data_ctr) then dissect_next_state <= CLEANUP; elsif (tx_frame_loaded = g_MAX_FRAME_SIZE) then - dissect_next_state <= DIVIDE; --WAIT_FOR_TC; --DIVIDE; + dissect_next_state <= DIVIDE; else dissect_next_state <= LOAD_FRAME; end if; - --- when WAIT_FOR_TC => --- state <= x"d"; --- if (TC_BUSY_IN = '0') then --- dissect_next_state <= DIVIDE; --- else --- dissect_next_state <= WAIT_FOR_TC; --- end if; when DIVIDE => state <= x"c"; @@ -490,6 +485,7 @@ begin end case; end process DISSECT_MACHINE; + -- counter of bytes of currently constructed frame FRAME_LOADED_PROC : process(CLK) begin diff --git a/gbe2_ecp3/trb_net16_gbe_transmit_control.vhd b/gbe2_ecp3/trb_net16_gbe_transmit_control.vhd index b30d5a4..4f1a982 100644 --- a/gbe2_ecp3/trb_net16_gbe_transmit_control.vhd +++ b/gbe2_ecp3/trb_net16_gbe_transmit_control.vhd @@ -239,7 +239,7 @@ begin if (MC_FRAME_TYPE_IN = x"0008") then -- in case of ip FC_IP_SIZE_OUT <= MC_IP_SIZE_IN; if (MC_UDP_SIZE_IN > g_MAX_FRAME_SIZE) then - FC_UDP_SIZE_OUT <= MC_UDP_SIZE_IN - x"1"; + FC_UDP_SIZE_OUT <= MC_UDP_SIZE_IN; -- - x"1"; else FC_UDP_SIZE_OUT <= MC_UDP_SIZE_IN; end if; @@ -250,7 +250,7 @@ begin -- FC_IP_SIZE_OUT <= temp_frame_size; --MC_FRAME_SIZE_IN; -- FC_UDP_SIZE_OUT <= temp_frame_size; --MC_FRAME_SIZE_IN; - FC_FLAGS_OFFSET_OUT <= MC_FLAGS_OFFSET_IN; --(others => '0'); -- fixed to one-frame packets + FC_FLAGS_OFFSET_OUT <= MC_FLAGS_OFFSET_IN; if (ctrl_construct_current_state = WAIT_FOR_FC) and (FC_H_READY_IN = '1') then MC_RD_EN_OUT <= '1'; diff --git a/gbe2_ecp3/trb_net_gbe_protocols.vhd b/gbe2_ecp3/trb_net_gbe_protocols.vhd index cec0553..c389a7f 100644 --- a/gbe2_ecp3/trb_net_gbe_protocols.vhd +++ b/gbe2_ecp3/trb_net_gbe_protocols.vhd @@ -17,6 +17,8 @@ signal g_MY_MAC : std_logic_vector(47 downto 0); -- size of ethernet frame use for fragmentation of outgoing packets signal g_MAX_FRAME_SIZE : std_logic_vector(15 downto 0); -- set up in main controller +--signal g_MAX_PACKET_SIZE : std_logic_vector(15 downto 0); + constant c_MAX_FRAME_TYPES : integer range 1 to 16 := 2; constant c_MAX_PROTOCOLS : integer range 1 to 16 := 5; constant c_MAX_IP_PROTOCOLS : integer range 1 to 16 := 2; -- 2.43.0