diff --git a/generic_ip/third_party_ip/mac/src/MII_MI.vhd b/generic_ip/third_party_ip/mac/src/MII_MI.vhd
new file mode 100644
index 0000000..886ed70
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/MII_MI.vhd
@@ -0,0 +1,233 @@
+-------------------------------------------------------------
+-- MSS copyright 2003-2018
+-- Filename: MII_MI.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 12/2/17
+-- Inheritance: MII_MI.VHD rev3 2/1/14 (COM-5401)
+-- MII_MI.vhd rev1 11-8-03 (COM-5003/5004)
+--
+-- description: MII management interface.
+-- Three transactions are supported: set register address, write and read register
+-- to/from the PHY IC through the MDC & MDIO serial interface.
+-- The MCLK clock speed is set as a constant within (integer division of the reference clock CLK).
+-- USAGE: adjust the constant MCLK_COUNTER_DIV within to meet the MDC/MDIO timing requirements (see PHY specs).
+-- Note: uses a ST="00" start of frame, unlike previous versions using a "01"
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee. numeric_std.all;
+
+entity MII_MI is
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ CLK: in std_logic;
+
+ PHY_ADDR: std_logic_vector(4 downto 0);
+ -- destination device address
+ MI_REGAD: in std_logic_vector(4 downto 0);
+ -- 32 register address space for the PHY (ieee 802.3)
+ -- 0 - 15 are standard PHY registers as per IEEE specification.
+ -- 16 - 31 are vendor-specific registers
+ MI_TX_DATA: in std_logic_vector(15 downto 0);
+ -- address/data
+ MI_RX_DATA: out std_logic_vector(15 downto 0);
+ MI_ADDR_START: in std_logic;
+ -- 1 CLK wide pulse to start a set address transaction
+ -- The 16-bit address is in MI_TX_DATA
+ -- will be ignored if the previous transaction is yet to be completed.
+ -- For reliable operation, the user must check MI_TRANSACTION_COMPLETE first.
+ MI_READ_START: in std_logic;
+ -- 1 CLK wide pulse to start read transaction
+ -- will be ignored if the previous transaction is yet to be completed.
+ -- For reliable operation, the user must check MI_TRANSACTION_COMPLETE first.
+ MI_WRITE_START: in std_logic;
+ -- 1 CLK wide pulse to start write transaction
+ -- will be ignored if the previous transaction is yet to be completed.
+ -- For reliable operation, the user must check MI_TRANSACTION_COMPLETE first.
+
+ MI_TRANSACTION_COMPLETE: out std_logic;
+ -- '1' when transaction is complete
+
+ --// serial interface to/from MDIO managed devices:
+ -- Connect to external PHY and XAUI adapter (shared MDIO bus)
+ MDC: out std_logic;
+ MDIO_OUT: out std_logic;
+ MDIO_IN: in std_logic;
+ MDIO_DIR: out std_logic
+ -- '0' when output, '1' when input
+ -- MDIO serial interface to control and monitor two MMDs: external 10G PHY and
+ -- internal XAUI adapter.
+
+ );
+end entity;
+
+architecture Behavioral of MII_MI is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal TRANSACTION: std_logic_vector(1 downto 0) := "00";
+signal STATE: unsigned(7 downto 0) := (others => '0'); -- 0 is idle
+signal TXRX_FRAME: std_logic_vector(63 downto 0); --32-bit idle sequence + 32-bit MI serial port frame + 2 end bit
+signal MCLK_LOCAL: std_logic := '0';
+signal MDOE: std_logic := '1';
+signal MDI_SAMPLE_CLK: std_logic := '0';
+constant MCLK_COUNTER_DIV: unsigned(7 downto 0) := x"4D"; -- 1 MHz (156.25 MHz/156)
+--constant MCLK_COUNTER_DIV: std_logic_vector(7 downto 0) := x"17";
+ -- divide CLK by this 2*(value + 1) to generate a slower MCLK
+ -- MCLK period (typ): 600 ns [Microsemi VSC8486-11]
+ -- Example: 156.25 MHz clock, 1us MCLK period => MCLK_COUNTER_DIV = 77
+signal MCLK_COUNTER: unsigned(7 downto 0) := x"00";
+signal MI_SAMPLE_REQ: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+------------------------------------------------------
+-- MCLK GENERATION
+------------------------------------------------------
+-- Divide CLK by MCLK_COUNTER_DIV
+MCLK_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MCLK_COUNTER <= (others => '0');
+ MI_SAMPLE_REQ <= '0';
+ elsif(STATE = 0) then
+ -- idle. awaiting a start of transaction.
+ MI_SAMPLE_REQ <= '0';
+ if(MI_WRITE_START = '1') or (MI_READ_START = '1') or (MI_ADDR_START = '1') then
+ -- get started. reset MCLK phase.
+ MCLK_COUNTER <= (others => '0');
+ end if;
+ else
+ -- read/write transaction in progress
+ if(MCLK_COUNTER = MCLK_COUNTER_DIV) then
+ -- next sample
+ MI_SAMPLE_REQ <= '1';
+ MCLK_COUNTER <= (others => '0');
+ else
+ MI_SAMPLE_REQ <= '0';
+ MCLK_COUNTER <= MCLK_COUNTER + 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+------------------------------------------------------
+-- OUTPUT TO PHY
+------------------------------------------------------
+
+STATE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ STATE <= (others => '0');
+ MCLK_LOCAL <= '0';
+ MDOE <= '0';
+ TRANSACTION <= "00";
+ elsif(STATE = 0) then
+ if(MI_ADDR_START = '1') then
+ -- was idle. start of set address transaction. start counting
+ TRANSACTION <= "00";
+ STATE <= x"01";
+ MCLK_LOCAL <= '0';
+ MDOE <= '1';
+ elsif (MI_WRITE_START = '1') then
+ -- was idle. start of write transaction. start counting
+ TRANSACTION <= "01";
+ STATE <= x"01";
+ MCLK_LOCAL <= '0';
+ MDOE <= '1';
+ elsif (MI_READ_START = '1') then
+ -- was idle. start of read transaction. start counting
+ TRANSACTION <= "11";
+ STATE <= x"01";
+ MCLK_LOCAL <= '0';
+ MDOE <= '1';
+ end if;
+ elsif (MI_SAMPLE_REQ = '1') then
+ if (STATE = 128) then
+ -- address/write transaction complete. set output enable to high impedance
+ TRANSACTION <= "00";
+ STATE <= x"00";
+ MCLK_LOCAL <= '0';
+ MDOE <= '0';
+ if(TRANSACTION(1) = '1') then
+ -- read transaction near complete
+ MI_RX_DATA <= TXRX_FRAME(15 downto 0); -- complete word read from PHY
+ end if;
+ elsif (TRANSACTION(1) = '1') and (STATE = 92) then
+ -- read transaction: finished writing addresses. switch to read mode
+ STATE <= STATE + 1;
+ MCLK_LOCAL <= not MCLK_LOCAL;
+ MDOE <= '0';
+ else
+ STATE <= STATE + 1;
+ MCLK_LOCAL <= not MCLK_LOCAL;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- immediate turn off the 'available' message as soon as a new transaction is triggered.
+MI_TRANSACTION_COMPLETE <= '0' when (STATE > 0) else
+ '0' when (MI_ADDR_START = '1') else
+ '0' when (MI_WRITE_START = '1') else
+ '0' when (MI_READ_START = '1') else
+ '1';
+
+-- send MCLK to output
+MDC <= MCLK_LOCAL;
+
+TXRX_FRAME_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TXRX_FRAME <= (others => '0');
+ elsif(MI_ADDR_START = '1') then
+ -- start of set address transaction.
+ -- Note: transmission sequence starts at bit 63
+ TXRX_FRAME(63 downto 32) <= x"FFFFFFFF"; -- preamble: idle sequence 32 '1's
+ TXRX_FRAME(31 downto 23) <= "0000" & PHY_ADDR;
+ TXRX_FRAME(22 downto 18) <= MI_REGAD;
+ TXRX_FRAME(17 downto 16) <= "10";
+ TXRX_FRAME(15 downto 0) <= MI_TX_DATA;
+ elsif(MI_WRITE_START = '1') then
+ -- start of write transaction.
+ -- Note: transmission sequence starts at bit 63
+ TXRX_FRAME(63 downto 32) <= x"FFFFFFFF"; -- preamble: idle sequence 32 '1's
+ TXRX_FRAME(31 downto 23) <= "0001" & PHY_ADDR;
+ TXRX_FRAME(22 downto 18) <= MI_REGAD;
+ TXRX_FRAME(17 downto 16) <= "10";
+ TXRX_FRAME(15 downto 0) <= MI_TX_DATA;
+ elsif(MI_READ_START = '1') then
+ -- start of read transaction.
+ -- Note: transmission sequence starts at bit 63
+ TXRX_FRAME(63 downto 32) <= x"FFFFFFFF"; -- preamble: idle sequence 32 '1's
+ TXRX_FRAME(31 downto 23) <= "0011" & PHY_ADDR;
+ TXRX_FRAME(22 downto 18) <= MI_REGAD;
+ elsif(MI_SAMPLE_REQ = '1') and (STATE /= 0) and (STATE(0) = '0') and (MDOE = '1') then
+ -- shift TXRX_FRAME 1 bit left every two clocks
+ TXRX_FRAME(63 downto 1) <= TXRX_FRAME(62 downto 0);
+ elsif(MI_SAMPLE_REQ = '1') and (STATE /= 0) and (STATE(0) = '1') and (MDOE = '0') then
+ -- shift MDIO into TXRX_FRAME 1 bit left every two clocks (read at the rising edge of MCLK)
+ -- do this 16 times to collect the 16-bit response from the PHY.
+ TXRX_FRAME(63 downto 1) <= TXRX_FRAME(62 downto 0);
+ TXRX_FRAME(0) <= MDIO_IN;
+ end if;
+ end if;
+end process;
+
+-- select output bit.
+MDIO_OUT <= TXRX_FRAME(63);
+MDIO_DIR <= not MDOE;
+
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/bram_dp2.vhd b/generic_ip/third_party_ip/mac/src/bram_dp2.vhd
new file mode 100644
index 0000000..5e4ce6b
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/bram_dp2.vhd
@@ -0,0 +1,150 @@
+-------------------------------------------------------------
+-- Filename: BRAM_DP2.VHD
+-- Authors:
+-- from http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_4/xst_v6s6.pdf
+-- Alain Zarembowitch / MSS
+-- Version: Rev 2
+-- Last modified: 6/29/16
+
+-- Inheritance: BRAM_DP.VHD 5/7/15
+--
+-- description: synthesizable generic dual port RAM
+--
+-- Rev 1b 6/21/16 AZ
+-- Switched to numeric_std library
+-- Initialize to zero during simulation
+--
+-- Rev 2 6/29/16 AZ
+-- Added asymmetrical case (different data widths on A and B ports)
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity BRAM_DP2 is
+ Generic (
+ DATA_WIDTHA: integer := 9; -- MUST BE <= DATA_WIDTHB
+ ADDR_WIDTHA: integer := 11;
+ DATA_WIDTHB: integer := 9;
+ ADDR_WIDTHB: integer := 11
+ -- total size on A size MUST match total size on B side
+ -- (DATA_WIDTHA * 2**ADDR_WIDTHA) == (DATA_WIDTHB * 2**ADDR_WIDTHB)
+ );
+ Port (
+ -- chip select, active high
+
+ -- Port A
+ CLKA : in std_logic;
+ CSA: in std_logic; -- chip select, active high
+ WEA : in std_logic; -- write enable, active high
+ OEA : in std_logic; -- output enable, active high
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+
+ -- Port B
+ CLKB : in std_logic;
+ CSB: in std_logic; -- chip select, active high
+ WEB : in std_logic; -- write enable, active high
+ OEB : in std_logic; -- output enable, active high
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+end entity;
+
+architecture Behavioral of BRAM_DP2 is
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------function
+--function max(L,R:INTEGER) return INTEGER is
+--begin
+-- if (L > R) then
+-- return L;
+-- else
+-- return R;
+-- end if;
+--end;
+--function min(L,R:INTEGER) return INTEGER is
+--begin
+-- if(L < R) then
+-- return L;
+-- else
+-- return R;
+-- end if;
+--end;
+
+-- see users constraints in generic section
+constant MIN_DATA_WIDTH: integer := DATA_WIDTHA;
+constant MAX_DATA_WIDTH: integer := DATA_WIDTHB;
+constant MIN_ADDR_WIDTH: integer := ADDR_WIDTHB;
+constant MAX_ADDR_WIDTH: integer := ADDR_WIDTHA;
+constant RATIO: integer := MAX_DATA_WIDTH / MIN_DATA_WIDTH;
+constant log2RATIO: integer := ADDR_WIDTHA - ADDR_WIDTHB;
+
+-- infered
+type mem_type is array ( (2**MAX_ADDR_WIDTH)-1 downto 0 ) of std_logic_vector(MIN_DATA_WIDTH-1 downto 0);
+shared variable MEM : mem_type := (others => (others => '0'));
+signal DOA_local: std_logic_vector(DATA_WIDTHA-1 downto 0) := (others => '0');
+signal DOB_local: std_logic_vector(DATA_WIDTHB-1 downto 0) := (others => '0');
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Port A write
+process(CLKA)
+begin
+ if rising_edge(CLKA) then
+ if(CSA = '1') and (WEA = '1') then
+ mem(to_integer(unsigned(ADDRA))) := DIA;
+ end if;
+ end if;
+end process;
+
+-- Port A read
+process(CLKA)
+begin
+ if rising_edge(CLKA) then
+ if(CSA = '1') then
+ DOA_local <= mem(to_integer(unsigned(ADDRA)));
+ else
+ DOA_local <= (others => '0');
+ end if;
+ end if;
+end process;
+
+-- tri-state output
+DOA <= DOA_local when (CSA = '1') and (OEA = '1') else (others => 'Z');
+
+-- Port B write
+process(CLKB)
+begin
+ if rising_edge(CLKB) then
+ if(CSB = '1') and (WEB = '1') then
+ for I in 0 to RATIO-1 loop
+ mem(to_integer(unsigned(ADDRB) & to_unsigned(I,log2RATIO))) := DIB((I+1)*MIN_DATA_WIDTH - 1 downto I*MIN_DATA_WIDTH);
+ end loop;
+ end if;
+ end if;
+end process;
+
+-- Port B read
+process(CLKB)
+begin
+ if rising_edge(CLKB) then
+ if(CSB = '1') then
+ for I in 0 to RATIO-1 loop
+ DOB_local((I+1)*MIN_DATA_WIDTH - 1 downto I*MIN_DATA_WIDTH) <= mem(to_integer(unsigned(ADDRB) & to_unsigned(I,log2RATIO)));
+ end loop;
+ else
+ DOB_local <= (others => '0');
+ end if;
+ end if;
+end process;
+
+-- tri-state output
+DOB <= DOB_local when (CSB = '1') and (OEB = '1') else (others => 'Z');
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/com5501.vhd b/generic_ip/third_party_ip/mac/src/com5501.vhd
new file mode 100644
index 0000000..41ec514
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/com5501.vhd
@@ -0,0 +1,2491 @@
+-------------------------------------------------------------
+-- MSS copyright 2017-2019
+-- Filename: COM5501.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 2
+-- Date last modified: 6/15/19
+-- Inheritance: COM5401.vhd
+--
+-- description: 10G Ethernet MAC with XGMII hardware interface
+-- Features include
+-- (a) Automatic appending of 32-bit CRC to tx packets. Users don't have to.
+-- (b) discarding of rx packets with bad CRC.
+-- (c) implement MAC pause control
+--
+-- The transmit elastic buffer is large enough for 2 maximum size frame. The tx Clear To Send (MAC_TX_CTS)
+-- signal is raised when the the MAC is ready to accept one complete frame without interruption.
+-- In this case, MAC_TX_CTS may go low while the frame transfer has started, but there is guaranteed
+-- space for the entire frame.
+--
+-- Rev1 4/25/19
+-- Corrected bad CRC when SFD is located at locations 3 and bytes are flushed (discrepancy reported by BR)
+--
+-- Rev2 6/15/19
+-- Corrected bug when frame size is 61-64 bytes
+-- Corrected bug: PHY status state machine was incremented 1 CLK too early
+--
+-------------------------------------------
+-- Device utilization
+-------------------------------------------
+--Number of Slice Registers: 1210
+--Number of Slice LUTs: 2737
+--Number of 18 Kb Block RAM/FIFO: 0
+--Number of DSP48: 0
+--Number of BUFG: 2
+--Minimum period: 4.830ns (Maximum Frequency: 207.039MHz) Artix7-100T -1 speed grade
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.numeric_std.ALL;
+
+entity COM5501 is
+ generic (
+ EXT_PHY_MDIO_ADDR: std_logic_vector(4 downto 0) := "00000";
+ -- external PHY MDIO address
+ RX_MTU: integer := 1500;
+ -- Maximum Transmission Unit: maximum number of payload Bytes.
+ -- Typically 1500 for standard frames, 9000 for jumbo frames.
+ -- A frame will be deemed invalid if its payload size exceeds this MTU value.
+ RX_BUFFER: std_logic := '0';
+ -- '1' when the received messages are stored temporarily into an elastic buffer prior to the output.
+ -- either because the next block is slower (and thus regulates the data flow), or when crossing clock
+ -- domains from CLK156g to CLK.
+ -- '0' for no output buffer: when flow control is not needed on the rx path and
+ -- the same 156.25 MHz clock is used as both user clock CLK and PHY clock CLK156g.
+ -- This setting is preferred for the lowest latency on the receive path.
+ RX_BUFFER_ADDR_NBITS: integer := 10;
+ -- size of the receiver output elastic buffer (when enabled by RX_BUFFER = '1'). Data width is always 74 bits.
+ -- Example: when RX_BUFFER_ADDR_NBITS = 10, the receive buffer size is 74*2^10 = 75776 bits
+ TX_MTU: integer := 1500;
+ TX_BUFFER: std_logic := '0';
+ -- '1' when the transmit messages are stored temporarily into an input elastic buffer,
+ -- when crossing clock domains from user CLK to PHY CLK156g.
+ -- '0' for no input buffer: when the same 156.25 MHz clock is used as both user clock CLK and PHY clock CLK156g.
+ -- This setting is preferred for the lowest latency on the transmit path.
+ TX_BUFFER_ADDR_NBITS: integer := 10;
+ MAC_CONTROL_PAUSE_ENABLE: std_logic := '1';
+ -- enable (1)/disable (0) enacting transmit pause upon receive a MAC control PAUSE message.
+ SIMULATION: std_logic := '0'
+ -- during simulation, fake LINK_STATUS = '1'
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ -- USER-side GLOBAL clock. Must be at least 156.25 MHz for full 10Gbits/s throughput.
+ -- It must be the same signal as CLK156g when RX_BUFFER = '0'
+ SYNC_RESET: in std_logic;
+ -- reset pulse must be > slowest clock period (>400ns)
+ -- synchronous with CLK
+ CLK156g: in std_logic;
+ -- PHY-side GLOBAL clock at 156.25 MHz
+
+ --// MAC CONFIGURATION
+ -- configuration signals are synchonous with the user-side CLK
+ MAC_TX_CONFIG: in std_logic_vector(7 downto 0);
+ -- bit 0: (1) Automatic padding of short frames. Requires that auto-CRC insertion be enabled too.
+ -- (0) Skip padding. User is responsible for adding padding to meet the minimum 60 byte frame size
+ -- bit 1: (1) Automatic appending of 32-bit CRC at the end of the frame
+ -- (0) Skip CRC32 insertion. User is responsible for including the frame check sequence
+ -- Note: use 0x03 when interfacing with COM-5502 IP/UDP/TCP stack.
+ MAC_RX_CONFIG: in std_logic_vector(7 downto 0);
+ -- bit 0: (1) promiscuous mode enabled (0) disabled, i.e. destination address is verified for each incoming packet
+ -- bit 1: (1) accept broadcast rx packets (0) reject
+ -- bit 2: (1) accept multi-cast rx packets (0) reject
+ -- bit 3: unused
+ -- bit 4: (1) Verify MTU size. Frames will be flagged as invalid if the payload size exceeds RX_MTU Bytes.
+ -- (0) Do not check MTU size
+ -- Note2: use 0x0F when interfacing with COM-5502 IP/UDP/TCP stack.
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- This network node 48-bit MAC address. The receiver checks incoming packets for a match between
+ -- the destination address field and this MAC address.
+ -- The user is responsible for selecting a unique ‘hardware’ address for each instantiation.
+ -- Natural bit order: enter x0123456789ab for the MAC address 01:23:45:67:89:ab
+ -- here, x01 is the first received/transmitted byte in the address
+
+ --// USER -> Transmit MAC Interface
+ -- Synchonous with the user-side CLK
+ MAC_TX_DATA: in std_logic_vector(63 downto 0);
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID = '1'
+ -- Bytes order: LSB is sent first
+ -- Bytes are right aligned: first byte in LSB, occasional follow-on fill-in Bytes in the MSB(s)
+ -- The first destination address byte is always a LSB (MAC_TX_DATA(7:0))
+ -- USAGE RULE: only the end of frame word can be partially full (MAC_TX_DATA_VALID = 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f)
+ -- all other words must contain either 0 or 8 bytes.
+ MAC_TX_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- '1' for each meaningful byte in MAC_TX_DATA.
+ -- In this application, only valid values are 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
+ MAC_TX_EOF: in std_logic;
+ -- '1' when sending the last word in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: out std_logic;
+ -- MAC-generated Clear To Send flow control signal, indicating room in the
+ -- tx elastic buffer for a complete MTU.
+ -- The user should check that this signal is high before deciding to send
+ -- sending the next frame.
+ -- Note: MAC_TX_CTS may go low while the frame is transfered in. Ignore it.
+
+ --// Receive MAC -> USER Interface
+ -- Valid rx packets only: packets with bad CRC or invalid address are discarded.
+ -- Synchonous with the user-side CLK
+ -- The short-frame padding is included .
+ MAC_RX_DATA: out std_logic_vector(63 downto 0);
+ -- USER reads the data at the rising edge of CLK when MAC_RX_DATA_VALID = '1'
+ -- Bytes order: LSB was received first
+ -- Bytes are right aligned: first byte in LSB, occasional follow-on fill-in Bytes in the MSB(s)
+ -- The first destination address byte is always a LSB (MAC_RX_DATA(7:0))
+ MAC_RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- '1' for each meaningful byte in MAC_RX_DATA.
+ -- In this application, only valid values are 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
+ MAC_RX_SOF: out std_logic;
+ -- '1' when sending the first byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ MAC_RX_EOF: out std_logic;
+ -- '1' when sending the last byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ -- The entire frame validity is confirmed at the end of frame when MAC_RX_FRAME_VALID = '1'
+ -- Users should discard the entire frame when MAC_RX_FRAME_VALID = '0' at MAC_RX_EOF
+ MAC_RX_FRAME_VALID: out std_logic;
+ -- '1' when the received frame passed all validity checks, including CRC32.
+ -- Read at the end of frame when MAC_RX_EOF = '1'
+ MAC_RX_CTS: in std_logic;
+ -- User-generated Clear To Send flow control signal. The receive MAC checks that this
+ -- signal is high before sending the next MAC_RX_DATA byte.
+ -- Ignored when the rx output buffer is not instantiated (RX_BUFFER = '0')
+ -- parsed information from received MAC frame
+
+
+ --// XGMII PHY Interface
+ XGMII_TXD: out std_logic_vector(63 downto 0);
+ XGMII_TXC: out std_logic_vector(7 downto 0);
+ -- Single data rate transmit interface
+ -- LSB is sent first
+
+ XGMII_RXD: in std_logic_vector(63 downto 0);
+ XGMII_RXC: in std_logic_vector(7 downto 0);
+ -- Single data rate receive interface
+ -- LSb of LSB is received first
+ -- Start character 0xFB is in byte 0 or 4
+ -- XGMII_RXC bit is '0' for valid data byte
+ RESET_N: out std_logic;
+ -- PHY reset#
+ MDC: out std_logic;
+ MDIO_OUT: out std_logic;
+ MDIO_IN: in std_logic;
+ MDIO_DIR: out std_logic; -- '0' when output, '1' when input
+ -- MDIO serial interface to control and monitor two MMDs: external 10G PHY and
+ -- internal XAUI adapter.
+
+ --// PHY CONFIGURATION
+ -- configuration signals are synchonous with the user-side CLK.
+ PHY_CONFIG_CHANGE: in std_logic;
+ -- optional pulse to activate any configuration change below.
+ -- Not needed if the internal default values are acceptable.
+ PHY_RESET: in std_logic;
+ -- 1 = PHY software reset (default), 0 = no reset
+ TEST_MODE: in std_logic_vector(1 downto 0);
+ -- 00 = normal mode (default)
+ -- 01 = loopback mode
+ -- 10 = remote loopback
+ POWER_DOWN: in std_logic;
+ -- software power down mode. 1 = enabled, 0 = disabled (default).
+
+
+ --// PHY status
+ -- synchronous with CLK156g global clock
+ PHY_STATUS: out std_logic_vector(7 downto 0);
+ -- XAUI side of the PHY chip
+ -- bit0: all PHY XAUI rx lanes in sync
+ -- bit1: PHY XAUI rx PLL in lock
+ -- bit2: PHY XAUI rx lane0 signal present
+ -- bit3: PHY XAUI rx lane1 signal present
+ -- bit4: PHY XAUI rx lane2 signal present
+ -- bit5: PHY XAUI rx lane3 signal present
+ -- Expecting 0x3F during normal operations
+ -- read periodically.
+ PHY_STATUS2: out std_logic_vector(7 downto 0);
+ -- SFP+ side of the PHY chip
+ PHY_ID: out std_logic_vector(15 downto 0);
+ -- read PHY device ID (part of hardware self-test). Correct answer for VSC8486-11 is 0x8486
+ -- read once at power up.
+
+ --// DIAGNOSTICS (synchronous with user-supplied clock CLK)
+ N_TX_FRAMES: out std_logic_vector(15 downto 0);
+ -- number of transmitted frames
+ N_RX_FRAMES: out std_logic_vector(15 downto 0);
+ -- number of received frames
+ N_RX_BAD_CRCS: out std_logic_vector(15 downto 0);
+ -- number of BAD CRCs among the received frames
+ N_RX_FRAMES_TOO_SHORT: out std_logic_vector(15 downto 0);
+ -- number of rx frames too short (<64B)
+ N_RX_FRAMES_TOO_LONG: out std_logic_vector(15 downto 0);
+ -- number of rx frames too long (>1518B)
+ N_RX_WRONG_ADDR: out std_logic_vector(15 downto 0);
+ -- number of rx frames where address does not match (and promiscuous mode is off)
+ N_RX_LENGTH_ERRORS: out std_logic_vector(15 downto 0);
+ -- number of rx frames with length field inconsistent with actual rx frame length
+ RX_IPG: out std_logic_vector(7 downto 0);
+ -- InterPacket Gap (in Bytes) between the last two successive packets (min is typically 12 Bytes, but
+ -- can be as low as 5 Bytes for 10G).
+
+ --// TEST POINTS
+ DEBUG1: out std_logic_vector(63 downto 0);
+ DEBUG2: out std_logic_vector(63 downto 0);
+ DEBUG3: out std_logic_vector(63 downto 0);
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of COM5501 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT PHY_CONFIG
+ GENERIC (
+ EXT_PHY_MDIO_ADDR: std_logic_vector(4 downto 0)
+ -- external PHY MDIO address
+ );
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ CONFIG_CHANGE : IN std_logic;
+ PHY_RESET: in std_logic;
+ TEST_MODE: in std_logic_vector(1 downto 0);
+ POWER_DOWN: in std_logic;
+ SREG_READ_START : IN std_logic;
+ SREG_MMD: in std_logic_vector(4 downto 0);
+ SREG_ADDR: in std_logic_vector(15 downto 0);
+ SREG_DATA : OUT std_logic_vector(15 downto 0);
+ SREG_SAMPLE_CLK : OUT std_logic;
+ SREG_READ_IDLE: out std_logic;
+ MDC: out std_logic;
+ MDIO_OUT: out std_logic;
+ MDIO_IN: in std_logic;
+ MDIO_DIR: out std_logic; -- '0' when output, '1' when input
+ TP: out std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT CRC32
+ PORT(
+ CLK : IN std_logic;
+ DATA_IN : IN std_logic_vector(63 downto 0);
+ SAMPLE_CLK_IN : IN std_logic;
+ SOF_IN: in std_logic;
+ DATA_VALID_IN : IN std_logic_vector(7 downto 0);
+ CRC_INITIALIZATION: in std_logic_vector(31 downto 0);
+ CRC_OUT : OUT std_logic_vector(31 downto 0);
+ SAMPLE_CLK_OUT : OUT std_logic
+ );
+ END COMPONENT;
+
+ /*
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CSA : IN std_logic;
+ CLKA : in std_logic;
+ WEA : in std_logic;
+ OEA : IN std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CSB : IN std_logic;
+ CLKB : in std_logic;
+ WEB : in std_logic;
+ OEB : IN std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+ */
+ component sdp_ram is
+ generic (
+ ADDR_WIDTH : natural;
+ DATA_WIDTH : integer);
+ port (
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic;
+ enb : in std_logic;
+ wea : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+ end component sdp_ram;
+
+-- COMPONENT TEST_XGMII_TX
+-- PORT(
+-- CLK156g : IN std_logic;
+-- SYNC_RESET156 : IN std_logic;
+-- TX_TRIGGER : IN std_logic;
+-- XGMII_TXD : OUT std_logic_vector(63 downto 0);
+-- XGMII_TXC : OUT std_logic_vector(7 downto 0);
+-- TP : OUT std_logic_vector(10 downto 1)
+-- );
+-- END COMPONENT;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- NOTATIONS:
+-- _E as one-CLK early sample
+-- _D as one-CLK delayed sample
+-- _D2 as two-CLKs delayed sample
+
+--// CLK & RESETS ---------
+
+signal SYNC_RESET_D: std_logic := '0';
+signal SYNC_RESET156: std_logic := '0';
+
+--// PHY RESET AND CONFIGURATION ----------------------------------------------------------
+signal RESET_CNTR: unsigned(8 downto 0) := (others => '0');
+signal SYNC_RESET_local: std_logic := '0';
+signal RESET_COMPLETE: std_logic := '0';
+signal INITIAL_CONFIG_PULSE: std_logic := '1';
+signal PHY_CONFIG_CHANGE_PENDING: std_logic := '0';
+signal PHY_CONFIG_CHANGE_A: std_logic := '0';
+
+
+signal PHY_RESET_A: std_logic := '0';
+signal TEST_MODE_A: std_logic_vector(1 downto 0);
+signal POWER_DOWN_A: std_logic := '0';
+signal PHY_IF_WRAPPER_RESET: std_logic := '0';
+signal SREG_READ_START: std_logic := '0';
+signal SREG_READ_START_D: std_logic := '0';
+signal SREG_SAMPLE_CLK: std_logic := '0';
+signal SREG_READ_IDLE: std_logic := '0';
+signal SREG_READ_IDLE_D: std_logic := '0';
+signal LINK_STATUS_local: std_logic := '0';
+signal SREG_MMD: std_logic_vector(4 downto 0) := (others => '0');
+signal SREG_ADDR: std_logic_vector(15 downto 0) := (others => '0');
+signal SREG_DATA : std_logic_vector(15 downto 0) := (others => '0');
+signal SREG_STATE: unsigned(2 downto 0) := (others => '0');
+
+--// LOW-LATENCY TX INPUT ----------------------------------------------------------
+signal MAC_TX_INFRAME: std_logic := '0';
+signal MAC_TX_DATA2: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA2_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_SOF2: std_logic := '0';
+signal MAC_TX_EOF2: std_logic := '0';
+
+--// TX ELASTIC BUFFER ----------------------------------------------------------
+signal MAC_TX_DIA: std_logic_vector(72 downto 0) := (others => '0');
+signal MAC_TX_DOB: std_logic_vector(72 downto 0) := (others => '0');
+signal MAC_TX_WPTR: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_D: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_D2: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_D3: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_STABLE: std_logic := '0';
+signal MAC_TX_WPTR_STABLE_D: std_logic := '0';
+signal TX_COUNTER8: unsigned(2 downto 0) :=(others => '0');
+signal MAC_TX_WEA: std_logic := '0';
+signal MAC_TX_SAMPLE2_CLK: std_logic := '0'; -- TODO
+signal MAC_TX_SAMPLE2_CLK_E: std_logic := '0'; -- TODO
+
+signal MAC_TX_BUF_SIZE: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_RPTR: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_TX_RPTR_D: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_TX_RPTR_CONFIRMED: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_TX_RPTR_CONFIRMED_D: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal COMPLETE_TX_FRAMES_INBUF: std_logic_vector(7 downto 0) := x"00"; -- can't have more than 147 frames in a 16k buffer
+signal ATLEAST1_COMPLETE_TX_FRAME_INBUF: std_logic := '0';
+signal MAC_TX_EOF_TOGGLE: std_logic := '0';
+signal MAC_TX_EOF_TOGGLE_D: std_logic := '0';
+signal MAC_TX_EOF_TOGGLE_D2: std_logic := '0';
+signal MAC_TX_CTS_local: std_logic := '0';
+
+--// SHORT FRAME PADDING ----------------------------------------------------------
+signal TX_BYTE_CNTR: unsigned(13 downto 0):= (others => '0'); -- large enough for counting 9000 bytes in Jumbo frame
+signal TX_FILL_CNTR: unsigned(5 downto 0):= (others => '0'); -- range 0 - 60
+signal TX_FILL_NEXT: std_logic := '0';
+signal MAC_TX_DATA3: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA3_D: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA3_D2: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA3_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_DATA3_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_DATA3_VALID_D2: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_SOF3: std_logic := '0';
+signal MAC_TX_SOF3_D: std_logic := '0';
+signal MAC_TX_EOF3: std_logic := '0';
+signal MAC_TX_EOF3_D: std_logic := '0';
+signal MAC_TX_EOF3_D2: std_logic := '0';
+signal MAC_TX_EOF3_D3: std_logic := '0';
+
+--// TX 32-BIT CRC COMPUTATION -------------------------------------------------------
+signal TX_CRC_DATA_IN: std_logic_vector(63 downto 0) := (others => '0');
+signal TX_CRC_SAMPLE_CLK_IN: std_logic := '0';
+signal TX_CRC_DATA_VALID_IN: std_logic_vector(7 downto 0):= (others => '0');
+signal TX_CRC32: std_logic_vector(31 downto 0) := (others => '0');
+signal TX_CRC_SAMPLE_CLK_OUT: std_logic := '0';
+signal TX_CRC32_FLIPPED_INV: std_logic_vector(31 downto 0) := (others => '0');
+
+--//-- XGMII TX INTERFACE --------------------------------
+signal XGMII_TXD0: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_TXC0: std_logic_vector(7 downto 0) := (others => '0');
+signal XGMII_TXD0_NEXT: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_TXC0_NEXT: std_logic_vector(7 downto 0) := (others => '0');
+signal XGMII_TXD_NEXT: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_TXC_NEXT: std_logic_vector(7 downto 0) := (others => '0');
+signal N_TX_FRAMES_local: unsigned(15 downto 0) := (others => '0');
+
+--//-- TX FLOW CONTROL --------------------------------
+signal TX_SUCCESS_TOGGLE: std_logic := '0';
+signal TX_SUCCESS_TOGGLE_D: std_logic := '0';
+signal TX_SUCCESS_TOGGLE_D2: std_logic := '0';
+signal MAC_TX_BUF_FREE: std_logic_vector(11 downto 0) := (others => '0');
+
+
+--// MAC TX STATE MACHINE ----------------------------------------------------------
+--signal TX_CLKG: std_logic := '0';
+--signal IPG: std_logic := '0';
+--signal IPG_CNTR: std_logic_vector(7 downto 0) := (others => '0'); -- TODO CHECK CONSISTENCY WITH TIMER VALUES
+--signal TX_EVENT1: std_logic := '0';
+--signal TX_EVENT2: std_logic := '0';
+--signal TX_EVENT3: std_logic := '0';
+--signal TX_STATE: integer range 0 to 15 := 0;
+--signal TX_BYTE_COUNTER: std_logic_vector(18 downto 0) := (others => '0'); -- large enough for counting 2000 Bytes in max size packet
+--signal TX_BYTE_COUNTER2: std_logic_vector(2 downto 0) := (others => '0'); -- small auxillary byte counter for small fields
+--signal RETX_ATTEMPT_COUNTER: std_logic_vector(4 downto 0) := (others => '0'); -- re-transmission attempts counter
+--signal TX_SUCCESS: std_logic := '0';
+--signal TX_ER: std_logic := '0';
+
+
+
+--// TEST XGMII TX -------------------------------------------------------
+signal TEST_XGMII_TX_TP: std_logic_vector(10 downto 1) := (others => '0');
+
+
+--// MAC RX STATE MACHINE ----------------------------------------------------------
+signal XGMII_RXD_D: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_RX_START_CHAR: std_logic := '0';
+signal XGMII_RX_START_CHAR_D: std_logic := '0'; -- TEST TEST TEST DEL
+signal XGMII_RX_START_LOC: unsigned(2 downto 0) := (others => '0');
+signal XGMII_RX_SFD_CHAR: std_logic := '0';
+signal XGMII_RX_SFD_LOC: unsigned(2 downto 0) := (others => '0');
+signal XGMII_RX_TERM_CHAR: std_logic := '0';
+signal XGMII_RX_TERM_LOC: unsigned(2 downto 0) := (others => '0');
+signal XGMII_RX_ERROR_CHAR: std_logic := '0';
+signal XGMII_RX_IN_FRAME: std_logic := '0';
+signal XGMII_RX_DATA1: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_RX_DATA1_D: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_RX_DATA1A: std_logic_vector(31 downto 0) := (others => '0');
+signal XGMII_RX_SAMPLE1_CLK: std_logic := '0';
+signal XGMII_RX_SAMPLE1_CLK_D: std_logic := '0';
+signal XGMII_RX_DATA1_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal XGMII_RX_DATA1_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal XGMII_RX_SOF1: std_logic := '0';
+signal XGMII_RX_SOF1_D: std_logic := '0';
+signal XGMII_RX_SOF1_D2: std_logic := '0'; -- TEST TEST TEST
+signal XGMII_RX_EOF1A: std_logic := '0';
+signal XGMII_RX_EOF1: std_logic := '0';
+signal XGMII_RX_EOF1_D: std_logic := '0';
+signal XGMII_RX_FLUSH: std_logic := '0';
+signal RX_STATE: integer range 0 to 3 := 0;
+signal RX_STATE2: std_logic := '0';
+signal RX_STATE2_D: std_logic := '0';
+signal RX_TOO_SHORT: std_logic := '0';
+signal RX_TOO_LONG: std_logic := '0';
+signal RX_IPG_local: unsigned(8 downto 0):= (others => '0');
+signal RX_VALID_ADDR: std_logic := '0';
+signal MAC_ADDR_REORDER: std_logic_vector(47 downto 0) := (others => '0');
+signal RX_BYTE_CNTR: unsigned(13 downto 0):= (others => '0'); -- large enough for counting 9000 bytes in Jumbo frame
+signal RX_BYTE_CNTR_FINAL: unsigned(13 downto 0):= (others => '0');
+signal RX_WORD_CNTR: unsigned(RX_BYTE_CNTR'left-3 downto 0):= (others => '0'); -- 64-bit word counter
+
+--//-- RX ETHERNET FRAME PARSING ---------------------------
+signal RX_VLAN: std_logic := '0';
+
+--//-- MAC CONTROL PAUSE OPERATION ---------------------------
+signal RX_CONTROL_PAUSE_VALID: std_logic := '0';
+signal RX_CONTROL_PAUSE_VALID2: std_logic := '0';
+signal PAUSE_OPCODE: std_logic_vector(15 downto 0) := (others => '0');
+signal PAUSE_TIME: std_logic_vector(15 downto 0) := (others => '0');
+
+--// RX 32-BIT CRC COMPUTATION -------------------------------------------------------
+signal RX_CRC_DATA_IN: std_logic_vector(63 downto 0) := (others => '0');
+signal RX_CRC_DATA_VALID_IN: std_logic_vector(7 downto 0) := (others => '0');
+signal RX_CRC0: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_CRC: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_CRC_VALID: std_logic := '0';
+
+--// Length/type field check ----------------------
+signal RX_LENGTH_TYPE_FIELD: std_logic_vector(15 downto 0) := (others => '0');
+signal RX_LENGTH_TYPEN: std_logic := '0';
+signal RX_LENGTH: unsigned(13 downto 0) := (others => '0');
+signal RX_DIFF: unsigned(13 downto 0) := (others => '0');
+signal RX_LENGTH_ERR: std_logic := '0';
+
+--// VALID RX FRAME? ----------------------------------------------------------
+signal MAC_RX_EOF_TOGGLE: std_logic := '0';
+signal MAC_RX_EOF_TOGGLE_D: std_logic := '0';
+signal MAC_RX_EOF_TOGGLE_D2: std_logic := '0';
+signal N_RX_FRAMES_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_BAD_CRCS_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_FRAMES_TOO_SHORT_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_FRAMES_TOO_LONG_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_LENGTH_ERRORS_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_WRONG_ADDR_local: unsigned(15 downto 0) := (others => '0');
+signal MAC_RX_FRAME_VALID_local: std_logic := '0';
+
+signal MAC_RX_DATA2: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_RX_DATA2_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_RX_SOF2: std_logic := '0';
+signal MAC_RX_EOF2: std_logic := '0';
+signal MAC_RX_SAMPLE2_CLK: std_logic := '0';
+
+--// RX INPUT ELASTIC BUFFER ----------------------------------------------------------
+signal MAC_RX_WPTR: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_WPTR_CONFIRMED: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_WPTR_CONFIRMED_D: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_DIA: std_logic_vector(73 downto 0) := (others => '0');
+signal MAC_RX_DOB: std_logic_vector(73 downto 0) := (others => '0');
+signal MAC_RX_BUF_SIZE: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_RPTR: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_RX_SAMPLE3_CLK: std_logic := '0';
+signal MAC_RX_SAMPLE3_CLK_E: std_logic := '0';
+
+
+
+signal PHY_CONFIG_TP: std_logic_vector(10 downto 1) := (others => '0');
+
+-- test test test
+signal FIRST_RXCRCERROR_FLAG: std_logic;
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// SYNCHRONOUS RESETS ----------------------------------------------------------
+-- Create synchronous reset for all two clocks within: CLK156g, CLK
+
+-- Create synchronous reset for CLK156g
+SYNC_RESET156_GEN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ SYNC_RESET_D <= SYNC_RESET;
+ SYNC_RESET156 <= SYNC_RESET_D;
+ end if;
+end process;
+
+--// PHY RESET AND CONFIGURATION ----------------------------------------------------------
+-- First generate a RESET_N pulse at least 100ns wide(VSC8486-11 specs)
+RESET_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RESET_CNTR <= (others => '0');
+ elsif(RESET_CNTR(8) = '0') then
+ RESET_CNTR <= RESET_CNTR + 1;
+ end if;
+
+ case RESET_CNTR(8 downto 7) is
+ when "00" => RESET_N <= '1'; -- between 0 and 63
+ when "01" => RESET_N <= '0'; -- 64-127
+ when "10" => RESET_N <= '1'; -- 128+
+ when others => RESET_N <= '1';
+ end case;
+ end if;
+end process;
+SYNC_RESET_local <= not RESET_CNTR(8);
+RESET_COMPLETE <= RESET_CNTR(8);
+INITIAL_CONFIG_PULSE <= '1' when (RESET_CNTR) = 192 else '0';
+
+-- hold the PHY_CONFIG_CHANGE until the intial reset cycle is complete
+PHY_CONFIG_CHANGE_HOLD: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(PHY_CONFIG_CHANGE = '1') then
+ PHY_CONFIG_CHANGE_PENDING <= '1';
+ elsif(PHY_CONFIG_CHANGE_PENDING = '1') and (RESET_COMPLETE = '1') then
+ PHY_CONFIG_CHANGE_PENDING <= '0';
+ end if;
+ end if;
+end process;
+
+-- enact the configuration
+PHY_CONFIG_CHANGE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or ((INITIAL_CONFIG_PULSE = '1') and (PHY_CONFIG_CHANGE_PENDING = '0')) then
+ -- A default configuration is loaded automatically after power up.
+ PHY_CONFIG_CHANGE_A <= '1';
+ PHY_RESET_A <= '0'; -- no software PHY reset, we just did a hardware reset
+ TEST_MODE_A <= "00";
+ POWER_DOWN_A <= '0';
+ elsif(PHY_CONFIG_CHANGE_PENDING = '1') and (RESET_COMPLETE = '1') then
+ -- PHY_CONFIG_CHANGE indicates a user-triggered configuration change.
+ PHY_CONFIG_CHANGE_A <= '1';
+ PHY_RESET_A <= PHY_RESET;
+ TEST_MODE_A <= TEST_MODE;
+ POWER_DOWN_A <= POWER_DOWN;
+ else
+ PHY_CONFIG_CHANGE_A <= '0';
+ end if;
+ end if;
+end process;
+
+
+PHY_CONFIG_001: PHY_CONFIG
+GENERIC MAP(
+ EXT_PHY_MDIO_ADDR => EXT_PHY_MDIO_ADDR
+)
+PORT MAP(
+ SYNC_RESET => SYNC_RESET_local, -- wait until reset is complete
+ CLK => CLK,
+ CONFIG_CHANGE => PHY_CONFIG_CHANGE_A,
+ PHY_RESET => PHY_RESET_A,
+ TEST_MODE => TEST_MODE_A,
+ POWER_DOWN => POWER_DOWN_A,
+ SREG_READ_START => SREG_READ_START,
+ SREG_MMD => SREG_MMD, -- MDIO managed device
+ SREG_ADDR => SREG_ADDR, -- status register address
+ SREG_DATA => SREG_DATA,
+ SREG_SAMPLE_CLK => SREG_SAMPLE_CLK,
+ SREG_READ_IDLE => SREG_READ_IDLE,
+ MDC => MDC,
+ MDIO_OUT => MDIO_OUT,
+ MDIO_IN => MDIO_IN,
+ MDIO_DIR => MDIO_DIR,
+ TP => PHY_CONFIG_TP
+);
+
+
+---- Special cases
+--LINK_STATUS_local <= '1' when (SIMULATION = '1') else -- fake link status during simulation
+-- LINK_STATUS_FROM_PHY; -- otherwise, ask the PHY for LINK_STATUS
+--
+-- read PHY identification once at power-up or reset (hardware self-test
+-- then periodically read the link status
+PHY_STATUS_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ SREG_READ_IDLE_D <= SREG_READ_IDLE;
+ SREG_READ_START_D <= SREG_READ_START;
+
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ SREG_MMD <= "00001"; -- MDIO managed device
+ SREG_ADDR <= x"E800"; -- PHY device Identifier CHIP_ID
+ SREG_STATE <= "000";
+ SREG_READ_START <= '1'; -- start asking for status register
+ elsif(SREG_READ_START = '1') then
+ SREG_STATE <= SREG_STATE + 1; -- await status response
+ SREG_READ_START <= '0';
+ elsif(SREG_STATE = 1) and ((SREG_SAMPLE_CLK = '1') or ((SREG_READ_IDLE_D = '1') and (SREG_READ_START_D = '0'))) then
+ -- received CHIP_ID
+ -- periodically read XAUI RX loss of signal status into PHY_STATUS
+ SREG_MMD <= "00100"; -- MDIO managed device
+ SREG_ADDR <= x"8012"; -- PHY XAUI RX status
+ SREG_STATE <= SREG_STATE + 1;
+ SREG_READ_START <= '1'; -- ask for next status register
+ elsif(SREG_STATE = 3) and ((SREG_SAMPLE_CLK = '1') or ((SREG_READ_IDLE_D = '1') and (SREG_READ_START_D = '0'))) then
+ -- received XAUI RX status.
+ -- periodically read PHY SPF+ status
+ SREG_MMD <= "00001"; -- MDIO managed device
+ SREG_ADDR <= x"E600"; -- PMA status 4
+ SREG_STATE <= SREG_STATE + 1;
+ SREG_READ_START <= '1'; -- ask for next status register
+ elsif(SREG_STATE = 5) and ((SREG_SAMPLE_CLK = '1') or ((SREG_READ_IDLE_D = '1') and (SREG_READ_START_D = '0'))) then
+ -- received PHY SPF+ status. Ask again for PHY device ID etc... in a loop
+ SREG_MMD <= "00001"; -- MDIO managed device
+ SREG_ADDR <= x"E800"; -- PHY device Identifier CHIP_ID
+ SREG_STATE <= "000";
+ SREG_READ_START <= '1'; -- ask for next status register
+ end if;
+ end if;
+end process;
+
+PHY_STATUS_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ PHY_ID <= (others => '0');
+ elsif(SREG_STATE = 1) and (SREG_SAMPLE_CLK = '1') then
+ PHY_ID <= SREG_DATA;
+ end if;
+
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ PHY_STATUS <= (others => '0');
+ elsif(SREG_STATE = 3) and (SREG_SAMPLE_CLK = '1') then
+ -- bit0: all PHY XAUI rx lanes in sync
+ -- bit1: PHY XAUI rx PLL in lock
+ -- bit2: PHY XAUI rx lane0 signal present
+ -- bit3: PHY XAUI rx lane1 signal present
+ -- bit4: PHY XAUI rx lane2 signal present
+ -- bit5: PHY XAUI rx lane3 signal present
+ PHY_STATUS(0) <= SREG_DATA(6);
+ PHY_STATUS(1) <= not SREG_DATA(5);
+ PHY_STATUS(2) <= not SREG_DATA(0);
+ PHY_STATUS(3) <= not SREG_DATA(1);
+ PHY_STATUS(4) <= not SREG_DATA(2);
+ PHY_STATUS(5) <= not SREG_DATA(3);
+ end if;
+
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ PHY_STATUS2 <= (others => '0');
+ elsif(SREG_STATE = 5) and (SREG_SAMPLE_CLK = '1') then
+ -- received PHY SPF+ status. Ask again for PHY XAUI RX status
+ PHY_STATUS2 <= SREG_DATA(7 downto 0);
+ end if;
+
+ end if;
+end process;
+
+--// LOW-LATENCY TX INPUT ----------------------------------------------------------
+-- low-latency transmit case CLK=CLK156g
+NO_TX_BUF_001: if(TX_BUFFER = '0') generate
+ MAC_TX_DATA2 <= MAC_TX_DATA;
+ MAC_TX_DATA2_VALID <= MAC_TX_DATA_VALID;
+ MAC_TX_SOF2 <= '1' when ((MAC_TX_INFRAME = '0') and (unsigned(MAC_TX_DATA_VALID) /= 0)) else '0';
+ MAC_TX_EOF2 <= MAC_TX_EOF;
+
+ -- recreate a MAC_TX_SOF2
+ TX_SOF_GEN_001: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ -- GIS Edit : This signal must be cleared at reset, otherwise you
+ -- may not transmit correctly first packet after the reset
+ --if(MAC_TX_EOF = '1') then
+ if(SYNC_RESET156 = '1' or MAC_TX_EOF = '1') then
+ MAC_TX_INFRAME <= '0';
+ elsif (unsigned(MAC_TX_DATA_VALID) /= 0) then
+ MAC_TX_INFRAME <= '1';
+ end if;
+ end if;
+ end process;
+
+ MAC_TX_CTS <= '0' when (MAC_TX_EOF = '1') else -- immediately stop inflow when receiving EOF (we may need a few CLKs for padding)
+ '0' when (TX_FILL_NEXT = '1') else
+ '1';
+end generate;
+
+
+--// TX ELASTIC BUFFER ----------------------------------------------------------
+TX_BUF_001: if(TX_BUFFER = '1') generate
+ -- The purpose of the elastic buffer is two-fold:
+ -- (a) a transition between the CLK-synchronous user side, and the CLK156g synchronous PHY side
+ -- (b) storage for Ethernet transmit frames, to absorb traffic peaks, minimize the number of
+ -- UDP packets lost at high throughput.
+ -- The tx elastic buffer is 16Kbits, large enough for TWO complete maximum size
+ -- (14addr+1500data+4FCS = 1518B) frames.
+
+ MAC_TX_WEA <= '1' when (unsigned(MAC_TX_DATA_VALID) /= 0) else '0';
+ -- write pointer management
+ MAC_TX_WPTR_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_COUNTER8 <= (others => '0');
+ MAC_TX_WPTR <= (others => '0');
+ MAC_TX_WPTR_D <= (others => '0');
+ MAC_TX_WPTR_STABLE <= '0';
+ else
+ TX_COUNTER8 <= TX_COUNTER8 + 1;
+
+ if(MAC_TX_WEA = '1') then
+ MAC_TX_WPTR <= MAC_TX_WPTR + 1;
+ end if;
+
+ -- update WPTR_D once every 8 clocks.
+ if(TX_COUNTER8 = 7) then
+ MAC_TX_WPTR_D <= MAC_TX_WPTR;
+ end if;
+
+ -- allow WPTR reclocking with another clock, as long as it is away from the transition area
+ if(TX_COUNTER8 < 6) then
+ MAC_TX_WPTR_STABLE <= '1';
+ else
+ MAC_TX_WPTR_STABLE <= '0';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ MAC_TX_DIA <= MAC_TX_EOF & MAC_TX_DATA_VALID & MAC_TX_DATA;
+ -- concatenate 64-bit word and byte valid
+
+ -- GIS Edit : replaced the memory model with a symmetrical, dual-clock
+ -- simple-dual-port (one read port, one write port) memory.
+ /*
+ BRAM_DP2_001: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 73,
+ ADDR_WIDTHA => TX_BUFFER_ADDR_NBITS,
+ DATA_WIDTHB => 73,
+ ADDR_WIDTHB => TX_BUFFER_ADDR_NBITS
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => MAC_TX_WEA,
+ OEA => '0',
+ ADDRA => std_logic_vector(MAC_TX_WPTR),
+ DIA => std_logic_vector(MAC_TX_DIA),
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK156g,
+ WEB => '0',
+ OEB => '1',
+ ADDRB => std_logic_vector(MAC_TX_RPTR),
+ DIB => (others => '0'),
+ DOB => MAC_TX_DOB
+ );
+ */
+ BRAM_DP2_001: SDP_RAM
+ GENERIC MAP (
+ ADDR_WIDTH => TX_BUFFER_ADDR_NBITS,
+ DATA_WIDTH => 73)
+ PORT MAP (
+ ENA => '1',
+ CLKA => CLK,
+ WEA => MAC_TX_WEA,
+ ADDRA => std_logic_vector(MAC_TX_WPTR),
+ DIA => std_logic_vector(MAC_TX_DIA),
+ ENB => '1',
+ CLKB => CLK156g,
+ ADDRB => std_logic_vector(MAC_TX_RPTR),
+ DOB => MAC_TX_DOB);
+
+ MAC_TX_DATA2 <= MAC_TX_DOB(63 downto 0);
+ MAC_TX_DATA2_VALID <= MAC_TX_DOB(71 downto 64) when (MAC_TX_SAMPLE2_CLK = '1') else (others => '0');
+ MAC_TX_SOF2 <= '1' when ((MAC_TX_INFRAME = '0') and (unsigned(MAC_TX_DATA2_VALID) /= 0)) else '0';
+ MAC_TX_EOF2 <= MAC_TX_DOB(72);
+
+ -- recreate a MAC_TX_SOF2
+ TX_SOF_GEN_001: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(MAC_TX_EOF2 = '1') then
+ MAC_TX_INFRAME <= '0';
+ elsif (unsigned(MAC_TX_DATA2_VALID) /= 0) then
+ MAC_TX_INFRAME <= '1';
+ end if;
+ end if;
+ end process;
+
+ -- CLK156g zone. Reclock WPTR
+ MAC_TX_WPTR_002: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ MAC_TX_WPTR_STABLE_D <= '0';
+ MAC_TX_WPTR_D2 <= (others => '0');
+ MAC_TX_WPTR_D3 <= (others => '0');
+ else
+ MAC_TX_WPTR_STABLE_D <= MAC_TX_WPTR_STABLE;
+ MAC_TX_WPTR_D2 <= MAC_TX_WPTR_D;
+
+ if(MAC_TX_WPTR_STABLE_D = '1') then
+ -- WPTR is stable. OK to resample with the CLK156g clock.
+ MAC_TX_WPTR_D3 <= MAC_TX_WPTR_D2;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ MAC_TX_BUF_SIZE <= MAC_TX_WPTR_D3 + not(MAC_TX_RPTR);
+ -- occupied tx buffer size for reading purposes (CLKG clock domain)(
+ -- always lags, could be a bit more, never less.
+
+ MAC_TX_CTS <= '1'; -- TODO !!!!!!!!!!!!!!!!!!!!!!
+ -- TODO: RPTR, FLOW CONTROL???
+
+end generate;
+
+--// SHORT FRAME PADDING ----------------------------------------------------------
+-- keep track of incoming tx frame size
+-- TX_BYTE_CNTR ready at MAC_TX_EOF2_D
+TX_PADDING_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ TX_BYTE_CNTR <= (others => '0');
+ elsif(MAC_TX_SOF2 = '1') then
+ TX_BYTE_CNTR <= to_unsigned(8,TX_BYTE_CNTR'length);
+-- elsif(MAC_TX_DATA2_VALID /= x"00") and (MAC_TX_EOF2 = '0') then
+-- simplify *081318
+ elsif(MAC_TX_DATA2_VALID(7) = '1') and (MAC_TX_EOF2 = '0') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(8,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_EOF2 = '1') then
+ if(MAC_TX_DATA2_VALID(7) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(8,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(6) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(7,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(5) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(6,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(4) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(5,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(3) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(4,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(2) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(3,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(1) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(2,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(0) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(1,TX_BYTE_CNTR'length);
+ --else
+ -- illegal
+ end if;
+ end if;
+ end if;
+end process;
+
+-- padding
+TX_PADDING_002: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= (others => '0');
+ MAC_TX_EOF3 <= '0';
+ elsif (MAC_TX_CONFIG(0) = '0') then
+ -- bit 0: (0) no short frame padding
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= MAC_TX_DATA2_VALID;
+ MAC_TX_EOF3 <= MAC_TX_EOF2;
+ elsif(MAC_TX_EOF2 = '1') then
+ -- bit 0: (1) Automatic padding of short frames. Requires that auto-CRC insertion be enabled too.
+ if (TX_BYTE_CNTR < 56) then
+ -- Minimum input frame size is 60 bytes
+ TX_FILL_NEXT <= '1';
+ TX_FILL_CNTR <= 56 - TX_BYTE_CNTR(5 downto 0);
+ MAC_TX_DATA3_VALID <= x"FF";
+ MAC_TX_EOF3 <= '0';
+ elsif (TX_BYTE_CNTR = 56) and (MAC_TX_DATA2_VALID(4) = '0') then -- *061119
+ -- min 60Bytes = 56+4
+ TX_FILL_NEXT <= '0';
+ MAC_TX_EOF3 <= '1';
+ MAC_TX_DATA3_VALID <= x"0F";
+ else
+ -- case 61-64 bytes
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= MAC_TX_DATA2_VALID;
+ MAC_TX_EOF3 <= '1';
+ end if;
+ elsif(TX_FILL_NEXT = '1') then
+ if(TX_FILL_CNTR <= 8) then
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= x"0F";
+ MAC_TX_EOF3 <= '1';
+ else
+ TX_FILL_CNTR <= TX_FILL_CNTR - 8;
+ MAC_TX_DATA3_VALID <= x"FF";
+ MAC_TX_EOF3 <= '0';
+ end if;
+ else
+ MAC_TX_DATA3_VALID <= MAC_TX_DATA2_VALID;
+ MAC_TX_EOF3 <= '0';
+ TX_FILL_NEXT <= '0';
+ end if;
+ end if;
+end process;
+
+-- zero masked bytes
+TX_PADDING_003: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ MAC_TX_SOF3 <= MAC_TX_SOF2;
+
+ for I in 0 to 7 loop
+ if(MAC_TX_DATA2_VALID(I) = '1') then
+ MAC_TX_DATA3(8*I+7 downto 8*I) <= MAC_TX_DATA2(8*I+7 downto 8*I);
+ else
+ MAC_TX_DATA3(8*I+7 downto 8*I) <= x"00";
+ end if;
+ end loop;
+ end if;
+end process;
+
+--// TX 32-BIT CRC COMPUTATION -------------------------------------------------------
+-- 802.3 section 3.2.9:
+-- protected fields: payload data + optional pad + CRC (excludes preamble and start of frame sequence)
+
+-- The CRC32 component assumes the serial stream is packed into 64-bit words MSb of MSB first.
+-- Since MAC_TX_DATA3 is packed LSb of LSB first, we need to re-order.
+-- Other reordering consideration: the CRC32 is computed with 'reflected' input bytes.
+-- In summary MSB <-> LSB
+REORDER_TX_CRC32_INPUT: process(MAC_TX_DATA3, MAC_TX_DATA3_VALID)
+begin
+ for I in 0 to 63 loop
+ TX_CRC_DATA_IN(I) <= MAC_TX_DATA3(63-I);
+ end loop;
+ for J in 0 to 7 loop
+ TX_CRC_DATA_VALID_IN(J) <= MAC_TX_DATA3_VALID(7-J);
+ end loop;
+end process;
+TX_CRC_SAMPLE_CLK_IN <= '1' when (MAC_TX_DATA3_VALID /= x"00") else '0';
+
+-- latency: 2 CLKs
+TX_CRC_001: CRC32 PORT MAP (
+ CLK => CLK156g,
+ DATA_IN => TX_CRC_DATA_IN,
+ SOF_IN => MAC_TX_SOF3,
+ SAMPLE_CLK_IN => TX_CRC_SAMPLE_CLK_IN,
+ DATA_VALID_IN => TX_CRC_DATA_VALID_IN,
+ CRC_INITIALIZATION => x"FFFFFFFF",
+ CRC_OUT => TX_CRC32,
+ SAMPLE_CLK_OUT => TX_CRC_SAMPLE_CLK_OUT
+ );
+
+-- flip LSb<->MSb and invert
+TX_CRC32_002: process(TX_CRC32)
+begin
+ for I in 0 to 31 loop
+ TX_CRC32_FLIPPED_INV(I) <= not TX_CRC32(31 - I);
+ end loop;
+end process;
+
+--//-- XGMII TX INTERFACE --------------------------------
+-- when user inserts the CRC
+TX_XGMII_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') or (MAC_TX_CONFIG(1) = '1') then
+ XGMII_TXD0 <= x"0707070707070707";
+ XGMII_TXC0 <= x"FF";
+ elsif(MAC_TX_SOF3 = '1') then
+ -- insert start + preamble
+ XGMII_TXD0 <= x"D5555555555555FB";
+ XGMII_TXC0 <= x"01";
+ elsif(MAC_TX_EOF3_D = '1') then
+ -- user supplies CRC
+ case MAC_TX_DATA3_VALID_D is
+ when x"01" =>
+ XGMII_TXD0 <= x"070707070707FD" & MAC_TX_DATA3_D(7 downto 0);
+ XGMII_TXC0 <= x"FE";
+ XGMII_TXD0_NEXT <= x"0707070707070707";
+ XGMII_TXC0_NEXT <= x"FF";
+ when x"03" =>
+ XGMII_TXD0 <= x"0707070707FD" & MAC_TX_DATA3_D(15 downto 0);
+ XGMII_TXC0 <= x"FC";
+ XGMII_TXD0_NEXT <= x"0707070707070707";
+ XGMII_TXC0_NEXT <= x"FF";
+ when x"07" =>
+ XGMII_TXD0 <= x"07070707FD" & MAC_TX_DATA3_D(23 downto 0);
+ XGMII_TXC0 <= x"F8";
+ XGMII_TXD0_NEXT <= x"0707070707070707";
+ XGMII_TXC0_NEXT <= x"FF";
+ when x"0F" =>
+ XGMII_TXD0 <= x"070707FD" & MAC_TX_DATA3_D(31 downto 0);
+ XGMII_TXC0 <= x"F0";
+ XGMII_TXD0_NEXT <= x"0707070707070707";
+ XGMII_TXC0_NEXT <= x"FF";
+ when x"1F" =>
+ XGMII_TXD0 <= x"0707FD" & MAC_TX_DATA3_D(39 downto 0);
+ XGMII_TXC0 <= x"E0";
+ XGMII_TXD0_NEXT <= x"0707070707070707";
+ XGMII_TXC0_NEXT <= x"FF";
+ when x"3F" =>
+ XGMII_TXD0 <= x"07FD" & MAC_TX_DATA3_D(47 downto 0);
+ XGMII_TXC0 <= x"C0";
+ XGMII_TXD0_NEXT <= x"0707070707070707";
+ XGMII_TXC0_NEXT <= x"FF";
+ when x"7F" =>
+ XGMII_TXD0 <= x"FD" & MAC_TX_DATA3_D(55 downto 0);
+ XGMII_TXC0 <= x"80";
+ XGMII_TXD0_NEXT <= x"0707070707070707";
+ XGMII_TXC0_NEXT <= x"FF";
+ when x"FF" =>
+ XGMII_TXD0 <= MAC_TX_DATA3_D(63 downto 0);
+ XGMII_TXC0 <= x"00";
+ XGMII_TXD0_NEXT <= x"07070707070707FD";
+ XGMII_TXC0_NEXT <= x"FF";
+ when others => null;
+ end case;
+ elsif(MAC_TX_EOF3_D2 = '1') then
+ XGMII_TXD0 <= XGMII_TXD0_NEXT;
+ XGMII_TXC0 <= XGMII_TXC0_NEXT;
+ elsif(MAC_TX_DATA3_VALID_D = x"FF") then
+ XGMII_TXD0 <= MAC_TX_DATA3_D;
+ XGMII_TXC0 <= x"00";
+ else
+ XGMII_TXD0 <= x"0707070707070707"; -- idle
+ XGMII_TXC0 <= x"FF";
+ end if;
+ end if;
+end process;
+
+-- when the CRC is inserted automatically
+TX_XGMII_002: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ MAC_TX_DATA3_VALID_D <= MAC_TX_DATA3_VALID;
+ MAC_TX_DATA3_VALID_D2 <= MAC_TX_DATA3_VALID_D;
+ MAC_TX_DATA3_D <= MAC_TX_DATA3;
+ MAC_TX_DATA3_D2 <= MAC_TX_DATA3_D;
+ MAC_TX_SOF3_D <= MAC_TX_SOF3;
+ MAC_TX_EOF3_D <= MAC_TX_EOF3;
+ MAC_TX_EOF3_D2 <= MAC_TX_EOF3_D;
+ MAC_TX_EOF3_D3 <= MAC_TX_EOF3_D2;
+
+ if (SYNC_RESET156 = '1') then
+ XGMII_TXD <= x"0707070707070707";
+ XGMII_TXC <= x"FF";
+ elsif(MAC_TX_CONFIG(1) = '0') then
+ -- user inserts the CRC
+ XGMII_TXD <= XGMII_TXD0;
+ XGMII_TXC <= XGMII_TXC0;
+ elsif(MAC_TX_SOF3_D = '1') then
+ -- insert start + preamble
+ -- user enabled auto-CRC32 insertion. Start inserting CRC
+ XGMII_TXD <= x"D5555555555555FB";
+ XGMII_TXC <= x"01";
+ elsif(MAC_TX_EOF3_D2 = '1') then
+ case MAC_TX_DATA3_VALID_D2 is
+ when x"01" =>
+ XGMII_TXD <= x"0707FD" & TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D2(7 downto 0);
+ XGMII_TXC <= x"E0";
+ XGMII_TXD_NEXT <= x"0707070707070707";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"03" =>
+ XGMII_TXD <= x"07FD" & TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D2(15 downto 0);
+ XGMII_TXC <= x"C0";
+ XGMII_TXD_NEXT <= x"0707070707070707";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"07" =>
+ XGMII_TXD <= x"FD" & TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D2(23 downto 0);
+ XGMII_TXC <= x"80";
+ XGMII_TXD_NEXT <= x"0707070707070707";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"0F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D2(31 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"07070707070707FD";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"1F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV(23 downto 0) & MAC_TX_DATA3_D2(39 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"070707070707FD" & TX_CRC32_FLIPPED_INV(31 downto 24);
+ XGMII_TXC_NEXT <= x"FE";
+ when x"3F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV(15 downto 0) & MAC_TX_DATA3_D2(47 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"0707070707FD" & TX_CRC32_FLIPPED_INV(31 downto 16);
+ XGMII_TXC_NEXT <= x"FC";
+ when x"7F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV(7 downto 0) & MAC_TX_DATA3_D2(55 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"07070707FD" & TX_CRC32_FLIPPED_INV(31 downto 8);
+ XGMII_TXC_NEXT <= x"F8";
+ when x"FF" =>
+ XGMII_TXD <= MAC_TX_DATA3_D2;
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"070707FD" & TX_CRC32_FLIPPED_INV;
+ XGMII_TXC_NEXT <= x"F0";
+ when others => null;
+ end case;
+ elsif(MAC_TX_EOF3_D3 = '1') then
+ XGMII_TXD <= XGMII_TXD_NEXT;
+ XGMII_TXC <= XGMII_TXC_NEXT;
+ elsif(MAC_TX_DATA3_VALID_D2 = x"FF") then
+ XGMII_TXD <= MAC_TX_DATA3_D2;
+ XGMII_TXC <= x"00";
+ else
+ XGMII_TXD <= x"0707070707070707"; -- idle
+ XGMII_TXC <= x"FF";
+ end if;
+ end if;
+end process;
+
+TX_XGMII_003: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(MAC_TX_EOF3_D2 = '1') then
+ N_TX_FRAMES_local <= N_TX_FRAMES_local + 1;
+ end if;
+ end if;
+end process;
+N_TX_FRAMES <= std_logic_vector(N_TX_FRAMES_local);
+
+
+----//-- TX FLOW CONTROL --------------------------------
+---- ask for more input data if there is room for at least 1K more input bytes
+---- Never write past the last confirmed read pointer location.
+--
+---- read the last confirmed read pointer location and reclock in CLK domain when stable
+--MAC_TX_CTS_001: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- TX_SUCCESS_TOGGLE_D <= '0';
+-- TX_SUCCESS_TOGGLE_D2 <= '0';
+-- MAC_TX_RPTR_CONFIRMED_D <= (others => '1');
+-- else
+-- TX_SUCCESS_TOGGLE_D <= TX_SUCCESS_TOGGLE;
+-- TX_SUCCESS_TOGGLE_D2 <= TX_SUCCESS_TOGGLE_D;
+-- if(TX_SUCCESS_TOGGLE_D2 /= TX_SUCCESS_TOGGLE_D) then
+-- -- shortly after successful packet transmission.
+-- MAC_TX_RPTR_CONFIRMED_D <= MAC_TX_RPTR_CONFIRMED;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--
+---- Compute available room for more tx data
+--MAC_TX_CTS_002: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- MAC_TX_BUF_FREE <= (others => '0');
+-- else
+-- MAC_TX_BUF_FREE <= not (MAC_TX_WPTR_D2 + not MAC_TX_RPTR_CONFIRMED_D);
+-- end if;
+-- end if;
+--end process;
+--
+---- Is there enough room for a complete max size frame?
+---- Don't cut it too close because user interface can flood the buffer very quickly (CLK @ 125 MHz clock)
+---- while we compute the buffer size with the possibly much slower RX_CLG (could be 2.5 MHz for 10Mbps).
+--MAC_TX_CTS_003: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- MAC_TX_CTS_local <= '0'; -- reset
+-- elsif(LINK_STATUS_local = '0') then
+-- -- don't ask the stack for data if there is no link
+-- MAC_TX_CTS_local <= '0'; -- reset
+-- elsif(MAC_TX_BUF_FREE(11) = '0') then
+-- -- room for less than 2KB. Activate flow control
+-- MAC_TX_CTS_local <= '0';
+-- else
+-- MAC_TX_CTS_local <= '1';
+-- end if;
+-- end if;
+--end process;
+--MAC_TX_CTS <= MAC_TX_CTS_local;
+--
+--
+---- manage read pointer
+--MAC_TX_RPTR_001: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if(SYNC_RESETTX = '1') then
+-- MAC_TX_RPTR <= (others => '1');
+-- MAC_TX_RPTR_D <= (others => '1');
+-- else
+-- MAC_TX_RPTR_D <= MAC_TX_RPTR;
+--
+-- if(SYNC_RESETRX = '1') then
+-- MAC_TX_RPTR <= (others => '1');
+-- elsif(TX_STATE = 1) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(2 downto 0) <= 1) then
+-- -- read the first byte(s) in advance (need 2 RX_CLKG to get the data out)
+-- -- Note: we may temporarily read past the write pointer (by one location)
+-- -- but will rewind immediately thereafter
+-- MAC_TX_RPTR <= MAC_TX_RPTR + 1;
+-- elsif(TX_STATE = 2) and (TX_EVENT3 = '1') then
+-- -- we are done reading the packet. rewind the read pointer, as we went past the end of packet.
+-- MAC_TX_RPTR <= MAC_TX_RPTR - 1;
+-- elsif(TX_STATE = 2) and (TX_BYTE_CLK = '1') then
+-- -- read the rest of the packet
+-- -- forward data from input elastic buffer to RGMII interface
+-- -- Note: we may temporarily read past the write pointer (by one location)
+-- -- but will rewind immediately thereafter
+-- MAC_TX_RPTR <= MAC_TX_RPTR + 1;
+-- elsif(TX_STATE = 6) then
+-- -- collision detected. rewind read pointer to the start of frame.
+-- MAC_TX_RPTR <= MAC_TX_RPTR_CONFIRMED;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--
+---- update confirmed read pointer after successful frame transmission
+--MAC_TX_RPTR_002: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if(SYNC_RESETTX = '1') then
+-- MAC_TX_RPTR_CONFIRMED <= (others => '1');
+-- TX_SUCCESS_TOGGLE <= '0';
+-- elsif(TX_SUCCESS = '1') then
+-- MAC_TX_RPTR_CONFIRMED <= MAC_TX_RPTR;
+-- TX_SUCCESS_TOGGLE <= not TX_SUCCESS_TOGGLE;
+-- end if;
+-- end if;
+--end process;
+--
+---- How many COMPLETE tx frames are available for transmission in the input elastic buffer?
+---- Transmission is triggered by the availability of a COMPLETE frame in the buffer (not just a few frame bytes)
+---- It is therefore important to keep track of the number of complete frames.
+---- At the elastic buffer input, a new complete frame is detected upon receiving the EOF pulse.
+--COMPLETE_TX_FRAMES_001: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- MAC_TX_EOF_TOGGLE <= '0';
+-- elsif(MAC_TX_DATA_VALID = '1') and (MAC_TX_EOF = '1') then
+-- MAC_TX_EOF_TOGGLE <= not MAC_TX_EOF_TOGGLE; -- Need toggle signal to generate copy in RX_CLKG clock domain
+-- end if;
+-- end if;
+--end process;
+--
+--
+--COMPLETE_TX_FRAMES_002: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if(SYNC_RESETTX = '1') then
+-- MAC_TX_EOF_TOGGLE_D <= '0';
+-- MAC_TX_EOF_TOGGLE_D2 <= '0';
+-- COMPLETE_TX_FRAMES_INBUF <= (others => '0');
+-- else
+-- MAC_TX_EOF_TOGGLE_D <= MAC_TX_EOF_TOGGLE; -- reclock in TX_CLKG clock domain (to prevent glitches)
+-- MAC_TX_EOF_TOGGLE_D2 <= MAC_TX_EOF_TOGGLE_D;
+--
+-- if(MAC_TX_EOF_TOGGLE_D2 /= MAC_TX_EOF_TOGGLE_D) and (TX_SUCCESS = '0') then
+-- -- just added another complete frame into the tx buffer (while no successful transmission concurrently)
+-- COMPLETE_TX_FRAMES_INBUF <= COMPLETE_TX_FRAMES_INBUF + 1;
+-- elsif(MAC_TX_EOF_TOGGLE_D2 = MAC_TX_EOF_TOGGLE_D) and (TX_SUCCESS = '1')
+-- and (ATLEAST1_COMPLETE_TX_FRAME_INBUF = '1') then
+-- -- a frame was successfully transmitted (and none was added at the very same instant)
+-- COMPLETE_TX_FRAMES_INBUF <= COMPLETE_TX_FRAMES_INBUF - 1;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--
+---- Flag to indicate at least one complete tx frame in buffer.
+--ATLEAST1_COMPLETE_TX_FRAME_INBUF <= '0' when (COMPLETE_TX_FRAMES_INBUF = 0) else '1';
+--
+--
+--
+--
+----// MAC TX STATE MACHINE ----------------------------------------------------------
+--
+--
+---- 96-bit InterPacketGap (Interframe Delay) timer
+--IPG_001: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if (SYNC_RESETRX = '1') then
+-- IPG_CNTR <= (others => '0');
+-- CRS_D <= '0';
+-- else
+-- CRS_D <= CRS; -- reclock with TX_CLKG
+--
+-- -- or carrier extension in progress
+-- -- Arm InterPacketGap timer
+-- IPG_CNTR <= x"0C" ; -- 96 bits = 12 bytes 802.3 section 4.4.2
+-- elsif(IPG_CNTR > 0) and (TX_BYTE_CLK = '1') then
+-- -- after end of passing packet, decrement counter downto to zero (InterPacketGap).
+-- IPG_CNTR <= IPG_CNTR - 1;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--IPG <= '1' when (IPG_CNTR = 0) else '0'; -- '1' last passing packet was more than InterPacketGap ago. OK to start tx.
+--
+---- Events ------------------------
+---- First tx packet trigger
+--TX_EVENT1 <= '0' when (ATLEAST1_COMPLETE_TX_FRAME_INBUF = '0') else -- no COMPLETE frame in tx input buffer
+-- '0' when (MAC_TX_BUF_SIZE = 0) else -- no data in tx input buffer
+-- '0' when (IPG = '0') else -- medium is not clear. need to wait after the InterPacketGap. Deferring on.
+-- '0' when (TX_SUCCESS = '1') else -- don't act too quickly. It takes one RX_CLKG to update the complete_tx_frame_inbuf counter.
+-- '0' when (PHY_IF_WRAPPER_RESET = '1') else -- PHY/RGMII wrapper are being reset. Do not start tx.
+-- TX_BYTE_CLK; -- go ahead..start transmitting. align event pulse with TX_BYTE_CLK
+--
+--
+--
+---- Tx state machine ------------------------
+--TX_STATE_GEN_001: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if (SYNC_RESETTX = '1') or (LINK_STATUS_local = '0') then
+-- TX_STATE <= 0; -- idle state
+-- TX_SUCCESS <= '0';
+-- TX_BYTE_CLK_D <= '0';
+-- RETX_ATTEMPT_COUNTER <= (Others => '0'); -- re-transmission attempts counter
+-- else
+--
+-- TX_BYTE_CLK_D <= TX_BYTE_CLK; -- output byte ready one RX_CLKG later
+--
+-- if(TX_STATE = 0) then
+-- TX_SUCCESS <= '0';
+-- RETX_ATTEMPT_COUNTER <= (Others => '0'); -- reset re-transmission attempts counter
+-- if (TX_EVENT1 = '1') then
+-- -- start tx packet: send 1st byte of preamble
+-- TX_STATE <= 1;
+-- TX_BYTE_COUNTER2 <= "111"; -- 8-byte preamble + start of frame sequence
+-- end if;
+-- elsif(TX_STATE = 1) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(2 downto 0) /= 0) then
+-- -- counting through the preamble + start frame sequence
+-- TX_BYTE_COUNTER2 <= TX_BYTE_COUNTER2 - 1;
+-- elsif(TX_STATE = 1) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(2 downto 0) = 0) then
+-- -- end of preamble. start forwarding data from elastic buffer to RGMII wrapper
+-- TX_STATE <= 2;
+-- TX_BYTE_COUNTER <= (others => '0');
+-- elsif(TX_STATE = 2) and (TX_BYTE_CLK = '1') and (TX_EVENT3 = '0') then
+-- -- keep track of the payload byte count (to detect the need for padding)
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- elsif(TX_STATE = 2) and (TX_BYTE_CLK = '1') and (TX_EVENT3 = '1') then
+-- -- found end of frame
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- if (TX_BYTE_COUNTER(10 downto 0) < 59) then
+-- if (MAC_TX_CONFIG(1 downto 0) = "11") then
+-- -- frame is too short: payload data does not meet minimum 60-byte size.
+-- -- user enabled automatic padding and automatic CRC32 insertion
+-- TX_STATE <= 3;
+-- else
+-- -- error: frame is too short. abort.
+-- TX_STATE <= 10;
+-- end if;
+-- elsif (TX_BYTE_COUNTER(10 downto 0) >= 63) then
+-- -- complete packet (including user-supplied CRC)
+-- else
+-- -- we are done here
+-- TX_STATE <= 0;
+-- TX_SUCCESS <= '1'; -- completed frame transmission
+-- end if;
+-- else
+-- -- error. frame is too short (< 64 bytes including 4-byte CRC). abort.
+-- TX_STATE <= 10;
+-- end if;
+-- elsif(TX_STATE = 3) and (TX_BYTE_CLK = '1') then
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- if(TX_BYTE_COUNTER(10 downto 0) < 59) then
+-- -- padding payload field to the minimum size.
+-- -- keep track of the byte count
+-- else
+-- -- error. Illegal user configuration. auto-pad requires auto-CRC. abort.
+-- TX_STATE <= 10;
+-- end if;
+-- elsif(TX_STATE = 4) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) /= 0) then
+-- -- counting through the CRC/FCS sequence
+-- TX_BYTE_COUNTER2 <= TX_BYTE_COUNTER2 - 1;
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- elsif(TX_STATE = 4) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) = 0) then
+-- -- end of CRC/FCS. Packet is now complete.
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- else
+-- -- we are done here
+-- TX_STATE <= 0;
+-- TX_SUCCESS <= '1'; -- completed frame transmission
+-- end if;
+-- elsif(TX_STATE = 5) and (TX_BYTE_CLK = '1') then
+-- -- Carrier extension
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- if(TX_BYTE_COUNTER(10 downto 0) >= 511) then
+-- -- met slotTime requirement.
+-- TX_STATE <= 0;
+-- TX_SUCCESS <= '1'; -- completed frame transmission
+-- end if;
+-- elsif(TX_STATE = 6) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) /= 0) then
+-- -- Jam . counting through the 4-byte jam
+-- TX_BYTE_COUNTER2 <= TX_BYTE_COUNTER2 - 1;
+-- elsif(TX_STATE = 6) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) = 0) then
+-- -- end of Jam
+--
+--
+--TX_ER <= '1' when (TX_STATE = 5) else -- carrier extension
+-- '0';
+--
+--
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-- test code to send a pre-stored frame
+--TEST_XGMII_TX_001: TEST_XGMII_TX PORT MAP(
+-- CLK156g => CLK156g,
+-- SYNC_RESET156 => SYNC_RESET156,
+-- TX_TRIGGER => TX_TRIGGER,
+-- XGMII_TXD => XGMII_TXD,
+-- XGMII_TXC => XGMII_TXC,
+-- TP => TEST_XGMII_TX_TP
+--);
+
+--// MAC RX STATE MACHINE ----------------------------------------------------------
+-- delay XGMII_RXD one CLK while we search for special characters (start,terminate,error)
+RX_RECLOCK_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ XGMII_RXD_D <= XGMII_RXD;
+ end if;
+end process;
+
+-- detect start character (0xFB) and pinpoint its byte location within the 8-byte XGMII rx word
+-- There are two possible locations 0 and 4
+-- (see Xilinx PG053 "Internal 64-bit SDR client-side interface" p77)
+-- (see Altera UG-01080 7-12)
+XGMII_RX_START_CHAR_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(XGMII_RXC(0) = '1') and (XGMII_RXD(7 downto 0) = x"FB") then
+ XGMII_RX_START_CHAR <= '1';
+ XGMII_RX_START_LOC <= "000";
+ elsif(XGMII_RXC(4) = '1') and (XGMII_RXD(39 downto 32) = x"FB") then
+ XGMII_RX_START_CHAR <= '1';
+ XGMII_RX_START_LOC <= "100";
+ else
+ XGMII_RX_START_CHAR <= '0';
+ end if;
+ end if;
+end process;
+
+-- detect the first SFD character (0xD5) and pinpoint its byte location within the 8-byte XGMII rx word
+XGMII_RX_SFD_CHAR_001: process(CLK156g)
+variable SFD: std_logic := '0';
+variable SFD_LOC: unsigned(2 downto 0) := "000";
+begin
+ if rising_edge(CLK156g) then
+ SFD := '0';
+ for I in 0 to 7 loop
+ if(XGMII_RXC(I) = '0') and (XGMII_RXD(8*I+7 downto 8*I) = x"D5") and (SFD = '0') then
+ -- stop as soon as we found the character
+ SFD := '1';
+ SFD_LOC := to_unsigned(I,3);
+ end if;
+ end loop;
+ if(SFD = '1') and (RX_STATE /= 2) then
+ -- filter out xD5 characters in payload
+ XGMII_RX_SFD_LOC <= SFD_LOC;
+ XGMII_RX_SFD_CHAR <= '1';
+ else
+ XGMII_RX_SFD_CHAR <= '0';
+ end if;
+ end if;
+end process;
+
+-- detect terminate character and pinpoints its byte location within the 8-byte XGMII rx word
+XGMII_RX_TERMINATE_001: process(CLK156g)
+variable TERMINATE: std_logic := '0';
+variable TERMINATE_LOC: unsigned(2 downto 0) := "000";
+begin
+ if rising_edge(CLK156g) then
+ TERMINATE := '0';
+ for I in 0 to 7 loop
+ if(XGMII_RXC(I) = '1') and (XGMII_RXD(8*I+7 downto 8*I) = x"FD") and (TERMINATE = '0') then
+ -- stop as soon as we found the character
+ TERMINATE := '1';
+ TERMINATE_LOC := to_unsigned(I,3);
+ end if;
+ end loop;
+ XGMII_RX_TERM_CHAR <= TERMINATE;
+ XGMII_RX_TERM_LOC <= TERMINATE_LOC;
+ end if;
+end process;
+
+-- detect error character
+XGMII_RX_ERROR_001: process(CLK156g)
+variable ERROR: std_logic := '0';
+begin
+ if rising_edge(CLK156g) then
+ ERROR := '0';
+ for I in 0 to 7 loop
+ if(XGMII_RXC(I) = '1') and (XGMII_RXD(8*I+7 downto 8*I) = x"FE") then
+ ERROR := '1';
+ end if;
+ end loop;
+ XGMII_RX_ERROR_CHAR <= ERROR;
+ end if;
+end process;
+
+
+-- delineate a frame using a state machine
+XGMII_RX_STATE_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_IN_FRAME <= '0';
+ elsif(XGMII_RX_START_CHAR = '1') then
+ -- entering a frame
+ XGMII_RX_IN_FRAME <= '1';
+ elsif((XGMII_RX_TERM_CHAR = '1') or (XGMII_RX_ERROR_CHAR = '1')) then
+ XGMII_RX_IN_FRAME <= '0';
+ end if;
+ end if;
+end process;
+
+-- Assess the InterPacket Gap. Clamp at 255 bytes
+RX_IPG_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_IPG_local <= (others => '0');
+ RX_IPG <= (others => '0');
+ elsif (XGMII_RX_TERM_CHAR = '1') then
+ -- detected terminate character. Start counting IPG bytes and report previous IPG
+ if(RX_IPG_local(8) = '1') then
+ -- clamp at 255 bytes
+ RX_IPG <= x"FF";
+ else
+ RX_IPG <= std_logic_vector(RX_IPG_local(7 downto 0));
+ end if;
+ if(XGMII_RX_START_CHAR = '0') then
+ -- start and terminate characters are not in the same word
+ RX_IPG_local <= resize(not XGMII_RX_TERM_LOC, RX_IPG_local'length);
+ elsif(XGMII_RX_TERM_LOC < XGMII_RX_START_LOC) then
+ -- start and terminate characters are in the same word, and start follows terminate as expected
+ RX_IPG_local <= resize(XGMII_RX_START_LOC - XGMII_RX_TERM_LOC,RX_IPG_local'length);
+ else
+ -- really really short frame. ignore
+ end if;
+ elsif (XGMII_RX_START_CHAR = '0') then
+ if(XGMII_RXC = x"FF") and (RX_IPG_local(8) = '0') then -- clamp at 255 bytes
+ RX_IPG_local <= RX_IPG_local + to_unsigned(8,RX_IPG_local'length);
+ end if;
+ else
+ -- detected start character. Finalize IPG byte count and report.
+ if (RX_IPG_local(8) = '0') then -- clamp at 255 bytes
+ RX_IPG_local <= RX_IPG_local + resize(XGMII_RX_START_LOC,RX_IPG_local'length);
+ end if;
+ end if;
+ end if;
+end process;
+
+-- Rx state machine ------------------------
+-- states:
+-- 0 idle
+-- 1 received start character, awaiting start of frame delimiter (SFD)
+-- 2 received SFD, receiving data
+--
+-- Keeps track of the received bytes and words.
+-- RX_BYTE_CNTR should be read when RX_SAMPLE1_CLK = '1'
+-- It also represents the word count in fixed point format 10.3
+-- For example RX_BYTE_CNTR = "0000000011.001" marks the third word with one extra byte waiting in cache
+RX_STATE_GEN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ RX_STATE2_D <= RX_STATE2;
+
+ if (SYNC_RESET156 = '1') then
+ RX_STATE <= 0;
+ RX_BYTE_CNTR <= (others => '0');
+ elsif(RX_STATE2 = '0') and (XGMII_RX_TERM_CHAR = '1') then
+ -- defensive code: back to idle
+ RX_STATE <= 0;
+ elsif(XGMII_RX_START_CHAR = '1') then
+ -- SFD may be in the same word or in the next
+ if(XGMII_RX_SFD_CHAR = '1') then
+ -- both start character and SFD byte in the same word. Start counting rx bytes
+ RX_STATE <= 2;
+-- RX_BYTE_CNTR <= resize(not XGMII_RX_SFD_LOC, RX_BYTE_CNTR'length); -- always 0
+ RX_BYTE_CNTR <= (others => '0');
+ else
+ RX_STATE <= 1; -- awaiting SFD byte in the next word
+ end if;
+ elsif(RX_STATE = 1) then
+ if(XGMII_RX_SFD_CHAR = '1') then
+ -- received both start and SFD bytes. Start counting rx bytes
+ RX_STATE <= 2;
+ -- RX_BYTE_CNTR <= resize(not XGMII_RX_SFD_LOC, RX_BYTE_CNTR'length); -- always 4
+ RX_BYTE_CNTR <= (2 => '1', others => '0');
+ else
+ -- something wrong (SFD always follows START character) Error. Back to idle
+ RX_STATE <= 0;
+ end if;
+ elsif(RX_STATE2 = '1') then
+ if(XGMII_RX_TERM_CHAR = '0') then
+ RX_BYTE_CNTR <= RX_BYTE_CNTR + to_unsigned(8,RX_BYTE_CNTR'length);
+ else
+ RX_BYTE_CNTR <= RX_BYTE_CNTR_FINAL;
+ RX_STATE <= 0; -- back to idle
+ end if;
+ end if;
+ end if;
+end process;
+RX_WORD_CNTR <= RX_BYTE_CNTR(RX_BYTE_CNTR'left downto 3); -- int(byte counter/8)
+RX_BYTE_CNTR_FINAL <= RX_BYTE_CNTR + resize(XGMII_RX_TERM_LOC, RX_BYTE_CNTR'length);
+ -- read when XGMII_RX_TERM_CHAR = '1'
+
+
+-- Assess whether rx frame is too short (<64 Bytes)
+RX_TOO_SHORT_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') or (XGMII_RX_START_CHAR = '1') then
+ RX_TOO_SHORT <= '0';
+ elsif (XGMII_RX_TERM_CHAR = '1') then
+ -- end of frame
+ if(RX_STATE /= 2) or (RX_BYTE_CNTR_FINAL < 64)then
+ -- end of frame before the data field, or
+ -- less than 64 bytes
+ RX_TOO_SHORT <= '1';
+ else
+ RX_TOO_SHORT <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+-- Assess whether rx frame is too long (>1500 payload bytes or >9000 payload bytes when jumbo frames allowed)
+-- Add MAC addresses, CRC32, ethertype/length, and 802.1Q tag to payload length.
+RX_TOO_LONG_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') or (XGMII_RX_START_CHAR = '1') then
+ RX_TOO_LONG <= '0';
+ elsif (XGMII_RX_TERM_CHAR = '1') and (MAC_RX_CONFIG(4) = '1') then
+ -- Detect payload frames longer than the user-specified MTU size
+ -- at end of frame
+ if(RX_VLAN = '0') and (RX_BYTE_CNTR_FINAL > RX_MTU+18) then
+ RX_TOO_LONG <= '1';
+ elsif(RX_VLAN = '1') and (RX_BYTE_CNTR_FINAL > RX_MTU+22) then
+ RX_TOO_LONG <= '1';
+ else
+ RX_TOO_LONG <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+-- realign bytes starting at the destination address, immediately after the SFD.
+-- Discard the preamble
+RX_ALIGN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ XGMII_RX_SAMPLE1_CLK_D <= XGMII_RX_SAMPLE1_CLK;
+ XGMII_RX_DATA1_VALID_D <= XGMII_RX_DATA1_VALID;
+ XGMII_RX_DATA1_D <= XGMII_RX_DATA1;
+
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_FLUSH <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ XGMII_RX_DATA1 <= (others => '0');
+ elsif(XGMII_RX_SFD_CHAR = '1') then
+ -- save 0 or 4 bytes in cache XGMII_RX_DATA1A until we have a full 8-byte word
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_FLUSH <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ if(XGMII_RX_SFD_LOC = "011") then
+ XGMII_RX_DATA1A <= XGMII_RXD_D(63 downto 32);
+ end if;
+ elsif(RX_STATE2 = '1') then
+ if(XGMII_RX_TERM_CHAR = '0') then
+ -- 8 more Bytes
+ XGMII_RX_FLUSH <= '0';
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ XGMII_RX_DATA1_VALID <= x"FF";
+ elsif(XGMII_RX_SFD_LOC = "111") then
+ -- terminate character detected. No data in cache.
+ XGMII_RX_FLUSH <= '0';
+ -- received terminate character: received less than 8 bytes and no data in XGMII_RX_DATA1A cache
+ case XGMII_RX_TERM_LOC(2 downto 0) is
+ when "001" => XGMII_RX_DATA1_VALID <= x"01";
+ when "010" => XGMII_RX_DATA1_VALID <= x"03";
+ when "011" => XGMII_RX_DATA1_VALID <= x"07";
+ when "100" => XGMII_RX_DATA1_VALID <= x"0F";
+ when "101" => XGMII_RX_DATA1_VALID <= x"1F";
+ when "110" => XGMII_RX_DATA1_VALID <= x"3F";
+ when "111" => XGMII_RX_DATA1_VALID <= x"7F";
+ when others => XGMII_RX_DATA1_VALID <= x"00";
+ end case;
+ if(XGMII_RX_TERM_LOC = "000") then
+ -- no new data, no data in cache
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ else
+ -- new data, no data in cache
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ end if;
+ else
+ -- received terminate character: received less than 8 bytes and 4 Bytes data in cache.
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ case XGMII_RX_TERM_LOC(2 downto 0) is
+ when "000" => XGMII_RX_DATA1_VALID <= x"0F";
+ when "001" => XGMII_RX_DATA1_VALID <= x"1F";
+ when "010" => XGMII_RX_DATA1_VALID <= x"3F";
+ when "011" => XGMII_RX_DATA1_VALID <= x"7F";
+ when others => XGMII_RX_DATA1_VALID <= x"FF";
+ end case;
+ if(unsigned(XGMII_RX_TERM_LOC) < 5) then
+ -- 4 Bytes or less of new data + 4 Bytes in cache
+ XGMII_RX_FLUSH <= '0';
+ else
+ -- 5 Bytes or more of new data + 4 Bytes in cache
+ -- need an additional flush cycle for remaining bytes
+ XGMII_RX_FLUSH <= '1';
+ end if;
+ end if;
+
+ -- SFD is located only at locations 3 or 7
+ -- Note: some bytes will be masked if a terminate character is received (see process below)
+ -- In this case, we don't even try to zero these meaningless bytes
+ if(XGMII_RX_SFD_LOC = "011") then
+ XGMII_RX_DATA1(31 downto 0) <= XGMII_RX_DATA1A;
+ XGMII_RX_DATA1(63 downto 32) <= XGMII_RXD_D(31 downto 0);
+ XGMII_RX_DATA1A(31 downto 0) <= XGMII_RXD_D(63 downto 32);
+ else
+ XGMII_RX_DATA1(63 downto 0) <= XGMII_RXD_D(63 downto 0);
+ end if;
+ elsif(XGMII_RX_FLUSH = '1') then
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ XGMII_RX_DATA1 <= x"00000000" & XGMII_RX_DATA1A;
+ XGMII_RX_FLUSH <= '0';
+ -- flush remaining bytes in XGMII_RX_DATA1A cache
+ --case RX_BYTE_CNTR_FINAL(2 downto 0) is -- original code before rev1 bug correction
+ case RX_BYTE_CNTR(2 downto 0) is -- *042519 BR
+ when "001" => XGMII_RX_DATA1_VALID <= x"01";
+ when "010" => XGMII_RX_DATA1_VALID <= x"03";
+ when "011" => XGMII_RX_DATA1_VALID <= x"07";
+ when others => XGMII_RX_DATA1_VALID <= x"00";
+ end case;
+ else
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ end if;
+ end if;
+end process;
+
+-- generate start of frame
+-- mark the XGMII_RX_SOF1 (1st word, contains destination MAC address + partial source address )
+RX_STATE2 <= '1' when (RX_STATE = 2) else '0';
+XGMII_RX_SOF1_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ -- the first received word with start character does not have enough data bytes to fill the 8-byte XGMII_RX_DATA1,
+ -- but the next word certainly has
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_SOF1 <= '0';
+ elsif(RX_STATE2 = '1') and (RX_STATE2_D = '0') then
+ XGMII_RX_SOF1 <= '1';
+ else
+ XGMII_RX_SOF1 <= '0';
+ end if;
+ XGMII_RX_SOF1_D <= XGMII_RX_SOF1;
+ XGMII_RX_SOF1_D2 <= XGMII_RX_SOF1_D;
+-- collect first few words of first failed CRC frame (compare with Wireshark)
+-- if(XGMII_RX_SOF1 = '1') and (FIRST_RXCRCERROR_FLAG = '0') then
+-- DEBUG1 <= XGMII_RX_DATA1;
+-- end if;
+-- if(XGMII_RX_SOF1_D = '1') and (FIRST_RXCRCERROR_FLAG = '0') then
+-- DEBUG2 <= XGMII_RX_DATA1;
+-- end if;
+-- if(XGMII_RX_SOF1_D2 = '1') and (FIRST_RXCRCERROR_FLAG = '0') then
+-- DEBUG3 <= XGMII_RX_DATA1;
+-- end if;
+
+ end if;
+end process;
+
+-- mark the XGMII_RX_EOF1 (last word, may be partially filled: see XGMII_RX_FRAME_SIZE(2 downto 0))
+XGMII_RX_EOF1_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ XGMII_RX_EOF1_D <= XGMII_RX_EOF1;
+
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_EOF1A <= '0';
+ elsif(RX_STATE2 = '1') and (XGMII_RX_TERM_CHAR = '1') then
+ if (XGMII_RX_SFD_LOC = "111") then
+ -- terminate character detected, no data in cache
+ if(XGMII_RX_TERM_LOC = "000") then
+ -- no new data, no data in cache (immediate EOF, see addendum below this process)
+ XGMII_RX_EOF1A <= '0';
+ else
+ -- new data, no data in cache
+ XGMII_RX_EOF1A <= '1';
+ end if;
+ else
+ -- received terminate character: received less than 8 bytes and 4 Bytes data in cache.
+ if(unsigned(XGMII_RX_TERM_LOC) < 5) then
+ -- 4 Bytes or less of new data + 4 Bytes in cache
+ XGMII_RX_EOF1A <= '1';
+ else
+ -- 5 Bytes or more of new data + 4 Bytes in cache
+ -- need an additional flush cycle for remaining bytes
+ XGMII_RX_EOF1A <= '0';
+ end if;
+ end if;
+ elsif(XGMII_RX_FLUSH = '1') then
+ -- flush remaining bytes in XGMII_RX_DATA1A cache
+ XGMII_RX_EOF1A <= '1';
+ else
+ XGMII_RX_EOF1A <= '0';
+ end if;
+ end if;
+end process;
+
+XGMII_RX_EOF1 <=
+ '1' when (RX_STATE = 2) and (XGMII_RX_TERM_CHAR = '1') and (XGMII_RX_TERM_LOC = "000") else
+ XGMII_RX_EOF1A;
+
+
+
+-- Destination address check
+MAC_ADDR_REORDER <= MAC_ADDR(7 downto 0) & MAC_ADDR(15 downto 8) &
+ MAC_ADDR(23 downto 16) & MAC_ADDR(31 downto 24) &
+ MAC_ADDR(39 downto 32) & MAC_ADDR(47 downto 40);
+ -- reorder the bytes, as the XGMII interface packs first byte as LSB
+ADDR_CHECK_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_VALID_ADDR <= '0';
+ elsif(MAC_RX_CONFIG(0) = '1') then
+ -- promiscuous mode. No destination address check
+ RX_VALID_ADDR <= '1';
+ elsif(XGMII_RX_SOF1 = '1') then
+ -- 1st word. Check address in Bytes 5:0
+ if(XGMII_RX_DATA1(47 downto 0) = MAC_ADDR_REORDER) then
+ -- destination address matches
+ RX_VALID_ADDR <= '1';
+ elsif (XGMII_RX_DATA1(47 downto 0) = x"FFFFFFFFFFFF") and (MAC_RX_CONFIG(1) = '1') then
+ -- accepts broadcast packets with the broadcast destination address FF:FF:FF:FF:FF:FF.
+ RX_VALID_ADDR <= '1';
+ elsif (XGMII_RX_DATA1(0) = '1') and (MAC_RX_CONFIG(2) = '1') then
+ -- accept multicast packets with the multicast bit set in the destination address.
+ -- '1' in the LSb of the first address byte.
+ RX_VALID_ADDR <= '1';
+ else
+ RX_VALID_ADDR <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+
+--//-- RX ETHERNET FRAME PARSING ---------------------------
+-- IEEE 802.1Q field, VLAN
+VLAN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_VLAN <= '0';
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 2) then
+ -- 2nd word, check bytes 5:4
+ if(XGMII_RX_DATA1(47 downto 32) = x"0081") then
+ RX_VLAN <= '1';
+ else
+ RX_VLAN <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+--//-- MAC CONTROL PAUSE OPERATION ---------------------------
+-- As per IEEE 802.3-2015 clause 31
+-- See also Annex 31B.1
+PAUSE_OPCODE <= XGMII_RX_DATA1(55 downto 48) & XGMII_RX_DATA1(63 downto 56);
+MAC_CONTROL_PAUSE_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') and (MAC_CONTROL_PAUSE_ENABLE = '0') then
+ RX_CONTROL_PAUSE_VALID <= '0';
+ elsif(XGMII_RX_SOF1 = '1') then
+ -- Destination is always the globally assigned 48-bit multicast address 01-80-C2-00-00-01
+ if(XGMII_RX_DATA1(47 downto 0) = x"010000c28001") then
+ -- destination address matches
+ RX_CONTROL_PAUSE_VALID <= '1';
+ else
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 2) then
+ if(RX_LENGTH_TYPE_FIELD /= x"8808") then
+ -- not the expected type field for a MAC control message
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ if(PAUSE_OPCODE /= x"0001") then
+ -- not the expected PAUSE OpCode
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ elsif(MAC_RX_EOF2 = '1') and (RX_CRC_VALID = '0') then
+ -- BAD_CRC
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ end if;
+end process;
+-- confirm valid MAC control PAUSE message
+RX_CONTROL_PAUSE_VALID2 <= RX_CONTROL_PAUSE_VALID and RX_CRC_VALID and MAC_RX_EOF2;
+
+-- parse pause time
+MAC_CONTROL_PAUSE_002: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') and (MAC_CONTROL_PAUSE_ENABLE = '0') then
+ RX_CONTROL_PAUSE_VALID <= '0';
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 3) then
+ PAUSE_TIME <= XGMII_RX_DATA1(7 downto 0) & XGMII_RX_DATA1(15 downto 8);
+ end if;
+ end if;
+end process;
+
+-- TODO: enact tx pause
+
+--// RX 32-BIT CRC COMPUTATION -------------------------------------------------------
+-- 802.3 section 3.2.9:
+-- protected fields: payload data + optional pad + CRC (excludes preamble and start of frame sequence)
+
+-- The CRC32 component assumes the serial stream is packed into 64-bit words MSb of MSB first.
+-- Since XGMII_RX_DATA1 is packed LSb of LSB first, we need to re-order.
+-- Other reordering consideration: the CRC32 is computed with 'reflected' input bytes.
+-- In summary MSB <-> LSB
+REORDER_CRC32_INPUT: process(XGMII_RX_DATA1, XGMII_RX_DATA1_VALID)
+begin
+ for I in 0 to 63 loop
+ RX_CRC_DATA_IN(I) <= XGMII_RX_DATA1(63-I);
+ end loop;
+ for J in 0 to 7 loop
+ RX_CRC_DATA_VALID_IN(J) <= XGMII_RX_DATA1_VALID(7-J);
+ end loop;
+end process;
+
+-- Latency: 2 CLKs
+RX_CRC_001: CRC32 PORT MAP (
+ CLK => CLK156g,
+ DATA_IN => RX_CRC_DATA_IN,
+ SOF_IN => XGMII_RX_SOF1,
+ SAMPLE_CLK_IN => XGMII_RX_SAMPLE1_CLK,
+ DATA_VALID_IN => RX_CRC_DATA_VALID_IN,
+ CRC_INITIALIZATION => x"FFFFFFFF",
+ CRC_OUT => RX_CRC0,
+ SAMPLE_CLK_OUT => open
+ );
+
+---- The CRC output must be 'reflected' and inverted.
+--REORDER_CRC32_OUTPUT: process(RX_CRC0)
+--begin
+-- for I in 0 to 31 loop
+-- RX_CRC(I) <= not RX_CRC0(31-I);
+-- end loop;
+--end process;
+
+-- when not reflected nor inverted, the correct value for RX_CRC0 is 0xC704DD7B
+-- (reflected/inverted: 0x2144DF1C)
+RX_CRC_VALID <= '1' when RX_CRC0 = x"C704DD7B" else '0';
+
+-- align data output with CRC computation output
+RECLOCK_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ MAC_RX_DATA2 <= (others => '0');
+ MAC_RX_DATA2_VALID <= (others => '0');
+ MAC_RX_SOF2 <= '0';
+ MAC_RX_EOF2 <= '0';
+ MAC_RX_SAMPLE2_CLK <= '0';
+ else
+ MAC_RX_DATA2 <= XGMII_RX_DATA1_D;
+ MAC_RX_DATA2_VALID <= XGMII_RX_DATA1_VALID_D;
+ MAC_RX_SOF2 <= XGMII_RX_SOF1_D;
+ MAC_RX_EOF2 <= XGMII_RX_EOF1_D;
+ MAC_RX_SAMPLE2_CLK <= XGMII_RX_SAMPLE1_CLK_D;
+ end if;
+ end if;
+end process;
+
+-- The entire frame validity is confirmed at the end of frame
+MAC_RX_FRAME_VALID_local <=
+ '1' when (RX_CRC_VALID = '1') and (RX_TOO_SHORT = '0') and (RX_TOO_LONG = '0') and (RX_VALID_ADDR = '1')
+ and (RX_LENGTH_ERR = '0') else
+ '0';
+
+-- test test test
+FIRST_RXCRCERROR_FLAG_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ FIRST_RXCRCERROR_FLAG <= '0';
+ elsif(MAC_RX_EOF2 = '1') and (RX_CRC_VALID = '0') then
+ -- BAD_CRC
+ FIRST_RXCRCERROR_FLAG <= '0';
+ end if;
+ end if;
+end process;
+
+
+
+--// Length/type field check ----------------------
+RX_LENGTH_TYPE_FIELD <= XGMII_RX_DATA1(39 downto 32) & XGMII_RX_DATA1(47 downto 40); -- easier to read the expected 0x0800 0x0806 etc.
+LENGTH_CHECK_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_LENGTH_TYPEN <= '0';
+ elsif(XGMII_RX_SOF1 = '1') then
+ -- assume type field by default at the start of frame
+ RX_LENGTH_TYPEN <= '0'; -- length/type field represents a type. ignore the length value.
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 2) then
+ if(unsigned(RX_LENGTH_TYPE_FIELD(15 downto 11)) = 0) then
+ -- this field is interpreted as "Length" = client data field size
+ -- MSB first (802.3 section 3.2.6)
+ RX_LENGTH <= unsigned(RX_LENGTH_TYPE_FIELD(13 downto 0));
+ RX_LENGTH_TYPEN <= '1'; -- length/type field represents a length
+ else
+ -- this is an ethertype or 802.1q tag
+ RX_LENGTH_TYPEN <= '0'; -- length/type field represents a type. ignore the length value.
+ end if;
+ end if;
+ end if;
+end process;
+
+
+-- compute the difference between RX_BYTE_CNTR and RX_LENGTH (meaningless, but help minimize gates)
+RX_DIFF <= RX_BYTE_CNTR - RX_LENGTH;
+
+-- Length field consistency with actual rx frame length. Check if the length/type field is 'length'
+RX_LENGTH_ERR_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_LENGTH_ERR <= '0';
+ elsif(RX_LENGTH_TYPEN = '0') then
+ -- type field. No explicit length info. Can't validate actual length.
+ RX_LENGTH_ERR <= '0';
+ elsif(XGMII_RX_EOF1 = '1') then
+ if ((RX_LENGTH <= 46) and (RX_VLAN = '0')) or
+ ((RX_LENGTH <= 42) and (RX_VLAN = '1')) then
+ -- short rx frame is padded to the minimum size of 60 bytes + 4 CRC
+ if(RX_BYTE_CNTR = 64) then
+ -- correct answer.
+ RX_LENGTH_ERR <= '0';
+ else
+ -- inconsistency
+ RX_LENGTH_ERR <= '1';
+ end if;
+ else
+ -- normal size frame. no pad.
+ if((RX_DIFF = 18) and (RX_VLAN = '0')) or
+ ((RX_DIFF = 22) and (RX_VLAN = '1'))then
+ -- correct answer.
+ RX_LENGTH_ERR <= '0';
+ else
+ -- inconsistency
+ RX_LENGTH_ERR <= '1';
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+
+
+--// VALID RX FRAME? ----------------------------------------------------------
+-- Is the rx frame valid? If so, confirm the wptr location.
+MAC_RX_VALID_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+
+ if(SYNC_RESET156 = '1') then
+ --MAC_RX_WPTR_CONFIRMED <= (others => '0'); -- GIS Edit
+ N_RX_BAD_CRCS_local <= (others => '0');
+ N_RX_FRAMES_TOO_SHORT_local <= (others => '0');
+ N_RX_FRAMES_TOO_LONG_local <= (others => '0');
+ N_RX_WRONG_ADDR_local <= (others => '0');
+ N_RX_LENGTH_ERRORS_local <= (others => '0');
+ else
+ if(MAC_RX_EOF2 = '1') then -- when CRC32 computation is ready
+ -- frame complete, all checks complete
+ N_RX_FRAMES_local <= N_RX_FRAMES_local + 1;
+
+ if(RX_CRC_VALID = '0') then
+ -- BAD_CRC
+ N_RX_BAD_CRCS_local <= N_RX_BAD_CRCS_local + 1;
+ end if;
+
+ if(RX_TOO_SHORT = '1') then
+ -- frame is too short (<64B)
+ N_RX_FRAMES_TOO_SHORT_local <= N_RX_FRAMES_TOO_SHORT_local + 1;
+ end if;
+
+ if(RX_TOO_LONG = '1') then
+ -- frame is too long
+ N_RX_FRAMES_TOO_LONG_local <= N_RX_FRAMES_TOO_LONG_local + 1;
+ end if;
+
+ if(RX_VALID_ADDR = '0') then
+ -- address does not match (and promiscuous mode is off)
+ N_RX_WRONG_ADDR_local <= N_RX_WRONG_ADDR_local + 1;
+ end if;
+
+ if(RX_LENGTH_ERR = '1') then
+ -- length field is inconsistent with actual rx frame length
+ N_RX_LENGTH_ERRORS_local <= N_RX_LENGTH_ERRORS_local + 1;
+ end if;
+
+-- if (RX_CRC_VALID = '1') and (RX_TOO_SHORT = '0') and (RX_TOO_LONG = '0') and (RX_VALID_ADDR = '1')
+-- and (RX_LENGTH_ERR = '0') then
+-- -- passed all checks
+-- RX_FRAME_TOGGLE3 <= not RX_FRAME_TOGGLE3; -- delineates VALID rx frames (does not toggle if rx frame was rejected)
+-- end if;
+
+ end if;
+ end if;
+ end if;
+end process;
+
+MAC_RX_VALID_002: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (MAC_RX_EOF2 = '1') then
+ MAC_RX_EOF_TOGGLE <= not MAC_RX_EOF_TOGGLE;
+ end if;
+ end if;
+end process;
+
+-- to DIAGNOSTICS output (reclock with user CLK)
+MAC_RX_VALID_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ MAC_RX_EOF_TOGGLE_D <= MAC_RX_EOF_TOGGLE;
+ MAC_RX_EOF_TOGGLE_D2 <= MAC_RX_EOF_TOGGLE_D;
+
+ if(MAC_RX_EOF_TOGGLE_D /= MAC_RX_EOF_TOGGLE_D2) then
+ -- diagnostics were just updated. Safe to reclock with CLK now.
+ N_RX_FRAMES <= std_logic_vector(N_RX_FRAMES_local);
+ N_RX_BAD_CRCS <= std_logic_vector(N_RX_BAD_CRCS_local);
+ N_RX_FRAMES_TOO_SHORT <= std_logic_vector(N_RX_FRAMES_TOO_SHORT_local);
+ N_RX_FRAMES_TOO_LONG <= std_logic_vector(N_RX_FRAMES_TOO_LONG_local);
+ N_RX_WRONG_ADDR <= std_logic_vector(N_RX_WRONG_ADDR_local);
+ N_RX_LENGTH_ERRORS <= std_logic_vector(N_RX_LENGTH_ERRORS_local);
+ end if;
+ end if;
+end process;
+
+--// LOW-LATENCY RX OUTPUT ----------------------------------------------------------
+-- low-latency output case
+NO_RX_BUF_001: if(RX_BUFFER = '0') generate
+ MAC_RX_DATA <= MAC_RX_DATA2;
+ MAC_RX_DATA_VALID <= MAC_RX_DATA2_VALID;
+ MAC_RX_SOF <= MAC_RX_SOF2;
+ MAC_RX_EOF <= MAC_RX_EOF2;
+ MAC_RX_FRAME_VALID <= MAC_RX_FRAME_VALID_local;
+end generate;
+
+--// RX INPUT ELASTIC BUFFER ----------------------------------------------------------
+RX_BUF_001: if(RX_BUFFER = '1') generate
+ -- The purpose of the elastic buffer is two-fold:
+ -- (a) a transition between the CLK156g synchronous PHY side and the CLK-synchronous user side.
+ -- (b) storage for receive packets, to absorb traffic peaks, minimize the number of
+ -- UDP packets lost at high throughput.
+ -- The rx elastic buffer is 16Kbits, large enough for a complete maximum size (14addr+1500data+4FCS = 1518B) frame.
+
+ -- write pointer management
+ MAC_RX_WPTR_001: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ MAC_RX_WPTR <= (others => '0');
+ else
+ if(MAC_RX_SAMPLE2_CLK = '1') and (MAC_RX_EOF2 = '0') then
+ MAC_RX_WPTR <= MAC_RX_WPTR + 1;
+ elsif (MAC_RX_EOF2 = '1') then
+ if(MAC_RX_FRAME_VALID_local = '1') then
+ -- valid frame
+ MAC_RX_WPTR <= MAC_RX_WPTR + 1;
+ else
+ -- faulty frame. rewind write pointer to the last confirmed location
+ MAC_RX_WPTR <= MAC_RX_WPTR_CONFIRMED;
+ end if;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ MAC_RX_WPTR_002: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ MAC_RX_WPTR_CONFIRMED <= (others => '0');
+ elsif (MAC_RX_FRAME_VALID_local = '1') and (MAC_RX_EOF2 = '1') then
+ MAC_RX_WPTR_CONFIRMED <= MAC_RX_WPTR + 1;
+ end if;
+ end if;
+ end process;
+
+ -- concatenate data word, nbytes, sof, eof
+ MAC_RX_DIA <= MAC_RX_EOF2 & MAC_RX_SOF2 & MAC_RX_DATA2_VALID & MAC_RX_DATA2;
+
+ -- No need for initialization
+ -- cross clock domain from PHY CLK156g to user CLK
+ -- GIS Edit : replaced the memory model with a symmetrical, dual-clock
+ -- simple-dual-port (one read port, one write port) memory.
+ /*
+ BRAM_DP2_002: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 74,
+ ADDR_WIDTHA => RX_BUFFER_ADDR_NBITS,
+ DATA_WIDTHB => 74,
+ ADDR_WIDTHB => RX_BUFFER_ADDR_NBITS
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK156g,
+ WEA => MAC_RX_SAMPLE2_CLK,
+ OEA => '0',
+ ADDRA => std_logic_vector(MAC_RX_WPTR),
+ DIA => std_logic_vector(MAC_RX_DIA),
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ OEB => '1',
+ ADDRB => std_logic_vector(MAC_RX_RPTR),
+ DIB => (others => '0'),
+ DOB => MAC_RX_DOB
+ );
+ */
+ BRAM_DP2_002: SDP_RAM
+ GENERIC MAP(
+ ADDR_WIDTH => RX_BUFFER_ADDR_NBITS,
+ DATA_WIDTH => 74)
+ PORT MAP(
+ ENA => '1',
+ CLKA => CLK156g,
+ WEA => MAC_RX_SAMPLE2_CLK,
+ ADDRA => std_logic_vector(MAC_RX_WPTR),
+ DIA => std_logic_vector(MAC_RX_DIA),
+ ENB => '1',
+ CLKB => CLK,
+ ADDRB => std_logic_vector(MAC_RX_RPTR),
+ DOB => MAC_RX_DOB);
+
+ MAC_RX_WPTR_003: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_RX_WPTR_CONFIRMED_D <= (others => '0');
+ elsif(MAC_RX_EOF_TOGGLE_D /= MAC_RX_EOF_TOGGLE_D2) then
+ -- MAC_RX_WPTR_CONFIRMED is stable. OK to resample with the CLK clock.
+ MAC_RX_WPTR_CONFIRMED_D <= MAC_RX_WPTR_CONFIRMED;
+ end if;
+ end if;
+ end process;
+
+ MAC_RX_BUF_SIZE <= MAC_RX_WPTR_CONFIRMED_D + not(MAC_RX_RPTR);
+ -- occupied tx buffer size
+
+ -- manage read pointer
+ MAC_RX_RPTR_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ MAC_RX_SAMPLE3_CLK <= MAC_RX_SAMPLE3_CLK_E; -- it takes one CLK to read data from the RAMB
+
+ if(SYNC_RESET = '1') then
+ MAC_RX_RPTR <= (others => '1');
+ MAC_RX_SAMPLE3_CLK_E <= '0';
+ elsif(MAC_RX_BUF_SIZE /= 0) and (MAC_RX_CTS = '1') then
+ MAC_RX_RPTR <= MAC_RX_RPTR + 1;
+ MAC_RX_SAMPLE3_CLK_E <= '1';
+ else
+ MAC_RX_SAMPLE3_CLK_E <= '0';
+ end if;
+ end if;
+ end process;
+
+ MAC_RX_DATA <= MAC_RX_DOB(63 downto 0);
+ MAC_RX_DATA_VALID <= MAC_RX_DOB(71 downto 64);
+ MAC_RX_SOF <= MAC_RX_DOB(72) and MAC_RX_SAMPLE3_CLK;
+ MAC_RX_EOF <= MAC_RX_DOB(73) and MAC_RX_SAMPLE3_CLK;
+
+end generate;
+
+--// TEST POINTS -------------------------
+--TP <= PHY_CONFIG_TP;
+TP_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ TP(1) <= SYNC_RESET_local;
+ TP(2) <= PHY_CONFIG_CHANGE_A;
+ TP(3) <= SREG_READ_START;
+ TP(4) <= SREG_SAMPLE_CLK;
+ if (SREG_STATE = 1) and (SREG_SAMPLE_CLK = '1') then
+ TP(5) <= '1';
+ else
+ TP(5) <= '0';
+ end if;
+
+
+-- if(XGMII_RX_START_LOC = "000") then
+-- TP(2) <= '1';
+-- else
+-- TP(2) <= '0';
+-- end if;
+-- if(XGMII_RXC /= x"FF") then
+-- TP(3) <= '1';
+-- else
+-- TP(3) <= '0';
+-- end if;
+-- if(XGMII_RXC = x"00") then
+-- TP(4) <= '1';
+-- else
+-- TP(4) <= '0';
+-- end if;
+-- TP(5) <= XGMII_RX_START_CHAR;
+-- TP(6) <= XGMII_RX_SFD_CHAR;
+-- TP(7) <= XGMII_RX_TERM_CHAR;
+
+-- if(XGMII_RXC(0) = '1') and (XGMII_RXD(7 downto 0) = x"FB") then
+-- TP(8) <= '1';
+-- else
+-- TP(8) <= '0';
+-- end if;
+-- if(XGMII_RXC(0) = '0') and (XGMII_RXD(63 downto 56) = x"D5") then
+-- TP(9) <= '1';
+-- else
+-- TP(9) <= '0';
+-- end if;
+---- TP(8) <= XGMII_RX_SOF1;
+---- TP(9) <= XGMII_RX_SAMPLE1_CLK;
+-- TP(10) <= XGMII_RX_SOF1;
+
+-- TP(2) <= MAC_RX_EOF2;
+-- TP(3) <= MAC_RX_EOF2 and MAC_RX_FRAME_VALID_local;
+-- TP(4) <= RX_CRC_VALID;
+-- TP(5) <= XGMII_RX_SOF1;
+-- TP(6) <= XGMII_RX_SAMPLE1_CLK;
+-- if(XGMII_RXC /= x"FF") then
+-- TP(7) <= '1';
+-- else
+-- TP(7) <= '0';
+-- end if;
+-- if(XGMII_RX_DATA1_VALID /= x"00") then
+-- TP(8) <= '1';
+-- else
+-- TP(8) <= '0';
+-- end if;
+-- if(XGMII_RX_DATA1_VALID = x"FF") then
+-- TP(9) <= '1';
+-- else
+-- TP(9) <= '0';
+-- end if;
+
+-- TP(1) <= MAC_RX_FRAME_VALID_local;
+-- TP(2) <= RX_CRC_VALID;
+-- TP(3) <= RX_TOO_SHORT;
+-- TP(4) <= RX_TOO_LONG;
+-- TP(5) <= RX_VALID_ADDR;
+-- TP(6) <= RX_LENGTH_ERR;
+-- TP(7) <= MAC_RX_EOF2;
+-- TP(8) <= '0';
+-- TP(9) <= '0';
+-- TP(10) <= '0';
+
+-- TP(1) <= MAC_TX_CTS_local;
+-- if(MAC_TX_DATA_VALID /= x"00") then
+-- TP(2) <= '1';
+-- else
+-- TP(2) <= '0';
+-- end if;
+-- TP(3) <= MAC_TX_INFRAME;
+-- TP(4) <= MAC_TX_SOF2;
+-- TP(5) <= MAC_TX_EOF2;
+-- TP(6) <= TX_BYTE_CNTR(0);
+-- TP(7) <= TX_FILL_NEXT;
+-- if(MAC_TX_DATA3_VALID /= x"00") then
+-- TP(8) <= '1';
+-- else
+-- TP(8) <= '0';
+-- end if;
+-- TP(9) <= MAC_TX_EOF3;
+
+ end if;
+end process;
+
+end Behavioral;
+
diff --git a/generic_ip/third_party_ip/mac/src/com5501test.vhd b/generic_ip/third_party_ip/mac/src/com5501test.vhd
new file mode 100644
index 0000000..4cf0970
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/com5501test.vhd
@@ -0,0 +1,2280 @@
+-------------------------------------------------------------
+-- MSS copyright 2017-2018
+-- Filename: COM5501.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 3/1/18
+-- Inheritance: COM5401.vhd
+--
+-- description: 10G Ethernet MAC with XGMII hardware interface
+-- Features include
+-- (a) Automatic appending of 32-bit CRC to tx packets. Users don't have to.
+-- (b) discarding of rx packets with bad CRC.
+-- (c) implement MAC pause control
+--
+-- The transmit elastic buffer is large enough for 2 maximum size frame. The tx Clear To Send (MAC_TX_CTS)
+-- signal is raised when the the MAC is ready to accept one complete frame without interruption.
+-- In this case, MAC_TX_CTS may go low while the frame transfer has started, but there is guaranteed
+-- space for the entire frame.
+-------------------------------------------
+-- Device utilization
+-------------------------------------------
+--Number of Slice Registers: 1512
+--Number of Slice LUTs: 2389
+--Number of 18 Kb Block RAM/FIFO: 8
+--Number of DSP48: 0
+--Number of BUFG: 2
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.numeric_std.ALL;
+
+entity COM5501 is
+ generic (
+ EXT_PHY_MDIO_ADDR: std_logic_vector(4 downto 0) := "00000";
+ -- external PHY MDIO address
+ RX_MTU: integer := 1500;
+ -- Maximum Transmission Unit: maximum number of payload Bytes.
+ -- Typically 1500 for standard frames, 9000 for jumbo frames.
+ -- A frame will be deemed invalid if its payload size exceeds this MTU value.
+ RX_BUFFER: std_logic := '0';
+ -- '1' when the received messages are stored temporarily into an elastic buffer prior to the output.
+ -- either because the next block is slower (and thus regulates the data flow), or when crossing clock
+ -- domains from CLK156g to CLK.
+ -- '0' for no output buffer: when flow control is not needed on the rx path and
+ -- the same 156.25 MHz clock is used as both user clock CLK and PHY clock CLK156g.
+ -- This setting is preferred for the lowest latency on the receive path.
+ RX_BUFFER_ADDR_NBITS: integer := 10;
+ -- size of the receiver output elastic buffer (when enabled by RX_BUFFER = '1'). Data width is always 69 bits.
+ -- Example: when RX_BUFFER_ADDR_NBITS = 10, the receive buffer size is 74*2^10 = 75776 bits
+ TX_MTU: integer := 1500;
+ TX_BUFFER: std_logic := '0';
+ -- '1' when the transmit messages are stored temporarily into an input elastic buffer,
+ -- when crossing clock domains from user CLK to PHY CLK156g.
+ -- '0' for no input buffer: when the same 156.25 MHz clock is used as both user clock CLK and PHY clock CLK156g.
+ -- This setting is preferred for the lowest latency on the transmit path.
+ TX_BUFFER_ADDR_NBITS: integer := 10;
+ MAC_CONTROL_PAUSE_ENABLE: std_logic := '1';
+ -- enable (1)/disable (0) enacting transmit pause upon receive a MAC control PAUSE message.
+ SIMULATION: std_logic := '0'
+ -- during simulation, fake LINK_STATUS = '1'
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ -- USER-side GLOBAL clock. Must be at least 156.25 MHz for full 10Gbits/s throughput.
+ -- It must be the same signal as CLK156g when RX_BUFFER = '0'
+ SYNC_RESET: in std_logic;
+ -- reset pulse must be > slowest clock period (>400ns)
+ -- synchronous with CLK
+ CLK156g: in std_logic;
+ -- PHY-side GLOBAL clock at 156.25 MHz
+
+ --// MAC CONFIGURATION
+ -- configuration signals are synchonous with the user-side CLK
+ MAC_TX_CONFIG: in std_logic_vector(7 downto 0);
+ -- bit 0: (1) Automatic padding of short frames. Requires that auto-CRC insertion be enabled too.
+ -- (0) Skip padding. User is responsible for adding padding to meet the minimum 60 byte frame size
+ -- bit 1: (1) Automatic appending of 32-bit CRC at the end of the frame
+ -- (0) Skip CRC32 insertion. User is responsible for including the frame check sequence
+ -- bit 2: (1) Verify MTU size. Frames will be flagged as invalid if the payload size exceeds RX_MTU Bytes.
+ -- (0) Do not check MTU size
+ -- Note: use 0x03 when interfacing with COM-5502 IP/UDP/TCP stack.
+ MAC_RX_CONFIG: in std_logic_vector(7 downto 0);
+ -- bit 0: (1) promiscuous mode enabled (0) disabled, i.e. destination address is verified for each incoming packet
+ -- bit 1: (1) accept broadcast rx packets (0) reject
+ -- bit 2: (1) accept multi-cast rx packets (0) reject
+ -- bit 3: (1) filter out the 4-byte CRC field (0) pass along the CRC field.
+ -- IGNORED IN LOW-LATENCY RECEIVE MODE when RX_BUFFER = '0': CRC is passed along in this case.
+ -- bit 4: (1) Verify MTU size. Frames will be flagged as invalid if the payload size exceeds RX_MTU Bytes.
+ -- (0) Do not check MTU size
+ -- Note2: use 0x0F when interfacing with COM-5502 IP/UDP/TCP stack.
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- This network node 48-bit MAC address. The receiver checks incoming packets for a match between
+ -- the destination address field and this MAC address.
+ -- The user is responsible for selecting a unique ‘hardware’ address for each instantiation.
+ -- Natural bit order: enter x0123456789ab for the MAC address 01:23:45:67:89:ab
+ -- here, x01 is the first received/transmitted byte in the address
+
+ --// USER -> Transmit MAC Interface
+ -- Synchonous with the user-side CLK
+ MAC_TX_DATA: in std_logic_vector(63 downto 0);
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID = '1'
+ -- Bytes order: LSB is sent first
+ -- Bytes are right aligned: first byte in LSB, occasional follow-on fill-in Bytes in the MSB(s)
+ -- The first destination address byte is always a LSB (MAC_TX_DATA(7:0))
+ -- USAGE RULE: only the end of frame word can be partially full (MAC_TX_DATA_VALID = 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f)
+ -- all other words must contain either 0 or 8 bytes.
+ MAC_TX_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- '1' for each meaningful byte in MAC_TX_DATA.
+ -- In this application, only valid values are 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
+ MAC_TX_EOF: in std_logic;
+ -- '1' when sending the last word in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: out std_logic;
+ -- MAC-generated Clear To Send flow control signal, indicating room in the
+ -- tx elastic buffer for a complete MTU.
+ -- The user should check that this signal is high before deciding to send
+ -- sending the next frame.
+ -- Note: MAC_TX_CTS may go low while the frame is transfered in. Ignore it.
+
+ --// Receive MAC -> USER Interface
+ -- Valid rx packets only: packets with bad CRC or invalid address are discarded.
+ -- Synchonous with the user-side CLK
+ -- The short-frame padding is included .
+ MAC_RX_DATA: out std_logic_vector(63 downto 0);
+ -- USER reads the data at the rising edge of CLK when MAC_RX_DATA_VALID = '1'
+ -- Bytes order: LSB was received first
+ -- Bytes are right aligned: first byte in LSB, occasional follow-on fill-in Bytes in the MSB(s)
+ -- The first destination address byte is always a LSB (MAC_RX_DATA(7:0))
+ MAC_RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- '1' for each meaningful byte in MAC_RX_DATA.
+ -- In this application, only valid values are 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
+ MAC_RX_SOF: out std_logic;
+ -- '1' when sending the first byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ MAC_RX_EOF: out std_logic;
+ -- '1' when sending the last byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ -- The entire frame validity is confirmed at the end of frame when MAC_RX_FRAME_VALID = '1'
+ -- Users should discard the entire frame when MAC_RX_FRAME_VALID = '0' at MAC_RX_EOF
+ MAC_RX_FRAME_VALID: out std_logic;
+ -- '1' when the received frame passed all validity checks, including CRC32.
+ -- Read at the end of frame when MAC_RX_EOF = '1'
+ MAC_RX_CTS: in std_logic;
+ -- User-generated Clear To Send flow control signal. The receive MAC checks that this
+ -- signal is high before sending the next MAC_RX_DATA byte.
+ -- Ignored when the rx output buffer is not instantiated (RX_BUFFER = '0')
+ -- parsed information from received MAC frame
+
+
+ --// XGMII PHY Interface
+ XGMII_TXD: out std_logic_vector(63 downto 0);
+ XGMII_TXC: out std_logic_vector(7 downto 0);
+ -- Single data rate transmit interface
+ -- LSB is sent first
+
+ XGMII_RXD: in std_logic_vector(63 downto 0);
+ XGMII_RXC: in std_logic_vector(7 downto 0);
+ -- Single data rate receive interface
+ -- LSb of LSB is received first
+ -- Start character 0xFB is in byte 0 or 4
+ -- XGMII_RXC bit is '0' for valid data byte
+ RESET_N: out std_logic;
+ -- PHY reset#
+ MDC: out std_logic;
+ MDIO_OUT: out std_logic;
+ MDIO_IN: in std_logic;
+ MDIO_DIR: out std_logic; -- '0' when output, '1' when input
+ -- MDIO serial interface to control and monitor two MMDs: external 10G PHY and
+ -- internal XAUI adapter.
+
+ --// PHY CONFIGURATION
+ -- configuration signals are synchonous with the user-side CLK.
+ PHY_CONFIG_CHANGE: in std_logic;
+ -- optional pulse to activate any configuration change below.
+ -- Not needed if the internal default values are acceptable.
+ PHY_RESET: in std_logic;
+ -- 1 = PHY software reset (default), 0 = no reset
+ TEST_MODE: in std_logic_vector(1 downto 0);
+ -- 00 = normal mode (default)
+ -- 01 = loopback mode
+ -- 10 = remote loopback
+ POWER_DOWN: in std_logic;
+ -- software power down mode. 1 = enabled, 0 = disabled (default).
+
+
+ --// PHY status
+ -- synchronous with CLK156g global clock
+ PHY_STATUS: out std_logic_vector(7 downto 0);
+ -- XAUI side of the PHY chip
+ -- bit0: all PHY XAUI rx lanes in sync
+ -- bit1: PHY XAUI rx PLL in lock
+ -- bit2: PHY XAUI rx lane0 signal present
+ -- bit3: PHY XAUI rx lane1 signal present
+ -- bit4: PHY XAUI rx lane2 signal present
+ -- bit5: PHY XAUI rx lane3 signal present
+ -- Expecting 0x3F during normal operations
+ -- read periodically.
+ PHY_STATUS2: out std_logic_vector(7 downto 0);
+ -- SFP+ side of the PHY chip
+ PHY_ID: out std_logic_vector(15 downto 0);
+ -- read PHY device ID (part of hardware self-test). Correct answer for VSC8486-11 is 0x8486
+ -- read once at power up.
+
+ --// DIAGNOSTICS (synchronous with user-supplied clock CLK)
+ N_RX_FRAMES: out std_logic_vector(15 downto 0);
+ -- number of received frames
+ N_RX_BAD_CRCS: out std_logic_vector(15 downto 0);
+ -- number of BAD CRCs among the received frames
+ N_RX_FRAMES_TOO_SHORT: out std_logic_vector(15 downto 0);
+ -- number of rx frames too short (<64B)
+ N_RX_FRAMES_TOO_LONG: out std_logic_vector(15 downto 0);
+ -- number of rx frames too long (>1518B)
+ N_RX_WRONG_ADDR: out std_logic_vector(15 downto 0);
+ -- number of rx frames where address does not match (and promiscuous mode is off)
+ N_RX_LENGTH_ERRORS: out std_logic_vector(15 downto 0);
+ -- number of rx frames with length field inconsistent with actual rx frame length
+ RX_IPG: out std_logic_vector(7 downto 0);
+ -- InterPacket Gap (in Bytes) between the last two successive packets (min is typically 12 Bytes, but
+ -- can be as low as 5 Bytes for 10G).
+
+ --// TEST POINTS
+ DEBUG1: out std_logic_vector(63 downto 0);
+ DEBUG2: out std_logic_vector(63 downto 0);
+ DEBUG3: out std_logic_vector(63 downto 0);
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of COM5501 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT PHY_CONFIG
+ GENERIC (
+ EXT_PHY_MDIO_ADDR: std_logic_vector(4 downto 0)
+ -- external PHY MDIO address
+ );
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ CONFIG_CHANGE : IN std_logic;
+ PHY_RESET: in std_logic;
+ TEST_MODE: in std_logic_vector(1 downto 0);
+ POWER_DOWN: in std_logic;
+ SREG_READ_START : IN std_logic;
+ SREG_MMD: in std_logic_vector(4 downto 0);
+ SREG_ADDR: in std_logic_vector(15 downto 0);
+ SREG_DATA : OUT std_logic_vector(15 downto 0);
+ SREG_SAMPLE_CLK : OUT std_logic;
+ MDC: out std_logic;
+ MDIO_OUT: out std_logic;
+ MDIO_IN: in std_logic;
+ MDIO_DIR: out std_logic; -- '0' when output, '1' when input
+ TP: out std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT CRC32
+ PORT(
+ CLK : IN std_logic;
+ DATA_IN : IN std_logic_vector(63 downto 0);
+ SAMPLE_CLK_IN : IN std_logic;
+ SOF_IN: in std_logic;
+ DATA_VALID_IN : IN std_logic_vector(7 downto 0);
+ CRC_INITIALIZATION: in std_logic_vector(31 downto 0);
+ CRC_OUT : OUT std_logic_vector(31 downto 0);
+ SAMPLE_CLK_OUT : OUT std_logic
+ );
+ END COMPONENT;
+
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CSA : IN std_logic;
+ CLKA : in std_logic;
+ WEA : in std_logic;
+ OEA : IN std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CSB : IN std_logic;
+ CLKB : in std_logic;
+ WEB : in std_logic;
+ OEB : IN std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+
+-- COMPONENT TEST_XGMII_TX
+-- PORT(
+-- CLK156g : IN std_logic;
+-- SYNC_RESET156 : IN std_logic;
+-- TX_TRIGGER : IN std_logic;
+-- XGMII_TXD : OUT std_logic_vector(63 downto 0);
+-- XGMII_TXC : OUT std_logic_vector(7 downto 0);
+-- TP : OUT std_logic_vector(10 downto 1)
+-- );
+-- END COMPONENT;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- NOTATIONS:
+-- _E as one-CLK early sample
+-- _D as one-CLK delayed sample
+-- _D2 as two-CLKs delayed sample
+
+--// CLK & RESETS ---------
+
+signal SYNC_RESET_D: std_logic := '0';
+signal SYNC_RESET156: std_logic := '0';
+
+--// PHY RESET AND CONFIGURATION ----------------------------------------------------------
+signal RESET_CNTR: unsigned(8 downto 0) := (others => '0');
+signal SYNC_RESET_local: std_logic := '0';
+signal RESET_COMPLETE: std_logic := '0';
+signal INITIAL_CONFIG_PULSE: std_logic := '1';
+signal PHY_CONFIG_CHANGE_PENDING: std_logic := '0';
+signal PHY_CONFIG_CHANGE_A: std_logic := '0';
+
+
+signal PHY_RESET_A: std_logic := '0';
+signal TEST_MODE_A: std_logic_vector(1 downto 0);
+signal POWER_DOWN_A: std_logic := '0';
+signal PHY_IF_WRAPPER_RESET: std_logic := '0';
+signal SREG_READ_START: std_logic := '0';
+signal SREG_SAMPLE_CLK: std_logic := '0';
+signal LINK_STATUS_local: std_logic := '0';
+signal SREG_MMD: std_logic_vector(4 downto 0) := (others => '0');
+signal SREG_ADDR: std_logic_vector(15 downto 0) := (others => '0');
+signal SREG_DATA : std_logic_vector(15 downto 0) := (others => '0');
+signal SREG_STATE: unsigned(2 downto 0) := (others => '0');
+
+--// LOW-LATENCY TX INPUT ----------------------------------------------------------
+signal MAC_TX_INFRAME: std_logic := '0';
+signal MAC_TX_DATA2: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA2_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_SOF2: std_logic := '0';
+signal MAC_TX_EOF2: std_logic := '0';
+
+--// TX ELASTIC BUFFER ----------------------------------------------------------
+signal MAC_TX_DIA: std_logic_vector(72 downto 0) := (others => '0');
+signal MAC_TX_DOB: std_logic_vector(72 downto 0) := (others => '0');
+signal MAC_TX_WPTR: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_D: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_D2: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_D3: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_WPTR_STABLE: std_logic := '0';
+signal MAC_TX_WPTR_STABLE_D: std_logic := '0';
+signal TX_COUNTER8: unsigned(2 downto 0) :=(others => '0');
+signal MAC_TX_WEA: std_logic := '0';
+signal MAC_TX_SAMPLE2_CLK: std_logic := '0'; -- TODO
+signal MAC_TX_SAMPLE2_CLK_E: std_logic := '0'; -- TODO
+
+signal MAC_TX_BUF_SIZE: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_TX_RPTR: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_TX_RPTR_D: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_TX_RPTR_CONFIRMED: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_TX_RPTR_CONFIRMED_D: unsigned(TX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal COMPLETE_TX_FRAMES_INBUF: std_logic_vector(7 downto 0) := x"00"; -- can't have more than 147 frames in a 16k buffer
+signal ATLEAST1_COMPLETE_TX_FRAME_INBUF: std_logic := '0';
+signal MAC_TX_EOF_TOGGLE: std_logic := '0';
+signal MAC_TX_EOF_TOGGLE_D: std_logic := '0';
+signal MAC_TX_EOF_TOGGLE_D2: std_logic := '0';
+signal MAC_TX_CTS_local: std_logic := '0';
+
+--// SHORT FRAME PADDING ----------------------------------------------------------
+signal TX_BYTE_CNTR: unsigned(13 downto 0):= (others => '0'); -- large enough for counting 9000 bytes in Jumbo frame
+signal TX_FILL_CNTR: unsigned(5 downto 0):= (others => '0'); -- range 0 - 60
+signal TX_FILL_NEXT: std_logic := '0';
+signal MAC_TX_DATA3: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA3_D: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA3_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_DATA3_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_SOF3: std_logic := '0';
+signal MAC_TX_EOF3: std_logic := '0';
+signal MAC_TX_EOF3_D: std_logic := '0';
+signal MAC_TX_EOF3_D2: std_logic := '0';
+
+--// TX 32-BIT CRC COMPUTATION -------------------------------------------------------
+signal TX_CRC_DATA_IN: std_logic_vector(63 downto 0) := (others => '0');
+signal TX_CRC_SAMPLE_CLK_IN: std_logic := '0';
+signal TX_CRC_DATA_VALID_IN: std_logic_vector(7 downto 0):= (others => '0');
+signal TX_CRC32: std_logic_vector(31 downto 0) := (others => '0');
+signal TX_CRC_SAMPLE_CLK_OUT: std_logic := '0';
+signal TX_CRC32_FLIPPED_INV: std_logic_vector(31 downto 0) := (others => '0');
+
+--//-- XGMII TX INTERFACE --------------------------------
+signal XGMII_TXD_NEXT: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_TXC_NEXT: std_logic_vector(7 downto 0) := (others => '0');
+
+--//-- TX FLOW CONTROL --------------------------------
+signal TX_SUCCESS_TOGGLE: std_logic := '0';
+signal TX_SUCCESS_TOGGLE_D: std_logic := '0';
+signal TX_SUCCESS_TOGGLE_D2: std_logic := '0';
+signal MAC_TX_BUF_FREE: std_logic_vector(11 downto 0) := (others => '0');
+
+
+--// MAC TX STATE MACHINE ----------------------------------------------------------
+--signal TX_CLKG: std_logic := '0';
+--signal IPG: std_logic := '0';
+--signal IPG_CNTR: std_logic_vector(7 downto 0) := (others => '0'); -- TODO CHECK CONSISTENCY WITH TIMER VALUES
+--signal TX_EVENT1: std_logic := '0';
+--signal TX_EVENT2: std_logic := '0';
+--signal TX_EVENT3: std_logic := '0';
+--signal TX_STATE: integer range 0 to 15 := 0;
+--signal TX_BYTE_COUNTER: std_logic_vector(18 downto 0) := (others => '0'); -- large enough for counting 2000 Bytes in max size packet
+--signal TX_BYTE_COUNTER2: std_logic_vector(2 downto 0) := (others => '0'); -- small auxillary byte counter for small fields
+--signal RETX_ATTEMPT_COUNTER: std_logic_vector(4 downto 0) := (others => '0'); -- re-transmission attempts counter
+--signal TX_SUCCESS: std_logic := '0';
+--signal TX_ER: std_logic := '0';
+
+
+
+--// TEST XGMII TX -------------------------------------------------------
+signal TEST_XGMII_TX_TP: std_logic_vector(10 downto 1) := (others => '0');
+
+
+--// MAC RX STATE MACHINE ----------------------------------------------------------
+signal XGMII_RXD_D: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_RX_START_CHAR: std_logic := '0';
+signal XGMII_RX_START_CHAR_D: std_logic := '0'; -- TEST TEST TEST DEL
+signal XGMII_RX_START_LOC: unsigned(2 downto 0) := (others => '0');
+signal XGMII_RX_SFD_CHAR: std_logic := '0';
+signal XGMII_RX_SFD_LOC: unsigned(2 downto 0) := (others => '0');
+signal XGMII_RX_TERM_CHAR: std_logic := '0';
+signal XGMII_RX_TERM_LOC: unsigned(2 downto 0) := (others => '0');
+signal XGMII_RX_ERROR_CHAR: std_logic := '0';
+signal XGMII_RX_IN_FRAME: std_logic := '0';
+signal XGMII_RX_DATA1: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_RX_DATA1A: std_logic_vector(31 downto 0) := (others => '0');
+signal XGMII_RX_DATA1_D: std_logic_vector(63 downto 0) := (others => '0');
+signal XGMII_RX_SAMPLE1_CLK: std_logic := '0';
+signal XGMII_RX_SAMPLE1_CLK_D: std_logic := '0';
+signal XGMII_RX_DATA1_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal XGMII_RX_DATA1_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal XGMII_RX_SOF1: std_logic := '0';
+signal XGMII_RX_SOF1_D: std_logic := '0'; -- TEST TEST TEST
+signal XGMII_RX_SOF1_D2: std_logic := '0'; -- TEST TEST TEST
+signal XGMII_RX_EOF1A: std_logic := '0';
+signal XGMII_RX_EOF1: std_logic := '0';
+signal XGMII_RX_EOF1_D: std_logic := '0';
+signal XGMII_RX_FLUSH: std_logic := '0';
+signal RX_STATE: integer range 0 to 3 := 0;
+signal RX_STATE2: std_logic := '0';
+signal RX_STATE2_D: std_logic := '0';
+signal RX_TOO_SHORT: std_logic := '0';
+signal RX_TOO_LONG: std_logic := '0';
+signal RX_IPG_local: unsigned(8 downto 0):= (others => '0');
+signal RX_VALID_ADDR: std_logic := '0';
+signal MAC_ADDR_REORDER: std_logic_vector(47 downto 0) := (others => '0');
+signal RX_BYTE_CNTR: unsigned(13 downto 0):= (others => '0'); -- large enough for counting 9000 bytes in Jumbo frame
+signal RX_BYTE_CNTR_FINAL: unsigned(13 downto 0):= (others => '0');
+signal RX_WORD_CNTR: unsigned(RX_BYTE_CNTR'left-3 downto 0):= (others => '0'); -- 64-bit word counter
+
+--//-- RX ETHERNET FRAME PARSING ---------------------------
+signal RX_VLAN: std_logic := '0';
+
+--//-- MAC CONTROL PAUSE OPERATION ---------------------------
+signal RX_CONTROL_PAUSE_VALID: std_logic := '0';
+signal RX_CONTROL_PAUSE_VALID2: std_logic := '0';
+signal PAUSE_OPCODE: std_logic_vector(15 downto 0) := (others => '0');
+signal PAUSE_TIME: std_logic_vector(15 downto 0) := (others => '0');
+
+--// RX 32-BIT CRC COMPUTATION -------------------------------------------------------
+signal RX_CRC_DATA_IN: std_logic_vector(63 downto 0) := (others => '0');
+signal RX_CRC_DATA_VALID_IN: std_logic_vector(7 downto 0) := (others => '0');
+signal RX_CRC1_D: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_CRC2: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_CRC_VALID2: std_logic := '0';
+
+--// Length/type field check ----------------------
+signal RX_LENGTH_TYPE_FIELD: std_logic_vector(15 downto 0) := (others => '0');
+signal RX_LENGTH_TYPEN: std_logic := '0';
+signal RX_LENGTH: unsigned(13 downto 0) := (others => '0');
+signal RX_DIFF: unsigned(13 downto 0) := (others => '0');
+signal RX_LENGTH_ERR: std_logic := '0';
+
+--// VALID RX FRAME? ----------------------------------------------------------
+signal MAC_RX_EOF_TOGGLE: std_logic := '0';
+signal MAC_RX_EOF_TOGGLE_D: std_logic := '0';
+signal MAC_RX_EOF_TOGGLE_D2: std_logic := '0';
+signal N_RX_FRAMES_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_BAD_CRCS_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_FRAMES_TOO_SHORT_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_FRAMES_TOO_LONG_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_LENGTH_ERRORS_local: unsigned(15 downto 0) := (others => '0');
+signal N_RX_WRONG_ADDR_local: unsigned(15 downto 0) := (others => '0');
+signal MAC_RX_FRAME_VALID2A: std_logic := '0';
+signal MAC_RX_FRAME_VALID2: std_logic := '0';
+
+signal MAC_RX_DATA2: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_RX_DATA2_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_RX_SOF2: std_logic := '0';
+signal MAC_RX_EOF2: std_logic := '0';
+signal MAC_RX_SAMPLE2_CLK: std_logic := '0';
+
+--// RX INPUT ELASTIC BUFFER ----------------------------------------------------------
+signal MAC_RX_WPTR: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_WPTR_CONFIRMED: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_WPTR_CONFIRMED_D: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_DIA: std_logic_vector(68 downto 0) := (others => '0');
+signal MAC_RX_DOB: std_logic_vector(68 downto 0) := (others => '0');
+signal MAC_RX_BUF_SIZE: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '0');
+signal MAC_RX_RPTR: unsigned(RX_BUFFER_ADDR_NBITS-1 downto 0) := (others => '1');
+signal MAC_RX_SAMPLE3_CLK: std_logic := '0';
+signal MAC_RX_SAMPLE3_CLK_E: std_logic := '0';
+
+
+
+signal PHY_CONFIG_TP: std_logic_vector(10 downto 1) := (others => '0');
+
+-- test test test
+signal FIRST_RXCRCERROR_FLAG: std_logic;
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// SYNCHRONOUS RESETS ----------------------------------------------------------
+-- Create synchronous reset for all two clocks within: CLK156g, CLK
+
+-- Create synchronous reset for CLK156g
+SYNC_RESET156_GEN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ SYNC_RESET_D <= SYNC_RESET;
+ SYNC_RESET156 <= SYNC_RESET_D;
+ end if;
+end process;
+
+--// PHY RESET AND CONFIGURATION ----------------------------------------------------------
+-- First generate a RESET_N pulse at least 100ns wide(VSC8486-11 specs)
+RESET_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RESET_CNTR <= (others => '0');
+ elsif(RESET_CNTR(8) = '0') then
+ RESET_CNTR <= RESET_CNTR + 1;
+ end if;
+
+ case RESET_CNTR(8 downto 7) is
+ when "00" => RESET_N <= '1'; -- between 0 and 63
+ when "01" => RESET_N <= '0'; -- 64-127
+ when "10" => RESET_N <= '1'; -- 128+
+ when others => RESET_N <= '1';
+ end case;
+ end if;
+end process;
+SYNC_RESET_local <= not RESET_CNTR(8);
+RESET_COMPLETE <= RESET_CNTR(8);
+INITIAL_CONFIG_PULSE <= '1' when (RESET_CNTR) = 192 else '0';
+
+-- hold the PHY_CONFIG_CHANGE until the intial reset cycle is complete
+PHY_CONFIG_CHANGE_HOLD: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(PHY_CONFIG_CHANGE = '1') then
+ PHY_CONFIG_CHANGE_PENDING <= '1';
+ elsif(PHY_CONFIG_CHANGE_PENDING = '1') and (RESET_COMPLETE = '1') then
+ PHY_CONFIG_CHANGE_PENDING <= '0';
+ end if;
+ end if;
+end process;
+
+-- enact the configuration
+PHY_CONFIG_CHANGE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or ((INITIAL_CONFIG_PULSE = '1') and (PHY_CONFIG_CHANGE_PENDING = '0')) then
+ -- A default configuration is loaded automatically after power up.
+ PHY_CONFIG_CHANGE_A <= '1';
+ PHY_RESET_A <= '0'; -- no software PHY reset, we just did a hardware reset
+ TEST_MODE_A <= "00";
+ POWER_DOWN_A <= '0';
+ elsif(PHY_CONFIG_CHANGE_PENDING = '1') and (RESET_COMPLETE = '1') then
+ -- PHY_CONFIG_CHANGE indicates a user-triggered configuration change.
+ PHY_CONFIG_CHANGE_A <= '1';
+ PHY_RESET_A <= PHY_RESET;
+ TEST_MODE_A <= TEST_MODE;
+ POWER_DOWN_A <= POWER_DOWN;
+ else
+ PHY_CONFIG_CHANGE_A <= '0';
+ end if;
+ end if;
+end process;
+
+
+PHY_CONFIG_001: PHY_CONFIG
+GENERIC MAP(
+ EXT_PHY_MDIO_ADDR => EXT_PHY_MDIO_ADDR
+)
+PORT MAP(
+ SYNC_RESET => SYNC_RESET_local, -- wait until reset is complete
+ CLK => CLK,
+ CONFIG_CHANGE => PHY_CONFIG_CHANGE_A,
+ PHY_RESET => PHY_RESET_A,
+ TEST_MODE => TEST_MODE_A,
+ POWER_DOWN => POWER_DOWN_A,
+ SREG_READ_START => SREG_READ_START,
+ SREG_MMD => SREG_MMD, -- MDIO managed device
+ SREG_ADDR => SREG_ADDR, -- status register address
+ SREG_DATA => SREG_DATA,
+ SREG_SAMPLE_CLK => SREG_SAMPLE_CLK,
+ MDC => MDC,
+ MDIO_OUT => MDIO_OUT,
+ MDIO_IN => MDIO_IN,
+ MDIO_DIR => MDIO_DIR,
+ TP => PHY_CONFIG_TP
+);
+
+
+---- Special cases
+--LINK_STATUS_local <= '1' when (SIMULATION = '1') else -- fake link status during simulation
+-- LINK_STATUS_FROM_PHY; -- otherwise, ask the PHY for LINK_STATUS
+--
+-- read PHY identification once at power-up or reset (hardware self-test
+-- then periodically read the link status
+PHY_STATUS_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ SREG_MMD <= "00001"; -- MDIO managed device
+ SREG_ADDR <= x"E800"; -- PHY device Identifier CHIP_ID
+ SREG_STATE <= "000";
+ SREG_READ_START <= '1'; -- start asking for status register
+ elsif(SREG_READ_START = '1') then
+ SREG_STATE <= SREG_STATE + 1; -- await status response
+ SREG_READ_START <= '0';
+ elsif(SREG_STATE = 1) and (SREG_SAMPLE_CLK = '1') then
+ -- received CHIP_ID
+ -- periodically read XAUI RX loss of signal status into PHY_STATUS
+ SREG_MMD <= "00100"; -- MDIO managed device
+ SREG_ADDR <= x"8012"; -- PHY XAUI RX status
+ SREG_STATE <= SREG_STATE + 1;
+ SREG_READ_START <= '1'; -- ask for next status register
+ elsif(SREG_STATE = 3) and (SREG_SAMPLE_CLK = '1') then
+ -- received XAUI RX status.
+ -- periodically read PHY SPF+ status
+ SREG_MMD <= "00001"; -- MDIO managed device
+ SREG_ADDR <= x"E600"; -- PMA status 4
+ SREG_STATE <= SREG_STATE + 1;
+ SREG_READ_START <= '1'; -- ask for next status register
+ elsif(SREG_STATE = 5) and (SREG_SAMPLE_CLK = '1') then
+ -- received PHY SPF+ status. Ask again for PHY XAUI RX status
+ SREG_MMD <= "00100"; -- MDIO managed device
+ SREG_ADDR <= x"8012"; -- PHY Identifier MSBs
+ SREG_STATE <= "010";
+ SREG_READ_START <= '1'; -- ask for next status register
+ end if;
+ end if;
+end process;
+
+PHY_STATUS_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ PHY_ID <= (others => '0');
+ elsif(SREG_STATE = 1) and (SREG_SAMPLE_CLK = '1') then
+ PHY_ID <= SREG_DATA;
+ end if;
+
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ PHY_STATUS <= (others => '0');
+ elsif(SREG_STATE = 3) and (SREG_SAMPLE_CLK = '1') then
+ -- bit0: all PHY XAUI rx lanes in sync
+ -- bit1: PHY XAUI rx PLL in lock
+ -- bit2: PHY XAUI rx lane0 signal present
+ -- bit3: PHY XAUI rx lane1 signal present
+ -- bit4: PHY XAUI rx lane2 signal present
+ -- bit5: PHY XAUI rx lane3 signal present
+ PHY_STATUS(0) <= SREG_DATA(6);
+ PHY_STATUS(1) <= not SREG_DATA(5);
+ PHY_STATUS(2) <= not SREG_DATA(0);
+ PHY_STATUS(3) <= not SREG_DATA(1);
+ PHY_STATUS(4) <= not SREG_DATA(2);
+ PHY_STATUS(5) <= not SREG_DATA(3);
+ end if;
+
+ if(SYNC_RESET_local = '1') or (PHY_CONFIG_CHANGE_A = '1') then -- power-up/reset
+ PHY_STATUS2 <= (others => '0');
+ elsif(SREG_STATE = 5) and (SREG_SAMPLE_CLK = '1') then
+ -- received PHY SPF+ status. Ask again for PHY XAUI RX status
+ PHY_STATUS2 <= SREG_DATA(7 downto 0);
+ end if;
+
+ end if;
+end process;
+
+--// LOW-LATENCY TX INPUT ----------------------------------------------------------
+-- low-latency transmit case CLK=CLK156g
+NO_TX_BUF_001: if(TX_BUFFER = '0') generate
+ MAC_TX_DATA2 <= MAC_TX_DATA;
+ MAC_TX_DATA2_VALID <= MAC_TX_DATA_VALID;
+ MAC_TX_SOF2 <= '1' when ((MAC_TX_INFRAME = '0') and (unsigned(MAC_TX_DATA_VALID) /= 0)) else '0';
+ MAC_TX_EOF2 <= MAC_TX_EOF;
+
+ -- recreate a MAC_TX_SOF2
+ TX_SOF_GEN_001: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(MAC_TX_EOF = '1') then
+ MAC_TX_INFRAME <= '0';
+ elsif (unsigned(MAC_TX_DATA_VALID) /= 0) then
+ MAC_TX_INFRAME <= '1';
+ end if;
+ end if;
+ end process;
+
+ MAC_TX_CTS <= '0' when (MAC_TX_EOF = '1') else -- immediately stop inflow when receiving EOF (we may need a few CLKs for padding)
+ '0' when (TX_FILL_NEXT = '1') else
+ '1';
+end generate;
+
+
+--// TX ELASTIC BUFFER ----------------------------------------------------------
+TX_BUF_001: if(TX_BUFFER = '1') generate
+ -- The purpose of the elastic buffer is two-fold:
+ -- (a) a transition between the CLK-synchronous user side, and the CLK156g synchronous PHY side
+ -- (b) storage for Ethernet transmit frames, to absorb traffic peaks, minimize the number of
+ -- UDP packets lost at high throughput.
+ -- The tx elastic buffer is 16Kbits, large enough for TWO complete maximum size
+ -- (14addr+1500data+4FCS = 1518B) frames.
+
+ MAC_TX_WEA <= '1' when (unsigned(MAC_TX_DATA_VALID) /= 0) else '0';
+ -- write pointer management
+ MAC_TX_WPTR_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_COUNTER8 <= (others => '0');
+ MAC_TX_WPTR <= (others => '0');
+ MAC_TX_WPTR_D <= (others => '0');
+ MAC_TX_WPTR_STABLE <= '0';
+ else
+ TX_COUNTER8 <= TX_COUNTER8 + 1;
+
+ if(MAC_TX_WEA = '1') then
+ MAC_TX_WPTR <= MAC_TX_WPTR + 1;
+ end if;
+
+ -- update WPTR_D once every 8 clocks.
+ if(TX_COUNTER8 = 7) then
+ MAC_TX_WPTR_D <= MAC_TX_WPTR;
+ end if;
+
+ -- allow WPTR reclocking with another clock, as long as it is away from the transition area
+ if(TX_COUNTER8 < 6) then
+ MAC_TX_WPTR_STABLE <= '1';
+ else
+ MAC_TX_WPTR_STABLE <= '0';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ MAC_TX_DIA <= MAC_TX_EOF & MAC_TX_DATA_VALID & MAC_TX_DATA;
+ -- concatenate 64-bit word and byte valid
+ BRAM_DP2_001: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 73,
+ ADDR_WIDTHA => TX_BUFFER_ADDR_NBITS,
+ DATA_WIDTHB => 73,
+ ADDR_WIDTHB => TX_BUFFER_ADDR_NBITS
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => MAC_TX_WEA,
+ OEA => '0',
+ ADDRA => std_logic_vector(MAC_TX_WPTR),
+ DIA => std_logic_vector(MAC_TX_DIA),
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK156g,
+ WEB => '0',
+ OEB => '1',
+ ADDRB => std_logic_vector(MAC_TX_RPTR),
+ DIB => (others => '0'),
+ DOB => MAC_TX_DOB
+ );
+
+ MAC_TX_DATA2 <= MAC_TX_DOB(63 downto 0);
+ MAC_TX_DATA2_VALID <= MAC_TX_DOB(71 downto 64) when (MAC_TX_SAMPLE2_CLK = '1') else (others => '0');
+ MAC_TX_SOF2 <= '1' when ((MAC_TX_INFRAME = '0') and (unsigned(MAC_TX_DATA2_VALID) /= 0)) else '0';
+ MAC_TX_EOF2 <= MAC_TX_DOB(72);
+
+ -- recreate a MAC_TX_SOF2
+ TX_SOF_GEN_001: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(MAC_TX_EOF2 = '1') then
+ MAC_TX_INFRAME <= '0';
+ elsif (unsigned(MAC_TX_DATA2_VALID) /= 0) then
+ MAC_TX_INFRAME <= '1';
+ end if;
+ end if;
+ end process;
+
+ -- CLK156g zone. Reclock WPTR
+ MAC_TX_WPTR_002: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ MAC_TX_WPTR_STABLE_D <= '0';
+ MAC_TX_WPTR_D2 <= (others => '0');
+ MAC_TX_WPTR_D3 <= (others => '0');
+ else
+ MAC_TX_WPTR_STABLE_D <= MAC_TX_WPTR_STABLE;
+ MAC_TX_WPTR_D2 <= MAC_TX_WPTR_D;
+
+ if(MAC_TX_WPTR_STABLE_D = '1') then
+ -- WPTR is stable. OK to resample with the CLK156g clock.
+ MAC_TX_WPTR_D3 <= MAC_TX_WPTR_D2;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ MAC_TX_BUF_SIZE <= MAC_TX_WPTR_D3 + not(MAC_TX_RPTR);
+ -- occupied tx buffer size for reading purposes (CLKG clock domain)(
+ -- always lags, could be a bit more, never less.
+
+ MAC_TX_CTS <= '1'; -- TODO !!!!!!!!!!!!!!!!!!!!!!
+ -- TODO: RPTR, FLOW CONTROL???
+
+end generate;
+
+--// SHORT FRAME PADDING ----------------------------------------------------------
+-- keep track of incoming tx frame size
+TX_PADDING_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ TX_BYTE_CNTR <= (others => '0');
+ elsif(MAC_TX_SOF2 = '1') then
+ TX_BYTE_CNTR <= to_unsigned(8,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID /= x"00") and (MAC_TX_EOF2 = '0') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(8,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_EOF2 = '1') then
+ if(MAC_TX_DATA2_VALID(7) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(8,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(6) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(7,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(5) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(6,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(4) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(5,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(3) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(4,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(2) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(3,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(1) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(2,TX_BYTE_CNTR'length);
+ elsif(MAC_TX_DATA2_VALID(0) = '1') then
+ TX_BYTE_CNTR <= TX_BYTE_CNTR + to_unsigned(1,TX_BYTE_CNTR'length);
+ else
+ -- illegal
+ end if;
+ end if;
+ end if;
+end process;
+
+-- padding
+TX_PADDING_002: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= (others => '0');
+ MAC_TX_EOF3 <= '0';
+ elsif (MAC_TX_CONFIG(0) = '0') then
+ -- bit 0: (0) no short frame padding
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= MAC_TX_DATA2_VALID;
+ MAC_TX_EOF3 <= MAC_TX_EOF2;
+ elsif(MAC_TX_EOF2 = '1') then
+ -- bit 0: (1) Automatic padding of short frames. Requires that auto-CRC insertion be enabled too.
+ if (TX_BYTE_CNTR < 56) then
+ -- Minimum input frame size is 60 bytes
+ TX_FILL_NEXT <= '1';
+ TX_FILL_CNTR <= 56 - TX_BYTE_CNTR(5 downto 0);
+ MAC_TX_DATA3_VALID <= x"FF";
+ MAC_TX_EOF3 <= '0';
+ elsif (TX_BYTE_CNTR = 56) then
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= x"0F";
+ MAC_TX_EOF3 <= '1';
+ else
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= MAC_TX_DATA2_VALID;
+ MAC_TX_EOF3 <= '1';
+ end if;
+ elsif(TX_FILL_NEXT = '1') then
+ if(TX_FILL_CNTR <= 8) then
+ TX_FILL_NEXT <= '0';
+ MAC_TX_DATA3_VALID <= x"0F";
+ MAC_TX_EOF3 <= '1';
+ else
+ TX_FILL_CNTR <= TX_FILL_CNTR - 8;
+ MAC_TX_DATA3_VALID <= x"FF";
+ MAC_TX_EOF3 <= '0';
+ end if;
+ else
+ MAC_TX_DATA3_VALID <= MAC_TX_DATA2_VALID;
+ MAC_TX_EOF3 <= '0';
+ TX_FILL_NEXT <= '0';
+ end if;
+ end if;
+end process;
+
+-- zero masked bytes
+TX_PADDING_003: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ MAC_TX_SOF3 <= MAC_TX_SOF2;
+
+ for I in 0 to 7 loop
+ if(MAC_TX_DATA2_VALID(I) = '1') then
+ MAC_TX_DATA3(8*I+7 downto 8*I) <= MAC_TX_DATA2(8*I+7 downto 8*I);
+ else
+ MAC_TX_DATA3(8*I+7 downto 8*I) <= x"00";
+ end if;
+ end loop;
+ end if;
+end process;
+
+--// TX 32-BIT CRC COMPUTATION -------------------------------------------------------
+-- 802.3 section 3.2.9:
+-- protected fields: payload data + optional pad + CRC (excludes preamble and start of frame sequence)
+
+-- The CRC32 component assumes the serial stream is packed into 64-bit words MSb of MSB first.
+-- Since MAC_TX_DATA3 is packed LSb of LSB first, we need to re-order.
+-- Other reordering consideration: the CRC32 is computed with 'reflected' input bytes.
+-- In summary MSB <-> LSB
+REORDER_TX_CRC32_INPUT: process(MAC_TX_DATA3, MAC_TX_DATA3_VALID)
+begin
+ for I in 0 to 63 loop
+ TX_CRC_DATA_IN(I) <= MAC_TX_DATA3(63-I);
+ end loop;
+ for J in 0 to 7 loop
+ TX_CRC_DATA_VALID_IN(J) <= MAC_TX_DATA3_VALID(7-J);
+ end loop;
+end process;
+TX_CRC_SAMPLE_CLK_IN <= '1' when (MAC_TX_DATA3_VALID /= x"00") else '0';
+
+TX_CRC_001: CRC32 PORT MAP (
+ CLK => CLK156g,
+ DATA_IN => TX_CRC_DATA_IN,
+ SOF_IN => MAC_TX_SOF3,
+ SAMPLE_CLK_IN => TX_CRC_SAMPLE_CLK_IN,
+ DATA_VALID_IN => TX_CRC_DATA_VALID_IN,
+ CRC_INITIALIZATION => x"FFFFFFFF",
+ CRC_OUT => TX_CRC32,
+ SAMPLE_CLK_OUT => TX_CRC_SAMPLE_CLK_OUT
+ );
+
+-- flip LSb<->MSb and invert
+TX_CRC32_002: process(TX_CRC32)
+begin
+ for I in 0 to 31 loop
+ TX_CRC32_FLIPPED_INV(I) <= not TX_CRC32(31 - I);
+ end loop;
+end process;
+
+--//-- XGMII TX INTERFACE --------------------------------
+TX_XGMII_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ MAC_TX_DATA3_VALID_D <= MAC_TX_DATA3_VALID;
+ MAC_TX_DATA3_D <= MAC_TX_DATA3;
+ MAC_TX_EOF3_D <= MAC_TX_EOF3;
+ MAC_TX_EOF3_D2 <= MAC_TX_EOF3_D;
+
+ if (SYNC_RESET156 = '1') then
+ XGMII_TXD <= x"0707070707070707";
+ XGMII_TXC <= x"FF";
+ elsif(MAC_TX_SOF3 = '1') then
+ -- insert start + preamble
+ XGMII_TXD <= x"D5555555555555FB";
+ XGMII_TXC <= x"01";
+ elsif(MAC_TX_EOF3_D = '1') then
+ case MAC_TX_DATA3_VALID_D is
+ when x"01" =>
+ XGMII_TXD <= x"0707FD" & TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D(7 downto 0);
+ XGMII_TXC <= x"E0";
+ XGMII_TXD_NEXT <= x"0707070707070707";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"03" =>
+ XGMII_TXD <= x"07FD" & TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D(15 downto 0);
+ XGMII_TXC <= x"C0";
+ XGMII_TXD_NEXT <= x"0707070707070707";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"07" =>
+ XGMII_TXD <= x"FD" & TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D(23 downto 0);
+ XGMII_TXC <= x"80";
+ XGMII_TXD_NEXT <= x"0707070707070707";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"0F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV & MAC_TX_DATA3_D(31 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"07070707070707FD";
+ XGMII_TXC_NEXT <= x"FF";
+ when x"1F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV(23 downto 0) & MAC_TX_DATA3_D(39 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"070707070707FD" & TX_CRC32_FLIPPED_INV(31 downto 24);
+ XGMII_TXC_NEXT <= x"FE";
+ when x"3F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV(15 downto 0) & MAC_TX_DATA3_D(47 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"0707070707FD" & TX_CRC32_FLIPPED_INV(31 downto 16);
+ XGMII_TXC_NEXT <= x"FC";
+ when x"7F" =>
+ XGMII_TXD <= TX_CRC32_FLIPPED_INV(7 downto 0) & MAC_TX_DATA3_D(55 downto 0);
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"07070707FD" & TX_CRC32_FLIPPED_INV(31 downto 8);
+ XGMII_TXC_NEXT <= x"F8";
+ when x"FF" =>
+ XGMII_TXD <= MAC_TX_DATA3_D;
+ XGMII_TXC <= x"00";
+ XGMII_TXD_NEXT <= x"070707FD" & TX_CRC32_FLIPPED_INV;
+ XGMII_TXC_NEXT <= x"F0";
+ when others => null;
+ end case;
+ elsif(MAC_TX_EOF3_D2 = '1') then
+ XGMII_TXD <= XGMII_TXD_NEXT;
+ XGMII_TXC <= XGMII_TXC_NEXT;
+ elsif(MAC_TX_DATA3_VALID_D = x"FF") then
+ XGMII_TXD <= MAC_TX_DATA3_D;
+ XGMII_TXC <= x"00";
+ else
+ XGMII_TXD <= x"0707070707070707"; -- idle
+ XGMII_TXC <= x"FF";
+ end if;
+ end if;
+end process;
+
+
+
+
+
+----//-- TX FLOW CONTROL --------------------------------
+---- ask for more input data if there is room for at least 1K more input bytes
+---- Never write past the last confirmed read pointer location.
+--
+---- read the last confirmed read pointer location and reclock in CLK domain when stable
+--MAC_TX_CTS_001: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- TX_SUCCESS_TOGGLE_D <= '0';
+-- TX_SUCCESS_TOGGLE_D2 <= '0';
+-- MAC_TX_RPTR_CONFIRMED_D <= (others => '1');
+-- else
+-- TX_SUCCESS_TOGGLE_D <= TX_SUCCESS_TOGGLE;
+-- TX_SUCCESS_TOGGLE_D2 <= TX_SUCCESS_TOGGLE_D;
+-- if(TX_SUCCESS_TOGGLE_D2 /= TX_SUCCESS_TOGGLE_D) then
+-- -- shortly after successful packet transmission.
+-- MAC_TX_RPTR_CONFIRMED_D <= MAC_TX_RPTR_CONFIRMED;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--
+---- Compute available room for more tx data
+--MAC_TX_CTS_002: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- MAC_TX_BUF_FREE <= (others => '0');
+-- else
+-- MAC_TX_BUF_FREE <= not (MAC_TX_WPTR_D2 + not MAC_TX_RPTR_CONFIRMED_D);
+-- end if;
+-- end if;
+--end process;
+--
+---- Is there enough room for a complete max size frame?
+---- Don't cut it too close because user interface can flood the buffer very quickly (CLK @ 125 MHz clock)
+---- while we compute the buffer size with the possibly much slower RX_CLG (could be 2.5 MHz for 10Mbps).
+--MAC_TX_CTS_003: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- MAC_TX_CTS_local <= '0'; -- reset
+-- elsif(LINK_STATUS_local = '0') then
+-- -- don't ask the stack for data if there is no link
+-- MAC_TX_CTS_local <= '0'; -- reset
+-- elsif(MAC_TX_BUF_FREE(11) = '0') then
+-- -- room for less than 2KB. Activate flow control
+-- MAC_TX_CTS_local <= '0';
+-- else
+-- MAC_TX_CTS_local <= '1';
+-- end if;
+-- end if;
+--end process;
+--MAC_TX_CTS <= MAC_TX_CTS_local;
+--
+--
+---- manage read pointer
+--MAC_TX_RPTR_001: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if(SYNC_RESETTX = '1') then
+-- MAC_TX_RPTR <= (others => '1');
+-- MAC_TX_RPTR_D <= (others => '1');
+-- else
+-- MAC_TX_RPTR_D <= MAC_TX_RPTR;
+--
+-- if(SYNC_RESETRX = '1') then
+-- MAC_TX_RPTR <= (others => '1');
+-- elsif(TX_STATE = 1) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(2 downto 0) <= 1) then
+-- -- read the first byte(s) in advance (need 2 RX_CLKG to get the data out)
+-- -- Note: we may temporarily read past the write pointer (by one location)
+-- -- but will rewind immediately thereafter
+-- MAC_TX_RPTR <= MAC_TX_RPTR + 1;
+-- elsif(TX_STATE = 2) and (TX_EVENT3 = '1') then
+-- -- we are done reading the packet. rewind the read pointer, as we went past the end of packet.
+-- MAC_TX_RPTR <= MAC_TX_RPTR - 1;
+-- elsif(TX_STATE = 2) and (TX_BYTE_CLK = '1') then
+-- -- read the rest of the packet
+-- -- forward data from input elastic buffer to RGMII interface
+-- -- Note: we may temporarily read past the write pointer (by one location)
+-- -- but will rewind immediately thereafter
+-- MAC_TX_RPTR <= MAC_TX_RPTR + 1;
+-- elsif(TX_STATE = 6) then
+-- -- collision detected. rewind read pointer to the start of frame.
+-- MAC_TX_RPTR <= MAC_TX_RPTR_CONFIRMED;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--
+---- update confirmed read pointer after successful frame transmission
+--MAC_TX_RPTR_002: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if(SYNC_RESETTX = '1') then
+-- MAC_TX_RPTR_CONFIRMED <= (others => '1');
+-- TX_SUCCESS_TOGGLE <= '0';
+-- elsif(TX_SUCCESS = '1') then
+-- MAC_TX_RPTR_CONFIRMED <= MAC_TX_RPTR;
+-- TX_SUCCESS_TOGGLE <= not TX_SUCCESS_TOGGLE;
+-- end if;
+-- end if;
+--end process;
+--
+---- How many COMPLETE tx frames are available for transmission in the input elastic buffer?
+---- Transmission is triggered by the availability of a COMPLETE frame in the buffer (not just a few frame bytes)
+---- It is therefore important to keep track of the number of complete frames.
+---- At the elastic buffer input, a new complete frame is detected upon receiving the EOF pulse.
+--COMPLETE_TX_FRAMES_001: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(SYNC_RESET = '1') then
+-- MAC_TX_EOF_TOGGLE <= '0';
+-- elsif(MAC_TX_DATA_VALID = '1') and (MAC_TX_EOF = '1') then
+-- MAC_TX_EOF_TOGGLE <= not MAC_TX_EOF_TOGGLE; -- Need toggle signal to generate copy in RX_CLKG clock domain
+-- end if;
+-- end if;
+--end process;
+--
+--
+--COMPLETE_TX_FRAMES_002: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if(SYNC_RESETTX = '1') then
+-- MAC_TX_EOF_TOGGLE_D <= '0';
+-- MAC_TX_EOF_TOGGLE_D2 <= '0';
+-- COMPLETE_TX_FRAMES_INBUF <= (others => '0');
+-- else
+-- MAC_TX_EOF_TOGGLE_D <= MAC_TX_EOF_TOGGLE; -- reclock in TX_CLKG clock domain (to prevent glitches)
+-- MAC_TX_EOF_TOGGLE_D2 <= MAC_TX_EOF_TOGGLE_D;
+--
+-- if(MAC_TX_EOF_TOGGLE_D2 /= MAC_TX_EOF_TOGGLE_D) and (TX_SUCCESS = '0') then
+-- -- just added another complete frame into the tx buffer (while no successful transmission concurrently)
+-- COMPLETE_TX_FRAMES_INBUF <= COMPLETE_TX_FRAMES_INBUF + 1;
+-- elsif(MAC_TX_EOF_TOGGLE_D2 = MAC_TX_EOF_TOGGLE_D) and (TX_SUCCESS = '1')
+-- and (ATLEAST1_COMPLETE_TX_FRAME_INBUF = '1') then
+-- -- a frame was successfully transmitted (and none was added at the very same instant)
+-- COMPLETE_TX_FRAMES_INBUF <= COMPLETE_TX_FRAMES_INBUF - 1;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--
+---- Flag to indicate at least one complete tx frame in buffer.
+--ATLEAST1_COMPLETE_TX_FRAME_INBUF <= '0' when (COMPLETE_TX_FRAMES_INBUF = 0) else '1';
+--
+--
+--
+--
+----// MAC TX STATE MACHINE ----------------------------------------------------------
+--
+--
+---- 96-bit InterPacketGap (Interframe Delay) timer
+--IPG_001: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if (SYNC_RESETRX = '1') then
+-- IPG_CNTR <= (others => '0');
+-- CRS_D <= '0';
+-- else
+-- CRS_D <= CRS; -- reclock with TX_CLKG
+--
+-- -- or carrier extension in progress
+-- -- Arm InterPacketGap timer
+-- IPG_CNTR <= x"0C" ; -- 96 bits = 12 bytes 802.3 section 4.4.2
+-- elsif(IPG_CNTR > 0) and (TX_BYTE_CLK = '1') then
+-- -- after end of passing packet, decrement counter downto to zero (InterPacketGap).
+-- IPG_CNTR <= IPG_CNTR - 1;
+-- end if;
+-- end if;
+-- end if;
+--end process;
+--IPG <= '1' when (IPG_CNTR = 0) else '0'; -- '1' last passing packet was more than InterPacketGap ago. OK to start tx.
+--
+---- Events ------------------------
+---- First tx packet trigger
+--TX_EVENT1 <= '0' when (ATLEAST1_COMPLETE_TX_FRAME_INBUF = '0') else -- no COMPLETE frame in tx input buffer
+-- '0' when (MAC_TX_BUF_SIZE = 0) else -- no data in tx input buffer
+-- '0' when (IPG = '0') else -- medium is not clear. need to wait after the InterPacketGap. Deferring on.
+-- '0' when (TX_SUCCESS = '1') else -- don't act too quickly. It takes one RX_CLKG to update the complete_tx_frame_inbuf counter.
+-- '0' when (PHY_IF_WRAPPER_RESET = '1') else -- PHY/RGMII wrapper are being reset. Do not start tx.
+-- TX_BYTE_CLK; -- go ahead..start transmitting. align event pulse with TX_BYTE_CLK
+--
+--
+--
+---- Tx state machine ------------------------
+--TX_STATE_GEN_001: process(TX_CLKG)
+--begin
+-- if rising_edge(TX_CLKG) then
+-- if (SYNC_RESETTX = '1') or (LINK_STATUS_local = '0') then
+-- TX_STATE <= 0; -- idle state
+-- TX_SUCCESS <= '0';
+-- TX_BYTE_CLK_D <= '0';
+-- RETX_ATTEMPT_COUNTER <= (Others => '0'); -- re-transmission attempts counter
+-- else
+--
+-- TX_BYTE_CLK_D <= TX_BYTE_CLK; -- output byte ready one RX_CLKG later
+--
+-- if(TX_STATE = 0) then
+-- TX_SUCCESS <= '0';
+-- RETX_ATTEMPT_COUNTER <= (Others => '0'); -- reset re-transmission attempts counter
+-- if (TX_EVENT1 = '1') then
+-- -- start tx packet: send 1st byte of preamble
+-- TX_STATE <= 1;
+-- TX_BYTE_COUNTER2 <= "111"; -- 8-byte preamble + start of frame sequence
+-- end if;
+-- elsif(TX_STATE = 1) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(2 downto 0) /= 0) then
+-- -- counting through the preamble + start frame sequence
+-- TX_BYTE_COUNTER2 <= TX_BYTE_COUNTER2 - 1;
+-- elsif(TX_STATE = 1) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(2 downto 0) = 0) then
+-- -- end of preamble. start forwarding data from elastic buffer to RGMII wrapper
+-- TX_STATE <= 2;
+-- TX_BYTE_COUNTER <= (others => '0');
+-- elsif(TX_STATE = 2) and (TX_BYTE_CLK = '1') and (TX_EVENT3 = '0') then
+-- -- keep track of the payload byte count (to detect the need for padding)
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- elsif(TX_STATE = 2) and (TX_BYTE_CLK = '1') and (TX_EVENT3 = '1') then
+-- -- found end of frame
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- if (TX_BYTE_COUNTER(10 downto 0) < 59) then
+-- if (MAC_TX_CONFIG(1 downto 0) = "11") then
+-- -- frame is too short: payload data does not meet minimum 60-byte size.
+-- -- user enabled automatic padding and automatic CRC32 insertion
+-- TX_STATE <= 3;
+-- else
+-- -- error: frame is too short. abort.
+-- TX_STATE <= 10;
+-- end if;
+-- elsif (MAC_TX_CONFIG(1) = '1') then
+-- -- user enabled auto-CRC32 insertion. Start inserting CRC
+-- TX_STATE <= 4;
+-- TX_BYTE_COUNTER2 <= "011"; -- 4-byte CRC(FCS)
+-- elsif (TX_BYTE_COUNTER(10 downto 0) >= 63) then
+-- -- complete packet (including user-supplied CRC)
+-- else
+-- -- we are done here
+-- TX_STATE <= 0;
+-- TX_SUCCESS <= '1'; -- completed frame transmission
+-- end if;
+-- else
+-- -- error. frame is too short (< 64 bytes including 4-byte CRC). abort.
+-- TX_STATE <= 10;
+-- end if;
+-- elsif(TX_STATE = 3) and (TX_BYTE_CLK = '1') then
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- if(TX_BYTE_COUNTER(10 downto 0) < 59) then
+-- -- padding payload field to the minimum size.
+-- -- keep track of the byte count
+-- elsif (MAC_TX_CONFIG(1) = '1') then
+-- -- Completed padding. User enabled CRC32 insertion. Start inserting CRC
+-- TX_STATE <= 4;
+-- TX_BYTE_COUNTER2 <= "011"; -- 4-byte CRC(FCS)
+-- else
+-- -- error. Illegal user configuration. auto-pad requires auto-CRC. abort.
+-- TX_STATE <= 10;
+-- end if;
+-- elsif(TX_STATE = 4) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) /= 0) then
+-- -- counting through the CRC/FCS sequence
+-- TX_BYTE_COUNTER2 <= TX_BYTE_COUNTER2 - 1;
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- elsif(TX_STATE = 4) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) = 0) then
+-- -- end of CRC/FCS. Packet is now complete.
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- else
+-- -- we are done here
+-- TX_STATE <= 0;
+-- TX_SUCCESS <= '1'; -- completed frame transmission
+-- end if;
+-- elsif(TX_STATE = 5) and (TX_BYTE_CLK = '1') then
+-- -- Carrier extension
+-- TX_BYTE_COUNTER <= TX_BYTE_COUNTER + 1;
+-- if(TX_BYTE_COUNTER(10 downto 0) >= 511) then
+-- -- met slotTime requirement.
+-- TX_STATE <= 0;
+-- TX_SUCCESS <= '1'; -- completed frame transmission
+-- end if;
+-- elsif(TX_STATE = 6) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) /= 0) then
+-- -- Jam . counting through the 4-byte jam
+-- TX_BYTE_COUNTER2 <= TX_BYTE_COUNTER2 - 1;
+-- elsif(TX_STATE = 6) and (TX_BYTE_CLK = '1') and (TX_BYTE_COUNTER2(1 downto 0) = 0) then
+-- -- end of Jam
+--
+--
+--TX_ER <= '1' when (TX_STATE = 5) else -- carrier extension
+-- '0';
+--
+--
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-- test code to send a pre-stored frame
+--TEST_XGMII_TX_001: TEST_XGMII_TX PORT MAP(
+-- CLK156g => CLK156g,
+-- SYNC_RESET156 => SYNC_RESET156,
+-- TX_TRIGGER => TX_TRIGGER,
+-- XGMII_TXD => XGMII_TXD,
+-- XGMII_TXC => XGMII_TXC,
+-- TP => TEST_XGMII_TX_TP
+--);
+
+--// MAC RX STATE MACHINE ----------------------------------------------------------
+-- delay XGMII_RXD one CLK while we search for special characters (start,terminate,error)
+RX_RECLOCK_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ XGMII_RXD_D <= XGMII_RXD;
+ end if;
+end process;
+
+-- detect start character (0xFB) and pinpoint its byte location within the 8-byte XGMII rx word
+-- There are two possible locations 0 and 4
+-- (see Xilinx PG053 "Internal 64-bit SDR client-side interface" p77)
+-- (see Altera UG-01080 7-12)
+XGMII_RX_START_CHAR_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(XGMII_RXC(0) = '1') and (XGMII_RXD(7 downto 0) = x"FB") then
+ XGMII_RX_START_CHAR <= '1';
+ XGMII_RX_START_LOC <= "000";
+ elsif(XGMII_RXC(4) = '1') and (XGMII_RXD(39 downto 32) = x"FB") then
+ XGMII_RX_START_CHAR <= '1';
+ XGMII_RX_START_LOC <= "100";
+ else
+ XGMII_RX_START_CHAR <= '0';
+ end if;
+ end if;
+end process;
+
+-- detect the first SFD character (0xD5) and pinpoint its byte location within the 8-byte XGMII rx word
+XGMII_RX_SFD_CHAR_001: process(CLK156g)
+variable SFD: std_logic := '0';
+variable SFD_LOC: unsigned(2 downto 0) := "000";
+begin
+ if rising_edge(CLK156g) then
+ SFD := '0';
+ for I in 0 to 7 loop
+ if(XGMII_RXC(I) = '0') and (XGMII_RXD(8*I+7 downto 8*I) = x"D5") and (SFD = '0') then
+ -- stop as soon as we found the character
+ SFD := '1';
+ SFD_LOC := to_unsigned(I,3);
+ end if;
+ end loop;
+ if(SFD = '1') and (RX_STATE /= 2) then
+ -- filter out xD5 characters in payload
+ XGMII_RX_SFD_LOC <= SFD_LOC;
+ XGMII_RX_SFD_CHAR <= '1';
+ else
+ XGMII_RX_SFD_CHAR <= '0';
+ end if;
+ end if;
+end process;
+
+-- detect terminate character and pinpoints its byte location within the 8-byte XGMII rx word
+XGMII_RX_TERMINATE_001: process(CLK156g)
+variable TERMINATE: std_logic := '0';
+variable TERMINATE_LOC: unsigned(2 downto 0) := "000";
+begin
+ if rising_edge(CLK156g) then
+ TERMINATE := '0';
+ for I in 0 to 7 loop
+ if(XGMII_RXC(I) = '1') and (XGMII_RXD(8*I+7 downto 8*I) = x"FD") and (TERMINATE = '0') then
+ -- stop as soon as we found the character
+ TERMINATE := '1';
+ TERMINATE_LOC := to_unsigned(I,3);
+ end if;
+ end loop;
+ XGMII_RX_TERM_CHAR <= TERMINATE;
+ XGMII_RX_TERM_LOC <= TERMINATE_LOC;
+ end if;
+end process;
+
+-- detect error character
+XGMII_RX_ERROR_001: process(CLK156g)
+variable ERROR: std_logic := '0';
+begin
+ if rising_edge(CLK156g) then
+ ERROR := '0';
+ for I in 0 to 7 loop
+ if(XGMII_RXC(I) = '1') and (XGMII_RXD(8*I+7 downto 8*I) = x"FE") then
+ ERROR := '1';
+ end if;
+ end loop;
+ XGMII_RX_ERROR_CHAR <= ERROR;
+ end if;
+end process;
+
+
+-- delineate a frame using a state machine
+XGMII_RX_STATE_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_IN_FRAME <= '0';
+ elsif(XGMII_RX_START_CHAR = '1') then
+ -- entering a frame
+ XGMII_RX_IN_FRAME <= '1';
+ elsif((XGMII_RX_TERM_CHAR = '1') or (XGMII_RX_ERROR_CHAR = '1')) then
+ XGMII_RX_IN_FRAME <= '0';
+ end if;
+ end if;
+end process;
+
+-- Assess the InterPacket Gap. Clamp at 255 bytes
+RX_IPG_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_IPG_local <= (others => '0');
+ RX_IPG <= (others => '0');
+ elsif (XGMII_RX_TERM_CHAR = '1') then
+ -- detected terminate character. Start counting IPG bytes and report previous IPG
+ if(RX_IPG_local(8) = '1') then
+ -- clamp at 255 bytes
+ RX_IPG <= x"FF";
+ else
+ RX_IPG <= std_logic_vector(RX_IPG_local(7 downto 0));
+ end if;
+ if(XGMII_RX_START_CHAR = '0') then
+ -- start and terminate characters are not in the same word
+ RX_IPG_local <= resize(not XGMII_RX_TERM_LOC, RX_IPG_local'length);
+ elsif(XGMII_RX_TERM_LOC < XGMII_RX_START_LOC) then
+ -- start and terminate characters are in the same word, and start follows terminate as expected
+ RX_IPG_local <= resize(XGMII_RX_START_LOC - XGMII_RX_TERM_LOC,RX_IPG_local'length);
+ else
+ -- really really short frame. ignore
+ end if;
+ elsif (XGMII_RX_START_CHAR = '0') then
+ if(XGMII_RXC = x"FF") and (RX_IPG_local(8) = '0') then -- clamp at 255 bytes
+ RX_IPG_local <= RX_IPG_local + to_unsigned(8,RX_IPG_local'length);
+ end if;
+ else
+ -- detected start character. Finalize IPG byte count and report.
+ if (RX_IPG_local(8) = '0') then -- clamp at 255 bytes
+ RX_IPG_local <= RX_IPG_local + resize(XGMII_RX_START_LOC,RX_IPG_local'length);
+ end if;
+ end if;
+ end if;
+end process;
+
+-- Rx state machine ------------------------
+-- states:
+-- 0 idle
+-- 1 received start character, awaiting start of frame delimiter (SFD)
+-- 2 received SFD, receiving data
+--
+-- Keeps track of the received bytes and words.
+-- RX_BYTE_CNTR should be read when RX_SAMPLE1_CLK = '1'
+-- It also represents the word count in fixed point format 10.3
+-- For example RX_BYTE_CNTR = "0000000011.001" marks the third word with one extra byte waiting in cache
+RX_STATE_GEN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ RX_STATE2_D <= RX_STATE2;
+
+ if (SYNC_RESET156 = '1') then
+ RX_STATE <= 0;
+ RX_BYTE_CNTR <= (others => '0');
+ elsif(RX_STATE2 = '0') and (XGMII_RX_TERM_CHAR = '1') then
+ -- defensive code: back to idle
+ RX_STATE <= 0;
+ elsif(XGMII_RX_START_CHAR = '1') then
+ -- SFD may be in the same word or in the next
+ if(XGMII_RX_SFD_CHAR = '1') then
+ -- both start character and SFD byte in the same word. Start counting rx bytes
+ RX_STATE <= 2;
+-- RX_BYTE_CNTR <= resize(not XGMII_RX_SFD_LOC, RX_BYTE_CNTR'length); -- always 0
+ RX_BYTE_CNTR <= (others => '0');
+ else
+ RX_STATE <= 1; -- awaiting SFD byte in the next word
+ end if;
+ elsif(RX_STATE = 1) then
+ if(XGMII_RX_SFD_CHAR = '1') then
+ -- received both start and SFD bytes. Start counting rx bytes
+ RX_STATE <= 2;
+ -- RX_BYTE_CNTR <= resize(not XGMII_RX_SFD_LOC, RX_BYTE_CNTR'length); -- always 4
+ RX_BYTE_CNTR <= (2 => '1', others => '0');
+ else
+ -- something wrong (SFD always follows START character) Error. Back to idle
+ RX_STATE <= 0;
+ end if;
+ elsif(RX_STATE2 = '1') then
+ if(XGMII_RX_TERM_CHAR = '0') then
+ RX_BYTE_CNTR <= RX_BYTE_CNTR + to_unsigned(8,RX_BYTE_CNTR'length);
+ else
+ RX_BYTE_CNTR <= RX_BYTE_CNTR_FINAL;
+ RX_STATE <= 0; -- back to idle
+ end if;
+ end if;
+ end if;
+end process;
+RX_WORD_CNTR <= RX_BYTE_CNTR(RX_BYTE_CNTR'left downto 3); -- int(byte counter/8)
+RX_BYTE_CNTR_FINAL <= RX_BYTE_CNTR + resize(XGMII_RX_TERM_LOC, RX_BYTE_CNTR'length);
+ -- read when XGMII_RX_TERM_CHAR = '1'
+
+
+-- Assess whether rx frame is too short (<64 Bytes)
+RX_TOO_SHORT_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') or (XGMII_RX_START_CHAR = '1') then
+ RX_TOO_SHORT <= '0';
+ elsif (XGMII_RX_TERM_CHAR = '1') then
+ -- end of frame
+ if(RX_STATE /= 2) or (RX_BYTE_CNTR_FINAL < 64)then
+ -- end of frame before the data field, or
+ -- less than 64 bytes
+ RX_TOO_SHORT <= '1';
+ else
+ RX_TOO_SHORT <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+-- Assess whether rx frame is too long (>1500 payload bytes or >9000 payload bytes when jumbo frames allowed)
+-- Add MAC addresses, CRC32, ethertype/length, and 802.1Q tag to payload length.
+RX_TOO_LONG_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') or (XGMII_RX_START_CHAR = '1') then
+ RX_TOO_LONG <= '0';
+ elsif (XGMII_RX_TERM_CHAR = '1') and (MAC_RX_CONFIG(4) = '1') then
+ -- Detect payload frames longer than the user-specified MTU size
+ -- at end of frame
+ if(RX_VLAN = '0') and (RX_BYTE_CNTR_FINAL > RX_MTU+18) then
+ RX_TOO_LONG <= '1';
+ elsif(RX_VLAN = '1') and (RX_BYTE_CNTR_FINAL > RX_MTU+22) then
+ RX_TOO_LONG <= '1';
+ else
+ RX_TOO_LONG <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+-- realign bytes starting at the destination address, immediately after the SFD.
+-- Discard the preamble
+RX_ALIGN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_FLUSH <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ XGMII_RX_DATA1 <= (others => '0');
+ elsif(XGMII_RX_SFD_CHAR = '1') then
+ -- save 0 or 4 bytes in cache XGMII_RX_DATA1A until we have a full 8-byte word
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_FLUSH <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ if(XGMII_RX_SFD_LOC = "011") then
+ XGMII_RX_DATA1A <= XGMII_RXD_D(63 downto 32);
+ end if;
+ elsif(RX_STATE2 = '1') then
+ if(XGMII_RX_TERM_CHAR = '0') then
+ -- 8 more Bytes
+ XGMII_RX_FLUSH <= '0';
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ XGMII_RX_DATA1_VALID <= x"FF";
+ elsif(XGMII_RX_SFD_LOC = "111") then
+ -- terminate character detected. No data in cache.
+ XGMII_RX_FLUSH <= '0';
+ -- received terminate character: received less than 8 bytes and no data in XGMII_RX_DATA1A cache
+ case XGMII_RX_TERM_LOC(2 downto 0) is
+ when "001" => XGMII_RX_DATA1_VALID <= x"01";
+ when "010" => XGMII_RX_DATA1_VALID <= x"03";
+ when "011" => XGMII_RX_DATA1_VALID <= x"07";
+ when "100" => XGMII_RX_DATA1_VALID <= x"0F";
+ when "101" => XGMII_RX_DATA1_VALID <= x"1F";
+ when "110" => XGMII_RX_DATA1_VALID <= x"3F";
+ when "111" => XGMII_RX_DATA1_VALID <= x"7F";
+ when others => XGMII_RX_DATA1_VALID <= x"00";
+ end case;
+ if(XGMII_RX_TERM_LOC = "000") then
+ -- no new data, no data in cache
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ else
+ -- new data, no data in cache
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ end if;
+ else
+ -- received terminate character: received less than 8 bytes and 4 Bytes data in cache.
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ case XGMII_RX_TERM_LOC(2 downto 0) is
+ when "000" => XGMII_RX_DATA1_VALID <= x"0F";
+ when "001" => XGMII_RX_DATA1_VALID <= x"1F";
+ when "010" => XGMII_RX_DATA1_VALID <= x"3F";
+ when "011" => XGMII_RX_DATA1_VALID <= x"7F";
+ when others => XGMII_RX_DATA1_VALID <= x"FF";
+ end case;
+ if(unsigned(XGMII_RX_TERM_LOC) < 5) then
+ -- 4 Bytes or less of new data + 4 Bytes in cache
+ XGMII_RX_FLUSH <= '0';
+ else
+ -- 5 Bytes or more of new data + 4 Bytes in cache
+ -- need an additional flush cycle for remaining bytes
+ XGMII_RX_FLUSH <= '1';
+ end if;
+ end if;
+
+ -- SFD is located only at locations 3 or 7
+ -- Note: some bytes will be masked if a terminate character is received (see process below)
+ -- In this case, we don't even try to zero these meaningless bytes
+ if(XGMII_RX_SFD_LOC = "011") then
+ XGMII_RX_DATA1(31 downto 0) <= XGMII_RX_DATA1A;
+ XGMII_RX_DATA1(63 downto 32) <= XGMII_RXD_D(31 downto 0);
+ XGMII_RX_DATA1A(31 downto 0) <= XGMII_RXD_D(63 downto 32);
+ else
+ XGMII_RX_DATA1(63 downto 0) <= XGMII_RXD_D(63 downto 0);
+ end if;
+ elsif(XGMII_RX_FLUSH = '1') then
+ XGMII_RX_SAMPLE1_CLK <= '1';
+ XGMII_RX_DATA1 <= x"00000000" & XGMII_RX_DATA1A;
+ XGMII_RX_FLUSH <= '0';
+ -- flush remaining bytes in XGMII_RX_DATA1A cache
+ case RX_BYTE_CNTR_FINAL(2 downto 0) is
+ when "001" => XGMII_RX_DATA1_VALID <= x"01";
+ when "010" => XGMII_RX_DATA1_VALID <= x"03";
+ when "011" => XGMII_RX_DATA1_VALID <= x"07";
+ when others => XGMII_RX_DATA1_VALID <= x"00";
+ end case;
+ else
+ XGMII_RX_SAMPLE1_CLK <= '0';
+ XGMII_RX_DATA1_VALID <= x"00";
+ end if;
+ end if;
+end process;
+
+-- generate start of frame
+-- mark the XGMII_RX_SOF1 (1st word, contains destination MAC address + partial source address )
+RX_STATE2 <= '1' when (RX_STATE = 2) else '0';
+XGMII_RX_SOF1_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ -- the first received word with start character does not have enough data bytes to fill the 8-byte XGMII_RX_DATA1,
+ -- but the next word certainly has
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_SOF1 <= '0';
+ elsif(RX_STATE2 = '1') and (RX_STATE2_D = '0') then
+ XGMII_RX_SOF1 <= '1';
+ else
+ XGMII_RX_SOF1 <= '0';
+ end if;
+ -- test test test
+ XGMII_RX_SOF1_D2 <= XGMII_RX_SOF1_D;
+-- collect first few words of first failed CRC frame (compare with Wireshark)
+-- if(XGMII_RX_SOF1 = '1') and (FIRST_RXCRCERROR_FLAG = '0') then
+-- DEBUG1 <= XGMII_RX_DATA1;
+-- end if;
+-- if(XGMII_RX_SOF1_D = '1') and (FIRST_RXCRCERROR_FLAG = '0') then
+-- DEBUG2 <= XGMII_RX_DATA1;
+-- end if;
+-- if(XGMII_RX_SOF1_D2 = '1') and (FIRST_RXCRCERROR_FLAG = '0') then
+-- DEBUG3 <= XGMII_RX_DATA1;
+-- end if;
+
+ end if;
+end process;
+
+-- mark the XGMII_RX_EOF1 (last word, may be partially filled: see XGMII_RX_FRAME_SIZE(2 downto 0))
+XGMII_RX_EOF1_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ XGMII_RX_EOF1A <= '0';
+ elsif(RX_STATE2 = '1') and (XGMII_RX_TERM_CHAR = '1') then
+ if (XGMII_RX_SFD_LOC = "111") then
+ -- terminate character detected, no data in cache
+ if(XGMII_RX_TERM_LOC = "000") then
+ -- no new data, no data in cache (immediate EOF, see addendum below this process)
+ XGMII_RX_EOF1A <= '0';
+ else
+ -- new data, no data in cache
+ XGMII_RX_EOF1A <= '1';
+ end if;
+ else
+ -- received terminate character: received less than 8 bytes and 4 Bytes data in cache.
+ if(unsigned(XGMII_RX_TERM_LOC) < 5) then
+ -- 4 Bytes or less of new data + 4 Bytes in cache
+ XGMII_RX_EOF1A <= '1';
+ else
+ -- 5 Bytes or more of new data + 4 Bytes in cache
+ -- need an additional flush cycle for remaining bytes
+ XGMII_RX_EOF1A <= '0';
+ end if;
+ end if;
+ elsif(XGMII_RX_FLUSH = '1') then
+ -- flush remaining bytes in XGMII_RX_DATA1A cache
+ XGMII_RX_EOF1A <= '1';
+ else
+ XGMII_RX_EOF1A <= '0';
+ end if;
+ end if;
+end process;
+
+XGMII_RX_EOF1 <=
+ '1' when (RX_STATE = 2) and (XGMII_RX_TERM_CHAR = '1') and (XGMII_RX_TERM_LOC = "000") else
+ XGMII_RX_EOF1A;
+
+
+
+-- Destination address check
+MAC_ADDR_REORDER <= MAC_ADDR(7 downto 0) & MAC_ADDR(15 downto 8) &
+ MAC_ADDR(23 downto 16) & MAC_ADDR(31 downto 24) &
+ MAC_ADDR(39 downto 32) & MAC_ADDR(47 downto 40);
+ -- reorder the bytes, as the XGMII interface packs first byte as LSB
+ADDR_CHECK_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_VALID_ADDR <= '0';
+ elsif(MAC_RX_CONFIG(0) = '1') then
+ -- promiscuous mode. No destination address check
+ RX_VALID_ADDR <= '1';
+ elsif(XGMII_RX_SOF1 = '1') then
+ -- 1st word. Check address in Bytes 5:0
+ if(XGMII_RX_DATA1(47 downto 0) = MAC_ADDR_REORDER) then
+ -- destination address matches
+ RX_VALID_ADDR <= '1';
+ elsif (XGMII_RX_DATA1(47 downto 0) = x"FFFFFFFFFFFF") and (MAC_RX_CONFIG(1) = '1') then
+ -- accepts broadcast packets with the broadcast destination address FF:FF:FF:FF:FF:FF.
+ RX_VALID_ADDR <= '1';
+ elsif (XGMII_RX_DATA1(0) = '1') and (MAC_RX_CONFIG(2) = '1') then
+ -- accept multicast packets with the multicast bit set in the destination address.
+ -- '1' in the LSb of the first address byte.
+ RX_VALID_ADDR <= '1';
+ else
+ RX_VALID_ADDR <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+
+--//-- RX ETHERNET FRAME PARSING ---------------------------
+-- IEEE 802.1Q field, VLAN
+VLAN_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_VLAN <= '0';
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 2) then
+ -- 2nd word, check bytes 5:4
+ if(XGMII_RX_DATA1(47 downto 32) = x"0081") then
+ RX_VLAN <= '1';
+ else
+ RX_VLAN <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+--//-- MAC CONTROL PAUSE OPERATION ---------------------------
+-- As per IEEE 802.3-2015 clause 31
+-- See also Annex 31B.1
+PAUSE_OPCODE <= XGMII_RX_DATA1(55 downto 48) & XGMII_RX_DATA1(63 downto 56);
+MAC_CONTROL_PAUSE_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') and (MAC_CONTROL_PAUSE_ENABLE = '0') then
+ RX_CONTROL_PAUSE_VALID <= '0';
+ elsif(XGMII_RX_SOF1 = '1') then
+ -- Destination is always the globally assigned 48-bit multicast address 01-80-C2-00-00-01
+ if(XGMII_RX_DATA1(47 downto 0) = x"010000c28001") then
+ -- destination address matches
+ RX_CONTROL_PAUSE_VALID <= '1';
+ else
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 2) then
+ if(RX_LENGTH_TYPE_FIELD /= x"8808") then
+ -- not the expected type field for a MAC control message
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ if(PAUSE_OPCODE /= x"0001") then
+ -- not the expected PAUSE OpCode
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ elsif(MAC_RX_EOF2 = '1') and (RX_CRC_VALID2 = '0') then
+ -- BAD_CRC
+ RX_CONTROL_PAUSE_VALID <= '0';
+ end if;
+ end if;
+end process;
+-- confirm valid MAC control PAUSE message
+RX_CONTROL_PAUSE_VALID2 <= RX_CONTROL_PAUSE_VALID and RX_CRC_VALID2 and MAC_RX_EOF2;
+
+-- parse pause time
+MAC_CONTROL_PAUSE_002: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') and (MAC_CONTROL_PAUSE_ENABLE = '0') then
+ RX_CONTROL_PAUSE_VALID <= '0';
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 3) then
+ PAUSE_TIME <= XGMII_RX_DATA1(7 downto 0) & XGMII_RX_DATA1(15 downto 8);
+ end if;
+ end if;
+end process;
+
+-- TODO: enact tx pause
+
+--// RX 32-BIT CRC COMPUTATION -------------------------------------------------------
+-- 802.3 section 3.2.9:
+-- protected fields: payload data + optional pad + CRC (excludes preamble and start of frame sequence)
+
+-- The CRC32 component assumes the serial stream is packed into 64-bit words MSb of MSB first.
+-- Since XGMII_RX_DATA1 is packed LSb of LSB first, we need to re-order.
+-- Other reordering consideration: the CRC32 is computed with 'reflected' input bytes.
+-- In summary MSB <-> LSB
+REORDER_CRC32_INPUT: process(XGMII_RX_DATA1, XGMII_RX_DATA1_VALID)
+begin
+ for I in 0 to 63 loop
+ RX_CRC_DATA_IN(I) <= XGMII_RX_DATA1(63-I);
+ end loop;
+ for J in 0 to 7 loop
+ RX_CRC_DATA_VALID_IN(J) <= XGMII_RX_DATA1_VALID(7-J);
+ end loop;
+end process;
+
+RX_CRC_001: CRC32 PORT MAP (
+ CLK => CLK156g,
+ DATA_IN => RX_CRC_DATA_IN,
+ SOF_IN => XGMII_RX_SOF1,
+ SAMPLE_CLK_IN => XGMII_RX_SAMPLE1_CLK,
+ DATA_VALID_IN => RX_CRC_DATA_VALID_IN,
+ CRC_INITIALIZATION => x"FFFFFFFF",
+ CRC_OUT => RX_CRC1_D,
+ SAMPLE_CLK_OUT => open
+ );
+
+---- The CRC output must be 'reflected' and inverted.
+--REORDER_CRC32_OUTPUT: process(RX_CRC0)
+--begin
+-- for I in 0 to 31 loop
+-- RX_CRC(I) <= not RX_CRC0(31-I);
+-- end loop;
+--end process;
+
+-- when not reflected nor inverted, the correct value for RX_CRC0 is 0xC704DD7B
+-- (reflected/inverted: 0x2144DF1C)
+RX_CRC_VALID2 <= '1' when RX_CRC2 = x"C704DD7B" else '0';
+
+-- align data output with CRC computation output
+RECLOCK_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ XGMII_RX_DATA1_D <= XGMII_RX_DATA1;
+ XGMII_RX_DATA1_VALID_D <= XGMII_RX_DATA1_VALID;
+ XGMII_RX_SOF1_D <= XGMII_RX_SOF1;
+ XGMII_RX_EOF1_D <= XGMII_RX_EOF1;
+ XGMII_RX_SAMPLE1_CLK_D <= XGMII_RX_SAMPLE1_CLK;
+
+ MAC_RX_DATA2 <= XGMII_RX_DATA1_D;
+ MAC_RX_DATA2_VALID <= XGMII_RX_DATA1_VALID_D;
+ MAC_RX_SOF2 <= XGMII_RX_SOF1_D;
+ MAC_RX_EOF2 <= XGMII_RX_EOF1_D;
+ MAC_RX_SAMPLE2_CLK <= XGMII_RX_SAMPLE1_CLK_D;
+ RX_CRC2 <= RX_CRC1_D;
+
+ -- The entire frame validity is confirmed at the end of frame
+ -- (CRC check excluded in this partial report)
+ if (RX_TOO_SHORT = '0') and (RX_TOO_LONG = '0') and
+ (RX_VALID_ADDR = '1') and (RX_LENGTH_ERR = '0') then
+ MAC_RX_FRAME_VALID2A <= '1';
+ else
+ MAC_RX_FRAME_VALID2A <= '0';
+ end if;
+ end if;
+end process;
+MAC_RX_FRAME_VALID2 <= MAC_RX_FRAME_VALID2A and RX_CRC_VALID2;
+-- test test test
+FIRST_RXCRCERROR_FLAG_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ FIRST_RXCRCERROR_FLAG <= '0';
+ elsif(MAC_RX_EOF2 = '1') and (RX_CRC_VALID2 = '0') then
+ -- BAD_CRC
+ FIRST_RXCRCERROR_FLAG <= '0';
+ end if;
+ end if;
+end process;
+
+
+
+--// Length/type field check ----------------------
+RX_LENGTH_TYPE_FIELD <= XGMII_RX_DATA1(39 downto 32) & XGMII_RX_DATA1(47 downto 40); -- easier to read the expected 0x0800 0x0806 etc.
+LENGTH_CHECK_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_LENGTH_TYPEN <= '0';
+ elsif(XGMII_RX_SOF1 = '1') then
+ -- assume type field by default at the start of frame
+ RX_LENGTH_TYPEN <= '0'; -- length/type field represents a type. ignore the length value.
+ elsif(XGMII_RX_SAMPLE1_CLK = '1') and (RX_WORD_CNTR = 2) then
+ if(unsigned(RX_LENGTH_TYPE_FIELD(15 downto 11)) = 0) then
+ -- this field is interpreted as "Length" = client data field size
+ -- MSB first (802.3 section 3.2.6)
+ RX_LENGTH <= unsigned(RX_LENGTH_TYPE_FIELD(13 downto 0));
+ RX_LENGTH_TYPEN <= '1'; -- length/type field represents a length
+ else
+ -- this is an ethertype or 802.1q tag
+ RX_LENGTH_TYPEN <= '0'; -- length/type field represents a type. ignore the length value.
+ end if;
+ end if;
+ end if;
+end process;
+
+
+-- compute the difference between RX_BYTE_CNTR and RX_LENGTH (meaningless, but help minimize gates)
+RX_DIFF <= RX_BYTE_CNTR - RX_LENGTH;
+
+-- Length field consistency with actual rx frame length. Check if the length/type field is 'length'
+RX_LENGTH_ERR_GEN: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (SYNC_RESET156 = '1') then
+ RX_LENGTH_ERR <= '0';
+ elsif(RX_LENGTH_TYPEN = '0') then
+ -- type field. No explicit length info. Can't validate actual length.
+ RX_LENGTH_ERR <= '0';
+ elsif(XGMII_RX_EOF1 = '1') then
+ if ((RX_LENGTH <= 46) and (RX_VLAN = '0')) or
+ ((RX_LENGTH <= 42) and (RX_VLAN = '1')) then
+ -- short rx frame is padded to the minimum size of 60 bytes + 4 CRC
+ if(RX_BYTE_CNTR = 64) then
+ -- correct answer.
+ RX_LENGTH_ERR <= '0';
+ else
+ -- inconsistency
+ RX_LENGTH_ERR <= '1';
+ end if;
+ else
+ -- normal size frame. no pad.
+ if((RX_DIFF = 18) and (RX_VLAN = '0')) or
+ ((RX_DIFF = 22) and (RX_VLAN = '1'))then
+ -- correct answer.
+ RX_LENGTH_ERR <= '0';
+ else
+ -- inconsistency
+ RX_LENGTH_ERR <= '1';
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+
+
+--// VALID RX FRAME? ----------------------------------------------------------
+-- Is the rx frame valid? If so, confirm the wptr location.
+MAC_RX_VALID_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+
+ if(SYNC_RESET156 = '1') then
+ MAC_RX_WPTR_CONFIRMED <= (others => '0');
+ N_RX_BAD_CRCS_local <= (others => '0');
+ N_RX_FRAMES_TOO_SHORT_local <= (others => '0');
+ N_RX_FRAMES_TOO_LONG_local <= (others => '0');
+ N_RX_WRONG_ADDR_local <= (others => '0');
+ N_RX_LENGTH_ERRORS_local <= (others => '0');
+ else
+ if(MAC_RX_EOF2 = '1') then -- when CRC32 computation is ready
+ -- frame complete, all checks complete
+ N_RX_FRAMES_local <= N_RX_FRAMES_local + 1;
+
+ if(RX_CRC_VALID2 = '0') then
+ -- BAD_CRC
+ N_RX_BAD_CRCS_local <= N_RX_BAD_CRCS_local + 1;
+ end if;
+
+ if(RX_TOO_SHORT = '1') then
+ -- frame is too short (<64B)
+ N_RX_FRAMES_TOO_SHORT_local <= N_RX_FRAMES_TOO_SHORT_local + 1;
+ end if;
+
+ if(RX_TOO_LONG = '1') then
+ -- frame is too long
+ N_RX_FRAMES_TOO_LONG_local <= N_RX_FRAMES_TOO_LONG_local + 1;
+ end if;
+
+ if(RX_VALID_ADDR = '0') then
+ -- address does not match (and promiscuous mode is off)
+ N_RX_WRONG_ADDR_local <= N_RX_WRONG_ADDR_local + 1;
+ end if;
+
+ if(RX_LENGTH_ERR = '1') then
+ -- length field is inconsistent with actual rx frame length
+ N_RX_LENGTH_ERRORS_local <= N_RX_LENGTH_ERRORS_local + 1;
+ end if;
+
+-- if (RX_CRC_VALID = '1') and (RX_TOO_SHORT = '0') and (RX_TOO_LONG = '0') and (RX_VALID_ADDR = '1')
+-- and (RX_LENGTH_ERR = '0') then
+-- -- passed all checks
+-- RX_FRAME_TOGGLE3 <= not RX_FRAME_TOGGLE3; -- delineates VALID rx frames (does not toggle if rx frame was rejected)
+-- end if;
+
+ end if;
+ end if;
+ end if;
+end process;
+
+MAC_RX_VALID_002: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+ if (MAC_RX_EOF2 = '1') then
+ MAC_RX_EOF_TOGGLE <= not MAC_RX_EOF_TOGGLE;
+ end if;
+ end if;
+end process;
+
+-- to DIAGNOSTICS output (reclock with user CLK)
+MAC_RX_VALID_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ MAC_RX_EOF_TOGGLE_D <= MAC_RX_EOF_TOGGLE;
+ MAC_RX_EOF_TOGGLE_D2 <= MAC_RX_EOF_TOGGLE_D;
+
+ if(MAC_RX_EOF_TOGGLE_D /= MAC_RX_EOF_TOGGLE_D2) then
+ -- diagnostics were just updated. Safe to reclock with CLK now.
+ N_RX_FRAMES <= std_logic_vector(N_RX_FRAMES_local);
+ N_RX_BAD_CRCS <= std_logic_vector(N_RX_BAD_CRCS_local);
+ N_RX_FRAMES_TOO_SHORT <= std_logic_vector(N_RX_FRAMES_TOO_SHORT_local);
+ N_RX_FRAMES_TOO_LONG <= std_logic_vector(N_RX_FRAMES_TOO_LONG_local);
+ N_RX_WRONG_ADDR <= std_logic_vector(N_RX_WRONG_ADDR_local);
+ N_RX_LENGTH_ERRORS <= std_logic_vector(N_RX_LENGTH_ERRORS_local);
+ end if;
+ end if;
+end process;
+
+--// LOW-LATENCY RX OUTPUT ----------------------------------------------------------
+-- low-latency output case
+NO_RX_BUF_001: if(RX_BUFFER = '0') generate
+ MAC_RX_DATA <= MAC_RX_DATA2;
+ MAC_RX_DATA_VALID <= MAC_RX_DATA2_VALID;
+ MAC_RX_SOF <= MAC_RX_SOF2;
+ MAC_RX_EOF <= MAC_RX_EOF2;
+ MAC_RX_FRAME_VALID <= MAC_RX_FRAME_VALID2;
+end generate;
+
+--// RX INPUT ELASTIC BUFFER ----------------------------------------------------------
+RX_BUF_001: if(RX_BUFFER = '1') generate
+ -- The purpose of the elastic buffer is two-fold:
+ -- (a) a transition between the CLK156g synchronous PHY side and the CLK-synchronous user side.
+ -- (b) storage for receive packets, to absorb traffic peaks, minimize the number of
+ -- UDP packets lost at high throughput.
+ -- The rx elastic buffer is 16Kbits, large enough for a complete maximum size (14addr+1500data+4FCS = 1518B) frame.
+
+ -- write pointer management
+ MAC_RX_WPTR_001: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ MAC_RX_WPTR <= (others => '0');
+ else
+ if(MAC_RX_SAMPLE2_CLK = '1') and (MAC_RX_EOF2 = '0') then
+ MAC_RX_WPTR <= MAC_RX_WPTR + 1;
+ elsif (MAC_RX_EOF2 = '1') then
+ if(MAC_RX_FRAME_VALID2 = '1') then
+ -- valid frame
+ MAC_RX_WPTR <= MAC_RX_WPTR + 1;
+ else
+ -- faulty frame. rewind write pointer to the last confirmed location
+ MAC_RX_WPTR <= MAC_RX_WPTR_CONFIRMED;
+ end if;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ MAC_RX_WPTR_002: process(CLK156g)
+ begin
+ if rising_edge(CLK156g) then
+ if(SYNC_RESET156 = '1') then
+ MAC_RX_WPTR_CONFIRMED <= (others => '0');
+ elsif (MAC_RX_FRAME_VALID2 = '1') and (MAC_RX_EOF2 = '1') then
+ MAC_RX_WPTR_CONFIRMED <= MAC_RX_WPTR + 1;
+ end if;
+ end if;
+ end process;
+
+ -- concatenate data word, nbytes, sof, eof
+ MAC_RX_DIA <= MAC_RX_EOF2 & MAC_RX_SOF2 & MAC_RX_DATA2_VALID & MAC_RX_DATA2;
+
+ -- No need for initialization
+ -- cross clock domain from PHY CLK156g to user CLK
+ BRAM_DP2_002: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 74,
+ ADDR_WIDTHA => RX_BUFFER_ADDR_NBITS,
+ DATA_WIDTHB => 74,
+ ADDR_WIDTHB => RX_BUFFER_ADDR_NBITS
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK156g,
+ WEA => MAC_RX_SAMPLE2_CLK,
+ OEA => '0',
+ ADDRA => std_logic_vector(MAC_RX_WPTR),
+ DIA => std_logic_vector(MAC_RX_DIA),
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ OEB => '1',
+ ADDRB => std_logic_vector(MAC_RX_RPTR),
+ DIB => (others => '0'),
+ DOB => MAC_RX_DOB
+ );
+
+ MAC_RX_WPTR_003: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_RX_WPTR_CONFIRMED_D <= (others => '0');
+ elsif(MAC_RX_EOF_TOGGLE_D /= MAC_RX_EOF_TOGGLE_D2) then
+ -- MAC_RX_WPTR_CONFIRMED is stable. OK to resample with the CLK clock.
+ MAC_RX_WPTR_CONFIRMED_D <= MAC_RX_WPTR_CONFIRMED;
+ end if;
+ end if;
+ end process;
+
+ MAC_RX_BUF_SIZE <= MAC_RX_WPTR_CONFIRMED_D + not(MAC_RX_RPTR);
+ -- occupied tx buffer size
+
+ -- manage read pointer
+ MAC_RX_RPTR_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ MAC_RX_SAMPLE3_CLK <= MAC_RX_SAMPLE3_CLK_E; -- it takes one CLK to read data from the RAMB
+
+ if(SYNC_RESET = '1') then
+ MAC_RX_RPTR <= (others => '1');
+ MAC_RX_SAMPLE3_CLK_E <= '0';
+ elsif(MAC_RX_BUF_SIZE /= 0) and (MAC_RX_CTS = '1') then
+ MAC_RX_RPTR <= MAC_RX_RPTR + 1;
+ MAC_RX_SAMPLE3_CLK_E <= '1';
+ else
+ MAC_RX_SAMPLE3_CLK_E <= '0';
+ end if;
+ end if;
+ end process;
+
+ MAC_RX_DATA <= MAC_RX_DOB(63 downto 0);
+ MAC_RX_DATA_VALID <= MAC_RX_DOB(71 downto 64);
+ MAC_RX_SOF <= MAC_RX_DOB(72) and MAC_RX_SAMPLE3_CLK;
+ MAC_RX_EOF <= MAC_RX_DOB(73) and MAC_RX_SAMPLE3_CLK;
+
+end generate;
+
+--// TEST POINTS -------------------------
+--TP<= PHY_CONFIG_TP;
+TP_001: process(CLK156g)
+begin
+ if rising_edge(CLK156g) then
+-- if(XGMII_RX_START_LOC = "000") then
+-- TP(2) <= '1';
+-- else
+-- TP(2) <= '0';
+-- end if;
+-- if(XGMII_RXC /= x"FF") then
+-- TP(3) <= '1';
+-- else
+-- TP(3) <= '0';
+-- end if;
+-- if(XGMII_RXC = x"00") then
+-- TP(4) <= '1';
+-- else
+-- TP(4) <= '0';
+-- end if;
+-- TP(5) <= XGMII_RX_START_CHAR;
+-- TP(6) <= XGMII_RX_SFD_CHAR;
+-- TP(7) <= XGMII_RX_TERM_CHAR;
+
+-- if(XGMII_RXC(0) = '1') and (XGMII_RXD(7 downto 0) = x"FB") then
+-- TP(8) <= '1';
+-- else
+-- TP(8) <= '0';
+-- end if;
+-- if(XGMII_RXC(0) = '0') and (XGMII_RXD(63 downto 56) = x"D5") then
+-- TP(9) <= '1';
+-- else
+-- TP(9) <= '0';
+-- end if;
+---- TP(8) <= XGMII_RX_SOF1;
+---- TP(9) <= XGMII_RX_SAMPLE1_CLK;
+-- TP(10) <= XGMII_RX_SOF1;
+
+ TP(2) <= MAC_RX_EOF2;
+ TP(3) <= MAC_RX_EOF2 and MAC_RX_FRAME_VALID2;
+ TP(4) <= RX_CRC_VALID2;
+ TP(5) <= XGMII_RX_SOF1;
+ TP(6) <= XGMII_RX_SAMPLE1_CLK;
+ if(XGMII_RXC /= x"FF") then
+ TP(7) <= '1';
+ else
+ TP(7) <= '0';
+ end if;
+ if(XGMII_RX_DATA1_VALID /= x"00") then
+ TP(8) <= '1';
+ else
+ TP(8) <= '0';
+ end if;
+ if(XGMII_RX_DATA1_VALID = x"FF") then
+ TP(9) <= '1';
+ else
+ TP(9) <= '0';
+ end if;
+
+ end if;
+end process;
+
+end Behavioral;
+
diff --git a/generic_ip/third_party_ip/mac/src/crc32.vhd b/generic_ip/third_party_ip/mac/src/crc32.vhd
new file mode 100644
index 0000000..3005747
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32.vhd
@@ -0,0 +1,236 @@
+-------------------------------------------------------------
+-- Filename: CRC32.VHD
+-- Authors:
+-- Alain Zarembowitch / MSS
+-- Version: Rev 1
+-- Last modified: 8/6/18
+-- Inheritance: n/a
+--
+-- description: high-speed generation of 32-bit CRC32 (optimized for 10G Ethernet 64-bit words)
+-- Data bit order: MSb of MSB is first sent/received
+-- Algorithm based on seminal paper "High Performance Table-Based Algorithm for Pipelined CRC Calculation",
+-- by Yan Sun and Min Sik Kim
+-- Verified by comparing with the crc calculator at http://www.sunshine2k.de/coding/javascript/crc/crc_js.html
+--
+-- Rev 1 8/6/18 AZ
+-- Added one extra stage of pipelining for better timing
+--
+-------------------------------------------
+-- Device utilization
+-------------------------------------------
+-- FF: 188
+-- LUT: 682
+-- 18Kb block RAMs: 0
+-- DSP: 0
+-- GCLK: 1
+-- Minimum period: 4.836ns (Maximum Frequency: 206.782MHz) Artix7-100T -1 speed grade
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32 is
+ Port (
+ CLK : IN std_logic;
+ DATA_IN: in std_logic_vector(63 downto 0);
+ -- Natural order (as if input to a standard LFSR), i.e. not inverted, not reversed.
+ -- order: MSb of MSB is first serialized bit
+ -- Special case: when last word is less than 8 bytes, bytes are left-aligned (MSB first) and lower byte(s) are ignored.
+ SAMPLE_CLK_IN: in std_logic;
+ -- read DATA_IN at the rising_edge of CLK when SAMPLE_CLK_IN = '1'
+ SOF_IN: in std_logic;
+ -- 1-CLK wide pulse marks the first word in a message. Initializes the CRC to all zero
+ -- aligned with SAMPLE_CLK_IN
+ DATA_VALID_IN : IN std_logic_vector(7 downto 0);
+ -- Valid bytes in DATA_IN.
+ -- Valid inputs: 0x00,80 (one MSB byte),C0,E0,F0,F8,FC,FE,FF (8 bytes)
+ CRC_INITIALIZATION: in std_logic_vector(31 downto 0);
+ -- typically 0xFFFFFFFF. Read at SOF_IN = '1'
+ CRC_OUT: out std_logic_vector(31 downto 0);
+ -- Natural order (as in the flip-flop values of a standard LFSR), i.e. not inverted, not reversed.
+ SAMPLE_CLK_OUT: out std_logic
+ -- latency 2 CLKs after SAMPLE_CLK_IN
+ );
+end entity;
+
+architecture Behavioral of CRC32 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT CRC32_LUT1
+ PORT(
+ CLK : IN std_logic;
+ DATA_IN : IN std_logic_vector(31 downto 0);
+ SAMPLE_CLK_IN : IN std_logic;
+ CRC_OUT : OUT std_logic_vector(31 downto 0);
+ SAMPLE_CLK_OUT : OUT std_logic
+ );
+ END COMPONENT;
+
+ COMPONENT CRC32_LUT2
+ PORT(
+ CLK : IN std_logic;
+ DATA_IN : IN std_logic_vector(31 downto 0);
+ SAMPLE_CLK_IN : IN std_logic;
+ CRC_OUT : OUT std_logic_vector(31 downto 0);
+ SAMPLE_CLK_OUT : OUT std_logic
+ );
+ END COMPONENT;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal DATA1: std_logic_vector(63 downto 0) := (others => '0');
+signal DATA1_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal DATA2: std_logic_vector(63 downto 0) := (others => '0');
+signal DATA12: std_logic_vector(63 downto 0) := (others => '0');
+signal SAMPLE1_CLK: std_logic := '0';
+signal SAMPLE1_CLK_D: std_logic := '0';
+signal SAMPLE1_CLK_D2: std_logic := '0';
+signal SOF1: std_logic := '0';
+signal SOF1_D: std_logic := '0';
+signal CRC1: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC2: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC12: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC12_D: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC12_FROZEN: std_logic_vector(31 downto 0) := (others => '0');
+
+
+
+signal CRC3: std_logic_vector(31 downto 0) := (others => '0');
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Special case: when last word is less than 8 bytes, input bytes are left-aligned (MSB first) and lower byte(s) are ignored.
+-- partial last word case: reorder last word so that bytes are right aligned
+REORDER_01: process(CLK)
+begin
+ if rising_edge(CLK) then
+ SAMPLE1_CLK <= SAMPLE_CLK_IN;
+ DATA1_VALID <= DATA_VALID_IN;
+ SOF1 <= SOF_IN;
+
+ if(SAMPLE_CLK_IN = '1') then
+-- if(DATA_VALID_IN(7) = '0') then
+-- DATA1 <= (others => '0');
+-- elsif(DATA_VALID_IN(6) = '0') then
+-- DATA1 <= x"00000000000000" & DATA_IN(63 downto 56); -- last word contains 1 byte
+-- elsif(DATA_VALID_IN(5) = '0') then
+-- DATA1 <= x"000000000000" & DATA_IN(63 downto 48); -- last word
+-- elsif(DATA_VALID_IN(4) = '0') then
+-- DATA1 <= x"0000000000" & DATA_IN(63 downto 40); -- last word
+-- elsif(DATA_VALID_IN(3) = '0') then
+-- DATA1 <= x"00000000" & DATA_IN(63 downto 32); -- last word
+-- elsif(DATA_VALID_IN(2) = '0') then
+-- DATA1 <= x"000000" & DATA_IN(63 downto 24); -- last word
+-- elsif(DATA_VALID_IN(1) = '0') then
+-- DATA1 <= x"0000" & DATA_IN(63 downto 16); -- last word
+-- elsif(DATA_VALID_IN(0) = '0') then
+-- DATA1 <= x"00" & DATA_IN(63 downto 8); -- last word
+-- else
+-- DATA1 <= DATA_IN(63 downto 0); -- full 8-byte input word
+-- end if;
+-- slightly better rephrasing below
+ case DATA_VALID_IN is
+ when "11111111" => DATA1 <= DATA_IN(63 downto 0); -- full 8-byte input word
+ when "11111110" => DATA1 <= x"00" & DATA_IN(63 downto 8); -- last word
+ when "11111100" => DATA1 <= x"0000" & DATA_IN(63 downto 16); -- last word
+ when "11111000" => DATA1 <= x"000000" & DATA_IN(63 downto 24); -- last word
+ when "11110000" => DATA1 <= x"00000000" & DATA_IN(63 downto 32); -- last word
+ when "11100000" => DATA1 <= x"0000000000" & DATA_IN(63 downto 40); -- last word
+ when "11000000" => DATA1 <= x"000000000000" & DATA_IN(63 downto 48); -- last word
+ when "10000000" => DATA1 <= x"00000000000000" & DATA_IN(63 downto 56); -- last word contains 1 byte
+ when others => DATA1 <= (others => '0');
+ end case;
+ end if;
+ end if;
+end process;
+
+-- CRC32 look-up table
+-- Latency: 1 CLK (from table address DATA_IN to table output CRC_OUT)
+-- lower 32-bits
+LUT1_001: CRC32_LUT1 PORT MAP (
+ CLK => CLK,
+ DATA_IN => DATA12(31 downto 0),
+ SAMPLE_CLK_IN => SAMPLE1_CLK,
+ CRC_OUT => CRC1,
+ SAMPLE_CLK_OUT => SAMPLE1_CLK_D
+ );
+-- upper 32-bits. LUT2 shifts the input by x^32
+-- Latency: 1 CLK (from table address DATA_IN to table output CRC_OUT)
+LUT2_001: CRC32_LUT2 PORT MAP (
+ CLK => CLK,
+ DATA_IN => DATA12(63 downto 32),
+ SAMPLE_CLK_IN => SAMPLE1_CLK,
+ CRC_OUT => CRC2,
+ SAMPLE_CLK_OUT => open
+ );
+CRC12 <= CRC1 xor CRC2; -- this is the CRC[DATA_IN(63:0)]
+
+-- freeze CRC12 (otherwise algorithm runs amok) immediately at the LUT output (without waiting for next rising edge)
+FREEZE_CRC12_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SAMPLE1_CLK_D = '1') then
+ CRC12_D <= CRC12;
+ end if;
+ end if;
+end process;
+CRC12_FROZEN <= CRC_INITIALIZATION when (SOF1 = '1') else -- initialize CRC to zero at the first input word
+ CRC12 when (SAMPLE1_CLK_D = '1') else
+ CRC12_D;
+
+-- last word special case. Add left-over bytes from last word CRC
+DATA2_GEN_001: process(CRC12_FROZEN, DATA1_VALID)
+begin
+ if(DATA1_VALID(7) = '0') then
+ DATA2 <= (others => '0');
+ elsif(DATA1_VALID(6) = '0') then
+ DATA2 <= x"00000000000000" & CRC12_FROZEN(31 downto 24); -- last input word contains 1 byte
+ elsif(DATA1_VALID(5) = '0') then
+ DATA2 <= x"000000000000" & CRC12_FROZEN(31 downto 16); -- last input word contains 2 bytes
+ elsif(DATA1_VALID(4) = '0') then
+ DATA2 <= x"0000000000" & CRC12_FROZEN(31 downto 8); -- last input word contains 3 bytes
+ elsif(DATA1_VALID(3) = '0') then
+ DATA2 <= x"00000000" & CRC12_FROZEN(31 downto 0);
+ elsif(DATA1_VALID(2) = '0') then
+ DATA2 <= x"000000" & CRC12_FROZEN(31 downto 0) & x"00";
+ elsif(DATA1_VALID(1) = '0') then
+ DATA2 <= x"0000" & CRC12_FROZEN(31 downto 0) & x"0000";
+ elsif(DATA1_VALID(0) = '0') then
+ DATA2 <= x"00" & CRC12_FROZEN(31 downto 0) & x"000000";
+ else
+ DATA2 <= CRC12_FROZEN(31 downto 0) & x"00000000";
+ end if;
+end process;
+
+DATA12 <= DATA1 xor DATA2;
+
+
+CRC3_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SAMPLE1_CLK = '1') then
+ if(DATA1_VALID(7) = '0') then
+ CRC3 <= (others => '0');
+ elsif(DATA1_VALID(6) = '0') then
+ CRC3 <= CRC12_FROZEN(23 downto 0) & x"00"; -- last input word contains 1 byte
+ elsif(DATA1_VALID(5) = '0') then
+ CRC3 <= CRC12_FROZEN(15 downto 0) & x"0000"; -- last input word contains 2 bytes
+ elsif(DATA1_VALID(4) = '0') then
+ CRC3 <= CRC12_FROZEN(7 downto 0) & x"000000"; -- last input word contains 3 bytes
+ else
+ CRC3 <= (others => '0');
+ end if;
+ end if;
+ end if;
+end process;
+
+-- outputs
+CRC_OUT <= CRC12_FROZEN xor CRC3;
+SAMPLE_CLK_OUT <= SAMPLE1_CLK_D;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/crc32_lut1.vhd b/generic_ip/third_party_ip/mac/src/crc32_lut1.vhd
new file mode 100644
index 0000000..4413c03
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32_lut1.vhd
@@ -0,0 +1,118 @@
+-------------------------------------------------------------
+-- Filename: CRC32_LUT1.VHD
+-- Authors:
+-- Alain Zarembowitch / MSS
+-- Version: Rev 0
+-- Last modified: 2/25/18
+-- Inheritance: n/a
+--
+-- description: 32-bit CRC lookup table
+-- Actually comprised of 4 small (256 entries) tables, one for each input byte
+-- Data bit order: MSb of MSB is first sent/received
+-- Algorithm based on seminal paper "High Performance Table-Based Algorithm for Pipelined CRC Calculation",
+-- by Yan Sun and Min Sik Kim
+-- CRC_OUT only depends on DATA_IN. The algorithm is thus memoryless.
+-- Verified by comparing with the crc calculator at http://www.sunshine2k.de/coding/javascript/crc/crc_js.html
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32_LUT1 is
+ Port (
+ CLK : IN std_logic;
+ DATA_IN: in std_logic_vector(31 downto 0);
+ -- Natural order (as if input to a standard LFSR), i.e. not inverted, not reversed.
+ -- order: MSb of MSB is first serialized bit
+ SAMPLE_CLK_IN: in std_logic;
+ -- read DATA_IN at the rising_edge of CLK when SAMPLE_CLK_IN = '1'
+ CRC_OUT: out std_logic_vector(31 downto 0);
+ -- Natural order (as if the flip-flop values of a standard LFSR), i.e. not inverted, not reversed.
+ SAMPLE_CLK_OUT: out std_logic
+ -- latency 1 CLK after SAMPLE_CLK_IN
+ );
+end entity;
+
+architecture Behavioral of CRC32_LUT1 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT CRC32_LUT1ab
+ GENERIC (
+ DATA_WIDTH: integer;
+ ADDR_WIDTH: integer
+ );
+ PORT(
+ ADDRA : IN std_logic_vector(8 downto 0);
+ ADDRB : IN std_logic_vector(8 downto 0);
+ DOA : OUT std_logic_vector(31 downto 0);
+ DOB : OUT std_logic_vector(31 downto 0)
+ );
+ END COMPONENT;
+
+ COMPONENT CRC32_LUT1cd
+ GENERIC (
+ DATA_WIDTH: integer;
+ ADDR_WIDTH: integer
+ );
+ PORT(
+ ADDRA : IN std_logic_vector(8 downto 0);
+ ADDRB : IN std_logic_vector(8 downto 0);
+ DOA : OUT std_logic_vector(31 downto 0);
+ DOB : OUT std_logic_vector(31 downto 0)
+ );
+ END COMPONENT;
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal ADDR0: std_logic_vector(8 downto 0) := (others => '0');
+signal ADDR1: std_logic_vector(8 downto 0) := (others => '0');
+signal ADDR2: std_logic_vector(8 downto 0) := (others => '0');
+signal ADDR3: std_logic_vector(8 downto 0) := (others => '0');
+signal CRC0: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC1: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC2: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC3: std_logic_vector(31 downto 0) := (others => '0');
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- input bytes 0(A-side) and 1 (B-side)
+-- Latency: 0 CLK after
+ADDR0 <= '0' & DATA_IN(7 downto 0); -- order: LSB (last received)
+ADDR1 <= '1' & DATA_IN(15 downto 8);
+CRC32_LUT1ab_001: CRC32_LUT1ab
+GENERIC MAP(
+ DATA_WIDTH => 32,
+ ADDR_WIDTH => 9)
+PORT MAP(
+ ADDRA => ADDR0,
+ DOA => CRC0,
+ ADDRB => ADDR1,
+ DOB => CRC1
+);
+
+ADDR2 <= '0' & DATA_IN(23 downto 16);
+ADDR3 <= '1' & DATA_IN(31 downto 24); -- order: MSb of MSB received first
+CRC32_LUT1cd_001: CRC32_LUT1cd
+GENERIC MAP(
+ DATA_WIDTH => 32,
+ ADDR_WIDTH => 9)
+PORT MAP(
+ ADDRA => ADDR2,
+ DOA => CRC2,
+ ADDRB => ADDR3,
+ DOB => CRC3
+);
+
+
+RECLOCK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ CRC_OUT <= CRC0 xor CRC1 xor CRC2 xor CRC3;
+ SAMPLE_CLK_OUT <= SAMPLE_CLK_IN;
+ end if;
+end process;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/crc32_lut1ab.vhd b/generic_ip/third_party_ip/mac/src/crc32_lut1ab.vhd
new file mode 100644
index 0000000..2a6d397
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32_lut1ab.vhd
@@ -0,0 +1,134 @@
+-------------------------------------------------------------
+-- Filename: CRC32_LUT1ab.VHD
+-- Authors:
+-- from http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_4/xst_v6s6.pdf p262
+-- Alain Zarembowitch / MSS
+-- Version: Rev 0
+-- Last modified: 12/13/17
+-- Inheritance: ROM1.vhd 8/24/16
+--
+-- description: synthesizable generic dual port ROM containing two tables of 256 CRC32s values each
+-- (called LUT1a and LUT1b)
+-- The tables are generated by the Java application crc32tables in the /java folder
+-- LUT1a computes the CRC32s for inputs in the form 00 00 00 x, where x is the LSB (last received byte)
+-- LUT1b computes the CRC32s for inputs in the form 00 00 x 00
+-- Data bit order: MSb of MSB is first sent/received
+-- Note: the returned crc values are NOT inverted and NOT reflected left-right. They are as they would appear
+-- when generated by a standard LFSR
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32_LUT1ab is
+ Generic (
+ DATA_WIDTH: integer := 32;
+ ADDR_WIDTH: integer := 9
+ );
+ Port (
+ -- Port A
+ ADDRA : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1a at addresses 0 - 255
+ -- LUT1b at addresses 256 - 511
+ DOA : out std_logic_vector(DATA_WIDTH-1 downto 0);
+
+ -- Port B
+ ADDRB : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1a at addresses 0 - 255
+ -- LUT1b at addresses 256 - 511
+ DOB : out std_logic_vector(DATA_WIDTH-1 downto 0)
+ );
+end entity;
+
+architecture Behavioral of CRC32_LUT1ab is
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- inferred rom
+signal DOA_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+signal DOB_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+type ROM_TYPE is array ( (2**ADDR_WIDTH)-1 downto 0 ) of std_logic_vector(DATA_WIDTH-1 downto 0);
+-- IMPORTANT ORDER INFORMATION: the table below is read from bottom to top and right to left. Thus
+-- to restore a common-sense order, address bits are inverted.
+constant ROM : ROM_TYPE := (
+-- LUT1a
+x"00000000", x"04C11DB7", x"09823B6E", x"0D4326D9", x"130476DC", x"17C56B6B", x"1A864DB2", x"1E475005",
+x"2608EDB8", x"22C9F00F", x"2F8AD6D6", x"2B4BCB61", x"350C9B64", x"31CD86D3", x"3C8EA00A", x"384FBDBD",
+x"4C11DB70", x"48D0C6C7", x"4593E01E", x"4152FDA9", x"5F15ADAC", x"5BD4B01B", x"569796C2", x"52568B75",
+x"6A1936C8", x"6ED82B7F", x"639B0DA6", x"675A1011", x"791D4014", x"7DDC5DA3", x"709F7B7A", x"745E66CD",
+x"9823B6E0", x"9CE2AB57", x"91A18D8E", x"95609039", x"8B27C03C", x"8FE6DD8B", x"82A5FB52", x"8664E6E5",
+x"BE2B5B58", x"BAEA46EF", x"B7A96036", x"B3687D81", x"AD2F2D84", x"A9EE3033", x"A4AD16EA", x"A06C0B5D",
+x"D4326D90", x"D0F37027", x"DDB056FE", x"D9714B49", x"C7361B4C", x"C3F706FB", x"CEB42022", x"CA753D95",
+x"F23A8028", x"F6FB9D9F", x"FBB8BB46", x"FF79A6F1", x"E13EF6F4", x"E5FFEB43", x"E8BCCD9A", x"EC7DD02D",
+x"34867077", x"30476DC0", x"3D044B19", x"39C556AE", x"278206AB", x"23431B1C", x"2E003DC5", x"2AC12072",
+x"128E9DCF", x"164F8078", x"1B0CA6A1", x"1FCDBB16", x"018AEB13", x"054BF6A4", x"0808D07D", x"0CC9CDCA",
+x"7897AB07", x"7C56B6B0", x"71159069", x"75D48DDE", x"6B93DDDB", x"6F52C06C", x"6211E6B5", x"66D0FB02",
+x"5E9F46BF", x"5A5E5B08", x"571D7DD1", x"53DC6066", x"4D9B3063", x"495A2DD4", x"44190B0D", x"40D816BA",
+x"ACA5C697", x"A864DB20", x"A527FDF9", x"A1E6E04E", x"BFA1B04B", x"BB60ADFC", x"B6238B25", x"B2E29692",
+x"8AAD2B2F", x"8E6C3698", x"832F1041", x"87EE0DF6", x"99A95DF3", x"9D684044", x"902B669D", x"94EA7B2A",
+x"E0B41DE7", x"E4750050", x"E9362689", x"EDF73B3E", x"F3B06B3B", x"F771768C", x"FA325055", x"FEF34DE2",
+x"C6BCF05F", x"C27DEDE8", x"CF3ECB31", x"CBFFD686", x"D5B88683", x"D1799B34", x"DC3ABDED", x"D8FBA05A",
+x"690CE0EE", x"6DCDFD59", x"608EDB80", x"644FC637", x"7A089632", x"7EC98B85", x"738AAD5C", x"774BB0EB",
+x"4F040D56", x"4BC510E1", x"46863638", x"42472B8F", x"5C007B8A", x"58C1663D", x"558240E4", x"51435D53",
+x"251D3B9E", x"21DC2629", x"2C9F00F0", x"285E1D47", x"36194D42", x"32D850F5", x"3F9B762C", x"3B5A6B9B",
+x"0315D626", x"07D4CB91", x"0A97ED48", x"0E56F0FF", x"1011A0FA", x"14D0BD4D", x"19939B94", x"1D528623",
+x"F12F560E", x"F5EE4BB9", x"F8AD6D60", x"FC6C70D7", x"E22B20D2", x"E6EA3D65", x"EBA91BBC", x"EF68060B",
+x"D727BBB6", x"D3E6A601", x"DEA580D8", x"DA649D6F", x"C423CD6A", x"C0E2D0DD", x"CDA1F604", x"C960EBB3",
+x"BD3E8D7E", x"B9FF90C9", x"B4BCB610", x"B07DABA7", x"AE3AFBA2", x"AAFBE615", x"A7B8C0CC", x"A379DD7B",
+x"9B3660C6", x"9FF77D71", x"92B45BA8", x"9675461F", x"8832161A", x"8CF30BAD", x"81B02D74", x"857130C3",
+x"5D8A9099", x"594B8D2E", x"5408ABF7", x"50C9B640", x"4E8EE645", x"4A4FFBF2", x"470CDD2B", x"43CDC09C",
+x"7B827D21", x"7F436096", x"7200464F", x"76C15BF8", x"68860BFD", x"6C47164A", x"61043093", x"65C52D24",
+x"119B4BE9", x"155A565E", x"18197087", x"1CD86D30", x"029F3D35", x"065E2082", x"0B1D065B", x"0FDC1BEC",
+x"3793A651", x"3352BBE6", x"3E119D3F", x"3AD08088", x"2497D08D", x"2056CD3A", x"2D15EBE3", x"29D4F654",
+x"C5A92679", x"C1683BCE", x"CC2B1D17", x"C8EA00A0", x"D6AD50A5", x"D26C4D12", x"DF2F6BCB", x"DBEE767C",
+x"E3A1CBC1", x"E760D676", x"EA23F0AF", x"EEE2ED18", x"F0A5BD1D", x"F464A0AA", x"F9278673", x"FDE69BC4",
+x"89B8FD09", x"8D79E0BE", x"803AC667", x"84FBDBD0", x"9ABC8BD5", x"9E7D9662", x"933EB0BB", x"97FFAD0C",
+x"AFB010B1", x"AB710D06", x"A6322BDF", x"A2F33668", x"BCB4666D", x"B8757BDA", x"B5365D03", x"B1F740B4",
+-- LUT1b
+x"00000000", x"D219C1DC", x"A0F29E0F", x"72EB5FD3", x"452421A9", x"973DE075", x"E5D6BFA6", x"37CF7E7A",
+x"8A484352", x"5851828E", x"2ABADD5D", x"F8A31C81", x"CF6C62FB", x"1D75A327", x"6F9EFCF4", x"BD873D28",
+x"10519B13", x"C2485ACF", x"B0A3051C", x"62BAC4C0", x"5575BABA", x"876C7B66", x"F58724B5", x"279EE569",
+x"9A19D841", x"4800199D", x"3AEB464E", x"E8F28792", x"DF3DF9E8", x"0D243834", x"7FCF67E7", x"ADD6A63B",
+x"20A33626", x"F2BAF7FA", x"8051A829", x"524869F5", x"6587178F", x"B79ED653", x"C5758980", x"176C485C",
+x"AAEB7574", x"78F2B4A8", x"0A19EB7B", x"D8002AA7", x"EFCF54DD", x"3DD69501", x"4F3DCAD2", x"9D240B0E",
+x"30F2AD35", x"E2EB6CE9", x"9000333A", x"4219F2E6", x"75D68C9C", x"A7CF4D40", x"D5241293", x"073DD34F",
+x"BABAEE67", x"68A32FBB", x"1A487068", x"C851B1B4", x"FF9ECFCE", x"2D870E12", x"5F6C51C1", x"8D75901D",
+x"41466C4C", x"935FAD90", x"E1B4F243", x"33AD339F", x"04624DE5", x"D67B8C39", x"A490D3EA", x"76891236",
+x"CB0E2F1E", x"1917EEC2", x"6BFCB111", x"B9E570CD", x"8E2A0EB7", x"5C33CF6B", x"2ED890B8", x"FCC15164",
+x"5117F75F", x"830E3683", x"F1E56950", x"23FCA88C", x"1433D6F6", x"C62A172A", x"B4C148F9", x"66D88925",
+x"DB5FB40D", x"094675D1", x"7BAD2A02", x"A9B4EBDE", x"9E7B95A4", x"4C625478", x"3E890BAB", x"EC90CA77",
+x"61E55A6A", x"B3FC9BB6", x"C117C465", x"130E05B9", x"24C17BC3", x"F6D8BA1F", x"8433E5CC", x"562A2410",
+x"EBAD1938", x"39B4D8E4", x"4B5F8737", x"994646EB", x"AE893891", x"7C90F94D", x"0E7BA69E", x"DC626742",
+x"71B4C179", x"A3AD00A5", x"D1465F76", x"035F9EAA", x"3490E0D0", x"E689210C", x"94627EDF", x"467BBF03",
+x"FBFC822B", x"29E543F7", x"5B0E1C24", x"8917DDF8", x"BED8A382", x"6CC1625E", x"1E2A3D8D", x"CC33FC51",
+x"828CD898", x"50951944", x"227E4697", x"F067874B", x"C7A8F931", x"15B138ED", x"675A673E", x"B543A6E2",
+x"08C49BCA", x"DADD5A16", x"A83605C5", x"7A2FC419", x"4DE0BA63", x"9FF97BBF", x"ED12246C", x"3F0BE5B0",
+x"92DD438B", x"40C48257", x"322FDD84", x"E0361C58", x"D7F96222", x"05E0A3FE", x"770BFC2D", x"A5123DF1",
+x"189500D9", x"CA8CC105", x"B8679ED6", x"6A7E5F0A", x"5DB12170", x"8FA8E0AC", x"FD43BF7F", x"2F5A7EA3",
+x"A22FEEBE", x"70362F62", x"02DD70B1", x"D0C4B16D", x"E70BCF17", x"35120ECB", x"47F95118", x"95E090C4",
+x"2867ADEC", x"FA7E6C30", x"889533E3", x"5A8CF23F", x"6D438C45", x"BF5A4D99", x"CDB1124A", x"1FA8D396",
+x"B27E75AD", x"6067B471", x"128CEBA2", x"C0952A7E", x"F75A5404", x"254395D8", x"57A8CA0B", x"85B10BD7",
+x"383636FF", x"EA2FF723", x"98C4A8F0", x"4ADD692C", x"7D121756", x"AF0BD68A", x"DDE08959", x"0FF94885",
+x"C3CAB4D4", x"11D37508", x"63382ADB", x"B121EB07", x"86EE957D", x"54F754A1", x"261C0B72", x"F405CAAE",
+x"4982F786", x"9B9B365A", x"E9706989", x"3B69A855", x"0CA6D62F", x"DEBF17F3", x"AC544820", x"7E4D89FC",
+x"D39B2FC7", x"0182EE1B", x"7369B1C8", x"A1707014", x"96BF0E6E", x"44A6CFB2", x"364D9061", x"E45451BD",
+x"59D36C95", x"8BCAAD49", x"F921F29A", x"2B383346", x"1CF74D3C", x"CEEE8CE0", x"BC05D333", x"6E1C12EF",
+x"E36982F2", x"3170432E", x"439B1CFD", x"9182DD21", x"A64DA35B", x"74546287", x"06BF3D54", x"D4A6FC88",
+x"6921C1A0", x"BB38007C", x"C9D35FAF", x"1BCA9E73", x"2C05E009", x"FE1C21D5", x"8CF77E06", x"5EEEBFDA",
+x"F33819E1", x"2121D83D", x"53CA87EE", x"81D34632", x"B61C3848", x"6405F994", x"16EEA647", x"C4F7679B",
+x"79705AB3", x"AB699B6F", x"D982C4BC", x"0B9B0560", x"3C547B1A", x"EE4DBAC6", x"9CA6E515", x"4EBF24C9"
+ );
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Port A read
+DOA <= ROM(to_integer(unsigned(not ADDRA))); -- see IMPORTANT ORDER INFORMATION above
+
+
+-- Port B read
+DOB <= ROM(to_integer(unsigned(not ADDRB))); -- see IMPORTANT ORDER INFORMATION above
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/crc32_lut1cd.vhd b/generic_ip/third_party_ip/mac/src/crc32_lut1cd.vhd
new file mode 100644
index 0000000..4b13647
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32_lut1cd.vhd
@@ -0,0 +1,134 @@
+-------------------------------------------------------------
+-- Filename: CRC32_LUT1cd.VHD
+-- Authors:
+-- from http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_4/xst_v6s6.pdf p262
+-- Alain Zarembowitch / MSS
+-- Version: Rev 0
+-- Last modified: 12/13/17
+-- Inheritance: ROM1.vhd 8/24/16
+--
+-- description: synthesizable generic dual port ROM containing two tables of 256 CRC32s values each
+-- (called LUT1c and LUT1d)
+-- The tables are generated by the Java application crc32tables in the /java folder
+-- LUT1c computes the CRC32s for inputs in the form 00 x 00 00
+-- LUT1d computes the CRC32s for inputs in the form y 00 00 00, where y is the MSB
+-- Data bit order: MSb of MSB is first sent/received
+-- Note: the returned crc values are NOT inverted and NOT reflected left-right. They are as they would appear
+-- when generated by a standard LFSR
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32_LUT1cd is
+ Generic (
+ DATA_WIDTH: integer := 32;
+ ADDR_WIDTH: integer := 9
+ );
+ Port (
+ -- Port A
+ ADDRA : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1c at addresses 0 - 255
+ -- LUT1d at addresses 256 - 511
+ DOA : out std_logic_vector(DATA_WIDTH-1 downto 0);
+
+ -- Port B
+ ADDRB : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1c at addresses 0 - 255
+ -- LUT1d at addresses 256 - 511
+ DOB : out std_logic_vector(DATA_WIDTH-1 downto 0)
+ );
+end entity;
+
+architecture Behavioral of CRC32_LUT1cd is
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- inferred rom
+signal DOA_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+signal DOB_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+type ROM_TYPE is array ( (2**ADDR_WIDTH)-1 downto 0 ) of std_logic_vector(DATA_WIDTH-1 downto 0);
+-- IMPORTANT ORDER INFORMATION: the table below is read from bottom to top and right to left. Thus
+-- to restore a common-sense order, address bits are inverted.
+constant ROM : ROM_TYPE := (
+-- LUT1c
+x"00000000", x"01D8AC87", x"03B1590E", x"0269F589", x"0762B21C", x"06BA1E9B", x"04D3EB12", x"050B4795",
+x"0EC56438", x"0F1DC8BF", x"0D743D36", x"0CAC91B1", x"09A7D624", x"087F7AA3", x"0A168F2A", x"0BCE23AD",
+x"1D8AC870", x"1C5264F7", x"1E3B917E", x"1FE33DF9", x"1AE87A6C", x"1B30D6EB", x"19592362", x"18818FE5",
+x"134FAC48", x"129700CF", x"10FEF546", x"112659C1", x"142D1E54", x"15F5B2D3", x"179C475A", x"1644EBDD",
+x"3B1590E0", x"3ACD3C67", x"38A4C9EE", x"397C6569", x"3C7722FC", x"3DAF8E7B", x"3FC67BF2", x"3E1ED775",
+x"35D0F4D8", x"3408585F", x"3661ADD6", x"37B90151", x"32B246C4", x"336AEA43", x"31031FCA", x"30DBB34D",
+x"269F5890", x"2747F417", x"252E019E", x"24F6AD19", x"21FDEA8C", x"2025460B", x"224CB382", x"23941F05",
+x"285A3CA8", x"2982902F", x"2BEB65A6", x"2A33C921", x"2F388EB4", x"2EE02233", x"2C89D7BA", x"2D517B3D",
+x"762B21C0", x"77F38D47", x"759A78CE", x"7442D449", x"714993DC", x"70913F5B", x"72F8CAD2", x"73206655",
+x"78EE45F8", x"7936E97F", x"7B5F1CF6", x"7A87B071", x"7F8CF7E4", x"7E545B63", x"7C3DAEEA", x"7DE5026D",
+x"6BA1E9B0", x"6A794537", x"6810B0BE", x"69C81C39", x"6CC35BAC", x"6D1BF72B", x"6F7202A2", x"6EAAAE25",
+x"65648D88", x"64BC210F", x"66D5D486", x"670D7801", x"62063F94", x"63DE9313", x"61B7669A", x"606FCA1D",
+x"4D3EB120", x"4CE61DA7", x"4E8FE82E", x"4F5744A9", x"4A5C033C", x"4B84AFBB", x"49ED5A32", x"4835F6B5",
+x"43FBD518", x"4223799F", x"404A8C16", x"41922091", x"44996704", x"4541CB83", x"47283E0A", x"46F0928D",
+x"50B47950", x"516CD5D7", x"5305205E", x"52DD8CD9", x"57D6CB4C", x"560E67CB", x"54679242", x"55BF3EC5",
+x"5E711D68", x"5FA9B1EF", x"5DC04466", x"5C18E8E1", x"5913AF74", x"58CB03F3", x"5AA2F67A", x"5B7A5AFD",
+x"EC564380", x"ED8EEF07", x"EFE71A8E", x"EE3FB609", x"EB34F19C", x"EAEC5D1B", x"E885A892", x"E95D0415",
+x"E29327B8", x"E34B8B3F", x"E1227EB6", x"E0FAD231", x"E5F195A4", x"E4293923", x"E640CCAA", x"E798602D",
+x"F1DC8BF0", x"F0042777", x"F26DD2FE", x"F3B57E79", x"F6BE39EC", x"F766956B", x"F50F60E2", x"F4D7CC65",
+x"FF19EFC8", x"FEC1434F", x"FCA8B6C6", x"FD701A41", x"F87B5DD4", x"F9A3F153", x"FBCA04DA", x"FA12A85D",
+x"D743D360", x"D69B7FE7", x"D4F28A6E", x"D52A26E9", x"D021617C", x"D1F9CDFB", x"D3903872", x"D24894F5",
+x"D986B758", x"D85E1BDF", x"DA37EE56", x"DBEF42D1", x"DEE40544", x"DF3CA9C3", x"DD555C4A", x"DC8DF0CD",
+x"CAC91B10", x"CB11B797", x"C978421E", x"C8A0EE99", x"CDABA90C", x"CC73058B", x"CE1AF002", x"CFC25C85",
+x"C40C7F28", x"C5D4D3AF", x"C7BD2626", x"C6658AA1", x"C36ECD34", x"C2B661B3", x"C0DF943A", x"C10738BD",
+x"9A7D6240", x"9BA5CEC7", x"99CC3B4E", x"981497C9", x"9D1FD05C", x"9CC77CDB", x"9EAE8952", x"9F7625D5",
+x"94B80678", x"9560AAFF", x"97095F76", x"96D1F3F1", x"93DAB464", x"920218E3", x"906BED6A", x"91B341ED",
+x"87F7AA30", x"862F06B7", x"8446F33E", x"859E5FB9", x"8095182C", x"814DB4AB", x"83244122", x"82FCEDA5",
+x"8932CE08", x"88EA628F", x"8A839706", x"8B5B3B81", x"8E507C14", x"8F88D093", x"8DE1251A", x"8C39899D",
+x"A168F2A0", x"A0B05E27", x"A2D9ABAE", x"A3010729", x"A60A40BC", x"A7D2EC3B", x"A5BB19B2", x"A463B535",
+x"AFAD9698", x"AE753A1F", x"AC1CCF96", x"ADC46311", x"A8CF2484", x"A9178803", x"AB7E7D8A", x"AAA6D10D",
+x"BCE23AD0", x"BD3A9657", x"BF5363DE", x"BE8BCF59", x"BB8088CC", x"BA58244B", x"B831D1C2", x"B9E97D45",
+x"B2275EE8", x"B3FFF26F", x"B19607E6", x"B04EAB61", x"B545ECF4", x"B49D4073", x"B6F4B5FA", x"B72C197D",
+-- LUT1d
+x"00000000", x"DC6D9AB7", x"BC1A28D9", x"6077B26E", x"7CF54C05", x"A098D6B2", x"C0EF64DC", x"1C82FE6B",
+x"F9EA980A", x"258702BD", x"45F0B0D3", x"999D2A64", x"851FD40F", x"59724EB8", x"3905FCD6", x"E5686661",
+x"F7142DA3", x"2B79B714", x"4B0E057A", x"97639FCD", x"8BE161A6", x"578CFB11", x"37FB497F", x"EB96D3C8",
+x"0EFEB5A9", x"D2932F1E", x"B2E49D70", x"6E8907C7", x"720BF9AC", x"AE66631B", x"CE11D175", x"127C4BC2",
+x"EAE946F1", x"3684DC46", x"56F36E28", x"8A9EF49F", x"961C0AF4", x"4A719043", x"2A06222D", x"F66BB89A",
+x"1303DEFB", x"CF6E444C", x"AF19F622", x"73746C95", x"6FF692FE", x"B39B0849", x"D3ECBA27", x"0F812090",
+x"1DFD6B52", x"C190F1E5", x"A1E7438B", x"7D8AD93C", x"61082757", x"BD65BDE0", x"DD120F8E", x"017F9539",
+x"E417F358", x"387A69EF", x"580DDB81", x"84604136", x"98E2BF5D", x"448F25EA", x"24F89784", x"F8950D33",
+x"D1139055", x"0D7E0AE2", x"6D09B88C", x"B164223B", x"ADE6DC50", x"718B46E7", x"11FCF489", x"CD916E3E",
+x"28F9085F", x"F49492E8", x"94E32086", x"488EBA31", x"540C445A", x"8861DEED", x"E8166C83", x"347BF634",
+x"2607BDF6", x"FA6A2741", x"9A1D952F", x"46700F98", x"5AF2F1F3", x"869F6B44", x"E6E8D92A", x"3A85439D",
+x"DFED25FC", x"0380BF4B", x"63F70D25", x"BF9A9792", x"A31869F9", x"7F75F34E", x"1F024120", x"C36FDB97",
+x"3BFAD6A4", x"E7974C13", x"87E0FE7D", x"5B8D64CA", x"470F9AA1", x"9B620016", x"FB15B278", x"277828CF",
+x"C2104EAE", x"1E7DD419", x"7E0A6677", x"A267FCC0", x"BEE502AB", x"6288981C", x"02FF2A72", x"DE92B0C5",
+x"CCEEFB07", x"108361B0", x"70F4D3DE", x"AC994969", x"B01BB702", x"6C762DB5", x"0C019FDB", x"D06C056C",
+x"3504630D", x"E969F9BA", x"891E4BD4", x"5573D163", x"49F12F08", x"959CB5BF", x"F5EB07D1", x"29869D66",
+x"A6E63D1D", x"7A8BA7AA", x"1AFC15C4", x"C6918F73", x"DA137118", x"067EEBAF", x"660959C1", x"BA64C376",
+x"5F0CA517", x"83613FA0", x"E3168DCE", x"3F7B1779", x"23F9E912", x"FF9473A5", x"9FE3C1CB", x"438E5B7C",
+x"51F210BE", x"8D9F8A09", x"EDE83867", x"3185A2D0", x"2D075CBB", x"F16AC60C", x"911D7462", x"4D70EED5",
+x"A81888B4", x"74751203", x"1402A06D", x"C86F3ADA", x"D4EDC4B1", x"08805E06", x"68F7EC68", x"B49A76DF",
+x"4C0F7BEC", x"9062E15B", x"F0155335", x"2C78C982", x"30FA37E9", x"EC97AD5E", x"8CE01F30", x"508D8587",
+x"B5E5E3E6", x"69887951", x"09FFCB3F", x"D5925188", x"C910AFE3", x"157D3554", x"750A873A", x"A9671D8D",
+x"BB1B564F", x"6776CCF8", x"07017E96", x"DB6CE421", x"C7EE1A4A", x"1B8380FD", x"7BF43293", x"A799A824",
+x"42F1CE45", x"9E9C54F2", x"FEEBE69C", x"22867C2B", x"3E048240", x"E26918F7", x"821EAA99", x"5E73302E",
+x"77F5AD48", x"AB9837FF", x"CBEF8591", x"17821F26", x"0B00E14D", x"D76D7BFA", x"B71AC994", x"6B775323",
+x"8E1F3542", x"5272AFF5", x"32051D9B", x"EE68872C", x"F2EA7947", x"2E87E3F0", x"4EF0519E", x"929DCB29",
+x"80E180EB", x"5C8C1A5C", x"3CFBA832", x"E0963285", x"FC14CCEE", x"20795659", x"400EE437", x"9C637E80",
+x"790B18E1", x"A5668256", x"C5113038", x"197CAA8F", x"05FE54E4", x"D993CE53", x"B9E47C3D", x"6589E68A",
+x"9D1CEBB9", x"4171710E", x"2106C360", x"FD6B59D7", x"E1E9A7BC", x"3D843D0B", x"5DF38F65", x"819E15D2",
+x"64F673B3", x"B89BE904", x"D8EC5B6A", x"0481C1DD", x"18033FB6", x"C46EA501", x"A419176F", x"78748DD8",
+x"6A08C61A", x"B6655CAD", x"D612EEC3", x"0A7F7474", x"16FD8A1F", x"CA9010A8", x"AAE7A2C6", x"768A3871",
+x"93E25E10", x"4F8FC4A7", x"2FF876C9", x"F395EC7E", x"EF171215", x"337A88A2", x"530D3ACC", x"8F60A07B"
+ );
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Port A read
+DOA <= ROM(to_integer(unsigned(not ADDRA))); -- see IMPORTANT ORDER INFORMATION above
+
+
+-- Port B read
+DOB <= ROM(to_integer(unsigned(not ADDRB))); -- see IMPORTANT ORDER INFORMATION above
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/crc32_lut2.vhd b/generic_ip/third_party_ip/mac/src/crc32_lut2.vhd
new file mode 100644
index 0000000..d0e2bfd
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32_lut2.vhd
@@ -0,0 +1,118 @@
+-------------------------------------------------------------
+-- Filename: CRC32_LUT2.VHD
+-- Authors:
+-- Alain Zarembowitch / MSS
+-- Version: Rev 0
+-- Last modified: 2/25/17
+-- Inheritance: n/a
+--
+-- description: 32-bit CRC lookup table for x^32.DATA_IN (in other words, the upper 32-bits of a 64-bit word)
+-- Actually comprised of 4 small (256 entries) tables, one for each input byte
+-- Data bit order: MSb of MSB is first sent/received
+-- Algorithm based on seminal paper "High Performance Table-Based Algorithm for Pipelined CRC Calculation",
+-- by Yan Sun and Min Sik Kim
+-- CRC_OUT only depends on DATA_IN. The algorithm is thus memoryless.
+-- Verified by comparing with the crc calculator at http://www.sunshine2k.de/coding/javascript/crc/crc_js.html
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32_LUT2 is
+ Port (
+ CLK : IN std_logic;
+ DATA_IN: in std_logic_vector(31 downto 0);
+ -- Natural order (as if input to a standard LFSR), i.e. not inverted, not reversed.
+ -- order: MSb of MSB is first serialized bit
+ SAMPLE_CLK_IN: in std_logic;
+ -- read DATA_IN at the rising_edge of CLK when SAMPLE_CLK_IN = '1'
+ CRC_OUT: out std_logic_vector(31 downto 0);
+ -- Natural order (as if the flip-flop values of a standard LFSR), i.e. not inverted, not reversed.
+ SAMPLE_CLK_OUT: out std_logic
+ -- latency 1 CLK after SAMPLE_CLK_IN
+ );
+end entity;
+
+architecture Behavioral of CRC32_LUT2 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT CRC32_LUT2ab
+ GENERIC (
+ DATA_WIDTH: integer;
+ ADDR_WIDTH: integer
+ );
+ PORT(
+ ADDRA : IN std_logic_vector(8 downto 0);
+ ADDRB : IN std_logic_vector(8 downto 0);
+ DOA : OUT std_logic_vector(31 downto 0);
+ DOB : OUT std_logic_vector(31 downto 0)
+ );
+ END COMPONENT;
+
+ COMPONENT CRC32_LUT2cd
+ GENERIC (
+ DATA_WIDTH: integer;
+ ADDR_WIDTH: integer
+ );
+ PORT(
+ ADDRA : IN std_logic_vector(8 downto 0);
+ ADDRB : IN std_logic_vector(8 downto 0);
+ DOA : OUT std_logic_vector(31 downto 0);
+ DOB : OUT std_logic_vector(31 downto 0)
+ );
+ END COMPONENT;
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal ADDR0: std_logic_vector(8 downto 0) := (others => '0');
+signal ADDR1: std_logic_vector(8 downto 0) := (others => '0');
+signal ADDR2: std_logic_vector(8 downto 0) := (others => '0');
+signal ADDR3: std_logic_vector(8 downto 0) := (others => '0');
+signal CRC0: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC1: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC2: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC3: std_logic_vector(31 downto 0) := (others => '0');
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- input bytes 0(A-side) and 1 (B-side)
+-- Latency: 0 CLK after
+ADDR0 <= '0' & DATA_IN(7 downto 0); -- order: LSB (last received)
+ADDR1 <= '1' & DATA_IN(15 downto 8);
+CRC32_LUT2ab_001: CRC32_LUT2ab
+GENERIC MAP(
+ DATA_WIDTH => 32,
+ ADDR_WIDTH => 9)
+PORT MAP(
+ ADDRA => ADDR0,
+ DOA => CRC0,
+ ADDRB => ADDR1,
+ DOB => CRC1
+);
+
+ADDR2 <= '0' & DATA_IN(23 downto 16);
+ADDR3 <= '1' & DATA_IN(31 downto 24); -- order: MSb of MSB received first
+CRC32_LUT2cd_001: CRC32_LUT2cd
+GENERIC MAP(
+ DATA_WIDTH => 32,
+ ADDR_WIDTH => 9)
+PORT MAP(
+ ADDRA => ADDR2,
+ DOA => CRC2,
+ ADDRB => ADDR3,
+ DOB => CRC3
+);
+
+
+RECLOCK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ CRC_OUT <= CRC0 xor CRC1 xor CRC2 xor CRC3;
+ SAMPLE_CLK_OUT <= SAMPLE_CLK_IN;
+ end if;
+end process;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/crc32_lut2ab.vhd b/generic_ip/third_party_ip/mac/src/crc32_lut2ab.vhd
new file mode 100644
index 0000000..5c64136
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32_lut2ab.vhd
@@ -0,0 +1,134 @@
+-------------------------------------------------------------
+-- Filename: CRC32_LUT2ab.VHD
+-- Authors:
+-- from http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_4/xst_v6s6.pdf p262
+-- Alain Zarembowitch / MSS
+-- Version: Rev 0
+-- Last modified: 12/13/17
+-- Inheritance: ROM1.vhd 8/24/16
+--
+-- description: synthesizable generic dual port ROM containing two tables of 256 CRC32s values each
+-- (called LUT2a and LUT2b)
+-- The tables are generated by the Java application crc32tables in the /java folder
+-- LUT2a computes the CRC32s for 64-BIT INPUT WORDS in the form 00 00 00 x 00 00 00 00, where x is the LSB (last received byte)
+-- LUT2b computes the CRC32s for 64-BIT INPUT WORDS in the form 00 00 x 00 00 00 00 00
+-- Data bit order: MSb of MSB is first sent/received
+-- Note: the returned crc values are NOT inverted and NOT reflected left-right. They are as they would appear
+-- when generated by a standard LFSR
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32_LUT2ab is
+ Generic (
+ DATA_WIDTH: integer := 32;
+ ADDR_WIDTH: integer := 9
+ );
+ Port (
+ -- Port A
+ ADDRA : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1a at addresses 0 - 255
+ -- LUT1b at addresses 256 - 511
+ DOA : out std_logic_vector(DATA_WIDTH-1 downto 0);
+
+ -- Port B
+ ADDRB : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1a at addresses 0 - 255
+ -- LUT1b at addresses 256 - 511
+ DOB : out std_logic_vector(DATA_WIDTH-1 downto 0)
+ );
+end entity;
+
+architecture Behavioral of CRC32_LUT2ab is
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- inferred rom
+signal DOA_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+signal DOB_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+type ROM_TYPE is array ( (2**ADDR_WIDTH)-1 downto 0 ) of std_logic_vector(DATA_WIDTH-1 downto 0);
+-- IMPORTANT ORDER INFORMATION: the table below is read from bottom to top and right to left. Thus
+-- to restore a common-sense order, address bits are inverted.
+constant ROM : ROM_TYPE := (
+-- LUT2a
+x"00000000", x"490D678D", x"921ACF1A", x"DB17A897", x"20F48383", x"69F9E40E", x"B2EE4C99", x"FBE32B14",
+x"41E90706", x"08E4608B", x"D3F3C81C", x"9AFEAF91", x"611D8485", x"2810E308", x"F3074B9F", x"BA0A2C12",
+x"83D20E0C", x"CADF6981", x"11C8C116", x"58C5A69B", x"A3268D8F", x"EA2BEA02", x"313C4295", x"78312518",
+x"C23B090A", x"8B366E87", x"5021C610", x"192CA19D", x"E2CF8A89", x"ABC2ED04", x"70D54593", x"39D8221E",
+x"036501AF", x"4A686622", x"917FCEB5", x"D872A938", x"2391822C", x"6A9CE5A1", x"B18B4D36", x"F8862ABB",
+x"428C06A9", x"0B816124", x"D096C9B3", x"999BAE3E", x"6278852A", x"2B75E2A7", x"F0624A30", x"B96F2DBD",
+x"80B70FA3", x"C9BA682E", x"12ADC0B9", x"5BA0A734", x"A0438C20", x"E94EEBAD", x"3259433A", x"7B5424B7",
+x"C15E08A5", x"88536F28", x"5344C7BF", x"1A49A032", x"E1AA8B26", x"A8A7ECAB", x"73B0443C", x"3ABD23B1",
+x"06CA035E", x"4FC764D3", x"94D0CC44", x"DDDDABC9", x"263E80DD", x"6F33E750", x"B4244FC7", x"FD29284A",
+x"47230458", x"0E2E63D5", x"D539CB42", x"9C34ACCF", x"67D787DB", x"2EDAE056", x"F5CD48C1", x"BCC02F4C",
+x"85180D52", x"CC156ADF", x"1702C248", x"5E0FA5C5", x"A5EC8ED1", x"ECE1E95C", x"37F641CB", x"7EFB2646",
+x"C4F10A54", x"8DFC6DD9", x"56EBC54E", x"1FE6A2C3", x"E40589D7", x"AD08EE5A", x"761F46CD", x"3F122140",
+x"05AF02F1", x"4CA2657C", x"97B5CDEB", x"DEB8AA66", x"255B8172", x"6C56E6FF", x"B7414E68", x"FE4C29E5",
+x"444605F7", x"0D4B627A", x"D65CCAED", x"9F51AD60", x"64B28674", x"2DBFE1F9", x"F6A8496E", x"BFA52EE3",
+x"867D0CFD", x"CF706B70", x"1467C3E7", x"5D6AA46A", x"A6898F7E", x"EF84E8F3", x"34934064", x"7D9E27E9",
+x"C7940BFB", x"8E996C76", x"558EC4E1", x"1C83A36C", x"E7608878", x"AE6DEFF5", x"757A4762", x"3C7720EF",
+x"0D9406BC", x"44996131", x"9F8EC9A6", x"D683AE2B", x"2D60853F", x"646DE2B2", x"BF7A4A25", x"F6772DA8",
+x"4C7D01BA", x"05706637", x"DE67CEA0", x"976AA92D", x"6C898239", x"2584E5B4", x"FE934D23", x"B79E2AAE",
+x"8E4608B0", x"C74B6F3D", x"1C5CC7AA", x"5551A027", x"AEB28B33", x"E7BFECBE", x"3CA84429", x"75A523A4",
+x"CFAF0FB6", x"86A2683B", x"5DB5C0AC", x"14B8A721", x"EF5B8C35", x"A656EBB8", x"7D41432F", x"344C24A2",
+x"0EF10713", x"47FC609E", x"9CEBC809", x"D5E6AF84", x"2E058490", x"6708E31D", x"BC1F4B8A", x"F5122C07",
+x"4F180015", x"06156798", x"DD02CF0F", x"940FA882", x"6FEC8396", x"26E1E41B", x"FDF64C8C", x"B4FB2B01",
+x"8D23091F", x"C42E6E92", x"1F39C605", x"5634A188", x"ADD78A9C", x"E4DAED11", x"3FCD4586", x"76C0220B",
+x"CCCA0E19", x"85C76994", x"5ED0C103", x"17DDA68E", x"EC3E8D9A", x"A533EA17", x"7E244280", x"3729250D",
+x"0B5E05E2", x"4253626F", x"9944CAF8", x"D049AD75", x"2BAA8661", x"62A7E1EC", x"B9B0497B", x"F0BD2EF6",
+x"4AB702E4", x"03BA6569", x"D8ADCDFE", x"91A0AA73", x"6A438167", x"234EE6EA", x"F8594E7D", x"B15429F0",
+x"888C0BEE", x"C1816C63", x"1A96C4F4", x"539BA379", x"A878886D", x"E175EFE0", x"3A624777", x"736F20FA",
+x"C9650CE8", x"80686B65", x"5B7FC3F2", x"1272A47F", x"E9918F6B", x"A09CE8E6", x"7B8B4071", x"328627FC",
+x"083B044D", x"413663C0", x"9A21CB57", x"D32CACDA", x"28CF87CE", x"61C2E043", x"BAD548D4", x"F3D82F59",
+x"49D2034B", x"00DF64C6", x"DBC8CC51", x"92C5ABDC", x"692680C8", x"202BE745", x"FB3C4FD2", x"B231285F",
+x"8BE90A41", x"C2E46DCC", x"19F3C55B", x"50FEA2D6", x"AB1D89C2", x"E210EE4F", x"390746D8", x"700A2155",
+x"CA000D47", x"830D6ACA", x"581AC25D", x"1117A5D0", x"EAF48EC4", x"A3F9E949", x"78EE41DE", x"31E32653",
+-- LUT2b
+x"00000000", x"1B280D78", x"36501AF0", x"2D781788", x"6CA035E0", x"77883898", x"5AF02F10", x"41D82268",
+x"D9406BC0", x"C26866B8", x"EF107130", x"F4387C48", x"B5E05E20", x"AEC85358", x"83B044D0", x"989849A8",
+x"B641CA37", x"AD69C74F", x"8011D0C7", x"9B39DDBF", x"DAE1FFD7", x"C1C9F2AF", x"ECB1E527", x"F799E85F",
+x"6F01A1F7", x"7429AC8F", x"5951BB07", x"4279B67F", x"03A19417", x"1889996F", x"35F18EE7", x"2ED9839F",
+x"684289D9", x"736A84A1", x"5E129329", x"453A9E51", x"04E2BC39", x"1FCAB141", x"32B2A6C9", x"299AABB1",
+x"B102E219", x"AA2AEF61", x"8752F8E9", x"9C7AF591", x"DDA2D7F9", x"C68ADA81", x"EBF2CD09", x"F0DAC071",
+x"DE0343EE", x"C52B4E96", x"E853591E", x"F37B5466", x"B2A3760E", x"A98B7B76", x"84F36CFE", x"9FDB6186",
+x"0743282E", x"1C6B2556", x"311332DE", x"2A3B3FA6", x"6BE31DCE", x"70CB10B6", x"5DB3073E", x"469B0A46",
+x"D08513B2", x"CBAD1ECA", x"E6D50942", x"FDFD043A", x"BC252652", x"A70D2B2A", x"8A753CA2", x"915D31DA",
+x"09C57872", x"12ED750A", x"3F956282", x"24BD6FFA", x"65654D92", x"7E4D40EA", x"53355762", x"481D5A1A",
+x"66C4D985", x"7DECD4FD", x"5094C375", x"4BBCCE0D", x"0A64EC65", x"114CE11D", x"3C34F695", x"271CFBED",
+x"BF84B245", x"A4ACBF3D", x"89D4A8B5", x"92FCA5CD", x"D32487A5", x"C80C8ADD", x"E5749D55", x"FE5C902D",
+x"B8C79A6B", x"A3EF9713", x"8E97809B", x"95BF8DE3", x"D467AF8B", x"CF4FA2F3", x"E237B57B", x"F91FB803",
+x"6187F1AB", x"7AAFFCD3", x"57D7EB5B", x"4CFFE623", x"0D27C44B", x"160FC933", x"3B77DEBB", x"205FD3C3",
+x"0E86505C", x"15AE5D24", x"38D64AAC", x"23FE47D4", x"622665BC", x"790E68C4", x"54767F4C", x"4F5E7234",
+x"D7C63B9C", x"CCEE36E4", x"E196216C", x"FABE2C14", x"BB660E7C", x"A04E0304", x"8D36148C", x"961E19F4",
+x"A5CB3AD3", x"BEE337AB", x"939B2023", x"88B32D5B", x"C96B0F33", x"D243024B", x"FF3B15C3", x"E41318BB",
+x"7C8B5113", x"67A35C6B", x"4ADB4BE3", x"51F3469B", x"102B64F3", x"0B03698B", x"267B7E03", x"3D53737B",
+x"138AF0E4", x"08A2FD9C", x"25DAEA14", x"3EF2E76C", x"7F2AC504", x"6402C87C", x"497ADFF4", x"5252D28C",
+x"CACA9B24", x"D1E2965C", x"FC9A81D4", x"E7B28CAC", x"A66AAEC4", x"BD42A3BC", x"903AB434", x"8B12B94C",
+x"CD89B30A", x"D6A1BE72", x"FBD9A9FA", x"E0F1A482", x"A12986EA", x"BA018B92", x"97799C1A", x"8C519162",
+x"14C9D8CA", x"0FE1D5B2", x"2299C23A", x"39B1CF42", x"7869ED2A", x"6341E052", x"4E39F7DA", x"5511FAA2",
+x"7BC8793D", x"60E07445", x"4D9863CD", x"56B06EB5", x"17684CDD", x"0C4041A5", x"2138562D", x"3A105B55",
+x"A28812FD", x"B9A01F85", x"94D8080D", x"8FF00575", x"CE28271D", x"D5002A65", x"F8783DED", x"E3503095",
+x"754E2961", x"6E662419", x"431E3391", x"58363EE9", x"19EE1C81", x"02C611F9", x"2FBE0671", x"34960B09",
+x"AC0E42A1", x"B7264FD9", x"9A5E5851", x"81765529", x"C0AE7741", x"DB867A39", x"F6FE6DB1", x"EDD660C9",
+x"C30FE356", x"D827EE2E", x"F55FF9A6", x"EE77F4DE", x"AFAFD6B6", x"B487DBCE", x"99FFCC46", x"82D7C13E",
+x"1A4F8896", x"016785EE", x"2C1F9266", x"37379F1E", x"76EFBD76", x"6DC7B00E", x"40BFA786", x"5B97AAFE",
+x"1D0CA0B8", x"0624ADC0", x"2B5CBA48", x"3074B730", x"71AC9558", x"6A849820", x"47FC8FA8", x"5CD482D0",
+x"C44CCB78", x"DF64C600", x"F21CD188", x"E934DCF0", x"A8ECFE98", x"B3C4F3E0", x"9EBCE468", x"8594E910",
+x"AB4D6A8F", x"B06567F7", x"9D1D707F", x"86357D07", x"C7ED5F6F", x"DCC55217", x"F1BD459F", x"EA9548E7",
+x"720D014F", x"69250C37", x"445D1BBF", x"5F7516C7", x"1EAD34AF", x"058539D7", x"28FD2E5F", x"33D52327"
+ );
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Port A read
+DOA <= ROM(to_integer(unsigned(not ADDRA))); -- see IMPORTANT ORDER INFORMATION above
+
+
+-- Port B read
+DOB <= ROM(to_integer(unsigned(not ADDRB))); -- see IMPORTANT ORDER INFORMATION above
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/crc32_lut2cd.vhd b/generic_ip/third_party_ip/mac/src/crc32_lut2cd.vhd
new file mode 100644
index 0000000..1159cb5
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32_lut2cd.vhd
@@ -0,0 +1,134 @@
+-------------------------------------------------------------
+-- Filename: CRC32_LUT2cd.VHD
+-- Authors:
+-- from http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_4/xst_v6s6.pdf p262
+-- Alain Zarembowitch / MSS
+-- Version: Rev 0
+-- Last modified: 12/13/17
+-- Inheritance: ROM1.vhd 8/24/16
+--
+-- description: synthesizable generic dual port ROM containing two tables of 256 CRC32s values each
+-- (called LUT2c and LUT2d)
+-- The tables are generated by the Java application crc32tables in the /java folder
+-- LUT1c computes the CRC32s for 64-BIT INPUT WORDS in the form 00 x 00 00 00 00 00 00
+-- LUT1d computes the CRC32s for 64-BIT INPUT WORDS in the form y 00 00 00 00 00 00 00, where y is the MSB
+-- Data bit order: MSb of MSB is first sent/received
+-- Note: the returned crc values are NOT inverted and NOT reflected left-right. They are as they would appear
+-- when generated by a standard LFSR
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32_LUT2cd is
+ Generic (
+ DATA_WIDTH: integer := 32;
+ ADDR_WIDTH: integer := 9
+ );
+ Port (
+ -- Port A
+ ADDRA : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1c at addresses 0 - 255
+ -- LUT1d at addresses 256 - 511
+ DOA : out std_logic_vector(DATA_WIDTH-1 downto 0);
+
+ -- Port B
+ ADDRB : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ -- LUT1c at addresses 0 - 255
+ -- LUT1d at addresses 256 - 511
+ DOB : out std_logic_vector(DATA_WIDTH-1 downto 0)
+ );
+end entity;
+
+architecture Behavioral of CRC32_LUT2cd is
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- inferred rom
+signal DOA_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+signal DOB_local: std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+type ROM_TYPE is array ( (2**ADDR_WIDTH)-1 downto 0 ) of std_logic_vector(DATA_WIDTH-1 downto 0);
+-- IMPORTANT ORDER INFORMATION: the table below is read from bottom to top and right to left. Thus
+-- to restore a common-sense order, address bits are inverted.
+constant ROM : ROM_TYPE := (
+-- LUT2c
+x"00000000", x"4F576811", x"9EAED022", x"D1F9B833", x"399CBDF3", x"76CBD5E2", x"A7326DD1", x"E86505C0",
+x"73397BE6", x"3C6E13F7", x"ED97ABC4", x"A2C0C3D5", x"4AA5C615", x"05F2AE04", x"D40B1637", x"9B5C7E26",
+x"E672F7CC", x"A9259FDD", x"78DC27EE", x"378B4FFF", x"DFEE4A3F", x"90B9222E", x"41409A1D", x"0E17F20C",
+x"954B8C2A", x"DA1CE43B", x"0BE55C08", x"44B23419", x"ACD731D9", x"E38059C8", x"3279E1FB", x"7D2E89EA",
+x"C824F22F", x"87739A3E", x"568A220D", x"19DD4A1C", x"F1B84FDC", x"BEEF27CD", x"6F169FFE", x"2041F7EF",
+x"BB1D89C9", x"F44AE1D8", x"25B359EB", x"6AE431FA", x"8281343A", x"CDD65C2B", x"1C2FE418", x"53788C09",
+x"2E5605E3", x"61016DF2", x"B0F8D5C1", x"FFAFBDD0", x"17CAB810", x"589DD001", x"89646832", x"C6330023",
+x"5D6F7E05", x"12381614", x"C3C1AE27", x"8C96C636", x"64F3C3F6", x"2BA4ABE7", x"FA5D13D4", x"B50A7BC5",
+x"9488F9E9", x"DBDF91F8", x"0A2629CB", x"457141DA", x"AD14441A", x"E2432C0B", x"33BA9438", x"7CEDFC29",
+x"E7B1820F", x"A8E6EA1E", x"791F522D", x"36483A3C", x"DE2D3FFC", x"917A57ED", x"4083EFDE", x"0FD487CF",
+x"72FA0E25", x"3DAD6634", x"EC54DE07", x"A303B616", x"4B66B3D6", x"0431DBC7", x"D5C863F4", x"9A9F0BE5",
+x"01C375C3", x"4E941DD2", x"9F6DA5E1", x"D03ACDF0", x"385FC830", x"7708A021", x"A6F11812", x"E9A67003",
+x"5CAC0BC6", x"13FB63D7", x"C202DBE4", x"8D55B3F5", x"6530B635", x"2A67DE24", x"FB9E6617", x"B4C90E06",
+x"2F957020", x"60C21831", x"B13BA002", x"FE6CC813", x"1609CDD3", x"595EA5C2", x"88A71DF1", x"C7F075E0",
+x"BADEFC0A", x"F589941B", x"24702C28", x"6B274439", x"834241F9", x"CC1529E8", x"1DEC91DB", x"52BBF9CA",
+x"C9E787EC", x"86B0EFFD", x"574957CE", x"181E3FDF", x"F07B3A1F", x"BF2C520E", x"6ED5EA3D", x"2182822C",
+x"2DD0EE65", x"62878674", x"B37E3E47", x"FC295656", x"144C5396", x"5B1B3B87", x"8AE283B4", x"C5B5EBA5",
+x"5EE99583", x"11BEFD92", x"C04745A1", x"8F102DB0", x"67752870", x"28224061", x"F9DBF852", x"B68C9043",
+x"CBA219A9", x"84F571B8", x"550CC98B", x"1A5BA19A", x"F23EA45A", x"BD69CC4B", x"6C907478", x"23C71C69",
+x"B89B624F", x"F7CC0A5E", x"2635B26D", x"6962DA7C", x"8107DFBC", x"CE50B7AD", x"1FA90F9E", x"50FE678F",
+x"E5F41C4A", x"AAA3745B", x"7B5ACC68", x"340DA479", x"DC68A1B9", x"933FC9A8", x"42C6719B", x"0D91198A",
+x"96CD67AC", x"D99A0FBD", x"0863B78E", x"4734DF9F", x"AF51DA5F", x"E006B24E", x"31FF0A7D", x"7EA8626C",
+x"0386EB86", x"4CD18397", x"9D283BA4", x"D27F53B5", x"3A1A5675", x"754D3E64", x"A4B48657", x"EBE3EE46",
+x"70BF9060", x"3FE8F871", x"EE114042", x"A1462853", x"49232D93", x"06744582", x"D78DFDB1", x"98DA95A0",
+x"B958178C", x"F60F7F9D", x"27F6C7AE", x"68A1AFBF", x"80C4AA7F", x"CF93C26E", x"1E6A7A5D", x"513D124C",
+x"CA616C6A", x"8536047B", x"54CFBC48", x"1B98D459", x"F3FDD199", x"BCAAB988", x"6D5301BB", x"220469AA",
+x"5F2AE040", x"107D8851", x"C1843062", x"8ED35873", x"66B65DB3", x"29E135A2", x"F8188D91", x"B74FE580",
+x"2C139BA6", x"6344F3B7", x"B2BD4B84", x"FDEA2395", x"158F2655", x"5AD84E44", x"8B21F677", x"C4769E66",
+x"717CE5A3", x"3E2B8DB2", x"EFD23581", x"A0855D90", x"48E05850", x"07B73041", x"D64E8872", x"9919E063",
+x"02459E45", x"4D12F654", x"9CEB4E67", x"D3BC2676", x"3BD923B6", x"748E4BA7", x"A577F394", x"EA209B85",
+x"970E126F", x"D8597A7E", x"09A0C24D", x"46F7AA5C", x"AE92AF9C", x"E1C5C78D", x"303C7FBE", x"7F6B17AF",
+x"E4376989", x"AB600198", x"7A99B9AB", x"35CED1BA", x"DDABD47A", x"92FCBC6B", x"43050458", x"0C526C49",
+-- LUT2d
+x"00000000", x"5BA1DCCA", x"B743B994", x"ECE2655E", x"6A466E9F", x"31E7B255", x"DD05D70B", x"86A40BC1",
+x"D48CDD3E", x"8F2D01F4", x"63CF64AA", x"386EB860", x"BECAB3A1", x"E56B6F6B", x"09890A35", x"5228D6FF",
+x"ADD8A7CB", x"F6797B01", x"1A9B1E5F", x"413AC295", x"C79EC954", x"9C3F159E", x"70DD70C0", x"2B7CAC0A",
+x"79547AF5", x"22F5A63F", x"CE17C361", x"95B61FAB", x"1312146A", x"48B3C8A0", x"A451ADFE", x"FFF07134",
+x"5F705221", x"04D18EEB", x"E833EBB5", x"B392377F", x"35363CBE", x"6E97E074", x"8275852A", x"D9D459E0",
+x"8BFC8F1F", x"D05D53D5", x"3CBF368B", x"671EEA41", x"E1BAE180", x"BA1B3D4A", x"56F95814", x"0D5884DE",
+x"F2A8F5EA", x"A9092920", x"45EB4C7E", x"1E4A90B4", x"98EE9B75", x"C34F47BF", x"2FAD22E1", x"740CFE2B",
+x"262428D4", x"7D85F41E", x"91679140", x"CAC64D8A", x"4C62464B", x"17C39A81", x"FB21FFDF", x"A0802315",
+x"BEE0A442", x"E5417888", x"09A31DD6", x"5202C11C", x"D4A6CADD", x"8F071617", x"63E57349", x"3844AF83",
+x"6A6C797C", x"31CDA5B6", x"DD2FC0E8", x"868E1C22", x"002A17E3", x"5B8BCB29", x"B769AE77", x"ECC872BD",
+x"13380389", x"4899DF43", x"A47BBA1D", x"FFDA66D7", x"797E6D16", x"22DFB1DC", x"CE3DD482", x"959C0848",
+x"C7B4DEB7", x"9C15027D", x"70F76723", x"2B56BBE9", x"ADF2B028", x"F6536CE2", x"1AB109BC", x"4110D576",
+x"E190F663", x"BA312AA9", x"56D34FF7", x"0D72933D", x"8BD698FC", x"D0774436", x"3C952168", x"6734FDA2",
+x"351C2B5D", x"6EBDF797", x"825F92C9", x"D9FE4E03", x"5F5A45C2", x"04FB9908", x"E819FC56", x"B3B8209C",
+x"4C4851A8", x"17E98D62", x"FB0BE83C", x"A0AA34F6", x"260E3F37", x"7DAFE3FD", x"914D86A3", x"CAEC5A69",
+x"98C48C96", x"C365505C", x"2F873502", x"7426E9C8", x"F282E209", x"A9233EC3", x"45C15B9D", x"1E608757",
+x"79005533", x"22A189F9", x"CE43ECA7", x"95E2306D", x"13463BAC", x"48E7E766", x"A4058238", x"FFA45EF2",
+x"AD8C880D", x"F62D54C7", x"1ACF3199", x"416EED53", x"C7CAE692", x"9C6B3A58", x"70895F06", x"2B2883CC",
+x"D4D8F2F8", x"8F792E32", x"639B4B6C", x"383A97A6", x"BE9E9C67", x"E53F40AD", x"09DD25F3", x"527CF939",
+x"00542FC6", x"5BF5F30C", x"B7179652", x"ECB64A98", x"6A124159", x"31B39D93", x"DD51F8CD", x"86F02407",
+x"26700712", x"7DD1DBD8", x"9133BE86", x"CA92624C", x"4C36698D", x"1797B547", x"FB75D019", x"A0D40CD3",
+x"F2FCDA2C", x"A95D06E6", x"45BF63B8", x"1E1EBF72", x"98BAB4B3", x"C31B6879", x"2FF90D27", x"7458D1ED",
+x"8BA8A0D9", x"D0097C13", x"3CEB194D", x"674AC587", x"E1EECE46", x"BA4F128C", x"56AD77D2", x"0D0CAB18",
+x"5F247DE7", x"0485A12D", x"E867C473", x"B3C618B9", x"35621378", x"6EC3CFB2", x"8221AAEC", x"D9807626",
+x"C7E0F171", x"9C412DBB", x"70A348E5", x"2B02942F", x"ADA69FEE", x"F6074324", x"1AE5267A", x"4144FAB0",
+x"136C2C4F", x"48CDF085", x"A42F95DB", x"FF8E4911", x"792A42D0", x"228B9E1A", x"CE69FB44", x"95C8278E",
+x"6A3856BA", x"31998A70", x"DD7BEF2E", x"86DA33E4", x"007E3825", x"5BDFE4EF", x"B73D81B1", x"EC9C5D7B",
+x"BEB48B84", x"E515574E", x"09F73210", x"5256EEDA", x"D4F2E51B", x"8F5339D1", x"63B15C8F", x"38108045",
+x"9890A350", x"C3317F9A", x"2FD31AC4", x"7472C60E", x"F2D6CDCF", x"A9771105", x"4595745B", x"1E34A891",
+x"4C1C7E6E", x"17BDA2A4", x"FB5FC7FA", x"A0FE1B30", x"265A10F1", x"7DFBCC3B", x"9119A965", x"CAB875AF",
+x"3548049B", x"6EE9D851", x"820BBD0F", x"D9AA61C5", x"5F0E6A04", x"04AFB6CE", x"E84DD390", x"B3EC0F5A",
+x"E1C4D9A5", x"BA65056F", x"56876031", x"0D26BCFB", x"8B82B73A", x"D0236BF0", x"3CC10EAE", x"6760D264"
+ );
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Port A read
+DOA <= ROM(to_integer(unsigned(not ADDRA))); -- see IMPORTANT ORDER INFORMATION above
+
+
+-- Port B read
+DOB <= ROM(to_integer(unsigned(not ADDRB))); -- see IMPORTANT ORDER INFORMATION above
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/crc32minlatency.vhd b/generic_ip/third_party_ip/mac/src/crc32minlatency.vhd
new file mode 100644
index 0000000..e7585a3
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/crc32minlatency.vhd
@@ -0,0 +1,226 @@
+-------------------------------------------------------------
+-- Filename: CRC32.VHD
+-- Authors:
+-- Alain Zarembowitch / MSS
+-- Version: Rev 0
+-- Last modified: 2/26/17
+-- Inheritance: n/a
+--
+-- description: high-speed generation of 32-bit CRC32 (optimized for 10G Ethernet 64-bit words)
+-- Data bit order: MSb of MSB is first sent/received
+-- Algorithm based on seminal paper "High Performance Table-Based Algorithm for Pipelined CRC Calculation",
+-- by Yan Sun and Min Sik Kim
+-- Verified by comparing with the crc calculator at http://www.sunshine2k.de/coding/javascript/crc/crc_js.html
+--
+-- Utilization:
+-- FF: 188
+-- LUT: 728
+-- 18Kb block RAMs: 0
+-- DSP: 0
+-- GCLK: 1
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity CRC32 is
+ Port (
+ CLK : IN std_logic;
+ DATA_IN: in std_logic_vector(63 downto 0);
+ -- Natural order (as if input to a standard LFSR), i.e. not inverted, not reversed.
+ -- order: MSb of MSB is first serialized bit
+ -- Special case: when last word is less than 8 bytes, bytes are left-aligned (MSB first) and lower byte(s) are ignored.
+ SAMPLE_CLK_IN: in std_logic;
+ -- read DATA_IN at the rising_edge of CLK when SAMPLE_CLK_IN = '1'
+ SOF_IN: in std_logic;
+ -- 1-CLK wide pulse marks the first word in a message. Initializes the CRC to all zero
+ -- aligned with SAMPLE_CLK_IN
+ DATA_VALID_IN : IN std_logic_vector(7 downto 0);
+ -- Valid bytes in DATA_IN.
+ -- Valid inputs: 0x00,80 (one MSB byte),C0,E0,F0,F8,FC,FE,FF (8 bytes)
+ CRC_INITIALIZATION: in std_logic_vector(31 downto 0);
+ -- typically 0xFFFFFFFF. Read at SOF_IN = '1'
+ CRC_OUT: out std_logic_vector(31 downto 0);
+ -- Natural order (as in the flip-flop values of a standard LFSR), i.e. not inverted, not reversed.
+ SAMPLE_CLK_OUT: out std_logic
+ -- latency 1 CLKs after SAMPLE_CLK_IN
+ );
+end entity;
+
+architecture Behavioral of CRC32 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT CRC32_LUT1
+ PORT(
+ CLK : IN std_logic;
+ DATA_IN : IN std_logic_vector(31 downto 0);
+ SAMPLE_CLK_IN : IN std_logic;
+ CRC_OUT : OUT std_logic_vector(31 downto 0);
+ SAMPLE_CLK_OUT : OUT std_logic
+ );
+ END COMPONENT;
+
+ COMPONENT CRC32_LUT2
+ PORT(
+ CLK : IN std_logic;
+ DATA_IN : IN std_logic_vector(31 downto 0);
+ SAMPLE_CLK_IN : IN std_logic;
+ CRC_OUT : OUT std_logic_vector(31 downto 0);
+ SAMPLE_CLK_OUT : OUT std_logic
+ );
+ END COMPONENT;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal DATA1: std_logic_vector(63 downto 0) := (others => '0');
+signal DATA1_D: std_logic_vector(63 downto 0) := (others => '0');
+signal DATA2: std_logic_vector(63 downto 0) := (others => '0');
+signal DATA12: std_logic_vector(63 downto 0) := (others => '0');
+signal SAMPLE1_CLK: std_logic := '0';
+signal SAMPLE1_CLK_D: std_logic := '0';
+signal SAMPLE1_CLK_D2: std_logic := '0';
+signal SOF1: std_logic := '0';
+signal SOF1_D: std_logic := '0';
+signal CRC1: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC2: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC12: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC12_D: std_logic_vector(31 downto 0) := (others => '0');
+signal CRC12_FROZEN: std_logic_vector(31 downto 0) := (others => '0');
+
+
+
+signal CRC3: std_logic_vector(31 downto 0) := (others => '0');
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Special case: when last word is less than 8 bytes, input bytes are left-aligned (MSB first) and lower byte(s) are ignored.
+-- partial last word case: reorder last word so that bytes are right aligned
+REORDER_001: process(DATA_IN, SAMPLE_CLK_IN, DATA_VALID_IN)
+begin
+ if(SAMPLE_CLK_IN = '1') then
+ if(DATA_VALID_IN(7) = '0') then
+ DATA1 <= (others => '0');
+ elsif(DATA_VALID_IN(6) = '0') then
+ DATA1 <= x"00000000000000" & DATA_IN(63 downto 56); -- last word contains 1 byte
+ elsif(DATA_VALID_IN(5) = '0') then
+ DATA1 <= x"000000000000" & DATA_IN(63 downto 48); -- last word
+ elsif(DATA_VALID_IN(4) = '0') then
+ DATA1 <= x"0000000000" & DATA_IN(63 downto 40); -- last word
+ elsif(DATA_VALID_IN(3) = '0') then
+ DATA1 <= x"00000000" & DATA_IN(63 downto 32); -- last word
+ elsif(DATA_VALID_IN(2) = '0') then
+ DATA1 <= x"000000" & DATA_IN(63 downto 24); -- last word
+ elsif(DATA_VALID_IN(1) = '0') then
+ DATA1 <= x"0000" & DATA_IN(63 downto 16); -- last word
+ elsif(DATA_VALID_IN(0) = '0') then
+ DATA1 <= x"00" & DATA_IN(63 downto 8); -- last word
+ else
+ DATA1 <= DATA_IN(63 downto 0); -- full 8-byte input word
+ end if;
+ else
+ DATA1 <= DATA1_D;
+ end if;
+end process;
+SAMPLE1_CLK <= SAMPLE_CLK_IN;
+SOF1 <= SOF_IN;
+
+FREEZE_DATA1_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ SOF1_D <= SOF1;
+ if(SAMPLE1_CLK = '1') then
+ DATA1_D <= DATA1;
+ end if;
+ end if;
+end process;
+
+-- CRC32 look-up table
+-- Latency: 1 CLK (from table address DATA_IN to table output CRC_OUT)
+-- lower 32-bits
+LUT1_001: CRC32_LUT1 PORT MAP (
+ CLK => CLK,
+ DATA_IN => DATA12(31 downto 0),
+ SAMPLE_CLK_IN => SAMPLE1_CLK,
+ CRC_OUT => CRC1,
+ SAMPLE_CLK_OUT => SAMPLE1_CLK_D
+ );
+-- upper 32-bits. LUT2 shifts the input by x^32
+-- Latency: 1 CLK (from table address DATA_IN to table output CRC_OUT)
+LUT2_001: CRC32_LUT2 PORT MAP (
+ CLK => CLK,
+ DATA_IN => DATA12(63 downto 32),
+ SAMPLE_CLK_IN => SAMPLE1_CLK,
+ CRC_OUT => CRC2,
+ SAMPLE_CLK_OUT => open
+ );
+CRC12 <= CRC1 xor CRC2; -- this is the CRC[DATA_IN(63:0)]
+
+-- freeze CRC12 (otherwise algorithm runs amok) immediately at the LUT output (without waiting for next rising edge)
+FREEZE_CRC12_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SAMPLE1_CLK_D = '1') then
+ CRC12_D <= CRC12;
+ end if;
+ end if;
+end process;
+CRC12_FROZEN <= CRC_INITIALIZATION when (SOF1 = '1') else -- initialize CRC to zero at the first input word
+ CRC12 when (SAMPLE1_CLK_D = '1') else
+ CRC12_D;
+
+-- last word special case. Add left-over bytes from last word CRC
+DATA2_GEN_001: process(CRC12_FROZEN, DATA_VALID_IN)
+begin
+ if(DATA_VALID_IN(7) = '0') then
+ DATA2 <= (others => '0');
+ elsif(DATA_VALID_IN(6) = '0') then
+ DATA2 <= x"00000000000000" & CRC12_FROZEN(31 downto 24); -- last input word contains 1 byte
+ elsif(DATA_VALID_IN(5) = '0') then
+ DATA2 <= x"000000000000" & CRC12_FROZEN(31 downto 16); -- last input word contains 2 bytes
+ elsif(DATA_VALID_IN(4) = '0') then
+ DATA2 <= x"0000000000" & CRC12_FROZEN(31 downto 8); -- last input word contains 3 bytes
+ elsif(DATA_VALID_IN(3) = '0') then
+ DATA2 <= x"00000000" & CRC12_FROZEN(31 downto 0);
+ elsif(DATA_VALID_IN(2) = '0') then
+ DATA2 <= x"000000" & CRC12_FROZEN(31 downto 0) & x"00";
+ elsif(DATA_VALID_IN(1) = '0') then
+ DATA2 <= x"0000" & CRC12_FROZEN(31 downto 0) & x"0000";
+ elsif(DATA_VALID_IN(0) = '0') then
+ DATA2 <= x"00" & CRC12_FROZEN(31 downto 0) & x"000000";
+ else
+ DATA2 <= CRC12_FROZEN(31 downto 0) & x"00000000";
+ end if;
+end process;
+
+DATA12 <= DATA1 xor DATA2;
+
+
+CRC3_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SAMPLE_CLK_IN = '1') then
+ if(DATA_VALID_IN(7) = '0') then
+ CRC3 <= (others => '0');
+ elsif(DATA_VALID_IN(6) = '0') then
+ CRC3 <= CRC12_FROZEN(23 downto 0) & x"00"; -- last input word contains 1 byte
+ elsif(DATA_VALID_IN(5) = '0') then
+ CRC3 <= CRC12_FROZEN(15 downto 0) & x"0000"; -- last input word contains 2 bytes
+ elsif(DATA_VALID_IN(4) = '0') then
+ CRC3 <= CRC12_FROZEN(7 downto 0) & x"000000"; -- last input word contains 3 bytes
+ else
+ CRC3 <= (others => '0');
+ end if;
+ end if;
+ end if;
+end process;
+
+-- outputs
+CRC_OUT <= CRC12_FROZEN xor CRC3;
+SAMPLE_CLK_OUT <= SAMPLE1_CLK_D;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/mac/src/phy_config.vhd b/generic_ip/third_party_ip/mac/src/phy_config.vhd
new file mode 100644
index 0000000..c195f75
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/phy_config.vhd
@@ -0,0 +1,334 @@
+-------------------------------------------------------------
+-- MSS copyright 2010-2018
+-- Filename: PHY_CONFIG.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 8/16/18
+-- Inheritance: COM-5401 PHY_CONFIG.VHD rev6 8/23/13
+--
+-- description: Configures a 10G PHY through a MDIO interface.
+-- The control and status registers are specific to the VSC8486-11 PHY
+-- The state machine must be edited to reflect any other PHY.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity PHY_CONFIG is
+ generic (
+ EXT_PHY_MDIO_ADDR: std_logic_vector(4 downto 0) := "00000"
+ -- external PHY MDIO address
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ CLK: in std_logic;
+
+ --// CONTROLS
+ CONFIG_CHANGE: in std_logic;
+ -- 1 CLK-wide pulse to activate any configuration change below.
+ -- Not needed if the default values are acceptable.
+ PHY_RESET: in std_logic;
+ -- 1 = PHY software reset, 0 = no reset
+ TEST_MODE: in std_logic_vector(1 downto 0);
+ -- 00 = normal mode (default)
+ -- 01 = loopback mode
+ -- 10 = remote loopback
+ POWER_DOWN: in std_logic;
+ -- software power down mode. 1 = enabled, 0 = disabled (default).
+
+ --// MONITORING
+ -- read ONE status register
+ SREG_READ_START: in std_logic;
+ -- 1 CLK wide pulse to start read transaction
+ -- will be ignored if the previous transaction is yet to be completed.
+ SREG_MMD: in std_logic_vector(4 downto 0);
+ -- device
+ SREG_ADDR: in std_logic_vector(15 downto 0);
+ -- status register address
+ SREG_DATA : OUT std_logic_vector(15 downto 0);
+ -- 16-bit status register. Read when SREG_SAMPLE_CLK = '1'
+ SREG_SAMPLE_CLK: out std_logic;
+ SREG_READ_IDLE: out std_logic;
+ -- '1' when the state machine is idle and thus available to read another status register
+
+
+ -- Connect to external PHY and XAUI adapter (shared MDIO bus)
+ MDC: out std_logic;
+ MDIO_OUT: out std_logic;
+ MDIO_IN: in std_logic;
+ MDIO_DIR: out std_logic; -- '0' when output, '1' when input
+ -- MDIO serial interface to control and monitor two MMDs: external 10G PHY and
+ -- internal XAUI adapter.
+
+ --// TEST POINTS
+ TP: out std_logic_vector(10 downto 1)
+
+
+);
+end entity;
+
+architecture Behavioral of PHY_CONFIG is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT MII_MI
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ PHY_ADDR: std_logic_vector(4 downto 0);
+ MI_REGAD : IN std_logic_vector(4 downto 0);
+ MI_TX_DATA : IN std_logic_vector(15 downto 0);
+ MI_ADDR_START: in std_logic;
+ MI_READ_START : IN std_logic;
+ MI_WRITE_START : IN std_logic;
+ MI_RX_DATA : OUT std_logic_vector(15 downto 0);
+ MI_TRANSACTION_COMPLETE : OUT std_logic;
+ MDC: out std_logic;
+ MDIO_OUT: out std_logic;
+ MDIO_IN: in std_logic;
+ MDIO_DIR: out std_logic -- '0' when output, '1' when input
+ );
+ END COMPONENT;
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal CONFIG_CHANGE_PENDING_FLAG: std_logic:= '0';
+signal PHY_RESET0: std_logic:= '0';
+signal PHY_RESET_D: std_logic:= '0';
+signal TEST_MODE0: std_logic_vector(1 downto 0) := (others => '0');
+signal POWER_DOWN0: std_logic:= '0';
+signal POWER_DOWN_D: std_logic:= '0';
+signal LOOPBACK_MODE: std_logic:= '0';
+signal REMOTE_LOOPBACK: std_logic:= '0';
+signal STATE: unsigned(7 downto 0) := (others => '0');
+signal MI_WRITE_START: std_logic := '0';
+signal MI_REGAD: std_logic_vector(4 downto 0) := "00000";
+signal MI_TX_DATA: std_logic_vector(15 downto 0) := (others => '0');
+signal MI_READ_START: std_logic := '0';
+signal MI_ADDR_START: std_logic := '0';
+signal MI_RX_DATA: std_logic_vector(15 downto 0) := (others => '0');
+signal MI_TRANSACTION_COMPLETE: std_logic:= '0';
+signal SREG_SAMPLE_CLK_local: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- hold the configuration request until it is time to process it (state machine may be busy)
+CONFIG_SAVE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(CONFIG_CHANGE = '1') then
+ CONFIG_CHANGE_PENDING_FLAG <= '1';
+ PHY_RESET0 <= PHY_RESET;
+ TEST_MODE0 <= TEST_MODE;
+ POWER_DOWN0 <= POWER_DOWN;
+ elsif(STATE = 0) and (CONFIG_CHANGE_PENDING_FLAG = '1') then
+ CONFIG_CHANGE_PENDING_FLAG <= '0';
+ end if;
+ end if;
+end process;
+
+
+-- save the configuration so that it does not change while the configuration is in progress
+RECLOCK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(STATE = 0) and (CONFIG_CHANGE_PENDING_FLAG = '1') then
+ PHY_RESET_D <= PHY_RESET0;
+ POWER_DOWN_D <= POWER_DOWN0;
+
+ case TEST_MODE0 is
+ when "00" =>
+ LOOPBACK_MODE <= '0';
+ REMOTE_LOOPBACK <= '0';
+ when "01" =>
+ LOOPBACK_MODE <= '1';
+ REMOTE_LOOPBACK <= '0';
+ when "10" =>
+ LOOPBACK_MODE <= '0';
+ REMOTE_LOOPBACK <= '1';
+ when others =>
+ LOOPBACK_MODE <= '0';
+ REMOTE_LOOPBACK <= '0';
+ end case;
+ end if;
+ end if;
+end process;
+
+-- state machine
+-- The state machine structure is generic, however, the actual control and status registers
+-- depend on the PHY.
+-- Written specifically for the Microsemi VSC8486-11 PHY
+STATE_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ STATE <= (others => '0');
+ MI_REGAD <= (others => '0');
+ MI_TX_DATA <= (others => '0');
+ MI_ADDR_START <= '0';
+ MI_WRITE_START <= '0';
+ MI_READ_START <= '0';
+ SREG_SAMPLE_CLK_local <= '0';
+
+ -- WRITE CONFIGURATION REGISTERS as needed
+ elsif(STATE = 0) and (CONFIG_CHANGE_PENDING_FLAG = '1') then
+ -- triggers a PHY reconfiguration. await PHY MDIO availability
+ STATE <= STATE + 1;
+ SREG_SAMPLE_CLK_local <= '0';
+
+ elsif(STATE = 1) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- PHY is ready for next transaction.
+ -- Set address register 1x0000
+ STATE <= STATE + 1;
+ MI_REGAD <= "00001";
+ MI_TX_DATA <= x"0000";
+ MI_ADDR_START <= '1';
+ elsif(STATE = 2) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- set configuration register 1x0000 (part 1/2)
+ STATE <= STATE + 1;
+ MI_REGAD <= "00001";
+ MI_TX_DATA <= PHY_RESET_D & "010" & POWER_DOWN_D & "0000100000" & LOOPBACK_MODE;
+ -- loopback J
+ -- low power
+ -- soft reset
+ MI_WRITE_START <= '1';
+ elsif(STATE = 3) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- set configuration register 1x0000 (part 2/2)
+ -- remove the reset condition
+ STATE <= STATE + 1;
+ MI_REGAD <= "00001";
+ MI_TX_DATA <= "0010" & POWER_DOWN_D & "0000100000" & LOOPBACK_MODE;
+ -- loopback J
+ -- low power
+ -- soft reset
+ MI_WRITE_START <= '1';
+ elsif(STATE = 4) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- PHY is ready for next transaction.
+ -- Set address register 1x8000
+ STATE <= STATE + 1;
+ MI_REGAD <= "00001";
+ MI_TX_DATA <= x"8000";
+ MI_ADDR_START <= '1';
+ elsif(STATE = 5) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- set configuration register 1x8000
+ STATE <= STATE + 1;
+ MI_REGAD <= "00001";
+ MI_TX_DATA <= x"B55F";
+ -- invert tx data polarity (see com5104 schematics)
+ MI_WRITE_START <= '1';
+ elsif(STATE = 6) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- PHY is ready for next transaction.
+ -- Set address register 1xE901
+ STATE <= STATE + 1;
+ MI_REGAD <= "00001";
+ MI_TX_DATA <= x"E901";
+ MI_ADDR_START <= '1';
+ elsif(STATE = 7) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- set configuration register 1xE901
+ STATE <= STATE + 1;
+ MI_REGAD <= "00001";
+ MI_TX_DATA <= x"283A";
+ -- LEDs configured for rx and tx lines activity
+ MI_WRITE_START <= '1';
+ elsif(STATE = 8) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- PHY is ready for next transaction.
+ -- Set address register 4x800F
+ STATE <= STATE + 1;
+ MI_REGAD <= "00100";
+ MI_TX_DATA <= x"800F";
+ MI_ADDR_START <= '1';
+ elsif(STATE = 9) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- set configuration register 4x800F
+ STATE <= (others => '0'); -- back to idle unless there are other write transactions
+ MI_REGAD <= "00100";
+ MI_TX_DATA <= x"0600";
+ -- invert XAUI tx/rx bits (see COM-5104 schematics p3)
+ MI_WRITE_START <= '1';
+
+ -- add more write cycles to control registers... as needed
+ -- then move to reading a status register
+
+ -- READ ONE STATUS REGISTER
+ elsif(STATE = 0) and (SREG_READ_START = '1') then
+ -- triggers a PHY status read. await PHY MDIO availability
+ STATE <= "00010000";
+ SREG_SAMPLE_CLK_local <= '0';
+ elsif(STATE = 16) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- set status register address
+ STATE <= STATE + 1;
+ MI_REGAD <= SREG_MMD;
+ MI_TX_DATA <= SREG_ADDR;
+ MI_ADDR_START <= '1';
+ elsif(STATE = 17) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- read status register
+ STATE <= STATE + 1;
+ MI_REGAD <= SREG_MMD;
+ MI_READ_START <= '1';
+ elsif(STATE = 18) and (MI_TRANSACTION_COMPLETE = '1') then
+ -- we are done reading a status register! Going back to idle.
+ STATE <= (others => '0');
+ MI_READ_START <= '0';
+ SREG_SAMPLE_CLK_local <= '1';
+ else
+ MI_ADDR_START <= '0';
+ MI_WRITE_START <= '0';
+ MI_READ_START <= '0';
+ SREG_SAMPLE_CLK_local <= '0';
+
+ end if;
+ end if;
+end process;
+
+SREG_READ_IDLE <= '1' when (STATE = 0) and (CONFIG_CHANGE_PENDING_FLAG = '0') else '0';
+ -- '1' when the state machine is idle and thus available to read another status register
+
+-- latch status register
+SREGOUT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ SREG_SAMPLE_CLK <= SREG_SAMPLE_CLK_local;
+
+ if(SREG_SAMPLE_CLK_local = '1') then
+ SREG_DATA <= MI_RX_DATA;
+ end if;
+ end if;
+end process;
+
+
+MII_MI_001: MII_MI
+PORT MAP(
+ SYNC_RESET => SYNC_RESET,
+ CLK => CLK,
+ PHY_ADDR => EXT_PHY_MDIO_ADDR,
+ MI_REGAD => MI_REGAD,
+ MI_TX_DATA => MI_TX_DATA,
+ MI_RX_DATA => MI_RX_DATA,
+ MI_ADDR_START => MI_ADDR_START,
+ MI_WRITE_START => MI_WRITE_START,
+ MI_READ_START => MI_READ_START,
+ MI_TRANSACTION_COMPLETE => MI_TRANSACTION_COMPLETE,
+ MDC => MDC,
+ MDIO_OUT => MDIO_OUT,
+ MDIO_IN => MDIO_IN,
+ MDIO_DIR => MDIO_DIR
+);
+
+--// TEST POINTS -------------------------
+TP(1) <= CONFIG_CHANGE;
+TP(2) <= MI_TRANSACTION_COMPLETE;
+TP(3) <= SREG_SAMPLE_CLK_local;
+TP(4) <= '1' when (STATE = 1) else '0';
+TP(5) <= '1' when (STATE = 6) else '0';
+TP(6) <= '1' when (STATE = 9) else '0';
+TP(7) <= '1' when (STATE = 10) else '0';
+TP(8) <= MI_ADDR_START;
+TP(9) <= MI_WRITE_START;
+TP(10) <= MI_READ_START;
+
+
+end Behavioral;
+
diff --git a/generic_ip/third_party_ip/mac/src/sdp_ram.vhd b/generic_ip/third_party_ip/mac/src/sdp_ram.vhd
new file mode 100644
index 0000000..f1e5557
--- /dev/null
+++ b/generic_ip/third_party_ip/mac/src/sdp_ram.vhd
@@ -0,0 +1,48 @@
+-- Simple Dual-Port Block RAM with Two Clocks
+-- Correct Modelization with a Shared Variable
+-- File: simple_dual_two_clocks.vhd
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.std_logic_unsigned.all;
+
+entity sdp_ram is
+ generic(
+ ADDR_WIDTH: natural := 11;
+ DATA_WIDTH: integer := 9);
+ port(
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic;
+ enb : in std_logic;
+ wea : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+end sdp_ram;
+
+architecture syn of sdp_ram is
+ type ram_type is array (2**ADDR_WIDTH-1 downto 0) of std_logic_vector(DATA_WIDTH-1 downto 0);
+ shared variable RAM : ram_type;
+begin
+ process(clka)
+ begin
+ if clka'event and clka = '1' then
+ if ena = '1' then
+ if wea = '1' then
+ RAM(conv_integer(addra)) := dia;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ process(clkb)
+ begin
+ if clkb'event and clkb = '1' then
+ if enb = '1' then
+ dob <= RAM(conv_integer(addrb));
+ end if;
+ end if;
+ end process;
+
+end syn;
diff --git a/generic_ip/third_party_ip/tcp_server/src/STREAM_2_PACKETS2_TODO.vhd b/generic_ip/third_party_ip/tcp_server/src/STREAM_2_PACKETS2_TODO.vhd
new file mode 100644
index 0000000..771c065
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/STREAM_2_PACKETS2_TODO.vhd
@@ -0,0 +1,494 @@
+-------------------------------------------------------------
+-- MSS copyright 2018
+-- Filename: STREAM_2_PACKETS2.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 3/11/18
+-- Inheritance: STREAM_2_PACKETS2.VHD rev4 7/14/17
+--
+-- description: Encapsulate input data into data packets (for example for UDP transmission).
+-- The input stream is segmented into data packets.
+-- The packet transmission is triggered by either a timeout (TIMEOUT = maximum time between successive packets)
+-- or when the number of bytes waiting for transmission is greater or equal than MAX_PACKET_SIZE bytes.
+-- A 16-byte preamble field is inserted prior to the data field, consisting of
+-- 2 bytes for payload data length, 14 bytes for PREAMBLE_IN.
+--
+-- Note: no packet is sent if there is no data available when the timer expires.
+--
+-- If the follow-on transmission component is unable to immediately send the packet
+-- (for example if UDP_TX is missing routing information) it will return a negative acknowledgement (NAK).
+-- This component is responsible for triggering a re-transmission at a later time.
+-- The wait before the next retransmission attempt is defined by the constant TX_RETRY_TIMEOUT within.
+--
+-- This component can interface seemlessly with UDP_TX.vhd at the output to encapsulate
+-- the output packets within UDP frames for network transmission.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity STREAM_2_PACKETS2 is
+ generic (
+ NBUFS: integer := 1;
+ -- number of 16Kb dual-port RAM buffers instantiated within.
+ -- Valid values: 1,2,4,8
+ TIMEOUT_ENABLE: std_logic := '1';
+ TIMEOUT: integer range 1 to 262144:= 125000;
+ -- maximum time between successive packets, expressed in 4 us units
+ MAX_PACKET_SIZE: std_logic_vector(13 downto 0) := "00" & x"400"; -- in bytes. 1024 bytes
+ -- maximum data field size, in bytes. Does not include the preamble.
+ SIMULATION: std_logic := '0'
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ CLK: in std_logic; -- synchronous clock
+ -- Must be a global clocks. No BUFG instantiation within this component.
+ TICK_4us: in std_logic;
+ -- 1 CLK wide pulse
+
+ --// INPUT STREAM
+ DATA_IN: in std_logic_vector(63 downto 0); -- input data
+ DATA_VALID_IN: in std_logic_vector(7 downto 0); -- 1 clk wide pulse for each input sample
+ CTS_OUT: out std_logic;
+ -- flow control. Typically 1 as component is fast enough to process input samples
+ -- in real time.
+
+ --// PREAMBLE
+ PACKET_TX_PULSE: out std_logic;
+ -- 1 CLK pulse when the decision to send a frame is made.
+ PREAMBLE_IN: in std_logic_vector(111 downto 0);
+ -- user-defined preamble. for example timestamp.
+ -- read upon making the decision to send a packet (PACKET_TX_PULSE = '1').
+ -- Note: a 16-bit data payload length field is inserted in the first two bytes of the output frame,
+ -- before this preamble.
+
+ --// OUTPUT PACKETS
+ -- For example, interfaces with UDP_TX
+ DATA_OUT: out std_logic_vector(63 downto 0);
+ DATA_VALID_OUT: out std_logic_vector(7 downto 0);
+ SOF_OUT: out std_logic; -- also resets internal state machine
+ EOF_OUT: out std_logic;
+ RTS_OUT: out std_logic; -- indicate that we are ready to send a complete frame. Stays high until acknowledged by CTS_IN
+ CTS_IN: in std_logic; -- destination acknowledges that it's ok to send the complete frame.
+ ACK_IN: in std_logic;
+ -- previous packet is accepted for transmission.
+ -- ACK/NAK can arrive anytime after SOF_OUT, even before the packet is fully transferred
+ NAK_IN: in std_logic;
+ -- could not send the packet (for example, no routing information available for the selected
+ -- LAN destination IP). Try later.
+
+ --// TEST POINTS
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of STREAM_2_PACKETS2 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- Suffix _D indicates a one CLK delayed version of the net with the same name
+-- Suffix _E indicates a one CLK early version of the net with the same name
+-- Suffix _X indicates an extended precision version of the net with the same name
+-- Suffix _N indicates an inverted version of the net with the same name
+
+--//-- COMPONENT CONFIGURATION (FIXED AT PRE-SYNTHESIS) ---------------
+constant TX_RETRY_TIMEOUT: integer range 0 to 1023 := 500;
+constant TX_RETRY_TIMEOUT_SIM: integer range 0 to 1023 := 10; -- shorter timer during simulations
+ -- wait time after a NAK before trying a retransmission, expressed in 4us units. -- 500*4us = 2ms
+ -- IMPORTANT: the timeout starts at the SOF. It therefore includes the output data transfer duration (MAX_PACKET_SIZE/fCLK).
+ -- Always make sure the timeout is always greater than the output data transfer duration.
+
+signal DATA_VALID_IN_D: std_logic := '0';
+signal DATA_IN_D: std_logic_vector(7 downto 0) := (others => '0');
+signal PREAMBLE_IN_SHIFT: std_logic_vector(127 downto 0):= (others => '0');
+
+--//-- INPUT ELASTIC BUFFER ---------------------------
+signal STREAM_DATAx: std_logic_vector(8 downto 0) := (others => '0');
+signal PTR_MASK: std_logic_vector(13 downto 0) := (others => '1');
+signal WPTR: std_logic_vector(13 downto 0) := (others => '0');
+signal RPTR: std_logic_vector(13 downto 0) := (others => '1');
+signal RPTR_INC: std_logic_vector(13 downto 0) := (others => '0');
+signal RPTR_D: std_logic_vector(13 downto 0) := (others => '1');
+signal RPTR_ACKED: std_logic_vector(13 downto 0) := (others => '1');
+signal BUF_SIZE: std_logic_vector(13 downto 0) := (others => '0');
+signal DATA_FIELD_SIZE: std_logic_vector(13 downto 0) := (others => '0');
+signal WEA: std_logic_vector((NBUFS-1) downto 0) := (others => '0');
+signal WPTR_MEMINDEX: std_logic_vector(2 downto 0) := (others => '0');
+signal RPTR_MEMINDEX: std_logic_vector(2 downto 0) := (others => '0');
+signal RPTR_MEMINDEX_D: std_logic_vector(2 downto 0) := (others => '0');
+type DOBtype is array(integer range 0 to (NBUFS-1)) of std_logic_vector(8 downto 0);
+signal DOB: DOBtype := (others => (others => '0'));
+
+--//-- TIMEOUT ----------------------------
+signal TIMER: integer range 0 to 262144 := 0;
+
+--//-- READ POINTER AND STATE MACHINE ----------------------------
+signal STATE: integer range 0 to 5 := 0;
+signal STATE_D: integer range 0 to 5 := 0;
+signal PREAMBLE_DATA: std_logic_vector(7 downto 0) := (others => '0');
+signal PAYLOAD_DATA: std_logic_vector(7 downto 0) := (others => '0');
+signal PREAMBLE_RPTR: integer range 0 to 16:= 16;
+signal RPTR_MAX: std_logic_vector(13 downto 0) := (others => '0');
+signal DATA_VALID_E: std_logic := '0';
+signal DATA_VALID: std_logic := '0';
+signal DATA_VALID_D: std_logic := '0';
+signal SOF_E: std_logic := '0';
+signal SOF: std_logic := '0';
+signal EOF_E: std_logic := '0';
+signal EOF: std_logic := '0';
+signal TX_RETRY_TIMER: integer range 0 to 1023 := 0;
+signal TX_RETRY_TIMEOUT_B: integer range 0 to 1023 := 0;
+
+signal ACK_IN_FLAG: std_logic := '0';
+signal NAK_IN_FLAG: std_logic := '0';
+signal RTS_OUT_local: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- during simulations, reduce long timer values
+TX_RETRY_TIMEOUT_B <= TX_RETRY_TIMEOUT when (SIMULATION = '0') else TX_RETRY_TIMEOUT_SIM;
+
+INPUT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DATA_VALID_IN_D <= DATA_VALID_IN;
+ DATA_IN_D <= DATA_IN;
+ end if;
+end process;
+
+--//-- INPUT ELASTIC BUFFER ---------------------------
+WPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WPTR <= (others => '0');
+ elsif(DATA_VALID_IN_D = '1') then
+ -- data sample
+ WPTR <= (WPTR + 1) and PTR_MASK;
+ end if;
+ end if;
+end process;
+
+
+-- Mask upper address bits, depending on the memory depth (1,2,4, or 8 RAMblocks)
+WPTR_MEMINDEX <= WPTR(13 downto 11) when (NBUFS = 8) else
+ "0" & WPTR(12 downto 11) when (NBUFS = 4) else
+ "00" & WPTR(11 downto 11) when (NBUFS = 2) else
+ "000"; -- when (NBUFS = 1)
+
+PTR_MASK <= "11111111111111" when (NBUFS = 8) else
+ "01111111111111" when (NBUFS = 4) else
+ "00111111111111" when (NBUFS = 2) else
+ "00011111111111"; -- when (NBUFS = 1)
+
+
+-- select which RAMBlock to write to.
+WEA_GEN_001: process(WPTR_MEMINDEX, DATA_VALID_IN_D)
+begin
+ for J in 0 to (NBUFS -1) loop
+ if(WPTR_MEMINDEX = J) then -- range 0 through 7
+ WEA(J) <= DATA_VALID_IN_D;
+ else
+ WEA(J) <= '0';
+ end if;
+ end loop;
+end process;
+
+-- 1,2,4, or 8 RAM blocks.
+RAMB_16_S9_S9_Y: for J in 0 to (NBUFS-1) generate
+ STREAM_DATAx <= "0" & DATA_IN_D;
+
+ -- 18Kbit buffer(s)
+ RAMB16_S18_S9_001: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 9,
+ ADDR_WIDTHA => 11,
+ DATA_WIDTHB => 9,
+ ADDR_WIDTHB => 11
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA(J), -- Port A Write Enable Input
+ ADDRA => WPTR(10 downto 0), -- 11-bit address
+ DIA => STREAM_DATAx,
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => RPTR(10 downto 0), -- 11-bit address
+ DIB => "000000000",
+ OEB => '1',
+ DOB => DOB(J)
+ );
+end generate;
+
+-- Mask upper address bits, depending on the memory depth (1,2,4, or 8 RAMblocks)
+RPTR_MEMINDEX <= RPTR(13 downto 11) when (NBUFS = 8) else
+ "0" & RPTR(12 downto 11) when (NBUFS = 4) else
+ "00" & RPTR(11 downto 11) when (NBUFS = 2) else
+ "000"; -- when (NBUFS = 1)
+
+BUF_SIZE <= (WPTR + not (RPTR_ACKED)) and PTR_MASK;
+ -- occupied space in the buffer (i.e. data waiting for transmission). Expressed in Bytes.
+
+-- input flow control
+CTS_OUT <= '1' when (not BUF_SIZE(13 downto 7) /= 0) and (NBUFS = 8) else
+ '1' when (not BUF_SIZE(12 downto 7) /= 0) and (NBUFS = 4) else
+ '1' when (not BUF_SIZE(11 downto 7) /= 0) and (NBUFS = 2) else
+ '1' when (not BUF_SIZE(10 downto 7) /= 0) and (NBUFS = 1) else
+ '0';
+
+ -- allow more tx data in if there is room for at least 128 bytes
+
+--//-- TIMEOUT ----------------------------
+TIMER_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ -- re-arm timer
+ TIMER <= TIMEOUT-1;
+ elsif(STATE = 1) then
+ -- Decision was made to send a packet. Rearm timer
+ TIMER <= TIMEOUT-1;
+ elsif (TICK_4us = '1') then
+ if(TIMER = 0) then
+ -- re-arm timer
+ TIMER <= TIMEOUT-1;
+ else
+ TIMER <= TIMER - 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+--//-- READ POINTER AND STATE MACHINE ----------------------------
+-- manage read pointer
+RPTR_INC <= RPTR + 1;
+
+RPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ RPTR_MEMINDEX_D <= RPTR_MEMINDEX;
+
+ if(SYNC_RESET = '1') then
+ STATE <= 0;
+ RPTR <= PTR_MASK;
+ RPTR_D <= PTR_MASK;
+ RPTR_ACKED <= PTR_MASK;
+ DATA_VALID_E <= '0';
+ SOF_E <= '0';
+ EOF_E <= '0';
+ DATA_VALID <= '0';
+ SOF <= '0';
+ EOF <= '0';
+ PREAMBLE_RPTR <= 16;
+ RTS_OUT_local <= '0';
+ else
+ -- 1 CLK delay in reading data from block RAM
+ RPTR_D <= RPTR;
+ DATA_VALID <= DATA_VALID_E;
+ SOF <= SOF_E;
+ EOF <= EOF_E;
+ -- reset start of sequence after 2^16 frames
+
+ if(STATE = 0) and (BUF_SIZE /= 0) and (RTS_OUT_local = '0') then
+ -- transmit decision
+ -- idle state, data is waiting in input elastic buffer. Trigger next transmit frame
+ if(BUF_SIZE >= MAX_PACKET_SIZE) then
+ -- tx trigger: got enough data in buffer to fill a maximum size packet
+ RTS_OUT_local <= '1'; -- signal outside that a frame is ready to be send. Must be acknowledged with CTS_IN
+ DATA_FIELD_SIZE <= MAX_PACKET_SIZE; -- freeze size
+ STATE <= 1; -- await CTS_IN
+ elsif((TICK_4us = '1') and (TIMER = 0) and (TIMEOUT_ENABLE = '1')) then
+ -- timeout waiting for more data and at least one byte of payload data waiting for transmission.
+ RTS_OUT_local <= '1'; -- signal outside that a frame is ready to be send. Must be acknowledged with CTS_IN
+ DATA_FIELD_SIZE <= BUF_SIZE; -- freeze size
+ STATE <= 1; -- await CTS_IN
+ end if;
+ elsif(STATE = 1) and (CTS_IN = '1') then
+ -- start frame transmission
+ RTS_OUT_local <= '0';
+ PREAMBLE_RPTR <= 0; -- preamble data in 2 CLKs, just like reading the DPRAM
+ DATA_VALID_E <= '1';
+ SOF_E <= '1';
+ STATE <= 2;
+ elsif(STATE = 2) then
+ -- sending preamble
+ SOF_E <= '0';
+ if(CTS_IN = '1') then
+ DATA_VALID_E <= '1';
+ PREAMBLE_RPTR <= PREAMBLE_RPTR + 1;
+ if(PREAMBLE_RPTR >= 15) then
+ -- end of preamble
+ STATE <= 3;
+ -- start sending payload data
+ RPTR_MAX <= (RPTR_ACKED + DATA_FIELD_SIZE) and PTR_MASK;
+ RPTR <= RPTR_INC and PTR_MASK; -- start transferring the first byte
+ if(DATA_FIELD_SIZE = 1) then
+ -- special case: 1 byte packet. EOF = SOF
+ EOF_E <= '1';
+ end if;
+ end if;
+ else
+ DATA_VALID_E <= '0';
+ end if;
+ elsif(STATE = 3) then
+ if ((RPTR and PTR_MASK) = (RPTR_MAX and PTR_MASK)) then
+ -- end of packet transmission
+ DATA_VALID_E <= '0';
+ EOF_E <= '0';
+ STATE <= 4; -- data transfer complete. wait for ACK or NAK
+ TX_RETRY_TIMER <= TX_RETRY_TIMEOUT_B;
+ -- this timer has two objectives:
+ -- (a) make sure the state machine does not get stuck at state 4 if for some unexplained reason
+ -- no ACK/NAK is received, and
+ -- (b) wait a bit before retransmitting a NAK'ed packet.
+ elsif (CTS_IN = '1') then
+ -- not yet done transferring bytes
+ RPTR <= RPTR_INC and PTR_MASK; -- continue transferring bytes
+ DATA_VALID_E <= '1';
+ if((RPTR_INC and PTR_MASK) = (RPTR_MAX and PTR_MASK)) then
+ EOF_E <= '1';
+ end if;
+ else
+ DATA_VALID_E <= '0';
+ end if;
+ elsif(STATE = 4) then
+ -- data transfer complete. waiting for ACK/NAK
+ if(ACK_IN = '1') or (ACK_IN_FLAG = '1') then
+ -- All done.
+ STATE <= 0; -- back to idle
+ RPTR_ACKED <= RPTR and PTR_MASK; -- new acknowledged read pointer
+ elsif(NAK_IN = '1') or (NAK_IN_FLAG = '1') then
+ -- no transfer. try again later
+ STATE <= 5; -- wait a bit, then re-try
+ RPTR <= RPTR_ACKED and PTR_MASK; -- rewind read pointer
+ elsif(TX_RETRY_TIMER = 0) then
+ -- timer expired without receiving an ACK/NAK (abnormal condition). go back to idle
+ STATE <= 0;
+ RPTR <= RPTR_ACKED and PTR_MASK; -- rewind read pointer
+ elsif(TICK_4us = '1') then
+ TX_RETRY_TIMER <= TX_RETRY_TIMER - 1;
+ end if;
+ elsif(STATE = 5) then
+ -- wait a bit then retry sending
+ if(TX_RETRY_TIMER = 0) then
+ -- waited long enough. try retransmitting.
+ STATE <= 0;
+ elsif(TICK_4us = '1') then
+ TX_RETRY_TIMER <= TX_RETRY_TIMER - 1;
+ end if;
+ else
+
+ end if;
+ end if;
+ end if;
+end process;
+
+RTS_OUT <= RTS_OUT_local;
+PACKET_TX_PULSE <= SOF_E;
+ -- 1 CLK pulse when the decision to send a frame is made.
+
+-- latch in the preamble when the decision is taken to send another packet
+-- preamble data
+PREAMBLE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ STATE_D <= STATE;
+
+ if(SOF_E = '1') then
+ PREAMBLE_IN_SHIFT <= "00" & DATA_FIELD_SIZE & PREAMBLE_IN;
+ elsif(PREAMBLE_RPTR < 16) then
+ PREAMBLE_IN_SHIFT(127 downto 8) <= PREAMBLE_IN_SHIFT(119 downto 0);
+ end if;
+ end if;
+end process;
+PREAMBLE_DATA <= PREAMBLE_IN_SHIFT(127 downto 120);
+
+-- payload data
+PAYLOAD_DATA_GEN: process(RPTR_MEMINDEX_D, DOB)
+variable data: std_logic_vector(7 downto 0);
+begin
+ for I in 0 to (NBUFS -1) loop
+ if(I = RPTR_MEMINDEX_D) then
+ data := DOB(I)(7 downto 0);
+ end if;
+ end loop;
+ PAYLOAD_DATA <= data;
+end process;
+
+-- ACK/NAK received flags
+ACK_NAK_FLAGS_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ ACK_IN_FLAG <= '0';
+ NAK_IN_FLAG <= '0';
+ else
+ if(STATE = 0) then
+ ACK_IN_FLAG <= '0';
+ elsif(ACK_IN = '1') then
+ ACK_IN_FLAG <= '1';
+ end if;
+ if(STATE = 0) then
+ NAK_IN_FLAG <= '0';
+ elsif(NAK_IN = '1') then
+ NAK_IN_FLAG <= '1';
+ end if;
+ end if;
+ end if;
+end process;
+
+--//-- OUTPUT --------------------------------
+DATA_OUT <= PREAMBLE_DATA when (STATE_D = 2) else PAYLOAD_DATA;
+DATA_VALID_OUT <= DATA_VALID;
+SOF_OUT <= SOF;
+EOF_OUT <= EOF;
+
+--//-- TEST POINTS ----------------------------
+TP(1) <= WPTR(0);
+TP(2) <= RPTR(0);
+TP(3) <= CTS_IN;
+TP(4) <= '1' when (STATE = 0) else '0';
+TP(5) <= '1' when (STATE = 1) else '0';
+TP(6) <= '1' when (BUF_SIZE >= MAX_PACKET_SIZE) else '0';
+--TP(7) <= NAK_IN_FLAG;
+--TP(8) <= SOF;
+--TP(9) <= EOF;
+--TP(9) <= DATA_VALID;
+--TP(10) <= ACK_IN_FLAG;
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/arp_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/arp_10G.vhd
new file mode 100644
index 0000000..9d55a9c
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/arp_10G.vhd
@@ -0,0 +1,354 @@
+-------------------------------------------------------------
+-- MSS copyright 2003-2018
+-- Filename: ARP_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 5/1/18
+-- Inheritance: ARP_10G.VHD version 2, 12/10/15
+--
+-- description: Address resolution protocol, 10GbE version
+-- Reads receive packet structure on the fly and generates an ARP reply.
+-- Any new received packet is presumed to be an ARP request. Within a few bytes,
+-- information is received as to the real protocol associated with the received packet.
+-- The ARP reply generation is immediately cancelled if
+-- (a) the received packet type is not an ARP request/reply
+-- (b) the Opcode does not indicate an ARP request
+-- (c) the IP address does not match
+-- (d) erroneous MAC frame
+-- Supports only Ethernet (IEEE 802.3) encapsulation
+-- ARP only applies to IPv4. For IPv6, use neighbour discovery protocol instead.
+-- Any follow-on received MAC frame is discarded while a valid ARP response awaits transmission in the elastic buffer.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity ARP_10G is
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ -- Must be a global clock. No BUFG instantiation within this component.
+ SYNC_RESET: in std_logic;
+
+ --// Packet/Frame received
+ MAC_RX_DATA: in std_logic_vector(63 downto 0);
+ -- USER reads the data at the rising edge of CLK when MAC_RX_DATA_VALID /= 0
+ -- Bytes order: MSB was received first
+ -- Bytes are left aligned: first byte in MSB, occasional follow-on fill-in Bytes in the LSB(s)
+ -- The first destination address byte is always a MSB (MAC_RX_DATA(7:0))
+ MAC_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- data valid, for each byte in MAC_RX_DATA
+ MAC_RX_SOF: in std_logic;
+ -- '1' when sending the first byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ MAC_RX_EOF: in std_logic;
+ -- '1' when sending the last byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ MAC_RX_FRAME_VALID: in std_logic;
+ -- MAC frame integrity verification (at the end of frame)
+ MAC_RX_WORD_COUNT: in std_logic_vector(10 downto 0);
+ -- MAC word counter, 1 CLK after the input. 0 is the first word.
+
+ --// Configuration data: IP address, MAC address
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ -- local IP address. 4 bytes for IPv4 only
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+
+ --// Received type
+ RX_TYPE: in std_logic_vector(3 downto 0);
+ -- Information stays until start of following packet.
+ -- Only one valid types:
+ -- 2 = Ethernet encapsulation, ARP request/reply
+ RX_TYPE_RDY: in std_logic;
+ -- 1 CLK-wide pulse indicating that a detection was made on the received packet
+ -- type, and that RX_TYPE can be read.
+ -- Detection occurs as soon as possible, two clocks after receiving byte 13 or 21.
+
+ --// Packet origin, already parsed in PACKET_PARSING (shared code)
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(31 downto 0); -- IPv4 only
+
+ --// USER -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended. User should not supply it.
+ -- Synchonous with CLK
+ MAC_TX_DATA: out std_logic_vector(63 downto 0);
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID /= 0
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- data valid
+ MAC_TX_EOF: out std_logic;
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal. The user should check that this
+ -- signal is high before sending the next MAC_TX_DATA byte.
+ RTS: out std_logic;
+ -- '1' when a full or partial packet is ready to be read.
+ -- '0' when output buffer is empty.
+ -- When the user starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of ARP_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+
+--// STATE MACHINE ------------------
+signal STATE: unsigned(0 downto 0) := (others => '0');
+signal INPUT_ENABLED: std_logic := '1';
+signal MAC_RX_DATA_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_RX_SOF_D: std_logic := '0';
+signal MAC_RX_EOF_D: std_logic := '0';
+signal MAC_RX_DATA_D: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_RX_WORD_VALID_D: std_logic := '0';
+signal MAC_RX_EOF_D2: std_logic := '0';
+
+--// VALIDATE ARP REQUEST -----------
+signal VALID_ARP_REQ: std_logic := '0';
+signal RX_SOURCE_MAC_ADDR0: std_logic_vector(47 downto 0) := (others => '0');
+signal RX_SOURCE_IP_ADDR0: std_logic_vector(31 downto 0) := (others => '0');
+
+--// ARP REPLY -----------------
+signal MAC_TX_EOF_local: std_logic := '0';
+signal RPTR: unsigned(5 downto 0) := (others => '0'); -- range 0 - 41
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// STATE MACHINE ------------------
+-- A state machine is needed as this process is memoryless.
+-- State 0 = idle or incoming packet being processed. No tx packet waiting.
+-- State 1 = valid ARP request. tx packet waiting for tx capacity. Incoming packets are ignored.
+STATE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ STATE <= (others => '0');
+ elsif(MAC_RX_EOF_D2 = '1') and (VALID_ARP_REQ = '1') then
+ -- event = valid ARP request. Ready to send ARP reply when tx channel opens.
+ -- In the mean time, incoming packets are ignored.
+ STATE <= "1";
+ elsif(MAC_TX_EOF_local = '1') then
+ -- event = successfully sent ARP reply. Reopen input
+ STATE <= "0";
+ end if;
+ end if;
+end process;
+
+INPUT_ENABLED <= '1' when (STATE = 0) else '0';
+
+STATE_GEN_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_RX_DATA_D <= (others => '0');
+ MAC_RX_DATA_VALID_D <= (others => '0');
+ MAC_RX_SOF_D <= '0';
+ MAC_RX_EOF_D <= '0';
+ MAC_RX_WORD_VALID_D <= '0';
+ -- reclock data and sample clock so that they are aligned with the word count.
+ elsif(INPUT_ENABLED = '0') then
+ -- we still waiting to send the last ARP reply. Ignore any incoming packets until transmission is complete.
+ MAC_RX_DATA_D <= (others => '0');
+ MAC_RX_DATA_VALID_D <= (others => '0');
+ MAC_RX_SOF_D <= '0';
+ MAC_RX_EOF_D <= '0';
+ MAC_RX_WORD_VALID_D <= '0';
+ else
+ MAC_RX_DATA_D <= MAC_RX_DATA;
+ MAC_RX_DATA_VALID_D <= MAC_RX_DATA_VALID;
+ MAC_RX_SOF_D <= MAC_RX_SOF;
+ MAC_RX_EOF_D <= MAC_RX_EOF;
+ if(unsigned(MAC_RX_DATA_VALID) /= 0) then
+ MAC_RX_WORD_VALID_D <= '1';
+ else
+ MAC_RX_WORD_VALID_D <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+--
+--// VALIDATE ARP REQUEST -----------
+-- The ARP reply generation is immediately cancelled if
+-- (a) the received packet type is not an ARP request/reply
+-- (b) the Opcode does not indicate an ARP request
+-- (c) the IP address does not match
+-- (d) erroneous MAC frame
+-- VALID_ARP_REQ is ready at MAC_RX_EOF_D2
+VALIDITY_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ VALID_ARP_REQ <= '1';
+ MAC_RX_EOF_D2 <= '0';
+ else
+ MAC_RX_EOF_D2 <= MAC_RX_EOF_D;
+
+ if(MAC_RX_SOF_D = '1') then
+ -- just received first byte. ARP request valid until proven otherwise
+ VALID_ARP_REQ <= '1';
+ elsif(MAC_RX_EOF = '1') and (MAC_RX_FRAME_VALID = '0') then
+ -- (d) erroneous MAC frame
+ VALID_ARP_REQ <= '0';
+ elsif(MAC_RX_EOF_D = '1') and (unsigned(RX_TYPE) /= 2) then
+ -- (a) the received packet type is not an ARP request/reply
+ VALID_ARP_REQ <= '0';
+ elsif (MAC_RX_WORD_VALID_D = '1') and (unsigned(MAC_RX_WORD_COUNT) = 1) then
+ if (MAC_RX_DATA_D(15 downto 0) /= x"0001") then
+ -- unexpected hardware type
+ VALID_ARP_REQ <= '0';
+ end if;
+ elsif (MAC_RX_WORD_VALID_D = '1') and (unsigned(MAC_RX_WORD_COUNT) = 2) then
+ if (MAC_RX_DATA_D(63 downto 32) /= x"08000604") then
+ -- unexpected protocol type, hardware length or protocol length
+ VALID_ARP_REQ <= '0';
+ end if;
+ if (MAC_RX_DATA_D(23 downto 16) /= x"01") then
+ -- (b) op field does not indicate ARP request
+ VALID_ARP_REQ <= '0';
+ end if;
+ elsif (MAC_RX_WORD_VALID_D = '1') and (unsigned(MAC_RX_WORD_COUNT) = 4) then
+ if(MAC_RX_DATA_VALID_D(1 downto 0) /= "11") or (MAC_RX_DATA_D(15 downto 0) /= IPv4_ADDR(31 downto 16)) then
+ -- (c) Target IP address does not match
+ VALID_ARP_REQ <= '0';
+ end if;
+ elsif (MAC_RX_WORD_VALID_D = '1') and (unsigned(MAC_RX_WORD_COUNT) = 5) then
+ if(MAC_RX_DATA_VALID_D(7 downto 6) /= "11") or (MAC_RX_DATA_D(63 downto 48) /= IPv4_ADDR(15 downto 0)) then
+ -- (c) Target IP address does not match
+ VALID_ARP_REQ <= '0';
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+
+--// freeze source MAC address and source IP address at the end of the packet
+-- Reason: we don't want subsequent packets to change this information while we are waiting
+-- to send the ARP reply.
+FREEZE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_SOURCE_MAC_ADDR0 <= (others => '0');
+ RX_SOURCE_IP_ADDR0 <= (others => '0');
+ elsif(MAC_RX_EOF = '1') and (STATE = 0) then
+ RX_SOURCE_MAC_ADDR0 <= RX_SOURCE_MAC_ADDR;
+ RX_SOURCE_IP_ADDR0 <= RX_SOURCE_IP_ADDR;
+ end if;
+ end if;
+end process;
+
+--// ARP REPLY -----------------
+--// Generate ARP reply packet on the fly
+ARP_RESP_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_TX_DATA <= (others => '0');
+ MAC_TX_DATA_VALID <= (others => '0');
+ MAC_TX_EOF_local <= '0';
+ elsif(MAC_TX_CTS = '1') and (RPTR <= 6) then
+ case(RPTR) is
+ -- destination Ethernet address
+ when "000000" =>
+ MAC_TX_DATA(63 downto 16) <= RX_SOURCE_MAC_ADDR0;
+ -- source Ethernet address
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ -- our Ethernet address (2 MSBs)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000001" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ -- our Ethernet address (4 LSBs)
+ MAC_TX_DATA(31 downto 0) <= x"08060001";
+ -- Ethernet type, hardware type
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000010" =>
+ MAC_TX_DATA(63 downto 16) <= x"080006040002";
+ -- protocol type
+ -- hardware size, protocol size
+ -- op field. ARP reply
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ -- source Ethernet address (2 MSBs)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000011" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ -- our Ethernet address (4 LSBs)
+ MAC_TX_DATA(31 downto 0) <= IPv4_ADDR(31 downto 0);
+ -- sender IP address
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000100" =>
+ MAC_TX_DATA(63 downto 16) <= RX_SOURCE_MAC_ADDR0;
+ -- destination Ethernet address
+ MAC_TX_DATA(15 downto 0) <= RX_SOURCE_IP_ADDR0(31 downto 16);
+ -- target IP address (2 MSBs)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000101" =>
+ MAC_TX_DATA(63 downto 48) <= RX_SOURCE_IP_ADDR0(15 downto 0);
+ -- target IP address (2 LSBs)
+ MAC_TX_DATA(47 downto 0) <= (others => '0');
+ MAC_TX_DATA_VALID <= x"C0";
+ MAC_TX_EOF_local <= '1';
+ when others =>
+ MAC_TX_DATA <= (others => '0');
+ MAC_TX_DATA_VALID <= x"00";
+ MAC_TX_EOF_local <= '0';
+ end case;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ MAC_TX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+--// Sequence reply transmission and Flow control
+-- Request to send when ARP reply is ready.
+RTS_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RTS <= '0';
+ RPTR <= (others => '0');
+ elsif(STATE = 0) and (MAC_RX_EOF_D2 = '1') and (VALID_ARP_REQ = '1') then
+ -- Valid & complete ARP request was received. Start reply transmission.
+ RTS <= '1'; -- tell MAC we have a packet to send
+ RPTR <= (others => '0');
+ elsif(MAC_TX_CTS = '1') and (RPTR < 5) then
+ -- Assemble reply on the fly.
+ -- Always Ethernet encapsulation
+ RPTR <= RPTR + 1; -- move read pointer in response to read request
+ elsif(MAC_TX_CTS = '1') and (RPTR = 5) then
+ RPTR <= RPTR + 1; -- move read pointer in response to read request
+ RTS <= '0';
+ end if;
+ end if;
+end process;
+
+
+--// Test Point
+TP(1) <= MAC_RX_SOF_D;
+TP(2) <= MAC_RX_WORD_VALID_D;
+TP(3) <= STATE(0);
+TP(4) <= VALID_ARP_REQ;
+--TP(5) <= '1' when (unsigned(RX_TYPE) = 2) else '0';
+--TP(6) <= RPTR(0);
+TP(5) <= '1' when (IPv4_ADDR = x"A9FE5080") else '0';
+TP(6) <= MAC_TX_EOF_local;
+TP(10 downto 7) <= (others => '0');
+
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/arp_cache2_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/arp_cache2_10G.vhd
new file mode 100644
index 0000000..d031b09
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/arp_cache2_10G.vhd
@@ -0,0 +1,1191 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: ARP_CACHE2_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 1
+-- Date last modified: 5/24/19
+-- Inheritance: COM-5402 ARP_CACHE2.VHD 5/10/17 rev7
+--
+-- description: table linking 32-bit IPv4 or 128-bit IPv6 addresses to 48-bit MAC addresses and the information
+-- "freshness", i.e. time last seen, in effect a routing table.
+-- Uses one 16Kbit block RAM for a maximum of 128 entries.
+-- This component determines whether the destination IP address is local or not. In the
+-- latter case, the MAC address of the gateway is returned.
+-- Only records regarding local addresses are stored (i.e. not WAN addresses since these often
+-- point to the router MAC address anyway).
+--
+-- Assumming a 156.25 MHz clock...
+-- Time to access an existing record: between 24ns to 850ns max depending on the record location in the table.
+
+-- An important startup issue is that ARP requests sent shortly after power up are
+-- lost either at our LAN IC or at the destination LAN network interface card (PC
+-- operating system slow at detecting a new LAN connection).
+--
+-- Rev1 5/24/19
+-- Corrected bug when searching for IP match at address 0
+--
+-- Device utilization (IPv6_ENABLED='1')
+-- FF: 1629
+-- LUT: 1849
+-- DSP48: 0
+-- 18Kb BRAM: 5
+-- BUFG: 1
+-- Minimum period: 4.952ns (Maximum Frequency: 201.939MHz) Artix7-100T -1 speed grade
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity ARP_CACHE2_10G is
+ generic (
+ IPv6_ENABLED: std_logic := '1'
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ -- synchronous reset: MANDATORY to properly initialize this component
+ CLK: in std_logic;
+ -- reference clock.
+ -- Global clock. No BUFG instantiation within this component.
+ TICK_100MS : in std_logic;
+ -- 100 ms tick for timer
+
+ --// User interface (query/reply)
+ -- (a) query
+ RT_IP_ADDR: in std_logic_vector(127 downto 0);
+ -- user query: destination IP address to resolve (could be local or remote). read when RT_REQ_RTS = '1'
+ RT_IPv4_6n: in std_logic;
+ -- IP version for RT_IP_ADDR: 1 for IPv4, 0 for IPv6
+ RT_REQ_RTS: in std_logic;
+ -- new requests will be ignored until the module is
+ -- finished with the previous request/reply transaction
+ RT_CTS: out std_logic;
+ -- ready to accept a new routing query.
+ -- (b) reply
+ RT_MAC_REPLY: out std_logic_vector(47 downto 0);
+ -- Destination MAC address associated with the destination IP address RT_IP_ADDR.
+ -- Could be the Gateway MAC address if the destination IP address is outside the local area network.
+ RT_MAC_RDY: out std_logic;
+ -- 1 CLK pulse to read the MAC reply
+ -- The worst case latency from the RT_REQ_RTS request is 1.33us
+ -- If there is no match in the table, no response will be provided. Calling routine should
+ -- therefore have a timeout timer to detect lack of response.
+ RT_NAK: out std_logic;
+ -- 1 CLK pulse indicating that no record matching the RT_IP_ADDR was found in the table.
+
+ --// Routing information
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ -- local MAC address
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ -- local IP address. 4 bytes for IPv4
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+ IPv4_SUBNET_MASK: in std_logic_vector(31 downto 0);
+ -- local subnet mask. used to distinguish local vs wan packets
+ IPv4_GATEWAY_ADDR: in std_logic_vector(31 downto 0);
+ -- Gateway IP address. Direct WAN packets to that gateway if non-local;
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- local IP address. 16 bytes for IPv6
+ IPv6_SUBNET_PREFIX_LENGTH: in std_logic_vector(7 downto 0);
+ -- 128 - subnet size in bits. Usually expressed as /n. Typical range 64-128
+ IPv6_GATEWAY_ADDR: in std_logic_vector(127 downto 0);
+ -- upper 64 bits MUST match our IPv6 address (i.e. gateway MUST be on the same network)
+
+ --// WHOIS interface (send ARP request)
+ WHOIS_IP_ADDR: out std_logic_vector(127 downto 0) := (others => '0');
+ -- user query: IP address to resolve. read at WHOIS_START
+ WHOIS_IPv4_6n: out std_logic;
+ -- IP version for WHOIS_IP_ADDR: 1 for IPv4, 0 for IPv6
+ WHOIS_START: out std_logic := '0';
+ -- 1 CLK pulse to start the ARP query
+ -- Note: since we do not check for the WHOIS_RDY signal, there is a small probability that WHOIS is busy
+ -- and that the request will be ignored. Higher-level Application should ask again in this case.
+
+ --// Source MAC/IP addresses
+ -- Packet origin, parsed in PACKET_PARSING (shared code) from
+ -- ARP responses and IP packets. Ignored when the component is busy.
+ RX_SOURCE_ADDR_RDY: in std_logic;
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0); -- all received packets
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0); -- IPv4,ARP
+ RX_IPv4_6n: in std_logic;
+
+ -- Test Points
+ SREG1 : OUT std_logic_vector(7 downto 0);
+ SREG2 : OUT std_logic_vector(7 downto 0);
+ SREG3 : OUT std_logic_vector(7 downto 0);
+ SREG4 : OUT std_logic_vector(7 downto 0);
+ SREG5 : OUT std_logic_vector(7 downto 0);
+ SREG6 : OUT std_logic_vector(7 downto 0);
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of ARP_CACHE2_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+ */
+
+ component tdp_ram is
+ generic (
+ ADDR_WIDTH : natural;
+ DATA_WIDTH : integer);
+ port (
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic := '1';
+ enb : in std_logic := '1';
+ wea : in std_logic;
+ web : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dib : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ doa : out std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+ end component tdp_ram;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+constant REFRESH_PERIOD: unsigned(19 downto 0) := x"00BB8"; -- time between entries refreshed (5 minutes)
+constant ADDR_WIDTH: integer := 8; -- table size is 2^(ADDR_WIDTH-1) entries
+
+--// TIME ------------------------------------------------
+signal TIMER1: integer range 0 to 50 := 0;
+signal IPv4GATEWAY_REFRESH_TIMER: unsigned(11 downto 0) := (others => '0'); -- 12-bits = 409.6s refresh max
+signal IPv6GATEWAY_REFRESH_TIMER: unsigned(11 downto 0) := (others => '0'); -- 12-bits = 409.6s refresh max
+signal TIME_CNTR: unsigned(19 downto 0) := (others => '0');
+signal TIMEDIFF: unsigned(19 downto 0) := (others => '0');
+
+--//-- NEW QUERY IP CHECK ---------------------------------------------------
+signal IPv6_SUBNET_MASK: std_logic_vector(63 downto 0) := (others => '0');
+signal IPv4_MASKED: std_logic_vector(31 downto 0) := (others => '0');
+signal IPv6_MASKED: std_logic_vector(63 downto 0) := (others => '0');
+signal RT_IP_ADDR_MASKED: std_logic_vector(63 downto 0) := (others => '0');
+signal RT_IP_ADDR_D: std_logic_vector(127 downto 0) := (others => '0');
+signal RT_IPv4_6n_D: std_logic := '0';
+signal EVENT1: std_logic := '0';
+signal EVENT2: std_logic := '0';
+signal EVENT3: std_logic := '0';
+signal EVENT4: std_logic := '0';
+signal EVENT5: std_logic := '0';
+signal EVENT6: std_logic := '0';
+signal EVENT7: std_logic := '0';
+signal EVENT8: std_logic := '0';
+signal EVENT9: std_logic := '0';
+signal EVENT10: std_logic := '0';
+signal EVENTB1: std_logic := '0';
+signal EVENTB2: std_logic := '0';
+
+--//-- B-SIDE STATE MACHINE ---------------------------------------
+signal MEMORY_INITIALIZED: std_logic := '0';
+signal STATE_B: integer range 0 to 8;
+signal STATE_B_D: integer range 0 to 8;
+signal STATE_B_D2: integer range 0 to 8;
+signal STATE_B_D3: integer range 0 to 8;
+signal LAST_IP: std_logic_vector(63 downto 0) := (others => '0');
+signal LAST_IPv4_6n: std_logic := '0';
+signal LAST_MAC: std_logic_vector(47 downto 0) := (others => '0');
+signal LAST_TIME: unsigned(19 downto 0) := (others => '0');
+signal RT_MAC_RDY_local: std_logic := '0';
+signal RT_NAK_local: std_logic := '0';
+signal RT_MAC_REPLY_local: std_logic_vector(47 downto 0) := (others => '0');
+signal ADDRB: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0'); -- table is 128 entries x 133b + 1 bit for overflow detection
+signal ADDRB_INC: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal ADDRB_D: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal ADDRB_D2: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WHOIS_START_local: std_logic := '0';
+signal WHOIS_IP_ADDR_local: std_logic_vector(127 downto 0) := (others => '0');
+signal WHOIS_IPv4_6n_local: std_logic := '0';
+signal WHOIS_IPv4GATEWAY: std_logic := '0';
+signal WHOIS_IPv6GATEWAY: std_logic := '0';
+
+--//-- ROUTING TABLE ---------------------------------------------------
+signal WEA: std_logic := '0';
+signal WEB: std_logic := '0';
+signal ENA: std_logic := '0';
+signal ENB: std_logic := '0';
+signal DIA: std_logic_vector(132 downto 0) := (others => '0');
+signal DOA: std_logic_vector(132 downto 0) := (others => '0');
+signal DOA_D: std_logic_vector(132 downto 0) := (others => '0');
+signal DIB: std_logic_vector(132 downto 0) := (others => '0');
+signal DOB: std_logic_vector(132 downto 0) := (others => '0');
+signal DOB_D: std_logic_vector(132 downto 0) := (others => '0');
+
+--//-- KEY MATCH ---------------------------------------------------
+signal ZERO_IP_AMATCH: std_logic_vector (3 downto 0) := (others => '0');
+signal IP_KEY1_AMATCH: std_logic_vector (4 downto 0) := (others => '0');
+signal IP_KEY1_BMATCH: std_logic_vector (4 downto 0) := (others => '0');
+signal IP_KEY1_MATCH: std_logic := '0';
+signal IP_KEY1: std_logic_vector (64 downto 0) := (others => '0');
+signal IP_KEY1_MAC: std_logic_vector(47 downto 0) := (others => '0');
+signal IP_KEY1_TIME: unsigned(19 downto 0) := (others => '0');
+signal IP_KEY2_AMATCH: std_logic_vector (4 downto 0) := (others => '0');
+signal IP_KEY2_BMATCH: std_logic_vector (4 downto 0) := (others => '0');
+signal IP_KEY2_MATCH: std_logic := '0';
+signal IP_KEY2: std_logic_vector (64 downto 0) := (others => '0');
+signal IP_KEY2_ADDR: std_logic_vector (ADDR_WIDTH-2 downto 0) := (others => '0');
+
+--//-- NEW MAC/IP ADDRESSES ENTRY ---------------------------------------------------
+signal RX_SOURCE_MAC_ADDR_D: std_logic_vector(47 downto 0) := (others => '0');
+signal RX_SOURCE_IP_ADDR_D: std_logic_vector(127 downto 0) := (others => '0');
+signal RX_IPv4_6n_D: std_logic := '0';
+signal LAST_RX_MAC: std_logic_vector(47 downto 0) := (others => '0');
+signal LAST_RX_IP: std_logic_vector(127 downto 0) := (others => '0');
+signal LAST_RX_IPv4_6n: std_logic := '0';
+signal LAST_RX_TIME: unsigned(19 downto 0) := (others => '0');
+signal RX_SOURCE_IP_ADDR_MASKED:std_logic_vector(63 downto 0) := (others => '0');
+
+--//-- A-SIDE STATE MACHINE ---------------------------------------
+signal EVENTA1: std_logic := '0';
+signal STATE_A: integer range 0 to 4 := 0;
+signal STATE_A_D: integer range 0 to 4 := 0;
+signal STATE_A_D2: integer range 0 to 4 := 0;
+signal ADDRA: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0'); -- table is 128 entries x 133b + 1 bit for overflow detection
+signal ADDRA_D: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal ADDRA_D2: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal GATEWAYv4_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal GATEWAYv6_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+
+--//-- FIND OLDEST ENTRY -----------------------------
+signal TIME_A: unsigned(19 downto 0) := (others => '0');
+signal TIME_B: unsigned(19 downto 0) := (others => '0');
+signal OLDEST_TIME: unsigned(19 downto 0) := (others => '0');
+signal OLDEST_ADDR: unsigned(ADDR_WIDTH-2 downto 0) := (others => '0');
+signal VIRGIN: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// TIME ------------------------------------------------
+-- keep track of time, by increments of 100ms
+-- range: 29 hours
+TIME_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') then
+ TIME_CNTR <= (others => '0');
+ elsif(TICK_100MS = '1') then
+ TIME_CNTR <= TIME_CNTR + 1;
+ end if;
+
+ -- to improve timing, pre-compute TIME_CNTR - REFRESH_PERIOD
+ TIMEDIFF <= TIME_CNTR - REFRESH_PERIOD;
+
+ end if;
+end process;
+
+-- prevent flood of ARP requests / Neighbor solicitations being sent out
+TIMER1_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') then
+ TIMER1 <= 0;
+ elsif (WHOIS_START_local = '1') then
+ -- re-arm timer
+ TIMER1 <= 10;
+ elsif(TICK_100MS = '1') and (TIMER1 > 0) then
+ TIMER1 <= TIMER1 - 1;
+ end if;
+ end if;
+end process;
+
+-- gateway MAC refresh timer. 12-bits = 409.6s refresh max
+IPv4GATEWAY_REFRESH_TIMER_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') then
+ IPv4GATEWAY_REFRESH_TIMER <= to_unsigned(11,IPv4GATEWAY_REFRESH_TIMER'length);
+ -- first ARP request approximately 1s after FPGA is configured
+ elsif(WHOIS_IPv4GATEWAY = '1') then
+ -- sent the ARP request. awaiting ARP reply. Short timer value to prevent a flood of ARP requests.
+ -- If no gateway response, another ARP request will be sent in 30 seconds
+ IPv4GATEWAY_REFRESH_TIMER <= to_unsigned(301,IPv4GATEWAY_REFRESH_TIMER'length);
+ -- use slightly different timers to alleviate repetitive contentions
+ elsif (RX_SOURCE_ADDR_RDY = '1') and (RX_IPv4_6n = '1') and (RX_SOURCE_IP_ADDR(31 downto 0) = IPv4_GATEWAY_ADDR) then
+ -- re-arm timer
+ IPv4GATEWAY_REFRESH_TIMER <= REFRESH_PERIOD(IPv4GATEWAY_REFRESH_TIMER'left downto 0);
+ elsif(TICK_100MS = '1') and (IPv4GATEWAY_REFRESH_TIMER > 0) then
+ IPv4GATEWAY_REFRESH_TIMER <= IPv4GATEWAY_REFRESH_TIMER - 1;
+ end if;
+ end if;
+end process;
+
+IPv6GATEWAY_REFRESH_TIMER_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') or (IPv6_ENABLED = '0') then
+ IPv6GATEWAY_REFRESH_TIMER <= to_unsigned(12,IPv6GATEWAY_REFRESH_TIMER'length);
+ -- first ARP request approximately 1s after FPGA is configured
+ elsif(WHOIS_IPv6GATEWAY = '1') then
+ -- sent the ARP request. awaiting ARP reply. Short timer value to prevent a flood of ARP requests
+ -- If no gateway response, another ARP request will be sent in 30 seconds
+ IPv6GATEWAY_REFRESH_TIMER <= to_unsigned(302,IPv6GATEWAY_REFRESH_TIMER'length);
+ -- use slightly different timers to alleviate repetitive contentions
+ elsif (RX_SOURCE_ADDR_RDY = '1') and (RX_IPv4_6n = '0') and (RX_SOURCE_IP_ADDR = IPv6_GATEWAY_ADDR) then
+ -- re-arm timer
+ IPv6GATEWAY_REFRESH_TIMER <= REFRESH_PERIOD(IPv6GATEWAY_REFRESH_TIMER'left downto 0);
+ elsif(TICK_100MS = '1') and (IPv4GATEWAY_REFRESH_TIMER > 0) then
+ IPv6GATEWAY_REFRESH_TIMER <= IPv6GATEWAY_REFRESH_TIMER - 1;
+ end if;
+ end if;
+end process;
+
+--//-- NEW QUERY IP CHECK ---------------------------------------------------
+-- Is target IP local or remote? If remote, the Gateway is the next hop
+-- -> search for Gateway MAC address instead.
+
+IPv6_SUBNET_MASK_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ for I in 64 to 127 loop
+ if(I >= to_integer(unsigned(IPv6_SUBNET_PREFIX_LENGTH))) then
+ IPv6_SUBNET_MASK(127-I) <= '0';
+ else
+ IPv6_SUBNET_MASK(127-I) <= '1';
+ end if;
+ end loop;
+ end if;
+end process;
+
+LATCH_RT_IP_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IPv4_MASKED <= IPv4_ADDR and IPv4_SUBNET_MASK;
+ IPv6_MASKED <= IPv6_ADDR(63 downto 0) and IPv6_SUBNET_MASK; -- no need for the upper 64-bits
+
+ -- new request
+ if(STATE_B = 0) and (RT_REQ_RTS = '1') then
+ -- idle + new query. freeze input information during the query
+ -- just in case two requests are very close to eachother)
+ if(RT_IPv4_6n = '1') then
+ RT_IP_ADDR_MASKED(31 downto 0) <= RT_IP_ADDR(31 downto 0) and IPv4_SUBNET_MASK;
+ elsif(IPv6_ENABLED = '1') then
+ -- IPv6
+ RT_IP_ADDR_MASKED <= RT_IP_ADDR(63 downto 0) and IPv6_SUBNET_MASK;
+ end if;
+ RT_IP_ADDR_D <= RT_IP_ADDR;
+ RT_IPv4_6n_D <= RT_IPv4_6n;
+
+ -- process events 1 CLK before use (for better timing)
+ if (unsigned(RT_IP_ADDR(31 downto 24)) >= 224) and (unsigned(RT_IP_ADDR(31 downto 24)) <= 239) then
+ EVENT1 <= '1';
+ else
+ EVENT1 <= '0';
+ end if;
+
+ if (RT_IP_ADDR(31 downto 0) = x"FF_FF_FF_FF") then
+ EVENT2 <= '1';
+ else
+ EVENT2 <= '0';
+ end if;
+
+ if(RT_IP_ADDR(31 downto 0) = LAST_IP(31 downto 0)) and (LAST_IPv4_6n = '1') and (EVENTB1 = '1') then
+ EVENT3 <= '1';
+ else
+ EVENT3 <= '0';
+ end if;
+
+ if(RT_IP_ADDR(31 downto 0) = IPv4_GATEWAY_ADDR) and (unsigned(GATEWAYv4_MAC_ADDR) /= 0) then
+ EVENT4 <= '1';
+ else
+ EVENT4 <= '0';
+ end if;
+
+ if(RT_IP_ADDR(31 downto 0) = x"7F000001") or (RT_IP_ADDR(31 downto 0) = IPv4_ADDR) then
+ EVENT5 <= '1';
+ else
+ EVENT5 <= '0';
+ end if;
+
+ if (RT_IPv4_6n = '0') and (RT_IP_ADDR(127 downto 120) = x"FF") then
+ EVENT6 <= '1';
+ else
+ EVENT6 <= '0';
+ end if;
+
+ if (RT_IP_ADDR(127 downto 112) = x"FE80") and (RT_IP_ADDR(127 downto 64) /= IPv6_ADDR(127 downto 64)) then
+ EVENT7 <= '1';
+ else
+ EVENT7 <= '0';
+ end if;
+
+ if (RT_IP_ADDR(63 downto 0) = LAST_IP(63 downto 0)) and (LAST_IPv4_6n = '0') and (EVENTB1 = '1') then
+ EVENT8 <= '1';
+ else
+ EVENT8 <= '0';
+ end if;
+
+ if (RT_IP_ADDR(63 downto 0) = IPv6_GATEWAY_ADDR(63 downto 0)) and (unsigned(GATEWAYv6_MAC_ADDR) /= 0) then
+ EVENT9 <= '1';
+ else
+ EVENT9 <= '0';
+ end if;
+
+ if (RT_IP_ADDR(63 downto 0) = x"0000000000000001") or (RT_IP_ADDR(63 downto 0) = IPv6_ADDR(63 downto 0)) then
+ EVENT10 <= '1';
+ else
+ EVENT10 <= '0';
+ end if;
+
+
+
+ end if;
+ end if;
+end process;
+
+EVENTB1 <= '1' when (TIMEDIFF < LAST_TIME) or ((TIMEDIFF(TIMEDIFF'left) = '1') and (LAST_TIME(LAST_TIME'left) = '0')) else '0';
+ -- '1' when LAST_TIME is recent (i.e. occurred less than refresh period)
+ -- Code is a bit tricky because of the wrap-around unsigned time
+ -- Also because we rephrased this time comparison for better timing (TIMEDIFF is pipelined already)
+
+EVENTB2 <= '1' when (TIMEDIFF < IP_KEY1_TIME) or ((TIMEDIFF(TIMEDIFF'left) = '1') and (IP_KEY1_TIME(IP_KEY1_TIME'left) = '0')) else '0';
+ -- '1' when record found in database is recent enough, '0' when record is too old
+
+-- accept new routing queries when idle
+RT_CTS <= MEMORY_INITIALIZED when (STATE_B = 0) else '0';
+
+----//-- B-SIDE STATE MACHINE ---------------------------------------
+---- B-side of the block RAM used for (a) block RAM initialization and (b) look-up table
+
+ADDRB_INC <= ADDRB + 1;
+
+STATE_MACHINE_B_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ ADDRB_D <= ADDRB; -- 1 CLK delay to read data from the block RAM.
+ ADDRB_D2 <= ADDRB_D; -- 1 CLK delay to read data from the block RAM.
+ STATE_B_D <= STATE_B;
+ STATE_B_D2 <= STATE_B_D;
+ STATE_B_D3 <= STATE_B_D2;
+
+ if(SYNC_RESET = '1') or ((MEMORY_INITIALIZED = '0') and (STATE_B /= 8))then
+ STATE_B <= 8; -- start with clearing the RAMB (could remember old entries?)
+ RT_MAC_REPLY_local <= (others => '0');
+ RT_MAC_RDY_local <= '0';
+ ADDRB <= (others => '0');
+ WEB <= '1';
+ elsif(STATE_B = 8) then
+ -- one-time RAMB initialization. Scan through all the block RAM addresses 0 - 127
+ if(ADDRB_INC(ADDR_WIDTH-1) = '1') then
+ -- done.
+ MEMORY_INITIALIZED <= '1';
+ STATE_B <= 0;
+ WEB <= '0';
+ else
+ ADDRB <= ADDRB + 1;
+ DIB(112+ADDR_WIDTH downto 113) <= std_logic_vector(ADDRB);
+ -- trick so that first entry (oldest timestamp) will be at address 0 (to minimize the search time)
+ end if;
+ elsif(STATE_B = 0) then
+ -- idle
+ ADDRB <= (others => '0');
+ RT_MAC_RDY_local <= '0'; -- clear
+ if (RT_REQ_RTS = '1') then
+ -- new query. (1 CLK duration)
+ STATE_B <= 1;
+ end if;
+ elsif(STATE_B = 1) then
+ -- In the several cases below, there is no need for a table search. STATE_B goes back to zero
+ if (RT_IPv4_6n_D = '1') then
+ if (EVENT1 = '1') then -- new 12/21/15 AZ
+ -- IPv4 multicast destination
+ RT_MAC_REPLY_local(47 downto 24) <= x"01_00_5E";
+ RT_MAC_REPLY_local(23 downto 0) <= "0" & RT_IP_ADDR_D(22 downto 0);
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (EVENT2 = '1') then
+ -- Broadcast IP 255.255.255.255
+ RT_MAC_REPLY_local <= x"FF_FF_FF_FF_FF_FF";
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (RT_IP_ADDR_MASKED(31 downto 0) /= IPv4_MASKED) or (EVENT4 = '1') then
+ -- remote (WAN) address. substitute Gateway IP
+ -- (b) Gateway IPv4
+ -- Do not forward IP broadcast messages to the WAN
+ RT_MAC_REPLY_local <= GATEWAYv4_MAC_ADDR;
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (EVENT3 = '1') then
+ -- (a) same as last and last information is recent. No need to go further. Same reply.
+ RT_MAC_REPLY_local <= LAST_MAC;
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (EVENT5 = '1') then
+ -- (c) local host 127.0.0.1. Local loopback
+ RT_MAC_REPLY_local <= MAC_ADDR;
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ else
+ STATE_B <= 2;
+ ADDRB <= (others => '0'); -- prepare to read in STATE_B = 3
+ end if;
+ elsif (IPv6_ENABLED = '1') then
+ if (EVENT6 = '1') then
+ -- IPv6 multicast destination
+ RT_MAC_REPLY_local(47 downto 32) <= x"33_33";
+ RT_MAC_REPLY_local(31 downto 0) <= RT_IP_ADDR_D(31 downto 0);
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (EVENT9 = '1') or (EVENT7 = '1') or ((RT_IP_ADDR_D(127 downto 112) = x"FE80") and (RT_IP_ADDR_MASKED(63 downto 0) /= IPv6_MASKED)) then -- *042918
+ -- unicast destination address, different network/subnet -> remote (WAN) address. substitute Gateway IP
+ RT_MAC_REPLY_local <= GATEWAYv6_MAC_ADDR;
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (EVENT8 = '1') then
+ -- (a) same as last and last information is recent. No need to go further. Same reply.
+ RT_MAC_REPLY_local <= LAST_MAC;
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (EVENT10 = '1') then
+ -- (c) Local loopback
+ RT_MAC_REPLY_local <= MAC_ADDR;
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ else
+ STATE_B <= 2;
+ ADDRB <= (others => '0'); -- prepare to read in STATE_B = 3
+ end if;
+ end if;
+ elsif(STATE_B = 2) then
+ -- SEARCH TABLE
+ STATE_B <= 3; -- scan routing table from the bottom
+ ADDRB <= ADDRB + 1; -- go from 0 to 1
+ elsif (STATE_B = 3) then
+ -- scan records 0 - 127 or until we find the target IP address
+ -- is there a match with the query?
+ if(IP_KEY1_MATCH = '1') then
+ -- found a match
+ RT_MAC_REPLY_local <= IP_KEY1_MAC;
+ RT_MAC_RDY_local <= '1';
+ STATE_B <= 0; -- back to idle
+ elsif (ADDRB_D2(ADDR_WIDTH-1) = '1') then
+ -- no match found. reached end of range and yet no match.
+ -- note STATE_B=3 is extended three more clocks to wait for the last possible key match
+ -- send out an ARP request IF some conditions are met
+ STATE_B <= 0; -- back to idle
+ else
+ -- scan until we find the Target IP address
+ ADDRB <= ADDRB + 1; -- just look up the IP key to scan fast
+ end if;
+ end if;
+ end if;
+end process;
+RT_MAC_RDY <= RT_MAC_RDY_local;
+RT_NAK <= RT_NAK_local;
+RT_MAC_REPLY <= RT_MAC_REPLY_local;
+
+STATE_MACHINE_B_010: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MEMORY_INITIALIZED = '0') then
+ WHOIS_START_local <= '0';
+ elsif (STATE_B = 3) and (IP_KEY1_MATCH = '1') then
+ -- found a match
+ if(EVENTB2 = '0') then
+ -- If the record is too old, send another ARP request to refresh the table
+ WHOIS_IPv4_6n_local <= RT_IPv4_6n_D;
+ WHOIS_START_local <= '1';
+ if(RT_IPv4_6n_D = '1') then
+ -- IPv4
+ WHOIS_IP_ADDR_local(31 downto 0) <= RT_IP_ADDR_D(31 downto 0);
+ WHOIS_IP_ADDR_local(127 downto 32) <= (others => '0');
+ elsif(IPv6_ENABLED = '1') then
+ -- IPv6
+ WHOIS_IP_ADDR_local(63 downto 0) <= RT_IP_ADDR_D(63 downto 0);
+ WHOIS_IP_ADDR_local(127 downto 64) <= RT_IP_ADDR_D(127 downto 64);
+ end if;
+ end if;
+ elsif (STATE_B = 3) and (ADDRB_D2(ADDR_WIDTH-1) = '1') then
+ -- no. reached end of range and yet no match
+ -- send out an ARP request IF some conditions are met
+ if(RT_IP_ADDR_D(63 downto 0) /= WHOIS_IP_ADDR_local(63 downto 0)) or (RT_IPv4_6n_D /= WHOIS_IPv4_6n_local) or (TIMER1 = 0) then
+ -- different address from last ARP request
+ -- OR elapsed enough time since last similar ARP request
+ WHOIS_IPv4_6n_local <= RT_IPv4_6n_D;
+ WHOIS_START_local <= '1';
+ if(RT_IPv4_6n_D = '1') then
+ -- IPv4
+ WHOIS_IP_ADDR_local(31 downto 0) <= RT_IP_ADDR_D(31 downto 0);
+ WHOIS_IP_ADDR_local(127 downto 32) <= (others => '0');
+ elsif(IPv6_ENABLED = '1') then
+ -- IPv6
+ WHOIS_IP_ADDR_local <= RT_IP_ADDR_D;
+ end if;
+ end if;
+ elsif (STATE_B = 0) and (IPv4GATEWAY_REFRESH_TIMER = 0) and (WHOIS_IPv4GATEWAY = '0') then
+ -- refresh gateway IPv4 MAC
+ WHOIS_IP_ADDR_local(31 downto 0) <= IPv4_GATEWAY_ADDR;
+ WHOIS_IP_ADDR_local(127 downto 32) <= (others => '0');
+ WHOIS_IPv4_6n_local <= '1';
+ WHOIS_START_local <= '1';
+ WHOIS_IPv4GATEWAY <= '1';
+ elsif (IPv6_ENABLED = '1') and (STATE_B = 0) and (IPv6GATEWAY_REFRESH_TIMER = 0) and (WHOIS_IPv6GATEWAY = '0') then
+ -- refresh gateway IPv6 MAC
+ WHOIS_IP_ADDR_local <= IPv6_GATEWAY_ADDR;
+ WHOIS_IPv4_6n_local <= '0';
+ WHOIS_START_local <= '1';
+ WHOIS_IPv6GATEWAY <= '1';
+ else
+ WHOIS_START_local <= '0';
+ WHOIS_IPv4GATEWAY <= '0';
+ WHOIS_IPv6GATEWAY <= '0';
+ end if;
+ end if;
+end process;
+WHOIS_START <= WHOIS_START_local;
+WHOIS_IP_ADDR <= WHOIS_IP_ADDR_local;
+WHOIS_IPv4_6n <= WHOIS_IPv4_6n_local;
+
+-- break down state machine into smaller parts (otherwise timing is bad)
+STATE_MACHINE_B_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MEMORY_INITIALIZED = '0') then
+ LAST_IP <= (others => '0');
+ LAST_IPv4_6n <= '0';
+ LAST_MAC <= (others => '0');
+ LAST_TIME <= (others => '0');
+ elsif (STATE_B_D3 = 3) then
+ -- scan records 0 - 127 or until we find the target IP address
+
+ -- is there a match with the query?
+ if (IP_KEY1_MATCH = '1') then
+ -- yes!
+ -- remember last valid response just in case someone asks again (saves time)
+ LAST_IP <= RT_IP_ADDR_D(63 downto 0);
+ LAST_IPv4_6n <= RT_IPv4_6n_D;
+ LAST_MAC <= IP_KEY1_MAC;
+ LAST_TIME <= IP_KEY1_TIME;
+ end if;
+ end if;
+ end if;
+end process;
+
+STATE_MACHINE_B_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ --if (STATE_B = 3) and (ADDRB(ADDR_WIDTH-1) = '1') and ((RT_IP_ADDR_D(63 downto 0) /= DOB(63 downto 0)) or (RT_IPv4_6n_D /= DOB(112))) then
+ if(SYNC_RESET = '1') or ((MEMORY_INITIALIZED = '0') and (STATE_B /= 8))then
+ RT_NAK_local <= '0'; -- clear
+ elsif (STATE_B = 3) and (IP_KEY1_MATCH = '0') and (ADDRB_D2(ADDR_WIDTH-1) = '1') then -- *080918
+ -- scan records 0 - 127 or until we find the target IP address
+ -- no. reached end of range and yet no match
+ -- send a NAK to the caller
+ RT_NAK_local <= '1';
+ else
+ RT_NAK_local <= '0'; -- clear
+ end if;
+ end if;
+end process;
+
+
+
+
+
+--//-- ROUTING TABLE ---------------------------------------------------
+-- Each entry comprises 133 bits: 64-bit IP address (full IPv4 or the local part of IPv6) + 1-bit IPversion + 48-bit MAC address + 20-bit TIME
+ENA <= '0' when (SYNC_RESET = '1') else '1'; -- to prevent warnings in modelsim
+ENB <= '0' when (SYNC_RESET = '1') else '1';
+
+-- split into narrower 18Kb BRAMs for slightly better timing on Xilinx (marginal improvement 070918)
+-- original: one 133 bit-wide BRAM
+BRAM_DP2_00x: for I in 0 to 3 generate
+
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ BRAM_DP2_001: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 32,
+ ADDR_WIDTHA => ADDR_WIDTH-1, -- 2^(ADDR_WIDTH-1) entries
+ DATA_WIDTHB => 32,
+ ADDR_WIDTHB => ADDR_WIDTH-1
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA,
+ ADDRA => std_logic_vector(ADDRA(ADDR_WIDTH-2 downto 0)),
+ DIA => DIA(32*I +31 downto 32*I),
+ OEA => '1',
+ DOA => DOA(32*I +31 downto 32*I),
+ CSB => '1',
+ CLKB => CLK,
+ WEB => WEB,
+ ADDRB => std_logic_vector(ADDRB(ADDR_WIDTH-2 downto 0)),
+ DIB => DIB(32*I +31 downto 32*I),
+ OEB => '1',
+ DOB => DOB(32*I +31 downto 32*I)
+ );
+ */
+
+ BRAM_DP2_001: TDP_RAM
+ GENERIC MAP(
+ DATA_WIDTH => 32,
+ ADDR_WIDTH => ADDR_WIDTH-1)
+ PORT MAP(
+ CLKA => CLK,
+ WEA => WEA,
+ ADDRA => std_logic_vector(ADDRA(ADDR_WIDTH-2 downto 0)),
+ DIA => DIA(32*I +31 downto 32*I),
+ DOA => DOA(32*I +31 downto 32*I),
+ CLKB => CLK,
+ WEB => WEB,
+ ADDRB => std_logic_vector(ADDRB(ADDR_WIDTH-2 downto 0)),
+ DIB => DIB(32*I +31 downto 32*I),
+ DOB => DOB(32*I +31 downto 32*I));
+
+end generate;
+
+ /*
+ BRAM_DP2_001b: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 5,
+ ADDR_WIDTHA => ADDR_WIDTH-1, -- 2^(ADDR_WIDTH-1) entries
+ DATA_WIDTHB => 5,
+ ADDR_WIDTHB => ADDR_WIDTH-1
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA,
+ ADDRA => std_logic_vector(ADDRA(ADDR_WIDTH-2 downto 0)),
+ DIA => DIA(132 downto 128),
+ OEA => '1',
+ DOA => DOA(132 downto 128),
+ CSB => '1',
+ CLKB => CLK,
+ WEB => WEB,
+ ADDRB => std_logic_vector(ADDRB(ADDR_WIDTH-2 downto 0)),
+ DIB => DIB(132 downto 128),
+ OEB => '1',
+ DOB => DOB(132 downto 128)
+ );
+ */
+
+ BRAM_DP2_001b: TDP_RAM
+ GENERIC MAP(
+ DATA_WIDTH => 5,
+ ADDR_WIDTH => ADDR_WIDTH-1)
+ PORT MAP(
+ CLKA => CLK,
+ WEA => WEA,
+ ADDRA => std_logic_vector(ADDRA(ADDR_WIDTH-2 downto 0)),
+ DIA => DIA(132 downto 128),
+ DOA => DOA(132 downto 128),
+ CLKB => CLK,
+ WEB => WEB,
+ ADDRB => std_logic_vector(ADDRB(ADDR_WIDTH-2 downto 0)),
+ DIB => DIB(132 downto 128),
+ DOB => DOB(132 downto 128));
+
+-- for timing purposes pipeline the large comparisons into smaller subsets
+IP_KEY1_MATCH_DETECT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DOA_D <= DOA;
+ DOB_D <= DOB;
+
+ -- break 64-bit comparison into 4*16-bit comparisons
+ -- A side
+ for I in 0 to 3 loop
+ if(DOA(16*I+15 downto 16*I) = IP_KEY1(16*I+15 downto 16*I)) then
+ IP_KEY1_AMATCH(I) <= '1';
+ else
+ IP_KEY1_AMATCH(I) <= '0';
+ end if;
+ end loop;
+ if(DOA(112) = IP_KEY1(64)) then
+ IP_KEY1_AMATCH(4) <= '1';
+ else
+ IP_KEY1_AMATCH(4) <= '1';
+ end if;
+
+ -- B side
+ for I in 0 to 3 loop
+ if(DOB(16*I+15 downto 16*I) = IP_KEY1(16*I+15 downto 16*I)) then
+ IP_KEY1_BMATCH(I) <= '1';
+ else
+ IP_KEY1_BMATCH(I) <= '0';
+ end if;
+ end loop;
+ if(DOB(112) = IP_KEY1(64)) then
+ IP_KEY1_BMATCH(4) <= '1';
+ else
+ IP_KEY1_BMATCH(4) <= '1';
+ end if;
+
+ end if;
+end process;
+
+IP_KEY2_MATCH_DETECT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+
+ -- break 64-bit comparison into 4*16-bit comparisons
+ -- A side
+ for I in 0 to 3 loop
+ if(DOA(16*I+15 downto 16*I) = IP_KEY2(16*I+15 downto 16*I)) then
+ IP_KEY2_AMATCH(I) <= '1';
+ else
+ IP_KEY2_AMATCH(I) <= '0';
+ end if;
+ end loop;
+ if(DOA(112) = IP_KEY2(64)) then
+ IP_KEY2_AMATCH(4) <= '1';
+ else
+ IP_KEY2_AMATCH(4) <= '1';
+ end if;
+
+ -- B side
+ for I in 0 to 3 loop
+ if(DOB(16*I+15 downto 16*I) = IP_KEY2(16*I+15 downto 16*I)) then
+ IP_KEY2_BMATCH(I) <= '1';
+ else
+ IP_KEY2_BMATCH(I) <= '0';
+ end if;
+ end loop;
+ if(DOB(112) = IP_KEY2(64)) then
+ IP_KEY2_BMATCH(4) <= '1';
+ else
+ IP_KEY2_BMATCH(4) <= '1';
+ end if;
+
+ end if;
+end process;
+
+-- same for zero address. break into 4*16 comparisons for timing
+ZERO_IP_MATCH_DETECT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ -- break 64-bit comparison into 4*16-bit comparisons
+ for I in 0 to 3 loop
+ if(DOA(16*I+15 downto 16*I) = x"0000") then
+ ZERO_IP_AMATCH(I) <= '1';
+ else
+ ZERO_IP_AMATCH(I) <= '0';
+ end if;
+ end loop;
+ end if;
+end process;
+
+--//-- KEY MATCH ---------------------------------------------------
+IP_KEY1 <= RT_IPv4_6n_D & RT_IP_ADDR_D(63 downto 0);
+IP_KEY2 <= RX_IPv4_6n_D & RX_SOURCE_IP_ADDR_D(63 downto 0);
+
+-- Since both A and B sides of the block RAM are independently searching for IP address keys,
+-- it will save time if we check both A and B outputs for match.
+
+-- IP_KEY_MATCH and IP_KEY1_ADDR valid during STATE_X_D3
+IP_KEY1_MATCH_DETECT_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ IP_KEY1_MATCH <= '0';
+ IP_KEY1_MAC <= (others => '0');
+ IP_KEY1_TIME <= (others => '0');
+ elsif((STATE_B_D2 = 2) or (STATE_B_D2 = 3)) and (IP_KEY1_BMATCH = "11111") then -- *052419
+ -- found a match for IP_KEY1 at ADDRB_D2 while scanning B-side
+ IP_KEY1_MATCH <= '1';
+ IP_KEY1_MAC <= DOB_D(111 downto 64);
+ IP_KEY1_TIME <= unsigned(DOB_D(132 downto 113));
+ elsif(STATE_A_D2 = 3) and (IP_KEY1_AMATCH = "11111") then
+ -- found a match for IP_KEY1 at ADDRA_D2 while scanning A-side
+ IP_KEY1_MATCH <= '1';
+ IP_KEY1_MAC <= DOA_D(111 downto 64);
+ IP_KEY1_TIME <= unsigned(DOA_D(132 downto 113));
+ else
+ IP_KEY1_MATCH <= '0';
+ end if;
+ end if;
+end process;
+
+-- IP_KEY_MATCH and IP_KEY2_ADDR valid during STATE_X_D3
+IP_KEY2_MATCH_DETECT_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ IP_KEY2_MATCH <= '0';
+ IP_KEY2_ADDR <= (others => '0');
+ elsif(STATE_B_D2 = 3) and (IP_KEY2_BMATCH = "11111") then
+ -- found a match for IP_KEY2 at ADDRB_D2 while scanning B-side
+ IP_KEY2_MATCH <= '1';
+ IP_KEY2_ADDR <= std_logic_vector(ADDRB_D2(ADDR_WIDTH-2 downto 0));
+ elsif(STATE_A_D2 = 3) and (IP_KEY2_AMATCH = "11111") then
+ -- found a match for IP_KEY2 at ADDRA_D2 while scanning A-side
+ IP_KEY2_MATCH <= '1';
+ IP_KEY2_ADDR <= std_logic_vector(ADDRA_D2(ADDR_WIDTH-2 downto 0));
+ else
+ IP_KEY2_MATCH <= '0';
+ end if;
+ end if;
+end process;
+
+
+--//-- NEW MAC/IP ADDRESSES ---------------------------------------------------
+-- Received another entry (decoded from received an IP or ARP response packet)
+NEW_ENTRY_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ -- new entry
+ if(STATE_A = 0) and (RX_SOURCE_ADDR_RDY = '1') then
+ -- idle + new entry. freeze input information during the processing
+ -- just in case two requests are very close to eachother.
+ RX_SOURCE_MAC_ADDR_D <= RX_SOURCE_MAC_ADDR;
+ RX_SOURCE_IP_ADDR_D <= RX_SOURCE_IP_ADDR;
+ RX_IPv4_6n_D <= RX_IPv4_6n;
+ if(RX_IPv4_6n = '1') then
+ RX_SOURCE_IP_ADDR_MASKED(31 downto 0) <= RX_SOURCE_IP_ADDR(31 downto 0) and IPv4_SUBNET_MASK;
+ elsif(IPv6_ENABLED = '1') then
+ -- IPv6
+ RX_SOURCE_IP_ADDR_MASKED <= RX_SOURCE_IP_ADDR(63 downto 0) and IPv6_SUBNET_MASK;
+ end if;
+ end if;
+
+ -- special case/shortcut: detect Gateway4 MAC address immediately (saves time instead of searching)
+ if(SYNC_RESET = '1') then
+ GATEWAYv4_MAC_ADDR <= (others => '0');
+ elsif(RX_SOURCE_ADDR_RDY = '1') and (RX_IPv4_6n = '1') and (RX_SOURCE_IP_ADDR(31 downto 0) = IPv4_GATEWAY_ADDR) then
+ GATEWAYv4_MAC_ADDR <= RX_SOURCE_MAC_ADDR;
+ end if;
+
+ -- special case/shortcut: detect Gateway6 MAC address immediately (saves time instead of searching)
+ if(SYNC_RESET = '1') then
+ GATEWAYv6_MAC_ADDR <= (others => '0');
+ elsif(RX_SOURCE_ADDR_RDY = '1') and (IPv6_ENABLED = '1') and (RX_IPv4_6n = '0') and (RX_SOURCE_IP_ADDR = IPv6_GATEWAY_ADDR) then
+ GATEWAYv6_MAC_ADDR <= RX_SOURCE_MAC_ADDR;
+ end if;
+ end if;
+end process;
+
+
+--//-- A-SIDE STATE MACHINE ---------------------------------------
+-- A-side of the block RAM used for (a) finding out the oldest entry and (b) save MAC/IP/timestamp
+-- based on received packets (ARP response or IP)
+
+EVENTA1 <= '1' when (TIMEDIFF < LAST_RX_TIME) or ((TIMEDIFF(TIMEDIFF'left) = '1') and (LAST_RX_TIME(LAST_RX_TIME'left) = '0')) else '0';
+ -- '1' when LAST_RX_TIME is recent (i.e. occurred less than refresh period)
+ -- Code is a bit tricky because of the wrap-around unsigned time
+ -- Also because we rephrased this time comparison for better timing (TIMEDIFF is pipelined already)
+
+STATE_MACHINE_A_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ ADDRA_D <= ADDRA;
+ ADDRA_D2 <= ADDRA_D;
+ STATE_A_D <= STATE_A;
+ STATE_A_D2 <= STATE_A_D;
+
+ if(SYNC_RESET = '1') or (MEMORY_INITIALIZED = '0') then
+ STATE_A <= 0;
+ WEA <= '0';
+ DIA <= (others => '0');
+ ADDRA <= (others => '0');
+ LAST_RX_MAC <= (others => '0');
+ LAST_RX_IP <= (others => '0');
+ LAST_RX_TIME <= (others => '0');
+ elsif(STATE_A = 0) then
+ WEA <= '0';
+ if(RX_SOURCE_ADDR_RDY = '1') then
+ -- idle + new entry.
+ STATE_A <= 1;
+ ADDRA <= (others => '0');
+ end if;
+ elsif(STATE_A = 1) then
+ if(RX_IPv4_6n_D = '1') then
+ -- SKIP LOOKUP CASES, don't waste time re-entering the information.
+ if(unsigned(RX_SOURCE_IP_ADDR_D(31 downto 0)) = 0) then
+ -- (a) meaningless zero IP address -> skip
+ STATE_A <= 0; -- go back to idle.
+ elsif(RX_SOURCE_IP_ADDR_D(31 downto 0) = x"7F000001") then
+ -- (b) meaningless localhost address -> skip
+ STATE_A <= 0; -- go back to idle.
+ elsif(RX_SOURCE_IP_ADDR_D(31 downto 0) = IPv4_ADDR) then
+ -- (c) meaningless self address -> skip
+ STATE_A <= 0; -- go back to idle.
+ elsif(RX_SOURCE_IP_ADDR_D(31 downto 0) = LAST_RX_IP(31 downto 0)) and (LAST_RX_IPv4_6n = '1') and (EVENTA1 = '1') then
+ -- (d) duplicate entry. We just wrote this one.
+ STATE_A <= 0; -- go back to idle.
+ elsif(RX_SOURCE_IP_ADDR_MASKED(31 downto 0) /= IPv4_MASKED) then
+ -- (e) WAN address. No need to store the MAC address because it has already
+ -- been replaced by that of the gateway.
+ STATE_A <= 0; -- go back to idle.
+ elsif(RX_SOURCE_IP_ADDR_D(31 downto 0) = IPv4_GATEWAY_ADDR) then
+ -- (f) special case: gateway address is handled by a shortcut to minimize search time.
+ STATE_A <= 0; -- go back to idle.
+ else
+ -- SEARCH ROUTING TABLE
+ -- search routing table by IP address key.
+ STATE_A <= 2;
+ end if;
+ elsif(IPv6_ENABLED = '1') and (RX_IPv4_6n_D = '0') then
+ -- SKIP LOOKUP CASES, don't waste time re-entering the information.
+ if(unsigned(RX_SOURCE_IP_ADDR_D) = 0) then
+ -- (a) meaningless zero IP address -> skip
+ STATE_A <= 0; -- go back to idle.
+ elsif(unsigned(RX_SOURCE_IP_ADDR_D) = 1) then
+ -- (b) meaningless localhost address -> skip
+ STATE_A <= 0; -- go back to idle.
+ elsif(RX_SOURCE_IP_ADDR_D = IPv6_ADDR) then
+ -- (c) meaningless self address -> skip
+ STATE_A <= 0; -- go back to idle.
+ --elsif(RX_SOURCE_IP_ADDR_D(63 downto 0) = LAST_RX_IP(63 downto 0)) and (LAST_RX_IPv4_6n = '0') and ((TIME_CNTR - LAST_RX_TIME) < REFRESH_PERIOD) then
+ -- rephrasing for better timing
+ elsif(RX_SOURCE_IP_ADDR_D(63 downto 0) = LAST_RX_IP(63 downto 0)) and (LAST_RX_IPv4_6n = '0') and (TIMEDIFF < LAST_RX_TIME) then
+ -- (d) duplicate entry. We just wrote this one.
+ STATE_A <= 0; -- go back to idle.
+ elsif (RX_SOURCE_IP_ADDR_D(127 downto 112) = x"FE80") and (RX_SOURCE_IP_ADDR_D(111 downto 64) /= IPv6_ADDR(111 downto 64)) then
+ -- (e) WAN unicast address. No need to store the MAC address because it has already
+ -- been replaced by that of the gateway.
+ STATE_A <= 0; -- go back to idle.
+ elsif (RX_SOURCE_IP_ADDR_D(127 downto 112) = x"FE80") and (RX_SOURCE_IP_ADDR_MASKED(63 downto 0) /= IPv6_MASKED) then
+ -- (f) WAN unicast address. No need to store the MAC address because it has already
+ -- been replaced by that of the gateway.
+ STATE_A <= 0; -- go back to idle.
+ else
+ -- SEARCH ROUTING TABLE
+ -- search routing table by IP address key.
+ STATE_A <= 2;
+ end if;
+ end if;
+ elsif(STATE_A = 2) then
+ -- needed an extra clock before starting the search
+ STATE_A <= 3;
+ ADDRA <= ADDRA + 1;
+ elsif(STATE_A = 3) then
+ -- scan address range 0 - 128 or until we find the target IP address
+ if(IP_KEY2_MATCH = '1') then
+ -- found a match
+ ADDRA <= unsigned("0" & IP_KEY2_ADDR);
+ STATE_A <= 4; -- go write the MAC/IP/Timestamp to the routing table
+ elsif(ADDRA_D2(ADDR_WIDTH-1) = '1') then
+ -- reached the end of the scan without any key match
+ -- note STATE_A=3 is extended three more clocks to wait for the last possible key match
+ -- find the oldest table entry and overwrite it with the newer MAC/IP/Timestamp.
+ ADDRA <= unsigned("0" & OLDEST_ADDR); -- design note: OLDEST_ADDR is only used following a full table scan
+ STATE_A <= 4;
+ elsif(ADDRA(ADDR_WIDTH-1) = '0') then
+ -- scan until we find the IP address key
+ ADDRA <= ADDRA + 1;
+ end if;
+ elsif(STATE_A = 4) then
+ -- write IP address + v4/v6n + MAC address + timestamp. A total of 133 bits
+ WEA <= '1';
+ DIA(63 downto 0) <= RX_SOURCE_IP_ADDR_D(63 downto 0);
+ DIA(111 downto 64) <= RX_SOURCE_MAC_ADDR_D;
+ DIA(112) <= RX_IPv4_6n_D;
+ DIA(132 downto 113) <= std_logic_vector(TIME_CNTR);
+ STATE_A <= 0;
+ -- remember so that we don't waste time doing successive repetitive write with the same parameters
+ LAST_RX_IP <= RX_SOURCE_IP_ADDR_D;
+ LAST_RX_MAC <= RX_SOURCE_MAC_ADDR_D;
+ LAST_RX_IPv4_6n <= RX_IPv4_6n_D;
+ LAST_RX_TIME <= TIME_CNTR;
+ end if;
+ end if;
+end process;
+
+--//-- FIND OLDEST ENTRY -----------------------------
+TIME_A <= unsigned(DOA(132 downto 113));
+TIME_B <= unsigned(DOB(132 downto 113));
+
+OLDEST_DETECT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') or (MEMORY_INITIALIZED = '0') then
+ OLDEST_TIME <= (others => '0');
+ OLDEST_ADDR <= (others => '0');
+ VIRGIN <= '0';
+ elsif(STATE_A = 0) then
+ VIRGIN <= '0';
+ elsif (STATE_A = 3) and (ZERO_IP_AMATCH = "1111") and (VIRGIN = '0') then
+ -- virgin record. perfect for use as 'oldest entry'
+ -- detect virgin record while scanning A side. Never been written to before. Therefore can be
+ -- used as 'oldest' record.
+ OLDEST_ADDR <= ADDRA_D2(ADDR_WIDTH-2 downto 0);
+ VIRGIN <= '1'; -- lowest address is better (shorter search). Stop updating OLDEST_ADDR
+ elsif (STATE_A = 3) and (IP_KEY2_MATCH = '0') and (ADDRA_D2(ADDR_WIDTH-1) = '1') then
+ -- reached the end of scan. No IP_KEY2 match
+ -- oldest entry or virgin entry is overwritten.... thus is no longer the oldest. Reset
+ OLDEST_TIME <= TIME_CNTR; -- reset time
+
+-- elsif (STATE_B_D = 3) and (ADDRB_D(1 downto 0)= "10") and (OLDEST_TIME(19 downto 18) = "00")
+-- and (TIME_B(19 downto 18) = "11") then
+-- -- found older entry (accounting for modulo time) while reading B-side
+-- OLDEST_TIME <= TIME_B;
+-- OLDEST_ADDR <= ADDRB_D(8 downto 2) & "00";
+-- elsif (STATE_B_D = 3) and (ADDRB_D(1 downto 0)= "10") and (OLDEST_TIME > TIME_B) then
+-- -- found older entry while reading B-side
+-- OLDEST_TIME <= TIME_B;
+-- OLDEST_ADDR <= ADDRB_D(8 downto 2) & "00";
+ elsif (STATE_A = 3) and (VIRGIN = '0') and (OLDEST_TIME(19 downto 18) = "00")
+ and (TIME_A(19 downto 18) = "11") then
+ -- found older entry (accounting for modulo time) while reading A-side
+ -- Note: virgin entry has precedence
+ OLDEST_TIME <= TIME_A;
+ OLDEST_ADDR <= ADDRA_D(ADDR_WIDTH-2 downto 0);
+ elsif (STATE_A = 3) and (VIRGIN = '0') and (OLDEST_TIME > TIME_A) then
+ -- found older entry while reading A-side
+ -- Note: virgin entry has precedence
+ OLDEST_TIME <= TIME_A;
+ OLDEST_ADDR <= ADDRA_D(ADDR_WIDTH-2 downto 0);
+ end if;
+ end if;
+end process;
+
+----// Test Point
+--TP(1) <= RT_REQ_RTS;
+--TP(2) <= '1' when (STATE_B = 0) else '0'; --RT_CTS
+--TP(3) <= RT_MAC_RDY_local;
+--TP(4) <= RT_NAK_local;
+
+--TP(5) <= WHOIS_START_local;
+
+--TP(6) <= RX_SOURCE_ADDR_RDY;
+--TP(7) <= '1' when (STATE_A = 0) else '0';
+--TP(8) <= '1' when (STATE_A = 3) and (IP_KEY2_MATCH = '1') else '0';
+--TP(9) <= '1' when (STATE_A = 3) and (ADDRA_D(7) = '1') else '0';
+--TP(10) <= '1' when (STATE_A = 4) else '0';
+
+TP(1) <= '1' when (IPv4GATEWAY_REFRESH_TIMER = 0) else '0';
+TP(2) <= '1' when (STATE_B = 0) else '0';
+TP(3) <= WHOIS_IPv4GATEWAY;
+
+----SREG1 <= OLDEST_ADDR(7 downto 0);
+----SREG2 <= LAST_IP(31 downto 24);
+----SREG3 <= LAST_IP(23 downto 16);
+----SREG4 <= LAST_IP(15 downto 8);
+----SREG5 <= LAST_IP(7 downto 0);
+----SREG6 <= OLDEST_ADDR(7 downto 0);
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/bram_dp2.vhd b/generic_ip/third_party_ip/tcp_server/src/bram_dp2.vhd
new file mode 100644
index 0000000..5e4ce6b
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/bram_dp2.vhd
@@ -0,0 +1,150 @@
+-------------------------------------------------------------
+-- Filename: BRAM_DP2.VHD
+-- Authors:
+-- from http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_4/xst_v6s6.pdf
+-- Alain Zarembowitch / MSS
+-- Version: Rev 2
+-- Last modified: 6/29/16
+
+-- Inheritance: BRAM_DP.VHD 5/7/15
+--
+-- description: synthesizable generic dual port RAM
+--
+-- Rev 1b 6/21/16 AZ
+-- Switched to numeric_std library
+-- Initialize to zero during simulation
+--
+-- Rev 2 6/29/16 AZ
+-- Added asymmetrical case (different data widths on A and B ports)
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use ieee.numeric_std.all;
+
+entity BRAM_DP2 is
+ Generic (
+ DATA_WIDTHA: integer := 9; -- MUST BE <= DATA_WIDTHB
+ ADDR_WIDTHA: integer := 11;
+ DATA_WIDTHB: integer := 9;
+ ADDR_WIDTHB: integer := 11
+ -- total size on A size MUST match total size on B side
+ -- (DATA_WIDTHA * 2**ADDR_WIDTHA) == (DATA_WIDTHB * 2**ADDR_WIDTHB)
+ );
+ Port (
+ -- chip select, active high
+
+ -- Port A
+ CLKA : in std_logic;
+ CSA: in std_logic; -- chip select, active high
+ WEA : in std_logic; -- write enable, active high
+ OEA : in std_logic; -- output enable, active high
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+
+ -- Port B
+ CLKB : in std_logic;
+ CSB: in std_logic; -- chip select, active high
+ WEB : in std_logic; -- write enable, active high
+ OEB : in std_logic; -- output enable, active high
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+end entity;
+
+architecture Behavioral of BRAM_DP2 is
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------function
+--function max(L,R:INTEGER) return INTEGER is
+--begin
+-- if (L > R) then
+-- return L;
+-- else
+-- return R;
+-- end if;
+--end;
+--function min(L,R:INTEGER) return INTEGER is
+--begin
+-- if(L < R) then
+-- return L;
+-- else
+-- return R;
+-- end if;
+--end;
+
+-- see users constraints in generic section
+constant MIN_DATA_WIDTH: integer := DATA_WIDTHA;
+constant MAX_DATA_WIDTH: integer := DATA_WIDTHB;
+constant MIN_ADDR_WIDTH: integer := ADDR_WIDTHB;
+constant MAX_ADDR_WIDTH: integer := ADDR_WIDTHA;
+constant RATIO: integer := MAX_DATA_WIDTH / MIN_DATA_WIDTH;
+constant log2RATIO: integer := ADDR_WIDTHA - ADDR_WIDTHB;
+
+-- infered
+type mem_type is array ( (2**MAX_ADDR_WIDTH)-1 downto 0 ) of std_logic_vector(MIN_DATA_WIDTH-1 downto 0);
+shared variable MEM : mem_type := (others => (others => '0'));
+signal DOA_local: std_logic_vector(DATA_WIDTHA-1 downto 0) := (others => '0');
+signal DOB_local: std_logic_vector(DATA_WIDTHB-1 downto 0) := (others => '0');
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- Port A write
+process(CLKA)
+begin
+ if rising_edge(CLKA) then
+ if(CSA = '1') and (WEA = '1') then
+ mem(to_integer(unsigned(ADDRA))) := DIA;
+ end if;
+ end if;
+end process;
+
+-- Port A read
+process(CLKA)
+begin
+ if rising_edge(CLKA) then
+ if(CSA = '1') then
+ DOA_local <= mem(to_integer(unsigned(ADDRA)));
+ else
+ DOA_local <= (others => '0');
+ end if;
+ end if;
+end process;
+
+-- tri-state output
+DOA <= DOA_local when (CSA = '1') and (OEA = '1') else (others => 'Z');
+
+-- Port B write
+process(CLKB)
+begin
+ if rising_edge(CLKB) then
+ if(CSB = '1') and (WEB = '1') then
+ for I in 0 to RATIO-1 loop
+ mem(to_integer(unsigned(ADDRB) & to_unsigned(I,log2RATIO))) := DIB((I+1)*MIN_DATA_WIDTH - 1 downto I*MIN_DATA_WIDTH);
+ end loop;
+ end if;
+ end if;
+end process;
+
+-- Port B read
+process(CLKB)
+begin
+ if rising_edge(CLKB) then
+ if(CSB = '1') then
+ for I in 0 to RATIO-1 loop
+ DOB_local((I+1)*MIN_DATA_WIDTH - 1 downto I*MIN_DATA_WIDTH) <= mem(to_integer(unsigned(ADDRB) & to_unsigned(I,log2RATIO)));
+ end loop;
+ else
+ DOB_local <= (others => '0');
+ end if;
+ end if;
+end process;
+
+-- tri-state output
+DOB <= DOB_local when (CSB = '1') and (OEB = '1') else (others => 'Z');
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/com5502.vhd b/generic_ip/third_party_ip/tcp_server/src/com5502.vhd
new file mode 100644
index 0000000..89c93da
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/com5502.vhd
@@ -0,0 +1,2171 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: COM5502.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 2
+-- Date last modified: 6/7/19
+-- Inheritance: COM5402.VHD (architecture)
+--
+-- description: 10Gbit Internet IP stack: IP/TCP/UDP/ARP/PING.
+-- The IP stack relies on the lower layers: MAC (for example COM5501) and PHY (Integrated circuit)
+-- Interfaces directly with COM-5501SOFT 10GbE MAC protocol layer and the COM-5401SOFT 1GbE MAC.
+--
+-- Rev 1 4/27/19 AZ
+-- Added IGMP for multicast addresses
+--
+-- Rev 2 6/7/19 AZ
+-- Corrected bug about the timeliness of RX_IP_PROTOCOL (cleared to early)
+-- Corrected bug on CHECK_UDP_RX_DEST_PORT_NO outside of UDP_RX_10G
+--
+-- Device utilization (NTCPSTREAMS=1, NUDPRX=1, NUDPRX=1, MTU = 1500, IPv6_ENABLED='1')
+-- FF: 7402
+-- LUT: 12082
+-- DSP48: 0
+-- 18Kb BRAM: 21
+-- BUFG: 1
+-- Minimum period: 6.888ns (Maximum Frequency: 145.175MHz) Artix7-100T -1 speed grade
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+use work.com5502pkg.all; -- defines global types, number of TCP streams, etc
+
+entity COM5502 is
+ generic (
+ NTCPSTREAMS: integer range 0 to 255 := 1;
+ -- number of concurrent TCP streams handled by this component
+ NUDPTX: integer range 0 to 1:= 1;
+ NUDPRX: integer range 0 to 1:= 1;
+ -- Enable/disable UDP protocol for tx and rx
+ MTU: integer range 1500 to 9000 := 1500;
+ -- Maximum Transmission Unit: maximum number of payload Bytes.
+ -- Typically 1500 for standard frames, 9000 for jumbo frames.
+ -- A frame will be deemed invalid if its payload size exceeds this MTU value.
+ -- Should match the values in MAC layer)
+ -- For maximum TCP throughput, select MTU = (buffer size/4) + 60 bytes (IP/TCP header)
+ -- for example, when ADDR_WIDTH = 12, best MTU is 8252. It will work at MTU = 9000 but with a
+ -- small degradation in TCP throughput.
+ IPv6_ENABLED: std_logic := '1';
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ DHCP_SERVER_EN: std_logic := '1';
+ -- instantiate ('1') a DHCP server
+ -- One can instantiate both DHCP server and DHCP client at the same time, but not enable them simultaneously
+ DHCP_CLIENT_EN: std_logic := '1';
+ -- '0' for static address (for minimum size), '1' for static/dynamic address (instantiates a DHCP_CLIENT component)
+ -- One can instantiate both DHCP server and DHCP client at the same time, but not enable them simultaneously
+ IGMP_EN: std_logic := '1';
+ -- '1' to enable UDP multicast (which requires IGMP)
+ TX_IDLE_TIMEOUT: integer range 0 to 50:= 50;
+ -- inactive input timeout, expressed in 4us units. -- 50*4us = 200us
+ -- Controls the TCP transmit stream segmentation: data in the elastic buffer will be transmitted if
+ -- no input is received within TX_IDLE_TIMEOUT, without waiting for the transmit frame to be filled with MSS data bytes.
+ TCP_KEEPALIVE_PERIOD: integer := 60;
+ -- period in seconds for sending no data keepalive frames.
+ -- "Typically TCP Keepalives are sent every 45 or 60 seconds on an idle TCP connection, and the connection is
+ -- dropped after 3 sequential ACKs are missed"
+ CLK_FREQUENCY: integer := 156;
+ -- CLK frequency in MHz. Needed to compute actual delays.
+ SIMULATION: std_logic := '0'
+ -- 1 during simulation with Wireshark .cap file, '0' otherwise
+ -- Wireshark many not be able to collect offloaded checksum computations.
+ -- when SIMULATION = '1': (a) IP header checksum is valid if 0000,
+ -- (b) TCP checksum computation is forced to a valid 00001 irrespective of the 16-bit checksum
+ -- captured by Wireshark.
+ );
+ Port (
+ --//-- CLK, RESET
+ CLK: in std_logic;
+ -- 10G: PHY/MAC clock at 156.25 MHz
+ -- 1G: User clock. Must be 125 MHz or above for 1G, 25 MHz or above for 100Mbps
+ -- GLOBAL clock
+ SYNC_RESET: in std_logic;
+ -- CLK-synchronous reset. MANDATORY after all configuration fields are defined.
+
+ --//-- CONFIGURATION
+ -- usage: use SYNC_RESET after a configuration change
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ DYNAMIC_IPv4: in std_logic;
+ -- '1' if dynamic IPv4 address using an external DHCP server, '0' if fixed (static) IPv4 address.
+ -- Dynamic IP address requires the generic parameter DHCP_CLIENT_EN = '1' to instantiate a DHCP client within.
+ -- Mutually exclusive with DHCP_SERVER_EN2 (chose DHCP client OR server, but not both)
+ REQUESTED_IPv4_ADDR: in std_logic_vector(31 downto 0);
+ -- fixed IP address if static, or requested IP address if dynamic (DHCP_CLIENT_EN and DYNAMIC_IP = '1').
+ -- In the case of dynamic IP, this is typically the last IP address, as stored in external non-volatile memory.
+ -- In the case of dynamic IP, use 0.0.0.0 if no previous IP address is available.
+ -- In the case of dynamic IP, this field is read only when SYNC_RESET = '1'
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+ IPv4_MULTICAST_ADDR: in std_logic_vector(31 downto 0);
+ -- to receive UDP multicast messages. One multicast address only
+ -- 0.0.0.0 to signify that IP multicasting is not supported here.
+ IPv4_SUBNET_MASK: in std_logic_vector(31 downto 0);
+ -- Ignored when the DHCP client feature is enabled, as the DHCP server provides the gateway information.
+ IPv4_GATEWAY_ADDR: in std_logic_vector(31 downto 0);
+ -- Ignored when the DHCP client feature is enabled, as the DHCP server provides the gateway information.
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- local IP address. 16 bytes for IPv6
+ IPv6_SUBNET_PREFIX_LENGTH: in std_logic_vector(7 downto 0);
+ -- 128 - subnet size in bits. Usually expressed as /n. Typical range 64-128
+ IPv6_GATEWAY_ADDR: in std_logic_vector(127 downto 0);
+
+ --// User-initiated connection reset for stream I
+ CONNECTION_RESET: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TCP_KEEPALIVE_EN: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- enable TCP Keepalive (1) or not (0)
+
+ --//-- DHCP SERVER CONFIGURATION
+ DHCP_SERVER_EN2: in std_logic;
+ -- enable(1)/disable(0) DHCP server at run-time. Requires DHCP_SERVER to be instantiated through DHCP_SERVER_EN
+ -- Mutually exclusive with DYNAMIC_IP (chose DHCP client OR server, but not both)
+ DHCP_SERVER_IP_MIN_LSB: in std_logic_vector(7 downto 0);
+ DHCP_SERVER_NIPs: in std_logic_vector(7 downto 0);
+ -- range of IP addresses to be assigned by this DHCP server
+ -- the actual address is in the form IPv4_ADDR for the 3 MSB, and a subnet address between IP_MIN (inclusive)
+ -- and IP_MIN + NIPs -1 (inclusive)
+ -- Maximum 128 entries.
+ -- For example, if IPv4_ADDR = 172.16.1.3, IP_MIN = 10, NIPs = 10, this DHCP server will assign and keep track of
+ -- IP addresses in the range 172.16.1.10 and 172.16.1.19 (inclusive).
+ DHCP_SERVER_LEASE_TIME: in std_logic_vector(31 downto 0);
+ -- DHCP server to provide a lease time in secs to DHCP clients.
+ -- applicable only when DHCP server is instantiated within and enabled, DHCP_SERVER_EN/DHCP_SERVER_EN2='1'
+ DHCP_ROUTER: in std_logic_vector(31 downto 0);
+ -- DHCP server to provide a router IP address to DHCP clients.
+ -- In a typical configuration, the router address is this device's address.
+ -- However, the network administrator can decide to use point to another router (in effect rendering this router LAN to WAN link inoperative)
+ DHCP_SERVER_DNS: in std_logic_vector(31 downto 0);
+ -- DHCP server to provide DNS address to DHCP clients.
+ -- applicable only when DHCP server is instantiated within and enabled, DHCP_SERVER_EN/DHCP_SERVER_EN2='1'
+
+ --//-- Protocol -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended by the MAC layer. User should not supply it.
+ MAC_TX_DATA: out std_logic_vector(63 downto 0);
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID = '1'
+ -- Bytes order: LSB was received first
+ -- Bytes are right aligned: first byte in LSB, occasional follow-on fill-in Bytes in the MSB(s)
+ -- The first destination address byte is always a LSB (MAC_TX_DATA(7:0))
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- data valid, for each byte in MAC_TX_DATA
+ MAC_TX_SOF: out std_logic;
+ -- start of frame: '1' when sending the first byte.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_EOF: out std_logic;
+ -- End of frame: '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal, indicating room in the
+ -- MAC tx elastic buffer for a complete frame of size MTU
+ -- The user should check that this signal is high before deciding to send
+ -- sending the next frame.
+ MAC_TX_RTS: out std_logic;
+ -- '1' when at least one of the inner processes is ready to transmit. Will on transmit when CTS goes high.
+ -- useful if there is an external transmission arbiter (for example in the case of multiple clients)
+
+ --//-- Receive MAC -> Protocol
+ -- Valid rx packets only: packets with bad CRC or invalid address are discarded in the MAC
+ -- The 32-bit CRC is always removed by the MAC layer.
+ MAC_RX_DATA: in std_logic_vector(63 downto 0);
+ -- USER reads the data at the rising edge of CLK when MAC_RX_DATA_VALID /= 0
+ -- Bytes order: LSB was received first
+ -- Bytes are right aligned: first byte in LSB, occasional follow-on fill-in Bytes in the MSB(s)
+ -- The first destination address byte is always a LSB (MAC_RX_DATA(7:0))
+ MAC_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- data valid, for each byte in MAC_RX_DATA
+ MAC_RX_SOF: in std_logic;
+ -- '1' when sending the first byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ MAC_RX_EOF: in std_logic;
+ -- '1' when sending the last byte in a received packet.
+ -- Aligned with MAC_RX_DATA_VALID
+ MAC_RX_FRAME_VALID: in std_logic;
+ -- this component verifies the frame validity (CRC good, length, MAC address) at
+ -- the end of the frame (when MAC_RX_EOF).
+
+ --//-- Application <- UDP rx payload
+ UDP_RX_DATA: out std_logic_vector(63 downto 0);
+ -- byte order: MSB first (reason: easier to read contents during simulation)
+ UDP_RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- example: 1 byte -> 0x80, 2 bytes -> 0xC0
+ UDP_RX_SOF: out std_logic; -- start of UDP payload data field
+ UDP_RX_EOF: out std_logic; -- end of UDP frame
+ UDP_RX_FRAME_VALID: out std_logic;
+ -- check entire frame validity at UDP_RX_EOF
+ -- 1 CLK pulse indicating that UDP_RX_DATA is the last byte in the UDP payload data field.
+ -- ALWAYS CHECK UDP_RX_FRAME_VALID at the end of packet (UDP_RX_EOF = '1') to confirm
+ -- that the UDP packet is valid. External buffer may have to backtrack to the the last
+ -- valid pointer to discard an invalid UDP packet.
+ -- Reason: we only knows about bad UDP packets at the end.
+ UDP_RX_DEST_PORT_NO_IN: in std_logic_vector(15 downto 0);
+ CHECK_UDP_RX_DEST_PORT_NO: in std_logic;
+ -- check the destination port number matches UDP_RX_DEST_PORT_NO (1) or ignore it (0)
+ -- The latter case is useful when this component is shared among multiple UDP ports
+ UDP_RX_DEST_PORT_NO_OUT: out std_logic_vector(15 downto 0);
+ -- Collected destination UDP port in received UDP frame. Read when APP_EOF = '1'
+
+ --//-- Application -> UDP tx
+ UDP_TX_DATA: in std_logic_vector(63 downto 0);
+ -- byte order: MSB first (reason: easier to read contents during simulation)
+ -- unused bytes are expected to be zeroed
+ UDP_TX_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- example: 1 byte -> 0x80, 2 bytes -> 0xC0
+ UDP_TX_SOF: in std_logic; -- 1 CLK-wide pulse to mark the first byte in the tx UDP frame
+ UDP_TX_EOF: in std_logic; -- 1 CLK-wide pulse to mark the last byte in the tx UDP frame
+ UDP_TX_CTS: out std_logic;
+ UDP_TX_ACK: out std_logic; -- 1 CLK-wide pulse indicating that the previous UDP frame is being sent
+ UDP_TX_NAK: out std_logic; -- 1 CLK-wide pulse indicating that the previous UDP frame could not be sent
+ UDP_TX_DEST_IP_ADDR: in std_logic_vector(127 downto 0);
+ UDP_TX_DEST_IPv4_6n: in std_logic;
+ UDP_TX_DEST_PORT_NO: in std_logic_vector(15 downto 0);
+ UDP_TX_SOURCE_PORT_NO: in std_logic_vector(15 downto 0);
+ -- the IP and port information is latched in at the UDP_TX_SOF pulse.
+ -- USAGE: wait until the previous UDP tx frame UDP_TX_ACK or UDP_TX_NAK to send the follow-on UDP tx frame
+
+ --//-- Application <- TCP rx
+ -- NTCPSTREAMS can operate independently and concurrently. No scheduling arbitration needed here.
+ -- Usage: application raises the Clear-To-Send flag for one CLK. If a 64-bit word is available to be read, it is
+ -- placed in RX_APP_DATA with a latency of 2 CLKs. In this case RX_APP_DATA_VALID(I) = x"FF" indicating a data width of 8 bytes.
+ -- The application can also request to 'peek' into the next 8-bytes in memory by raising RX_APP_PEEK_NEXT(I) for one CLK.
+ -- The data will also be placed in RX_APP_DATA and the width (which can be 1-8 bytes) will be placed in RX_APP_DATA_VALID.
+ -- Peeking does not advance the read pointer. It is mutually exclusive with a Clear-To-Send request. It has lower priority.
+ TCP_LOCAL_PORTS: in SLV16xNTCPSTREAMStype;
+ -- TCP_SERVER port configuration. Each one of the NTCPSTREAMS streams handled by this
+ -- component must be configured with a distinct port number.
+ -- This value is used as destination port number to filter incoming packets,
+ -- and as source port number in outgoing packets.
+ TCP_RX_DATA: out SLV64xNTCPSTREAMStype;
+ TCP_RX_DATA_VALID: out SLV8xNTCPSTREAMStype;
+ TCP_RX_RTS: out std_logic_vector((NTCPSTREAMS-1) downto 0); -- Ready To Send
+ TCP_RX_CTS: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- 1 CLK pulse to read the next (partial) word TCP_RX_DATA
+ -- Latency: 2 CLKs to TCP_RX_DATA, but only IF AND ONLY IF the next word has at least one available byte.
+ TCP_RX_CTS_ACK: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- '1' the TCP_RX_CTS request for new data is accepted:
+ -- indicating that a new (maybe partial) word will be placed on the output TCP_RX_DATA at the next CLK.
+
+ --//-- Application -> TCP tx
+ -- NTCPSTREAMS can operate independently and concurrently. No scheduling arbitration needed here.
+ TCP_TX_DATA: in SLV64xNTCPSTREAMStype;
+ TCP_TX_DATA_VALID: in SLV8xNTCPSTREAMStype;
+ TCP_TX_DATA_FLUSH: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TCP_TX_CTS: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- Clear To Send = transmit flow control.
+ -- App is responsible for checking the CTS signal before sending APP_DATA
+ -- byte order: MSB first (reason: easier to read contents during simulation)
+ -- All input words must include 8 bytes of data (TCP_TX_DATA_VALID = x"FF") except the last word which can
+ -- be partially filled with 1-8 bytes of data.
+
+ --//-- TEST POINTS, COMSCOPE TRACES
+ TCP_CONNECTED_FLAG: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ CS1: out std_logic_vector(7 downto 0);
+ CS1_CLK: out std_logic;
+ CS2: out std_logic_vector(7 downto 0);
+ CS2_CLK: out std_logic;
+ DEBUG1 : OUT std_logic_vector(63 downto 0);
+ DEBUG2 : OUT std_logic_vector(63 downto 0);
+ DEBUG3 : OUT std_logic_vector(63 downto 0);
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of COM5502 is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT TIMER_4US
+ GENERIC (
+ CLK_FREQUENCY: integer
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ TICK_4US : OUT std_logic;
+ TICK_100MS: out std_logic
+ );
+ END COMPONENT;
+
+ COMPONENT PACKET_PARSING_10G
+ GENERIC (
+ IPv6_ENABLED: std_logic;
+ SIMULATION: std_logic
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ MAC_RX_DATA : IN std_logic_vector(63 downto 0);
+ MAC_RX_DATA_VALID : IN std_logic_vector(7 downto 0);
+ MAC_RX_SOF : IN std_logic;
+ MAC_RX_EOF : IN std_logic;
+ MAC_RX_FRAME_VALID: in std_logic;
+ MAC_RX_WORD_COUNT: out std_logic_vector(10 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv4_MULTICAST_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ IP_RX_DATA: out std_logic_vector(63 downto 0);
+ IP_RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ IP_RX_SOF: out std_logic;
+ IP_RX_EOF: out std_logic;
+ IP_RX_WORD_COUNT: out std_logic_vector(10 downto 0);
+ IP_HEADER_FLAG: out std_logic_vector(1 downto 0);
+ RX_TYPE : OUT std_logic_vector(3 downto 0);
+ RX_TYPE_RDY : OUT std_logic;
+ RX_IPv4_6n: out std_logic;
+ RX_IP_PROTOCOL : OUT std_logic_vector(7 downto 0);
+ RX_IP_PROTOCOL_RDY : OUT std_logic;
+ IP_RX_FRAME_VALID: out std_logic;
+ IP_RX_FRAME_VALID2: out std_logic;
+ VALID_UNICAST_DEST_IP: out std_logic;
+ VALID_MULTICAST_DEST_IP: out std_logic;
+ VALID_DEST_IP_RDY : OUT std_logic;
+ IP_HEADER_CHECKSUM_VALID: out std_logic;
+ IP_HEADER_CHECKSUM_VALID_RDY: out std_logic;
+ RX_SOURCE_MAC_ADDR: out std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: out std_logic_vector(127 downto 0);
+ RX_DEST_IP_ADDR: out std_logic_vector(127 downto 0);
+ IP_PAYLOAD_DATA: out std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: out std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: out std_logic;
+ IP_PAYLOAD_EOF: out std_logic;
+ IP_PAYLOAD_LENGTH: out std_logic_vector(15 downto 0);
+ IP_PAYLOAD_WORD_COUNT: out std_logic_vector(10 downto 0);
+ VALID_IP_PAYLOAD_CHECKSUM: out std_logic;
+ VALID_UDP_CHECKSUM: out std_logic;
+ VALID_TCP_CHECKSUM: out std_logic;
+
+ CS1 : OUT std_logic_vector(7 downto 0);
+ CS1_CLK : OUT std_logic;
+ CS2 : OUT std_logic_vector(7 downto 0);
+ CS2_CLK : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT ARP_10G
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ MAC_RX_DATA: in std_logic_vector(63 downto 0);
+ MAC_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ MAC_RX_SOF: in std_logic;
+ MAC_RX_EOF: in std_logic;
+ MAC_RX_FRAME_VALID: in std_logic;
+ MAC_RX_WORD_COUNT: in std_logic_vector(10 downto 0);
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ RX_TYPE : IN std_logic_vector(3 downto 0);
+ RX_TYPE_RDY : IN std_logic;
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(31 downto 0);
+ MAC_TX_DATA: out std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ MAC_TX_CTS : IN std_logic;
+ RTS : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT ICMPV6_10G
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ IP_RX_DATA: in std_logic_vector(63 downto 0);
+ IP_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_RX_SOF: in std_logic;
+ IP_RX_EOF: in std_logic;
+ IP_RX_WORD_COUNT: in std_logic_vector(10 downto 0);
+ IP_RX_FRAME_VALID: in std_logic;
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0);
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ RX_IPv4_6n: in std_logic;
+ RX_IP_PROTOCOL : IN std_logic_vector(7 downto 0);
+ RX_IP_PROTOCOL_RDY : IN std_logic;
+ MAC_TX_CTS : IN std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ RTS : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT PING_10G
+ GENERIC (
+ IPv6_ENABLED: std_logic;
+ MAX_PING_SIZE: std_logic_vector(7 downto 0)
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ IP_RX_DATA: in std_logic_vector(63 downto 0);
+ IP_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_RX_SOF: in std_logic;
+ IP_RX_EOF: in std_logic;
+ IP_RX_WORD_COUNT: in std_logic_vector(10 downto 0);
+ IP_RX_FRAME_VALID2: in std_logic;
+ VALID_UNICAST_DEST_IP: in std_logic;
+ VALID_DEST_IP_RDY : in std_logic;
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0);
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ RX_IPv4_6n: in std_logic;
+ RX_IP_PROTOCOL : IN std_logic_vector(7 downto 0);
+ RX_IP_PROTOCOL_RDY : IN std_logic;
+ MAC_TX_CTS : IN std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ RTS : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT WHOIS2_10G
+ GENERIC (
+ IPv6_ENABLED: std_logic
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ WHOIS_IP_ADDR : IN std_logic_vector(127 downto 0);
+ WHOIS_IPv4_6n: in std_logic;
+ WHOIS_START : IN std_logic;
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ IPv4_ADDR : IN std_logic_vector(31 downto 0);
+ IPv6_ADDR : IN std_logic_vector(127 downto 0);
+ MAC_TX_CTS : IN std_logic;
+ WHOIS_RDY : OUT std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ RTS : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT ARP_CACHE2_10G
+ GENERIC (
+ IPv6_ENABLED: std_logic
+ );
+ PORT(
+ SYNC_RESET: in std_logic;
+ CLK : IN std_logic;
+ TICK_100MS : IN std_logic;
+ RT_IP_ADDR : IN std_logic_vector(127 downto 0);
+ RT_IPv4_6n: in std_logic;
+ RT_REQ_RTS : IN std_logic;
+ RT_CTS: out std_logic;
+ RT_MAC_REPLY : OUT std_logic_vector(47 downto 0);
+ RT_MAC_RDY : OUT std_logic;
+ RT_NAK: out std_logic;
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ IPv4_ADDR : IN std_logic_vector(31 downto 0);
+ IPv4_SUBNET_MASK : IN std_logic_vector(31 downto 0);
+ IPv4_GATEWAY_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR : IN std_logic_vector(127 downto 0);
+ IPv6_SUBNET_PREFIX_LENGTH: in std_logic_vector(7 downto 0);
+ IPv6_GATEWAY_ADDR : IN std_logic_vector(127 downto 0);
+ RX_SOURCE_ADDR_RDY: in std_logic;
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0);
+ RX_IPv4_6n: in std_logic;
+ WHOIS_IP_ADDR : OUT std_logic_vector(127 downto 0);
+ WHOIS_IPv4_6n: out std_logic;
+ WHOIS_START : OUT std_logic;
+ SREG1 : OUT std_logic_vector(7 downto 0);
+ SREG2 : OUT std_logic_vector(7 downto 0);
+ SREG3 : OUT std_logic_vector(7 downto 0);
+ SREG4 : OUT std_logic_vector(7 downto 0);
+ SREG5 : OUT std_logic_vector(7 downto 0);
+ SREG6 : OUT std_logic_vector(7 downto 0);
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT DHCP_SERVER_10G
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ TICK_4US : IN std_logic;
+ TICK_100MS : in std_logic;
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ HOST_NAME: in std_logic_vector(47 downto 0) := (others => '0'); -- 6 char max or hash if longer
+ IP_MIN: in std_logic_vector(7 downto 0);
+ NIPs: in std_logic_vector(7 downto 0);
+ LEASE_TIME: in std_logic_vector(31 downto 0);
+ SUBNET_MASK: in std_logic_vector(31 downto 0);
+ ROUTER: in std_logic_vector(31 downto 0);
+ DNS: in std_logic_vector(31 downto 0);
+ UDP_RX_DATA: in std_logic_vector(63 downto 0);
+ UDP_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ UDP_RX_SOF: in std_logic;
+ UDP_RX_EOF: in std_logic;
+ UDP_RX_FRAME_VALID: in std_logic;
+ UDP_RX_DEST_PORT_NO: in std_logic_vector(15 downto 0);
+
+ RX_SOURCE_IP_ADDR: in std_logic_vector(31 downto 0);
+ IP_ID_IN : IN std_logic_vector(15 downto 0);
+
+
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ MAC_TX_CTS : IN std_logic;
+ RTS: out std_logic := '0';
+-- N_DHCPDISCOVER_OUT: out std_logic_vector(7 downto 0);
+-- N_DHCPREQUEST1_OUT: out std_logic_vector(7 downto 0);
+-- N_DHCPREQUEST2_OUT: out std_logic_vector(7 downto 0);
+-- N_DHCPREQUEST3_OUT: out std_logic_vector(7 downto 0);
+-- N_DHCPACK_OUT: out std_logic_vector(7 downto 0);
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT DHCP_CLIENT_10G
+ GENERIC (
+ SIMULATION: std_logic
+ );
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ TICK_4US : IN std_logic;
+ TICK_100MS : IN std_logic;
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ LAST_IPv4_ADDR : IN std_logic_vector(31 downto 0);
+ IP_ID_IN : IN std_logic_vector(15 downto 0);
+ UDP_RX_DATA : IN std_logic_vector(63 downto 0);
+ UDP_RX_DATA_VALID : IN std_logic_vector(7 downto 0);
+ UDP_RX_SOF : IN std_logic;
+ UDP_RX_EOF : IN std_logic;
+ UDP_RX_FRAME_VALID : IN std_logic;
+ UDP_RX_DEST_PORT_NO : IN std_logic_vector(15 downto 0);
+ RX_SOURCE_IP_ADDR : IN std_logic_vector(31 downto 0);
+ MAC_TX_CTS : IN std_logic;
+ IPv4_ADDR : OUT std_logic_vector(31 downto 0);
+ LEASE_TIME : OUT std_logic_vector(31 downto 0);
+ SUBNET_MASK : OUT std_logic_vector(31 downto 0);
+ ROUTER : OUT std_logic_vector(31 downto 0);
+ DNS1 : OUT std_logic_vector(31 downto 0);
+ DNS2 : OUT std_logic_vector(31 downto 0);
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ RTS : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT IGMP_QUERY_10G
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ MULTICAST_IP_ADDR : IN std_logic_vector(31 downto 0);
+ IP_PAYLOAD_DATA: in std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: in std_logic;
+ IP_PAYLOAD_EOF: in std_logic;
+ IP_PAYLOAD_WORD_COUNT: in std_logic_vector(10 downto 0);
+ IP_RX_FRAME_VALID2: in std_logic;
+ RX_IP_PROTOCOL : IN std_logic_vector(7 downto 0);
+ VALID_MULTICAST_DEST_IP: IN std_logic;
+ VALID_IP_PAYLOAD_CHECKSUM: in std_logic;
+ RX_DEST_IP_ADDR: in std_logic_vector(31 downto 0);
+ TRIGGER_RESPONSE : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT IGMP_REPORT_10G
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ IGMP_START: in std_logic;
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IP_ID: in std_logic_vector(15 downto 0);
+ MULTICAST_IP_ADDR : IN std_logic_vector(31 downto 0);
+ MAC_TX_CTS : IN std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ RTS : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+-- COMPONENT UDP2SERIAL_10G
+-- GENERIC (
+-- PORT_NO: std_logic_vector(15 downto 0);
+-- CLK_FREQUENCY: integer
+-- );
+-- PORT(
+-- CLK : IN std_logic;
+-- SYNC_RESET : IN std_logic;
+-- IP_RX_DATA : IN std_logic_vector(7 downto 0);
+-- IP_RX_DATA_VALID : IN std_logic;
+-- IP_RX_SOF : IN std_logic;
+-- IP_RX_EOF : IN std_logic;
+-- IP_HEADER_FLAG : IN std_logic;
+-- RX_IP_PROTOCOL : IN std_logic_vector(7 downto 0);
+-- RX_IP_PROTOCOL_RDY : IN std_logic;
+-- SERIAL_OUT : OUT std_logic;
+-- TP : OUT std_logic_vector(10 downto 1)
+-- );
+-- END COMPONENT;
+--
+ COMPONENT UDP_RX_10G
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ IP_PAYLOAD_DATA: in std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: in std_logic;
+ IP_PAYLOAD_EOF: in std_logic;
+ IP_PAYLOAD_WORD_COUNT: in std_logic_vector(10 downto 0);
+ IP_RX_FRAME_VALID: in std_logic;
+ RX_IP_PROTOCOL: in std_logic_vector(7 downto 0);
+ VALID_UDP_CHECKSUM: in std_logic;
+ PORT_NO: in std_logic_vector(15 downto 0);
+ CHECK_UDP_RX_DEST_PORT_NO: in std_logic;
+ UDP_RX_DATA : OUT std_logic_vector(63 downto 0);
+ UDP_RX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ UDP_RX_SOF : OUT std_logic;
+ UDP_RX_EOF : OUT std_logic;
+ UDP_RX_FRAME_VALID: out std_logic;
+ UDP_RX_SRC_PORT: OUT std_logic_vector(15 downto 0);
+ UDP_RX_DEST_PORT: out std_logic_vector(15 downto 0);
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT UDP_TX_10G
+ generic (
+ ADDR_WIDTH: integer;
+ UDP_CKSUM_ENABLED: std_logic;
+ IPv6_ENABLED: std_logic
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ TICK_4US: in std_logic;
+ APP_DATA : IN std_logic_vector(63 downto 0);
+ APP_DATA_VALID : IN std_logic_vector(7 downto 0);
+ APP_SOF : IN std_logic;
+ APP_EOF : IN std_logic;
+ APP_CTS : OUT std_logic;
+ DEST_IP_ADDR: in std_logic_vector(127 downto 0);
+ IPv4_6n: in std_logic;
+ DEST_PORT_NO : IN std_logic_vector(15 downto 0);
+ SOURCE_PORT_NO : IN std_logic_vector(15 downto 0);
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ IP_ID: in std_logic_vector(15 downto 0);
+ ACK : OUT std_logic;
+ NAK : OUT std_logic;
+ RT_IP_ADDR : OUT std_logic_vector(127 downto 0);
+ RT_IPv4_6n: out std_logic;
+ RT_REQ_RTS: out std_logic;
+ RT_REQ_CTS: in std_logic;
+ RT_MAC_REPLY : IN std_logic_vector(47 downto 0);
+ RT_MAC_RDY : IN std_logic;
+ RT_NAK: in std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ MAC_TX_CTS : IN std_logic;
+ RTS: out std_logic := '0';
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT TCP_SERVER_10G
+ GENERIC (
+ NTCPSTREAMS: integer;
+ MSS: integer;
+ TCP_KEEPALIVE_PERIOD: integer;
+ IPv6_ENABLED: std_logic;
+ SIMULATION: std_logic
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET: in std_logic;
+ TICK_4US: in std_logic;
+ TICK_100MS: in std_logic;
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ TCP_LOCAL_PORTS: in SLV16xNTCPSTREAMStype;
+ CONNECTION_RESET: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TCP_KEEPALIVE_EN: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ IP_PAYLOAD_DATA: in std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: in std_logic;
+ IP_PAYLOAD_EOF: in std_logic;
+ IP_PAYLOAD_WORD_COUNT: in std_logic_vector(10 downto 0);
+ IP_RX_FRAME_VALID: in std_logic;
+
+ RX_IPv4_6n: in std_logic;
+ RX_IP_PROTOCOL: in std_logic_vector(7 downto 0);
+ RX_IP_PROTOCOL_RDY: in std_logic;
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0);
+ VALID_TCP_CHECKSUM: in std_logic;
+ RX_DATA: out std_logic_vector(63 downto 0);
+ RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ RX_SOF: out std_logic;
+ RX_TCP_STREAM_SEL_OUT: out std_logic_vector(NTCPSTREAMS-1 downto 0);
+ RX_EOF: out std_logic;
+ RX_FRAME_VALID: out std_logic;
+ RX_FREE_SPACE: in SLV16xNTCPSTREAMStype;
+ TX_PACKET_SEQUENCE_START_OUT: out std_logic;
+ TX_DEST_MAC_ADDR_OUT: out std_logic_vector(47 downto 0);
+ TX_DEST_IP_ADDR_OUT: out std_logic_vector(127 downto 0);
+ TX_DEST_PORT_NO_OUT: out std_logic_vector(15 downto 0);
+ TX_SOURCE_PORT_NO_OUT: out std_logic_vector(15 downto 0);
+ TX_IPv4_6n_OUT: out std_logic;
+ TX_SEQ_NO_OUT: out std_logic_vector(31 downto 0);
+ TX_ACK_NO_OUT: out std_logic_vector(31 downto 0);
+ TX_ACK_WINDOW_LENGTH_OUT: out std_logic_vector(15 downto 0);
+ TX_FLAGS_OUT: out std_logic_vector(7 downto 0);
+ TX_PACKET_TYPE_OUT : out std_logic_vector(1 downto 0);
+ MAC_TX_EOF: in std_logic; -- need to know when packet tx is complete
+ RTS: out std_logic := '0';
+ EFF_RX_WINDOW_SIZE_PARTIAL: out std_logic_vector(16 downto 0);
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM: out std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID: out std_logic; -- 1 CLK-wide pulse to indicate that the above information is valid
+ TX_SEQ_NO: out SLV17xNTCPSTREAMStype;
+ TX_SEQ_NO_JUMP: out std_logic_vector(NTCPSTREAMS-1 downto 0);
+ RX_TCP_ACK_NO_D: out SLV17xNTCPSTREAMStype;
+ CONNECTED_FLAG: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TX_STREAM_SEL: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TX_PAYLOAD_RTS: in std_logic;
+ TX_PAYLOAD_SIZE: in std_logic_vector(15 downto 0);
+ TP: out std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+ COMPONENT TCP_TXBUF_10G is
+ generic (
+ NTCPSTREAMS: integer;
+ MSS: integer;
+ ADDR_WIDTH: integer range 8 to 12;
+ TX_IDLE_TIMEOUT: integer range 0 to 50;
+ SIMULATION: std_logic
+ );
+ Port (
+ --//-- CLK, RESET
+ CLK: in std_logic;
+ SYNC_RESET: in std_logic;
+ TICK_4US: in std_logic;
+ APP_DATA: in SLV64xNTCPSTREAMStype;
+ APP_DATA_VALID: in SLV8xNTCPSTREAMStype;
+ APP_CTS: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ APP_DATA_FLUSH: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ EFF_RX_WINDOW_SIZE_PARTIAL_IN: in std_logic_vector(16 downto 0);
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID: in std_logic; -- 1 CLK-wide pulse to indicate that the above information is valid
+ TX_SEQ_NO_IN: in SLV17xNTCPSTREAMStype;
+ TX_SEQ_NO_JUMP: in std_logic_vector(NTCPSTREAMS-1 downto 0);
+ RX_TCP_ACK_NO_D: in SLV17xNTCPSTREAMStype;
+ CONNECTED_FLAG: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TX_STREAM_SEL: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TX_PAYLOAD_RTS: out std_logic;
+ TX_PAYLOAD_CHECKSUM: out std_logic_vector(17 downto 0);
+ TX_PAYLOAD_SIZE: out std_logic_vector(15 downto 0);
+ TX_PAYLOAD_CTS: in std_logic;
+ TX_PAYLOAD_DATA: out std_logic_vector(63 downto 0);
+ TX_PAYLOAD_DATA_VALID: out std_logic_vector(7 downto 0);
+ TX_PAYLOAD_WORD_VALID: out std_logic;
+ TX_PAYLOAD_DATA_EOF: out std_logic;
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+ end COMPONENT;
+
+ COMPONENT TCP_TX_10G
+ GENERIC (
+ MSSv4: integer;
+ MSSv6: integer;
+ IPv6_ENABLED: std_logic
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET: in std_logic;
+ MAC_ADDR : IN std_logic_vector(47 downto 0);
+ IPv4_ADDR : IN std_logic_vector(31 downto 0);
+ IPv6_ADDR : IN std_logic_vector(127 downto 0);
+ TX_PACKET_SEQUENCE_START : IN std_logic;
+ TX_DEST_MAC_ADDR_IN : IN std_logic_vector(47 downto 0);
+ TX_DEST_IP_ADDR_IN : IN std_logic_vector(127 downto 0);
+ TX_DEST_PORT_NO_IN : IN std_logic_vector(15 downto 0);
+ TX_SOURCE_PORT_NO_IN : IN std_logic_vector(15 downto 0);
+ TX_IPv4_6n_IN : IN std_logic;
+ TX_SEQ_NO_IN : IN std_logic_vector(31 downto 0);
+ TX_ACK_NO_IN : IN std_logic_vector(31 downto 0);
+ TX_ACK_WINDOW_LENGTH_IN : IN std_logic_vector(15 downto 0);
+ IP_ID_IN : IN std_logic_vector(15 downto 0);
+ TX_FLAGS_IN : IN std_logic_vector(7 downto 0);
+ TX_PACKET_TYPE_IN : IN std_logic_vector(1 downto 0);
+ TX_PAYLOAD_DATA : IN std_logic_vector(63 downto 0);
+ TX_PAYLOAD_DATA_VALID : IN std_logic_vector(7 downto 0);
+ TX_PAYLOAD_WORD_VALID: IN std_logic;
+ TX_PAYLOAD_DATA_EOF: in std_logic;
+ TX_PAYLOAD_RTS : IN std_logic;
+ TX_PAYLOAD_CTS : OUT std_logic;
+ TX_PAYLOAD_SIZE : IN std_logic_vector(15 downto 0);
+ TX_PAYLOAD_CHECKSUM: in std_logic_vector(17 downto 0);
+ MAC_TX_CTS : IN std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+
+ COMPONENT TCP_RXBUFNDEMUX2_10G
+ GENERIC (
+ NTCPSTREAMS: integer;
+ ADDR_WIDTH: integer range 8 to 12
+ );
+ PORT(
+ SYNC_RESET : IN std_logic;
+ CLK : IN std_logic;
+ RX_DATA : IN std_logic_vector(63 downto 0);
+ RX_DATA_VALID : IN std_logic_vector(7 downto 0);
+ RX_SOF : IN std_logic;
+ RX_TCP_STREAM_SEL: in std_logic_vector(NTCPSTREAMS-1 downto 0);
+ RX_EOF : IN std_logic;
+ RX_FRAME_VALID: in std_logic;
+ RX_FREE_SPACE: OUT SLV16xNTCPSTREAMStype;
+ RX_BUF_CLR: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ RX_APP_DATA: out SLV64xNTCPSTREAMStype;
+ RX_APP_DATA_VALID: out SLV8xNTCPSTREAMStype;
+ RX_APP_RTS: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ RX_APP_CTS: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ RX_APP_CTS_ACK: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- NOTATIONS:
+-- _E as one-CLK early sample
+-- _D as one-CLK delayed sample
+-- _D2 as two-CLKs delayed sample
+
+--//-- RESET -----------------------------
+signal SYNC_RESET_local: std_logic := '0';
+signal RESET_CNTR_MSB: std_logic := '0';
+signal RESET_CNTR_MSB_D: std_logic := '0';
+signal RESET_CNTR: unsigned(3 downto 0) := (others => '0');
+signal SYNC_RESET1: std_logic := '0';
+signal SYNC_RESET2: std_logic := '0';
+signal SYNC_RESET3: std_logic := '0';
+signal SYNC_RESET4: std_logic := '0';
+
+--//-- TIMERS -----------------------------
+signal TICK_4US: std_logic := '0';
+signal TICK_100MS_rt: std_logic := '0';
+signal TICK_100MS: std_logic := '0';
+signal TICK_CNTR: unsigned(6 downto 0) := (others => '0');
+signal TICK_CNTR2: unsigned(9 downto 0) := (others => '0');
+
+
+----//-- MAC INTERFACE --------------
+signal MAC_TX_DATA_local : std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA_VALID_local : std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_TX_EOF_FLAG : std_logic := '0';
+signal MAC_TX_EOF_local : std_logic := '0';
+signal MAC_TX_WORD_VALID : std_logic := '0';
+signal MAC_TX_EOF_FLAGn : std_logic := '0';
+
+--//-- FLIP BYTE ORDER IN MAC TX/RX WORD --------------
+signal MAC_RX_DATA_FLIP: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_RX_DATA_VALID_FLIP: std_logic_vector(7 downto 0) := (others => '0');
+signal MAC_RX_WORD_COUNT: std_logic_vector(10 downto 0) := (others => '0');
+signal MAC_TX_DATA_FLIP: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_TX_DATA_VALID_FLIP: std_logic_vector(7 downto 0) := (others => '0');
+--
+----//-- PARSE INCOMING PACKET --------------
+signal RX_TYPE: std_logic_vector(3 downto 0) := (others => '0');
+signal RX_TYPE_RDY : std_logic := '0';
+signal RX_IPv4_6n : std_logic := '0';
+signal RX_IP_PROTOCOL : std_logic_vector(7 downto 0) := (others => '0');
+signal RX_IP_PROTOCOL_RDY : std_logic := '0';
+signal IP_RX_FRAME_VALID: std_logic := '0';
+signal IP_RX_FRAME_VALID2: std_logic := '0';
+signal IP_RX_DATA : std_logic_vector(63 downto 0) := (others => '0');
+signal IP_RX_DATA_VALID : std_logic_vector(7 downto 0) := (others => '0');
+signal IP_RX_SOF : std_logic := '0';
+signal IP_RX_EOF : std_logic := '0';
+signal IP_RX_WORD_COUNT : std_logic_vector(10 downto 0) := (others => '0');
+signal IP_PAYLOAD_DATA : std_logic_vector(63 downto 0) := (others => '0');
+signal IP_PAYLOAD_DATA_VALID : std_logic_vector(7 downto 0) := (others => '0');
+signal IP_PAYLOAD_SOF : std_logic := '0';
+signal IP_PAYLOAD_EOF : std_logic := '0';
+signal IP_PAYLOAD_LENGTH: std_logic_vector(15 downto 0) := (others => '0');
+signal IP_PAYLOAD_WORD_COUNT : std_logic_vector(10 downto 0) := (others => '0');
+signal IP_HEADER_FLAG : std_logic_vector(1 downto 0) := (others => '0');
+signal VALID_IP_PAYLOAD_CHECKSUM: std_logic := '0';
+signal VALID_UDP_CHECKSUM: std_logic := '0';
+signal VALID_TCP_CHECKSUM: std_logic := '0';
+signal TP_PARSING: std_logic_vector(10 downto 1);
+signal RX_SOURCE_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal RX_SOURCE_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal RX_DEST_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal VALID_UNICAST_DEST_IP: std_logic := '0';
+signal VALID_MULTICAST_DEST_IP: std_logic := '0';
+signal VALID_DEST_IP_RDY: std_logic := '0';
+signal IP_HEADER_CHECKSUM_VALID: std_logic := '0';
+signal IP_HEADER_CHECKSUM_VALID_RDY: std_logic := '0';
+
+
+
+--//-- ARP REPLY --------------
+signal ARP_MAC_TX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal ARP_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0) := x"00";
+signal ARP_MAC_TX_EOF: std_logic := '0';
+signal ARP_MAC_TX_CTS: std_logic := '0';
+signal ARP_RTS: std_logic := '0';
+signal TP_ARP: std_logic_vector(10 downto 1);
+
+--//-- ICMPV6 --------------
+signal ICMPV6_MAC_TX_DATA: std_logic_vector(63 downto 0):= (others => '0');
+signal ICMPV6_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0):= (others => '0');
+signal ICMPV6_MAC_TX_EOF: std_logic := '0';
+signal ICMPV6_MAC_TX_CTS: std_logic := '0';
+signal ICMPV6_RTS: std_logic := '0';
+signal TP_ICMPV6: std_logic_vector(10 downto 1);
+
+--//-- PING REPLY --------------
+signal PING_MAC_TX_DATA: std_logic_vector(63 downto 0):= (others => '0');
+signal PING_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0):= (others => '0');
+signal PING_MAC_TX_EOF: std_logic := '0';
+signal PING_MAC_TX_CTS: std_logic := '0';
+signal PING_RTS: std_logic := '0';
+signal TP_PING: std_logic_vector(10 downto 1);
+
+--//-- WHOIS ---------------------------------------------
+signal WHOIS_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal WHOIS_IPv4_6n: std_logic := '0';
+signal WHOIS_START: std_logic := '0';
+signal WHOIS_RDY: std_logic := '0';
+signal WHOIS_MAC_TX_DATA: std_logic_vector(63 downto 0):= (others => '0');
+signal WHOIS_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0):= (others => '0');
+signal WHOIS_MAC_TX_EOF: std_logic := '0';
+signal WHOIS_MAC_TX_CTS: std_logic := '0';
+signal WHOIS_RTS: std_logic := '0';
+signal TP_WHOIS: std_logic_vector(10 downto 1) := (others => '0');
+
+--//-- ARP CACHE -----------------------------------------
+signal RT_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal RT_IPv4_6n: std_logic := '0';
+signal RT_REQ_RTS: std_logic := '0';
+signal RT_CTS: std_logic := '0';
+signal RT_MAC_REPLY: std_logic_vector(47 downto 0) := (others => '0');
+signal RT_MAC_RDY: std_logic := '0';
+signal RT_NAK: std_logic := '0';
+signal TP_ARP_CACHE2: std_logic_vector(10 downto 1) := (others => '0');
+
+--//-- DHCP SERVER ------------------------------------
+signal DHCPS_SYNC_RESET: std_logic := '0';
+signal DHCPS_MAC_TX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCPS_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal DHCPS_MAC_TX_EOF: std_logic := '0';
+signal DHCPS_MAC_TX_CTS: std_logic := '0';
+signal DHCPS_RTS: std_logic := '0';
+signal TP_DHCP_SERVER: std_logic_vector(10 downto 1) := (others => '0');
+
+--//-- DHCP CLIENT (DYNAMIC IP) -----------------------------------------
+signal IPv4_ADDR_local: std_logic_vector(31 downto 0) := (others => '0');
+signal IPv4_SUBNET_MASK_local: std_logic_vector(31 downto 0) := (others => '0');
+signal IPv4_GATEWAY_ADDR_local: std_logic_vector(31 downto 0) := (others => '0');
+signal DHCPC_SYNC_RESET: std_logic := '0';
+signal DHCPC_IPv4_ADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal DHCPC_SUBNET_MASK: std_logic_vector(31 downto 0) := (others => '0');
+signal DHCPC_ROUTER: std_logic_vector(31 downto 0) := (others => '0');
+signal DHCPC_MAC_TX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCPC_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0) := x"00";
+signal DHCPC_MAC_TX_EOF: std_logic := '0';
+signal DHCPC_MAC_TX_CTS: std_logic := '0';
+signal DHCPC_RTS: std_logic := '0';
+signal TP_DHCPC: std_logic_vector(10 downto 1);
+
+--//-- IGMP (MULTICAST) -----------------------------------------
+signal IGMP_REPORT_START: std_logic := '0';
+signal IGMP_TRIGGER_RESPONSE: std_logic := '0';
+signal IGMP_TRIGGER_RESPONSE2: std_logic := '0';
+signal IGMP_TRIGGER_RESPONSE3: std_logic := '0';
+signal IGMP_MAC_TX_DATA: std_logic_vector(63 downto 0):= (others => '0');
+signal IGMP_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0):= (others => '0');
+signal IGMP_MAC_TX_EOF: std_logic := '0';
+signal IGMP_MAC_TX_CTS: std_logic := '0';
+signal IGMP_RTS: std_logic := '0';
+signal TP_IGMP_QUERY: std_logic_vector(10 downto 1) := (others => '0');
+signal TP_IGMP_REPORT: std_logic_vector(10 downto 1) := (others => '0');
+
+--//-- UDP RX ------------------------------------
+signal UDP_RX_DATA_local: std_logic_vector(63 downto 0):= (others => '0');
+signal UDP_RX_DATA_VALID_local: std_logic_vector(7 downto 0):= (others => '0');
+signal UDP_RX_SOF_local: std_logic := '0';
+signal UDP_RX_EOF_local: std_logic := '0';
+signal UDP_RX_DEST_PORT_NO_local: std_logic_vector(15 downto 0):= (others => '0');
+signal UDP_RX_FRAME_VALID1: std_logic := '0';
+signal UDP_RX_FRAME_VALID2: std_logic := '0';
+signal TP_UDP_RX: std_logic_vector(10 downto 1) := (others => '0');
+
+----//-- UDP TX ------------------------------------
+signal UDP001_RT_REQ_RTS: std_logic := '0';
+signal UDP001_RT_REQ_CTS: std_logic := '0';
+signal UDP001_RT_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal UDP001_RT_IPv4_6n: std_logic := '0';
+signal UDP001_RT_MAC_RDY: std_logic := '0';
+signal UDP001_RT_NAK: std_logic := '0';
+signal UDP001_MAC_TX_DATA: std_logic_vector(63 downto 0):= (others => '0');
+signal UDP001_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0):= (others => '0');
+signal UDP001_MAC_TX_EOF: std_logic := '0';
+signal UDP001_MAC_TX_CTS: std_logic := '0';
+signal UDP001_RTS: std_logic := '0';
+signal TP_UDP_TX: std_logic_vector(10 downto 1) := (others => '0');
+signal UDP_TX_ACK_local: std_logic := '0';
+signal UDP_TX_NAK_local: std_logic := '0';
+--
+--//-- TCP RX ------------------------------------
+-- TCP server 001
+--signal TCP_LOCAL_PORTS: SLV16xNTCPSTREAMStype;
+signal TCP001_MAC_TX_DATA: std_logic_vector(63 downto 0):= (others => '0');
+signal TCP001_MAC_TX_DATA_VALID: std_logic_vector(7 downto 0):= (others => '0');
+signal TCP001_MAC_TX_EOF: std_logic := '0';
+signal TCP001_MAC_TX_CTS: std_logic := '0';
+signal TCP001_RTS: std_logic := '0';
+signal TCP001_RX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal TCP001_RX_DATA_VALID: std_logic_vector(7 downto 0):= (others => '0');
+signal TCP001_RX_SOF: std_logic := '0';
+signal TCP001_RX_TCP_STREAM_SEL: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+signal TCP001_RX_EOF: std_logic := '0';
+signal TCP_001_RX_FRAME_VALID: std_logic := '0';
+signal TCP001_RX_FREE_SPACE: SLV16xNTCPSTREAMStype;
+signal TCP001_TX_PACKET_SEQUENCE_START: std_logic := '0';
+signal TCP001_TX_DEST_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal TCP001_TX_DEST_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal TCP001_TX_DEST_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal TCP001_TX_SOURCE_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal TCP001_TX_IPv4_6n: std_logic := '0';
+signal TCP001_TX_SEQ_NO: std_logic_vector(31 downto 0) := (others => '0');
+signal TCP001_TX_ACK_NO: std_logic_vector(31 downto 0) := (others => '0');
+signal TCP001_TX_ACK_WINDOW_LENGTH: std_logic_vector(15 downto 0) := (others => '0');
+signal TCP001_TX_FLAGS: std_logic_vector(7 downto 0) := (others => '0');
+signal TCP001_TX_PACKET_TYPE: std_logic_vector(1 downto 0) := (others => '0');
+signal TCP001_EFF_RX_WINDOW_SIZE_PARTIAL: std_logic_vector(16 downto 0) := (others => '0');
+signal TCP001_EFF_RX_WINDOW_SIZE_PARTIAL_STREAM: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal TCP001_EFF_RX_WINDOW_SIZE_PARTIAL_VALID: std_logic := '0'; -- 1 CLK-wide pulse to indicate that the above information is valid
+signal TCP001_TX_SEQ_NOxNTCPSTREAMS: SLV17xNTCPSTREAMStype;
+signal TCP001_TX_SEQ_NO_JUMP: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal TCP001_RX_ACK_NOxNTCPSTREAMS: SLV17xNTCPSTREAMStype;
+signal TCP001_CONNECTED_FLAG: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal TCP001_TX_PAYLOAD_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal TCP001_TX_PAYLOAD_DATA_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal TCP001_TX_PAYLOAD_WORD_VALID: std_logic := '0';
+signal TCP001_TX_PAYLOAD_DATA_EOF: std_logic := '0';
+signal TCP001_TX_PAYLOAD_RTS: std_logic := '0';
+signal TCP001_TX_PAYLOAD_CTS: std_logic := '0';
+signal TCP001_TX_PAYLOAD_SIZE: std_logic_vector(15 downto 0) := (others => '0');
+signal TCP001_TX_PAYLOAD_CHECKSUM: std_logic_vector(17 downto 0) := (others => '0');
+signal TCP001_TX_STREAM_SEL: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal TCP001_TCP_TX_CTS: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal TP_TCP_SERVER: std_logic_vector(10 downto 1);
+signal TP_TCP_TXBUF: std_logic_vector(10 downto 1);
+--
+-- TCP server 002
+-- etc...
+
+--//-- TRANSMISSION ARBITER --------------
+signal IP_ID: unsigned(15 downto 0) := x"0000";
+signal TX_MUX_STATE: integer range 0 to 10; -- up to N protocol engines. Increase size if more.
+
+--//-- ROUTING TABLE ARBITER --------------
+signal RT_MUX_STATE: integer range 0 to 10;
+ -- 1 + number of transmit components vying for access to the routing table. Adjust as needed.
+
+------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--//-- RESET -----------------------------
+-- Reset is mandatory but just in case one forgets, create a local one at power up.
+SYNC_RESET_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ RESET_CNTR_MSB_D <= RESET_CNTR_MSB;
+
+ if(RESET_CNTR_MSB = '0') then
+ RESET_CNTR <= RESET_CNTR + 1;
+ end if;
+
+ if(RESET_CNTR_MSB_D = '0') and (RESET_CNTR_MSB = '1') then
+ SYNC_RESET_local <= '1';
+ else
+ SYNC_RESET_local <= SYNC_RESET;
+ end if;
+ end if;
+end process;
+RESET_CNTR_MSB <= RESET_CNTR(RESET_CNTR'left);
+
+-- manually reduce fanout for sync reset (there may be other methods, but this one works with Xilinx Vivado,
+-- Original SYNC_RESET fanout was over 1200 resulting in excessive routing delay)
+SYNC_RESET_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ SYNC_RESET1 <= SYNC_RESET_local;
+ SYNC_RESET2 <= SYNC_RESET_local;
+ SYNC_RESET3 <= SYNC_RESET_local;
+ SYNC_RESET4 <= SYNC_RESET_local;
+ end if;
+end process;
+
+--//-- TIMERS -----------------------------
+TIMER_4US_001: TIMER_4US
+GENERIC MAP(
+ CLK_FREQUENCY => CLK_FREQUENCY
+)
+PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET1,
+ TICK_4US => TICK_4US,
+ TICK_100MS => TICK_100MS_rt
+);
+
+TICK_100MS <= TICK_4US when (SIMULATION = '1') else TICK_100MS_rt; -- to accelerate simulations
+
+--//-- FLIP RX BYTE ORDER IN WORD --------------
+-- flipping the MSB <-> LSB makes it easier to read the various fields values in the code or simulator
+FLIP_RX_MAC_BYTES: process(MAC_RX_DATA, MAC_RX_DATA_VALID)
+begin
+ FOR I in 0 to 7 loop
+ MAC_RX_DATA_FLIP(I*8+7 downto I*8) <= MAC_RX_DATA((7-I)*8+7 downto (7-I)*8);
+ MAC_RX_DATA_VALID_FLIP(I) <= MAC_RX_DATA_VALID(7-I);
+ end loop;
+end process;
+
+
+--//-- PARSE INCOMING PACKET --------------
+-- Code is common to all protocols. Extracts key information from incoming packets.
+ PACKET_PARSING_001: PACKET_PARSING_10G
+ GENERIC MAP(
+ IPv6_ENABLED => IPv6_ENABLED,
+ SIMULATION => SIMULATION
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET1,
+ MAC_RX_DATA => MAC_RX_DATA_FLIP,
+ MAC_RX_DATA_VALID => MAC_RX_DATA_VALID_FLIP,
+ MAC_RX_SOF => MAC_RX_SOF,
+ MAC_RX_EOF => MAC_RX_EOF,
+ MAC_RX_FRAME_VALID => MAC_RX_FRAME_VALID,
+ MAC_RX_WORD_COUNT => MAC_RX_WORD_COUNT,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv6_ADDR => IPv6_ADDR,
+ IPv4_MULTICAST_ADDR => IPv4_MULTICAST_ADDR,
+ IP_RX_DATA => IP_RX_DATA,
+ IP_RX_DATA_VALID => IP_RX_DATA_VALID,
+ IP_RX_SOF => IP_RX_SOF,
+ IP_RX_EOF => IP_RX_EOF,
+ IP_RX_WORD_COUNT => IP_RX_WORD_COUNT,
+ IP_HEADER_FLAG => IP_HEADER_FLAG,
+ RX_TYPE => RX_TYPE,
+ RX_TYPE_RDY => RX_TYPE_RDY,
+ RX_IPv4_6n => RX_IPv4_6n,
+ RX_IP_PROTOCOL => RX_IP_PROTOCOL,
+ RX_IP_PROTOCOL_RDY => RX_IP_PROTOCOL_RDY,
+ IP_RX_FRAME_VALID => IP_RX_FRAME_VALID,
+ IP_RX_FRAME_VALID2 => IP_RX_FRAME_VALID2,
+ VALID_UNICAST_DEST_IP => VALID_UNICAST_DEST_IP,
+ VALID_MULTICAST_DEST_IP => VALID_MULTICAST_DEST_IP,
+ VALID_DEST_IP_RDY => VALID_DEST_IP_RDY,
+ IP_HEADER_CHECKSUM_VALID => IP_HEADER_CHECKSUM_VALID,
+ IP_HEADER_CHECKSUM_VALID_RDY => IP_HEADER_CHECKSUM_VALID_RDY,
+ RX_SOURCE_MAC_ADDR => RX_SOURCE_MAC_ADDR,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR,
+ RX_DEST_IP_ADDR => RX_DEST_IP_ADDR,
+ IP_PAYLOAD_DATA => IP_PAYLOAD_DATA,
+ IP_PAYLOAD_DATA_VALID => IP_PAYLOAD_DATA_VALID,
+ IP_PAYLOAD_SOF => IP_PAYLOAD_SOF,
+ IP_PAYLOAD_EOF => IP_PAYLOAD_EOF,
+ IP_PAYLOAD_LENGTH => IP_PAYLOAD_LENGTH,
+ IP_PAYLOAD_WORD_COUNT => IP_PAYLOAD_WORD_COUNT,
+ VALID_IP_PAYLOAD_CHECKSUM => VALID_IP_PAYLOAD_CHECKSUM,
+ VALID_UDP_CHECKSUM => VALID_UDP_CHECKSUM,
+ VALID_TCP_CHECKSUM => VALID_TCP_CHECKSUM,
+ CS1 => open,
+ CS1_CLK => open,
+ CS2 => open,
+ CS2_CLK => open,
+ TP => TP_PARSING
+ );
+
+-- DEBUG_001: process(CLK)
+-- begin
+-- if rising_edge(CLK) then
+-- if(IP_PAYLOAD_DATA_VALID /= x"00") then
+-- if(unsigned(IP_PAYLOAD_WORD_COUNT) = 1) then
+-- DEBUG1 <= IP_PAYLOAD_DATA;
+-- end if;
+-- if(unsigned(IP_PAYLOAD_WORD_COUNT) = 2) then
+-- DEBUG2 <= IP_PAYLOAD_DATA;
+-- end if;
+-- if(unsigned(IP_PAYLOAD_WORD_COUNT) = 3) then
+-- DEBUG3 <= IP_PAYLOAD_DATA;
+-- end if;
+-- end if;
+-- end if;
+-- end process;
+
+
+--//-- ARP REPLY --------------
+-- Instantiated once per PHY. IPv4-only. Use NDP for IPv6.
+ ARP_001: ARP_10G
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET2,
+ MAC_RX_DATA => MAC_RX_DATA_FLIP,
+ MAC_RX_DATA_VALID => MAC_RX_DATA_VALID_FLIP,
+ MAC_RX_SOF => MAC_RX_SOF,
+ MAC_RX_EOF => MAC_RX_EOF,
+ MAC_RX_FRAME_VALID => MAC_RX_FRAME_VALID,
+ MAC_RX_WORD_COUNT => MAC_RX_WORD_COUNT,
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ RX_TYPE => RX_TYPE,
+ RX_TYPE_RDY => RX_TYPE_RDY,
+ RX_SOURCE_MAC_ADDR => RX_SOURCE_MAC_ADDR,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR(31 downto 0),
+ MAC_TX_DATA => ARP_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => ARP_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => ARP_MAC_TX_EOF,
+ MAC_TX_CTS => ARP_MAC_TX_CTS,
+ RTS => ARP_RTS,
+ TP => TP_ARP
+ );
+
+--//-- ICMPV6 --------------
+-- Instantiated once per PHY.
+-- Respond to Neighbor Solicitation Messages
+ICMPV6_001: if(IPv6_ENABLED = '1') generate
+ ICMPV6_001: ICMPV6_10G
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET2,
+ IP_RX_DATA => IP_RX_DATA,
+ IP_RX_DATA_VALID => IP_RX_DATA_VALID,
+ IP_RX_SOF => IP_RX_SOF,
+ IP_RX_EOF => IP_RX_EOF,
+ IP_RX_WORD_COUNT => IP_RX_WORD_COUNT,
+ IP_RX_FRAME_VALID => IP_RX_FRAME_VALID,
+ RX_SOURCE_MAC_ADDR => RX_SOURCE_MAC_ADDR,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR,
+ MAC_ADDR => MAC_ADDR,
+ IPv6_ADDR => IPv6_ADDR,
+ RX_IPv4_6n => RX_IPv4_6n,
+ RX_IP_PROTOCOL => RX_IP_PROTOCOL,
+ RX_IP_PROTOCOL_RDY => RX_IP_PROTOCOL_RDY,
+ MAC_TX_DATA => ICMPV6_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => ICMPV6_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => ICMPV6_MAC_TX_EOF,
+ MAC_TX_CTS => ICMPV6_MAC_TX_CTS,
+ RTS => ICMPV6_RTS,
+ TP => TP_ICMPV6
+ );
+end generate;
+
+--//-- PING REPLY --------------
+-- Instantiated once per PHY.
+ PING_001: PING_10G
+ GENERIC MAP(
+ IPv6_ENABLED => IPv6_ENABLED,
+ MAX_PING_SIZE => x"20" -- 32*8-byte words threshold for incoming IP/ICMP frame
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET3,
+ IP_RX_DATA => IP_RX_DATA,
+ IP_RX_DATA_VALID => IP_RX_DATA_VALID,
+ IP_RX_SOF => IP_RX_SOF,
+ IP_RX_EOF => IP_RX_EOF,
+ IP_RX_WORD_COUNT => IP_RX_WORD_COUNT,
+ IP_RX_FRAME_VALID2 => IP_RX_FRAME_VALID2,
+ VALID_UNICAST_DEST_IP => VALID_UNICAST_DEST_IP,
+ VALID_DEST_IP_RDY => VALID_DEST_IP_RDY,
+ RX_SOURCE_MAC_ADDR => RX_SOURCE_MAC_ADDR,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR,
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv6_ADDR => IPv6_ADDR,
+ RX_IPv4_6n => RX_IPv4_6n,
+ RX_IP_PROTOCOL => RX_IP_PROTOCOL,
+ RX_IP_PROTOCOL_RDY => RX_IP_PROTOCOL_RDY,
+ MAC_TX_DATA => PING_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => PING_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => PING_MAC_TX_EOF,
+ MAC_TX_CTS => PING_MAC_TX_CTS,
+ RTS => PING_RTS,
+ TP => TP_PING
+ );
+
+--//-- WHOIS ---------------------------------------------
+-- Sends ARP and NDP requests
+-- Currently only used by UDP tx
+WHOIS2_X: if(NUDPTX /= 0) generate
+ WHOIS2_001: WHOIS2_10G
+ GENERIC MAP(
+ IPv6_ENABLED => IPv6_ENABLED
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET3,
+ WHOIS_IP_ADDR => WHOIS_IP_ADDR,
+ WHOIS_IPv4_6n => WHOIS_IPv4_6n,
+ WHOIS_START => WHOIS_START,
+ WHOIS_RDY => WHOIS_RDY, -- unused
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv6_ADDR => IPv6_ADDR,
+ MAC_TX_DATA => WHOIS_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => WHOIS_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => WHOIS_MAC_TX_EOF,
+ MAC_TX_CTS => WHOIS_MAC_TX_CTS,
+ RTS => WHOIS_RTS,
+ TP => TP_WHOIS
+ );
+end generate;
+
+--//-- ARP CACHE (ROUTING TABLE) -----------------------------------------
+-- Routing table mapping destination IP addresses and associated MAC addresses.
+-- Currently only used by UDP tx
+ARP_CACHE2_X: if(NUDPTX /= 0) generate
+ ARP_CACHE2_001: ARP_CACHE2_10G
+ GENERIC MAP(
+ IPv6_ENABLED => IPv6_ENABLED
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET2,
+ TICK_100MS => TICK_100MS,
+ RT_IP_ADDR => RT_IP_ADDR,
+ RT_IPv4_6n => RT_IPv4_6n,
+ RT_REQ_RTS => RT_REQ_RTS,
+ RT_CTS => RT_CTS,
+ RT_MAC_REPLY => RT_MAC_REPLY,
+ RT_MAC_RDY => RT_MAC_RDY,
+ RT_NAK => RT_NAK,
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv4_SUBNET_MASK => IPv4_SUBNET_MASK_local,
+ IPv4_GATEWAY_ADDR => IPv4_GATEWAY_ADDR_local,
+ IPv6_ADDR => IPv6_ADDR,
+ IPv6_SUBNET_PREFIX_LENGTH => IPv6_SUBNET_PREFIX_LENGTH,
+ IPv6_GATEWAY_ADDR => IPv6_GATEWAY_ADDR,
+ WHOIS_IP_ADDR => WHOIS_IP_ADDR,
+ WHOIS_IPv4_6n => WHOIS_IPv4_6n,
+ WHOIS_START => WHOIS_START,
+ RX_SOURCE_ADDR_RDY => MAC_RX_EOF,
+ RX_SOURCE_MAC_ADDR => RX_SOURCE_MAC_ADDR,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR,
+ RX_IPv4_6n => RX_IPv4_6n,
+ SREG1 => open,
+ SREG2 => open,
+ SREG3 => open,
+ SREG4 => open,
+ SREG5 => open,
+ SREG6 => open,
+ TP => TP_ARP_CACHE2
+ );
+end generate;
+
+--//-- DHCP SERVER ------------------------------------
+DHCP_SERVER_X: if(DHCP_SERVER_EN = '1') generate
+ DHCPS_SYNC_RESET <= SYNC_RESET or (not DHCP_SERVER_EN2);
+ DHCP_SERVER_001: DHCP_SERVER_10G
+ PORT MAP(
+ SYNC_RESET => DHCPS_SYNC_RESET,
+ CLK => CLK,
+ TICK_4US => TICK_4US,
+ TICK_100MS => TICK_100MS,
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv6_ADDR => IPv6_ADDR,
+ HOST_NAME => x"414243444546",
+ IP_MIN => DHCP_SERVER_IP_MIN_LSB,
+ NIPs => DHCP_SERVER_NIPs,
+ LEASE_TIME => DHCP_SERVER_LEASE_TIME,
+ SUBNET_MASK => IPv4_SUBNET_MASK_local,
+ ROUTER => DHCP_ROUTER,
+ DNS => DHCP_SERVER_DNS,
+ -- UDP rx frame
+ UDP_RX_DATA => UDP_RX_DATA_local,
+ UDP_RX_DATA_VALID => UDP_RX_DATA_VALID_local,
+ UDP_RX_SOF => UDP_RX_SOF_local,
+ UDP_RX_EOF => UDP_RX_EOF_local,
+ UDP_RX_FRAME_VALID => UDP_RX_FRAME_VALID1,
+ UDP_RX_DEST_PORT_NO => UDP_RX_DEST_PORT_NO_local,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR(31 downto 0),
+ IP_ID_IN => std_logic_vector(IP_ID),
+ -- MAC interface
+ MAC_TX_DATA => DHCPS_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => DHCPS_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => DHCPS_MAC_TX_EOF,
+ MAC_TX_CTS => DHCPS_MAC_TX_CTS,
+ RTS => DHCPS_RTS,
+-- N_DHCPDISCOVER_OUT => N_DHCPDISCOVER_OUT,
+-- N_DHCPREQUEST1_OUT => N_DHCPREQUEST1_OUT,
+-- N_DHCPREQUEST2_OUT => N_DHCPREQUEST2_OUT,
+-- N_DHCPREQUEST3_OUT => N_DHCPREQUEST3_OUT,
+-- N_DHCPACK_OUT => N_DHCPACK_OUT,
+ TP => TP_DHCP_SERVER
+ );
+end generate;
+
+--//-- DHCP CLIENT (DYNAMIC IP) -----------------------------------------
+DHCP_CLIENT_000: if(DHCP_CLIENT_EN = '0') generate
+ -- no DHCP client is instantiated. Always static IP address
+ -- use static IP address, subnet mask and gateway address (stored externally)
+ IPv4_ADDR_local <= REQUESTED_IPv4_ADDR;
+ IPv4_SUBNET_MASK_local <= IPv4_SUBNET_MASK;
+ IPv4_GATEWAY_ADDR_local <= IPv4_GATEWAY_ADDR;
+end generate;
+
+DHCP_CLIENT_001: if(DHCP_CLIENT_EN = '1') generate
+ -- keep this component in reset if the user selects static IP
+ DHCPC_SYNC_RESET <= (not DYNAMIC_IPv4) or SYNC_RESET;
+
+ -- remember the last assigned address
+ DHCPC_LAST_IPv4_ADDR_GEN: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(DYNAMIC_IPv4 = '0') then
+ -- static IP address
+ IPv4_ADDR_local <= REQUESTED_IPv4_ADDR;
+ IPv4_SUBNET_MASK_local <= IPv4_SUBNET_MASK;
+ IPv4_GATEWAY_ADDR_local <= IPv4_GATEWAY_ADDR;
+ else
+ -- dynamic IP address, based on DHCP server assignment
+ IPv4_ADDR_local <= DHCPC_IPv4_ADDR;
+ IPv4_SUBNET_MASK_local <= DHCPC_SUBNET_MASK;
+ IPv4_GATEWAY_ADDR_local <= DHCPC_ROUTER;
+ end if;
+ end if;
+ end process;
+
+ DHCP_CLIENT_10G_001: DHCP_CLIENT_10G
+ GENERIC MAP(
+ SIMULATION => SIMULATION
+ )
+ PORT MAP(
+ SYNC_RESET => DHCPC_SYNC_RESET,
+ CLK => CLK,
+ TICK_4US => TICK_4US,
+ TICK_100MS => TICK_100MS,
+ MAC_ADDR => MAC_ADDR,
+ LAST_IPv4_ADDR => REQUESTED_IPv4_ADDR,
+ -- DHCP server assignment
+ IPv4_ADDR => DHCPC_IPv4_ADDR,
+ LEASE_TIME => open,
+ SUBNET_MASK => DHCPC_SUBNET_MASK,
+ ROUTER => DHCPC_ROUTER,
+ DNS1 => open,
+ DNS2 => open,
+ -- UDP rx frame
+ UDP_RX_DATA => UDP_RX_DATA_local,
+ UDP_RX_DATA_VALID => UDP_RX_DATA_VALID_local,
+ UDP_RX_SOF => UDP_RX_SOF_local,
+ UDP_RX_EOF => UDP_RX_EOF_local,
+ UDP_RX_FRAME_VALID => UDP_RX_FRAME_VALID1,
+ UDP_RX_DEST_PORT_NO => UDP_RX_DEST_PORT_NO_local,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR(31 downto 0),
+ IP_ID_IN => std_logic_vector(IP_ID),
+ -- MAC interface
+ MAC_TX_DATA => DHCPC_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => DHCPC_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => DHCPC_MAC_TX_EOF,
+ MAC_TX_CTS => DHCPC_MAC_TX_CTS,
+ RTS => DHCPC_RTS,
+ TP => TP_DHCPC
+ );
+
+end generate;
+--IPv4_ADDR_OUT <= IPv4_ADDR_local; -- report actual IP address
+--SUBNET_MASK_OUT <= SUBNET_MASK_local;
+--GATEWAY_IP_ADDR_OUT <= GATEWAY_IP_ADDR_local;
+
+--//-- IGMP (MULTICAST) -----------------------------------------
+-- detects an IGMP membership query. Triggers a response
+IGMP_QUERY_001x: if (IGMP_EN = '1') and (NUDPTX /= 0) generate
+ IGMP_QUERY_001: IGMP_QUERY_10G
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET,
+ MULTICAST_IP_ADDR => IPv4_MULTICAST_ADDR,
+ IP_PAYLOAD_DATA => IP_PAYLOAD_DATA,
+ IP_PAYLOAD_DATA_VALID => IP_PAYLOAD_DATA_VALID,
+ IP_PAYLOAD_SOF => IP_PAYLOAD_SOF,
+ IP_PAYLOAD_EOF => IP_PAYLOAD_EOF,
+ IP_PAYLOAD_WORD_COUNT => IP_PAYLOAD_WORD_COUNT,
+ IP_RX_FRAME_VALID2 => IP_RX_FRAME_VALID2,
+ RX_IP_PROTOCOL => RX_IP_PROTOCOL,
+ VALID_MULTICAST_DEST_IP => VALID_MULTICAST_DEST_IP,
+ VALID_IP_PAYLOAD_CHECKSUM => VALID_IP_PAYLOAD_CHECKSUM,
+ RX_DEST_IP_ADDR => RX_DEST_IP_ADDR(31 downto 0), -- IGMP is only for IPv4
+ TRIGGER_RESPONSE => IGMP_TRIGGER_RESPONSE,
+ TP => TP_IGMP_QUERY
+ );
+
+ -- send an IGMP membership report either in response to a membership query
+ -- or a couple of times at power up/reset
+ -- or once every 102.4 seconds
+ IGMP_REPORT_TIMER_GEN: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') then
+ TICK_CNTR <= (others => '0');
+ elsif(TICK_100MS = '1') and (TICK_CNTR(6) = '0') then
+ -- counts from 0 to 64 and stay there
+ TICK_CNTR <= TICK_CNTR + 1;
+ end if;
+
+ -- modulo 1024 counter
+ if (SYNC_RESET = '1') then
+ TICK_CNTR2 <= (others => '0');
+ elsif(TICK_100MS = '1') then
+ TICK_CNTR2 <= TICK_CNTR2 + 1;
+ end if;
+
+
+ if(TICK_100MS = '1') and (TICK_CNTR(6) = '0') and (TICK_CNTR(4 downto 0) = 0) then
+ -- generate two pulses at 3.4 and 6.4s after reset
+ IGMP_TRIGGER_RESPONSE2 <= '1';
+ else
+ IGMP_TRIGGER_RESPONSE2 <= '0';
+ end if;
+
+ if(TICK_100MS = '1') and (TICK_CNTR2 = 1023) then
+ -- generate periodic pulses once every 102.4 seconds
+ IGMP_TRIGGER_RESPONSE3 <= '1';
+ else
+ IGMP_TRIGGER_RESPONSE3 <= '0';
+ end if;
+
+ end if;
+ end process;
+
+ -- 0.0.0.0 to signify that IP multicasting is not supported here.
+ IGMP_REPORT_START <= (IGMP_TRIGGER_RESPONSE or IGMP_TRIGGER_RESPONSE2 or IGMP_TRIGGER_RESPONSE3) when (IPv4_MULTICAST_ADDR /= x"00000000") else '0';
+
+ IGMP_REPORT_001: IGMP_REPORT_10G
+ PORT MAP(
+ SYNC_RESET => SYNC_RESET,
+ CLK => CLK,
+ IGMP_START => IGMP_REPORT_START,
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IP_ID => std_logic_vector(IP_ID),
+ MULTICAST_IP_ADDR => IPv4_MULTICAST_ADDR,
+ MAC_TX_CTS => IGMP_MAC_TX_CTS,
+ MAC_TX_DATA => IGMP_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => IGMP_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => IGMP_MAC_TX_EOF,
+ RTS => IGMP_RTS,
+ TP => TP_IGMP_REPORT
+ );
+end generate;
+
+
+----//-- UDP RX to Serial (Monitoring and control) ---------
+-- Inst_UDP2SERIAL: UDP2SERIAL_10G
+-- GENERIC MAP(
+-- PORT_NO => x"0405", --1029
+-- CLK_FREQUENCY => CLK_FREQUENCY
+-- )
+-- PORT MAP(
+-- CLK => CLK,
+-- SYNC_RESET => SYNC_RESET,
+-- IP_RX_DATA => IP_RX_DATA,
+-- IP_RX_DATA_VALID => IP_RX_DATA_VALID,
+-- IP_RX_SOF => IP_RX_SOF,
+-- IP_RX_EOF => IP_RX_EOF,
+-- IP_HEADER_FLAG => IP_HEADER_FLAG,
+-- RX_IP_PROTOCOL => RX_IP_PROTOCOL,
+-- RX_IP_PROTOCOL_RDY => RX_IP_PROTOCOL_RDY,
+-- SERIAL_OUT => open,
+-- TP => open
+-- );
+--
+--//-- UDP RX ------------------------------------
+UDP_RX_X: if(NUDPRX /= 0) or (DHCP_SERVER_EN = '1') or (DHCP_CLIENT_EN = '1') generate
+ -- Note: DHCP server and DHCP client rely on the UDP_RX
+ UDP_RX_001: UDP_RX_10G
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET1,
+ IP_PAYLOAD_DATA => IP_PAYLOAD_DATA,
+ IP_PAYLOAD_DATA_VALID => IP_PAYLOAD_DATA_VALID,
+ IP_PAYLOAD_SOF => IP_PAYLOAD_SOF,
+ IP_PAYLOAD_EOF => IP_PAYLOAD_EOF,
+ IP_PAYLOAD_WORD_COUNT => IP_PAYLOAD_WORD_COUNT,
+ IP_RX_FRAME_VALID => IP_RX_FRAME_VALID,
+ RX_IP_PROTOCOL => RX_IP_PROTOCOL,
+ VALID_UDP_CHECKSUM => VALID_UDP_CHECKSUM,
+ -- configuration
+ PORT_NO => x"0000",
+ CHECK_UDP_RX_DEST_PORT_NO => '0', -- destination UDP port check done below instead of within the component
+ -- Application interface + DHCP server interface
+ UDP_RX_DATA => UDP_RX_DATA_local,
+ UDP_RX_DATA_VALID => UDP_RX_DATA_VALID_local,
+ UDP_RX_SOF => UDP_RX_SOF_local,
+ UDP_RX_EOF => UDP_RX_EOF_local,
+ UDP_RX_FRAME_VALID => UDP_RX_FRAME_VALID1,
+ UDP_RX_SRC_PORT => open,
+ UDP_RX_DEST_PORT => UDP_RX_DEST_PORT_NO_local,
+ TP => TP_UDP_RX
+ );
+ -- send to application UDP port
+ UDP_RX_DATA <= UDP_RX_DATA_local;
+ UDP_RX_DATA_VALID <= UDP_RX_DATA_VALID_local;
+ UDP_RX_SOF <= UDP_RX_SOF_local;
+ UDP_RX_EOF <= UDP_RX_EOF_local;
+ UDP_RX_DEST_PORT_NO_OUT <= UDP_RX_DEST_PORT_NO_local;
+
+ -- check UDP destination port for application payload (when requested by the application)
+ UDP_RX_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(IP_PAYLOAD_SOF = '1') then
+ if(CHECK_UDP_RX_DEST_PORT_NO = '1') and (UDP_RX_DEST_PORT_NO_IN /= IP_PAYLOAD_DATA(47 downto 32)) then -- *060719
+ UDP_RX_FRAME_VALID2 <= '0';
+ else
+ UDP_RX_FRAME_VALID2 <= '1';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ UDP_RX_FRAME_VALID <= UDP_RX_FRAME_VALID1 and UDP_RX_FRAME_VALID2;
+end generate;
+
+--//-- UDP TX ------------------------------------
+UDP_TX_X: if(NUDPTX /= 0) generate
+ UDP_TX_001: UDP_TX_10G
+ GENERIC MAP(
+ ADDR_WIDTH => 10, -- elastic buffer size as 72b * 2^ADDR_WIDTH
+ UDP_CKSUM_ENABLED => '1',
+ IPv6_ENABLED => IPv6_ENABLED
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET1,
+ TICK_4US => TICK_4US,
+ -- Application interface
+ APP_DATA => UDP_TX_DATA,
+ APP_DATA_VALID => UDP_TX_DATA_VALID,
+ APP_SOF => UDP_TX_SOF,
+ APP_EOF => UDP_TX_EOF,
+ APP_CTS => UDP_TX_CTS,
+ ACK => UDP_TX_ACK_local,
+ NAK => UDP_TX_NAK_local,
+ DEST_IP_ADDR => UDP_TX_DEST_IP_ADDR,
+ IPv4_6n => UDP_TX_DEST_IPv4_6n,
+ DEST_PORT_NO => UDP_TX_DEST_PORT_NO,
+ SOURCE_PORT_NO => UDP_TX_SOURCE_PORT_NO,
+ -- Configuration
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv6_ADDR => IPv6_ADDR,
+ IP_ID => std_logic_vector(IP_ID),
+ -- Routing
+ RT_IP_ADDR => UDP001_RT_IP_ADDR,
+ RT_IPv4_6n => UDP001_RT_IPv4_6n,
+ RT_REQ_RTS => UDP001_RT_REQ_RTS,
+ RT_REQ_CTS => UDP001_RT_REQ_CTS,
+ RT_MAC_REPLY => RT_MAC_REPLY,
+ RT_MAC_RDY => UDP001_RT_MAC_RDY,
+ RT_NAK => UDP001_RT_NAK,
+ -- MAC interface
+ MAC_TX_DATA => UDP001_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => UDP001_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => UDP001_MAC_TX_EOF,
+ MAC_TX_CTS => UDP001_MAC_TX_CTS,
+ RTS => UDP001_RTS,
+ TP => TP_UDP_TX
+ );
+end generate;
+UDP_TX_ACK <= UDP_TX_ACK_local;
+UDP_TX_NAK <= UDP_TX_NAK_local;
+
+--//-- TCP SERVER 001 ------------------------------------
+-- declare the port number for each TCP stream (NTCPSTREAMS streams, declared in the generic section)
+
+TCP_SERVER_X: if (NTCPSTREAMS /= 0) generate
+ TCP_SERVER_001: TCP_SERVER_10G
+ GENERIC MAP(
+ NTCPSTREAMS => NTCPSTREAMS,
+ MSS => MTU-60, -- 40byte header for IPv4/TCP but 60byte header for IPv6/TCP
+ IPv6_ENABLED => IPv6_ENABLED,
+ TCP_KEEPALIVE_PERIOD => TCP_KEEPALIVE_PERIOD,
+ SIMULATION => SIMULATION
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET4,
+ TICK_4US => TICK_4US,
+ TICK_100MS => TICK_100MS,
+ MAC_ADDR => MAC_ADDR,
+ TCP_LOCAL_PORTS => TCP_LOCAL_PORTS,
+ CONNECTION_RESET => CONNECTION_RESET,
+ TCP_KEEPALIVE_EN => TCP_KEEPALIVE_EN,
+ IP_PAYLOAD_DATA => IP_PAYLOAD_DATA,
+ IP_PAYLOAD_DATA_VALID => IP_PAYLOAD_DATA_VALID,
+ IP_PAYLOAD_SOF => IP_PAYLOAD_SOF,
+ IP_PAYLOAD_EOF => IP_PAYLOAD_EOF,
+ IP_PAYLOAD_WORD_COUNT => IP_PAYLOAD_WORD_COUNT,
+ IP_RX_FRAME_VALID => IP_RX_FRAME_VALID,
+ RX_IPv4_6n => RX_IPv4_6n,
+ RX_IP_PROTOCOL => RX_IP_PROTOCOL,
+ RX_IP_PROTOCOL_RDY => RX_IP_PROTOCOL_RDY,
+ RX_SOURCE_MAC_ADDR => RX_SOURCE_MAC_ADDR,
+ RX_SOURCE_IP_ADDR => RX_SOURCE_IP_ADDR,
+ VALID_TCP_CHECKSUM => VALID_TCP_CHECKSUM,
+ RX_DATA => TCP001_RX_DATA,
+ RX_DATA_VALID => TCP001_RX_DATA_VALID,
+ RX_SOF => TCP001_RX_SOF,
+ RX_TCP_STREAM_SEL_OUT => TCP001_RX_TCP_STREAM_SEL,
+ RX_EOF => TCP001_RX_EOF,
+ RX_FRAME_VALID => TCP_001_RX_FRAME_VALID,
+ RX_FREE_SPACE => TCP001_RX_FREE_SPACE,
+ TX_PACKET_SEQUENCE_START_OUT => TCP001_TX_PACKET_SEQUENCE_START,
+ TX_DEST_MAC_ADDR_OUT => TCP001_TX_DEST_MAC_ADDR,
+ TX_DEST_IP_ADDR_OUT => TCP001_TX_DEST_IP_ADDR,
+ TX_DEST_PORT_NO_OUT => TCP001_TX_DEST_PORT_NO,
+ TX_SOURCE_PORT_NO_OUT => TCP001_TX_SOURCE_PORT_NO,
+ TX_IPv4_6n_OUT => TCP001_TX_IPv4_6n,
+ TX_SEQ_NO_OUT => TCP001_TX_SEQ_NO,
+ TX_ACK_NO_OUT => TCP001_TX_ACK_NO,
+ TX_ACK_WINDOW_LENGTH_OUT => TCP001_TX_ACK_WINDOW_LENGTH,
+ TX_FLAGS_OUT => TCP001_TX_FLAGS,
+ TX_PACKET_TYPE_OUT => TCP001_TX_PACKET_TYPE,
+ MAC_TX_EOF => TCP001_MAC_TX_EOF,
+ RTS => TCP001_RTS,
+ EFF_RX_WINDOW_SIZE_PARTIAL => TCP001_EFF_RX_WINDOW_SIZE_PARTIAL,
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM => TCP001_EFF_RX_WINDOW_SIZE_PARTIAL_STREAM,
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID => TCP001_EFF_RX_WINDOW_SIZE_PARTIAL_VALID,
+ TX_SEQ_NO => TCP001_TX_SEQ_NOxNTCPSTREAMS,
+ TX_SEQ_NO_JUMP => TCP001_TX_SEQ_NO_JUMP,
+ RX_TCP_ACK_NO_D => TCP001_RX_ACK_NOxNTCPSTREAMS,
+ TX_STREAM_SEL => TCP001_TX_STREAM_SEL,
+ TX_PAYLOAD_RTS => TCP001_TX_PAYLOAD_RTS,
+ TX_PAYLOAD_SIZE => TCP001_TX_PAYLOAD_SIZE,
+ CONNECTED_FLAG => TCP001_CONNECTED_FLAG,
+ TP => TP_TCP_SERVER
+ );
+ TCP_CONNECTED_FLAG <= TCP001_CONNECTED_FLAG;
+
+ -- assemble tx packet (MAC/IP/TCP)
+ TCP_TX_001: TCP_TX_10G
+ GENERIC MAP(
+ MSSv4 => MTU-40, -- 40byte header for IPv4/TCP
+ MSSv6 => MTU-60, -- 60byte header for IPv6/TCP
+ IPv6_ENABLED => IPv6_ENABLED
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET4,
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv6_ADDR => IPv6_ADDR,
+ TX_PACKET_SEQUENCE_START => TCP001_TX_PACKET_SEQUENCE_START,
+ TX_DEST_MAC_ADDR_IN => TCP001_TX_DEST_MAC_ADDR,
+ TX_DEST_IP_ADDR_IN => TCP001_TX_DEST_IP_ADDR,
+ TX_DEST_PORT_NO_IN => TCP001_TX_DEST_PORT_NO,
+ TX_SOURCE_PORT_NO_IN => TCP001_TX_SOURCE_PORT_NO,
+ TX_IPv4_6n_IN => TCP001_TX_IPv4_6n,
+ TX_SEQ_NO_IN => TCP001_TX_SEQ_NO,
+ TX_ACK_NO_IN => TCP001_TX_ACK_NO,
+ TX_ACK_WINDOW_LENGTH_IN => TCP001_TX_ACK_WINDOW_LENGTH,
+ IP_ID_IN => std_logic_vector(IP_ID),
+ TX_FLAGS_IN => TCP001_TX_FLAGS,
+ TX_PACKET_TYPE_IN => TCP001_TX_PACKET_TYPE,
+ TX_PAYLOAD_DATA => TCP001_TX_PAYLOAD_DATA,
+ TX_PAYLOAD_DATA_VALID => TCP001_TX_PAYLOAD_DATA_VALID,
+ TX_PAYLOAD_WORD_VALID => TCP001_TX_PAYLOAD_WORD_VALID,
+ TX_PAYLOAD_DATA_EOF => TCP001_TX_PAYLOAD_DATA_EOF,
+ TX_PAYLOAD_RTS => TCP001_TX_PAYLOAD_RTS,
+ TX_PAYLOAD_CTS => TCP001_TX_PAYLOAD_CTS,
+ TX_PAYLOAD_SIZE => TCP001_TX_PAYLOAD_SIZE,
+ TX_PAYLOAD_CHECKSUM => TCP001_TX_PAYLOAD_CHECKSUM,
+ MAC_TX_DATA => TCP001_MAC_TX_DATA,
+ MAC_TX_DATA_VALID => TCP001_MAC_TX_DATA_VALID,
+ MAC_TX_EOF => TCP001_MAC_TX_EOF,
+ MAC_TX_CTS => TCP001_MAC_TX_CTS,
+ TP => open
+ );
+
+ TCP_TXBUF_001: TCP_TXBUF_10G
+ GENERIC MAP(
+ NTCPSTREAMS => NTCPSTREAMS,
+ MSS => MTU-60, -- 40byte header for IPv4/TCP but 60byte header for IPv6/TCP
+ ADDR_WIDTH => 12, -- elastic buffer size as 64b * 2^ADDR_WIDTH, max value: 12
+ TX_IDLE_TIMEOUT => TX_IDLE_TIMEOUT,
+ SIMULATION => SIMULATION
+ )
+ PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET4,
+ TICK_4US => TICK_4US,
+ -- application interface -------
+ APP_DATA => TCP_TX_DATA,
+ APP_DATA_VALID => TCP_TX_DATA_VALID,
+ APP_CTS => TCP001_TCP_TX_CTS,
+ APP_DATA_FLUSH => TCP_TX_DATA_FLUSH,
+ -- TCP_SERVER interface -------
+ EFF_RX_WINDOW_SIZE_PARTIAL_IN => TCP001_EFF_RX_WINDOW_SIZE_PARTIAL,
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM => TCP001_EFF_RX_WINDOW_SIZE_PARTIAL_STREAM,
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID => TCP001_EFF_RX_WINDOW_SIZE_PARTIAL_VALID,
+ TX_SEQ_NO_IN => TCP001_TX_SEQ_NOxNTCPSTREAMS,
+ TX_SEQ_NO_JUMP => TCP001_TX_SEQ_NO_JUMP,
+ RX_TCP_ACK_NO_D => TCP001_RX_ACK_NOxNTCPSTREAMS,
+ CONNECTED_FLAG => TCP001_CONNECTED_FLAG,
+ TX_STREAM_SEL => TCP001_TX_STREAM_SEL,
+ -- TCP_TX interface -------
+ TX_PAYLOAD_DATA => TCP001_TX_PAYLOAD_DATA,
+ TX_PAYLOAD_DATA_VALID => TCP001_TX_PAYLOAD_DATA_VALID,
+ TX_PAYLOAD_WORD_VALID => TCP001_TX_PAYLOAD_WORD_VALID,
+ TX_PAYLOAD_DATA_EOF => TCP001_TX_PAYLOAD_DATA_EOF,
+ TX_PAYLOAD_RTS => TCP001_TX_PAYLOAD_RTS,
+ TX_PAYLOAD_CTS => TCP001_TX_PAYLOAD_CTS,
+ TX_PAYLOAD_SIZE => TCP001_TX_PAYLOAD_SIZE,
+ TX_PAYLOAD_CHECKSUM => TCP001_TX_PAYLOAD_CHECKSUM,
+ TP => TP_TCP_TXBUF
+ );
+ TCP_TX_CTS <= TCP001_TCP_TX_CTS;
+
+ TCP_RXBUFNDEMUX2_001: TCP_RXBUFNDEMUX2_10G
+ GENERIC MAP(
+ NTCPSTREAMS => NTCPSTREAMS,
+ ADDR_WIDTH => 12 -- elastic buffers size as 64b * 2^ADDR_WIDTH, MAX=12
+ )
+ PORT MAP(
+ SYNC_RESET => SYNC_RESET3,
+ CLK => CLK,
+ RX_DATA => TCP001_RX_DATA,
+ RX_DATA_VALID => TCP001_RX_DATA_VALID,
+ RX_SOF => TCP001_RX_SOF,
+ RX_TCP_STREAM_SEL => TCP001_RX_TCP_STREAM_SEL,
+ RX_EOF => TCP001_RX_EOF,
+ RX_FRAME_VALID => TCP_001_RX_FRAME_VALID,
+ RX_FREE_SPACE => TCP001_RX_FREE_SPACE,
+ RX_BUF_CLR => (others => '0'), -- TODO CLEAR ELASTIC BUFFERS AFTER CLOSING CONNECTION. BY APP???
+ RX_APP_RTS => TCP_RX_RTS,
+ RX_APP_DATA => TCP_RX_DATA,
+ RX_APP_DATA_VALID => TCP_RX_DATA_VALID,
+ RX_APP_CTS => TCP_RX_CTS,
+ RX_APP_CTS_ACK => TCP_RX_CTS_ACK,
+ TP => open
+ );
+end generate;
+
+
+--//-- IP ID generation
+-- Increment IP ID every time an IP datagram is sent
+IP_ID_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET2 = '1') then
+ IP_ID <= (others => '0');
+ elsif(TCP001_MAC_TX_EOF = '1') or (UDP_TX_EOF = '1') or (DHCPS_MAC_TX_EOF = '1') or (IGMP_MAC_TX_EOF = '1') then
+ -- increment every time an IP packet is send (or a commitment to send is made, in the case of UDP)
+ -- Adjust as needed when other IP/UDP/TCP components are instantiated
+ IP_ID <= IP_ID + 1;
+ end if;
+ end if;
+end process;
+
+--
+--//-- TRANSMISSION ARBITER --------------
+-- determines the source for the next packet to be transmitted.
+-- State machine to prevent overlapping between two packets ready...
+-- For example, one has to wait until a UDP packet has completed transmission
+-- before starting to send a TCP packet.
+TX_MUX_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET2 = '1') then
+ TX_MUX_STATE <= 0; -- idle
+ elsif(TX_MUX_STATE = 0) then
+ if (MAC_TX_CTS = '1') then
+ -- from idle to ...
+ if(ARP_RTS = '1') then
+ TX_MUX_STATE <= 1; -- enable ARP response
+ elsif(PING_RTS = '1') then
+ TX_MUX_STATE <= 2; -- enable PING response
+ elsif(TCP001_RTS = '1') and (NTCPSTREAMS /= 0) then
+ TX_MUX_STATE <= 3; -- enable TCP001 transmission
+ elsif(WHOIS_RTS = '1') and (NUDPTX /= 0) then
+ TX_MUX_STATE <= 4; -- enable WHOIS transmission
+ elsif(UDP001_RTS = '1') and (NUDPTX /= 0) then
+ TX_MUX_STATE <= 5; -- enable UDP001 transmission (duplicate as needed)
+ elsif(IGMP_RTS = '1') and (IGMP_EN = '1') and (NUDPTX /= 0) then
+ TX_MUX_STATE <= 6; -- enable IGMP message transmission
+ elsif(ICMPV6_RTS = '1') and (IPv6_ENABLED = '1') then
+ TX_MUX_STATE <= 7; -- enable ICMPv6 message transmission--
+ elsif(DHCPS_RTS = '1') and (DHCP_SERVER_EN = '1') and (DHCP_SERVER_EN2 = '1')then
+ TX_MUX_STATE <= 8; -- enable DHCP server message transmission--
+ elsif(DHCPC_RTS = '1') and (DHCP_CLIENT_EN = '1') and (DYNAMIC_IPv4 = '1')then
+ TX_MUX_STATE <= 9; -- enable DHCP client message transmission--
+ -- elsif(TCP002_RTS = '1') and (NTCPSTREAMS /= 0) then
+ -- TX_MUX_STATE <= 10; -- enable TCP002 transmission
+ end if;
+ end if;
+ else
+ -- Done transmitting. go from ... to idle
+ if((TX_MUX_STATE = 1) and (ARP_MAC_TX_EOF = '1')) or
+ ((TX_MUX_STATE = 2) and (PING_MAC_TX_EOF = '1')) or
+ ((TX_MUX_STATE = 3) and (TCP001_MAC_TX_EOF = '1')) or -- (duplicate as needed)]
+ ((TX_MUX_STATE = 4) and (WHOIS_MAC_TX_EOF = '1')) or
+ ((TX_MUX_STATE = 5) and (UDP001_MAC_TX_EOF = '1')) or -- (duplicate as needed)]
+ ((TX_MUX_STATE = 6) and (IGMP_MAC_TX_EOF = '1')) or
+ ((TX_MUX_STATE = 7) and (ICMPV6_MAC_TX_EOF = '1') and (IPv6_ENABLED = '1')) or
+ ((TX_MUX_STATE = 8) and (DHCPS_MAC_TX_EOF = '1')) or
+ ((TX_MUX_STATE = 9) and (DHCPC_MAC_TX_EOF = '1')) then
+ --((TX_MUX_STATE = 10) and (TCP002_MAC_TX_EOF = '1') or
+ TX_MUX_STATE <= 0; -- idle
+ end if;
+ end if;
+ end if;
+end process;
+
+MAC_TX_RTS <= ARP_RTS or PING_RTS or TCP001_RTS or WHOIS_RTS or UDP001_RTS or IGMP_RTS or ICMPV6_RTS or DHCPS_RTS;
+
+TX_MUX_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ case(TX_MUX_STATE) is
+ when (1) =>
+ MAC_TX_DATA_local <= ARP_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= ARP_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= ARP_MAC_TX_EOF;
+ when (2) =>
+ MAC_TX_DATA_local <= PING_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= PING_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= PING_MAC_TX_EOF;
+ when (3) =>
+ MAC_TX_DATA_local <= TCP001_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= TCP001_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= TCP001_MAC_TX_EOF;
+ when (4) =>
+ MAC_TX_DATA_local <= WHOIS_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= WHOIS_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= WHOIS_MAC_TX_EOF;
+ when (5) =>
+ MAC_TX_DATA_local <= UDP001_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= UDP001_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= UDP001_MAC_TX_EOF;
+ when (6) =>
+ MAC_TX_DATA_local <= IGMP_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= IGMP_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= IGMP_MAC_TX_EOF;
+ when (7) =>
+ MAC_TX_DATA_local <= ICMPV6_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= ICMPV6_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= ICMPV6_MAC_TX_EOF;
+ when (8) =>
+ MAC_TX_DATA_local <= DHCPS_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= DHCPS_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= DHCPS_MAC_TX_EOF;
+ when (9) =>
+ MAC_TX_DATA_local <= DHCPC_MAC_TX_DATA;
+ MAC_TX_DATA_VALID_local <= DHCPC_MAC_TX_DATA_VALID;
+ MAC_TX_EOF_local <= DHCPC_MAC_TX_EOF;
+-- when (10) =>
+-- MAC_TX_DATA_local <= TCP002_MAC_TX_DATA;
+-- MAC_TX_DATA_VALID_local <= TCP002_MAC_TX_DATA_VALID;
+-- MAC_TX_EOF_local <= TCP002_MAC_TX_EOF;
+ when others =>
+ MAC_TX_DATA_local <= (others => '0');
+ MAC_TX_DATA_VALID_local <= (others => '0');
+ MAC_TX_EOF_local <= '0';
+ end case;
+ end if;
+end process;
+MAC_TX_WORD_VALID <= '1' when (unsigned(MAC_TX_DATA_VALID_local) /= 0) else '0';
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+--//-- FLIP TX BYTE ORDER IN WORD --------------
+-- flipping the MSB <-> LSB makes it easier to read the various fields values in this code or simulator
+FLIP_TX_MAC_BYTES: process(MAC_TX_DATA_local, MAC_TX_DATA_VALID_local)
+begin
+ FOR I in 0 to 7 loop
+ MAC_TX_DATA(I*8+7 downto I*8) <= MAC_TX_DATA_local((7-I)*8+7 downto (7-I)*8);
+ MAC_TX_DATA_VALID(I) <= MAC_TX_DATA_VALID_local(7-I);
+ end loop;
+end process;
+
+-- reconstruct a SOF pulse for local loopback
+SOF_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET2 = '1') then
+ MAC_TX_EOF_FLAGn <= '0';
+ elsif(MAC_TX_EOF_local = '1') then
+ MAC_TX_EOF_FLAGn <= '0';
+ elsif(MAC_TX_WORD_VALID = '1') then
+ MAC_TX_EOF_FLAGn <= '1';--
+
+ end if;
+ end if;
+end process;
+MAC_TX_EOF_FLAG <= not MAC_TX_EOF_FLAGn;
+MAC_TX_SOF <= '1' when (MAC_TX_WORD_VALID = '1') and (MAC_TX_EOF_FLAG = '1') else '0';
+
+-- Route "Clear To Send" signal from the MAC to the proper protocol component
+ARP_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 1) else '0';
+PING_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 2) else '0';
+TCP001_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 3) else '0';
+WHOIS_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 4) else '0';
+UDP001_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 5) else '0';
+IGMP_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 6) else '0';
+ICMPV6_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 7) else '0';
+DHCPS_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 8) else '0';
+DHCPC_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 9) else '0';
+--TCP002_MAC_TX_CTS <= MAC_TX_CTS when (TX_MUX_STATE = 10) else '0';
+
+
+--//-- ROUTING TABLE ARBITER --------------
+-- Since several components could send simultaneous routing (RT) requests, one must
+-- determine who can access the routing table next
+RT_MUX_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET2 = '1') then
+ RT_MUX_STATE <= 0; -- idle
+ elsif(RT_MUX_STATE = 0) then
+ -- from idle to ...
+ if(UDP001_RT_REQ_RTS = '1') then
+ RT_MUX_STATE <= 1; -- gives UDP001 access to the routing table
+-- elsif(UDP002_RT_REQ_RTS = '1') then
+-- RT_MUX_STATE <= 2; -- gives UDP002 access to the routing table
+-- elsif(UDP003_RT_REQ_RTS = '1') then
+-- RT_MUX_STATE <= 3; -- gives UDP003 access to the routing table
+ end if;
+
+ -- Routing table transaction complete. go back to idle
+ elsif (RT_MAC_RDY = '1') or (RT_NAK = '1') then
+ RT_MUX_STATE <= 0; -- idle
+ end if;
+ end if;
+end process;
+
+RT_MUX_002: process(RT_MUX_STATE, UDP001_RT_IP_ADDR, UDP001_RT_IPv4_6n, UDP001_RT_REQ_RTS)
+begin
+ case(RT_MUX_STATE) is
+ when (1) =>
+ RT_IP_ADDR <= UDP001_RT_IP_ADDR;
+ RT_IPv4_6n <= UDP001_RT_IPv4_6n;
+ RT_REQ_RTS <= UDP001_RT_REQ_RTS;
+-- when (2) =>
+-- RT_IP_ADDR <= UDP002_RT_IP_ADDR;
+-- --when (3) =>
+-- RT_IP_ADDR <= UDP003_RT_IP_ADDR;
+-- etc...
+ when others =>
+ RT_IP_ADDR <= (others => '0');
+ RT_IPv4_6n <= '0';
+ RT_REQ_RTS <= '0';
+ end case;
+end process;
+
+UDP001_RT_REQ_CTS <= RT_CTS when (RT_MUX_STATE = 1) else '0';
+--UDP002_RT_REQ_CTS <= RT_CTS when (RT_MUX_STATE = 2) else '0';
+--UDP003_RT_REQ_CTS <= RT_CTS when (RT_MUX_STATE = 3) else '0';
+-- etc...
+
+UDP001_RT_MAC_RDY <= RT_MAC_RDY when (RT_MUX_STATE = 1) else '0';
+--UDP002_RT_MAC_RDY <= RT_MAC_RDY when (RT_MUX_STATE = 2) else '0';
+--UDP003_RT_MAC_RDY <= RT_MAC_RDY when (RT_MUX_STATE = 3) else '0';
+-- etc...
+
+UDP001_RT_NAK <= RT_NAK when (RT_MUX_STATE = 1) else '0';
+--UDP002_RT_NAK <= RT_NAK when (RT_MUX_STATE = 2) else '0';
+--UDP003_RT_NAK <= RT_NAK when (RT_MUX_STATE = 3) else '0';
+-- etc...
+
+--//-- TEST POINTS
+
+
+--TP_001: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(TCP001_TX_PAYLOAD_DATA(7 downto 0) = x"21") then
+-- TP(1) <= '1';
+-- else
+-- TP(1) <= '0';
+-- end if;
+-- TP(2) <= TCP001_TX_PAYLOAD_DATA_EOF;
+-- TP(3) <= TCP001_TX_PAYLOAD_RTS;
+-- TP(4) <= TCP001_TX_PAYLOAD_CTS;
+-- TP(5) <= TCP001_MAC_TX_EOF;
+-- TP(6) <= MAC_TX_EOF_local;
+--
+--
+---- TP(5) <= VALID_UDP_CHECKSUM;
+---- TP(6) <= IP_PAYLOAD_DATA_VALID(7);
+---- TP(7) <= IP_PAYLOAD_SOF;
+---- TP(8) <= IP_PAYLOAD_EOF;
+---- TP(9) <= IP_RX_FRAME_VALID;
+---- TP(10) <= IP_RX_EOF;
+-- end if;
+--end process;
+
+--TP(1) <= UDP001_RTS;
+--TP(2) <= UDP001_MAC_TX_CTS;
+--TP(3) <= UDP001_MAC_TX_DATA_VALID(7);
+--TP(4) <= UDP001_MAC_TX_EOF;
+
+
+
+--TP(1) <= '1' when (TX_MUX_STATE=1) else '0'; -- arp
+--TP(2) <= '1' when (TX_MUX_STATE=2) else '0'; -- ping
+----TP(3) <= '1' when (TX_MUX_STATE=3) else '0'; -- TCP
+--TP(3) <= '1' when (TX_MUX_STATE=4) else '0'; -- whois
+--TP(4) <= '1' when (TX_MUX_STATE=5) else '0'; -- udp tx
+--TP(6) <= '1' when (TX_MUX_STATE=0) else '0'; -- IDLE
+--TP(7) <= ARP_RTS;
+--TP(8) <= PING_RTS;
+--TP(9) <= UDP001_RTS;
+--
+----TP(5) <= '1' when (TX_MUX_STATE=5) else '0'; -- udp tx
+----TP(5) <= UDP_TX_DATA_VALID;
+----TP(6) <= UDP_TX_ACK_local;
+----TP(7) <= UDP_TX_NAK_local;
+----TP(8) <= WHOIS_START;
+----TP(9) <= RT_REQ_RTS;
+----TP(10) <= RT_MAC_RDY;
+--
+----TP(1) <= IGMP_TRIGGER_RESPONSE;
+----TP(2) <= IGMP_TRIGGER_RESPONSE2;
+----TP(3) <= IGMP_REPORT_START;
+----TP(4) <= TICK_100MS_MAC;
+----TP(5) <= TICK_CNTR(0);
+----TP(6) <= TICK_CNTR(5);
+----TP(7) <= IGMP_MAC_TX_CTS;
+----TP(8) <= IGMP_MAC_TX_DATA_VALID;
+----TP(9) <= IGMP_MAC_TX_EOF;
+
+TP <= TP_TCP_SERVER;
+
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/com5502pkg.vhd b/generic_ip/third_party_ip/tcp_server/src/com5502pkg.vhd
new file mode 100644
index 0000000..8e533a2
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/com5502pkg.vhd
@@ -0,0 +1,57 @@
+-------------------------------------------------------------
+-- MSS copyright 2011-2018
+-- Filename: com5502pkg.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 1
+-- Date last modified: 7/20/18
+-- Inheritance: com5402pkg.VHD 10/5/13
+--
+-- description: This package defines supplemental types, subtypes,
+-- constants, and functions.
+--
+-- Usage: enter the number of UDP tx and rx components, the number of TCP servers and the number of TCP clients.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.all;
+use ieee.numeric_std.all;
+
+package com5502pkg is
+
+ --// TCP STREAMS -----------------------------------------------------
+ constant NTCPSTREAMS_MAX: integer range 0 to 255 := 1;
+ -- MAXIMUM number of concurrent TCP streams handled by this component
+ -- MUST BE >= NTCPSTREAM in the generic section of COM5502/COM5503
+ -- limitation: <= 255 streams (some integer to 8-bit slv conversions in the memory pointers)
+ -- In practice, the number of concurrent TCP streams per instantiated server is quite small as timing
+ -- gets worse. If a large number of concurrent TCP streams is needed, it may be better to create
+ -- multiple instantiations of the TCP_SERVER, each with a limited number of concurrent streams.
+ type SLV128xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(127 downto 0);
+ type SLV64xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(63 downto 0);
+ type SLV32xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(31 downto 0);
+ type SLV24xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(23 downto 0);
+ type SLV20xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(19 downto 0);
+ type SLV16xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(15 downto 0);
+ type SLV17xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(16 downto 0);
+ type SLV9xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(8 downto 0);
+ type SLV8xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(7 downto 0);
+ type SLV4xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(3 downto 0);
+ type SLV2xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of std_logic_vector(1 downto 0);
+
+ type U64xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(63 downto 0);
+ type U32xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(31 downto 0);
+ type U24xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(23 downto 0);
+ type U17xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(16 downto 0);
+ type U16xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(15 downto 0);
+ type U8xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(7 downto 0);
+ type U4xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(3 downto 0);
+ type U2xNTCPSTREAMStype is array (integer range 0 to (NTCPSTREAMS_MAX-1)) of unsigned(1 downto 0);
+
+
+end com5502pkg;
+
+package body com5502pkg is
+-- Future use
+
+
+end com5502pkg;
+
diff --git a/generic_ip/third_party_ip/tcp_server/src/dhcp_client_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/dhcp_client_10G.vhd
new file mode 100644
index 0000000..e90d2b9
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/dhcp_client_10G.vhd
@@ -0,0 +1,1028 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: DHCP_CLIENT.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 5/3/19
+-- Inheritance: DHCP_CLIENT.VHD 6/25/16
+--
+-- description:
+-- DHCP client (on-top of UDP_TX and UDP_RX). 10G version.
+-- Based on RFC2131
+-- This client asks DHCP servers for an IP address and network information such as gateway, subnet mask and DNS address.
+--
+-- Limitations:
+-- Client and server are on the same subnet (no relay)
+--
+-- Usage:
+-- 1. A DHCP client can be instantiated (using the DHCP_CLIENT_EN generic parameter in COM540X.vhd), but still
+-- enabled/disabled dynamically at run-time using the SYNC_RESET input. Set SYNC_RESET to '1' to disable this server.
+-- 2. Proposed IP address is always on the same subnet as this server (i.e. same 1/2/3 MSBs as this server IPv4_ADDR)
+-- 4. Limited to 6-byte (Ethernet) hardware addressing
+--
+-- Device utilization
+-- FF: 1263
+-- LUT: 1216
+-- DSP48: 0
+-- 18Kb BRAM: 4
+-- BUFG: 1
+-- Minimum period: 6.414ns (Maximum Frequency: 155.909MHz) Artix7-100T -1 speed grade
+
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity DHCP_CLIENT_10G is
+ generic (
+ SIMULATION: std_logic := '0'
+ -- 1 during simulation otherwise timers are way too long for practical VHDL simulation
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ -- set to '1' to disable the DHCP server
+ CLK: in std_logic; -- synchronous clock
+ -- Must be a global clocks. No BUFG instantiation within this component.
+ TICK_4US: in std_logic;
+ TICK_100MS : in std_logic;
+ -- 100 ms tick for timer
+
+ --// CLIENT INFO
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ LAST_IPv4_ADDR: in std_logic_vector(31 downto 0);
+ -- last IP address. This DHCP client will use it to request a new IP after power up
+ -- to maintain some consistency. Since the FPGA is generally not capable of storing
+ -- this information in non-volatile memory, some external device (microcontroller, eeprom, etc)
+ -- should be used for persistent storage (preferred, not required)
+
+ --// DHCP CLIENT CONFIGURATION: IP address, MAC address, host name
+ IPv4_ADDR: out std_logic_vector(31 downto 0);
+ -- dynamic IP address. 4 bytes for IPv4
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+ LEASE_TIME: out std_logic_vector(31 downto 0);
+ -- default lease time in secs
+ -- FFFFFF for infinite (TBC)
+ SUBNET_MASK: out std_logic_vector(31 downto 0);
+ ROUTER: out std_logic_vector(31 downto 0);
+ DNS1: out std_logic_vector(31 downto 0);
+ DNS2: out std_logic_vector(31 downto 0);
+
+ IP_ID_IN: in std_logic_vector(15 downto 0);
+ -- 16-bit IP ID, unique for each datagram. Incremented every time
+ -- an IP datagram is sent (not just for this protocol).
+
+ --// Received UDP payload
+ -- DHCP message is encapsulated within a UDP frame
+ UDP_RX_DATA: in std_logic_vector(63 downto 0);
+ -- byte order: MSB first (reason: easier to read contents during simulation)
+ UDP_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ UDP_RX_SOF: in std_logic;
+ UDP_RX_EOF: in std_logic;
+ -- 1 CLK pulse indicating that UDP_RX_DATA is the last word in the UDP data field.
+ -- ALWAYS CHECK UDP_RX_FRAME_VALID at the end of packet (UDP_RX_EOF = '1') to confirm
+ -- that the UDP packet is valid. External buffer may have to backtrack to the the last
+ -- valid pointer to discard an invalid UDP packet.
+ -- Reason: we only knows about bad UDP packets at the end.
+ UDP_RX_FRAME_VALID: in std_logic;
+ -- check entire frame validity at UDP_RX_EOF
+ UDP_RX_DEST_PORT_NO: in std_logic_vector(15 downto 0);
+ -- Identify the destination UDP port. Read when UDP_RX_EOF = '1'
+
+ RX_SOURCE_IP_ADDR: in std_logic_vector(31 downto 0);
+
+ --// OUTPUT: TX UDP layer -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended by MAC. Not supplied here.
+ MAC_TX_DATA: out std_logic_vector(63 downto 0) := (others => '0');
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID /= 0
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0) := (others => '0');
+ -- data valid
+ MAC_TX_EOF: out std_logic := '0';
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal. The user should check that this
+ -- signal is high before sending the next MAC_TX_DATA byte.
+ RTS: out std_logic := '0';
+ -- '1' when a frame is ready to be sent (tell the COM5402 arbiter)
+ -- When the MAC starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+ --// TEST POINTS
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of DHCP_CLIENT_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+
+ COMPONENT UDP_TX_10G
+ generic (
+ ADDR_WIDTH: integer;
+ UDP_CKSUM_ENABLED: std_logic;
+ IPv6_ENABLED: std_logic
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ TICK_4US: in std_logic;
+ APP_DATA : IN std_logic_vector(63 downto 0);
+ APP_DATA_VALID : IN std_logic_vector(7 downto 0);
+ APP_SOF : IN std_logic;
+ APP_EOF : IN std_logic;
+ APP_CTS : OUT std_logic;
+ DEST_IP_ADDR: in std_logic_vector(127 downto 0);
+ IPv4_6n: in std_logic;
+ DEST_PORT_NO : IN std_logic_vector(15 downto 0);
+ SOURCE_PORT_NO : IN std_logic_vector(15 downto 0);
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ IP_ID: in std_logic_vector(15 downto 0);
+ ACK : OUT std_logic;
+ NAK : OUT std_logic;
+ RT_IP_ADDR : OUT std_logic_vector(127 downto 0);
+ RT_IPv4_6n: out std_logic;
+ RT_REQ_RTS: out std_logic;
+ RT_REQ_CTS: in std_logic;
+ RT_MAC_REPLY : IN std_logic_vector(47 downto 0);
+ RT_MAC_RDY : IN std_logic;
+ RT_NAK: in std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ MAC_TX_CTS : IN std_logic;
+ RTS: out std_logic := '0';
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+--// RESET ------------------------------------
+signal SYNC_RESET_local: std_logic := '0';
+
+--// RANDOM GENERATOR ------------------------------------
+signal RANDOM_NO: std_logic_vector(47 downto 0) := (others => '0');
+signal RANDOM_NO_REQ: std_logic := '0';
+
+--// TIME ------------------------------------------------
+signal TIMER1: unsigned(7 downto 0) := (others => '0');
+signal TIMER2: unsigned(7 downto 0) := (others => '0');
+constant DISCOVER_RETRANSMIT: unsigned(TIMER1'left downto 0) := to_unsigned(40,TIMER1'length); -- 4s
+constant COLLECT_DHCPOFFERS: unsigned(TIMER1'left downto 0) := to_unsigned(20,TIMER1'length); -- 2s
+constant AWAIT_DHCPACK: unsigned(TIMER1'left downto 0) := to_unsigned(20,TIMER1'length); -- 2s
+signal TIME_CNTR: unsigned(15 downto 0) := (others => '0');
+signal CNTR10: unsigned(3 downto 0) := (others => '0');
+signal TIME_CNTR_AT_DHCPDISCOVER: std_logic_vector(15 downto 0) := (others => '0');
+signal LEASE_TIMER: unsigned(31 downto 0) := (others => '0');
+
+--// UDP RX frame ---------------------------------------
+signal VALID_UDP_DEST_PORT: std_logic := '0';
+signal DHCP_RX_WORD_COUNT: unsigned(6 downto 0) := (others => '0');
+signal DHCP_RX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCP_RX_DATA_D: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCP_RX_DATA_D_FLIPPED: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCP_RX_DATA_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal DHCP_RX_DATA_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal DHCP_RX_SOF: std_logic := '0';
+signal DHCP_RX_SOF_D: std_logic := '0';
+signal DHCP_RX_EOF: std_logic := '0';
+signal DHCP_RX_EOF_D: std_logic := '0';
+signal DHCP_RX_WORD_VALID: std_logic := '0';
+signal DHCP_RX_WORD_VALID_D: std_logic := '0';
+
+signal XID: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_XID: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_FLAGS: std_logic_vector(15 downto 0) := (others => '0');
+signal RX_CIADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_YIADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_GIADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_CLIENT_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal RX_MAGIC_COOKIE: std_logic_vector(31 downto 0) := (others => '0');
+constant MAGIC_COOKIE: std_logic_vector(31 downto 0) := x"63825363";
+-- word to byte serialization
+signal DHCP_RX_BYTE_COUNT: unsigned(9 downto 0) := (others => '1');
+signal BUF1_SIZE: unsigned(9 downto 0) := (others => '0');
+signal DHCP_RX_DATA2_VALID_E: std_logic := '0';
+signal DHCP_RX_DATA2_VALID: std_logic := '0';
+signal DHCP_RX_DATA2: std_logic_vector(7 downto 0) := (others => '0');
+signal DHCP_READ_STATE: integer range 0 to 3 := 0;
+signal DHCP_RX_EOF2: std_logic := '0';
+signal DHCP_RX_EOF2_D: std_logic := '0';
+signal DHCP_OPTION: unsigned(7 downto 0) := (others => '0');
+signal DHCP_MESSAGE_LENGTH: unsigned(7 downto 0) := (others => '0');
+signal DHCP_MESSAGE: std_logic_vector(95 downto 0) := (others => '0');
+signal DHCP_MESSAGE_TYPE: unsigned(3 downto 0) := (others => '0');
+signal DHCP_SERVER_IP_ADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_IP_ADDR_LEASE_TIME: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_SUBNET_MASK: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_ROUTER: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_DNS1: std_logic_vector(31 downto 0) := (others => '0');
+signal RX_DNS2: std_logic_vector(31 downto 0) := (others => '0');
+
+signal RX_VALID: std_logic := '0';
+signal RECEIVED_DHCPOFFERS: std_logic := '0';
+signal BEST_DHCP_SERVER_IP_ADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal BEST_RX_YIADDR: std_logic_vector(31 downto 0) := (others => '0');
+
+signal EVENT1: std_logic := '0';
+signal EVENT2: std_logic := '0';
+signal EVENT3: std_logic := '0';
+signal EVENT4: std_logic := '0';
+signal EVENT5: std_logic := '0';
+signal STATE: integer range 0 to 15 := 0;
+signal IPv4_ADDR_local: std_logic_vector(31 downto 0) := (others => '0');
+
+--//-- COMPOSE REPLY --------------------------
+signal DEST_IPv4_ADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal DEST_IPv4_ADDRx: std_logic_vector(127 downto 0) := (others => '0');
+signal DEST_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal WPTR: unsigned(6 downto 0) := (others => '0'); -- maximum size 576Bytes or 73 Words
+signal UDP_TX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal UDP_TX_DATA_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal UDP_TX_SOF: std_logic := '0';
+signal UDP_TX_EOF: std_logic := '0';
+signal UDP_TX_CTS: std_logic := '0';
+signal UDP_TX_ACK_local: std_logic := '0';
+signal UDP_TX_NAK_local: std_logic := '0';
+signal MAC_TX_EOF_local: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// RESET ------------------------------------
+-- we must hold the DHCP client in internal reset until the MAC_ADDR is defined.
+RESET_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(unsigned(MAC_ADDR) = 0) then
+ SYNC_RESET_local <= '1';
+ else
+ SYNC_RESET_local <= SYNC_RESET;
+ end if;
+ end if;
+end process;
+
+--// RANDOM GENERATOR ------------------------------------
+-- The DHCP protocol requires random delays (for example for sending the first DHCPDISCOVER message).
+-- We use the MAC address as seed.
+RANDOM_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET_local = '1') then
+ RANDOM_NO <= MAC_ADDR(47 downto 0);
+ elsif(RANDOM_NO_REQ = '1') then
+ -- for every subsequent request, get a new random number
+ RANDOM_NO(47 downto 1) <= RANDOM_NO(46 downto 0);
+ RANDOM_NO(0) <= ((RANDOM_NO(47) xnor RANDOM_NO(46)) xnor RANDOM_NO(20)) xnor RANDOM_NO(19); -- Xilinx XAPP 052
+ end if;
+ end if;
+end process;
+
+-- request next random number: events triggering a new draw
+RANDOM_GEN_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET_local = '1') then
+ RANDOM_NO_REQ <= '0';
+ elsif(STATE = 0) then
+ -- 1st draw.. random delay before sending DHCPDISCOVER
+ RANDOM_NO_REQ <= '1';
+ elsif(STATE = 1) then
+ -- multiple draws before selecting XID
+ RANDOM_NO_REQ <= '1';
+ elsif(STATE = 3) and (WPTR = 0) then
+ -- pick a new XID for each DHCPDISCOVER restart
+ RANDOM_NO_REQ <= '1';
+ else
+ RANDOM_NO_REQ <= '0';
+ end if;
+ end if;
+end process;
+
+--// TIME ------------------------------------------------
+-- track relative time in secs.
+TIME_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') then
+ TIME_CNTR <= (0 => '1', others => '0');
+ CNTR10 <= (others => '0');
+ elsif(TICK_100MS = '1') then
+ if(CNTR10 = 9) then
+ -- TIME_CNTR units = seconds
+ CNTR10 <= (others => '0');
+ TIME_CNTR <= TIME_CNTR + 1;
+ else
+ CNTR10 <= CNTR10 + 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- Freeze time value upon sending DHCPDISCOVER (same value MUST be used in DHCPREQUEST)
+TIME_GEN_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(STATE = 3) and (WPTR = 0) then
+ -- start of DHCPDISCOVER
+ TIME_CNTR_AT_DHCPDISCOVER <= std_logic_vector(TIME_CNTR);
+ end if;
+ end if;
+end process;
+
+-- lease time countdown
+TIME_GEN_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET_local = '1') then
+ LEASE_TIMER <= (others => '0');
+ elsif (STATE = 9) and (EVENT3 = '1') then
+ -- lease time defined
+ if(SIMULATION = '0') then
+ LEASE_TIMER <= unsigned(RX_IP_ADDR_LEASE_TIME);
+ else
+ -- test fast expiration
+ LEASE_TIMER <= x"00000010";
+ end if;
+ elsif(TICK_100MS = '1') and (CNTR10 = 9) and (LEASE_TIMER /= 0) then
+ -- LEASE_TIMER units = seconds
+ LEASE_TIMER <= LEASE_TIMER - 1;
+ end if;
+ end if;
+end process;
+
+--// UDP RX frame ---------------------------------------
+-- DHCP is encapsulated within a UDP frame
+-- verify UDP destination port is 68 (x0044) DHCP client port
+VALID_UDP_DEST_PORT <= '1' when (UDP_RX_DEST_PORT_NO = x"0044") else '0';
+DHCP_RX_DATA <= UDP_RX_DATA;
+DHCP_RX_DATA_VALID <= UDP_RX_DATA_VALID when (VALID_UDP_DEST_PORT = '1') else x"00";
+DHCP_RX_SOF <= UDP_RX_SOF and VALID_UDP_DEST_PORT;
+DHCP_RX_EOF <= UDP_RX_EOF and VALID_UDP_DEST_PORT;
+DHCP_RX_WORD_VALID <= '1' when (UDP_RX_DATA_VALID /= x"00") and (VALID_UDP_DEST_PORT = '1') else '0';
+
+-- keep track of the received DHCP rx pointer
+-- Pointer DHCP_RX_WORD_COUNT aligned with DHCP_RX_DATA_VALID_D
+-- DHCP message datagram can be up to 576 bytes, thus DHCP_RX_WORD_COUNT 7-bits
+DHCP_RX_BYTE_COUNT_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DHCP_RX_DATA_D <= DHCP_RX_DATA;
+ DHCP_RX_DATA_VALID_D <= DHCP_RX_DATA_VALID;
+ DHCP_RX_WORD_VALID_D <= DHCP_RX_WORD_VALID;
+ DHCP_RX_SOF_D <= DHCP_RX_SOF;
+ DHCP_RX_EOF_D <= DHCP_RX_EOF;
+
+ if(SYNC_RESET_local = '1') or (DHCP_RX_SOF = '1') then
+ DHCP_RX_WORD_COUNT <= (others => '0');
+ elsif(DHCP_RX_WORD_VALID_D = '1') then
+ if(DHCP_RX_WORD_COUNT(6) = '0') then -- max 64. should not normally happen.
+ DHCP_RX_WORD_COUNT <= DHCP_RX_WORD_COUNT + 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- capture relevant fields (only while STATE = 6)
+GET_FIELDS_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(DHCP_RX_WORD_VALID_D = '1') and (STATE = 6) then -- *062516
+ if(DHCP_RX_SOF_D = '1') then
+ -- transaction ID
+ RX_XID <= DHCP_RX_DATA_D(31 downto 0);
+ -- zero other fields
+-- RX_FLAGS <= (others => '0');
+-- RX_CIADDR <= (others => '0');
+ RX_YIADDR <= (others => '0');
+-- RX_GIADDR <= (others => '0');
+ RX_CLIENT_MAC_ADDR <= (others => '0');
+ RX_MAGIC_COOKIE <= (others => '0');
+ end if;
+-- if(DHCP_RX_WORD_COUNT = 1) then
+-- RX_FLAGS <= DHCP_RX_DATA_D(47 downto 32);
+-- RX_CIADDR <= DHCP_RX_DATA_D(31 downto 0);
+-- end if;
+ if(DHCP_RX_WORD_COUNT = 2) then
+ RX_YIADDR <= DHCP_RX_DATA_D(63 downto 32);
+ end if;
+ if(DHCP_RX_WORD_COUNT = 3) then
+ RX_GIADDR <= DHCP_RX_DATA_D(63 downto 32);
+ RX_CLIENT_MAC_ADDR(47 downto 16) <= DHCP_RX_DATA_D(31 downto 0);
+ end if;
+ if(DHCP_RX_WORD_COUNT = 4) then
+ RX_CLIENT_MAC_ADDR(15 downto 0) <= DHCP_RX_DATA_D(63 downto 48);
+ end if;
+ if(DHCP_RX_WORD_COUNT = 29) then
+ RX_MAGIC_COOKIE <= DHCP_RX_DATA_D(31 downto 0);
+ end if;
+ end if;
+ end if;
+end process;
+
+-- parse the variable-length DHCP fields, starting immediately after the magic cookie
+-- serialize word through a small (1KB) DPRAM
+-- this eases the parsing of the option fields
+-- DHCP message datagram can be up to 576 bytes
+
+-- flip LSB/MSB
+PARSE_001: process(DHCP_RX_DATA_D)
+begin
+ for I in 0 to 7 loop
+ DHCP_RX_DATA_D_FLIPPED((7-I)*8+7 downto (7-I)*8) <= DHCP_RX_DATA_D(I*8+7 downto I*8);
+ end loop;
+end process;
+
+PARSE_002 : BRAM_DP2
+generic map (
+ DATA_WIDTHA => 8,
+ ADDR_WIDTHA => 10,
+ DATA_WIDTHB => 64,
+ ADDR_WIDTHB => 7
+)
+port map(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => '0',
+ ADDRA => std_logic_vector(DHCP_RX_BYTE_COUNT),
+ DIA => (others => '0'),
+ OEA => '1',
+ DOA => DHCP_RX_DATA2, -- byte-wide
+ CSB => '1',
+ CLKB => CLK,
+ WEB => DHCP_RX_WORD_VALID_D,
+ ADDRB => std_logic_vector(DHCP_RX_WORD_COUNT),
+ DIB => DHCP_RX_DATA_D_FLIPPED,
+ OEB => '0',
+ DOB => open
+);
+
+BUF1_SIZE <= (DHCP_RX_WORD_COUNT & "000") + (not DHCP_RX_BYTE_COUNT);
+
+PARSE_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DHCP_RX_DATA2_VALID <= DHCP_RX_DATA2_VALID_E; -- 1CLK latency to read from BRAM
+
+ if(SYNC_RESET_local = '1') or (DHCP_RX_SOF = '1') then
+ DHCP_RX_BYTE_COUNT <= (others => '1');
+ DHCP_RX_DATA2_VALID_E <= '0';
+ elsif(BUF1_SIZE > 0) then
+ DHCP_RX_BYTE_COUNT <= DHCP_RX_BYTE_COUNT + 1;
+ DHCP_RX_DATA2_VALID_E <= '1';
+ else
+ DHCP_RX_DATA2_VALID_E <= '0';
+ end if;
+ end if;
+end process;
+
+-- parse the variable-length DHCP fields, starting immediately after the magic cookie
+PARSE_DHCP_FIELDS: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ DHCP_READ_STATE <= 0;
+ elsif(DHCP_RX_BYTE_COUNT = 240) then
+ -- magic cookie immediately preceeds the DHCP options
+ DHCP_READ_STATE <= 1;
+ -- clear previous option fields
+ DHCP_MESSAGE_TYPE <= (others => '0');
+ DHCP_SERVER_IP_ADDR <= (others => '0');
+ RX_IP_ADDR_LEASE_TIME <= (others => '0');
+ RX_SUBNET_MASK <= (others => '0');
+ RX_ROUTER <= (others => '0');
+ RX_DNS1 <= (others => '0');
+ RX_DNS2 <= (others => '0');
+ elsif(DHCP_RX_DATA2_VALID = '1') then
+ if(DHCP_READ_STATE = 1) then
+ if(DHCP_RX_DATA2 = x"FF") then
+ -- end of DHCP options
+ DHCP_READ_STATE <= 0;
+ else
+ DHCP_READ_STATE <= 2;
+ DHCP_OPTION <= unsigned(DHCP_RX_DATA2);
+ DHCP_MESSAGE <= (others => '0'); -- clear message field before next option
+ end if;
+ elsif(DHCP_READ_STATE = 2) then
+ DHCP_READ_STATE <= 3;
+ DHCP_MESSAGE_LENGTH <= unsigned(DHCP_RX_DATA2);
+ elsif(DHCP_READ_STATE = 3) then
+ if(DHCP_MESSAGE_LENGTH = 1) then
+ -- reached end of DHCP message
+ DHCP_READ_STATE <= 1;
+ -- save in various fields
+ if(DHCP_OPTION = 53) then
+ -- DHCP message type
+ DHCP_MESSAGE_TYPE <= unsigned(DHCP_RX_DATA2(3 downto 0)); -- 1-8
+ end if;
+ if(DHCP_OPTION = 54) then
+ -- DHCP server identifier
+ DHCP_SERVER_IP_ADDR <= DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2; -- 4 bytes
+ end if;
+ if(DHCP_OPTION = 51) then
+ -- IP address lease time
+ RX_IP_ADDR_LEASE_TIME <= DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2; -- 4 bytes
+ end if;
+ if(DHCP_OPTION = 1) then
+ -- subnet mask
+ RX_SUBNET_MASK <= DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2; -- 4 bytes
+ end if;
+ if(DHCP_OPTION = 3) then
+ -- router
+ RX_ROUTER <= DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2; -- 4 bytes
+ end if;
+ if(DHCP_OPTION = 6) then
+ -- DNS
+ if(DHCP_MESSAGE_LENGTH = 4) then -- 4 bytes: 1 DNS
+ RX_DNS1 <= DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2; -- 4 bytes
+ RX_DNS2 <= (others => '0');
+ elsif(DHCP_MESSAGE_LENGTH = 8) then -- 8 bytes: 2 DNSs
+ RX_DNS1 <= DHCP_MESSAGE(55 downto 24);
+ RX_DNS2 <= DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2;
+ end if;
+ end if;
+
+ else
+ DHCP_MESSAGE <= DHCP_MESSAGE(87 downto 0) & DHCP_RX_DATA2;
+ DHCP_MESSAGE_LENGTH <= DHCP_MESSAGE_LENGTH - 1;
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- generate an EOF on the other side of the serialization buffer
+DHCP_RX_EOF2 <= '1' when (DHCP_RX_DATA2_VALID = '1') and (DHCP_READ_STATE = 1) and (DHCP_RX_DATA2 = x"FF") else '0';
+
+-- check incoming message validity
+-- ready at DHCP_RX_EOF1_D
+VALID_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DHCP_RX_EOF2_D <= DHCP_RX_EOF2;
+
+ if(UDP_RX_SOF = '1') then
+ RX_VALID <= '1'; -- valid by default, until proven otherwise
+ elsif(UDP_RX_EOF = '1') and (UDP_RX_FRAME_VALID = '0') then
+ -- invalid UDP message
+ RX_VALID <= '0';
+ elsif(DHCP_RX_EOF2 = '1') and (RX_MAGIC_COOKIE /= x"63825363") then
+ RX_VALID <= '0';
+ elsif(DHCP_RX_EOF2 = '1') and (RX_CLIENT_MAC_ADDR /= MAC_ADDR) then
+ -- non-matching client MAC address (spoofing?)
+ RX_VALID <= '0';
+ elsif(DHCP_RX_EOF2 = '1') and (RX_XID /= XID) then
+ -- non-matching XID
+ RX_VALID <= '0';
+ end if;
+ end if;
+end process;
+
+-- select best DHCPOFFER response
+-- criteria: the one that matches LAST_IPv4_ADDR, otherwise the first response
+BEST_DHCPOFFER_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ RECEIVED_DHCPOFFERS <= '0';
+ BEST_DHCP_SERVER_IP_ADDR <= (others => '0');
+ BEST_RX_YIADDR <= (others => '0');
+ elsif(STATE = 4) and (MAC_TX_EOF_local = '1') then
+ -- sending DHCPDISCOVER
+ RECEIVED_DHCPOFFERS <= '0';
+ elsif(EVENT1 = '1') then
+ -- valid DHCPOFFER
+ RECEIVED_DHCPOFFERS <= '1';
+ if(RECEIVED_DHCPOFFERS = '0') then
+ -- first DHCPOFFER after DHCPDISCOVER
+ BEST_DHCP_SERVER_IP_ADDR <= DHCP_SERVER_IP_ADDR;
+ BEST_RX_YIADDR <= RX_YIADDR;
+ elsif(RX_YIADDR = LAST_IPv4_ADDR) then
+ -- this DHCPOFFER matches the IP address last assigned to this device. Better choice.
+ BEST_DHCP_SERVER_IP_ADDR <= DHCP_SERVER_IP_ADDR;
+ BEST_RX_YIADDR <= RX_YIADDR;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- change IP address
+CHANGE_IP_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ IPv4_ADDR_local <= (others => '0');
+ elsif(EVENT2 = '1') then
+ IPv4_ADDR_local <= BEST_RX_YIADDR;
+ end if;
+ end if;
+end process;
+
+IPv4_ADDR <= IPv4_ADDR_local;
+
+-- report DHCP client configuration to the device
+CONFIG_OUT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ LEASE_TIME <= (others => '0');
+ SUBNET_MASK <= (others => '0');
+ ROUTER <= (others => '0');
+ DNS1 <= (others => '0');
+ DNS2 <= (others => '0');
+ elsif (STATE = 9) and (EVENT3 = '1') then
+ LEASE_TIME <= RX_IP_ADDR_LEASE_TIME;
+ SUBNET_MASK <= RX_SUBNET_MASK;
+ ROUTER <= RX_ROUTER;
+ DNS1 <= RX_DNS1;
+ DNS2 <= RX_DNS2;
+ end if;
+ end if;
+end process;
+
+--//-- EVENTS ---------------------------------------------------
+
+-- 1 = valid DHCPOFFER message
+EVENT1 <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 2) and (STATE = 6) else '0';
+
+-- 2 = finished sending DHCPREQUEST. Time to change our IP address since the follow-on DHCPACK message
+-- from the DHCP server is directed to the requested IP address.
+EVENT2 <= '1' when (STATE = 8) and (MAC_TX_EOF_local = '1') else '0';
+
+-- 3 = valid DHCPACK message from the expected DHCP server after a DHCPREQUEST
+EVENT3 <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 5)
+ and (RX_SOURCE_IP_ADDR = BEST_DHCP_SERVER_IP_ADDR) else '0';
+
+-- 4 = valid DHCPNAK message from the expected DHCP server
+EVENT4 <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 6)
+ and (RX_SOURCE_IP_ADDR = BEST_DHCP_SERVER_IP_ADDR) else '0';
+
+-- 5 = lease time expired
+EVENT5 <= '1' when (LEASE_TIMER = 0) else '0';
+
+--//-- STATE MACHINE ---------------------------------------------------
+STATE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ STATE <= 0; -- INIT STATE
+ -- initialize timers
+ TIMER1 <= (others => '0');
+ TIMER2 <= (others => '0');
+ elsif(STATE = 0) and (unsigned(RANDOM_NO) /= 0) then
+ -- arm timer with random number between 0.1 - 12.6s, before sending DHCPDISCOVER
+ TIMER1(6 downto 0) <= unsigned(RANDOM_NO(6 downto 0));
+ -- request next random number
+ TIMER1(TIMER1'left downto 7) <= (others => '0');
+ STATE <= 1;
+ elsif(STATE = 1) and (TIMER1 = 0) then
+ -- at the end of the random delay
+ -- send DHCPDISCOVER.
+ STATE <= 3;
+ TIMER1 <= DISCOVER_RETRANSMIT; -- defensive. should never happen.
+ elsif(STATE = 3) and (UDP_TX_ACK_local = '1') then
+ -- composed UDP reply. UDP confirmed. awaiting MAC confirmation.
+ STATE <= 4;
+ elsif(STATE = 3) and (UDP_TX_NAK_local = '1') then
+ -- composed UDP reply. NAK from UDP_TX (abnormal).
+ -- Wait before retransmitting DHCPDISCOVER.
+ STATE <= 5;
+ TIMER1 <= DISCOVER_RETRANSMIT;
+ elsif(STATE = 4) and (MAC_TX_EOF_local = '1') then
+ -- MAC transmission completion confirmed. Awaiting DHCHOFFERs
+ -- await responses from possible multiple DHCP servers.
+ STATE <= 6;
+ TIMER1 <= COLLECT_DHCPOFFERS; -- wait to collect all DHCPOFFERs
+ elsif((STATE = 3) or (STATE = 4) or (STATE = 5)) and (TIMER1 = 0) then
+ -- retry sending DHCPDISCOVER
+ STATE <= 3; -- *062516
+ TIMER1 <= DISCOVER_RETRANSMIT; -- defensive. should rarely happen (could happen if two clients
+ -- start at the same time (the DHCP server may only handle one transaction at a time)
+ elsif(STATE = 6) and (TIMER1 = 0) then
+ if (RECEIVED_DHCPOFFERS = '1') then
+ -- collected at least one DHCPOFFER. Start sending DHCPREQUEST
+ STATE <= 7;
+ TIMER1 <= DISCOVER_RETRANSMIT; -- defensive. should never happen.
+ else
+ -- received no DHCPOFFER
+ -- Wait before retransmitting DHCPDISCOVER.
+ STATE <= 5;
+ TIMER1 <= DISCOVER_RETRANSMIT;
+ end if;
+ elsif(STATE = 7) and (UDP_TX_ACK_local = '1') then
+ -- composed UDP reply. UDP confirmed. awaiting MAC confirmation.
+ STATE <= 8;
+ elsif(STATE = 7) and (UDP_TX_NAK_local = '1') then
+ -- composed UDP reply. NAK from UDP_TX (abnormal).
+ -- Wait before retransmitting DHCPDISCOVER.
+ STATE <= 5;
+ TIMER1 <= DISCOVER_RETRANSMIT;
+ elsif(STATE = 8) and (MAC_TX_EOF_local = '1') then
+ -- MAC transmission completion confirmed. Awaiting DHCHACK
+ STATE <= 9;
+ TIMER1 <= AWAIT_DHCPACK; -- Awaiting DHCPACK
+ elsif((STATE = 7) or (STATE = 8) or (STATE = 9)) and (TIMER1 = 0) then
+ -- retry sending DHCPDISCOVER
+ STATE <= 5;
+ TIMER1 <= DISCOVER_RETRANSMIT; -- defensive. should never happen.
+ elsif (STATE = 9) and (EVENT3 = '1') then
+ -- received a valid DHCPACK
+ STATE <= 10; -- BOUND state
+ elsif (STATE = 9) and (EVENT4 = '1') then
+ -- received a valid DHCPNAK
+ -- Wait before retransmitting DHCPDISCOVER.
+ STATE <= 5;
+ TIMER1 <= DISCOVER_RETRANSMIT;
+ elsif(STATE = 9) and (TIMER1 = 0) then
+ -- timeout waiting for a valid DHCPACK
+ -- Wait before retransmitting DHCPDISCOVER.
+ STATE <= 5;
+ TIMER1 <= DISCOVER_RETRANSMIT;
+ elsif(STATE = 10) and (EVENT5 = '1') then
+ -- BOUND state, lease expired. Renew.
+ STATE <= 7;
+ TIMER1 <= DISCOVER_RETRANSMIT; -- defensive. should never happen.
+ elsif ((TICK_100MS = '1') and (SIMULATION = '0')) or ((TICK_4US = '1') and (SIMULATION = '1')) then
+ -- countdown timer until expiration (0). Accelerate during simulation.
+ if(TIMER1 /= 0) then
+ TIMER1 <= TIMER1 - 1;
+ end if;
+ if(TIMER2 /= 0) then
+ TIMER2 <= TIMER2 - 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+--//-- TRANSMIT FIELDS ------------------------------------------
+-- XID
+XID_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ XID <= (others => '0');
+ elsif(STATE = 3) and (WPTR = 0) then
+ -- pick a random ID before sending DHCPDISCOVER. Changes at each retransmission.
+ XID <= RANDOM_NO(31 downto 0);
+ end if;
+ end if;
+end process;
+
+
+--//-- COMPOSE MESSAGES TO DHCP SERVER --------------------------
+-- WPTR is a word counter for the UDP tx payload
+WPTR_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ WPTR <= (others => '0');
+ elsif(STATE = 3) or (STATE = 7) then
+ -- DHCPDISCOVER or DHCPREQUEST message
+ if(UDP_TX_CTS = '1') then
+ WPTR <= WPTR + 1;
+ end if;
+ else
+ WPTR <= (others => '0');
+ end if;
+
+ end if;
+end process;
+
+COMPOSE_TX: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET_local = '1') then
+ UDP_TX_DATA_VALID <= X"00";
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ elsif(STATE = 3) and (UDP_TX_CTS = '1') then
+ -- DHCPDISCOVER message
+ -- UDP destination IP address, broadcast
+ DEST_IPv4_ADDR <= x"FFFFFFFF";
+ DEST_MAC_ADDR <= x"FFFFFFFFFFFF";
+ if(WPTR < 32) then
+ UDP_TX_DATA_VALID <= x"FF";
+ elsif(WPTR = 32) then
+ UDP_TX_DATA_VALID <= x"C0";
+ else
+ UDP_TX_DATA_VALID <= x"00";
+ end if;
+ case WPTR is
+ when "0000000" =>
+ UDP_TX_DATA <= x"01010600" & RANDOM_NO(31 downto 0);
+ -- op: BOOTREQUEST
+ -- hardware type: Ethernet
+ -- hardware address length
+ -- 00
+ -- XID -- Note: XID is only ready at the next CLK. Use RANDOM_NO instead here
+ UDP_TX_SOF <= '1';
+ when "0000001" =>
+ UDP_TX_DATA(63 downto 48) <= TIME_CNTR_AT_DHCPDISCOVER;
+ UDP_TX_DATA(47 downto 0) <= (others => '0');
+ -- seconds elapsed since DHCP client began address acquisition
+ UDP_TX_SOF <= '0';
+ when "0000011" =>
+ UDP_TX_DATA(63 downto 32) <= (others => '0');
+ UDP_TX_DATA(31 downto 0) <= MAC_ADDR(47 downto 16);
+ -- client MAC address
+ when "0000100" =>
+ UDP_TX_DATA(63 downto 48) <= MAC_ADDR(15 downto 0);
+ UDP_TX_DATA(47 downto 0) <= (others => '0');
+ -- client MAC address
+ when "0011101" =>
+ UDP_TX_DATA(63 downto 32) <= (others => '0');
+ UDP_TX_DATA(31 downto 0) <= MAGIC_COOKIE;
+ when "0011110" =>
+ UDP_TX_DATA <= x"3501013D0701" & MAC_ADDR(47 downto 32);
+ -- option DHCP message type (53)
+ -- length
+ -- DHCPDISCOVER
+ -- option DHCP client identifier (61)
+ -- length
+ -- Ethernet
+ -- client MAC address
+ when "0011111" =>
+ UDP_TX_DATA <= MAC_ADDR(31 downto 0) & x"37030103";
+ -- client MAC address
+ -- option parameter request list (55)
+ -- length
+ -- subnet mask
+ -- router
+ when "0100000" =>
+ UDP_TX_DATA <= x"06FF000000000000";
+ -- domain name server
+ -- option end (255)
+ UDP_TX_EOF <= '1';
+ when others =>
+ UDP_TX_DATA <= (others => '0');
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ end case;
+ elsif(STATE = 7) and (UDP_TX_CTS = '1') then
+ -- DHCPREQUEST message
+ -- UDP destination IP address, broadcast
+ DEST_IPv4_ADDR <= x"FFFFFFFF";
+ DEST_MAC_ADDR <= x"FFFFFFFFFFFF";
+ if(WPTR < 33) then
+ UDP_TX_DATA_VALID <= x"FF";
+ elsif(WPTR = 33) then
+ UDP_TX_DATA_VALID <= x"80";
+ else
+ UDP_TX_DATA_VALID <= x"00";
+ end if;
+ case WPTR is
+ when "0000000" =>
+ UDP_TX_DATA <= x"01010600" & XID;
+ -- op: BOOTREQUEST
+ -- hardware type: Ethernet
+ -- hardware address length
+ -- 00
+ -- XID
+ UDP_TX_SOF <= '1';
+ when "0000001" =>
+ UDP_TX_DATA <= TIME_CNTR_AT_DHCPDISCOVER & x"000000000000";
+ -- seconds elapsed since DHCP client began address acquisition. MUST be same as in DHCPDISCOVER
+ UDP_TX_SOF <= '0';
+ when "0000011" =>
+ UDP_TX_DATA(63 downto 32) <= (others => '0');
+ UDP_TX_DATA(31 downto 0) <= MAC_ADDR(47 downto 16);
+ -- client MAC address
+ when "0000100" =>
+ UDP_TX_DATA(63 downto 48) <= MAC_ADDR(15 downto 0);
+ UDP_TX_DATA(47 downto 0) <= (others => '0');
+ -- client MAC address
+ when "0011101" =>
+ UDP_TX_DATA(63 downto 32) <= (others => '0');
+ UDP_TX_DATA(31 downto 0) <= MAGIC_COOKIE;
+ -- magic cookie
+ when "0011110" =>
+ UDP_TX_DATA <= x"3501033d0701" & MAC_ADDR(47 downto 32);
+ -- option DHCP message type (53)
+ -- length
+ -- DHCPREQUEST
+ -- option DHCP client identifier (61)
+ -- length
+ -- Ethernet
+ -- client MAC address
+ when "0011111" =>
+ UDP_TX_DATA <= MAC_ADDR(31 downto 0) & x"3204" & BEST_RX_YIADDR(31 downto 16);
+ -- client MAC address
+ -- option requested IP address (50)
+ -- length
+ -- requested IP address
+ when "0100000" =>
+ UDP_TX_DATA <= BEST_RX_YIADDR(15 downto 0) & x"3604" & BEST_DHCP_SERVER_IP_ADDR(31 downto 0);
+ -- requested IP address
+ -- option DHCP server identifier (54)
+ -- length
+ -- DHCP server ID
+ when "0100001" =>
+ UDP_TX_DATA <= x"FF00000000000000" ;
+ -- option end (255)
+ UDP_TX_EOF <= '1';
+ when others =>
+ UDP_TX_DATA <= (others => '0');
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ end case;
+
+ else
+ UDP_TX_DATA_VALID <= X"00";
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ end if;
+ end if;
+end process;
+
+DEST_IPv4_ADDRx <= x"000000000000000000000000" & DEST_IPv4_ADDR;
+UDP_TX_001: UDP_TX_10G
+GENERIC MAP(
+ ADDR_WIDTH => 7, -- elastic buffer size as 72b * 2^ADDR_WIDTH
+ UDP_CKSUM_ENABLED => '1',
+ IPv6_ENABLED => '0'
+)
+PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET_local,
+ TICK_4US => TICK_4US,
+ -- Application interface
+ APP_DATA => UDP_TX_DATA,
+ APP_DATA_VALID => UDP_TX_DATA_VALID,
+ APP_SOF => UDP_TX_SOF,
+ APP_EOF => UDP_TX_EOF,
+ APP_CTS => UDP_TX_CTS,
+ ACK => UDP_TX_ACK_local,
+ NAK => UDP_TX_NAK_local,
+ DEST_IP_ADDR => DEST_IPv4_ADDRx,
+ IPv4_6n => '1',
+ DEST_PORT_NO => x"0043", -- DHCP server port (67)
+ SOURCE_PORT_NO => x"0044", -- DHCP client port (68)
+ -- Configuration
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR_local,
+ IPv6_ADDR => (others => '0'),
+ IP_ID => std_logic_vector(IP_ID_IN),
+ -- Routing
+ RT_IP_ADDR => open,
+ RT_IPv4_6n => open,
+ RT_REQ_RTS => open,
+ RT_REQ_CTS => '1',
+ RT_MAC_REPLY => DEST_MAC_ADDR,
+ RT_MAC_RDY => '1',
+ RT_NAK => '0',
+ -- MAC interface
+ MAC_TX_DATA => MAC_TX_DATA,
+ MAC_TX_DATA_VALID => MAC_TX_DATA_VALID,
+ MAC_TX_EOF => MAC_TX_EOF_local,
+ MAC_TX_CTS => MAC_TX_CTS,
+ RTS => RTS,
+ TP => open
+);
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+----// TEST POINTS -----------------------------
+--TP(1) <= DHCP_RX_DATA_VALID;
+--TP(2) <= EVENT1;
+--TP(3) <= EVENT2;
+----TP(4) <=
+----TP(5) <=
+----TP(6) <=
+--TP(7) <= UDP_TX_CTS;
+--TP(8) <= '1' when (STATE = 3) and (UDP_TX_CTS = '1') else '0';
+--TP(9) <= MAC_TX_EOF_local;
+--
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/dhcp_server_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/dhcp_server_10G.vhd
new file mode 100644
index 0000000..5362da8
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/dhcp_server_10G.vhd
@@ -0,0 +1,1364 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: DHCP_SERVER_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 5/3/19
+-- Inheritance: DHCP_SERVER.vhd 6/26/16
+--
+-- description:
+-- DHCP server (on-top of UDP_TX and UDP_RX). 10G version.
+-- Based on RFC2131
+-- Supports dynamic and automatic allocation:
+-- dynamic allocation: A network administrator assigns a range of IP addresses to DHCP, and each client computer on the LAN
+-- is configured to request an IP address from the DHCP server during network initialization. The request-and-grant process
+-- uses a lease concept with a controllable time period, allowing the DHCP server to reclaim (and then reallocate) IP
+-- addresses that are not renewed.
+-- automatic allocation: The DHCP server permanently assigns a free IP address to a requesting client from the range defined
+-- by the administrator. This is like dynamic allocation, but the DHCP server keeps a table of past IP address assignments,
+-- so that it can preferentially assign to a client the same IP address that the client previously had.
+--
+-- Limitations:
+-- No support for static allocation.
+-- Client and server are on the same subnet (no relay)
+--
+-- Usage:
+-- 1. A DHCP server can be instantiated (using the DHCP_SERVER_EN generic parameter in COM5502/3.vhd), but still
+-- enabled/disabled dynamically at run-time using the SYNC_RESET input. Set SYNC_RESET to '1' to disable this server.
+-- 2. After changing DHCP server configuration parameter, the server must be reset.
+-- 3. Proposed IP address is always on the same subnet as this server (i.e. same 3 MSBs as this server IPv4_ADDR)
+-- 4. Limited to 6-byte (Ethernet) hardware addressing
+--
+-- Device utilization
+-- FF: 1534
+-- LUT: 1399
+-- DSP48: 0
+-- 36Kb BRAM: 5
+-- BUFG: 1
+-- Minimum period: 6.122ns (Maximum Frequency: 163.359MHz) Artix7-100T -1 speed grade
+
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity DHCP_SERVER_10G is
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ -- set to '1' to disable the DHCP server
+ CLK: in std_logic; -- synchronous clock
+ -- Must be a global clocks. No BUFG instantiation within this component.
+ TICK_4US: in std_logic;
+ TICK_100MS : in std_logic;
+ -- 100 ms tick for timer
+
+ --// DHCP SERVER CONFIGURATION: IP address, MAC address, host name
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- this DHCP server IP address. 4 bytes for IPv4, 16 bytes for IPv6
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+ HOST_NAME: in std_logic_vector(47 downto 0) := (others => '0'); -- 6 char max or hash if longer
+ IP_MIN: in std_logic_vector(7 downto 0);
+ NIPs: in std_logic_vector(7 downto 0);
+ -- range of IP addresses to be assigned by this DHCP server
+ -- the actual address is in the form IPv4_ADDR for the 3 MSB, and a subnet address between IP_MIN (inclusive)
+ -- and IP_MIN + NIPs -1 (inclusive)
+ -- Maximum 128 entries.
+ -- For example, if IPv4_ADDR = 172.16.1.3, IP_MIN = 10, NIPs = 10, this DHCP server will assign and keep track of
+ -- IP addresses in the range 172.16.1.10 and 172.16.1.19 (inclusive).
+ LEASE_TIME: in std_logic_vector(31 downto 0);
+ -- lease time in secs
+ SUBNET_MASK: in std_logic_vector(31 downto 0);
+ ROUTER: in std_logic_vector(31 downto 0);
+ DNS: in std_logic_vector(31 downto 0);
+
+ IP_ID_IN: in std_logic_vector(15 downto 0);
+ -- 16-bit IP ID, unique for each datagram. Incremented every time
+ -- an IP datagram is sent (not just for this protocol).
+
+ --// Received UDP payload
+ -- DHCP message is encapsulated within a UDP frame
+ UDP_RX_DATA: in std_logic_vector(63 downto 0);
+ -- byte order: MSB first (reason: easier to read contents during simulation)
+ UDP_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ UDP_RX_SOF: in std_logic;
+ UDP_RX_EOF: in std_logic;
+ -- 1 CLK pulse indicating that UDP_RX_DATA is the last word in the UDP data field.
+ -- ALWAYS CHECK UDP_RX_FRAME_VALID at the end of packet (UDP_RX_EOF = '1') to confirm
+ -- that the UDP packet is valid. External buffer may have to backtrack to the the last
+ -- valid pointer to discard an invalid UDP packet.
+ -- Reason: we only knows about bad UDP packets at the end.
+ UDP_RX_FRAME_VALID: in std_logic;
+ -- check entire frame validity at UDP_RX_EOF
+ UDP_RX_DEST_PORT_NO: in std_logic_vector(15 downto 0);
+ -- Identify the destination UDP port. Read when UDP_RX_EOF = '1'
+
+ --// IP type, already parsed in PACKET_PARSING (shared code)
+ RX_SOURCE_IP_ADDR: in std_logic_vector(31 downto 0);
+
+ --// OUTPUT: TX UDP layer -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended by MAC. Not supplied here.
+ MAC_TX_DATA: out std_logic_vector(63 downto 0) := (others => '0');
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID /= 0
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0) := (others => '0');
+ -- data valid
+ MAC_TX_EOF: out std_logic := '0';
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal. The user should check that this
+ -- signal is high before sending the next MAC_TX_DATA byte.
+ RTS: out std_logic := '0';
+ -- '1' when a frame is ready to be sent (tell the COM550X arbiter)
+ -- When the MAC starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+ --// TEST POINTS
+-- N_DHCPDISCOVER_OUT: out std_logic_vector(7 downto 0);
+-- -- monitors the number of received DHCPDISCOVER messages, modulo 256
+-- N_DHCPREQUEST1_OUT: out std_logic_vector(7 downto 0);
+-- -- monitors the number of received DHCPREQUEST messages addressed to this server (continuation of the DHCPDISCOVER), modulo 256
+-- N_DHCPREQUEST2_OUT: out std_logic_vector(7 downto 0);
+-- -- monitors the number of DHCPREQUEST messages for renewing state
+-- N_DHCPREQUEST3_OUT: out std_logic_vector(7 downto 0);
+-- -- monitors the number of DHCPREQUEST messages (INIT REBOOT STATE)
+-- N_DHCPACK_OUT: out std_logic_vector(7 downto 0);
+-- -- monitors the number of successful DHCPACK messages sent, concluding the dynamic IP address assignment, modulo 256
+
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of DHCP_SERVER_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+
+ COMPONENT UDP_TX_10G
+ generic (
+ ADDR_WIDTH: integer;
+ UDP_CKSUM_ENABLED: std_logic;
+ IPv6_ENABLED: std_logic
+ );
+ PORT(
+ CLK : IN std_logic;
+ SYNC_RESET : IN std_logic;
+ TICK_4US: in std_logic;
+ APP_DATA : IN std_logic_vector(63 downto 0);
+ APP_DATA_VALID : IN std_logic_vector(7 downto 0);
+ APP_SOF : IN std_logic;
+ APP_EOF : IN std_logic;
+ APP_CTS : OUT std_logic;
+ DEST_IP_ADDR: in std_logic_vector(127 downto 0);
+ IPv4_6n: in std_logic;
+ DEST_PORT_NO : IN std_logic_vector(15 downto 0);
+ SOURCE_PORT_NO : IN std_logic_vector(15 downto 0);
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ IP_ID: in std_logic_vector(15 downto 0);
+ ACK : OUT std_logic;
+ NAK : OUT std_logic;
+ RT_IP_ADDR : OUT std_logic_vector(127 downto 0);
+ RT_IPv4_6n: out std_logic;
+ RT_REQ_RTS: out std_logic;
+ RT_REQ_CTS: in std_logic;
+ RT_MAC_REPLY : IN std_logic_vector(47 downto 0);
+ RT_MAC_RDY : IN std_logic;
+ RT_NAK: in std_logic;
+ MAC_TX_DATA : OUT std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID : OUT std_logic_vector(7 downto 0);
+ MAC_TX_EOF : OUT std_logic;
+ MAC_TX_CTS : IN std_logic;
+ RTS: out std_logic := '0';
+ TP : OUT std_logic_vector(10 downto 1)
+ );
+ END COMPONENT;
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+--// TIME ------------------------------------------------
+signal TIMER: integer range 0 to 50 := 0;
+signal TIME_CNTR: unsigned(31 downto 0) := (others => '0');
+signal CNTR10: unsigned(3 downto 0) := (others => '0');
+
+--// UDP RX frame ---------------------------------------
+signal VALID_UDP_DEST_PORT: std_logic := '0';
+signal DHCP_RX_WORD_COUNT: unsigned(6 downto 0) := (others => '0');
+signal DHCP_RX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCP_RX_DATA_D: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCP_RX_DATA_D_FLIPPED: std_logic_vector(63 downto 0) := (others => '0');
+signal DHCP_RX_DATA_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal DHCP_RX_DATA_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal DHCP_RX_SOF: std_logic := '0';
+signal DHCP_RX_SOF_D: std_logic := '0';
+signal DHCP_RX_EOF: std_logic := '0';
+signal DHCP_RX_EOF_D: std_logic := '0';
+signal DHCP_RX_WORD_VALID: std_logic := '0';
+signal DHCP_RX_WORD_VALID_D: std_logic := '0';
+signal CLIENT_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal XID: std_logic_vector(31 downto 0) := (others => '0');
+signal XID4RESPONSE: std_logic_vector(31 downto 0) := (others => '0');
+signal FLAGS: std_logic_vector(15 downto 0) := (others => '0');
+signal CIADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal GIADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal MAGIC_COOKIE: std_logic_vector(31 downto 0) := (others => '0');
+-- word to byte serialization
+signal DHCP_RX_BYTE_COUNT: unsigned(9 downto 0) := (others => '1');
+signal BUF1_SIZE: unsigned(9 downto 0) := (others => '0');
+signal DHCP_RX_DATA2_VALID_E: std_logic := '0';
+signal DHCP_RX_DATA2_VALID: std_logic := '0';
+signal DHCP_RX_DATA2: std_logic_vector(7 downto 0) := (others => '0');
+signal DHCP_READ_STATE: integer range 0 to 3 := 0;
+signal DHCP_RX_EOF2: std_logic := '0';
+signal DHCP_RX_EOF2_D: std_logic := '0';
+signal DHCP_OPTION: unsigned(7 downto 0) := (others => '0');
+signal DHCP_MESSAGE_LENGTH: unsigned(7 downto 0) := (others => '0');
+signal DHCP_MESSAGE: std_logic_vector(95 downto 0) := (others => '0');
+signal DHCP_MESSAGE_TYPE: unsigned(3 downto 0) := (others => '0');
+signal DHCP_CLIENT_ID: std_logic_vector(55 downto 0) := (others => '0');
+signal DHCP_CLIENT_ID_D: std_logic_vector(55 downto 0) := (others => '0');
+signal DHCP_CLIENT_ID_MATCH: std_logic := '0';
+signal DHCP_REQUESTED_IP_ADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal DHCP_SERVER_IP_ADDR: unsigned(31 downto 0) := (others => '0');
+signal DHCP_PARAMETERS_REQUEST: std_logic_vector(23 downto 0) := (others => '0');
+signal DHCP_HOST_NAME: std_logic_vector(47 downto 0) := (others => '0'); -- 6 char max or hash if longer
+signal RX_VALID: std_logic := '0';
+signal EVENT0: std_logic := '0';
+signal EVENT1: std_logic := '0';
+signal EVENT2A: std_logic := '0';
+signal EVENT2B: std_logic := '0';
+signal EVENT2C: std_logic := '0';
+signal EVENT2D: std_logic := '0';
+signal EVENT3A: std_logic := '0';
+signal EVENT3B: std_logic := '0';
+signal EVENT3C: std_logic := '0';
+--signal EVENT4: std_logic := '0';
+signal EVENT6: std_logic := '0';
+--signal EVENT7: std_logic := '0';
+--signal EVENT8: std_logic := '0';
+signal EVENT10: std_logic := '0';
+signal EVENT11: std_logic := '0';
+signal STATE: integer range 0 to 31 := 0;
+
+--//-- TABLE ---------------------------------------------------
+signal WEA: std_logic := '0';
+signal WEB: std_logic := '0';
+signal DIA: std_logic_vector(31 downto 0) := (others => '0');
+signal DIB: std_logic_vector(31 downto 0) := (others => '0');
+signal DOA: std_logic_vector(31 downto 0) := (others => '0');
+signal DOB: std_logic_vector(31 downto 0) := (others => '0');
+--
+--//-- SEARCH STATE MACHINE ---------------------------------------
+signal TRIGGER_SEARCH_BY_CLIENTID: std_logic := '0';
+signal SEARCH_STATE: integer range 0 to 3 := 0;
+signal SEARCH_STATE_D: integer range 0 to 3 := 0;
+signal SEARCH_STATE_D2: integer range 0 to 3 := 0;
+signal SEARCH_COMPLETE: std_logic := '0';
+signal SEARCH_COMPLETE_D: std_logic := '0';
+signal SEARCH_COMPLETE_D2: std_logic := '0';
+signal ADDRA: std_logic_vector(9 downto 0) := (others => '0'); -- table is 512 x 36 + 1 bit for overflow detection
+signal ADDRA_PLUS: std_logic_vector(9 downto 0) := (others => '0'); -- table is 512 x 36 + 1 bit for overflow detection
+signal ADDRA_D: std_logic_vector(9 downto 0) := (others => '0');
+signal ADDRA_D2: std_logic_vector(9 downto 0) := (others => '0');
+signal ADDRB: std_logic_vector(9 downto 0) := (others => '0'); -- table is 512 x 36 + 1 bit for overflow detection
+signal FOUND_CLIENT_ID: std_logic := '0';
+signal FOUND_CLIENT_ID_D: std_logic := '0';
+signal FOUND_IP: std_logic_vector(7 downto 0) := (others => '0');
+signal FOUND_IP_PLUSMIN: std_logic_vector(7 downto 0) := (others => '0');
+signal FOUND_OLDEST_IP: std_logic_vector(7 downto 0) := (others => '0');
+signal FOUND_OLDEST_EXPIRATION_TIME: std_logic_vector(31 downto 0) := (others => '0');
+signal EXPIRED_OLDEST_ENTRY: std_logic := '0';
+signal PROPOSED_IP_ADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal IP_MATCH: std_logic := '0';
+signal IP_MATCH_MSB: std_logic := '0';
+
+--//-- COMPOSE REPLY --------------------------
+signal DEST_IPv4_ADDR: std_logic_vector(31 downto 0) := (others => '0');
+signal DEST_IPv4_ADDRx: std_logic_vector(127 downto 0) := (others => '0');
+signal DEST_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal WPTR: unsigned(6 downto 0) := (others => '0'); -- maximum size 576Bytes or 73 Words
+signal UDP_TX_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal UDP_TX_DATA_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal UDP_TX_SOF: std_logic := '0';
+signal UDP_TX_EOF: std_logic := '0';
+signal UDP_TX_CTS: std_logic := '0';
+signal UDP_TX_ACK_local: std_logic := '0';
+signal UDP_TX_NAK_local: std_logic := '0';
+signal MAC_TX_EOF_local: std_logic := '0';
+--
+--//-- MONITORING ---------------------------------
+signal N_DHCPDISCOVER: unsigned(7 downto 0) := (others => '0');
+signal N_DHCPREQUEST1: unsigned(7 downto 0) := (others => '0');
+signal N_DHCPREQUEST2: unsigned(7 downto 0) := (others => '0');
+signal N_DHCPREQUEST3: unsigned(7 downto 0) := (others => '0');
+signal N_DHCPACK: unsigned(7 downto 0) := (others => '0');
+--
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// TIME ------------------------------------------------
+-- track relative time in secs.
+TIME_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if (SYNC_RESET = '1') then
+ TIME_CNTR <= (0 => '1', others => '0');
+ CNTR10 <= (others => '0');
+ elsif(TICK_100MS = '1') then
+ if(CNTR10 = 9) then
+ -- TIME_CNTR units = seconds
+ CNTR10 <= (others => '0');
+ TIME_CNTR <= TIME_CNTR + 1;
+ else
+ CNTR10 <= CNTR10 + 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+--// UDP RX frame ---------------------------------------
+-- DHCP is encapsulated within a UDP frame
+-- verify UDP destination port is 67 (x0043) 67 is the DHCP server port
+VALID_UDP_DEST_PORT <= '1' when (UDP_RX_DEST_PORT_NO = x"0043") else '0';
+DHCP_RX_DATA <= UDP_RX_DATA;
+DHCP_RX_DATA_VALID <= UDP_RX_DATA_VALID when (VALID_UDP_DEST_PORT = '1') else x"00";
+DHCP_RX_SOF <= UDP_RX_SOF and VALID_UDP_DEST_PORT;
+DHCP_RX_EOF <= UDP_RX_EOF and VALID_UDP_DEST_PORT;
+DHCP_RX_WORD_VALID <= '1' when (UDP_RX_DATA_VALID /= x"00") and (VALID_UDP_DEST_PORT = '1') else '0';
+
+-- keep track of the received DHCP rx pointer
+-- Pointer DHCP_RX_WORD_COUNT aligned with DHCP_RX_DATA_VALID_D
+-- DHCP message datagram can be up to 576 bytes, thus DHCP_RX_WORD_COUNT 7-bits
+DHCP_RX_BYTE_COUNT_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DHCP_RX_DATA_D <= DHCP_RX_DATA;
+ DHCP_RX_DATA_VALID_D <= DHCP_RX_DATA_VALID;
+ DHCP_RX_WORD_VALID_D <= DHCP_RX_WORD_VALID;
+ DHCP_RX_SOF_D <= DHCP_RX_SOF;
+ DHCP_RX_EOF_D <= DHCP_RX_EOF;
+
+ if(SYNC_RESET = '1') or (DHCP_RX_SOF = '1') then
+ DHCP_RX_WORD_COUNT <= (others => '0');
+ elsif(DHCP_RX_WORD_VALID_D = '1') then
+ if(DHCP_RX_WORD_COUNT(6) = '0') then -- max 64. should not normally happen.
+ DHCP_RX_WORD_COUNT <= DHCP_RX_WORD_COUNT + 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- capture relevant fields (only while STATE = 6)
+GET_FIELDS_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(DHCP_RX_WORD_VALID_D = '1') and (STATE = 6) then -- *062516
+ if(DHCP_RX_SOF_D = '1') then
+ -- transaction ID
+ XID <= DHCP_RX_DATA_D(31 downto 0);
+ end if;
+ if(DHCP_RX_WORD_COUNT = 1) then
+ FLAGS <= DHCP_RX_DATA_D(47 downto 32);
+ CIADDR <= DHCP_RX_DATA_D(31 downto 0);
+ end if;
+ if(DHCP_RX_WORD_COUNT = 3) then
+ GIADDR <= DHCP_RX_DATA_D(63 downto 32);
+ -- assumes a 6-byte Ethernet address (out of 16-byte field)
+ CLIENT_MAC_ADDR(47 downto 16) <= DHCP_RX_DATA_D(31 downto 0);
+ end if;
+ if(DHCP_RX_WORD_COUNT = 4) then
+ CLIENT_MAC_ADDR(15 downto 0) <= DHCP_RX_DATA_D(63 downto 48);
+ end if;
+ if(DHCP_RX_WORD_COUNT = 29) then
+ MAGIC_COOKIE <= DHCP_RX_DATA_D(31 downto 0);
+ end if;
+ end if;
+ end if;
+end process;
+
+-- parse the variable-length DHCP fields, starting immediately after the magic cookie
+-- serialize word through a small (1KB) DPRAM
+-- this eases the parsing of the option fields
+-- DHCP message datagram can be up to 576 bytes
+
+-- flip LSB/MSB
+PARSE_001: process(DHCP_RX_DATA_D)
+begin
+ for I in 0 to 7 loop
+ DHCP_RX_DATA_D_FLIPPED((7-I)*8+7 downto (7-I)*8) <= DHCP_RX_DATA_D(I*8+7 downto I*8);
+ end loop;
+end process;
+
+PARSE_002 : BRAM_DP2
+generic map (
+ DATA_WIDTHA => 8,
+ ADDR_WIDTHA => 10,
+ DATA_WIDTHB => 64,
+ ADDR_WIDTHB => 7
+)
+port map(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => '0',
+ ADDRA => std_logic_vector(DHCP_RX_BYTE_COUNT),
+ DIA => (others => '0'),
+ OEA => '1',
+ DOA => DHCP_RX_DATA2, -- byte-wide
+ CSB => '1',
+ CLKB => CLK,
+ WEB => DHCP_RX_WORD_VALID_D,
+ ADDRB => std_logic_vector(DHCP_RX_WORD_COUNT),
+ DIB => DHCP_RX_DATA_D_FLIPPED,
+ OEB => '0',
+ DOB => open
+);
+
+BUF1_SIZE <= (DHCP_RX_WORD_COUNT & "000") + (not DHCP_RX_BYTE_COUNT);
+
+PARSE_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DHCP_RX_DATA2_VALID <= DHCP_RX_DATA2_VALID_E; -- 1CLK latency to read from BRAM
+
+ if(SYNC_RESET = '1') or (DHCP_RX_SOF = '1') then
+ DHCP_RX_BYTE_COUNT <= (others => '1');
+ DHCP_RX_DATA2_VALID_E <= '0';
+ elsif(BUF1_SIZE > 0) then
+ DHCP_RX_BYTE_COUNT <= DHCP_RX_BYTE_COUNT + 1;
+ DHCP_RX_DATA2_VALID_E <= '1';
+ else
+ DHCP_RX_DATA2_VALID_E <= '0';
+ end if;
+ end if;
+end process;
+
+-- parse the variable-length DHCP fields, starting immediately after the magic cookie
+PARSE_DHCP_FIELDS: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ DHCP_READ_STATE <= 0;
+ elsif(DHCP_RX_BYTE_COUNT = 240) then
+ -- magic cookie immediately preceeds the DHCP options
+ DHCP_READ_STATE <= 1;
+ -- clear previous option fields
+ DHCP_MESSAGE_TYPE <= (others => '0');
+ DHCP_CLIENT_ID <= (others => '0');
+ DHCP_REQUESTED_IP_ADDR <= (others => '0');
+ DHCP_SERVER_IP_ADDR <= (others => '0');
+ DHCP_HOST_NAME <= (others => '0');
+ elsif(DHCP_RX_DATA2_VALID = '1') then
+ if(DHCP_READ_STATE = 1) then
+ if(DHCP_RX_DATA2 = x"FF") then
+ -- end of DHCP options
+ DHCP_READ_STATE <= 0;
+ else
+ DHCP_READ_STATE <= 2;
+ DHCP_OPTION <= unsigned(DHCP_RX_DATA2);
+ DHCP_MESSAGE <= (others => '0'); -- clear message field before next option
+ end if;
+ elsif(DHCP_READ_STATE = 2) then
+ DHCP_READ_STATE <= 3;
+ DHCP_MESSAGE_LENGTH <= unsigned(DHCP_RX_DATA2);
+ elsif(DHCP_READ_STATE = 3) then
+ if(DHCP_MESSAGE_LENGTH = 1) then
+ -- reached end of DHCP message
+ DHCP_READ_STATE <= 1;
+ -- save in various fields
+ if(DHCP_OPTION = 53) then
+ -- DHCP message type
+ DHCP_MESSAGE_TYPE <= unsigned(DHCP_RX_DATA2(3 downto 0)); -- 1-8
+ end if;
+ if(DHCP_OPTION = 61) then
+ -- client identifier
+ DHCP_CLIENT_ID <= DHCP_MESSAGE(47 downto 0) & DHCP_RX_DATA2; -- 7 bytes
+ end if;
+ if(DHCP_OPTION = 50) then
+ -- requested IP address
+ DHCP_REQUESTED_IP_ADDR <= DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2; -- 4 bytes
+ end if;
+ if(DHCP_OPTION = 54) then
+ -- DHCP server identifier
+ DHCP_SERVER_IP_ADDR <= unsigned(DHCP_MESSAGE(23 downto 0) & DHCP_RX_DATA2); -- 4 bytes
+ end if;
+ if(DHCP_OPTION = 55) then
+ -- DHCP parameters request list
+ DHCP_PARAMETERS_REQUEST <= DHCP_MESSAGE(15 downto 0) & DHCP_RX_DATA2; -- 3 bytes
+ end if;
+ if(DHCP_OPTION = 12) then
+ -- host name
+ DHCP_HOST_NAME <= DHCP_MESSAGE(39 downto 0) & DHCP_RX_DATA2; -- 6 char max or hash if longer
+ end if;
+
+ else
+ DHCP_MESSAGE <= DHCP_MESSAGE(87 downto 0) & DHCP_RX_DATA2;
+ DHCP_MESSAGE_LENGTH <= DHCP_MESSAGE_LENGTH - 1;
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- generate an EOF on the other side of the serialization buffer
+DHCP_RX_EOF2 <= '1' when (DHCP_RX_DATA2_VALID = '1') and (DHCP_READ_STATE = 1) and (DHCP_RX_DATA2 = x"FF") else '0';
+
+-- check incoming message validity
+-- ready at DHCP_RX_EOF1_D
+VALID_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DHCP_RX_EOF2_D <= DHCP_RX_EOF2;
+
+ if(UDP_RX_SOF = '1') then
+ RX_VALID <= '1'; -- valid by default, until proven otherwise
+ elsif(UDP_RX_EOF = '1') and (UDP_RX_FRAME_VALID = '0') then
+ -- invalid UDP message
+ RX_VALID <= '0';
+ elsif(DHCP_RX_EOF2 = '1') and (MAGIC_COOKIE /= x"63825363") then
+ RX_VALID <= '0';
+ end if;
+ end if;
+end process;
+
+
+--//-- EVENTS ---------------------------------------------------
+-- 0 = start of new rx message addressed to port 67 (x0043)
+EVENT0 <= DHCP_RX_SOF when (unsigned(UDP_RX_DEST_PORT_NO) = 67) else '0';
+
+-- 10 = end of invalid rx message (before parallel to serial buffer)
+EVENT10 <= DHCP_RX_EOF when (UDP_RX_FRAME_VALID = '0') or (unsigned(UDP_RX_DEST_PORT_NO) /= 67) else '0';
+
+-- 11 = end of invalid rx message (after parallel to serial buffer)
+EVENT11 <= DHCP_RX_EOF2_D when (RX_VALID = '0') else '0';
+
+-- 1 = DHCP Discover message (DHCPDISCOVER).
+EVENT1 <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 1) else '0';
+
+-- 3 = DHCP Request message (DHCPREQUEST) addressed to the right DHCP server
+EVENT3A <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 3)
+ and (DHCP_SERVER_IP_ADDR = unsigned(IPv4_ADDR)) else '0';
+
+-- 3 = DHCP Request message (DHCPREQUEST) for renewing
+EVENT3B <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 3)
+ and (DHCP_SERVER_IP_ADDR = 0) and (unsigned(DHCP_REQUESTED_IP_ADDR) = 0)
+ and ((CIADDR and SUBNET_MASK) = (IPv4_ADDR and SUBNET_MASK)) -- client IP addr on the correct network
+ else '0';
+
+-- 3 = DHCP Request message (DHCPREQUEST) for init-reboot
+EVENT3C <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 3)
+ and (DHCP_SERVER_IP_ADDR = 0) and (unsigned(DHCP_REQUESTED_IP_ADDR) /= 0)
+ and (unsigned(CIADDR) = 0) else '0';
+
+---- 4 = DHCP Request message (DHCPDECLINE).
+--EVENT4 <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 4) else '0';
+--
+-- 6 = end of message (whether valid or processed or not)
+EVENT6 <= '1' when (DHCP_RX_EOF2_D = '1') else '0';
+
+---- 7 = DHCP Request message (DHCPRELEASE).
+--EVENT7 <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 7) else '0';
+--
+---- 8 = DHCP Request message (DHCPINFORM).
+--EVENT8 <= '1' when (DHCP_RX_EOF2_D = '1') and (RX_VALID = '1') and (DHCP_MESSAGE_TYPE = 8) else '0';
+--
+-- search by client ID complete, found match
+EVENT2A <= SEARCH_COMPLETE_D2 and FOUND_CLIENT_ID;
+
+-- search by client ID complete, found no entry
+EVENT2B <= SEARCH_COMPLETE_D2 and (not FOUND_CLIENT_ID);
+
+-- search by client ID complete, found no entry and oldest entry has expired (free to re-assign)
+EVENT2C <= SEARCH_COMPLETE_D2 and (not FOUND_CLIENT_ID) and EXPIRED_OLDEST_ENTRY;
+
+-- search by client ID complete, found match, IP request matches table entry
+EVENT2D <= SEARCH_COMPLETE_D2 and FOUND_CLIENT_ID and IP_MATCH;
+
+--//-- STATE MACHINE ---------------------------------------------------
+-- new replace too large ifthenelse with case for better timing
+STATE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ STATE <= 0; -- idle
+ TRIGGER_SEARCH_BY_CLIENTID <= '0';
+ elsif(EVENT10 = '1') or (EVENT11 = '1') then
+ -- invalid rx UDP frame
+ STATE <= 0; -- idle
+ else
+ case STATE is
+ when 0 =>
+ if(EVENT0 = '1') then
+ -- new incoming message. start parsing fields
+ STATE <= 6;
+ end if;
+ when 6 =>
+ --------- DHCPDISCOVER --------------------------------
+ if(EVENT1 = '1') then
+ -- received valid DHCPDISCOVER, start table search
+ STATE <= 1;
+ N_DHCPDISCOVER <= N_DHCPDISCOVER + 1;
+ -- freeze key fields (XID, client ID) for response
+ XID4RESPONSE <= XID;
+ DHCP_CLIENT_ID_D <= DHCP_CLIENT_ID;
+ TRIGGER_SEARCH_BY_CLIENTID <= '1';
+ --------- DHCPREQUEST (SELECTING STATE) --------------------------------
+ elsif(EVENT3A = '1') then
+ -- received DHCP Request message (DHCPREQUEST) addressed to the right DHCP server
+ STATE <= 8;
+ N_DHCPREQUEST1 <= N_DHCPREQUEST1 + 1;
+ -- save XID for response
+ XID4RESPONSE <= XID;
+ DHCP_CLIENT_ID_D <= DHCP_CLIENT_ID;
+ TRIGGER_SEARCH_BY_CLIENTID <= '1';
+ --------- DHCPREQUEST (RENEWING STATE) --------------------------------
+ elsif(EVENT3B = '1') then
+ -- received DHCP Request message (DHCPREQUEST) for renewing
+ STATE <= 16;
+ N_DHCPREQUEST2 <= N_DHCPREQUEST1 + 2;
+ -- save XID for response
+ XID4RESPONSE <= XID;
+ DHCP_CLIENT_ID_D <= DHCP_CLIENT_ID;
+ --------- DHCPREQUEST (INIT REBOOT STATE) --------------------------------
+ elsif(EVENT3C = '1') then
+ if(unsigned(DHCP_REQUESTED_IP_ADDR and SUBNET_MASK) = unsigned(IPv4_ADDR and SUBNET_MASK)) then
+ -- correct network. next verify table
+ STATE <= 24;
+ N_DHCPREQUEST3 <= N_DHCPREQUEST3 + 1;
+ -- save XID for response
+ XID4RESPONSE <= XID;
+ DHCP_CLIENT_ID_D <= DHCP_CLIENT_ID;
+ else
+ -- incorrect network. send DHCPNAK
+ STATE <= 26;
+ end if;
+ elsif(EVENT6 = '1') then
+ -- end of message, none of the above. Back to idle
+ STATE <= 0;
+ end if;
+
+ when 1 =>
+ TRIGGER_SEARCH_BY_CLIENTID <= '0';
+ if(EVENT2A = '1') then
+ -- search by client ID complete, found match
+ -- send DHCPOFFER
+ PROPOSED_IP_ADDR(7 downto 0) <= FOUND_IP_PLUSMIN;
+ STATE <= 3;
+ elsif(EVENT2C = '1') then
+ -- search by client ID complete, found no entry and oldest entry has expired (free to re-assign)
+ STATE <= 2;
+ end if;
+ when 2 =>
+ -- done creating new entry with client ID from DHCPDISCOVER
+ -- send DHCPOFFER
+ PROPOSED_IP_ADDR(7 downto 0) <= std_logic_vector(unsigned(FOUND_OLDEST_IP) + unsigned(IP_MIN));
+ STATE <= 3;
+ when 3 =>
+ if (UDP_TX_ACK_local = '1') then
+ -- composed UDP reply. UDP confirmed. awaiting MAC confirmation.
+ STATE <= 4;
+ elsif (UDP_TX_NAK_local = '1') then
+ -- composed UDP reply. NAK from UDP_TX (abnormal). Abort.
+ STATE <= 0;
+ end if;
+ when 4 =>
+ if (MAC_TX_EOF_local = '1') then
+ -- MAC transmission completion confirmed
+ STATE <= 0;
+ end if;
+ when 8 =>
+ TRIGGER_SEARCH_BY_CLIENTID <= '0';
+ if(EVENT2D = '1') then
+ -- search by client ID complete, matching IP request/table index
+ -- write new expiration
+ STATE <= 9;
+ elsif(EVENT2B = '1') then
+ -- no match
+ -- TODO
+ STATE <= 0;
+ end if;
+ when 9 =>
+ -- send DHCPACK
+ PROPOSED_IP_ADDR(7 downto 0) <= FOUND_IP_PLUSMIN;
+ STATE <= 10;
+ when 10 =>
+ if (UDP_TX_ACK_local = '1') then
+ -- composed UDP reply. UDP confirmed. awaiting MAC confirmation.
+ STATE <= 11;
+ elsif(UDP_TX_NAK_local = '1') then
+ -- composed UDP reply. NAK from UDP_TX (abnormal). Abort.
+ STATE <= 0;
+ end if;
+ when 11 =>
+ if (MAC_TX_EOF_local = '1') then
+ -- MAC transmission completion confirmed
+ STATE <= 0;
+ N_DHCPACK <= N_DHCPACK + 1;
+ end if;
+ when 16 =>
+ -- waiting 1 CLK to read/verify the client ID from the table
+ STATE <= 17;
+ when 17 =>
+ -- wait one more CLK to do a large comparison (timing0
+ STATE <= 18;
+ when 18 =>
+ if(DHCP_CLIENT_ID_MATCH = '1') then
+ -- client ID matches information in table
+ -- write new expiration date, send DHCPACK
+ STATE <= 9;
+ else
+ -- abnormal case. IP address to renew is not associated with the correct client ID in the table
+ STATE <= 0;
+ end if;
+ when 24 =>
+ -- correct network.
+ -- waiting 1 CLK to read/verify the client ID from the table
+ STATE <= 25;
+ when 25 =>
+ if(unsigned(DOA) = 0) then
+ -- DHCP server has no record of this client.
+ -- server MUST remain silent
+ STATE <= 0;
+ elsif(DOA(23 downto 0) = DHCP_CLIENT_ID_D(55 downto 32)) and (DOB = DHCP_CLIENT_ID_D(31 downto 0)) then
+ -- client ID matches information in table
+ -- write new expiration date, send DHCPACK
+ STATE <= 9;
+ else
+ -- abnormal case. Requested IP address is not associated with the correct client ID in the table
+ -- send DHCPNAK
+ STATE <= 26;
+ end if;
+ when 26 =>
+ if(UDP_TX_ACK_local = '1') then
+ -- composed UDP reply. UDP confirmed. awaiting MAC confirmation.
+ STATE <= 27;
+ elsif(UDP_TX_NAK_local = '1') then
+ -- composed UDP reply. NAK from UDP_TX (abnormal). Abort.
+ STATE <= 0;
+ end if;
+ when 27 =>
+ if(MAC_TX_EOF_local = '1') then
+ -- MAC transmission completion confirmed
+ STATE <= 0;
+ end if;
+ when others => null;
+ end case;
+ end if;
+ end if;
+end process;
+
+
+PROPOSED_IP_ADDR(31 downto 8) <= IPv4_ADDR(31 downto 8);
+ -- Proposed IP address is always on the same subnet as this server (i.e. same 3 MSBs as this server IPv4_ADDR)
+
+--//-- TABLE ---------------------------------------------------
+-- Each entry comprises 4 * 36-bit locations. 128 entries max.
+-- location0: 8-bit spare + 24-bit client identifier (47:32) + 4-bit spare (parity)
+-- location1: 32-bit client identifier (31:0) + 4-bit spare (parity)
+-- location2: 32-bit TIME (31:0) + 4-bit spare (parity)
+-- location3: spare
+
+-- One table entry per bindable IP address.
+-- IP address binding is implied by the address.
+-- the actual address is in the form IPv4_ADDR for the 3 MSB, and a subnet address between IP_MIN (inclusive)
+-- and IP_MIN + NIPs -1 (inclusive)
+-- For example, if IPv4_ADDR = 172.16.1.3, IP_MIN = 10, NIPs = 10, this DHCP server will assign and keep track of
+-- IP addresses in the range 172.16.1.10 and 172.16.1.19 (inclusive).
+
+RAMB1_1 : BRAM_DP2
+generic map (
+ DATA_WIDTHA => 32,
+ ADDR_WIDTHA => 9,
+ DATA_WIDTHB => 32,
+ ADDR_WIDTHB => 9
+)
+port map(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA,
+ ADDRA => ADDRA(8 downto 0),
+ DIA => DIA,
+ OEA => '1',
+ DOA => DOA,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => WEB,
+ ADDRB => ADDRB(8 downto 0),
+ DIB => DIB,
+ OEB => '1',
+ DOB => DOB
+);
+
+--//-- SEARCH STATE MACHINE ---------------------------------------
+-- search the table based on a client ID
+-- new simplified process for timing 4/5/14 az
+SEARCH_STATE_MACHINE_001a: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ SEARCH_STATE <= 0;
+ elsif(SEARCH_STATE = 0) then
+ if(TRIGGER_SEARCH_BY_CLIENTID = '1') then
+ SEARCH_STATE <= 1;
+ elsif(STATE = 2) then
+ -- (over)write oldest expired entry with this new DHCPDISCOVER client ID
+ SEARCH_STATE <= 2;
+ WEA <= '1';
+ WEB <= '1';
+ elsif(STATE = 9) then
+ -- write new expiration
+ SEARCH_STATE <= 3;
+ WEA <= '1';
+ WEB <= '0';
+ end if;
+ elsif(SEARCH_STATE = 1) then
+ if(ADDRA_PLUS(9) = '1') then
+ -- scan complete
+ SEARCH_STATE <= 0;
+ end if;
+ elsif(SEARCH_STATE = 2) then
+ -- done creating new entry in table with client ID from DHCPDISCOVER
+ SEARCH_STATE <= 0;
+ WEA <= '0';
+ WEB <= '0';
+ elsif(SEARCH_STATE = 3) then
+ -- done updating entry in table with fresh expiration
+ SEARCH_STATE <= 0;
+ WEA <= '0';
+ end if;
+ end if;
+end process;
+
+SEARCH_STATE_MACHINE_001b: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SEARCH_STATE = 0) and (TRIGGER_SEARCH_BY_CLIENTID = '0') then
+ if (STATE = 2) then
+ -- (over)write oldest expired entry with this new DHCPDISCOVER client ID
+ DIA(23 downto 0) <= DHCP_CLIENT_ID_D(55 downto 32);
+ DIB <= DHCP_CLIENT_ID_D(31 downto 0);
+ elsif(STATE = 9) then
+ -- write new expiration
+ DIA <= std_logic_vector(TIME_CNTR + unsigned(LEASE_TIME));
+ end if;
+ end if;
+ end if;
+end process;
+
+-- new simplified process for timing 4/5/14 az
+SEARCH_STATE_MACHINE_001c: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ SEARCH_COMPLETE <= '0';
+ elsif(SEARCH_STATE = 1) and(ADDRA_PLUS(9) = '1') then
+ -- scan complete
+ SEARCH_COMPLETE <= '1'; -- aligned with last search in SEARCH_STATE_D/ADDRA_D
+ else
+ SEARCH_COMPLETE <= '0';
+ end if;
+ end if;
+end process;
+
+ADDRA_PLUS <= std_logic_vector(unsigned(ADDRA) + 2);
+SEARCH_STATE_MACHINE_001d: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SEARCH_STATE = 0) then
+ if(TRIGGER_SEARCH_BY_CLIENTID = '1') then
+ ADDRA <= (others => '0');
+ ADDRB <= (0 => '1', others => '0');
+ elsif(STATE = 2) then
+ -- (over)write oldest expired entry with this new DHCPDISCOVER client ID
+ ADDRA <= FOUND_OLDEST_IP & "00";
+ ADDRB <= FOUND_OLDEST_IP & "01";
+ elsif(STATE = 9) then
+ -- write new expiration
+ ADDRA <= FOUND_IP & "10";
+ elsif(STATE = 16) then
+ -- read client ID from the table (to verify)
+ ADDRA <= std_logic_vector((unsigned(CIADDR(7 downto 0)) - unsigned(IP_MIN)) & "00");
+ ADDRB <= std_logic_vector((unsigned(CIADDR(7 downto 0)) - unsigned(IP_MIN)) & "01");
+ elsif(STATE = 24) then
+ -- read client ID from the table (to verify)
+ ADDRA <= std_logic_vector((unsigned(DHCP_REQUESTED_IP_ADDR(7 downto 0)) - unsigned(IP_MIN)) & "00");
+ ADDRB <= std_logic_vector((unsigned(DHCP_REQUESTED_IP_ADDR(7 downto 0)) - unsigned(IP_MIN)) & "01");
+ end if;
+ elsif(SEARCH_STATE = 1) and(ADDRA_PLUS(9) = '0') then
+ -- scan all 128 positions
+ ADDRA <= ADDRA_PLUS;
+ ADDRB <= std_logic_vector(unsigned(ADDRB) + 2);
+ end if;
+ end if;
+end process;
+
+-- important for better timing. Aligned with ADDRA_D2
+DHCP_CLIENT_ID_MATCH_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ ADDRA_D2 <= ADDRA_D;
+
+ if(DOA(23 downto 0) = DHCP_CLIENT_ID_D(55 downto 32)) and (DOB = DHCP_CLIENT_ID_D(31 downto 0)) then
+ DHCP_CLIENT_ID_MATCH <= '1';
+ else
+ DHCP_CLIENT_ID_MATCH <= '0';
+ end if;
+ end if;
+end process;
+
+SEARCH_STATE_MACHINE_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ ADDRA_D <= ADDRA; -- 1 CLK delay between ADDRA and DOA
+ SEARCH_STATE_D <= SEARCH_STATE;
+ SEARCH_COMPLETE_D <= SEARCH_COMPLETE;
+ FOUND_CLIENT_ID_D <= FOUND_CLIENT_ID;
+
+ if(SYNC_RESET = '1') or (SEARCH_STATE_D2 = 0) then
+ FOUND_CLIENT_ID <= '0';
+ elsif(SEARCH_STATE_D2 = 1) and (DHCP_CLIENT_ID_MATCH = '1') then
+ -- found matching client ID. Aligned with ADDRA_D3
+ FOUND_CLIENT_ID <= '1';
+ FOUND_IP <= ADDRA_D2(9 downto 2); -- to make up the real IP address, add IP_MIN and subnet address
+ elsif(SEARCH_STATE = 0) and (STATE = 16) then
+ -- DHCPREQUEST generated during RENEWING state. save pointer, we'll need it later to write the expiration date
+ FOUND_IP <= std_logic_vector(unsigned(CIADDR(7 downto 0)) - unsigned(IP_MIN));
+ end if;
+ end if;
+end process;
+
+FOUND_IP_PLUSMIN <= std_logic_vector(unsigned(FOUND_IP) + unsigned(IP_MIN));
+
+-- found IP address in table = DHCP requested IP address
+IP_MATCH <= '1' when (FOUND_IP_PLUSMIN = DHCP_REQUESTED_IP_ADDR(7 downto 0)) and (IP_MATCH_MSB = '1') else '0';
+
+-- pipelining for better timing of the above statement
+IP_MATCH_MSB_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(DHCP_REQUESTED_IP_ADDR(31 downto 8) = IPv4_ADDR(31 downto 8)) then
+ IP_MATCH_MSB <= '1';
+ else
+ IP_MATCH_MSB <= '0';
+ end if;
+ end if;
+end process;
+
+
+-- find the oldest expired entry
+SEARCH_STATE_MACHINE_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ SEARCH_STATE_D2 <= SEARCH_STATE_D;
+
+ if(SEARCH_STATE_D = 1) and (unsigned(ADDRA_D(9 downto 2)) = 0) then -- *062516
+ -- first result in the search is the 'oldest' until older ones are found subsequently
+ FOUND_OLDEST_EXPIRATION_TIME <= DOA;
+ FOUND_OLDEST_IP <= ADDRA_D(9 downto 2); -- to make up the real IP address, add IP_MIN and subnet address
+ elsif(SEARCH_STATE_D = 1) and (ADDRA_D(1) = '1') and
+ (FOUND_OLDEST_EXPIRATION_TIME(31 downto 30) = "00") and (DOA(31 downto 30) = "11") then
+ -- found new oldest
+ FOUND_OLDEST_EXPIRATION_TIME <= DOA;
+ FOUND_OLDEST_IP <= ADDRA_D(9 downto 2); -- to make up the real IP address, add IP_MIN and subnet address
+ elsif(SEARCH_STATE_D = 1) and (ADDRA_D(1) = '1') and (DOA < FOUND_OLDEST_EXPIRATION_TIME) then
+ FOUND_OLDEST_EXPIRATION_TIME <= DOA;
+ FOUND_OLDEST_IP <= ADDRA_D(9 downto 2); -- to make up the real IP address, add IP_MIN and subnet address
+ end if;
+ end if;
+end process;
+
+-- is oldest entry expired?
+EXPIRATION_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ SEARCH_COMPLETE_D2 <= SEARCH_COMPLETE_D;
+
+ if(SYNC_RESET = '1') or (SEARCH_STATE_D2 = 0) then
+ EXPIRED_OLDEST_ENTRY <= '0';
+ elsif (FOUND_OLDEST_EXPIRATION_TIME(31 downto 30) = "11") and (TIME_CNTR(31 downto 30) = "00") then
+ -- expired entry
+ EXPIRED_OLDEST_ENTRY <= '1';
+ elsif (unsigned(FOUND_OLDEST_EXPIRATION_TIME) < TIME_CNTR) then
+ -- expired entry
+ EXPIRED_OLDEST_ENTRY <= '1';
+ end if;
+ end if;
+end process;
+
+
+--//-- COMPOSE REPLY TO DHCP CLIENT --------------------------
+-- WPTR is a word counter for the UDP tx payload
+WPTR_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WPTR <= (others => '0');
+ elsif(STATE = 3) or (STATE = 10) or (STATE = 26) then
+ -- DHCPOFFER message
+ -- DHCPACK message
+ -- DHCPNAK message
+ if(UDP_TX_CTS = '1') then
+ WPTR <= WPTR + 1;
+ end if;
+ else
+ WPTR <= (others => '0');
+ end if;
+
+ end if;
+end process;
+
+COMPOSE_TX: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ UDP_TX_DATA_VALID <= X"00";
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ elsif(STATE = 3) and (UDP_TX_CTS = '1') then
+ -- DHCPDISCOVER message
+ -- UDP destination IP address, broadcast
+ DEST_IPv4_ADDR <= x"FFFFFFFF";
+ DEST_MAC_ADDR <= CLIENT_MAC_ADDR;
+ if(WPTR < 34) then
+ UDP_TX_DATA_VALID <= x"FF";
+ elsif(WPTR = 34) then
+ UDP_TX_DATA_VALID <= x"C0";
+ else
+ UDP_TX_DATA_VALID <= x"00";
+ end if;
+ case WPTR is
+ when "0000000" =>
+ UDP_TX_DATA <= x"02010600" & XID4RESPONSE;
+ -- op: BOOTREPLY
+ -- hardware type: Ethernet
+ -- hardware address length
+ -- 00
+ -- XID4RESPONSE
+ UDP_TX_SOF <= '1';
+ when "0000001" =>
+ UDP_TX_DATA <= (others => '0');
+ -- 0000
+ -- unicast flag
+ -- reserved flags
+ -- 00000000
+ UDP_TX_SOF <= '0';
+ when "0000010" =>
+ UDP_TX_DATA <= PROPOSED_IP_ADDR & x"00000000";
+ -- proposed IP address
+ when "0000011" =>
+ UDP_TX_DATA <= GIADDR & CLIENT_MAC_ADDR(47 downto 16);
+ -- GIADDR
+ -- client MAC address
+ when "0000100" =>
+ UDP_TX_DATA <= CLIENT_MAC_ADDR(15 downto 0) & x"000000000000";
+ -- client MAC address
+ when "0011101" =>
+ UDP_TX_DATA(63 downto 32) <= (others => '0');
+ UDP_TX_DATA(31 downto 0) <= MAGIC_COOKIE;
+ when "0011110" =>
+ UDP_TX_DATA <= x"3501023604" & IPv4_ADDR(31 downto 8);
+ -- option DHCP message type (53)
+ -- length
+ -- DHCPOFFER
+ -- option DHCP server identifier (54)
+ -- length
+ -- server IP address
+ when "0011111" =>
+ UDP_TX_DATA <= IPv4_ADDR(7 downto 0) & x"3304" & LEASE_TIME(31 downto 0) & x"01";
+ -- server IP address
+ -- option lease time (51)
+ -- length
+ -- lease time
+ -- option subnet mask (01)
+ when "0100000" =>
+ UDP_TX_DATA <= x"04" & SUBNET_MASK & x"0304" & ROUTER(31 downto 24);
+ -- length
+ -- SUBNET_MASK
+ -- option router (03)
+ -- length
+ -- ROUTER
+ when "0100001" =>
+ UDP_TX_DATA <= ROUTER(23 downto 0) & x"0604" & DNS(31 downto 8);
+ -- ROUTER
+ -- option DNS (06)
+ -- length
+ -- DNS
+ when "0100010" =>
+ UDP_TX_DATA <= DNS(7 downto 0) & x"FF000000000000";
+ -- DNS
+ -- option end (255)
+ UDP_TX_EOF <= '1';
+ when others =>
+ UDP_TX_DATA <= (others => '0');
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ end case;
+
+ elsif(STATE = 10) then
+ -- DHCACK message
+ DEST_IPv4_ADDR <= PROPOSED_IP_ADDR;
+ DEST_MAC_ADDR <= CLIENT_MAC_ADDR;
+ -- UDP destination IP address
+ if(WPTR < 34) then
+ UDP_TX_DATA_VALID <= x"FF";
+ elsif(WPTR = 34) then
+ UDP_TX_DATA_VALID <= x"C0";
+ else
+ UDP_TX_DATA_VALID <= x"00";
+ end if;
+ case WPTR is
+ when "0000000" =>
+ UDP_TX_DATA <= x"02010600" & XID4RESPONSE;
+ -- op: BOOTREPLY
+ -- hardware type: Ethernet
+ -- hardware address length
+ -- 00
+ -- XID4RESPONSE
+ UDP_TX_SOF <= '1';
+ when "0000001" =>
+ UDP_TX_DATA <= (others => '0');
+ -- 0000
+ -- unicast flag
+ -- reserved flags
+ -- 00000000
+ UDP_TX_SOF <= '0';
+ when "0000010" =>
+ UDP_TX_DATA <= PROPOSED_IP_ADDR & x"00000000";
+ -- proposed IP address
+ when "0000011" =>
+ UDP_TX_DATA <= GIADDR & CLIENT_MAC_ADDR(47 downto 16);
+ -- GIADDR
+ -- client MAC address
+ when "0000100" =>
+ UDP_TX_DATA <= CLIENT_MAC_ADDR(15 downto 0) & x"000000000000";
+ -- client MAC address
+ when "0011101" =>
+ UDP_TX_DATA(63 downto 32) <= (others => '0');
+ UDP_TX_DATA(31 downto 0) <= MAGIC_COOKIE;
+ when "0011110" =>
+ UDP_TX_DATA <= x"3501053604" & IPv4_ADDR(31 downto 8);
+ -- option DHCP message type (53)
+ -- length
+ -- DHCPACK
+ -- option DHCP server identifier (54)
+ -- length
+ -- server IP address
+ when "0011111" =>
+ UDP_TX_DATA <= IPv4_ADDR(7 downto 0) & x"3304" & LEASE_TIME(31 downto 0) & x"01";
+ -- server IP address
+ -- option lease time (51)
+ -- length
+ -- lease time
+ -- option subnet mask (01)
+ when "0100000" =>
+ UDP_TX_DATA <= x"04" & SUBNET_MASK & x"0304" & ROUTER(31 downto 24);
+ -- length
+ -- SUBNET_MASK
+ -- option router (03)
+ -- length
+ -- ROUTER
+ when "0100001" =>
+ UDP_TX_DATA <= ROUTER(23 downto 0) & x"0604" & DNS(31 downto 8);
+ -- ROUTER
+ -- option DNS (06)
+ -- length
+ -- DNS
+ when "0100010" =>
+ UDP_TX_DATA <= DNS(7 downto 0) & x"FF000000000000";
+ -- DNS
+ -- option end (255)
+ UDP_TX_EOF <= '1';
+ when others =>
+ UDP_TX_DATA <= (others => '0');
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ end case;
+ elsif(STATE = 26) then
+ -- DHCNAK message
+ DEST_IPv4_ADDR <= PROPOSED_IP_ADDR;
+ -- UDP destination IP address
+ if(unsigned(GIADDR) = 0) then
+ -- client on same subnet as server. Broadcast DHCPNAK
+ DEST_MAC_ADDR <= x"FFFFFFFFFFFF";
+ else
+ DEST_MAC_ADDR <= CLIENT_MAC_ADDR;
+ end if;
+ if(WPTR < 31) then
+ UDP_TX_DATA_VALID <= x"FF";
+ elsif(WPTR = 31) then
+ UDP_TX_DATA_VALID <= x"C0";
+ else
+ UDP_TX_DATA_VALID <= x"00";
+ end if;
+ case WPTR is
+ when "0000000" =>
+ UDP_TX_DATA <= x"02010600" & XID4RESPONSE;
+ -- op: BOOTREPLY
+ -- hardware type: Ethernet
+ -- hardware address length
+ -- 00
+ -- XID4RESPONSE
+ UDP_TX_SOF <= '1';
+ when "0000001" =>
+ UDP_TX_DATA(63 downto 48) <= (others => '0');
+ if(unsigned(GIADDR) /= 0) then
+ -- client on a different subnet. set broadcast flag
+ UDP_TX_DATA(47 downto 40) <= x"80"; -- broadcast flag
+ else
+ UDP_TX_DATA(47 downto 40) <= x"00"; -- unicast flag
+ end if;
+ UDP_TX_DATA(39 downto 0) <= (others => '0');
+ -- 0000
+ -- unicast/broadcast flag
+ -- reserved flags
+ -- 00000000
+ UDP_TX_SOF <= '0';
+ when "0000010" =>
+ UDP_TX_DATA <= PROPOSED_IP_ADDR & x"00000000";
+ -- proposed IP address
+ when "0000011" =>
+ UDP_TX_DATA <= GIADDR & CLIENT_MAC_ADDR(47 downto 16);
+ -- GIADDR
+ -- client MAC address
+ when "0000100" =>
+ UDP_TX_DATA <= CLIENT_MAC_ADDR(15 downto 0) & x"000000000000";
+ -- client MAC address
+ when "0011101" =>
+ UDP_TX_DATA(63 downto 32) <= (others => '0');
+ UDP_TX_DATA(31 downto 0) <= MAGIC_COOKIE;
+ when "0011110" =>
+ UDP_TX_DATA <= x"3501063604" & IPv4_ADDR(31 downto 8);
+ -- option DHCP message type (53)
+ -- length
+ -- DHCPNAK
+ -- option DHCP server identifier (54)
+ -- length
+ -- server IP address
+ when "0011111" =>
+ UDP_TX_DATA <= IPv4_ADDR(7 downto 0) & x"FF000000000000";
+ -- server IP address
+ -- option end (255)
+ when others =>
+ UDP_TX_DATA <= (others => '0');
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ end case;
+ else
+ UDP_TX_DATA_VALID <= X"00";
+ UDP_TX_SOF <= '0';
+ UDP_TX_EOF <= '0';
+ end if;
+ end if;
+end process;
+
+DEST_IPv4_ADDRx <= x"000000000000000000000000" & DEST_IPv4_ADDR;
+UDP_TX_001: UDP_TX_10G
+GENERIC MAP(
+ ADDR_WIDTH => 7, -- elastic buffer size as 72b * 2^ADDR_WIDTH
+ UDP_CKSUM_ENABLED => '1',
+ IPv6_ENABLED => '0'
+)
+PORT MAP(
+ CLK => CLK,
+ SYNC_RESET => SYNC_RESET,
+ TICK_4US => TICK_4US,
+ -- Application interface
+ APP_DATA => UDP_TX_DATA,
+ APP_DATA_VALID => UDP_TX_DATA_VALID,
+ APP_SOF => UDP_TX_SOF,
+ APP_EOF => UDP_TX_EOF,
+ APP_CTS => UDP_TX_CTS,
+ ACK => UDP_TX_ACK_local,
+ NAK => UDP_TX_NAK_local,
+ DEST_IP_ADDR => DEST_IPv4_ADDRx,
+ IPv4_6n => '1',
+ DEST_PORT_NO => x"0044", -- DHCP client port (68)
+ SOURCE_PORT_NO => x"0043", -- DHCP server port (67)
+ -- Configuration
+ MAC_ADDR => MAC_ADDR,
+ IPv4_ADDR => IPv4_ADDR,
+ IPv6_ADDR => (others => '0'),
+ IP_ID => std_logic_vector(IP_ID_IN),
+ -- Routing
+ RT_IP_ADDR => open,
+ RT_IPv4_6n => open,
+ RT_REQ_RTS => open,
+ RT_REQ_CTS => '1',
+ RT_MAC_REPLY => DEST_MAC_ADDR,
+ RT_MAC_RDY => '1',
+ RT_NAK => '0',
+ -- MAC interface
+ MAC_TX_DATA => MAC_TX_DATA,
+ MAC_TX_DATA_VALID => MAC_TX_DATA_VALID,
+ MAC_TX_EOF => MAC_TX_EOF_local,
+ MAC_TX_CTS => MAC_TX_CTS,
+ RTS => RTS,
+ TP => open
+);
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+---- DHCP message check
+---- source IP is 0.0.0.0.
+---- RX_SOURCE_IP_ADDR: in std_logic_vector(31 downto 0);
+---- DHCP source port is 68
+---- Destination IP is 255.x.x.x
+--
+----// CHECK DHCP VALIDITY -----------------------------
+---- validate DHCL rx frame
+---- (a) received frame is a valid UDP frame
+---- (b) source IP address is 0.0.0.0.
+---- (c) received port is 67
+---- (d) source port is 68
+--
+--
+--
+----// TEST POINTS -----------------------------
+----TP(1) <= DHCP_RX_DATA_VALID;
+----TP(2) <= EVENT1;
+----TP(3) <= EVENT2A;
+----TP(4) <= EVENT2B;
+----TP(5) <= EVENT2C;
+----TP(6) <= EVENT2D;
+----TP(7) <= UDP_TX_CTS;
+----TP(8) <= '1' when (STATE = 3) and (UDP_TX_CTS = '1') else '0';
+----TP(9) <= MAC_TX_EOF_local;
+--
+--N_DHCPDISCOVER_OUT <= N_DHCPDISCOVER;
+--N_DHCPREQUEST1_OUT <= N_DHCPREQUEST1;
+--N_DHCPREQUEST2_OUT <= N_DHCPREQUEST2;
+--N_DHCPREQUEST3_OUT <= N_DHCPREQUEST3;
+--N_DHCPACK_OUT <= N_DHCPACK;
+--
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/dp_ram_gis.vhd b/generic_ip/third_party_ip/tcp_server/src/dp_ram_gis.vhd
new file mode 100644
index 0000000..bb51a22
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/dp_ram_gis.vhd
@@ -0,0 +1,228 @@
+-- megafunction wizard: %RAM: 2-PORT%
+-- GENERATION: STANDARD
+-- VERSION: WM1.0
+-- MODULE: altsyncram
+
+-- ============================================================
+-- File Name: dp_ram_gis.vhd
+-- Megafunction Name(s):
+-- altsyncram
+--
+-- Simulation Library Files(s):
+-- altera_mf
+-- ============================================================
+-- ************************************************************
+-- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+--
+-- 18.1.0 Build 625 09/12/2018 SJ Standard Edition
+-- ************************************************************
+
+
+--Copyright (C) 2018 Intel Corporation. All rights reserved.
+--Your use of Intel Corporation's design tools, logic functions
+--and other software and tools, and its AMPP partner logic
+--functions, and any output files from any of the foregoing
+--(including device programming or simulation files), and any
+--associated documentation or information are expressly subject
+--to the terms and conditions of the Intel Program License
+--Subscription Agreement, the Intel Quartus Prime License Agreement,
+--the Intel FPGA IP License Agreement, or other applicable license
+--agreement, including, without limitation, that your use is for
+--the sole purpose of programming logic devices manufactured by
+--Intel and sold by Intel or its authorized distributors. Please
+--refer to the applicable agreement for further details.
+
+
+LIBRARY ieee;
+USE ieee.std_logic_1164.all;
+
+LIBRARY altera_mf;
+USE altera_mf.altera_mf_components.all;
+
+ENTITY dp_ram_gis IS
+ GENERIC (
+ ADDR_WIDTH : natural := 11;
+ DATA_WIDTH : natural := 9
+ );
+ PORT
+ (
+ address_a : IN STD_LOGIC_VECTOR (ADDR_WIDTH-1 DOWNTO 0);
+ address_b : IN STD_LOGIC_VECTOR (ADDR_WIDTH-1 DOWNTO 0);
+ clock : IN STD_LOGIC := '1';
+ data_a : IN STD_LOGIC_VECTOR (DATA_WIDTH-1 DOWNTO 0);
+ data_b : IN STD_LOGIC_VECTOR (DATA_WIDTH-1 DOWNTO 0);
+ wren_a : IN STD_LOGIC := '0';
+ wren_b : IN STD_LOGIC := '0';
+ q_a : OUT STD_LOGIC_VECTOR (DATA_WIDTH-1 DOWNTO 0);
+ q_b : OUT STD_LOGIC_VECTOR (DATA_WIDTH-1 DOWNTO 0)
+ );
+END dp_ram_gis;
+
+
+ARCHITECTURE SYN OF dp_ram_gis IS
+
+ SIGNAL sub_wire0 : STD_LOGIC_VECTOR (DATA_WIDTH-1 DOWNTO 0);
+ SIGNAL sub_wire1 : STD_LOGIC_VECTOR (DATA_WIDTH-1 DOWNTO 0);
+
+BEGIN
+ q_a <= sub_wire0(DATA_WIDTH-1 DOWNTO 0);
+ q_b <= sub_wire1(DATA_WIDTH-1 DOWNTO 0);
+
+ altsyncram_component : altsyncram
+ GENERIC MAP (
+ address_reg_b => "CLOCK0",
+ clock_enable_input_a => "BYPASS",
+ clock_enable_input_b => "BYPASS",
+ clock_enable_output_a => "BYPASS",
+ clock_enable_output_b => "BYPASS",
+ indata_reg_b => "CLOCK0",
+ intended_device_family => "Cyclone V",
+ lpm_type => "altsyncram",
+ numwords_a => 2**ADDR_WIDTH,
+ numwords_b => 2**ADDR_WIDTH,
+ operation_mode => "BIDIR_DUAL_PORT",
+ outdata_aclr_a => "NONE",
+ outdata_aclr_b => "NONE",
+ outdata_reg_a => "UNREGISTERED",
+ outdata_reg_b => "UNREGISTERED",
+ power_up_uninitialized => "FALSE",
+ read_during_write_mode_mixed_ports => "DONT_CARE",
+ read_during_write_mode_port_a => "NEW_DATA_NO_NBE_READ",
+ read_during_write_mode_port_b => "NEW_DATA_NO_NBE_READ",
+ widthad_a => ADDR_WIDTH,
+ widthad_b => ADDR_WIDTH,
+ width_a => DATA_WIDTH,
+ width_b => DATA_WIDTH,
+ width_byteena_a => 1,
+ width_byteena_b => 1,
+ wrcontrol_wraddress_reg_b => "CLOCK0"
+ )
+ PORT MAP (
+ address_a => address_a,
+ address_b => address_b,
+ clock0 => clock,
+ data_a => data_a,
+ data_b => data_b,
+ wren_a => wren_a,
+ wren_b => wren_b,
+ q_a => sub_wire0,
+ q_b => sub_wire1
+ );
+
+
+
+END SYN;
+
+-- ============================================================
+-- CNX file retrieval info
+-- ============================================================
+-- Retrieval info: PRIVATE: ADDRESSSTALL_A NUMERIC "0"
+-- Retrieval info: PRIVATE: ADDRESSSTALL_B NUMERIC "0"
+-- Retrieval info: PRIVATE: BYTEENA_ACLR_A NUMERIC "0"
+-- Retrieval info: PRIVATE: BYTEENA_ACLR_B NUMERIC "0"
+-- Retrieval info: PRIVATE: BYTE_ENABLE_A NUMERIC "0"
+-- Retrieval info: PRIVATE: BYTE_ENABLE_B NUMERIC "0"
+-- Retrieval info: PRIVATE: BYTE_SIZE NUMERIC "8"
+-- Retrieval info: PRIVATE: BlankMemory NUMERIC "1"
+-- Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_A NUMERIC "0"
+-- Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_B NUMERIC "0"
+-- Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_A NUMERIC "0"
+-- Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_B NUMERIC "0"
+-- Retrieval info: PRIVATE: CLRdata NUMERIC "0"
+-- Retrieval info: PRIVATE: CLRq NUMERIC "0"
+-- Retrieval info: PRIVATE: CLRrdaddress NUMERIC "0"
+-- Retrieval info: PRIVATE: CLRrren NUMERIC "0"
+-- Retrieval info: PRIVATE: CLRwraddress NUMERIC "0"
+-- Retrieval info: PRIVATE: CLRwren NUMERIC "0"
+-- Retrieval info: PRIVATE: Clock NUMERIC "0"
+-- Retrieval info: PRIVATE: Clock_A NUMERIC "0"
+-- Retrieval info: PRIVATE: Clock_B NUMERIC "0"
+-- Retrieval info: PRIVATE: IMPLEMENT_IN_LES NUMERIC "0"
+-- Retrieval info: PRIVATE: INDATA_ACLR_B NUMERIC "0"
+-- Retrieval info: PRIVATE: INDATA_REG_B NUMERIC "1"
+-- Retrieval info: PRIVATE: INIT_FILE_LAYOUT STRING "PORT_A"
+-- Retrieval info: PRIVATE: INIT_TO_SIM_X NUMERIC "0"
+-- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone V"
+-- Retrieval info: PRIVATE: JTAG_ENABLED NUMERIC "0"
+-- Retrieval info: PRIVATE: JTAG_ID STRING "NONE"
+-- Retrieval info: PRIVATE: MAXIMUM_DEPTH NUMERIC "0"
+-- Retrieval info: PRIVATE: MEMSIZE NUMERIC "262144"
+-- Retrieval info: PRIVATE: MEM_IN_BITS NUMERIC "0"
+-- Retrieval info: PRIVATE: MIFfilename STRING ""
+-- Retrieval info: PRIVATE: OPERATION_MODE NUMERIC "3"
+-- Retrieval info: PRIVATE: OUTDATA_ACLR_B NUMERIC "0"
+-- Retrieval info: PRIVATE: OUTDATA_REG_B NUMERIC "0"
+-- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0"
+-- Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_MIXED_PORTS NUMERIC "2"
+-- Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_PORT_A NUMERIC "3"
+-- Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_PORT_B NUMERIC "3"
+-- Retrieval info: PRIVATE: REGdata NUMERIC "1"
+-- Retrieval info: PRIVATE: REGq NUMERIC "0"
+-- Retrieval info: PRIVATE: REGrdaddress NUMERIC "0"
+-- Retrieval info: PRIVATE: REGrren NUMERIC "0"
+-- Retrieval info: PRIVATE: REGwraddress NUMERIC "1"
+-- Retrieval info: PRIVATE: REGwren NUMERIC "1"
+-- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
+-- Retrieval info: PRIVATE: USE_DIFF_CLKEN NUMERIC "0"
+-- Retrieval info: PRIVATE: UseDPRAM NUMERIC "1"
+-- Retrieval info: PRIVATE: VarWidth NUMERIC "0"
+-- Retrieval info: PRIVATE: WIDTH_READ_A NUMERIC "64"
+-- Retrieval info: PRIVATE: WIDTH_READ_B NUMERIC "64"
+-- Retrieval info: PRIVATE: WIDTH_WRITE_A NUMERIC "64"
+-- Retrieval info: PRIVATE: WIDTH_WRITE_B NUMERIC "64"
+-- Retrieval info: PRIVATE: WRADDR_ACLR_B NUMERIC "0"
+-- Retrieval info: PRIVATE: WRADDR_REG_B NUMERIC "1"
+-- Retrieval info: PRIVATE: WRCTRL_ACLR_B NUMERIC "0"
+-- Retrieval info: PRIVATE: enable NUMERIC "0"
+-- Retrieval info: PRIVATE: rden NUMERIC "0"
+-- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+-- Retrieval info: CONSTANT: ADDRESS_REG_B STRING "CLOCK0"
+-- Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_A STRING "BYPASS"
+-- Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_B STRING "BYPASS"
+-- Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_A STRING "BYPASS"
+-- Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_B STRING "BYPASS"
+-- Retrieval info: CONSTANT: INDATA_REG_B STRING "CLOCK0"
+-- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V"
+-- Retrieval info: CONSTANT: LPM_TYPE STRING "altsyncram"
+-- Retrieval info: CONSTANT: NUMWORDS_A NUMERIC "4096"
+-- Retrieval info: CONSTANT: NUMWORDS_B NUMERIC "4096"
+-- Retrieval info: CONSTANT: OPERATION_MODE STRING "BIDIR_DUAL_PORT"
+-- Retrieval info: CONSTANT: OUTDATA_ACLR_A STRING "NONE"
+-- Retrieval info: CONSTANT: OUTDATA_ACLR_B STRING "NONE"
+-- Retrieval info: CONSTANT: OUTDATA_REG_A STRING "UNREGISTERED"
+-- Retrieval info: CONSTANT: OUTDATA_REG_B STRING "UNREGISTERED"
+-- Retrieval info: CONSTANT: POWER_UP_UNINITIALIZED STRING "FALSE"
+-- Retrieval info: CONSTANT: READ_DURING_WRITE_MODE_MIXED_PORTS STRING "DONT_CARE"
+-- Retrieval info: CONSTANT: READ_DURING_WRITE_MODE_PORT_A STRING "NEW_DATA_NO_NBE_READ"
+-- Retrieval info: CONSTANT: READ_DURING_WRITE_MODE_PORT_B STRING "NEW_DATA_NO_NBE_READ"
+-- Retrieval info: CONSTANT: WIDTHAD_A NUMERIC "12"
+-- Retrieval info: CONSTANT: WIDTHAD_B NUMERIC "12"
+-- Retrieval info: CONSTANT: WIDTH_A NUMERIC "64"
+-- Retrieval info: CONSTANT: WIDTH_B NUMERIC "64"
+-- Retrieval info: CONSTANT: WIDTH_BYTEENA_A NUMERIC "1"
+-- Retrieval info: CONSTANT: WIDTH_BYTEENA_B NUMERIC "1"
+-- Retrieval info: CONSTANT: WRCONTROL_WRADDRESS_REG_B STRING "CLOCK0"
+-- Retrieval info: USED_PORT: address_a 0 0 12 0 INPUT NODEFVAL "address_a[11..0]"
+-- Retrieval info: USED_PORT: address_b 0 0 12 0 INPUT NODEFVAL "address_b[11..0]"
+-- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT VCC "clock"
+-- Retrieval info: USED_PORT: data_a 0 0 64 0 INPUT NODEFVAL "data_a[63..0]"
+-- Retrieval info: USED_PORT: data_b 0 0 64 0 INPUT NODEFVAL "data_b[63..0]"
+-- Retrieval info: USED_PORT: q_a 0 0 64 0 OUTPUT NODEFVAL "q_a[63..0]"
+-- Retrieval info: USED_PORT: q_b 0 0 64 0 OUTPUT NODEFVAL "q_b[63..0]"
+-- Retrieval info: USED_PORT: wren_a 0 0 0 0 INPUT GND "wren_a"
+-- Retrieval info: USED_PORT: wren_b 0 0 0 0 INPUT GND "wren_b"
+-- Retrieval info: CONNECT: @address_a 0 0 12 0 address_a 0 0 12 0
+-- Retrieval info: CONNECT: @address_b 0 0 12 0 address_b 0 0 12 0
+-- Retrieval info: CONNECT: @clock0 0 0 0 0 clock 0 0 0 0
+-- Retrieval info: CONNECT: @data_a 0 0 64 0 data_a 0 0 64 0
+-- Retrieval info: CONNECT: @data_b 0 0 64 0 data_b 0 0 64 0
+-- Retrieval info: CONNECT: @wren_a 0 0 0 0 wren_a 0 0 0 0
+-- Retrieval info: CONNECT: @wren_b 0 0 0 0 wren_b 0 0 0 0
+-- Retrieval info: CONNECT: q_a 0 0 64 0 @q_a 0 0 64 0
+-- Retrieval info: CONNECT: q_b 0 0 64 0 @q_b 0 0 64 0
+-- Retrieval info: GEN_FILE: TYPE_NORMAL dp_ram_gis.vhd TRUE
+-- Retrieval info: GEN_FILE: TYPE_NORMAL dp_ram_gis.inc FALSE
+-- Retrieval info: GEN_FILE: TYPE_NORMAL dp_ram_gis.cmp TRUE
+-- Retrieval info: GEN_FILE: TYPE_NORMAL dp_ram_gis.bsf FALSE
+-- Retrieval info: GEN_FILE: TYPE_NORMAL tdp_ram_inst.vhd FALSE
+-- Retrieval info: LIB_FILE: altera_mf
diff --git a/generic_ip/third_party_ip/tcp_server/src/icmpv6_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/icmpv6_10G.vhd
new file mode 100644
index 0000000..6d15168
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/icmpv6_10G.vhd
@@ -0,0 +1,418 @@
+-------------------------------------------------------------
+-- MSS copyright 2018
+-- Filename: ICMPV6_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 3/4/18
+-- Inheritance: n/a
+--
+-- description: ICMPV6 protocol, 10Gb
+-- Reads a received IP/ICMP frame on the fly and generate responses (Ethernet format).
+-- Any new received frame is presumed to be a valid ICMPv6 message. Within a few bytes,
+-- information is received as to the real protocol associated with the received packet.
+-- The ping echo generation is immediately cancelled if
+-- (a) not IPv6
+-- (b) invalid target IP (unicast or multicast)
+-- (c) not ICMPv6
+-- (d) ICMPv6 type not a neighbor solicitation
+-- (e) ICMPv6 solicited IP address does not match
+-- (f) erroneous MAC frame
+-- Any follow-on received IP frame is discarded while a valid response awaits transmission in the elastic buffer.
+--
+-- Device utilization (IPv6_ENABLED='1')
+-- FF: 301
+-- LUT: 835
+-- DSP48: 0
+-- 18Kb BRAM: 0
+-- BUFG: 1
+-- Minimum period: 4.683ns (Maximum Frequency: 213.516MHz) Artix7-100T -1 speed grade
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity ICMPV6_10G is
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ -- Must be a global clock. No BUFG instantiation within this component.
+ SYNC_RESET: in std_logic;
+ -- CLK-synchronous reset. MANDATORY!
+
+ --// ICMP frame received
+ IP_RX_DATA: in std_logic_vector(63 downto 0);
+ IP_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_RX_SOF: in std_logic;
+ IP_RX_EOF: in std_logic;
+ IP_RX_WORD_COUNT: in std_logic_vector(10 downto 0);
+
+ --// Partial checks (done in PACKET_PARSING common code)
+ --// basic IP validity check
+ IP_RX_FRAME_VALID: in std_logic;
+ -- The received IP frame is presumed valid until proven otherwise.
+ -- IP frame validity checks include:
+ -- (a) protocol is IP
+ -- (b) unicast or multicast destination IP address matches
+ -- (c) correct IP header checksum (IPv4 only)
+ -- (d) allowed IPv6
+ -- (e) Ethernet frame is valid (correct FCS, dest address)
+ -- Ready at IP_RX_VALID_D (= MAC_RX_DATA_VALID_D3)
+
+ --// Partial checks (done in PACKET_PARSING common code)
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- Packet origin, already parsed in PACKET_PARSING (shared code)
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0); -- IPv4,IPv6,ARP
+
+ --// Configuration data: IP address, MAC address
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- local IP address. 4 bytes for IPv4, 16 bytes for IPv6
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+
+ --// IP type:
+ RX_IPv4_6n: in std_logic;
+ -- IP version. 4 or 6
+ RX_IP_PROTOCOL: in std_logic_vector(7 downto 0);
+ -- read between RX_IP_PROTOCOL_RDY (inclusive)(i.e. before IP_PAYLOAD_SOF) and IP_PAYLOAD_EOF (inclusive)
+ -- most common protocols:
+ -- 0 = unknown, 1 = ICMP, 2 = IGMP, 6 = TCP, 17 = UDP, 41 = IPv6 encapsulation,
+ -- 58 = ICMPv6, 89 = OSPF, 132 = SCTP
+ RX_IP_PROTOCOL_RDY: in std_logic;
+ -- 1 CLK wide pulse.
+
+ --// USER -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended. User should not supply it.
+ -- Synchonous with CLK
+ MAC_TX_DATA: out std_logic_vector(63 downto 0);
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID /= 0
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- data valid
+ MAC_TX_EOF: out std_logic;
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal. The user should check that this
+ -- signal is high before sending the next MAC_TX_DATA byte.
+ RTS: out std_logic;
+ -- '1' when a full or partial packet is ready to be read.
+ -- '0' when output buffer is empty.
+ -- When the user starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of ICMPV6_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+--// STATE MACHINE ------------------
+signal STATE: unsigned(0 downto 0) := (others => '0');
+signal INPUT_ENABLED: std_logic := '1';
+signal IP_RX_WORD_VALID: std_logic := '0';
+signal IP_RX_EOF_D: std_logic := '0';
+
+--// VALIDATE ICMP MESSAGE -----------
+signal VALID_ICMP_MSG0: std_logic := '0';
+signal VALID_ICMP_MSG: std_logic := '0';
+signal NEIGHBOR_SOLICITATION_FLAG: std_logic := '0';
+signal ECHO_REQUEST_FLAG: std_logic := '0';
+signal VALID_NEIGHBOR_SOLICITATION_MSG: std_logic := '0';
+--signal VALID_ECHO_REQUEST_MSG: std_logic := '0';
+signal RX_SOURCE_MAC_ADDR0: std_logic_vector(47 downto 0) := (others => '0');
+signal RX_SOURCE_IP_ADDR0: std_logic_vector(127 downto 0) := (others => '0');
+signal REPLY_CHECKSUM: unsigned(15 downto 0) := (others => '0');
+
+--// ICMP CHECKSUM -----------------
+signal CKSUM_SEQ_CNTR: unsigned(2 downto 0) := "000";
+signal CKSUM_PART1: unsigned(19 downto 0) := (others => '0');
+signal CKSUM_PART2: unsigned(19 downto 0) := (others => '0');
+
+--// ICMP REPLY -----------------
+signal MAC_TX_EOF_local: std_logic := '0';
+signal RPTR: unsigned(5 downto 0) := (others => '0'); -- range 0 - 10
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// STATE MACHINE ------------------
+-- A state machine is needed as this process is memoryless.
+-- State 0 = idle or incoming packet being processed. No tx packet waiting.
+-- State 1 = valid ICMP request. tx packet waiting for tx capacity. Incoming packets are ignored.
+STATE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ STATE <= (others => '0');
+ elsif(IP_RX_EOF_D = '1') and (INPUT_ENABLED = '1') and (VALID_NEIGHBOR_SOLICITATION_MSG = '1') then
+ -- event = valid ICMP message. Ready to send reply when tx channel opens.
+ -- In the mean time, incoming packets are ignored.
+ STATE <= "1";
+ elsif(MAC_TX_EOF_local = '1') then
+ -- event = successfully sent ICMP reply. Reopen input
+ STATE <= "0";
+ end if;
+ end if;
+end process;
+
+INPUT_ENABLED <= '1' when (STATE = 0) else '0';
+
+--// VALIDATE ICMP MESSAGE -----------
+IP_RX_WORD_VALID <= '1' when (unsigned(IP_RX_DATA_VALID) /= 0) else '0';
+
+VALIDITY_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_RX_EOF_D <= IP_RX_EOF;
+
+ if(INPUT_ENABLED = '1') then
+ if(IP_RX_SOF = '1') then
+ -- just received first byte. ICMP message valid until proven otherwise
+ VALID_ICMP_MSG0 <= '1';
+ else
+ if(RX_IPv4_6n = '1') then
+ -- (a) not IPv6
+ VALID_ICMP_MSG0 <= '0';
+ end if;
+ if(RX_IP_PROTOCOL_RDY = '1') and (unsigned(RX_IP_PROTOCOL) /= 58) then
+ -- (c) not ICMPv6
+ VALID_ICMP_MSG0 <= '0';
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+VALID_ICMP_MSG <= VALID_ICMP_MSG0 and IP_RX_FRAME_VALID; -- combine with the other checks done in parsing.vhd
+
+-- Neighbor solicitation flag
+VALIDITY_CHECK_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(INPUT_ENABLED = '1') and (IP_RX_SOF = '1') then
+ NEIGHBOR_SOLICITATION_FLAG <= '1';
+ elsif(INPUT_ENABLED = '1') and (IP_RX_WORD_VALID = '1') then
+ if (unsigned(IP_RX_WORD_COUNT) = 6) and (IP_RX_DATA(63 downto 48) /= x"8700") then
+ -- (e) ICMPv6 type not a neighbor solicitation
+ NEIGHBOR_SOLICITATION_FLAG <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+VALID_NEIGHBOR_SOLICITATION_MSG <= VALID_ICMP_MSG and NEIGHBOR_SOLICITATION_FLAG;
+
+---- Echo (ping) request flag (Note: implemented in PING.VHD)
+--VALIDITY_CHECK_003: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(INPUT_ENABLED = '1') and (IP_RX_SOF = '1') then
+-- ECHO_REQUEST_FLAG <= '1';
+-- elsif(INPUT_ENABLED = '1') and (IP_RX_WORD_VALID = '1') and (unsigned(IP_RX_WORD_COUNT) = 6) and (IP_RX_DATA(63 downto 48) /= x"8000") then
+-- -- (d) ICMPv6 type not an echo request
+-- ECHO_REQUEST_FLAG <= '0';
+-- end if;
+-- end if;
+--end process;
+--VALID_ECHO_REQUEST_MSG <= VALID_ICMP_MSG and ECHO_REQUEST_FLAG;
+
+--// freeze source MAC address and source IP address at the end of the packet
+-- Reason: we don't want subsequent packets to change this information while we are waiting
+-- to send the ICMP reply.
+FREEZE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_SOURCE_MAC_ADDR0 <= (others => '0');
+ RX_SOURCE_IP_ADDR0 <= (others => '0');
+ elsif(IP_RX_EOF = '1') and (INPUT_ENABLED = '1') then
+ RX_SOURCE_MAC_ADDR0 <= RX_SOURCE_MAC_ADDR;
+ RX_SOURCE_IP_ADDR0 <= RX_SOURCE_IP_ADDR;
+ end if;
+ end if;
+end process;
+
+--// ICMP CHECKSUM -----------------
+-- The ICMP reply checksum is computed in two parts: one part at reset, based on the IPv6_ADDR and MAC_ADDR.
+-- The second part is computed for each valid received ICMP message.
+CKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CKSUM_SEQ_CNTR <= "101";
+ elsif(CKSUM_SEQ_CNTR > 0) then
+ CKSUM_SEQ_CNTR <= CKSUM_SEQ_CNTR - 1;
+ end if;
+ end if;
+end process;
+
+CKSUM_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ -- fixed part of the checksum is initialized at reset
+ if(SYNC_RESET = '1') then
+ CKSUM_PART1 <= resize(unsigned(IPv6_ADDR(127 downto 112)& "0"),20) + resize(unsigned(IPv6_ADDR(111 downto 96)& "0"),20);
+ elsif(CKSUM_SEQ_CNTR = "101") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(95 downto 80)& "0"),20) + resize(unsigned(IPv6_ADDR(79 downto 64)& "0"),20);
+ elsif(CKSUM_SEQ_CNTR = "100") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(63 downto 48)& "0"),20) + resize(unsigned(IPv6_ADDR(47 downto 32)& "0"),20);
+ elsif(CKSUM_SEQ_CNTR = "011") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(31 downto 16)& "0"),20) + resize(unsigned(IPv6_ADDR(15 downto 0)& "0"),20);
+ elsif(CKSUM_SEQ_CNTR = "010") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(MAC_ADDR(47 downto 32)),20) + resize(unsigned(MAC_ADDR(31 downto 16)),20);
+ elsif(CKSUM_SEQ_CNTR = "001") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(MAC_ADDR(15 downto 0)),20) + x"EA5B";
+ -- constant is the sum of 3A + 20 + 8800 + 6000 + 0201
+ end if;
+
+ if(MAC_TX_CTS = '1') then
+ -- variable part of the checksum depends on the ICMP message originator
+ case(RPTR) is
+ when "000001" =>
+ CKSUM_PART2 <= CKSUM_PART1 + resize(unsigned(RX_SOURCE_IP_ADDR0(127 downto 112)),20) + resize(unsigned(RX_SOURCE_IP_ADDR0(111 downto 96)),20);
+ when "000010" =>
+ CKSUM_PART2 <= CKSUM_PART2 + resize(unsigned(RX_SOURCE_IP_ADDR0(95 downto 80)),20) + resize(unsigned(RX_SOURCE_IP_ADDR0(79 downto 64)),20);
+ when "000011" =>
+ CKSUM_PART2 <= CKSUM_PART2 + resize(unsigned(RX_SOURCE_IP_ADDR0(63 downto 48)),20) + resize(unsigned(RX_SOURCE_IP_ADDR0(47 downto 32)),20);
+ when "000100" =>
+ CKSUM_PART2 <= CKSUM_PART2 + resize(unsigned(RX_SOURCE_IP_ADDR0(31 downto 16)),20) + resize(unsigned(RX_SOURCE_IP_ADDR0(15 downto 0)),20);
+ when "000101" =>
+ CKSUM_PART2 <= resize(unsigned(CKSUM_PART2(15 downto 0)),20) + resize(unsigned(CKSUM_PART2(19 downto 16)),20);
+ when "000110" =>
+ CKSUM_PART2 <= resize(unsigned(CKSUM_PART2(15 downto 0)),20) + resize(unsigned(CKSUM_PART2(19 downto 16)),20);
+ when others => null;
+ end case;
+ end if;
+ end if;
+end process;
+REPLY_CHECKSUM <= not CKSUM_PART2(15 downto 0);
+
+--// ICMP REPLY -----------------
+--// Generate ICMP reply packet on the fly
+ICMP_RESP_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_TX_DATA <= (others => '0');
+ MAC_TX_DATA_VALID <= (others => '0');
+ MAC_TX_EOF_local <= '0';
+ elsif(MAC_TX_CTS = '1') and (RPTR <= 10) then
+ case(RPTR) is
+
+ when "000000" =>
+ MAC_TX_DATA(63 downto 16) <= RX_SOURCE_MAC_ADDR0;
+ -- destination ethernet address
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ -- our Ethernet address (2 MSBs)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000001" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ -- our Ethernet address (4 LSBs)
+ MAC_TX_DATA(31 downto 0) <= x"86DD6000";
+ -- Ethernet type, hardware type IPv6
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000010" =>
+ MAC_TX_DATA(63 downto 16) <= x"000000203aff";
+ -- ICMPv6,32 bytes header length, hop
+ MAC_TX_DATA(15 downto 0) <= IPv6_ADDR(127 downto 112);
+ -- our source IPv6 address (2 MSBs)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000011" =>
+ MAC_TX_DATA <= IPv6_ADDR(111 downto 48);
+ -- our source IPv6 address (cont'd)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000100" =>
+ MAC_TX_DATA(63 downto 16) <= IPv6_ADDR(47 downto 0);
+ -- our source IPv6 address (LSBs)
+ MAC_TX_DATA(15 downto 0) <= RX_SOURCE_IP_ADDR0(127 downto 112);
+ -- target IP address (2 MSBs)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000101" =>
+ MAC_TX_DATA <= RX_SOURCE_IP_ADDR0(111 downto 48);
+ -- target IP address (cont'd)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000110" =>
+ MAC_TX_DATA(63 downto 16) <= RX_SOURCE_IP_ADDR0(47 downto 0);
+ -- target IP address (LSBs)
+ MAC_TX_DATA(15 downto 0) <= x"8800";
+ -- neighbor advertisement message, code 0
+ MAC_TX_DATA_VALID <= x"FF";
+ when "000111" =>
+ MAC_TX_DATA(63 downto 48) <= std_logic_vector(REPLY_CHECKSUM);
+ -- checksum
+ MAC_TX_DATA(47 downto 16) <= x"60000000";
+ -- router flag = 0, solicited flag = 1, overide cache entry = 1
+ MAC_TX_DATA(15 downto 0) <= IPv6_ADDR(127 downto 112);
+ -- target address
+ MAC_TX_DATA_VALID <= x"FF";
+ when "001000" =>
+ MAC_TX_DATA <= IPv6_ADDR(111 downto 48);
+ -- target IP address (cont'd)
+ MAC_TX_DATA_VALID <= x"FF";
+ when "001001" =>
+ MAC_TX_DATA(63 downto 16) <= IPv6_ADDR(47 downto 0);
+ -- target IP address (LSBs)
+ MAC_TX_DATA(15 downto 0) <= x"0201";
+ -- target link layer address, length 8 bytes
+ MAC_TX_DATA_VALID <= x"FF";
+ when "001010" =>
+ MAC_TX_DATA(63 downto 16) <= MAC_ADDR;
+ MAC_TX_DATA(15 downto 0) <= x"0000";
+ -- our Ethernet address
+ MAC_TX_DATA_VALID <= x"FC";
+ MAC_TX_EOF_local <= '1';
+ when others =>
+ MAC_TX_DATA <= (others => '0');
+ MAC_TX_DATA_VALID <= x"00";
+ MAC_TX_EOF_local <= '0';
+ end case;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ MAC_TX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+--// Sequence reply transmission and Flow control
+-- Request to send when ICMP reply is ready.
+RTS_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RTS <= '0';
+ RPTR <= (others => '0');
+ elsif(IP_RX_EOF_D = '1') and (INPUT_ENABLED = '1') and (VALID_NEIGHBOR_SOLICITATION_MSG = '1') then
+ -- Valid & complete ICMP neighbor solicitation was received. Start reply transmission.
+ RTS <= '1'; -- tell MAC we have a packet to send
+ RPTR <= (others => '0');
+ elsif(MAC_TX_CTS = '1') and (RPTR < 10) then
+ -- Assemble reply on the fly.
+ -- Always Ethernet encapsulation
+ RPTR <= RPTR + 1; -- move read pointer in response to read request
+ elsif(MAC_TX_CTS = '1') and (RPTR = 10) then
+ RPTR <= RPTR + 1; -- move read pointer in response to read request
+ RTS <= '0';
+ end if;
+ end if;
+end process;
+
+--// TEST POINTS --------------------------
+TP(1) <= STATE(0);
+TP(2) <= IP_RX_WORD_VALID;
+TP(3) <= VALID_NEIGHBOR_SOLICITATION_MSG;
+TP(4) <= MAC_TX_EOF_local;
+TP(5) <= MAC_TX_CTS;
+TP(6) <= RPTR(0);
+
+
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/igmp_query_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/igmp_query_10G.vhd
new file mode 100644
index 0000000..4fa6127
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/igmp_query_10G.vhd
@@ -0,0 +1,161 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: IGMP_QUERY_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 4/27/19
+-- Inheritance: IGMP_QUERY.vhd 12/27/14
+--
+-- description: detect a valid IGMP membership query and trigger a response when applicable
+--
+-- Expects the following external validation checks (in PARSING):
+-- MAC address(just multicast bit), IP type, IP header checksum
+-- NO prior validation for complete MAC address, IP multicast destination address, IGMP checksum
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.numeric_std.ALL;
+
+entity IGMP_QUERY_10G is
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ SYNC_RESET: in std_logic;
+
+ --// Configuration
+ MULTICAST_IP_ADDR : IN std_logic_vector(31 downto 0);
+ -- our multicast IP address (just one)
+
+ --// Received IP frame payload
+ -- Excludes MAC layer header and IP header.
+ IP_PAYLOAD_DATA: in std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: in std_logic;
+ IP_PAYLOAD_EOF: in std_logic;
+ IP_PAYLOAD_WORD_COUNT: in std_logic_vector(10 downto 0);
+
+ --// Partial checks (done in PACKET_PARSING common code)
+ --// basic IP validity check
+ IP_RX_FRAME_VALID2: in std_logic;
+ -- As the IP frame validity is checked on-the-fly, the user should always check if
+ -- the IP_RX_FRAME_VALID is high AT THE END of the IP payload frame (IP_PAYLOAD_EOF) to confirm that the
+ -- ENTIRE IP frame is valid.
+ -- The received IP frame is presumed valid until proven otherwise.
+ -- IP frame validity checks include:
+ -- (a) protocol is IP
+ -- (c) correct IP header checksum (IPv4 only)
+ -- (d) allowed IPv6
+ -- (e) Ethernet frame is valid (correct FCS, dest address)
+ -- Note: ignore IP destination check in parsing. We do it within this component.
+ -- Ready at IP_RX_EOF_D2 = IP_PAYLOAD_EOF
+ RX_IP_PROTOCOL: in std_logic_vector(7 downto 0);
+ -- read between RX_IP_PROTOCOL_RDY (inclusive)(i.e. before IP_PAYLOAD_SOF) and IP_PAYLOAD_EOF (inclusive)
+ -- This component responds to protocol 2 = IGMP
+ VALID_MULTICAST_DEST_IP: IN std_logic;
+ VALID_IP_PAYLOAD_CHECKSUM: in std_logic;
+ -- '1' when valid IP payload checksum. Read at IP_RX_EOF_D2 or IP_PAYLOAD_EOF_D
+ RX_DEST_IP_ADDR: in std_logic_vector(31 downto 0);
+ --
+
+ --// Output
+ TRIGGER_RESPONSE: out std_logic;
+ -- aligned with IP_PAYLOAD_EOF_D
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of IGMP_QUERY_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+
+--// CHECK IGMP QUERY VALIDITY -----------------------------
+signal VALID_RX_IGMP0: std_logic := '0';
+signal VALID_RX_IGMP1: std_logic := '0';
+signal VALID_RX_IGMP2: std_logic := '0';
+signal VALID_RX_IGMP: std_logic := '0';
+signal IP_PAYLOAD_EOF_D: std_logic := '0';
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// CHECK IGMP QUERY VALIDITY -----------------------------
+-- The IGMP packet reception is immediately cancelled if
+-- (a) the received packet type is not an IP datagram (done in common code PACKET_PARSING)
+-- (b) invalid destination IP (done in common code PACKET_PARSING)
+-- (c) incorrect IP header checksum (done in common code PACKET_PARSING)
+-- (d) the received IP type is not IGMP
+-- (e) IGMP type is not membership request
+-- (f) IGMP checksum is incorrect
+-- (g) group address in IGMP query does not match our multicast IP address
+
+VALIDITY_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_PAYLOAD_EOF_D <= IP_PAYLOAD_EOF;
+
+ if(IP_PAYLOAD_SOF = '1') then
+ if(unsigned(RX_IP_PROTOCOL) /= 2) then
+ -- (d) the received IP type is not IGMP
+ VALID_RX_IGMP0 <= '0';
+ elsif(IP_PAYLOAD_DATA(63 downto 56) /= x"11") then
+ -- (e) IGMP type is not membership request
+ VALID_RX_IGMP0 <= '0';
+ else
+ VALID_RX_IGMP0 <= '1';
+ end if;
+ end if;
+
+ -- for IGMPv2, IP_PAYLOAD_SOF and IP_PAYLOAD_EOF can be concurrent
+ if(IP_PAYLOAD_EOF = '1') then
+ if (IP_RX_FRAME_VALID2 = '0') then
+ -- invalid IP frame
+ VALID_RX_IGMP1 <= '0';
+ else
+ VALID_RX_IGMP1 <= '1';
+ end if;
+ end if;
+
+ if(IP_PAYLOAD_DATA_VALID(3 downto 0) = x"F") and (unsigned(IP_PAYLOAD_WORD_COUNT) = 1) then
+ -- expecting group address
+ if(RX_DEST_IP_ADDR = x"E0000001") then
+ -- general IGMP query is sent to address 224.0.0.1 (all hosts)
+ -- The group field is zeroed when sending a General Query
+ if (unsigned(IP_PAYLOAD_DATA(31 downto 0)) = 0) then
+ VALID_RX_IGMP2 <= '1';
+ else
+ -- invalid combination of zero group field and unexpected destination IP address
+ VALID_RX_IGMP2 <= '0';
+ end if;
+ elsif(IP_PAYLOAD_DATA(31 downto 0) /= MULTICAST_IP_ADDR) then
+ -- group-specific IGMP query
+ -- (g) group address does not match our multicast IP address
+ VALID_RX_IGMP2 <= '0';
+ else
+ VALID_RX_IGMP2 <= '1';
+ end if;
+ end if;
+ end if;
+end process;
+-- combine with the other checks done in parsing.vhd
+VALID_RX_IGMP <= VALID_RX_IGMP0 and VALID_RX_IGMP1 and VALID_RX_IGMP2 and
+ VALID_MULTICAST_DEST_IP and VALID_IP_PAYLOAD_CHECKSUM;
+
+-- trigger a response to a query
+TRIGGER_RESPONSE <= VALID_RX_IGMP and IP_PAYLOAD_EOF_D;
+
+--// Test Point
+TP(1) <= IP_PAYLOAD_EOF_D;
+TP(2) <= VALID_RX_IGMP0;
+TP(3) <= VALID_RX_IGMP1;
+TP(4) <= VALID_RX_IGMP2;
+TP(6) <= VALID_RX_IGMP;
+TP(7) <= VALID_RX_IGMP and IP_PAYLOAD_EOF_D;
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/igmp_report_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/igmp_report_10G.vhd
new file mode 100644
index 0000000..d8c7a48
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/igmp_report_10G.vhd
@@ -0,0 +1,267 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: IGMP_REPORT_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 4/28/19
+-- Inheritance: IGMP_REPORT.VHD rev1 12/26/12
+--
+-- description: send an IGMP membership report out to whom it may concern
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.numeric_std.all;
+
+entity IGMP_REPORT_10G is
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ SYNC_RESET: in std_logic;
+ -- CLK-synchronous reset. MANDATORY after IPv4_ADDR and MULTICAST_IP_ADDR are defined.
+
+ --// Control
+ IGMP_START: in std_logic;
+ -- 1 CLK pulse to start the IGMP report
+ -- new requests will be ignored until the module is
+ -- finished with the previous request.
+
+ --// Configuration data: IP address, MAC address
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ -- local IP address
+ -- Natural order (MSB) 172.16.1.128 (LSB)
+ IP_ID: in std_logic_vector(15 downto 0);
+ -- 16-bit IP ID, unique for each IP frame. Incremented every time
+ -- an IP frame is sent .
+ MULTICAST_IP_ADDR : IN std_logic_vector(31 downto 0);
+ -- multicast IP address to report.
+
+ --// Transmit frame/packet to MAC interface
+ -- 32-bit CRC is automatically appended. User should not supply it.
+ -- Synchonous with CLK
+ MAC_TX_DATA: out std_logic_vector(63 downto 0);
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID /= 0
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- data valid
+ MAC_TX_EOF: out std_logic;
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal. The user should check that this
+ -- signal is high before sending the next MAC_TX_DATA byte.
+ RTS: out std_logic;
+ -- '1' when a full or partial packet is ready to be read.
+ -- '0' when output buffer is empty.
+ -- When the user starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of IGMP_REPORT_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+
+signal STATE: std_logic := '0';
+signal TX_PACKET_SEQUENCE: unsigned(4 downto 0) := (others => '1'); -- 46 bytes max
+signal MAC_TX_DATA_VALID_E: std_logic := '0';
+signal MAC_TX_EOF_local: std_logic := '0';
+signal RTS_local: std_logic := '0';
+signal IP_ID_D: std_logic_vector(15 downto 0):= (others => '0');
+
+--// ICMP CHECKSUM -----------------
+signal CKSUM_SEQ_CNTR: unsigned(1 downto 0) := (others => '0');
+signal IP_HEADER_CKSUM0: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CKSUM_FINAL: unsigned(17 downto 0) := (others => '0');
+signal IGMP_CKSUM: unsigned(17 downto 0) := (others => '0');
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+TX_SEQUENCE_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or ((IGMP_START = '1') and (STATE = '0')) or (MAC_TX_EOF_local = '1') then
+ TX_PACKET_SEQUENCE <= (others => '1');
+ MAC_TX_DATA_VALID_E <= '0';
+ elsif(STATE = '1') and (MAC_TX_CTS = '1') then
+ -- read the next word
+ TX_PACKET_SEQUENCE <= TX_PACKET_SEQUENCE + 1;
+ MAC_TX_DATA_VALID_E <= '1';
+ else
+ MAC_TX_DATA_VALID_E <= '0';
+ end if;
+ end if;
+end process;
+
+-- aligned with MAC_TX_DATA_VALID
+MAX_TX_EOF_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_TX_EOF_local = '1') then
+ MAC_TX_EOF_local <= '0';
+ MAC_TX_DATA_VALID <= x"00";
+ elsif(MAC_TX_DATA_VALID_E = '1') then
+ if(TX_PACKET_SEQUENCE = 5) then
+ -- IGMP report done. transmitting the last word (46-bytes)
+ MAC_TX_DATA_VALID <= x"FC"; -- last word contains only 6 bytes
+ MAC_TX_EOF_local <= '1';
+ else
+ MAC_TX_DATA_VALID <= x"ff";
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ MAC_TX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+-- State machine
+RTS_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RTS_local <= '0';
+ STATE <= '0';
+ else
+ if(IGMP_START = '1') and (STATE = '0') then
+ -- new transaction. Sending IGMP report
+ RTS_local <= '1';
+ STATE <= '1';
+ -- freeze IP_ID
+ IP_ID_D <= IP_ID;
+ elsif(MAC_TX_EOF_local = '1') then
+ -- done. transmitting the last word
+ RTS_local <= '0';
+ STATE <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+RTS <= RTS_local;
+
+----// Generate IGMP report
+MAC_TX_DATA_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_TX_DATA <= (others => '0');
+ elsif(MAC_TX_CTS = '1') then
+ case TX_PACKET_SEQUENCE is
+ -- Ethernet header
+ when "00000" =>
+ -- reserved a block of Ethernet addresses that map on to the Class D multicast addresses
+ -- The reserved address 0x0100.5e00.0000 is used by Ethernet to determine a unique multicast MAC
+ -- destination MAC address: multicast.
+ MAC_TX_DATA(63 downto 39) <= x"01005E" & "0";
+ MAC_TX_DATA(38 downto 16) <= MULTICAST_IP_ADDR(22 downto 0);
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ when "00001" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ MAC_TX_DATA(31 downto 0) <= x"08004600"; -- Ethernet type, IP version 4, 24-byte header length, DSCP 0
+ when "00010" =>
+ MAC_TX_DATA(63 downto 48) <= x"0020"; -- total length 32
+ MAC_TX_DATA(47 downto 32) <= IP_ID_D;
+ MAC_TX_DATA(31 downto 0) <= x"00000102"; -- flags, fragment offset, TTL always 1, protocol IGMP
+ when "00011" =>
+ MAC_TX_DATA(63 downto 48) <= std_logic_vector(IP_HEADER_CKSUM_FINAL(15 downto 0)); -- IP header checksum
+ MAC_TX_DATA(47 downto 16) <= IPv4_ADDR; -- sender IP address
+ MAC_TX_DATA(15 downto 0) <= MULTICAST_IP_ADDR(31 downto 16); -- multicast IP address being reported
+ when "00100" =>
+ MAC_TX_DATA(63 downto 48) <= MULTICAST_IP_ADDR(15 downto 0); -- multicast IP address being reported
+ -- options
+ MAC_TX_DATA(47 downto 16) <= x"94040000"; -- router alert: every router examines packet
+ -- IGMPv2
+ MAC_TX_DATA(15 downto 0) <= x"1600"; -- membership report, maximum response time
+ when others =>
+ --when "00101" =>
+ MAC_TX_DATA(63 downto 48) <= std_logic_vector(IGMP_CKSUM(15 downto 0)); -- IP checksum
+ MAC_TX_DATA(47 downto 16) <= MULTICAST_IP_ADDR; -- group address
+ MAC_TX_DATA(15 downto 0) <= (others => '0');
+ end case;
+ end if;
+ end if;
+end process;
+
+--// IP HEADER CHECKSUM -----------------
+-- Computed at reset, since all the information is fixed (except for IP_ID which changes at every message)
+CKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CKSUM_SEQ_CNTR <= "11";
+ elsif(CKSUM_SEQ_CNTR > 0) then
+ CKSUM_SEQ_CNTR <= CKSUM_SEQ_CNTR - 1;
+ end if;
+ end if;
+end process;
+
+IP_HEADER_CKSUM_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ -- fixed part of the IP header checksum.
+ if(SYNC_RESET = '1') then
+ IP_HEADER_CKSUM0 <= resize(unsigned(IPv4_ADDR(31 downto 16)),18) + resize(unsigned(IPv4_ADDR(15 downto 0)),18);
+ elsif(CKSUM_SEQ_CNTR = "11") then
+ IP_HEADER_CKSUM0 <= IP_HEADER_CKSUM0 + resize(unsigned(MULTICAST_IP_ADDR(31 downto 16)),18);
+ elsif(CKSUM_SEQ_CNTR = "10") then
+ IP_HEADER_CKSUM0 <= IP_HEADER_CKSUM0 + resize(unsigned(MULTICAST_IP_ADDR(15 downto 0)),18);
+ elsif(CKSUM_SEQ_CNTR = "01") then
+ IP_HEADER_CKSUM0 <= IP_HEADER_CKSUM0 + ("00" & x"DB26");
+ -- constant is the sum of x4600 + x0020 + x0102 + x9404
+ end if;
+
+ -- variable part of the IP header checksum. Add IP_ID
+ if(MAC_TX_CTS = '1') then
+ if(TX_PACKET_SEQUENCE = "00000") then
+ IP_HEADER_CKSUM_FINAL <= IP_HEADER_CKSUM0 + resize(unsigned(IP_ID_D), 18);
+ elsif(TX_PACKET_SEQUENCE = "00001") then
+ -- carry, first pass
+ IP_HEADER_CKSUM_FINAL <= resize(IP_HEADER_CKSUM_FINAL(15 downto 0), 18) + resize(IP_HEADER_CKSUM_FINAL(17 downto 16), 18);
+ elsif(TX_PACKET_SEQUENCE = "00010") then
+ -- final carry + final inversion
+ IP_HEADER_CKSUM_FINAL <= not(resize(IP_HEADER_CKSUM_FINAL(15 downto 0), 18) + resize(IP_HEADER_CKSUM_FINAL(17 downto 16), 18));
+ end if;
+ end if;
+ end if;
+end process;
+
+IGMP_CKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ -- fixed part of the IGMP checksum.
+ if(SYNC_RESET = '1') then
+ IGMP_CKSUM <= resize(unsigned(MULTICAST_IP_ADDR(31 downto 16)),18) + resize(unsigned(MULTICAST_IP_ADDR(15 downto 0)),18);
+ elsif(CKSUM_SEQ_CNTR = "11") then
+ IGMP_CKSUM <= IGMP_CKSUM + ("00" & x"1600");
+ -- constant
+ elsif(CKSUM_SEQ_CNTR = "10") then
+ -- possible carry + final inversion
+ IGMP_CKSUM <= not(resize(IGMP_CKSUM(15 downto 0), 18) + resize(IGMP_CKSUM(17 downto 16), 18));
+ end if;
+ end if;
+end process;
+
+
+--// Test Point
+--TP(1) <= IGMP_START;
+--TP(2) <= MAC_TX_CTS;
+--TP(3) <= MAC_TX_DATA_VALID_E;
+--TP(4) <= MAX_TX_EOF_local;
+--TP(5) <= RTS_local;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/packet_parsing_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/packet_parsing_10G.vhd
new file mode 100644
index 0000000..44c9282
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/packet_parsing_10G.vhd
@@ -0,0 +1,1351 @@
+-------------------------------------------------------------
+-- MSS copyright 2003-2019
+-- Filename: PACKET_PARSING_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 2
+-- Date last modified: 6/7/19
+-- Inheritance: COM-5402 PACKET_PARSING.VHD rev 8 12/10/15
+--
+-- description: Common code. This component parses the received packets from the MAC
+-- and extracts key information shared by all protocols.
+-- Reads receive packet structure on the fly and detect the following
+-- (a) encapsulation: ethernet (RFC 894) or 802.2/802.3 (RFC 1042)
+-- (b) type: 0800 IP datagram, 0806 ARP request/reply, 8035 RARP request/reply
+-- (c) IP address match
+-- (d) IP port match
+-- (e) IP protocol detected: ICMP, UDP, TCP-IP
+-- (f) IP checksum verification
+-- (g) UDP checksum verification
+-- It also saves the source IP/source LAN address on the fly to avoid doing ARPs
+-- This module includes all checks which could be performed in multiple protocol modules.
+-- The goal is to share these checks to save implementation gates.
+-- Each protocol layer is associated with one CLK latency.
+--
+-- Limitations: 802.3/802.2 encapsulation is only detected, not supported for any protocol.
+--
+-- Rev1 4/30/19 AZ
+-- Added IP payload checksum computation
+-- Added IPv4 broadcast address check (needed for DHCP)
+--
+-- Rev 2 6/7/19 AZ
+-- corrected bug clearing IPv4_PROTOCOL too early in very small frame and adjacent frames (no gap)
+--
+-- Device utilization (IPv6_ENABLED='1')
+-- FF: 850
+-- LUT: 1468
+-- DSP48: 0
+-- 18Kb BRAM: 0
+-- BUFG: 1
+-- Minimum period: 6.586ns (Maximum Frequency: 151.837MHz) Artix7-100T -1 speed grade
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity PACKET_PARSING_10G is
+ generic (
+ IPv6_ENABLED: std_logic := '1';
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ SIMULATION: std_logic := '0'
+ -- 1 during simulation with Wireshark .cap file, '0' otherwise
+ -- Wireshark many not be able to collect offloaded checksum computations.
+ -- when SIMULATION = '1':
+ -- (a) IP header checksum is valid if 0000,
+ -- (b) TCP checksum computation is forced to a valid 00001 irrespective of the 16-bit checksum
+ -- captured by Wireshark.
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ SYNC_RESET: in std_logic;
+
+ --// RECEIVED MAC FRAME ---------------------------------------------
+ MAC_RX_DATA: in std_logic_vector(63 downto 0);
+ -- USER reads the data at the rising edge of CLK when MAC_RX_DATA_VALID /= 0
+ -- Bytes order: MSB was received first
+ -- Bytes are left aligned: first byte in MSB, occasional follow-on fill-in Bytes in the LSB(s)
+ -- The first destination address byte is always a MSB (MAC_RX_DATA(7:0))
+ MAC_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ MAC_RX_SOF: in std_logic;
+ -- Start of Frame: one CLK-wide pulse indicating the first word in the received frame
+ -- aligned with MAC_RX_DATA_VALID.
+ MAC_RX_EOF: in std_logic;
+ -- End of Frame: one CLK-wide pulse indicating the last word in the received frame
+ -- aligned with MAC_RX_DATA_VALID.
+ MAC_RX_FRAME_VALID: in std_logic;
+ -- MAC frame integrity verification (at the end of frame)
+ MAC_RX_WORD_COUNT: out std_logic_vector(10 downto 0);
+ -- MAC word counter, 1 CLK after the input. 0 is the first word.
+
+ --// local IP address
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- local IP address. 4 bytes for IPv4, 16 bytes for IPv6
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+ IPv4_MULTICAST_ADDR: in std_logic_vector(31 downto 0);
+ -- to receive UDP multicast messages. One multicast address only
+ -- 0.0.0.0 to signify that IP multicasting is not supported here.
+
+ --// RECEIVED IP FRAME --------------------------------------------
+ -- Excludes MAC layer header. Includes IP header.
+ IP_RX_DATA: out std_logic_vector(63 downto 0);
+ IP_RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ IP_RX_SOF: out std_logic;
+ IP_RX_EOF: out std_logic;
+ IP_RX_WORD_COUNT: out std_logic_vector(10 downto 0);
+ IP_HEADER_FLAG: out std_logic_vector(1 downto 0);
+ -- bit 1 is for the upper 32-bit
+ -- bit 0 lower 32-bit
+
+ --// Received type
+ RX_TYPE: out std_logic_vector(3 downto 0);
+ -- Information stays until start of following packet.
+ -- 0 = unknown type
+ -- 1 = Ethernet encapsulation, IPv4 datagram
+ -- 2 = Ethernet encapsulation, ARP request/reply
+ -- 3 = Ethernet encapsulation, RARP request/reply
+ -- 5 = Ethernet encapsulation, IPv6 datagram
+ -- 9 = IEEE 802.3/802.2 encapsulation, IPv4 datagram (almost never used)
+ -- 10 = IEEE 802.3/802.2 encapsulation, ARP request/reply (almost never used)
+ -- 11 = IEEE 802.3/802.2 encapsulation, RARP request/reply (almost never used)
+ -- 13 = IEEE 802.3/802.2 encapsulation, IPv6 datagram (almost never used)
+ RX_TYPE_RDY: out std_logic;
+ -- 1 CLK-wide pulse indicating that a detection was made on the received packet
+ -- type, and that RX_TYPE can be read.
+ -- Detection occurs as soon as possible, two clocks after receiving byte 13 or 21.
+
+ --// IP type:
+ RX_IPv4_6n: out std_logic;
+ -- IP version. 4 or 6
+ RX_IP_PROTOCOL: out std_logic_vector(7 downto 0);
+ -- read between RX_IP_PROTOCOL_RDY (inclusive)(i.e. before IP_PAYLOAD_SOF) and IP_PAYLOAD_EOF (inclusive)
+ -- most common protocols:
+ -- 0 = unknown, 1 = ICMP, 2 = IGMP, 6 = TCP, 17 = UDP, 41 = IPv6 encapsulation,
+ -- 58 = ICMPv6, 89 = OSPF, 132 = SCTP
+ RX_IP_PROTOCOL_RDY: out std_logic;
+ -- 1 CLK wide pulse.
+
+ --// basic IP validity check
+ IP_RX_FRAME_VALID: out std_logic;
+ IP_RX_FRAME_VALID2: out std_logic;
+ -- The received IP frame is presumed valid until proven otherwise.
+ -- IP frame validity checks include:
+ -- (a) protocol is IP
+ -- (b) unicast or multicast destination IP address matches
+ -- (c) correct IP header checksum (IPv4 only)
+ -- (d) allowed IPv6
+ -- (e) Ethernet frame is valid (correct FCS, dest address)
+ -- Also compute IP_RX_FRAME_VALID2 (no IP destination check)
+ -- Ready at IP_RX_EOF_D2
+
+ --// Destination IP check for IP datagram
+ -- IP is checked only for IP datagrams (RX_TYPE 1,5)
+ -- Check is against unicast or multicast IP address IPv4_ADDR, IPv6_ADDR, or IPv4_MULTICAST_ADDR
+ VALID_UNICAST_DEST_IP: out std_logic;
+ VALID_MULTICAST_DEST_IP: out std_logic;
+ -- 1 = valid , 0 = invalid. Read when VALID_DEST_IP_RDY = '1'
+ -- IPv4: checks match against IPv4_MULTICAST_ADDR and IP broadcast (full or subnet) address
+ -- IPv6: checks match against solicited-node multicast IP FF02....+lower 24-bit of unicast IP
+ VALID_DEST_IP_RDY : out std_logic;
+ -- 1 CLK wide pulse.
+
+ --// IP header checksum verification
+ IP_HEADER_CHECKSUM_VALID: out std_logic;
+ IP_HEADER_CHECKSUM_VALID_RDY: out std_logic;
+
+ --// Packet origin, already parsed in PACKET_PARSING (shared code)
+ RX_SOURCE_MAC_ADDR: out std_logic_vector(47 downto 0); -- all received packets
+ RX_SOURCE_IP_ADDR: out std_logic_vector(127 downto 0); -- IPv4,IPv6,ARP
+ RX_DEST_IP_ADDR: out std_logic_vector(127 downto 0);
+
+ --// RECEIVED IP PAYLOAD ---------------------------------------------
+ IP_PAYLOAD_DATA: out std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: out std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: out std_logic;
+ IP_PAYLOAD_EOF: out std_logic;
+ IP_PAYLOAD_LENGTH: out std_logic_vector(15 downto 0);
+ -- payload length in bytes (i.e. excluding MAC and IP headers)
+ IP_PAYLOAD_WORD_COUNT: out std_logic_vector(10 downto 0);
+ -- 2 CLKs latency w.r.t. IP_RX_DATA
+ VALID_IP_PAYLOAD_CHECKSUM: out std_logic;
+ -- '1' when valid IP payload checksum. Read at IP_RX_EOF_D2 or IP_PAYLOAD_EOF_D
+ -- verified only for IGMP messages
+
+ --// UDP attributes
+ VALID_UDP_CHECKSUM: out std_logic;
+ -- '1' when valid UDP checksum(including pseudo-header). Read at IP_RX_EOF_D2 or IP_PAYLOAD_EOF_D
+ -- verified only for UDP messages
+
+ --// TCP attributes
+ VALID_TCP_CHECKSUM: out std_logic;
+ -- '1' when valid TCP checksum(including pseudo-header). Read at IP_RX_EOF_D2 or IP_PAYLOAD_EOF_D
+ -- verified only for TCP messages
+
+ --// TEST POINTS, COMSCOPE TRACES
+ CS1: out std_logic_vector(7 downto 0);
+ CS1_CLK: out std_logic;
+ CS2: out std_logic_vector(7 downto 0);
+ CS2_CLK: out std_logic;
+ TP: out std_logic_vector(10 downto 1) := (others => '0')
+
+ );
+end entity;
+
+architecture Behavioral of PACKET_PARSING_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- NOTATIONS:
+-- _E as one-CLK early sample
+-- _D as one-CLK delayed sample
+-- _D2 as two-CLKs delayed sample
+
+--// WORD COUNT ----------------------
+signal MAC_RX_DATA_VALID_D: std_logic_vector(7 downto 0):= (others => '0');
+signal MAC_RX_WORD_VALID_D: std_logic := '0';
+signal MAC_RX_SOF_D: std_logic := '0';
+signal MAC_RX_EOF_D: std_logic := '0';
+signal MAC_RX_DATA_D: std_logic_vector(63 downto 0) := (others => '0');
+signal MAC_RX_WORD_COUNT_local: unsigned(10 downto 0):= (others => '0');
+
+--// TYPE ---------------------------------
+signal RX_TYPE_FIELD_D: std_logic_vector(15 downto 0) := (others => '0');
+signal RX_TYPE_local: unsigned(3 downto 0) := x"0";
+signal RX_TYPE_RDY_local: std_logic := '0';
+
+--// SOURCE MAC ADDRESS ------------------------------------
+signal RX_SOURCE_MAC_ADDR_local: std_logic_vector(47 downto 0) := (others => '0');
+
+--// IP DATA -------------------------------------
+signal MAC_RX_SOF_D2: std_logic := '0';
+signal IP_RX_DATA_CACHE: std_logic_vector(63 downto 48) := (others => '0');
+signal IP_RX_DATA_CACHE_VALID: std_logic_vector(7 downto 6) := (others => '0');
+signal IP_RX_DATA0: std_logic_vector(63 downto 0) := (others => '0');
+signal IP_RX_DATA_local: std_logic_vector(63 downto 0) := (others => '0');
+signal IP_RX_WORD_VALID_local: std_logic := '0';
+signal IP_RX_SOF_local: std_logic := '0';
+signal IP_RX_EOF0: std_logic := '0';
+signal IP_RX_EOF_local: std_logic := '0';
+signal IP_RX_EOF_D: std_logic := '0';
+
+signal IP_RX_WORD_COUNT_local: unsigned(10 downto 0):= (others => '0');
+signal IP_RX_FLUSH_CACHE: std_logic := '0';
+signal IP_RX_DATA_VALID0: std_logic_vector(7 downto 0) := (others => '0');
+signal IP_RX_DATA_VALID_local: std_logic_vector(7 downto 0) := (others => '0');
+signal IP_RX_MASK_ETH_PADS: std_logic_vector(7 downto 0) := (others => '0');
+
+--// IP PROTOCOL ----------------------
+signal RX_IPv4_6n_local: std_logic := '1';
+signal RX_IP_PROTOCOL_local: std_logic_vector(7 downto 0) := x"00";
+signal IPv4_PROTOCOL: std_logic_vector(7 downto 0) := x"00";
+signal IPv4_PROTOCOL_RDY: std_logic := '0';
+signal IPv6_PROTOCOL: std_logic_vector(7 downto 0) := x"00";
+signal IPv6_PROTOCOL_RDY: std_logic := '0';
+
+--// IPv6 HEADER PARSING ---------------------------------------
+signal IPv6_HEADER_FLAG: std_logic := '0';
+signal IPv6_HEADER_WORD_CNTR: unsigned(7 downto 0):= (others => '0');
+signal IPv6_NEXT_HEADER: std_logic_vector(7 downto 0) := (others => '0');
+signal IP_HEADER_FLAG_local: std_logic_vector(1 downto 0) := (others => '0');
+
+--// IPv4 HEADER PARSING ---------------------------------------
+signal IPv4_HEADER_N32bWORDS: unsigned(3 downto 0) := (others => '0'); -- expressed in 32-bit words. read/use at MAC_RX_DATA_VALID_D3
+signal IPv4_HEADER_N32bWORDS_D: unsigned(3 downto 0) := (others => '0'); -- expressed in 32-bit words. read/use at MAC_RX_DATA_VALID_D3
+signal IPv4_HEADER_N32bWORDS_DEC: unsigned(3 downto 0) := (others => '0');
+signal IPv4_HEADER_MASK_A: std_logic_vector(1 downto 0) := (others => '0');
+signal IPv4_HEADER_MASK: std_logic_vector(1 downto 0) := (others => '0');
+signal IPv4_HEADER_MASK_D: std_logic_vector(1 downto 0) := (others => '0');
+--signal IPv4_HEADER_DATA: std_logic_vector(63 downto 0) := (others => '0');
+signal IPv4_RX_EOH: std_logic := '0';
+signal IPv4_RX_EOH_D: std_logic := '0';
+signal IP_TOTAL_LENGTH_DEC: unsigned(15 downto 0) := (others => '0');
+
+----// IP BYTE COUNT ----------------------
+--signal MAC_RX_EOF_D2: std_logic := '0';
+--signal MAC_RX_DATA_D2: std_logic_vector(7 downto 0) := x"00";
+--signal IP_FRAME_FLAG: std_logic := '0'; -- read/use at MAC_RX_DATA_VALID_D2
+--signal IP_HEADER_FLAG_E: std_logic := '0';
+--signal IP_FRAME_FLAG_E: std_logic := '0';
+--signal IP_RX_EOF_E: std_logic := '0';
+
+
+
+--// VALIDATE IP ADDRESS ----------------------
+signal VALID_UNICAST_DEST_IP_local: std_logic := '0';
+signal VALID_UNICAST_DEST_IP_MSBS: std_logic := '0';
+signal VALID_MULTICAST_DEST_IP_local: std_logic := '0';
+signal VALID_MULTICAST_DEST_IP_MSBS: std_logic := '0';
+signal VALID_DEST_IP_RDY_local: std_logic := '0';
+signal IP_ADDR_local: std_logic_vector(127 downto 0) := x"00000000000000000000000000000000";
+
+--// VALIDATE IP HEADER CHECKSUM ----------------------
+signal IP_RX_DATA_SUM_MSW: unsigned(17 downto 0) := (others => '0');
+signal IP_RX_DATA_SUM_LSW: unsigned(17 downto 0) := (others => '0');
+signal TYPE_FIELD_D2: std_logic_vector(15 downto 0) := (others => '0');
+signal HCKSUM1: unsigned(17 downto 0) := (others => '0');
+signal HCKSUM2: unsigned(17 downto 0) := (others => '0');
+signal HCKSUM3: unsigned(5 downto 0) := (others => '0');
+signal HCKSUM3_PLUS: unsigned(5 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM_FINAL: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM: unsigned(17 downto 0) := (others => '0'); -- 16-bit sum + carry
+signal IP_HEADER_CHECKSUM_VALID_local: std_logic := '0'; -- read/use at MAC_RX_DATA_VALID_D3
+signal IP_HEADER_CHECKSUM_VALID_RDY_local: std_logic := '0'; -- read/use at MAC_RX_DATA_VALID_D3
+
+--// IP LENGTH ----------------------
+signal IP_PAYLOAD_LENGTH_local: unsigned(15 downto 0) := x"0000"; -- IP payload length in bytes
+signal IP_PAYLOAD_LENGTH_RDY: std_logic := '0';
+
+--// SOURCE & DESTINATION IP ADDRESS -------------------------
+signal RX_SOURCE_IP_ADDR_local: std_logic_vector(127 downto 0) := (others => '0');
+signal RX_DEST_IP_ADDR_local: std_logic_vector(127 downto 0) := (others => '0');
+
+--// CHECK IP VALIDITY ----------------------
+signal IP_RX_FRAME_VALID_local: std_logic := '0';
+signal IP_RX_FRAME_VALID2_local: std_logic := '0';
+signal IP_RX_FRAME_VALID3_local: std_logic := '0';
+
+--// IP PAYLOAD ---------------------------------------------
+signal IP_PAYLOAD_DATA_LS32b_D: std_logic_vector(31 downto 0) := (others => '0');
+signal IP_PAYLOAD_DATA_VALID_LSB32b_D: std_logic_vector(3 downto 0) := (others => '0');
+signal IP_PAYLOAD_DATA_VALID0: std_logic_vector(7 downto 0) := (others => '0');
+signal IP_PAYLOAD_WORD_COUNT_local: unsigned(10 downto 0) := (others => '0');
+signal IP_PAYLOAD_SOF0: std_logic := '0';
+signal IP_PAYLOAD_EOF_local: std_logic := '0';
+signal IP_PAYLOAD_EOF_D: std_logic := '0';
+
+--//--- UDP LAYER ---------------------------------
+signal UDPv4_CKSUM_NULL: std_logic := '0';
+signal CKSUM1: unsigned(17 downto 0):= (others => '0');
+signal CKSUM2: unsigned(17 downto 0):= (others => '0');
+signal CKSUM3: unsigned(17 downto 0):= (others => '0');
+signal CKSUM3PLUS: unsigned(17 downto 0):= (others => '0');
+signal RX_UDP_CKSUM_local: unsigned(17 downto 0):= (others => '0');
+signal VALID_UDP_CHECKSUM0: std_logic := '0';
+signal VALID_UDP_CHECKSUM1: std_logic := '0';
+signal VALID_UDP_CHECKSUM_local: std_logic := '0';
+
+------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+---------------------------------------------------
+---- PACKET LAYER ---------------------------------
+---------------------------------------------------
+
+--// PACKET WORD COUNT ----------------------
+-- Most packet processing is performed with a 1CLK latency (processes MAC_RX_DATA_D and MAC_RX_DATA_VALID_D)
+-- count received bytes for each incoming packet. 0 is the first word.
+MAC_RX_WORD_COUNT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_RX_WORD_COUNT_local <= (others => '0');
+ MAC_RX_DATA_D <= (others => '0');
+ MAC_RX_DATA_VALID_D <= (others => '0');
+ MAC_RX_WORD_VALID_D <= '0';
+ MAC_RX_SOF_D <= '0';
+ MAC_RX_EOF_D <= '0';
+ else
+ -- reclock data and sample clock so that they are aligned with the byte count.
+ -- Also blank data bytes not marked as valid *063018
+ for I in 0 to 7 loop
+ if(MAC_RX_DATA_VALID(I) = '1') then
+ MAC_RX_DATA_D(8*I+7 downto 8*I) <= MAC_RX_DATA(8*I+7 downto 8*I);
+ else
+ MAC_RX_DATA_D(8*I+7 downto 8*I) <= (others => '0');
+ end if;
+ end loop;
+ --MAC_RX_DATA_D <= MAC_RX_DATA;
+ MAC_RX_DATA_VALID_D <= MAC_RX_DATA_VALID;
+ MAC_RX_SOF_D <= MAC_RX_SOF;
+ MAC_RX_EOF_D <= MAC_RX_EOF;
+
+ if(MAC_RX_SOF = '1') then
+ -- just received first byte.
+ MAC_RX_WORD_COUNT_local <= (others => '0');
+ elsif(unsigned(MAC_RX_DATA_VALID) /= 0) then
+ MAC_RX_WORD_COUNT_local <= MAC_RX_WORD_COUNT_local + 1;
+ end if;
+
+ if(unsigned(MAC_RX_DATA_VALID) /= 0) then
+ MAC_RX_WORD_VALID_D <= '1';
+ else
+ MAC_RX_WORD_VALID_D <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+MAC_RX_WORD_COUNT <= std_logic_vector(MAC_RX_WORD_COUNT_local);
+
+--// PACKET TYPE ---------------------------------
+-- type detection at word 6 (Ethernet encapsulation, RFC 894)
+-- OR at word 10 (802.3)
+RX_TYPE_FIELD_D <= MAC_RX_DATA_D(31 downto 16);
+DETECT_TYPE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_TYPE_local <= x"0"; -- unknown type
+ RX_TYPE_RDY_local <= '0';
+ elsif(MAC_RX_SOF_D = '1') then
+ -- clear type to unknown
+ RX_TYPE_local <= x"0"; -- unknown type
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 1) and (RX_TYPE_local= 0) then
+ -- Ethernet encapsulation, RFC 894
+ if(RX_TYPE_FIELD_D = x"0800") then
+ -- IPv4 datagram
+ RX_TYPE_local <= x"1";
+ RX_TYPE_RDY_local <= '1';
+ elsif(RX_TYPE_FIELD_D = x"0806") then
+ -- ARP request/reply
+ RX_TYPE_local <= x"2";
+ RX_TYPE_RDY_local <= '1';
+ elsif(RX_TYPE_FIELD_D = x"8035") then
+ -- RARP request/reply
+ RX_TYPE_local <= x"3";
+ RX_TYPE_RDY_local <= '1';
+ elsif(RX_TYPE_FIELD_D = x"86DD") then
+ -- IPv6 datagram
+ RX_TYPE_local <= x"5";
+ RX_TYPE_RDY_local <= '1';
+ else
+ RX_TYPE_RDY_local <= '0';
+ end if;
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 2) and (RX_TYPE_local = 0) then
+ -- IEEE 802.3/802.2 encapsulation, RFC 1042
+ if(RX_TYPE_FIELD_D = x"0800") then
+ -- IP datagram
+ RX_TYPE_local <= x"9";
+ RX_TYPE_RDY_local <= '1';
+ elsif(RX_TYPE_FIELD_D = x"0806") then
+ -- ARP request/reply
+ RX_TYPE_local <= x"A";
+ RX_TYPE_RDY_local <= '1';
+ elsif(RX_TYPE_FIELD_D = x"8035") then
+ -- RARP request/reply
+ RX_TYPE_local <= x"B";
+ RX_TYPE_RDY_local <= '1';
+ elsif(RX_TYPE_FIELD_D = x"86DD") then
+ -- IPv6 datagram
+ RX_TYPE_local <= x"D";
+ RX_TYPE_RDY_local <= '1';
+ else
+ -- still unrecognized type after second word, declare unknown type
+ RX_TYPE_RDY_local <= '1';
+ end if;
+ else
+ RX_TYPE_RDY_local <= '0';
+ end if;
+ end if;
+end process;
+RX_TYPE <= std_logic_vector(RX_TYPE_local);
+RX_TYPE_RDY <= RX_TYPE_RDY_local;
+
+--// SOURCE MAC ADDRESS ------------------------------------
+CAPTURE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_SOURCE_MAC_ADDR_local <= (others => '0');
+ elsif(MAC_RX_SOF_D = '1') and (MAC_RX_DATA_VALID_D(1 downto 0) = "11") then
+ RX_SOURCE_MAC_ADDR_local(47 downto 32) <= MAC_RX_DATA_D(15 downto 0);
+ elsif (MAC_RX_WORD_COUNT_local = 1) and (MAC_RX_DATA_VALID_D(7 downto 4) = "1111") then
+ RX_SOURCE_MAC_ADDR_local(31 downto 0) <= MAC_RX_DATA_D(63 downto 32);
+ end if;
+ end if;
+end process;
+RX_SOURCE_MAC_ADDR <= RX_SOURCE_MAC_ADDR_local;
+
+--// IP DATA -------------------------------------
+-- Parse the IP frame, (discard the Ethernet header), starting at the version number
+-- Most packet processing is performed with a 2CLK latency w.r.t. the input
+-- Keep track of the number of IP words (first is 1), even during Ethernet short frame padding.
+-- Note: IP_RX_DATA0 will be masked by IP_RX_DATA_VALID_local further down
+RX_IP_FRAME_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ MAC_RX_SOF_D2 <= MAC_RX_SOF_D;
+
+ if(SYNC_RESET = '1') then
+ IP_RX_DATA_CACHE <= (others => '0');
+ IP_RX_DATA_CACHE_VALID <= (others => '0');
+ IP_RX_DATA0 <= (others => '0');
+ IP_RX_WORD_COUNT_local <= (others => '0');
+ IP_RX_FLUSH_CACHE <= '0';
+ elsif(MAC_RX_SOF_D = '1') then
+ if(IP_RX_FLUSH_CACHE = '1') then
+ -- special case when EOF is followed immediately by SOF
+ IP_RX_DATA0(63 downto 48) <= IP_RX_DATA_CACHE(63 downto 48);
+ IP_RX_DATA0(47 downto 0) <= (others => '0');
+ IP_RX_WORD_COUNT_local <= IP_RX_WORD_COUNT_local + 1;
+ IP_RX_DATA_CACHE_VALID(7 downto 6) <= "00";
+ IP_RX_FLUSH_CACHE <= '0';
+ end if;
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 1) and (RX_TYPE_local= 0) then
+ -- Ethernet encapsulation, RFC 894
+ IP_RX_DATA_CACHE(63 downto 48) <= MAC_RX_DATA_D(15 downto 0);
+ IP_RX_DATA_CACHE_VALID(7 downto 6) <= MAC_RX_DATA_VALID_D(1 downto 0);
+ IP_RX_WORD_COUNT_local <= (others => '0');
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 2) and (RX_TYPE_local = 0) then
+ -- IEEE 802.3/802.2 encapsulation, RFC 1042
+ IP_RX_DATA_CACHE(63 downto 48) <= MAC_RX_DATA_D(15 downto 0);
+ IP_RX_DATA_CACHE_VALID(7 downto 6) <= MAC_RX_DATA_VALID_D(1 downto 0);
+ IP_RX_WORD_COUNT_local <= (others => '0');
+ elsif(MAC_RX_WORD_VALID_D = '1') then
+ IP_RX_DATA0(63 downto 48) <= IP_RX_DATA_CACHE(63 downto 48);
+ IP_RX_DATA0(47 downto 0) <= MAC_RX_DATA_D(63 downto 16);
+ IP_RX_DATA_CACHE(63 downto 48) <= MAC_RX_DATA_D(15 downto 0);
+ IP_RX_DATA_CACHE_VALID(7 downto 6) <= MAC_RX_DATA_VALID_D(1 downto 0);
+ IP_RX_WORD_COUNT_local <= IP_RX_WORD_COUNT_local + 1;
+ if(MAC_RX_DATA_VALID_D(1 downto 0) /= "00") then
+ IP_RX_FLUSH_CACHE <= MAC_RX_EOF_D; -- maybe last (full) word, or not the last word.
+ end if;
+ elsif(IP_RX_FLUSH_CACHE = '1') then
+ IP_RX_DATA0(63 downto 48) <= IP_RX_DATA_CACHE(63 downto 48);
+ IP_RX_DATA0(47 downto 0) <= (others => '0');
+ IP_RX_WORD_COUNT_local <= IP_RX_WORD_COUNT_local + 1;
+ IP_RX_DATA_CACHE_VALID(7 downto 6) <= "00";
+ IP_RX_FLUSH_CACHE <= '0';
+ end if;
+ end if;
+end process;
+IP_RX_WORD_COUNT <= std_logic_vector(IP_RX_WORD_COUNT_local);
+
+-- reconstruct IP_RX_SOF for the IP frame
+RX_IP_FRAME_GEN_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_RX_SOF_D = '1') then
+ IP_RX_SOF_local <= '0';
+ elsif (MAC_RX_WORD_VALID_D = '1') and (MAC_RX_WORD_COUNT_local = 2) and ((RX_TYPE_local = 1) or (RX_TYPE_local = 5)) then
+ -- Ethernet encapsulation, RFC 894
+ IP_RX_SOF_local <= '1';
+ elsif (MAC_RX_WORD_VALID_D = '1') and (MAC_RX_WORD_COUNT_local = 3) and ((RX_TYPE_local = 9) or (RX_TYPE_local = 13)) then
+ -- IEEE 802.3/802.2 encapsulation, RFC 1042
+ IP_RX_SOF_local <= '1';
+ else
+ IP_RX_SOF_local <= '0';
+ end if;
+ end if;
+end process;
+
+-- reconstruct the IP_RX_DATA_VALID for the IP frame
+RX_IP_FRAME_GEN_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ IP_RX_DATA_VALID0 <= (others => '0');
+ elsif(MAC_RX_SOF_D = '1') then
+ if(IP_RX_FLUSH_CACHE = '1') then
+ -- special case when EOF is followed immediately by SOF
+ IP_RX_DATA_VALID0 <= IP_RX_DATA_CACHE_VALID(7 downto 6) & "000000";
+ else
+ IP_RX_DATA_VALID0 <= (others => '0');
+ end if;
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 1) and (RX_TYPE_local= 0) then
+ -- Ethernet encapsulation, RFC 894
+ IP_RX_DATA_VALID0 <= (others => '0');
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 2) and (RX_TYPE_local = 0) then
+ -- IEEE 802.3/802.2 encapsulation, RFC 1042
+ IP_RX_DATA_VALID0 <= (others => '0');
+ elsif(IP_TOTAL_LENGTH_DEC(15 downto 14) = "00") and (IP_TOTAL_LENGTH_DEC(13 downto 3) < IP_RX_WORD_COUNT_local) then
+ -- Ethernet frame may be padded to meet the minimum 46 Byte (IPv4) or 26 Byte (IPv6) payload length.
+ -- Discard the padding here based on the IP total length
+ IP_RX_DATA_VALID0 <= (others => '0');
+ elsif(MAC_RX_WORD_VALID_D = '1') then
+ IP_RX_DATA_VALID0 <= IP_RX_DATA_CACHE_VALID(7 downto 6) & MAC_RX_DATA_VALID_D(7 downto 2);
+ elsif(IP_RX_FLUSH_CACHE = '1') then
+ IP_RX_DATA_VALID0 <= IP_RX_DATA_CACHE_VALID(7 downto 6) & "000000";
+ else
+ IP_RX_DATA_VALID0 <= (others => '0');
+ end if;
+ end if;
+end process;
+IP_RX_DATA_VALID_local <= IP_RX_DATA_VALID0 and IP_RX_MASK_ETH_PADS when (IP_RX_FRAME_VALID3_local = '1') else x"00";
+ -- mask Ethernet pads when short frame. Mask if not an IP frame.
+IP_RX_WORD_VALID_local <= '0' when (IP_RX_DATA_VALID_local = x"00") else '1';
+
+-- zero (mask) IP_RX_DATA bytes based on IP_RX_DATA_VALID_local
+RX_IP_FRAME_GEN_004: process(IP_RX_DATA0, IP_RX_DATA_VALID_local)
+begin
+ for I in 0 to 7 loop
+ if(IP_RX_DATA_VALID_local(I) = '1') then
+ IP_RX_DATA_local(8*I+7 downto 8*I) <= IP_RX_DATA0(8*I+7 downto 8*I);
+ else
+ IP_RX_DATA_local(8*I+7 downto 8*I) <= (others => '0');
+ end if;
+ end loop;
+end process;
+
+-- reconstruct the IP_RX_EOF for the IP frame
+-- TODO: EOF MAY ARRIVE EARLIER IN THE CASE OF SHORT (<60BYTES) ETHERNET FRAMES
+RX_IP_FRAME_GEN_005: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_RX_EOF_D <= IP_RX_EOF_local;
+
+ if(SYNC_RESET = '1') then
+ IP_RX_EOF0 <= '0';
+ elsif(MAC_RX_SOF_D = '1') then
+ if(IP_RX_FLUSH_CACHE = '1') then
+ -- special case when EOF is followed immediately by SOF
+ IP_RX_EOF0 <= '1';
+ else
+ IP_RX_EOF0 <= '0';
+ end if;
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 1) and (RX_TYPE_local= 0) then
+ -- Ethernet encapsulation, RFC 894
+ IP_RX_EOF0 <= '0';
+ elsif(MAC_RX_DATA_VALID_D(3 downto 2) = "11") and (MAC_RX_WORD_COUNT_local = 2) and (RX_TYPE_local = 0) then
+ -- IEEE 802.3/802.2 encapsulation, RFC 1042
+ IP_RX_EOF0 <= '0';
+ elsif((MAC_RX_WORD_VALID_D = '1') or (IP_RX_FLUSH_CACHE = '1')) and (IP_TOTAL_LENGTH_DEC(15 downto 14) = "00") and (IP_TOTAL_LENGTH_DEC(13 downto 3) = IP_RX_WORD_COUNT_local) then
+ -- Ethernet frame may be padded to meet the minimum 46 Byte (IPv4) or 26 Byte (IPv6) payload length.
+ -- Discard the padding here based on the IP total length
+ IP_RX_EOF0 <= '1';
+-- PREVIOUS CODE SMALL DOUBT 062118
+-- elsif(MAC_RX_WORD_VALID_D = '1') and (MAC_RX_DATA_VALID_D(1 downto 0) = "00") then
+-- IP_RX_EOF0 <= '1';
+-- elsif(IP_RX_FLUSH_CACHE = '1') then
+-- IP_RX_EOF0 <= '1';
+ else
+ IP_RX_EOF0 <= '0';
+ end if;
+ end if;
+end process;
+IP_RX_EOF_local <= IP_RX_EOF0 and IP_RX_FRAME_VALID3_local;
+ -- mask EOF if not an IP frame
+
+-- mask Ethernet short-frame padding bits
+IP_RX_MASK_ETH_PADS_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (IP_RX_WORD_COUNT_local < 2) then
+ -- wait until RX_IPv4_6N and IP_TOTAL_LENGTH_DEC are known to generate the ethernet mask
+ IP_RX_MASK_ETH_PADS <= x"FF";
+ elsif(IP_TOTAL_LENGTH_DEC(15 downto 14) = "00") and (IP_TOTAL_LENGTH_DEC(13 downto 3) = IP_RX_WORD_COUNT_local) then
+ -- last byte
+ case IP_TOTAL_LENGTH_DEC(2 downto 0) is
+ when "000" => IP_RX_MASK_ETH_PADS <= x"80";
+ when "001" => IP_RX_MASK_ETH_PADS <= x"C0";
+ when "010" => IP_RX_MASK_ETH_PADS <= x"E0";
+ when "011" => IP_RX_MASK_ETH_PADS <= x"F0";
+ when "100" => IP_RX_MASK_ETH_PADS <= x"F8";
+ when "101" => IP_RX_MASK_ETH_PADS <= x"FC";
+ when "110" => IP_RX_MASK_ETH_PADS <= x"FE";
+ when others => IP_RX_MASK_ETH_PADS <= x"FF";
+ end case;
+ elsif(IP_TOTAL_LENGTH_DEC(15 downto 14) = "00") and (IP_TOTAL_LENGTH_DEC(13 downto 3) > IP_RX_WORD_COUNT_local) then
+ IP_RX_MASK_ETH_PADS <= x"FF";
+ else
+ IP_RX_MASK_ETH_PADS <= x"00";
+ end if;
+ end if;
+end process;
+
+
+-- pass to other components
+IP_RX_DATA <= IP_RX_DATA_local;
+IP_RX_SOF <= IP_RX_SOF_local;
+IP_RX_EOF <= IP_RX_EOF_local;
+IP_RX_DATA_VALID <= IP_RX_DATA_VALID_local;
+
+--// IP PROTOCOL ----------------------
+-- IP version 4 or 6? Ready at IP_RX_SOF_D
+DETECT_IP_PROTOCOL_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_SOF_local = '1') then
+ if(unsigned(IP_RX_DATA_local(63 downto 60)) = 6) then
+ RX_IPv4_6n_local <= '0'; -- IPv6
+ else
+ RX_IPv4_6n_local <= '1'; -- IPv4
+ end if;
+ end if;
+ end if;
+end process;
+RX_IPv4_6n <= RX_IPv4_6n_local;
+
+-- IP protocol (ICMP, UDP, TCP) detection
+DETECT_IPv4_PROTOCOL_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_PAYLOAD_EOF_D <= IP_PAYLOAD_EOF_local;
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_EOF_D = '1') then -- *060719
+ -- reset or end of packet
+ -- clear type to unknown
+ IPv4_PROTOCOL <= x"00";
+ IPv4_PROTOCOL_RDY <= '0';
+ elsif (RX_IPv4_6n_local = '1') and (RX_TYPE_local(2 downto 0) = 1) and
+ (IP_RX_DATA_VALID_local(6) = '1') and (IP_RX_WORD_COUNT_local = 2) then
+ -- IPv4.
+ IPv4_PROTOCOL <= IP_RX_DATA_local(55 downto 48);
+ IPv4_PROTOCOL_RDY <= '1';
+ else
+ IPv4_PROTOCOL_RDY <= '0';
+ end if;
+ end if;
+end process;
+
+-- read between RX_IP_PROTOCOL_RDY (inclusive)(i.e. before IP_PAYLOAD_SOF) and IP_PAYLOAD_EOF (inclusive)
+RX_IP_PROTOCOL_local <= IPv4_PROTOCOL when (RX_IPv4_6n_local = '1') else IPv6_PROTOCOL;
+RX_IP_PROTOCOL <= RX_IP_PROTOCOL_local;
+RX_IP_PROTOCOL_RDY <= IPv4_PROTOCOL_RDY or IPv6_PROTOCOL_RDY;
+
+
+--// IPv6 HEADER PARSING ---------------------------------------
+-- outline IP header and IPv6 extension headers
+-- TODO: IPv6 extension header
+IPv6_ONLY_001: if(IPv6_ENABLED = '1') generate
+ IPv6_HEADER_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_EOF_D = '1') then -- *060719
+ -- reset or end of packet
+ -- clear type to unknown
+ IPv6_PROTOCOL <= (others => '0');
+ IPv6_PROTOCOL_RDY <= '0';
+ IPv6_HEADER_FLAG <= '0';
+ elsif(IP_RX_EOF_local = '1') then
+ -- safety (in case we missed a new extension protocol)
+ IPv6_HEADER_FLAG <= '0';
+ elsif (RX_TYPE_local(2 downto 0) = 5) and (IP_RX_WORD_VALID_local = '1') and
+ (IP_RX_WORD_COUNT_local = 1) and (unsigned(IP_RX_DATA_local(63 downto 60)) = 6) then
+ -- IP_RX_SOF IPv6 header length is 5 words
+ IPv6_HEADER_WORD_CNTR <= to_unsigned(5,IPv6_HEADER_WORD_CNTR'length);
+ IPv6_NEXT_HEADER <= IP_RX_DATA_local(15 downto 8);
+ IPv6_HEADER_FLAG <= '1';
+ elsif(IPv6_HEADER_FLAG = '1') and (IP_RX_WORD_VALID_local = '1') then
+ IPv6_HEADER_WORD_CNTR <= IPv6_HEADER_WORD_CNTR - 1;
+ if(IPv6_HEADER_WORD_CNTR = 2) then
+ if(unsigned(IPv6_NEXT_HEADER) = 0) then
+ -- extension header: hop-by-hop options
+ elsif(unsigned(IPv6_NEXT_HEADER) = 43) then
+ -- extension header: routing
+ else
+ -- end of current header
+ IPv6_HEADER_FLAG <= '0';
+ -- display protocol
+ IPv6_PROTOCOL <= IPv6_NEXT_HEADER;
+ IPv6_PROTOCOL_RDY <= '1';
+ end if;
+ elsif(IPv6_HEADER_WORD_CNTR = 1) then
+ -- 1st word in an extension header. Re-arm word counter
+ IPv6_HEADER_WORD_CNTR <= unsigned(IP_RX_DATA_local(55 downto 48));
+ IPv6_NEXT_HEADER <= IP_RX_DATA_local(63 downto 56);
+ end if;
+ else
+ IPv6_PROTOCOL_RDY <= '0';
+ end if;
+ end if;
+ end process;
+end generate;
+IP_HEADER_FLAG_local(0) <= IP_RX_SOF_local or IPv6_HEADER_FLAG or (IPv4_HEADER_MASK(0) and RX_IPv4_6n_local);
+IP_HEADER_FLAG_local(1) <= IP_RX_SOF_local or IPv6_HEADER_FLAG or (IPv4_HEADER_MASK(1) and RX_IPv4_6n_local);
+IP_HEADER_FLAG <= IP_HEADER_FLAG_local;
+
+
+--// IPv4 HEADER PARSING ---------------------------------------
+-- Parse IPv4_HEADER_N32bWORDS. To be used at MAC_RX_DATA_VALID_D3.
+-- Valid only if type is IPv4.
+IPv4_HEADER_N32bWORDS_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IPv4_HEADER_N32bWORDS_D <= IPv4_HEADER_N32bWORDS;
+
+ if(SYNC_RESET = '1') or (MAC_RX_SOF_D = '1') then
+ -- reset or new packet
+ -- clear last IP header length
+ IPv4_HEADER_N32bWORDS <= (others => '0');
+ elsif(IP_RX_SOF_local = '1') and (unsigned(IP_RX_DATA_local(63 downto 60)) = 4) then
+ -- IPv4 header
+ IPv4_HEADER_N32bWORDS <= unsigned(IP_RX_DATA_local(59 downto 56));
+ end if;
+ end if;
+end process;
+
+-- generate mask for IP header
+IPv4_HEADER_N32bWORDS_DEC <= IPv4_HEADER_N32bWORDS-1;
+IPv4_HEADER_MASK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IPv4_HEADER_MASK_D <= IPv4_HEADER_MASK;
+
+ if(SYNC_RESET = '1') or (MAC_RX_SOF_D = '1') then
+ -- reset or new packet
+ IPv4_HEADER_MASK_A <= "00";
+ elsif(IP_RX_SOF_local = '1') then
+ IPv4_HEADER_MASK_A <= "11";
+ elsif (IP_RX_WORD_VALID_local = '1') and (IP_RX_WORD_COUNT_local = IPv4_HEADER_N32bWORDS_DEC(3 downto 1)) then
+ if(IPv4_HEADER_N32bWORDS(0) = '0') then
+ -- even number of 32-bit words in IP header
+ IPv4_HEADER_MASK_A <= "11";
+ else
+ -- odd number of 32-bit words in IP header
+ IPv4_HEADER_MASK_A <= "10";
+ end if;
+ elsif (IP_RX_WORD_VALID_local = '1') and (IP_RX_WORD_COUNT_local > IPv4_HEADER_N32bWORDS_DEC(3 downto 1)) then
+ IPv4_HEADER_MASK_A <= "00";
+ end if;
+ end if;
+end process;
+IPv4_HEADER_MASK <= "11" when (IP_RX_SOF_local = '1') else IPv4_HEADER_MASK_A;
+
+-- End Of Header, marks the last word in an IPv4 header. Aligned with IP_RX_WORD_VALID_local
+IPv4_RX_EOH <= '1' when (IPv4_HEADER_MASK_A /= "00") and (IP_RX_WORD_VALID_local = '1') and (IP_RX_WORD_COUNT_local > IPv4_HEADER_N32bWORDS_DEC(3 downto 1)) else '0';
+
+
+-- Masked IPv4 header (unused)
+--IPv4_HEADER_DATA_GEN: process(IPv4_HEADER_MASK,IP_RX_DATA_local)
+--begin
+-- if(IPv4_HEADER_MASK = "00") then
+-- IPv4_HEADER_DATA <= (others => '0');
+-- elsif(IPv4_HEADER_MASK = "10") then
+-- IPv4_HEADER_DATA(63 downto 32) <= IP_RX_DATA_local(63 downto 32);
+-- IPv4_HEADER_DATA(31 downto 0) <= (others => '0');
+-- else
+-- IPv4_HEADER_DATA <= IP_RX_DATA_local;
+-- end if;
+--end process;
+
+-- Parse IP_TOTAL_LENGTH - 1
+-- Valid only if type is IPv4.
+IPv4_TOTAL_LENGTH_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_RX_SOF_D = '1') then
+ -- reset or new packet
+ -- clear last IP total length. Minimum length is 20 bytes
+ IP_TOTAL_LENGTH_DEC <= to_unsigned(19,IP_TOTAL_LENGTH_DEC'length);
+ elsif(IP_RX_SOF_local = '1') and (unsigned(IP_RX_DATA_local(63 downto 60)) = 4) then
+ -- IPv4 header
+ IP_TOTAL_LENGTH_DEC <= unsigned(IP_RX_DATA_local(47 downto 32)) - 1;
+ elsif(IP_RX_SOF_local = '1') and (unsigned(IP_RX_DATA_local(63 downto 60)) = 6) then
+ -- IPv6 header
+ IP_TOTAL_LENGTH_DEC <= unsigned(IP_RX_DATA_local(31 downto 16)) + to_unsigned(39,IP_TOTAL_LENGTH_DEC'length);
+ end if;
+ end if;
+end process;
+
+
+--// VALIDATE IP HEADER CHECKSUM ----------------------
+-- perform 1's complement sum of all 16-bit words within the header.
+-- IP_HEADER_CHECKSUM_VALID ready 2 CLK after the last header word (RX_SAMPLE_CLK_D4_LOCAL)
+-- This applies only to IPv4 (no such field in IPv6)
+
+-- sum most significant and least significant words (used several times in this component)
+IP_RX_DATA_SUM_MSW <= resize(unsigned(IP_RX_DATA_local(63 downto 48)),18) + resize(unsigned(IP_RX_DATA_local(47 downto 32)),18);
+IP_RX_DATA_SUM_LSW <= resize(unsigned(IP_RX_DATA_local(31 downto 16)),18) + resize(unsigned(IP_RX_DATA_local(15 downto 0)),18);
+
+IP_HEADER_CHECKSUM_001: process(CLK)
+variable CKSUM: unsigned(17 downto 0);
+begin
+ if rising_edge(CLK) then
+ IPv4_RX_EOH_D <= IPv4_RX_EOH; -- end of header
+ IP_HEADER_CHECKSUM_VALID_RDY_local <= IPv4_RX_EOH_D;
+
+ if(IP_RX_SOF_local = '1') then
+ HCKSUM1 <= IP_RX_DATA_SUM_MSW;
+ HCKSUM2 <= IP_RX_DATA_SUM_LSW;
+ HCKSUM3 <= (others => '0');
+ elsif (IP_RX_WORD_VALID_local = '1') then
+ if(IPv4_HEADER_MASK(1) = '1') then
+ HCKSUM1 <= resize(HCKSUM1(15 downto 0),18) + IP_RX_DATA_SUM_MSW;
+ end if;
+ if(IPv4_HEADER_MASK(0) = '1') then
+ HCKSUM2 <= resize(HCKSUM2(15 downto 0),18) + IP_RX_DATA_SUM_LSW;
+ else
+ HCKSUM2(17 downto 16) <= (others => '0'); -- blank carry bits, already summed into HCKSUM3_PLUS
+ end if;
+ if(IPv4_HEADER_MASK /= "00") then
+ HCKSUM3 <= HCKSUM3_PLUS;
+ end if;
+ end if;
+
+ IP_HEADER_CHECKSUM_FINAL <= resize(IP_HEADER_CHECKSUM(15 downto 0),18) + resize(IP_HEADER_CHECKSUM(17 downto 16),18); -- add carry
+
+ end if;
+end process;
+HCKSUM3_PLUS <= HCKSUM3 + resize(unsigned(HCKSUM1(17 downto 16)),6) + resize(unsigned(HCKSUM2(17 downto 16)),6);
+IP_HEADER_CHECKSUM <= resize(HCKSUM1(15 downto 0),18) + resize(HCKSUM2(15 downto 0),18) + resize(HCKSUM3_PLUS,18);
+IP_HEADER_CHECKSUM_VALID_local <= '1' when (SIMULATION = '1') else
+ '1' when (IP_HEADER_CHECKSUM_FINAL(16) = '0') and (IP_HEADER_CHECKSUM_FINAL(15 downto 0) = x"FFFF") else
+ '1' when (IP_HEADER_CHECKSUM_FINAL(16) = '1') and (IP_HEADER_CHECKSUM_FINAL(15 downto 0) = x"FFFE") else
+ '0';
+ -- ignore computation during simulation with a Wireshark stimulus file as the header checksum may be incorrect (offloaded)
+
+-- make information available to other components
+IP_HEADER_CHECKSUM_VALID <= IP_HEADER_CHECKSUM_VALID_local;
+IP_HEADER_CHECKSUM_VALID_RDY <= IP_HEADER_CHECKSUM_VALID_RDY_local;
+
+
+--// SOURCE & DESTINATION IP ADDRESS -------------------------
+-- includes IP (v4, v6) and ARP
+CAPTURE_SOURCE_IP_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_SOURCE_IP_ADDR_local <= (others => '0');
+ elsif(MAC_RX_SOF_D = '1') then
+ -- new packet. clear field.
+ RX_SOURCE_IP_ADDR_local <= (others => '0');
+ elsif (RX_TYPE_local(2 downto 0) = 2) then
+ -- ARP request/reply
+ if (MAC_RX_DATA_VALID_D(3 downto 0) = "1111") and (MAC_RX_WORD_COUNT_local = 3) then
+ RX_SOURCE_IP_ADDR_local(31 downto 0) <= MAC_RX_DATA_D(31 downto 0);
+ end if;
+ elsif (RX_IPv4_6n_local = '1') and (RX_TYPE_local(2 downto 0) = 1) and
+ (IP_RX_DATA_VALID_local(3 downto 0) = "1111") and (IP_RX_WORD_COUNT_local = 2) then
+ -- IPv4.
+ RX_SOURCE_IP_ADDR_local(31 downto 0) <= IP_RX_DATA_local(31 downto 0);
+ elsif (IPv6_ENABLED = '1') and (RX_IPv4_6n_local = '0') and (RX_TYPE_local(2 downto 0) = 5) and
+ (IP_RX_WORD_VALID_local = '1') then
+ -- IPv6 (when enabled)
+ if (IP_RX_WORD_COUNT_local = 2) then
+ RX_SOURCE_IP_ADDR_local(127 downto 64) <= IP_RX_DATA_local;
+ elsif (IP_RX_WORD_COUNT_local = 3) then
+ RX_SOURCE_IP_ADDR_local(63 downto 0) <= IP_RX_DATA_local;
+ end if;
+ end if;
+ end if;
+end process;
+RX_SOURCE_IP_ADDR <= RX_SOURCE_IP_ADDR_local;
+
+CAPTURE_DEST_IP_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_DEST_IP_ADDR_local <= (others => '0');
+ elsif(MAC_RX_SOF_D = '1') then
+ -- new packet. clear field.
+ RX_DEST_IP_ADDR_local <= (others => '0');
+ elsif (RX_TYPE_local(2 downto 0) = 2) then
+ -- ARP request
+ if (MAC_RX_DATA_VALID_D(1 downto 0) = "11") and (MAC_RX_WORD_COUNT_local = 4) then
+ RX_DEST_IP_ADDR_local(31 downto 16) <= MAC_RX_DATA_D(15 downto 0);
+ elsif (MAC_RX_DATA_VALID_D(7 downto 6) = "11") and (MAC_RX_WORD_COUNT_local = 5) then
+ RX_DEST_IP_ADDR_local(15 downto 0) <= MAC_RX_DATA_D(63 downto 48);
+ end if;
+ elsif (RX_IPv4_6n_local = '1') and (RX_TYPE_local(2 downto 0) = 1) and
+ (IP_RX_DATA_VALID_local(7 downto 4) = "1111") and (IP_RX_WORD_COUNT_local = 3) then
+ -- IPv4.
+ RX_DEST_IP_ADDR_local(31 downto 0) <= IP_RX_DATA_local(63 downto 32);
+ elsif (IPv6_ENABLED = '1') and (RX_IPv4_6n_local = '0') and (RX_TYPE_local(2 downto 0) = 5) and
+ (IP_RX_WORD_VALID_local = '1') and (IP_RX_WORD_COUNT_local = 4) then
+ -- IPv6 (when enabled) destination address upper 64-bit
+ RX_DEST_IP_ADDR_local(127 downto 64) <= IP_RX_DATA_local;
+ elsif (IPv6_ENABLED = '1') and (RX_IPv4_6n_local = '0') and (RX_TYPE_local(2 downto 0) = 5) and
+ (IP_RX_WORD_VALID_local = '1') and (IP_RX_WORD_COUNT_local = 5) then
+ -- IPv6 (when enabled) destination address lower 64-bit
+ RX_DEST_IP_ADDR_local(63 downto 0) <= IP_RX_DATA_local;
+ end if;
+ end if;
+end process;
+RX_DEST_IP_ADDR <= RX_DEST_IP_ADDR_local;
+
+--// VALIDATE IP DESTINATION ADDRESS ----------------------
+-- Check only in the case of IP datagram, as identified by the RX_TYPE = 1
+-- latency: 3 CLK after receiving the last byte of the destination address field.
+-- TODO: currently checking only for UNICAST addresses. Todo: extend to multicast? broadcast? limited broadcast?
+DEST_IP_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_RX_SOF_D = '1') then
+ VALID_UNICAST_DEST_IP_local <= '0';
+ VALID_UNICAST_DEST_IP_MSBS <= '0';
+ VALID_MULTICAST_DEST_IP_local <= '0';
+ VALID_MULTICAST_DEST_IP_MSBS <= '0';
+ VALID_DEST_IP_RDY_local <= '0';
+ -- IPv4
+ elsif (RX_IPv4_6n_local = '1') and (RX_TYPE_local(2 downto 0) = 1) and
+ (IP_RX_DATA_VALID_local(7 downto 4) = "1111") and (IP_RX_WORD_COUNT_local = 3) then
+ -- IPv4.
+ VALID_DEST_IP_RDY_local <= '1';
+ if(IP_RX_DATA_local(63 downto 32) = IPv4_ADDR) then
+ -- unicast address match
+ VALID_UNICAST_DEST_IP_local <= '1';
+ end if;
+ if(unsigned(IPv4_MULTICAST_ADDR(31 downto 24)) /= 0) and (IP_RX_DATA_local(63 downto 32) = IPv4_MULTICAST_ADDR) then
+ -- multicast address match when enabled (i.e. multicast address is not zero)
+ VALID_MULTICAST_DEST_IP_local <= '1';
+ elsif(IP_RX_DATA_local(39 downto 32) = x"FF") then
+ -- broadcast (weak check, could be strengthened if needed) *043019
+ VALID_MULTICAST_DEST_IP_local <= '1';
+ end if;
+ -- IPv6
+ elsif (IPv6_ENABLED = '1') and (RX_IPv4_6n_local = '0') and (RX_TYPE_local(2 downto 0) = 5) and
+ (IP_RX_WORD_VALID_local = '1') then
+ if(IP_RX_WORD_COUNT_local = 5) then
+ VALID_DEST_IP_RDY_local <= '1';
+ else
+ VALID_DEST_IP_RDY_local <= '0';
+ end if;
+ -- unicast
+ if (IP_RX_WORD_COUNT_local = 4) and (IP_RX_DATA_local = IPv6_ADDR(127 downto 64)) then
+ -- IPv6 (when enabled) destination address upper 64-bit
+ VALID_UNICAST_DEST_IP_MSBS <= '1';
+ elsif (IP_RX_WORD_COUNT_local = 5) and (IP_RX_DATA_local = IPv6_ADDR(63 downto 0)) then
+ -- IPv6 (when enabled) destination address lower 64-bit
+ VALID_UNICAST_DEST_IP_local <= VALID_UNICAST_DEST_IP_MSBS;
+ end if;
+ -- solicited-node multicast
+ if (IP_RX_WORD_COUNT_local = 4) and (IP_RX_DATA_local = x"FF02000000000000") then
+ -- IPv6 (when enabled) multicast destination address upper 64-bit
+ VALID_MULTICAST_DEST_IP_MSBS <= '1';
+ elsif (IP_RX_WORD_COUNT_local = 5) and (IP_RX_DATA_local(63 downto 24) = x"00000001FF") and (IP_RX_DATA_local(23 downto 0) = IPv6_ADDR(23 downto 0)) then
+ -- IPv6 (when enabled) multicast destination address lower 64-bit
+ VALID_MULTICAST_DEST_IP_local <= VALID_MULTICAST_DEST_IP_MSBS;
+ end if;
+ else
+ VALID_DEST_IP_RDY_local <= '0';
+ end if;
+ end if;
+end process;
+VALID_UNICAST_DEST_IP <= VALID_UNICAST_DEST_IP_local;
+VALID_MULTICAST_DEST_IP <= VALID_MULTICAST_DEST_IP_local;
+VALID_DEST_IP_RDY <= VALID_DEST_IP_RDY_local;
+
+----// CHECK IP VALIDITY ----------------------
+--IP_BYTE_COUNT <= IP_BYTE_COUNT_local;
+--IP_RX_DATA <= MAC_RX_DATA_D2;
+--IP_RX_SOF <= IP_RX_SOF_local;
+--IP_RX_EOF <= IP_RX_EOF_local;
+--IP_RX_DATA_VALID_local <= MAC_RX_DATA_VALID_D2 and IP_RX_FRAME_VALID and IP_FRAME_FLAG;
+--IP_RX_DATA_VALID <= IP_RX_DATA_VALID_local;
+--IP_RX_DATA_VALID2 <= MAC_RX_DATA_VALID_D2 and IP_RX_FRAME_VALID2 and IP_FRAME_FLAG;
+--IP_HEADER_FLAG <= IP_HEADER_FLAG_local;
+
+-- The received IP frame is presumed valid until proven otherwise.
+-- IP frame validity checks include:
+-- (a) protocol is IP
+-- (b) unicast or multicast destination IP address matches
+-- (c) correct IP header checksum (IPv4 only)
+-- (d) allowed IPv6
+-- (e) Ethernet frame is valid (correct FCS, dest address)
+-- Also compute IP_RX_FRAME_VALID2 (no IP destination check)
+-- Also compute IP_RX_FRAME_VALID3 (simply not IP, objective: if no IP_SOF then no IP_EOF, no IP_RX_WORD_VALID)
+-- Ready at IP_RX_VALID_D (= MAC_RX_DATA_VALID_D3)
+IP_RX_FRAME_VALID_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(MAC_RX_SOF_D2 = '1') then
+ -- just received first byte. valid until proven otherwise
+ IP_RX_FRAME_VALID_local <= '1';
+ IP_RX_FRAME_VALID2_local <= '1';
+ IP_RX_FRAME_VALID3_local <= '1';
+ else
+ if(RX_TYPE_RDY_local = '1') and (RX_TYPE_local /= 1) and (RX_TYPE_local /= 5) then
+ -- (a) the received packet type is not an IPv4 nor IPv6 datagram
+ IP_RX_FRAME_VALID_local <= '0';
+ IP_RX_FRAME_VALID2_local <= '0';
+ IP_RX_FRAME_VALID3_local <= '0';
+ end if;
+ if(IP_RX_SOF_local = '1') and (unsigned(IP_RX_DATA_local(63 downto 60)) = 6) and (IPv6_ENABLED = '0') then
+ -- (d) IPv6 frame not allowed
+ IP_RX_FRAME_VALID_local <= '0';
+ IP_RX_FRAME_VALID2_local <= '0';
+ end if;
+ if(VALID_DEST_IP_RDY_local = '1') and (VALID_UNICAST_DEST_IP_local = '0') and (VALID_MULTICAST_DEST_IP_local = '0') then
+ -- (b) invalid destination IP
+ IP_RX_FRAME_VALID_local <= '0';
+ end if;
+ if(RX_IPv4_6n_local = '1') and (IP_HEADER_CHECKSUM_VALID_RDY_local = '1') and (IP_HEADER_CHECKSUM_VALID_local = '0') then
+ -- (c) invalid IP header checksum (IPv4 only)
+ IP_RX_FRAME_VALID_local <= '0';
+ IP_RX_FRAME_VALID2_local <= '0';
+ end if;
+ if(MAC_RX_EOF = '1') and (MAC_RX_FRAME_VALID = '0') then
+ -- (g) erroneous MAC frame
+ IP_RX_FRAME_VALID_local <= '0';
+ IP_RX_FRAME_VALID2_local <= '0';
+ IP_RX_FRAME_VALID3_local <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+IP_RX_FRAME_VALID <= IP_RX_FRAME_VALID_local;
+IP_RX_FRAME_VALID2 <= IP_RX_FRAME_VALID2_local;
+
+
+--// IP PAYLOAD ---------------------------------------------
+-- 64-BIT WORD ALIGNMENT
+-- In IPv4, a payload frame may start with a 32-bit offset w.r.t. 64-bit words,
+-- depending on the IP header length. Perform realignment here
+IP_PAYLOAD_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_SOF_local = '1') or (IP_RX_FRAME_VALID_local = '0') then
+ IP_PAYLOAD_DATA <= (others => '0');
+ IP_PAYLOAD_DATA_VALID0 <= (others => '0');
+ IP_PAYLOAD_WORD_COUNT_local <= (others => '0');
+ IP_PAYLOAD_DATA_VALID_LSB32b_D <= (others => '0');
+ elsif (IP_RX_WORD_VALID_local = '1') then
+ -- 1 received word with 32 or 64-bit payload
+ IP_PAYLOAD_DATA_LS32b_D <= IP_RX_DATA_local(31 downto 0); -- remember the lower half of the previous word
+ IP_PAYLOAD_DATA_VALID_LSB32b_D <= IP_RX_DATA_VALID_local(3 downto 0);
+
+ if(RX_IPv4_6n_local = '1') and (IPv4_HEADER_N32bWORDS(0) = '1') and (IPv4_HEADER_MASK = "00") then
+ -- IPv4 and odd number of 32-bit words in IP header
+ IP_PAYLOAD_DATA(63 downto 32) <= IP_PAYLOAD_DATA_LS32b_D;
+ IP_PAYLOAD_DATA(31 downto 0) <= IP_RX_DATA_local(63 downto 32);
+ IP_PAYLOAD_DATA_VALID0(7 downto 4) <= IP_PAYLOAD_DATA_VALID_LSB32b_D;
+ IP_PAYLOAD_DATA_VALID0(3 downto 0) <= IP_RX_DATA_VALID_local(7 downto 4);
+ IP_PAYLOAD_WORD_COUNT_local <= IP_PAYLOAD_WORD_COUNT_local + 1;
+ elsif(RX_IPv4_6n_local = '1') and (IPv4_HEADER_N32bWORDS(0) = '0') and (IPv4_HEADER_MASK = "00") then
+ IP_PAYLOAD_DATA <= IP_RX_DATA_local;
+ IP_PAYLOAD_DATA_VALID0 <= IP_RX_DATA_VALID_local;
+ IP_PAYLOAD_WORD_COUNT_local <= IP_PAYLOAD_WORD_COUNT_local + 1;
+ elsif(IPv6_ENABLED = '1') and (RX_IPv4_6n_local = '0') and (IPv6_HEADER_FLAG = '0') then
+ IP_PAYLOAD_DATA <= IP_RX_DATA_local;
+ IP_PAYLOAD_DATA_VALID0 <= IP_RX_DATA_VALID_local;
+ IP_PAYLOAD_WORD_COUNT_local <= IP_PAYLOAD_WORD_COUNT_local + 1;
+ else
+ IP_PAYLOAD_DATA_VALID0 <= x"00";
+ end if;
+ elsif(IP_RX_EOF_D = '1') and (RX_IPv4_6n_local = '1') and (IPv4_HEADER_N32bWORDS_D(0) = '1') and (IP_PAYLOAD_DATA_VALID_LSB32b_D /= x"0") then
+ -- flush remaining 32 bits in cache
+ IP_PAYLOAD_DATA(63 downto 32) <= IP_PAYLOAD_DATA_LS32b_D;
+ IP_PAYLOAD_DATA(31 downto 0) <= (others => '0');
+ IP_PAYLOAD_DATA_VALID0(7 downto 4) <= IP_PAYLOAD_DATA_VALID_LSB32b_D;
+ IP_PAYLOAD_DATA_VALID0(3 downto 0) <= x"0";
+ IP_PAYLOAD_WORD_COUNT_local <= IP_PAYLOAD_WORD_COUNT_local + 1;
+ IP_PAYLOAD_DATA_VALID_LSB32b_D <= x"0";
+ else
+ IP_PAYLOAD_DATA_VALID0 <= x"00";
+ end if;
+ end if;
+end process;
+IP_PAYLOAD_DATA_VALID <= IP_PAYLOAD_DATA_VALID0 when (IP_RX_FRAME_VALID_local = '1') else x"00"; -- blank out ASAP when frame is invalid
+IP_PAYLOAD_WORD_COUNT <= std_logic_vector(IP_PAYLOAD_WORD_COUNT_local) when (IP_RX_FRAME_VALID_local = '1') else (others => '0');
+
+-- Generate SOF for the first word of the IP payload
+-- Takes into account the possibility of a zero-length payload.
+IP_PAYLOAD_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_SOF_local = '1') or (IP_RX_FRAME_VALID_local = '0') then
+ IP_PAYLOAD_SOF0 <= '0';
+ elsif (IP_RX_WORD_VALID_local = '1') and (IP_PAYLOAD_WORD_COUNT_local = 0) then
+ -- 1 received word with 32 or 64-bit payload
+ if(RX_IPv4_6n_local = '1') and (IPv4_HEADER_MASK = "00") then
+ -- IPv4
+ IP_PAYLOAD_SOF0 <= '1';
+ elsif(IPv6_ENABLED = '1') and (RX_IPv4_6n_local = '0') and (IPv6_HEADER_FLAG = '0') then
+ IP_PAYLOAD_SOF0 <= '1';
+ else
+ IP_PAYLOAD_SOF0 <= '0';
+ end if;
+ elsif(IP_RX_EOF_D = '1') and (IP_PAYLOAD_WORD_COUNT_local = 0) and (RX_IPv4_6n_local = '1') and (IPv4_HEADER_N32bWORDS_D(0) = '1') and (IP_PAYLOAD_DATA_VALID_LSB32b_D /= x"0") then
+ -- IP payload size is 1-4 bytes => IP_PAYLOAD_SOF coincides with IP_PAYLOAD_EOF
+ IP_PAYLOAD_SOF0 <= '1';
+ else
+ IP_PAYLOAD_SOF0 <= '0';
+ end if;
+ end if;
+end process;
+IP_PAYLOAD_SOF <= IP_PAYLOAD_SOF0 and IP_RX_FRAME_VALID_local; -- blank out ASAP when frame is invalid
+
+-- Generate EOF for the last word of the IP payload
+-- Takes into account the possibility of a zero-length payload.
+IP_PAYLOAD_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_SOF_local = '1') or (IP_RX_FRAME_VALID_local = '0') then
+ IP_PAYLOAD_EOF_local <= '0';
+ elsif (IP_RX_EOF_local = '1') then
+ if(RX_IPv4_6n_local = '1') and (IPv4_HEADER_N32bWORDS(0) = '1') and (IPv4_HEADER_MASK = "00") and (IP_RX_DATA_VALID_local(3 downto 0) = x"0") then
+ IP_PAYLOAD_EOF_local <= '1';
+ elsif(RX_IPv4_6n_local = '1') and (IPv4_HEADER_N32bWORDS(0) = '0') and (IPv4_HEADER_MASK = "00") then
+ IP_PAYLOAD_EOF_local <= '1';
+ elsif(IPv6_ENABLED = '1') and (RX_IPv4_6n_local = '0') and (IPv6_HEADER_FLAG = '0') then
+ IP_PAYLOAD_EOF_local <= '1';
+ end if;
+ elsif(IP_RX_EOF_D = '1') and (RX_IPv4_6n_local = '1') and (IPv4_HEADER_N32bWORDS_D(0) = '1') and (IP_PAYLOAD_DATA_VALID_LSB32b_D /= x"0") then
+ -- flush remaining 32 bits in cache
+ IP_PAYLOAD_EOF_local <= '1';
+ else
+ IP_PAYLOAD_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+IP_PAYLOAD_EOF <= IP_PAYLOAD_EOF_local;
+
+-- Parse IP payload length (excluding IP header), expressed in bytes.
+IP_PAYLOAD_004: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_SOF_local = '1') then
+ if (unsigned(IP_RX_DATA_local(63 downto 60)) = 4) then
+ -- IPv4 header
+ IP_PAYLOAD_LENGTH_local <= unsigned(IP_RX_DATA_local(47 downto 32)) - unsigned(IP_RX_DATA_local(59 downto 56) & "00");
+ IP_PAYLOAD_LENGTH_RDY <= '1';
+ -- IP payload length (= UDP or TCP length) = total IP length - IP header length in bytes
+ elsif(IPv6_ENABLED = '1') and (unsigned(IP_RX_DATA_local(63 downto 60)) = 6) then
+ -- IPv6 header
+ IP_PAYLOAD_LENGTH_local <= unsigned(IP_RX_DATA_local(31 downto 16));
+ IP_PAYLOAD_LENGTH_RDY <= '1';
+ -- UDP length (excludes IP header)
+ else
+ IP_PAYLOAD_LENGTH_RDY <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+IP_PAYLOAD_LENGTH <= std_logic_vector(IP_PAYLOAD_LENGTH_local);
+
+---------------------------------------------------
+--//--- UDP LAYER ---------------------------------
+---------------------------------------------------
+
+--// UDP CHECKSUM -----------------
+-- In IPv4, computing the UDP checksum is not sufficient. One must also check if the UDP checksum is zero
+-- (meaning that the sender did not compute the UDP checksum). It is captured here
+GET_UDP_CKSUM_IPv4: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_SOF_local = '1') then
+ UDPv4_CKSUM_NULL <= '0'; -- assume sender computed a non-null checksum until we reach the actual UDP header
+ elsif(IP_RX_WORD_VALID_local = '1') and (RX_IPv4_6n_local = '1') and (IPv4_PROTOCOL = x"11") then
+ -- IPv4, UDP, new word
+ -- location within the 64-bit word depends on the IP header length
+ if(IPv4_HEADER_MASK_D = "11") and (IPv4_HEADER_MASK = "00") and (unsigned(IP_RX_DATA_local(15 downto 0)) = 0) then
+ UDPv4_CKSUM_NULL <= '1';
+ end if;
+ if(IPv4_HEADER_MASK_D = "10") and (unsigned(IP_RX_DATA_local(47 downto 32)) = 0) then
+ UDPv4_CKSUM_NULL <= '1';
+ end if;
+ end if;
+ end if;
+end process;
+
+-- for timing reasons, we limit ourselves to summing up to 3 16-bit fields per CLK
+-- Different pseudo-headers are used for IPv4 and IPv6
+-- Design note: the same computation is used for UDP, TCP and IGMP. However,
+-- IGMP checksum computation only includes the IP payload, without pseudo-header.
+-- UDP/TCP checksum computation include both the IP payload and a pseudo-header.
+UDP_CKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_SOF_local = '1') then
+ if (unsigned(IP_RX_DATA_local(63 downto 60)) = 4) then
+ -- IPv4 header
+ CKSUM1 <= resize(unsigned(IP_RX_DATA_local(47 downto 32)),18) - resize(unsigned(IP_RX_DATA_local(59 downto 56) & "00"),18);
+ -- IP payload length (= UDP or TCP length) = total IP length - IP header length in bytes
+ CKSUM2 <= (others => '0');
+ CKSUM3 <= (others => '0'); -- carry
+ elsif(IPv6_ENABLED = '1') and (unsigned(IP_RX_DATA_local(63 downto 60)) = 6) then
+ -- IPv6 header
+ CKSUM1 <= resize(unsigned(IP_RX_DATA_local(31 downto 16)),18);
+ -- UDP length (excludes IP header)
+ CKSUM2 <= resize(unsigned(IP_RX_DATA_local(15 downto 8)),18);
+ -- Next header = protocol
+ CKSUM3 <= (others => '0'); -- carry
+ end if;
+ elsif(IP_RX_WORD_VALID_local = '1') then
+ if (RX_IPv4_6n_local = '1') then
+ -- IPv4
+ if(IP_RX_WORD_COUNT_local = 2) then
+ CKSUM1 <= resize(CKSUM1(15 downto 0),18) + resize(unsigned(IP_RX_DATA_local(55 downto 48)),18);
+ -- protocol
+ CKSUM2 <= resize(CKSUM2(15 downto 0),18) + IP_RX_DATA_SUM_LSW;
+ -- source address
+ elsif(IP_RX_WORD_COUNT_local = 3) then -- *042719
+ if(IP_RX_DATA_local(55 downto 48) = x"02") then
+ -- IGMP protocol case, no pseudo header in the checksum, just the IP payload. reset CKSUM1/2
+ CKSUM1 <= (others => '0');
+ CKSUM2 <= IP_RX_DATA_SUM_LSW;
+ else
+ -- UDP/TCP case, keep on summing the pseudo header
+ CKSUM1 <= resize(CKSUM1(15 downto 0),18) + IP_RX_DATA_SUM_MSW;
+ -- destination IP address
+ CKSUM2 <= resize(CKSUM2(15 downto 0),18) + IP_RX_DATA_SUM_LSW;
+ end if;
+ else
+ if (IP_HEADER_FLAG_local(1) = '0') then
+ CKSUM1 <= resize(CKSUM1(15 downto 0),18) + IP_RX_DATA_SUM_MSW;
+ end if;
+ if (IP_HEADER_FLAG_local(0) = '0') then
+ CKSUM2 <= resize(CKSUM2(15 downto 0),18) + IP_RX_DATA_SUM_LSW;
+ end if;
+ end if;
+ elsif (IPv6_ENABLED = '1') then
+ -- IPv6
+ if(IP_RX_WORD_COUNT_local <= 5) then
+ CKSUM1 <= resize(CKSUM1(15 downto 0),18) + IP_RX_DATA_SUM_MSW;
+ CKSUM2 <= resize(CKSUM2(15 downto 0),18) + IP_RX_DATA_SUM_LSW; -- *042918
+ -- destination + source IP addresses
+ elsif(IP_HEADER_FLAG_local = "00") then
+ CKSUM1 <= resize(CKSUM1(15 downto 0),18) + IP_RX_DATA_SUM_MSW;
+ CKSUM2 <= resize(CKSUM2(15 downto 0),18) + IP_RX_DATA_SUM_LSW;
+ end if;
+ end if;
+ CKSUM3 <= CKSUM3PLUS;
+ end if;
+ end if;
+end process;
+CKSUM3PLUS <= CKSUM3 + resize(CKSUM1(17 downto 16),18) + resize(CKSUM2(17 downto 16),18);
+
+-- for timing purposes, we need to reclock
+-- ready at IP_RX_EOF_D2 = IP_PAYLOAD_EOF_D
+UDP_CKSUM_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ RX_UDP_CKSUM_local <= resize(CKSUM1(15 downto 0),18) + resize(CKSUM2(15 downto 0),18) + CKSUM3PLUS;
+
+ if(RX_IPv4_6n_local = '1') and (UDPv4_CKSUM_NULL = '1') then
+ -- UDP checksum field is zero. Acceptable for IPv4, but not for IPv6
+ VALID_UDP_CHECKSUM0 <= '1';
+ else
+ VALID_UDP_CHECKSUM0 <= '0';
+ end if;
+ end if;
+end process;
+--VALID_UDP_CHECKSUM1 <= '1' when ((RX_UDP_CKSUM_local(15 downto 0) = x"FFFF") and (RX_UDP_CKSUM_local(17 downto 16) = "00"))
+-- or ((RX_UDP_CKSUM_local(15 downto 0) = x"FFFE") and (RX_UDP_CKSUM_local(17 downto 16) = "01"))
+-- or ((RX_UDP_CKSUM_local(15 downto 0) = x"FFFD") and (RX_UDP_CKSUM_local(17 downto 16) = "10")) else
+-- '0';
+-- alternative phrasing
+VALID_UDP_CHECKSUM1 <= '0' when (RX_UDP_CKSUM_local(15 downto 2) /= "11111111111111") else
+ '0' when ((RX_UDP_CKSUM_local(17 downto 16) xor RX_UDP_CKSUM_local(1 downto 0)) /= "11") else
+ '1';
+
+VALID_UDP_CHECKSUM_local <= VALID_UDP_CHECKSUM0 or VALID_UDP_CHECKSUM1;
+VALID_UDP_CHECKSUM <= VALID_UDP_CHECKSUM_local when (RX_IP_PROTOCOL_local = x"11") else '0';
+
+VALID_IP_PAYLOAD_CHECKSUM <= VALID_UDP_CHECKSUM1 when (IPv4_PROTOCOL = x"02") else '0';
+-----------------------------------------------------
+------ TCP LAYER ---------------------------------
+-----------------------------------------------------
+--
+-- The TCP checksum is computed in the same manner as the UDP checksum. Sharing the same code.
+
+-- mask the checksum when simulating using a Wireshark .cap capture file as input
+-- Reason: the checksum field may be wrong due to TCP checksum offload to hardware.
+--VALID_TCP_CHECKSUM <= VALID_UDP_CHECKSUM_local when (SIMULATION = '0') else '1';
+VALID_TCP_CHECKSUM <= VALID_UDP_CHECKSUM_local when (RX_IP_PROTOCOL_local = x"06") else '0';
+-- Note1: TCP checksum offload can be enabled/disabled in Windows/network and sharing center.
+-- Note2: TCP checksum validation can be enabled/disabled in Wireshark/Edit/Preferences/TCP
+
+
+--
+--// TEST POINTS --------------------------
+--TP(1) <= IP_RX_WORD_VALID_local;
+--TP(2) <= IP_RX_SOF_local;
+--TP(3) <= IP_RX_EOF_local;
+--TP(4) <= VALID_UNICAST_DEST_IP_local and VALID_DEST_IP_RDY_local;
+--TP(5) <= '1' when (unsigned(RX_IP_PROTOCOL_local) = 1) else '0' ;
+--TP(6) <= IP_RX_FLUSH_CACHE;
+--TP(7) <= VALID_MULTICAST_DEST_IP_local and VALID_DEST_IP_RDY_local;
+--TP(8) <= IP_HEADER_CHECKSUM_VALID_RDY_local and (not IP_HEADER_CHECKSUM_VALID_local);
+--TP(9) <= MAC_RX_EOF and MAC_RX_FRAME_VALID;
+--TP(10) <= IP_RX_FRAME_VALID_local;
+--TP(8) <= MAC_TX_EOF_local;
+--TP(9) <=
+--TP(10)<= MAC_TX_CTS;
+
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/packets_2_stream_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/packets_2_stream_10G.vhd
new file mode 100644
index 0000000..a36ba7f
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/packets_2_stream_10G.vhd
@@ -0,0 +1,270 @@
+-------------------------------------------------------------
+-- MSS copyright 2011-2018
+-- Filename: PACKETS_2_STREAM_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 7/20/16
+-- Inheritance: PACKETS_2_STREAM.VHD 1G 7/20/16
+--
+-- description: Receive packets (in sequence) and reassemble a stream.
+-- The packets validity is checked upon receiving the last packet byte. Any failure
+-- will cause this component to discard the invalid packet and rewind the write pointer in the
+-- elastic buffer to the previous valid location.
+-- No flow control on the packets side. Flow-control (see APP_CTS) on the application side.
+--
+-- This component can interface seemlessly with USB_RX.vhd at the input to receive
+-- input packets conveyed as UDP frames over the network.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity PACKETS_2_STREAM_10G is
+ generic (
+ ADDR_WIDTH: integer := 8
+ -- allocates buffer space: 73 bits * 2^ADDR_WIDTH words
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic; -- synchronous clock
+ -- Must be a global clocks. No BUFG instantiation within this component.
+ SYNC_RESET: in std_logic;
+
+ --// INPUT PACKETS
+ -- For example, interfaces with UDP_RX
+ PACKET_DATA_IN: in std_logic_vector(63 downto 0);
+ PACKET_DATA_VALID_IN: in std_logic_vector(7 downto 0);
+ PACKET_FRAME_VALID_IN: in std_logic;
+ PACKET_EOF_IN: in std_logic;
+ -- 1 CLK pulse indicating that PACKET_DATA_IN is the last byte in the received packet.
+ -- ALWAYS CHECK PACKET_FRAME_VALID_IN at the end of packet (PACKET_EOF_IN = '1') to confirm
+ -- that the packet is valid. Internal elastic buffer may have to backtrack to the the last
+ -- valid pointer to discard an invalid packet.
+ -- Reason: we only knows about bad UDP packets at the end.
+ PACKET_CTS_OUT: out std_logic; -- Clear To Send = transmit flow control.
+
+
+ --// OUTPUT STREAM
+ STREAM_DATA_OUT: out std_logic_vector(63 downto 0);
+ STREAM_DATA_VALID_OUT: out std_logic_vector(7 downto 0);
+ STREAM_CTS_IN: in std_logic; -- flow control, clear-to-send
+
+ STREAM_SOF_OUT: out std_logic;
+ STREAM_EOF_OUT: out std_logic;
+ -- optional SOF/EOF markers
+
+ --// TEST POINTS, MONITORING
+ BAD_PACKET: out std_logic;
+ -- 1 CLK wide pulse indicating a bad packet
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of PACKETS_2_STREAM_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CSA : IN std_logic;
+ CLKA : in std_logic;
+ WEA : in std_logic;
+ OEA : IN std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CSB : IN std_logic;
+ CLKB : in std_logic;
+ WEB : in std_logic;
+ OEB : IN std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+ */
+ component tdp_ram is
+ generic (
+ ADDR_WIDTH : natural;
+ DATA_WIDTH : integer);
+ port (
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic := '1';
+ enb : in std_logic := '1';
+ wea : in std_logic;
+ web : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dib : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ doa : out std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+ end component tdp_ram;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- Suffix _D indicates a one CLK delayed version of the net with the same name
+-- Suffix _E indicates a one CLK early version of the net with the same name
+-- Suffix _X indicates an extended precision version of the net with the same name
+-- Suffix _N indicates an inverted version of the net with the same name
+
+--//-- ELASTIC BUFFER ---------------------------
+signal WPTR: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WPTR_ACKED: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WEA: std_logic := '0';
+signal DIAx: std_logic_vector(72 downto 0) := (others => '0');
+signal RPTR: unsigned(ADDR_WIDTH-1 downto 0) := (others => '1');
+signal RPTR_D: unsigned(ADDR_WIDTH-1 downto 0) := (others => '1');
+signal BUF_SIZE: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal BUF_SIZE_ACKED: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal DOBx: std_logic_vector(72 downto 0) := (others => '0');
+signal DATA_VALID_E: std_logic := '0';
+signal DATA_VALID: std_logic := '0';
+signal SOFn_FLAG: std_logic := '0';
+signal STREAM_EOF_OUT_local: std_logic := '0';
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- report a bad input packet
+BAD_PACKET <= PACKET_EOF_IN and (not PACKET_FRAME_VALID_IN);
+
+--//-- ELASTIC BUFFER ---------------------------
+WEA <= '1' when (unsigned(PACKET_DATA_VALID_IN) /= 0) else '0';
+WPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WPTR <= (others => '0');
+ WPTR_ACKED <= (others => '0');
+ elsif(WEA = '1') then
+ WPTR <= WPTR + 1;
+ if(PACKET_EOF_IN = '1') then
+ -- last byte in the received packet. Packet is valid. Remember the next start of packet
+ WPTR_ACKED <= WPTR + 1;
+ end if;
+ elsif(PACKET_EOF_IN = '1')then
+ -- last byte in the received packet. Packet is invalid. Discard it (i.e. rewind the write pointer)
+ WPTR <= WPTR_ACKED;
+ end if;
+ end if;
+end process;
+
+DIAx <= PACKET_EOF_IN & PACKET_DATA_VALID_IN & PACKET_DATA_IN;
+-- Buffer size is controlled by generic ADDR_WIDTH
+/*
+BRAM_DP2_001: BRAM_DP2
+GENERIC MAP(
+ DATA_WIDTHA => 73,
+ ADDR_WIDTHA => ADDR_WIDTH,
+ DATA_WIDTHB => 73,
+ ADDR_WIDTHB => ADDR_WIDTH
+)
+PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR),
+ DIA => DIAx,
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR),
+ DIB => (others => '0'),
+ OEB => '1',
+ DOB => DOBx
+);
+*/
+BRAM_DP2_001: TDP_RAM
+GENERIC MAP(
+ DATA_WIDTH => 73,
+ ADDR_WIDTH => ADDR_WIDTH)
+PORT MAP(
+ CLKA => CLK,
+ WEA => WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR),
+ DIA => DIAx,
+ DOA => open,
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR),
+ DIB => (others => '0'),
+ DOB => DOBx
+);
+
+BUF_SIZE <= WPTR + not (RPTR);
+BUF_SIZE_ACKED <= WPTR_ACKED + not (RPTR);
+ -- occupied space in the buffer
+ -- confirmed and unconfirmed
+
+-- input flow control (buffer 3/4 full)
+PACKET_CTS_OUT <= '0' when (BUF_SIZE(ADDR_WIDTH-1 downto ADDR_WIDTH-2) = "11") else '1';
+
+-- manage read pointer
+RPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RPTR <= (others => '1');
+ RPTR_D <= (others => '1');
+ DATA_VALID_E <= '0';
+ DATA_VALID <= '0';
+ else
+ -- 1 CLK delay in reading data from block RAM
+ RPTR_D <= RPTR;
+ DATA_VALID <= DATA_VALID_E;
+
+ if(STREAM_CTS_IN = '1') and (BUF_SIZE_ACKED /= 0) then
+ RPTR <= RPTR + 1;
+ DATA_VALID_E <= '1';
+ else
+ DATA_VALID_E <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+--//-- OUTPUT --------------------------------
+STREAM_DATA_OUT <= DOBx(63 downto 0);
+STREAM_DATA_VALID_OUT <= DOBx(71 downto 64) when (DATA_VALID = '1') else (others => '0');
+STREAM_EOF_OUT_local <= DOBx(72) and DATA_VALID;
+STREAM_EOF_OUT <= STREAM_EOF_OUT_local;
+STREAM_SOF_OUT <= DATA_VALID and (not SOFn_FLAG);
+
+-- reconstruct SOF marker
+SOF_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ SOFn_FLAG <= '0'; -- arm
+ elsif(STREAM_EOF_OUT_local = '1') then
+ SOFn_FLAG <= '0'; -- arm
+ elsif(DATA_VALID = '1') then
+ SOFn_FLAG <= '1'; -- clear
+ end if;
+ end if;
+end process;
+
+--//-- TEST POINTS ----------------------------
+TP(1) <= WPTR(0);
+TP(2) <= RPTR(0);
+TP(3) <= WPTR(ADDR_WIDTH-1);
+TP(4) <= RPTR(ADDR_WIDTH-1);
+TP(5) <= '1' when (BUF_SIZE = 0) else '0';
+TP(6) <= '1' when (BUF_SIZE_ACKED = 0) else '0';
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/ping_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/ping_10G.vhd
new file mode 100644
index 0000000..ba4b677
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/ping_10G.vhd
@@ -0,0 +1,574 @@
+-------------------------------------------------------------
+-- MSS copyright 2018
+-- Filename: PING_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 3/4/18
+-- Inheritance: PING.VHD rev 4, 12/10/15
+--
+-- description: PING protocol, 10Gb, for IPv4 and IPv6
+-- Reads a received IP/ICMP frame on the fly and generates a ping echo (Ethernet format).
+-- Any new received frame is presumed to be an ICMP echo (ping) request. Within a few bytes,
+-- information is received as to the real protocol associated with the received packet.
+-- The ping echo generation is immediately cancelled if
+-- (a) the received packet type is not an IP datagram or IPv6 is not allowed
+-- (b) the received IP type is not ICMP/ICMP6
+-- (c) invalid unicast destination IP (IPv4 or IPv6)
+-- (d) packet size is greater than MAX_PING_SIZE (units = 64-bit words, including IP/ICMP headers)
+-- (e) ICMP incoming packet is not an echo request (ICMP type /= x"0800") or (ICMP6 type /= 128)
+-- (f) incorrect IP header checksum (IPv4 only)
+-- (g) erroneous MAC frame (incorrect FCS, wrong dest MAC address)
+-- Any follow-on received IP frame is discarded while a valid ping response awaits transmission in the elastic buffer.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity PING_10G is
+ generic (
+ IPv6_ENABLED: std_logic := '0';
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ MAX_PING_SIZE: std_logic_vector(7 downto 0) := x"FE"
+ -- maximum IP/ICMP size (excluding Ethernet/MAC, but including the IP/ICMP header) in 64-bit words. Larger echo requests will be ignored.
+ -- The ping buffer contains up to 18Kbits total (for a queued IP/ICMP response waiting for the tx path
+ -- to become available)
+
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ -- Must be a global clock. No BUFG instantiation within this component.
+ SYNC_RESET: in std_logic;
+
+ --// ICMP frame received
+ IP_RX_DATA: in std_logic_vector(63 downto 0);
+ IP_RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_RX_SOF: in std_logic;
+ IP_RX_EOF: in std_logic;
+ IP_RX_WORD_COUNT: in std_logic_vector(10 downto 0);
+
+ --// Partial checks (done in PACKET_PARSING common code)
+ --// basic IP validity check
+ IP_RX_FRAME_VALID2: in std_logic;
+ -- The received IP frame is presumed valid until proven otherwise.
+ -- IP frame validity checks include:
+ -- (a) protocol is IP
+ -- (b) unicast or multicast destination IP address matches
+ -- (c) correct IP header checksum (IPv4 only)
+ -- (d) allowed IPv6
+ -- (e) Ethernet frame is valid (correct FCS, dest address)
+ -- Also compute IP_RX_FRAME_VALID2 (no IP destination check)
+ -- Ready at IP_RX_VALID_D (= MAC_RX_DATA_VALID_D3)
+ VALID_UNICAST_DEST_IP: in std_logic;
+ VALID_DEST_IP_RDY : in std_logic;
+ -- Unicast destination address verification
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0);
+ -- Packet origin, already parsed in PACKET_PARSING (shared code)
+
+ --// Configuration data: IP address, MAC address
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- local IP address. 4 bytes for IPv4, 16 bytes for IPv6
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+
+ --// IP type, already parsed in PACKET_PARSING (shared code)
+ RX_IPv4_6n: in std_logic;
+ -- IP version. 4 or 6
+ RX_IP_PROTOCOL: in std_logic_vector(7 downto 0);
+ -- read between RX_IP_PROTOCOL_RDY (inclusive)(i.e. before IP_PAYLOAD_SOF) and IP_PAYLOAD_EOF (inclusive)
+ -- most common protocols:
+ -- 0 = unknown, 1 = ICMP, 2 = IGMP, 6 = TCP, 17 = UDP, 41 = IPv6 encapsulation, 89 = OSPF, 132 = SCTP
+ RX_IP_PROTOCOL_RDY: in std_logic;
+ -- 1 CLK wide pulse.
+
+ --// USER -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended. User should not supply it.
+ -- Synchonous with CLK
+ MAC_TX_DATA: out std_logic_vector(63 downto 0);
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID /= 0
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- data valid
+ MAC_TX_EOF: out std_logic;
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal. The user should check that this
+ -- signal is high before sending the next MAC_TX_DATA byte.
+ RTS: out std_logic;
+ -- '1' when a full or partial packet is ready to be read.
+ -- '0' when output buffer is empty.
+ -- When the user starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of PING_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+ */
+ component tdp_ram is
+ generic (
+ ADDR_WIDTH : natural;
+ DATA_WIDTH : integer);
+ port (
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic := '1';
+ enb : in std_logic := '1';
+ wea : in std_logic;
+ web : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dib : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ doa : out std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+ end component tdp_ram;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+--// STATE MACHINE ------------------
+signal STATE: unsigned(0 downto 0) := (others => '0');
+signal INPUT_ENABLED: std_logic := '1';
+signal IP_RX_WORD_VALID: std_logic := '0';
+signal RX_IPv4_6n0: std_logic := '0';
+
+signal IP_RX_DATA_PREVIOUS: std_logic_vector(63 downto 0) := (others => '0');
+signal IP_RX_DATA_MOD: std_logic_vector(63 downto 0) := (others => '0');
+signal REPLY_CHECKSUM: unsigned(15 downto 0) := (others => '0');
+signal IP_RX_DATA_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal IP_RX_EOF_D: std_logic := '0';
+
+--// ELASTIC BUFFER ----------------------
+signal WPTR: unsigned(7 downto 0) := (others => '0');
+signal WPTR_CONFIRMED: unsigned(7 downto 0) := (others => '0');
+signal WEA: std_logic := '0';
+signal DIA: std_logic_vector(72 downto 0) := (others => '0');
+signal DOB: std_logic_vector(72 downto 0) := (others => '0');
+signal DOB_PREVIOUS: std_logic_vector(72 downto 0) := (others => '0');
+signal RPTR: unsigned(7 downto 0) := (others => '1');
+signal BUF_SIZE: unsigned(7 downto 0) := (others => '0');
+
+--// VALIDATE PING REQUEST -----------
+signal VALID_PING_REQ0: std_logic := '0';
+signal VALID_PING_REQ: std_logic := '0';
+
+--// OUTPUT SECTION -------------------
+signal TX_SEQUENCE_CNTR: unsigned(7 downto 0) := (others => '0');
+signal TX_SEQUENCE_CNTR_D: unsigned(7 downto 0) := (others => '0');
+signal DOB_SAMPLE_CLK_E: std_logic := '0';
+signal DOB_SAMPLE_CLK: std_logic := '0';
+signal MAC_TX_CTS_D: std_logic := '0';
+signal MAC_TX_CTS_D2: std_logic := '0';
+signal MAC_TX_EOF_local: std_logic := '0';
+signal MAC_TX_DATA_VALID_local: std_logic_vector(7 downto 0) := (others => '0');
+signal RTS_local: std_logic := '0';
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// STATE MACHINE ------------------
+-- A state machine is needed as this process is memoryless.
+-- State 0 = idle or incoming IP frame being processed.
+-- State 1 = valid ping request. tx packet waiting for tx capacity. Incoming IP frames are discarded.
+STATE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ STATE <= (others => '0');
+ elsif(IP_RX_EOF_D = '1') and (VALID_PING_REQ = '1') then
+ -- event = valid PING request. Ready to send PING reply when tx channel opens.
+ -- In the mean time, incoming IP frames are discarded.
+ STATE <= "1";
+ elsif(MAC_TX_EOF_local = '1') then
+ -- event = successfully sent PING reply. Reopen input
+ STATE <= "0";
+ end if;
+ end if;
+end process;
+
+INPUT_ENABLED <= '1' when (STATE = 0) else '0';
+
+
+-- save previous IP word (needed information to swap fields)
+IN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ IP_RX_DATA_PREVIOUS <= (others => '0');
+ elsif(IP_RX_DATA_VALID /= x"00") then
+ IP_RX_DATA_PREVIOUS <= IP_RX_DATA;
+ end if;
+ end if;
+end process;
+
+--// freeze some parameters at the end of the packet
+-- Reason: we don't want subsequent packets to change this information while we are waiting
+-- to send the echo .
+FREEZE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_RX_EOF = '1') and (INPUT_ENABLED = '1') then
+ RX_IPv4_6n0 <= RX_IPv4_6n;
+ end if;
+ end if;
+end process;
+
+--// FIELDS ALTERATIONS --------------------
+-- Modify the incoming words on the fly before temporary storage into elastic buffer
+IN_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_RX_EOF_D <= IP_RX_EOF;
+ IP_RX_DATA_VALID_D <= IP_RX_DATA_VALID;
+
+ if(SYNC_RESET = '1') or (INPUT_ENABLED = '0') then
+ IP_RX_DATA_MOD <= (others => '0');
+ elsif(RX_IPv4_6n = '1') then
+ if(unsigned(IP_RX_WORD_COUNT) = 2) then
+ IP_RX_DATA_MOD(63 downto 32) <= IP_RX_DATA(63 downto 32);
+ IP_RX_DATA_MOD(31 downto 0) <= IPv4_ADDR; -- source is our IP address
+ elsif(unsigned(IP_RX_WORD_COUNT) = 3) then
+ IP_RX_DATA_MOD(63 downto 32) <= IP_RX_DATA_PREVIOUS(31 downto 0); -- swap source/dest IP addresses in response
+ IP_RX_DATA_MOD(31 downto 24) <= x"00"; -- ICMP echo reply IPv4 type
+ IP_RX_DATA_MOD(23 downto 16) <= IP_RX_DATA(23 downto 16); -- ICMP echo reply IPv4 code
+ IP_RX_DATA_MOD(15 downto 0) <= std_logic_vector(REPLY_CHECKSUM); -- ICMP echo reply IPv4 checksum
+ elsif(IP_RX_DATA_VALID /= x"00") then
+ IP_RX_DATA_MOD <= IP_RX_DATA;
+ end if;
+ elsif(IPv6_ENABLED = '1') and (RX_IPv4_6n = '0') then
+ if(unsigned(IP_RX_WORD_COUNT) = 2) then
+ IP_RX_DATA_MOD <= IPv6_ADDR(127 downto 64); -- source is our IP address
+ elsif(unsigned(IP_RX_WORD_COUNT) = 3) then
+ IP_RX_DATA_MOD <= IPv6_ADDR(63 downto 0); -- source is our IP address
+ elsif(unsigned(IP_RX_WORD_COUNT) = 4) then
+ IP_RX_DATA_MOD <= RX_SOURCE_IP_ADDR(127 downto 64); -- destination IP
+ elsif(unsigned(IP_RX_WORD_COUNT) = 5) then
+ IP_RX_DATA_MOD <= RX_SOURCE_IP_ADDR(63 downto 0); -- destination IP
+ elsif(unsigned(IP_RX_WORD_COUNT) = 6) then
+ IP_RX_DATA_MOD <= x"8100" & std_logic_vector(REPLY_CHECKSUM) & IP_RX_DATA(31 downto 0); -- modify the ICMP checksum
+ elsif(IP_RX_DATA_VALID /= x"00") then
+ IP_RX_DATA_MOD <= IP_RX_DATA;
+ end if;
+ end if;
+ end if;
+end process;
+
+REPLY_CHECKSUM_GEN: process(IP_RX_DATA, RX_IPv4_6n)
+variable CKSUM: unsigned(16 downto 0);
+begin
+ if(RX_IPv4_6n = '1') then -- IPv4
+ CKSUM := resize(unsigned(IP_RX_DATA(15 downto 0)),17);
+ CKSUM := CKSUM + x"0800";
+ else -- IPv6
+ CKSUM := resize(unsigned(IP_RX_DATA(47 downto 32)),17);
+ CKSUM := CKSUM - x"0100";
+ end if;
+ if(CKSUM(16) = '1') then
+ CKSUM := CKSUM + 1;
+ end if;
+ REPLY_CHECKSUM <= CKSUM(15 downto 0);
+end process;
+
+--// ELASTIC BUFFER ----------------------
+-- Stores the IP/ICMP frame until validity check is complete and transmission path is open
+WEA_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WEA <= '0';
+ elsif(unsigned(IP_RX_DATA_VALID) /= 0) and (INPUT_ENABLED = '1') then
+ WEA <= '1';
+ else
+ WEA <= '0';
+ end if;
+ end if;
+end process;
+
+-- write pointer management
+WPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WPTR <= (others => '0');
+ elsif(IP_RX_SOF = '1') then
+ -- rewind write pointer
+ WPTR <= (others => '0');
+ elsif(WEA = '1') then
+ WPTR <= WPTR + 1;
+ end if;
+ end if;
+end process;
+
+-- confirm WPTR when valid IP/ICMP request
+WPTR_CONFIRMED_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_TX_EOF_local = '1') then
+ WPTR_CONFIRMED <= (others => '0');
+ elsif(IP_RX_EOF_D = '1') and (VALID_PING_REQ = '1') then
+ WPTR_CONFIRMED <= WPTR+1;
+ end if;
+ end if;
+end process;
+
+-- elastic buffer.
+-- 18Kbit buffer(s)
+DIA <= IP_RX_EOF_D & IP_RX_DATA_VALID_D & IP_RX_DATA_MOD;
+
+-- GIS Edit : replaced the memory model with one compatible with Intel devices
+/*
+BRAM_DP2_001: BRAM_DP2
+GENERIC MAP(
+ DATA_WIDTHA => 73,
+ ADDR_WIDTHA => 8,
+ DATA_WIDTHB => 73,
+ ADDR_WIDTHB => 8
+
+)
+PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR), -- Port A 8-bit Address Input
+ DIA => DIA, -- Port A 65-bit Data Input
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR), -- Port B 8-bit Address Input
+ DIB => (others => '0'), -- Port B 65-bit Data Input
+ OEB => '1',
+ DOB => DOB -- Port B 65-bit Data Output
+);
+*/
+
+BRAM_DP2_001: TDP_RAM
+GENERIC MAP(
+ DATA_WIDTH => 73,
+ ADDR_WIDTH => 8)
+PORT MAP(
+ CLKA => CLK,
+ WEA => WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR), -- Port A 8-bit Address Input
+ DIA => DIA, -- Port A 65-bit Data Input
+ DOA => open,
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR), -- Port B 8-bit Address Input
+ DIB => (others => '0'), -- Port B 65-bit Data Input
+ DOB => DOB); -- Port B 65-bit Data Output
+
+-- occupied buffer space, in bytes
+BUF_SIZE <= WPTR_CONFIRMED + (not RPTR);
+
+--// VALIDATE PING REQUEST -----------
+-- The ping echo generation is immediately cancelled if
+-- (a) the received packet type is not an IP datagram or IPv6 is not allowed
+-- (b) the received IP type is not ICMP/ICMP6
+-- (c) invalid unicast destination IP (IPv4 or IPv6)
+-- (d) packet size is greater than MAX_PING_SIZE (units = 64-bit words, including IP/ICMP headers)
+-- (e) ICMP incoming packet is not an echo request (ICMP type /= x"0800") or (ICMP6 type /= 128)
+-- (f) incorrect IP header checksum (IPv4 only)
+-- (g) erroneous MAC frame (incorrect FCS, wrong dest MAC address)
+
+IP_RX_WORD_VALID <= '1' when (unsigned(IP_RX_DATA_VALID) /= 0) else '0';
+
+VALIDITY_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ VALID_PING_REQ0 <= '1';
+ elsif(IP_RX_SOF = '1') then
+ -- just received first word in an IP frame. Assume validity
+ VALID_PING_REQ0 <= '1';
+ else
+ if(RX_IP_PROTOCOL_RDY = '1') and (unsigned(RX_IP_PROTOCOL) /= 1) and (unsigned(RX_IP_PROTOCOL) /= 58) then
+ -- (b) not ICMP nor ICMPv6
+ VALID_PING_REQ0 <= '0';
+ end if;
+ if(IP_RX_WORD_VALID = '1') and (unsigned(IP_RX_WORD_COUNT) = 3) and (RX_IPv4_6n = '1') and (IP_RX_DATA(31 downto 16) /= x"0800") then
+ -- (e) IPv4 and ICMP incoming packet is not an echo request (ICMP type /= 8)
+ VALID_PING_REQ0 <= '0';
+ end if;
+ if(VALID_DEST_IP_RDY = '1') and (VALID_UNICAST_DEST_IP = '0') then
+ -- (c) invalid destination IP (IPv4 or IPv6)
+ VALID_PING_REQ0 <= '0';
+ end if;
+ if(IP_RX_WORD_VALID = '1') and (unsigned(IP_RX_WORD_COUNT) = 6) and (RX_IPv4_6n = '0') and
+ ((IP_RX_DATA(63 downto 48) /= x"8000") or (IPv6_ENABLED = '0')) then
+ -- (e) IPv6 and ICMP6 incoming packet is not an echo request (ICMP6 type /= 128)
+ VALID_PING_REQ0 <= '0';
+ end if;
+ if(IP_RX_WORD_VALID = '1') and (unsigned(IP_RX_WORD_COUNT(MAX_PING_SIZE'left downto 0)) > unsigned(MAX_PING_SIZE)) then
+ -- (d) packet size is greater than MAX_PING_SIZE (units = 64-bit words, including IP/ICMP headers)
+ VALID_PING_REQ0 <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+VALID_PING_REQ <= VALID_PING_REQ0 and IP_RX_FRAME_VALID2; -- combine with the other checks done in parsing.vhd
+
+--// OUTPUT SECTION -------------------
+-- send request to send when a valid IP/ICMP echo response is ready
+RTS_local <= '1' when (BUF_SIZE /= 0) else '0';
+RTS <= RTS_local;
+
+-- Output MAC frame generation
+RPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DOB_SAMPLE_CLK <= DOB_SAMPLE_CLK_E; -- latency to read from RAM
+ TX_SEQUENCE_CNTR_D <= TX_SEQUENCE_CNTR;
+ MAC_TX_CTS_D <= MAC_TX_CTS;
+ MAC_TX_CTS_D2 <= MAC_TX_CTS_D;
+
+ if(SYNC_RESET = '1') or (MAC_TX_EOF_local = '1') then
+ TX_SEQUENCE_CNTR <= (others => '0');
+ RPTR <= (others => '1');
+ DOB_SAMPLE_CLK_E <= '0';
+ elsif(RTS_local = '1') and (MAC_TX_CTS = '1') then
+ -- buffer is not empty and MAC requests another byte
+ TX_SEQUENCE_CNTR <= TX_SEQUENCE_CNTR + 1;
+ DOB_SAMPLE_CLK_E <= '1';
+ if(TX_SEQUENCE_CNTR > 0) then
+ RPTR <= RPTR + 1;
+ end if;
+ else
+ DOB_SAMPLE_CLK_E <= '0';
+ end if;
+ end if;
+end process;
+
+-- remember previous word
+DOB_PREVIOUS_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(DOB_SAMPLE_CLK = '1') then
+ DOB_PREVIOUS <= DOB;
+ end if;
+ end if;
+end process;
+
+MAC_TX_DATA_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ case TX_SEQUENCE_CNTR_D is
+ when x"01" =>
+ MAC_TX_DATA(63 downto 16) <= RX_SOURCE_MAC_ADDR; -- source <-> destination MAC
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ when x"02" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0); -- source <-> destination MAC
+ if(RX_IPv4_6n0 = '1') then
+ MAC_TX_DATA(31 downto 16) <= x"0800"; -- IPv4
+ else
+ MAC_TX_DATA(31 downto 16) <= x"86dd"; -- IPv6
+ end if;
+ MAC_TX_DATA(15 downto 0) <= DOB(63 downto 48);
+ when others =>
+ MAC_TX_DATA(63 downto 16) <= DOB_PREVIOUS(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= DOB(63 downto 48);
+ end case;
+ end if;
+end process;
+
+MAC_TX_DATA_VALID_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_TX_EOF_local = '1') or (STATE = "0") then
+ MAC_TX_DATA_VALID_local <= x"00";
+ elsif(DOB_SAMPLE_CLK = '1') then
+ if(unsigned(TX_SEQUENCE_CNTR_D) < 3) then
+ MAC_TX_DATA_VALID_local <= x"FF";
+ else
+ MAC_TX_DATA_VALID_local(7 downto 2) <= DOB_PREVIOUS(69 downto 64);
+ MAC_TX_DATA_VALID_local(1 downto 0) <= DOB(71 downto 70);
+ end if;
+ elsif(MAC_TX_CTS_D2 = '1') and (unsigned(DOB_PREVIOUS(69 downto 64)) /= 0) then
+ -- flush last bytes
+ MAC_TX_DATA_VALID_local(7 downto 2) <= DOB_PREVIOUS(69 downto 64);
+ MAC_TX_DATA_VALID_local(1 downto 0) <= "00";
+ else
+ MAC_TX_DATA_VALID_local <= x"00";
+ end if;
+ end if;
+end process;
+MAC_TX_DATA_VALID <= MAC_TX_DATA_VALID_local;
+
+MAC_TX_EOF_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_TX_EOF_local = '1') or (STATE = "0") then
+ MAC_TX_EOF_local <= '0';
+ elsif(DOB_SAMPLE_CLK = '1') then
+ if (DOB_SAMPLE_CLK_E = '0') and (BUF_SIZE = 0) and (unsigned(DOB(69 downto 64)) = 0) then
+ MAC_TX_EOF_local <= '1';
+ end if;
+ elsif(DOB_SAMPLE_CLK = '0') and (MAC_TX_CTS_D2 = '1') and (unsigned(DOB_PREVIOUS(69 downto 64)) /= 0) then
+ -- flush last bytes
+ MAC_TX_EOF_local <= '1';
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+
+
+
+--// TEST POINTS --------------------------
+TP(1) <= IP_RX_EOF_D and VALID_PING_REQ;
+--TP(1) <= IP_RX_SOF;
+TP(2) <= '1' when (IP_RX_DATA_VALID /= x"00") else '0';
+TP(3) <= IP_RX_EOF;
+TP(4) <= VALID_PING_REQ0;
+TP(5) <= VALID_UNICAST_DEST_IP and VALID_DEST_IP_RDY;
+TP(6) <= IP_RX_FRAME_VALID2;
+TP(7) <= DOB_SAMPLE_CLK;
+TP(8) <= MAC_TX_EOF_local;
+TP(9) <= '1' when (MAC_TX_DATA_VALID_local /= x"00") else '0';
+TP(10)<= MAC_TX_CTS;
+
+
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/sdp_ram.vhd b/generic_ip/third_party_ip/tcp_server/src/sdp_ram.vhd
new file mode 100644
index 0000000..f1e5557
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/sdp_ram.vhd
@@ -0,0 +1,48 @@
+-- Simple Dual-Port Block RAM with Two Clocks
+-- Correct Modelization with a Shared Variable
+-- File: simple_dual_two_clocks.vhd
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.std_logic_unsigned.all;
+
+entity sdp_ram is
+ generic(
+ ADDR_WIDTH: natural := 11;
+ DATA_WIDTH: integer := 9);
+ port(
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic;
+ enb : in std_logic;
+ wea : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+end sdp_ram;
+
+architecture syn of sdp_ram is
+ type ram_type is array (2**ADDR_WIDTH-1 downto 0) of std_logic_vector(DATA_WIDTH-1 downto 0);
+ shared variable RAM : ram_type;
+begin
+ process(clka)
+ begin
+ if clka'event and clka = '1' then
+ if ena = '1' then
+ if wea = '1' then
+ RAM(conv_integer(addra)) := dia;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ process(clkb)
+ begin
+ if clkb'event and clkb = '1' then
+ if enb = '1' then
+ dob <= RAM(conv_integer(addrb));
+ end if;
+ end if;
+ end process;
+
+end syn;
diff --git a/generic_ip/third_party_ip/tcp_server/src/serial64b_8b.vhd b/generic_ip/third_party_ip/tcp_server/src/serial64b_8b.vhd
new file mode 100644
index 0000000..7026dae
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/serial64b_8b.vhd
@@ -0,0 +1,204 @@
+-------------------------------------------------------------
+-- MSS copyright 2018-2019
+-- Filename: SERIAL_64b_8b.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 1b
+-- Date last modified: 4/19/19
+-- Inheritance: n/a
+--
+-- description: Specialized component to get 8-byte data words (typically from the COM5502 TCP receive interface)
+-- and queues the bytes into a simpler output buffer.
+-- Flow control is used from sink to source.
+-- The main reason for this component is the complexity of the 64-bit TCP rx interface.
+-- Simplicity comes at the price of throughput as the byte-wide interface is 8 times slower than the 64-bit interface.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity SERIAL_64b_8b is
+ generic (
+ LOOK_AHEAD: std_logic := '1'
+ -- '1' is DATA_OUT is ready before output request CTS_IN (CTS_IN then means 'move to the next byte')
+ -- '0' if DATA_OUT follows CTS_IN
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic; -- synchronous clock
+ -- Must be a global clocks. No BUFG instantiation within this component.
+ SYNC_RESET: in std_logic;
+
+ --// INPUT PACKETS
+ DATA_IN: in std_logic_vector(63 downto 0);
+ -- packed MSB first
+ DATA_VALID_IN: in std_logic_vector(7 downto 0);
+ -- MSb first
+ -- FF indicates that DATA_IN contains a complete 8-byte word (one CLK pulse only)
+ -- 80,C0,E0,F0,F8,FC,FE indicate a partially fully DATA_IN (can last more than one clock until the word becomes full)
+ RTS_IN: in std_logic; -- Ready To Send
+ CTS_OUT: out std_logic; -- Clear To Send
+ CTS_OUT_ACK: in std_logic; -- CTS_OUT accepted. New (partial) word at the next clock
+
+
+ --// OUTPUT STREAM
+ DATA_OUT: out std_logic_vector(7 downto 0);
+ DATA_VALID_OUT: out std_logic;
+ CTS_IN: in std_logic; -- flow control, clear-to-send (1 clk pulse requesting a byte)
+ RTS_OUT: out std_logic; -- indicates at least one byte awaiting to be read. User must raise CTS_IN for 1 clk to get it.
+
+ --// TEST POINTS, MONITORING
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of SERIAL_64b_8b is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- Suffix _D indicates a one CLK delayed version of the net with the same name
+-- Suffix _E indicates a one CLK early version of the net with the same name
+-- Suffix _X indicates an extended precision version of the net with the same name
+-- Suffix _N indicates an inverted version of the net with the same name
+
+signal SERIALIZING_IN_PROGRESS: std_logic := '0';
+signal DATA_VALID_IN_EXTENDED: std_logic := '0';
+signal DATA_VALID_IN_D: std_logic_vector(7 downto 0) := (others => '0');
+signal NEED_NEXT_WORD: std_logic := '0';
+signal CTS_OUT_local: std_logic := '0';
+signal CTS_OUT_D: std_logic := '0';
+signal NEXT_BYTE: std_logic_vector(7 downto 0) := (others => '0');
+signal RTS_OUT_local: std_logic := '0';
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- flow control
+SERIALIZING_IN_PROGRESS_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ SERIALIZING_IN_PROGRESS <= '0';
+ elsif(CTS_OUT_ACK = '1') then
+ -- new incoming word (partial or full)
+ SERIALIZING_IN_PROGRESS <= '1';
+ elsif(NEXT_BYTE(0) = '1') and (CTS_IN = '1') then
+ SERIALIZING_IN_PROGRESS <= '0';
+ end if;
+ end if;
+end process;
+
+-- extend the DATA_VALID_IN=xFF (a single clk pulse) until the next byte (first in next word) is received
+EXTEND_DATA_VALID_IN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ DATA_VALID_IN_EXTENDED <= '0';
+ elsif(NEXT_BYTE(0) = '1') and (CTS_IN = '1') then
+ -- reading the last byte in a word. clear
+ DATA_VALID_IN_EXTENDED <= '0';
+ elsif(DATA_VALID_IN = x"FF") then
+ DATA_VALID_IN_EXTENDED <= '1';
+ end if;
+ end if;
+end process;
+
+-- need next word
+NEED_NEXT_WORD <= '1' when (NEXT_BYTE = x"80") else '0';
+
+-- send request for next word
+CTS_OUT_local <= RTS_IN and (not SERIALIZING_IN_PROGRESS) and NEED_NEXT_WORD and not(CTS_OUT_D);
+CTS_OUT <= CTS_OUT_local;
+
+-- flow control
+CTS_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ CTS_OUT_D <= CTS_OUT_local;
+ end if;
+end process;
+
+-- byte pointer. Indicates the next byte to read.
+NEXT_BYTE_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ -- Point to first byte (MSB)
+ NEXT_BYTE <= "10000000";
+ elsif(CTS_IN = '1') and (RTS_OUT_local = '1') then
+ -- sink requests the next byte and it is available
+ -- circular shift of a single '1' from left to right
+ NEXT_BYTE <= NEXT_BYTE(0) & NEXT_BYTE(7 downto 1);
+ end if;
+ end if;
+end process;
+
+LH0: if (LOOK_AHEAD = '0') generate
+ DATA_OUT_GEN: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ DATA_VALID_OUT <= RTS_OUT_local and CTS_IN;
+
+ if(SYNC_RESET = '1') then
+ DATA_OUT <= (others => '0');
+ elsif(CTS_IN = '1') then
+ if (NEXT_BYTE(7) = '1') then -- MSB first
+ DATA_OUT <= DATA_IN(63 downto 56);
+ elsif (NEXT_BYTE(6) = '1') then
+ DATA_OUT <= DATA_IN(55 downto 48);
+ elsif (NEXT_BYTE(5) = '1') then
+ DATA_OUT <= DATA_IN(47 downto 40);
+ elsif (NEXT_BYTE(4) = '1') then
+ DATA_OUT <= DATA_IN(39 downto 32);
+ elsif (NEXT_BYTE(3) = '1') then
+ DATA_OUT <= DATA_IN(31 downto 24);
+ elsif (NEXT_BYTE(2) = '1') then
+ DATA_OUT <= DATA_IN(23 downto 16);
+ elsif (NEXT_BYTE(1) = '1') then
+ DATA_OUT <= DATA_IN(15 downto 8);
+ else
+ --elsif (NEXT_BYTE(0) = '1') then
+ DATA_OUT <= DATA_IN(7 downto 0);
+ end if;
+ end if;
+ end if;
+ end process;
+
+ RTS_OUT_local <= '1' when ((NEXT_BYTE and DATA_VALID_IN) /= x"00") or (DATA_VALID_IN_EXTENDED = '1') else '0';
+end generate;
+
+LH1: if (LOOK_AHEAD = '1') generate
+ DATA_OUT_GEN: process(NEXT_BYTE, DATA_IN)
+ begin
+ if (NEXT_BYTE(7) = '1') then -- MSB first
+ DATA_OUT <= DATA_IN(63 downto 56);
+ elsif (NEXT_BYTE(6) = '1') then
+ DATA_OUT <= DATA_IN(55 downto 48);
+ elsif (NEXT_BYTE(5) = '1') then
+ DATA_OUT <= DATA_IN(47 downto 40);
+ elsif (NEXT_BYTE(4) = '1') then
+ DATA_OUT <= DATA_IN(39 downto 32);
+ elsif (NEXT_BYTE(3) = '1') then
+ DATA_OUT <= DATA_IN(31 downto 24);
+ elsif (NEXT_BYTE(2) = '1') then
+ DATA_OUT <= DATA_IN(23 downto 16);
+ elsif (NEXT_BYTE(1) = '1') then
+ DATA_OUT <= DATA_IN(15 downto 8);
+ else
+ --elsif (NEXT_BYTE(0) = '1') then
+ DATA_OUT <= DATA_IN(7 downto 0);
+ end if;
+ end process;
+
+ DATA_VALID_OUT <= RTS_OUT_local and CTS_IN;
+
+ RTS_OUT_local <= '1' when ((NEXT_BYTE and DATA_VALID_IN) /= x"00") or (DATA_VALID_IN_EXTENDED = '1') else '0';
+
+end generate;
+
+RTS_OUT <= RTS_OUT_local;
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/stream_2_packets_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/stream_2_packets_10G.vhd
new file mode 100644
index 0000000..7c30264
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/stream_2_packets_10G.vhd
@@ -0,0 +1,440 @@
+-------------------------------------------------------------
+-- MSS copyright 2018
+-- Filename: STREAM_2_PACKETS_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 3/11/18
+-- Inheritance: COM-5402 STREAM_2_PACKETS.VHD 8/18/11 rev1
+--
+-- description: Send a stream in the form of packets.
+-- 10Gbits/s speed.
+-- Fully portable VHDL.
+-- The input stream is segmented into data packets. The packet transmission
+-- is triggered when one of two events occur:
+-- (a) full packet: the number of bytes waiting for transmission is greater or equal than
+-- the maximum packet size (see constant MAX_PACKET_SIZE within), or
+-- (b) no-new-input timeout: there are a few bytes waiting for transmission but no new input
+-- bytes were received in the last 200us (or adjust constant TX_IDLE_TIMEOUT within).
+--
+-- If the follow-on transmission component is unable to immediately send the packet
+-- (for example if UDP_TX is missing routing information) it will return a negative acknowledgement (NAK).
+-- This component is responsible for triggering a re-transmission at a later time.
+-- The wait before the next retransmission attempt is defined by the constant TX_RETRY_TIMEOUT within.
+--
+-- This component can interface seemlessly with PRBS11P.vhd at the input for generating
+-- a high-speed pseudo-random test pattern generation (perfect for throughput and BER
+-- measurements).
+--
+-- This component can interface seemlessly with USB_TX.vhd at the output to encapsulate
+-- the output packets within UDP frames for network transmission.
+
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity STREAM_2_PACKETS_10G is
+ generic (
+ MAX_PACKET_SIZE: integer := 256;
+ -- in number of 64-bit words.
+ TX_IDLE_TIMEOUT: integer range 0 to 50 := 50;
+ -- inactive input timeout, expressed in 4us units. -- 50*4us = 200us
+ ADDR_WIDTH: integer := 8;
+ -- allocates buffer space: 72 bits * 2^ADDR_WIDTH words
+ -- CAREFUL: if the buffer allocation is too small, the maximum frame size may not be reached
+ -- and only the (slow) timer will trigger a packet transmission
+ SIMULATION: std_logic := '0'
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ CLK: in std_logic; -- synchronous clock
+ -- Must be a global clocks. No BUFG instantiation within this component.
+ TICK_4US: in std_logic;
+
+ --// INPUT STREAM
+ STREAM_DATA: in std_logic_vector(63 downto 0);
+ STREAM_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- valid must be either 0x00 or 0xFF. No partial word allowed here.
+ STREAM_CTS: out std_logic; -- flow control
+
+ --// OUTPUT PACKETS
+ -- For example, interfaces with UDP_TX
+ DATA_OUT: out std_logic_vector(63 downto 0);
+ DATA_VALID_OUT: out std_logic_vector(7 downto 0);
+ SOF_OUT: out std_logic; -- also resets internal state machine
+ EOF_OUT: out std_logic;
+ CTS_IN: in std_logic; -- Clear To Send = transmit flow control.
+ ACK_IN: in std_logic;
+ -- previous packet is accepted for transmission.
+ -- ACK/NAK can arrive anytime after SOF_OUT, even before the packet is fully transferred
+ NAK_IN: in std_logic;
+ -- could not send the packet (for example, no routing information available for the selected
+ -- LAN destination IP). Try later.
+
+ --// TEST POINTS
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of STREAM_2_PACKETS_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CSA : IN std_logic;
+ CLKA : in std_logic;
+ WEA : in std_logic;
+ OEA : IN std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CSB : IN std_logic;
+ CLKB : in std_logic;
+ WEB : in std_logic;
+ OEB : IN std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+ */
+ component tdp_ram is
+ generic (
+ ADDR_WIDTH : natural;
+ DATA_WIDTH : integer);
+ port (
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic := '1';
+ enb : in std_logic := '1';
+ wea : in std_logic;
+ web : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dib : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ doa : out std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+ end component tdp_ram;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- Suffix _D indicates a one CLK delayed version of the net with the same name
+-- Suffix _E indicates a one CLK early version of the net with the same name
+-- Suffix _X indicates an extended precision version of the net with the same name
+-- Suffix _N indicates an inverted version of the net with the same name
+
+--//-- COMPONENT CONFIGURATION (FIXED AT PRE-SYNTHESIS) ---------------
+constant TX_RETRY_TIMEOUT: integer range 0 to 1023 := 500; -- expressed in 4us units. -- 500*4us = 2ms
+constant TX_RETRY_TIMEOUT_SIM: integer range 0 to 1023 := 10; -- shorter timer during simulations
+ -- wait time after a NAK before trying a retransmission, expressed in 4us units. -- 500*4us = 2ms
+ -- IMPORTANT: the timeout starts at the SOF. It therefore includes the output data transfer duration (MAX_PACKET_SIZE/fCLK).
+ -- Always make sure the timeout is always greater than the output data transfer duration.
+
+
+--//-- INPUT IDLE DETECTION ---------------------------
+signal TX_IDLE_TIMER: integer range 0 to 50 := TX_IDLE_TIMEOUT;
+signal TX_IDLE: std_logic := '0';
+
+--//-- ELASTIC BUFFER ---------------------------
+signal WPTR: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal RPTR: unsigned(ADDR_WIDTH-1 downto 0) := (others => '1');
+signal RPTR_INC: unsigned(ADDR_WIDTH-1 downto 0) := (others => '1');
+signal RPTR_ACKED: unsigned(ADDR_WIDTH-1 downto 0) := (others => '1');
+signal RPTR_MAX: unsigned(ADDR_WIDTH-1 downto 0) := (others => '1');
+signal BUF_SIZE: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal BUF_SIZE_ACKED: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WEA: std_logic := '0';
+signal DIA: std_logic_vector(71 downto 0) := (others => '0');
+signal DOB: std_logic_vector(71 downto 0) := (others => '0');
+
+--//-- READ POINTER AND STATE MACHINE ----------------------------
+signal STATE: integer range 0 to 3 := 0;
+signal WORD_VALID_E: std_logic := '0';
+signal WORD_VALID: std_logic := '0';
+signal SOF_E: std_logic := '0';
+signal SOF: std_logic := '0';
+signal EOF_E: std_logic := '0';
+signal EOF: std_logic := '0';
+signal TX_RETRY_TIMER: integer range 0 to 1023 := 0;
+signal TX_RETRY_TIMEOUT_B: integer range 0 to 1023 := 0;
+
+signal ACK_IN_FLAG: std_logic := '0';
+signal NAK_IN_FLAG: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+-- during simulations, reduce long timer values
+TX_RETRY_TIMEOUT_B <= TX_RETRY_TIMEOUT when (SIMULATION = '0') else TX_RETRY_TIMEOUT_SIM;
+
+--//-- INPUT IDLE DETECTION ---------------------------
+-- Raise a flag when no new Tx data is received in the last 200 us.
+-- Keep track for each stream.
+TX_IDLE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_IDLE_TIMER <= TX_IDLE_TIMEOUT;
+ elsif(WEA = '1') then
+ -- new transmit data, reset counter
+ --TX_IDLE_TIMER <= 1; -- TEST TEST TEST FOR SIMULATION PURPOSES ONLY
+ TX_IDLE_TIMER <= TX_IDLE_TIMEOUT;
+ elsif(TICK_4US = '1') and (TX_IDLE_TIMER /= 0) then
+ -- otherwise, decrement until counter reaches 0 (TX_IDLE condition)
+ TX_IDLE_TIMER <= TX_IDLE_TIMER -1;
+ end if;
+ end if;
+end process;
+
+TX_IDLE <= '1' when (TX_IDLE_TIMER = 0) and (WEA = '0') else '0';
+
+--//-- ELASTIC BUFFER ---------------------------
+WEA <= '1' when (unsigned(STREAM_DATA_VALID) /= 0) else '0';
+
+WPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WPTR <= (others => '0');
+ elsif(WEA = '1') then
+ WPTR <= WPTR + 1;
+ end if;
+ end if;
+end process;
+
+DIA(63 downto 0) <= STREAM_DATA;
+DIA(71 downto 64) <= STREAM_DATA_VALID;
+
+-- Buffer size is controlled by generic ADDR_WIDTH
+-- GIS Edit : replaced the memory model with one compatible with Intel devices
+/*
+BRAM_DP2_001: BRAM_DP2
+GENERIC MAP(
+ DATA_WIDTHA => 72,
+ ADDR_WIDTHA => ADDR_WIDTH,
+ DATA_WIDTHB => 72,
+ ADDR_WIDTHB => ADDR_WIDTH
+)
+PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR),
+ DIA => DIA,
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR),
+ DIB => (others => '0'),
+ OEB => '1',
+ DOB => DOB
+);
+*/
+
+BRAM_DP2_001: TDP_RAM
+GENERIC MAP(
+ DATA_WIDTH => 72,
+ ADDR_WIDTH => ADDR_WIDTH)
+PORT MAP(
+ CLKA => CLK,
+ WEA => WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR),
+ DIA => DIA,
+ DOA => open,
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR),
+ DIB => (others => '0'),
+ DOB => DOB);
+
+BUF_SIZE <= WPTR + not (RPTR);
+ -- occupied space in the buffer (i.e. data waiting for transmission)
+BUF_SIZE_ACKED <= WPTR + not (RPTR_ACKED);
+-- input flow control (buffer 3/4 full)
+STREAM_CTS <= '0' when (BUF_SIZE_ACKED(ADDR_WIDTH-1 downto ADDR_WIDTH-2) = "11") else '1';
+
+--//-- READ POINTER AND STATE MACHINE ----------------------------
+-- manage read pointer
+RPTR_INC <= RPTR + 1;
+RPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ -- 1 CLK delay in reading data from block RAM
+ WORD_VALID <= WORD_VALID_E;
+ SOF <= SOF_E;
+ EOF <= EOF_E;
+
+ if(SYNC_RESET = '1') then
+ STATE <= 0;
+ RPTR <= (others => '1');
+ WORD_VALID_E <= '0';
+ SOF_E <= '0';
+ EOF_E <= '0';
+ WORD_VALID <= '0';
+ SOF <= '0';
+ EOF <= '0';
+ elsif(STATE = 0) and (CTS_IN = '1') and (BUF_SIZE /= 0) then
+ -- idle state, destination ready for tx and data is waiting in input elastic buffer
+ if(BUF_SIZE >= MAX_PACKET_SIZE) then
+ -- tx trigger 2: got enough data in buffer to fill a maximum size packet
+ STATE <= 1;
+ RPTR_MAX <= RPTR_ACKED + MAX_PACKET_SIZE;
+ RPTR <= RPTR + 1; -- start transferring the first word
+ WORD_VALID_E <= '1';
+ SOF_E <= '1';
+ if(MAX_PACKET_SIZE = 1) then
+ -- special case: 1 word packet. EOF = SOF
+ EOF_E <= '1';
+ end if;
+ elsif(TX_IDLE = '1') then
+ -- tx trigger 1: timeout waiting for fresh input bytes
+ STATE <= 1;
+ RPTR_MAX <= WPTR - 1;
+ RPTR <= RPTR + 1; -- start transferring the first word
+ WORD_VALID_E <= '1';
+ SOF_E <= '1';
+ if(BUF_SIZE = 1) then
+ -- special case: 1 byte packet. EOF = SOF
+ EOF_E <= '1';
+ end if;
+ end if;
+ elsif(STATE = 1) then
+ SOF_E <= '0';
+ if (RPTR = RPTR_MAX) then
+ -- end of packet transmission
+ WORD_VALID_E <= '0';
+ EOF_E <= '0';
+ STATE <= 2; -- data transfer complete. wait for ACK or NAK
+ TX_RETRY_TIMER <= TX_RETRY_TIMEOUT_B;
+ -- this timer has two objectives:
+ -- (a) make sure the state machine does not get stuck at state 2 if for some unexplained reason
+ -- no ACK/NAK is received, and
+ -- (b) wait a bit before retransmitting a NAK'ed packet.
+ else
+ -- not yet done transferring bytes
+ if(CTS_IN = '1') then
+ RPTR <= RPTR + 1; -- continue transferring bytes
+ WORD_VALID_E <= '1';
+ if(RPTR_INC = RPTR_MAX) then
+ EOF_E <= '1';
+ end if;
+ else
+ WORD_VALID_E <= '0';
+ end if;
+ end if;
+ elsif(STATE = 2) then
+ -- data transfer complete. waiting for ACK/NAK
+ if(ACK_IN = '1') or (ACK_IN_FLAG = '1') then
+ -- All done.
+ if (CTS_IN = '1') and (BUF_SIZE >= MAX_PACKET_SIZE) then
+ -- don't waste a clock. skip going to STATE=0
+ -- tx trigger 2: got enough data in buffer to fill a maximum size packet
+ STATE <= 1;
+ RPTR_MAX <= RPTR + MAX_PACKET_SIZE;
+ RPTR <= RPTR + 1; -- start transferring the first word
+ WORD_VALID_E <= '1';
+ SOF_E <= '1';
+ if(MAX_PACKET_SIZE = 1) then
+ -- special case: 1 word packet. EOF = SOF
+ EOF_E <= '1';
+ end if;
+ else
+ -- wait for the next trigger condition
+ STATE <= 0; -- back to idle
+ end if;
+ elsif(NAK_IN = '1') or (NAK_IN_FLAG = '1') then
+ -- no transfer. try again later
+ STATE <= 3; -- wait a bit, then re-try
+ RPTR <= RPTR_ACKED; -- rewind read pointer
+ elsif(TX_RETRY_TIMER = 0) then
+ -- timer expired without receiving an ACK/NAK (abnormal condition). go back to idle
+ STATE <= 0;
+ RPTR <= RPTR_ACKED; -- rewind read pointer
+ elsif(TICK_4US = '1') then
+ TX_RETRY_TIMER <= TX_RETRY_TIMER - 1;
+ end if;
+ elsif(STATE = 3) then
+ -- wait a bit then retry sending
+ if(TX_RETRY_TIMER = 0) then
+ -- waited long enough. try retransmitting.
+ STATE <= 0;
+ elsif(TICK_4US = '1') then
+ TX_RETRY_TIMER <= TX_RETRY_TIMER - 1;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- split complex state machine into smaller simpler processes for better timing
+RPTR_GEN_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RPTR_ACKED <= (others => '1');
+ elsif(STATE = 2) then
+ -- data transfer complete. waiting for ACK/NAK
+ if(ACK_IN = '1') or (ACK_IN_FLAG = '1') then
+ -- All done.
+ RPTR_ACKED <= RPTR; -- new acknowledged read pointer
+ end if;
+ end if;
+ end if;
+end process;
+
+-- ACK/NAK received flags
+ACK_NAK_FLAGS_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ ACK_IN_FLAG <= '0';
+ NAK_IN_FLAG <= '0';
+ else
+ if(STATE = 0) or ((STATE = 2) and (ACK_IN = '1')) then
+ ACK_IN_FLAG <= '0';
+ elsif(ACK_IN = '1') then
+ ACK_IN_FLAG <= '1';
+ end if;
+ if(STATE = 0) then
+ NAK_IN_FLAG <= '0';
+ elsif(NAK_IN = '1') then
+ NAK_IN_FLAG <= '1';
+ end if;
+ end if;
+ end if;
+end process;
+
+--//-- OUTPUT --------------------------------
+DATA_OUT <= DOB(63 downto 0);
+DATA_VALID_OUT <= DOB(71 downto 64) when (WORD_VALID = '1') else x"00";
+SOF_OUT <= SOF;
+EOF_OUT <= EOF;
+
+--//-- TEST POINTS ----------------------------
+TP(1) <= '1' when (STATE = 0) else '0';
+TP(2) <= '1' when (STATE = 1) else '0';
+TP(3) <= '1' when (STATE = 2) else '0';
+TP(4) <= '1' when (STATE = 3) else '0';
+TP(5) <= RPTR(0);
+TP(6) <= NAK_IN_FLAG;
+TP(7) <= SOF;
+TP(8) <= EOF;
+TP(9) <= WORD_VALID;
+TP(10) <= ACK_IN_FLAG;
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/tcp_rxbufndemux2_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/tcp_rxbufndemux2_10G.vhd
new file mode 100644
index 0000000..dbc5762
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/tcp_rxbufndemux2_10G.vhd
@@ -0,0 +1,602 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: TCP_RXBUFNDEMUX2_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 1
+-- Date last modified: 4/25/19 AZ
+-- Inheritance: COM-5402SOFT TCP_RXBUFNDEMUX2.VHD rev2 12/8/15
+--
+-- description: This component has two objectives:
+-- (1) tentatively hold a received TCP frame on the fly until its validity is confirmed at the end of frame.
+-- Discard if invalid or further process if valid.
+-- (2) demultiplex multiple TCP streams, based on the destination port number
+-- 10G version. Portable.
+--
+-- Because of the TCP protocol, data can only be validated at the end of a packet.
+-- So the buffer management has to be able to backtrack, discard previous data and
+-- reposition pointer.
+--
+-- The overall buffer size (which affects overall throughput) is user selected in the generic section.
+-- This component is written of a single TCP stream.
+--
+-- This component is written for NTCPSTREAMS TCP tx streams. Adjust as needed in the com5402pkg package.
+--
+-- Note: This component should work in all application case, at the expense of many block RAM.
+-- Use the more efficient TCP_RXBUFNDEMUX only when the application is reading data faster than the data source
+-- and when RAMBs are at a premium.
+--
+-- Rev1 4/25/19 AZ
+-- Corrected bug regarding RX_APP_DATA_VALID
+-- Corrected sensitivity lists
+-- Corrected bug regarding BUF_SIZE.
+--
+-- Minimum period: 4.537ns (Maximum Frequency: 220.410MHz)
+-- FF: 386
+-- LUT: 583
+-- BRAM: 4
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+use work.com5502pkg.all; -- defines global types, number of TCP streams, etc
+
+entity TCP_RXBUFNDEMUX2_10G is
+ generic (
+ NTCPSTREAMS: integer := 1;
+ -- number of concurrent TCP streams handled by this component
+ ADDR_WIDTH: integer range 8 to 12:= 11
+ -- size of the dual-port RAM buffers instantiated within for each stream = 64b * 2^ADDR_WIDTH
+ -- Trade-off buffer depth and overall TCP throughput.
+ -- Recommended value for 10GbE: at least 11
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ CLK: in std_logic; -- synchronous clock
+ -- Must be global clocks. No BUFG instantiation within this component.
+
+ --// TCP RX protocol -> RX BUFFER
+ RX_DATA: in std_logic_vector(63 downto 0);
+ -- TCP payload data field. Each byte validity is in RX_DATA_VALID(I)
+ -- IMPORTANT: always left aligned (MSB first): RX_DATA_VALID is x80,xc0,xe0,xf0,....x01,x00
+ RX_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- delineates the TCP payload data field
+ RX_SOF: in std_logic;
+ -- 1st word of RX_DATA
+ -- Read ancillary information at this time:
+ -- (a) destination RX_STREAM_NO (based on the destination TCP port)
+ RX_TCP_STREAM_SEL: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- stream number based on the destination TCP port
+ RX_EOF: in std_logic;
+ -- 1 CLK pulse indicating that RX_DATA is the last byte in the TCP data field.
+ -- ALWAYS CHECK RX_FRAME_VALID at the end of packet (RX_EOF = '1') to confirm
+ -- that the TCP packet is valid.
+ -- Note: All packet information stored is tentative until
+ -- the entire frame is confirmed (RX_EOF = '1') and (RX_FRAME_VALID = '1').
+ -- MSbs are dropped.
+ -- If the frame is invalid, the data and ancillary information just received is discarded.
+ -- Reason: we only knows about bad TCP packets at the end.
+ RX_FRAME_VALID: in std_logic;
+ -- verify the entire frame validity at the end of frame (RX_EOF = '1')
+ RX_FREE_SPACE: out SLV16xNTCPSTREAMStype;
+ -- buffer available space, expressed in bytes.
+ -- Beware of delay (as data may be in transit and information is slightly old).
+ RX_BUF_CLR: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- '1' to clear the elastic buffer (for example after closing the connection)
+
+ --// RX BUFFER -> APPLICATION INTERFACE
+ -- NTCPSTREAMS can operate independently and concurrently. No scheduling arbitration needed here.
+ -- Usage: RX_APP_RTS goes high when at least one byte is in the output queue (i.e. not yet visible at the
+ -- output RX_APP_DATA). The application should then raise RX_APP_CTS for one clock to fetch the next word 2 CLKs later.
+ -- Note that the next word may be partial (<8 bytes) or full.
+ -- RX_APP_DATA and RX_APP_DATA_VALID are updated automatically without the application intervention as the
+ -- 8-byte output is being filled.
+ -- Thus, the application may have to check periodically RX_APP_DATA_VALID while waiting for the complete 8 bytes.
+ -- RX_APP_CTS pulse will cause a move to the next word IF AND ONLY IF the next word has at least one available byte.
+ RX_APP_DATA: out SLV64xNTCPSTREAMStype;
+ RX_APP_DATA_VALID: out SLV8xNTCPSTREAMStype;
+ RX_APP_RTS: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ RX_APP_CTS: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- 1 CLK pulse to read the next (partial) word RX_APP_DATA
+ -- Latency: 2 CLKs to RX_APP_DATA, but only IF AND ONLY IF the next word has at least one available byte.
+ RX_APP_CTS_ACK: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- '1' the RX_APP_CTS request for new data is accepted:
+ -- indicating that a new (maybe partial) word will be placed on the output RX_APP_DATA at the next CLK.
+
+
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of TCP_RXBUFNDEMUX2_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+ */
+ component tdp_ram is
+ generic (
+ ADDR_WIDTH : natural;
+ DATA_WIDTH : integer);
+ port (
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic := '1';
+ enb : in std_logic := '1';
+ wea : in std_logic;
+ web : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dib : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ doa : out std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+ end component tdp_ram;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal RESETn: std_logic := '0';
+signal RESET_CNTR: unsigned(2 downto 0) := (others => '0');
+
+-- freeze ancilliary input data at the SOF
+signal RX_TCP_STREAM_SEL_D: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+
+--//-- ELASTIC BUFFER ---------------------------
+signal RX_DATA_SHIFT: std_logic_vector(127 downto 0) := (others => '0');
+signal RX_DATA_VALID1: std_logic_vector(15 downto 0) := (others => '0');
+signal RX_DATA_REMAIN: std_logic_vector(63 downto 0) := (others => '0');
+signal RX_DATA_REMAIN_VALID: std_logic_vector(7 downto 0) := (others => '0');
+--signal FLUSH_RX_DATA_REMAIN: std_logic := '0';
+signal RX_DATA_D: std_logic_vector(63 downto 0) := (others => '0');
+signal RX_DATA_VALID_D: std_logic_vector(7 downto 0) := (others => '0');
+signal RX_SOF_D: std_logic := '0';
+signal RX_EOF_D: std_logic := '0';
+signal RX_EOF_D2: std_logic := '0';
+signal RX_EOF_D3: std_logic := '0';
+signal RX_WORD_VALID_D: std_logic := '0';
+signal RX_WORD_VALID_D2: std_logic := '0';
+signal RX_FRAME_VALID_D: std_logic := '0';
+signal RX_FRAME_VALID_D2: std_logic := '0';
+signal WPTR_INCREMENT: integer range 0 to 8 := 0;
+signal WPTRA_E: unsigned(ADDR_WIDTH+3 downto 0) := (others => '0');
+signal WPTRA: unsigned(ADDR_WIDTH+3 downto 0) := (others => '0');
+signal WPTRAb3_D: std_logic := '0';
+signal RPTRA: unsigned(ADDR_WIDTH+3 downto 0) := (others => '0');
+signal ADDRA: std_logic_vector(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WEA: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+signal DIA: std_logic_vector(63 downto 0) := (others => '0');
+type PTRtype is array (integer range 0 to (NTCPSTREAMS-1)) of unsigned(ADDR_WIDTH+3 downto 0);
+signal WPTR0: PTRtype := (others => (others => '0'));
+signal WPTR_CONFIRMED: PTRtype := (others => (others => '0'));
+signal RPTR: PTRtype := (others => (others => '0'));
+signal RPTR_MIN: PTRtype := (others => (others => '0'));
+signal BUF_SIZE: PTRtype := (others => (others => '0'));
+signal BUF_SIZE_D: PTRtype := (others => (others => '0'));
+type DOtype is array (integer range 0 to (NTCPSTREAMS-1)) of std_logic_vector(63 downto 0);
+signal DOA: DOtype := (others => (others => '0'));
+signal DOB: DOtype := (others => (others => '0'));
+signal FIRST_APP_DATA: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+signal RX_APP_RTS_local: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+signal RX_APP_CTS_ACK_local: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+signal RX_APP_CTS_ACK_D: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+-- create a local reset (because we want RPTR to be initialized to all '1's among other things
+RESETN_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(RESET_CNTR(RESET_CNTR'left) = '0') then
+ RESET_CNTR <= RESET_CNTR + 1;
+ end if;
+ end if;
+end process;
+RESETn <= RESET_CNTR(RESET_CNTR'left);
+
+-- freeze ancilliary data at the SOF
+FREEZE_INPUT: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(RX_SOF = '1') then
+ RX_TCP_STREAM_SEL_D <= RX_TCP_STREAM_SEL;
+ end if;
+ end if;
+end process;
+
+-- clean unused input bytes (because of follow-on ORing)
+-- Justification: TCP_SERVER_10G does a sloppy job filtering out unnecessary bytes
+CLEAN_INPUT: process(CLK)
+begin
+ if rising_edge(CLK) then
+ RX_DATA_VALID_D <= RX_DATA_VALID;
+ RX_SOF_D <= RX_SOF;
+ RX_EOF_D <= RX_EOF;
+ RX_EOF_D2 <= RX_EOF_D;
+ RX_EOF_D3 <= RX_EOF_D2;
+ RX_FRAME_VALID_D <= RX_FRAME_VALID;
+ RX_FRAME_VALID_D2 <= RX_FRAME_VALID_D;
+ RX_WORD_VALID_D <= RX_DATA_VALID(7);
+ RX_WORD_VALID_D2 <= RX_WORD_VALID_D;
+
+ for I in 0 to 7 loop
+ if(RX_DATA_VALID(I) = '1') then
+ RX_DATA_D(8*I+7 downto 8*I) <= RX_DATA(8*I+7 downto 8*I);
+ else
+ RX_DATA_D(8*I+7 downto 8*I) <= x"00";
+ end if;
+ end loop;
+
+ end if;
+end process;
+
+
+--//-- ELASTIC BUFFER ---------------------------
+-- write pointer management.
+WPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(RX_DATA_VALID(0) = '1') then
+ WPTR_INCREMENT <= 8;
+ elsif(RX_DATA_VALID(1) = '1') then
+ WPTR_INCREMENT <= 7;
+ elsif(RX_DATA_VALID(2) = '1') then
+ WPTR_INCREMENT <= 6;
+ elsif(RX_DATA_VALID(3) = '1') then
+ WPTR_INCREMENT <= 5;
+ elsif(RX_DATA_VALID(4) = '1') then
+ WPTR_INCREMENT <= 4;
+ elsif(RX_DATA_VALID(5) = '1') then
+ WPTR_INCREMENT <= 3;
+ elsif(RX_DATA_VALID(6) = '1') then
+ WPTR_INCREMENT <= 2;
+ elsif(RX_DATA_VALID(7) = '1') then
+ WPTR_INCREMENT <= 1;
+ else
+ WPTR_INCREMENT <= 0;
+ end if;
+ end if;
+end process;
+
+--
+WPTR_GEN_002a: process(CLK)
+begin
+ if rising_edge(CLK) then
+ WPTRAb3_D <= WPTRA(3);
+
+ if(SYNC_RESET = '1') or (RX_EOF_D3 = '1') then
+ WPTRA_E <= (others => '0');
+ WPTRA <= (others => '0');
+ elsif(RX_SOF = '1') then
+ -- for each received frame, position the write pointer as per the last confirmed pointer position
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL(I) = '1') then
+ WPTRA_E <= WPTR_CONFIRMED(I);
+ end if;
+ end loop;
+ elsif(RX_WORD_VALID_D = '1') then
+ -- about to write at least one payload byte
+ -- prepare the next address
+ WPTRA_E <= WPTRA_E + WPTR_INCREMENT;
+ WPTRA <= WPTRA_E;
+ else
+ WPTRA <= WPTRA_E;
+ end if;
+ end if;
+end process;
+
+WPTR_GEN_X: for I in 0 to NTCPSTREAMS-1 generate
+ WPTR_GEN_002b: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WPTR_CONFIRMED(I) <= (others => '0');
+ elsif(RX_TCP_STREAM_SEL_D(I) = '1') then
+ if(RX_BUF_CLR(I) = '1') then
+ WPTR_CONFIRMED(I) <= (others => '0');
+ elsif (RX_EOF_D2 = '1') and (RX_FRAME_VALID_D2 = '1') then
+ -- last frame confirmed valid. Remember the writer position (next location to write to)
+ WPTR_CONFIRMED(I) <= WPTRA_E;
+ end if;
+ end if;
+
+ -- keep track if this is the first output data for this session/stream
+ -- Any output data before that is meaningless.
+ if(SYNC_RESET = '1') or (RX_BUF_CLR(I) = '1') then
+ FIRST_APP_DATA(I) <= '0';
+ elsif(RX_APP_CTS_ACK_local(I) = '1') then
+ -- first output data will appear at the next clock
+ FIRST_APP_DATA(I) <= '1';
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- remember the wptr for each stream (we need it to compute free space)
+WPTR_GEN_003: FOR I in 0 to (NTCPSTREAMS-1) generate
+ WPTR_GEN_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (RX_BUF_CLR(I) = '1') then
+ WPTR0(I) <= (others => '0');
+ elsif(RX_TCP_STREAM_SEL_D(I) = '1') and (RX_WORD_VALID_D = '1') then
+ WPTR0(I) <= WPTRA_E + WPTR_INCREMENT;
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- shift input word depending on the next write byte address WPTRA(2 downto 0)
+-- ready at RX_DATA_VALID_D2
+SHIFT_RX_DATA_IN_001:process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(RX_SOF = '1') or (RX_EOF_D2 = '1') then
+ RX_DATA_VALID1 <= (others => '0');
+ RX_DATA_SHIFT <= (others => '0');
+ elsif(RX_WORD_VALID_D = '1') then
+ -- at RX_WORD_VALID_D
+ case(WPTRA_E(2 downto 0)) is
+ when "000" => RX_DATA_SHIFT <= RX_DATA_D & x"0000000000000000";
+ RX_DATA_VALID1 <= RX_DATA_VALID_D & "00000000";
+ when "001" => RX_DATA_SHIFT <= x"00" & RX_DATA_D & x"00000000000000";
+ RX_DATA_VALID1 <= "0" & RX_DATA_VALID_D & "0000000";
+ when "010" => RX_DATA_SHIFT <= x"0000" & RX_DATA_D & x"000000000000";
+ RX_DATA_VALID1 <= "00" & RX_DATA_VALID_D & "000000";
+ when "011" => RX_DATA_SHIFT <= x"000000" & RX_DATA_D & x"0000000000";
+ RX_DATA_VALID1 <= "000" & RX_DATA_VALID_D & "00000";
+ when "100" => RX_DATA_SHIFT <= x"00000000" & RX_DATA_D & x"00000000";
+ RX_DATA_VALID1 <= "0000" & RX_DATA_VALID_D & "0000";
+ when "101" => RX_DATA_SHIFT <= x"0000000000" & RX_DATA_D & x"000000";
+ RX_DATA_VALID1 <= "00000" & RX_DATA_VALID_D & "000";
+ when "110" => RX_DATA_SHIFT <= x"000000000000" & RX_DATA_D & x"0000";
+ RX_DATA_VALID1 <= "000000" & RX_DATA_VALID_D & "00";
+ when others => RX_DATA_SHIFT <= x"00000000000000" & RX_DATA_D & x"00";
+ RX_DATA_VALID1 <= "0000000" & RX_DATA_VALID_D & "0";
+ end case;
+ end if;
+
+ -- At the start of frame, we need to re-initialize RX_DATA_REMAIN as two successive frames
+ -- may target different streams
+ -- This is to avoid storing RX_DATA_REMAIN for each stream
+ if (RX_EOF_D3 = '1') then
+ -- cleaner
+ RX_DATA_REMAIN <= (others => '0');
+ elsif(RX_SOF_D = '1') then
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL_D(I) = '1') then
+ RX_DATA_REMAIN <= DOA(I);
+ end if;
+ end loop;
+ elsif((RX_WORD_VALID_D2 = '1') and (RX_DATA_VALID1(8) = '1')) then
+ -- writing complete word to memory. shift remaining bytes to the left
+ RX_DATA_REMAIN <= RX_DATA_SHIFT(63 downto 0);
+ RX_DATA_REMAIN_VALID <= RX_DATA_VALID1(7 downto 0);
+ elsif(RX_WORD_VALID_D2 = '1') and (RX_DATA_VALID1(8) = '0') then
+ -- not enough new bytes to fill a 8-byte word and write to memory. No shift
+ RX_DATA_REMAIN <= DIA(63 downto 0);
+ RX_DATA_REMAIN_VALID <= RX_DATA_VALID1(15 downto 8);
+ else
+ RX_DATA_REMAIN_VALID <= (others => '0');
+ end if;
+ end if;
+end process;
+
+-- create new hybrid word to write to memory
+DIA <= RX_DATA_REMAIN or RX_DATA_SHIFT(127 downto 64);
+
+-- Need to flush the last few bytes in RX_DATA_REMAIN
+--FLUSH_001: process(CLK)
+--begin
+-- if rising_edge(CLK) then
+-- if(RX_EOF_D2 = '1') and (RX_DATA_VALID1(15) = '1') then
+-- FLUSH_RX_DATA_REMAIN <= '1';
+-- else
+-- FLUSH_RX_DATA_REMAIN <= '0';
+-- end if;
+-- end if;
+--end process;
+
+-- select which RAMBlock to write to.
+WEA_GENx: process(RX_TCP_STREAM_SEL_D, RX_EOF_D3, RX_DATA_REMAIN_VALID, WPTRA, WPTRAb3_D, RX_WORD_VALID_D2)
+begin
+ for I in 0 to (NTCPSTREAMS-1) loop
+ if(RX_TCP_STREAM_SEL_D(I) = '1') then
+ if(RX_EOF_D3 = '1') and (RX_DATA_REMAIN_VALID /= x"00") and (WPTRA(3) /= WPTRAb3_D) then
+ -- Write flush remainder at RX_EOF_D3, when remainder is not empty and spills over the next 64-bit word
+ WEA(I) <= '1';
+ elsif(RX_WORD_VALID_D2 = '1') then
+ -- Write partial or full word.
+ WEA(I) <= '1';
+ else
+ WEA(I) <= '0';
+ end if;
+ else
+ WEA(I) <= '0';
+ end if;
+ end loop;
+end process;
+
+-- read the last (partial) word at the SOF, before writing the frame first (partial) word.
+ADDRA_GEN_001: process(RX_TCP_STREAM_SEL, WPTR_CONFIRMED)
+variable RPTRAv: unsigned(ADDR_WIDTH+3 downto 0);
+begin
+ -- for each received frame, position the write pointer as per the last confirmed pointer position
+ RPTRAv := (others => '0');
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL(I) = '1') then
+ RPTRAv := WPTR_CONFIRMED(I);
+ end if;
+ end loop;
+ RPTRA <= RPTRAv;
+end process;
+
+ADDRA_GEN: process(RPTRA, RX_SOF, WPTRA)
+begin
+ if(RX_SOF = '1') then
+ ADDRA <= std_logic_vector(RPTRA(ADDR_WIDTH+2 downto 3));
+ else
+ ADDRA <= std_logic_vector(WPTRA(ADDR_WIDTH+2 downto 3));
+ end if;
+end process;
+
+-- Latency 1 CLK from ADDRx to DOx
+BRAM_DP2_X: for I in 0 to (NTCPSTREAMS-1) generate
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ BRAM_DP2_001: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 64,
+ ADDR_WIDTHA => ADDR_WIDTH,
+ DATA_WIDTHB => 64,
+ ADDR_WIDTHB => ADDR_WIDTH
+
+ )
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA(I), -- Port A Write Enable Input
+ OEA => '1',
+ ADDRA => ADDRA, -- Port A Address Input
+ DIA => DIA, -- Port A Data Input
+ DOA => DOA(I),
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ OEB => '1',
+ ADDRB => std_logic_vector(RPTR(I)(ADDR_WIDTH+2 downto 3)), -- Port B Address Input
+ DIB => (others => '0'), -- Port B Data Input
+ DOB => DOB(I) -- Port B Data Output
+ );
+ */
+ BRAM_DP2_001: TDP_RAM
+ GENERIC MAP(
+ DATA_WIDTH => 64,
+ ADDR_WIDTH => ADDR_WIDTH)
+ PORT MAP(
+ CLKA => CLK,
+ WEA => WEA(I), -- Port A Write Enable Input
+ ADDRA => ADDRA, -- Port A Address Input
+ DIA => DIA, -- Port A Data Input
+ DOA => DOA(I),
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR(I)(ADDR_WIDTH+2 downto 3)), -- Port B Address Input
+ DIB => (others => '0'), -- Port B Data Input
+ DOB => DOB(I)); -- Port B Data Output
+end generate;
+
+-- How many bytes are waiting to be read?
+-- BUF_SIZE can be slightly negative when waiting for a few more bytes to complete a word
+RX_BUFFER_SIZE_GENx: for I in 0 to (NTCPSTREAMS - 1) generate
+ BUF_SIZE(I) <= WPTR_CONFIRMED(I) + (not RPTR(I));
+ -- tell the application when data is available to read
+ RX_APP_RTS_local(I) <= '0' when (BUF_SIZE(I) = 0) or (BUF_SIZE(I)(ADDR_WIDTH+3) = '1') or (RESETn = '0') else '1';
+end generate;
+RX_APP_RTS <= RX_APP_RTS_local;
+
+-- read pointer management
+-- Rule #1: RPTR points to the next memory location to be read (Units: words)
+RPTR_GENx: FOR I in 0 to (NTCPSTREAMS-1) generate
+ RPTR_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ BUF_SIZE_D(I) <= BUF_SIZE(I);
+ RX_APP_CTS_ACK_D(I) <= RX_APP_CTS_ACK_local(I);
+
+ if(SYNC_RESET = '1') or (RESETn = '0') or (RX_BUF_CLR(I) = '1') then
+ RPTR(I) <= (others => '1');
+ RX_APP_CTS_ACK_local(I) <= '0';
+ elsif(RX_APP_RTS_local(I) = '0') then
+ -- current output word DOB is not full (when BUF_SIZE is slightly negative). Do not increment the read pointer.
+ RX_APP_CTS_ACK_local(I) <= '0';
+ elsif(BUF_SIZE(I) /= 0) and (RX_APP_CTS(I) = '1') then
+ -- At least one byte is available to read in memory
+ -- and the application is ready to accept it. Read one (full or partial) word.
+ RPTR(I) <= RPTR(I) + 8;
+ RX_APP_CTS_ACK_local(I) <= '1';
+ else
+ RX_APP_CTS_ACK_local(I) <= '0';
+ end if;
+ end if;
+ end process;
+ -- design note: RPTR(I) is always ending in 111. As we do not know exactly how many bytes are
+ -- read by the application, RPTR(I) should be considered as a range spanning 8 bytes.
+ -- For example 3FFF really means 3FF8-3FFF.
+ -- This is an important consideration in computing the available free space.
+ RPTR_MIN(I) <= RPTR(I)(ADDR_WIDTH+3 downto 3) & "000";
+end generate;
+RX_APP_CTS_ACK <= RX_APP_CTS_ACK_local;
+
+OUTPUT_GEN: process(DOB, FIRST_APP_DATA, BUF_SIZE, BUF_SIZE_D, RX_APP_CTS_ACK_D)
+begin
+ for I in 0 to (NTCPSTREAMS-1) loop
+ RX_APP_DATA(I) <= DOB(I);
+
+ if(FIRST_APP_DATA(I) = '0') then
+ -- nothing to read
+ RX_APP_DATA_VALID(I) <= x"00";
+ elsif (BUF_SIZE_D(I)(ADDR_WIDTH+3) = '1') and (BUF_SIZE(I)(ADDR_WIDTH+3) = '0')then
+ -- previously partial word is now filled
+ RX_APP_DATA_VALID(I) <= x"FF";
+ elsif (BUF_SIZE_D(I)(ADDR_WIDTH+3) = '0') and (RX_APP_CTS_ACK_D(I) = '1')then
+ -- new full word
+ RX_APP_DATA_VALID(I) <= x"FF";
+ elsif (BUF_SIZE_D(I)(ADDR_WIDTH+3) = '1') then
+ -- reading last word in buffer, 1-8 bytes
+ case(BUF_SIZE_D(I)(2 downto 0)) is
+ when "001" => RX_APP_DATA_VALID(I) <= x"80";
+ when "010" => RX_APP_DATA_VALID(I) <= x"C0";
+ when "011" => RX_APP_DATA_VALID(I) <= x"E0";
+ when "100" => RX_APP_DATA_VALID(I) <= x"F0";
+ when "101" => RX_APP_DATA_VALID(I) <= x"F8";
+ when "110" => RX_APP_DATA_VALID(I) <= x"FC";
+ when "111" => RX_APP_DATA_VALID(I) <= x"FE";
+ when others => RX_APP_DATA_VALID(I) <= x"00";
+ end case;
+ else
+ RX_APP_DATA_VALID(I) <= x"00";
+ end if;
+ end loop;
+end process;
+
+-- report the worst case available space to the TCP engine (including space currently occupied by invalid frames)
+FREE_SPACE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ for I in 0 to (NTCPSTREAMS-1) loop
+ RX_FREE_SPACE(I) <= std_logic_vector(resize(RPTR_MIN(I)(ADDR_WIDTH+2 downto 0) - WPTR0(I)(ADDR_WIDTH+2 downto 0),RX_FREE_SPACE(I)'length));
+ end loop;
+ end if;
+end process;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/tcp_server_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/tcp_server_10G.vhd
new file mode 100644
index 0000000..93ba606
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/tcp_server_10G.vhd
@@ -0,0 +1,1980 @@
+-------------------------------------------------------------
+-- MSS copyright 2018-2020
+-- Filename: TCP_SERVER_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0.4
+-- Date last modified: 1/21/20
+-- Inheritance: COM-5402SOFT TCP_SERVER.VHD rev13 12/3/16
+--
+-- description: TCP protocol for a server. 10Gbits/s version. Tx and Rx.
+-- Server awaits connection from a client. Once the connection is established, bi-directional
+-- data transmission can take place.
+-- One instantiation per port.
+-- This component is mainly a state machine. It avoids storing any packet data to keep size to its minimum.
+-- Consequently, the rx data recipient should be able to backtrack and throw out the received packet if
+-- proven invalid at the end.
+-- Likewise, the tx data source should be able to rewind and re-transmit previous data if the TCP client
+-- requests is.
+-- Since this is a server, we do not know a priori whether the protocol is IPv4 or IPv6 (it depends on the client).
+-- So each server is given two IP addresses, one for each IP version.
+--
+-- Device utilization (NTCPSTREAMS=1, MSS=1460, IPv6_ENABLED='1')
+-- FF: 1134
+-- LUT: 1536
+-- DSP48: 0
+-- 18Kb BRAM: 0
+-- BUFG: 1
+-- Minimum period: 4.096ns (Maximum Frequency: 244.126MHz) Artix7-100T -1 speed grade
+--
+-- Rev 0.1 12/8/18
+-- Harmonizing with COM-5402SOFT/TCP_SERVER.VHD
+--
+-- Rev 0.2 4/24/19 AZ
+-- Corrected bug with (late) retransmission when a missing or delayed ACK is detected.
+-- Increased retransmit timeout value (x2)
+--
+-- Rev 0.3 6/10/19 AZ
+-- Set a min of 1second for the retransmission timeout as per RFC
+--
+-- Rev 0.4 1/20/20 AZ
+-- Eliminated instability in the ack/retransmission feedback loop
+-- Reduce latency for receiving the first full tx frame to < 90us starting at client connection request (don't wait for the first client ACK)
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.numeric_std.ALL;
+use work.com5502pkg.all; -- defines global types, number of TCP streams, etc
+
+entity TCP_SERVER_10G is
+ generic (
+ NTCPSTREAMS: integer := 1;
+ -- number of concurrent TCP streams handled by this component
+ MSS: integer := 1460;
+ -- The Maximum Segment Size (MSS) is the largest segment of TCP data that can be transmitted.
+ -- Fixed as the Ethernet MTU (Maximum Transmission Unit) of 1500-9000 bytes - 40(IPv4) or -60(IPv6) overhead bytes
+ TCP_KEEPALIVE_PERIOD: integer := 60;
+ -- period in seconds for sending a keep-alive frame after no data and no ack is received.
+ -- "Typically TCP Keepalives are sent every 45 or 60 seconds on an idle TCP connection, and the connection is
+ -- dropped after 3 sequential ACKs are missed"
+ IPv6_ENABLED: std_logic := '0';
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ SIMULATION: std_logic := '0'
+ -- 1 during simulation. for example to fix the tx_seq_no so that it matches the Wireshark
+ -- captures.
+ );
+ Port (
+ --// CLK, RESET, TIME
+ CLK: in std_logic;
+ -- Must be a global clock. No BUFG instantiation within this component.
+ SYNC_RESET: in std_logic;
+
+ TICK_4US: in std_logic;
+ TICK_100MS: in std_logic;
+ -- 1 CLK-wide pulse every 4us and 10ms
+
+ --// Configuration Fields
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ TCP_LOCAL_PORTS: in SLV16xNTCPSTREAMStype;
+ -- TCP_SERVER port configuration. Each one of the NTCPSTREAMS streams handled by this
+ -- component must be configured with a distinct port number.
+ -- This value is used as destination port number to filter incoming packets,
+ -- and as source port number in outgoing packets.
+
+ --// User-initiated connection reset for stream I
+ CONNECTION_RESET: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ TCP_KEEPALIVE_EN: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- enable TCP Keepalive (1) or not (0)
+
+ --// RECEIVED IP PAYLOAD ---------------------------------------------
+ -- Excludes MAC layer header, IP header.
+ IP_PAYLOAD_DATA: in std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: in std_logic;
+ IP_PAYLOAD_EOF: in std_logic;
+ IP_PAYLOAD_WORD_COUNT: in std_logic_vector(10 downto 0);
+
+ --// Partial checks (done in PACKET_PARSING common code)
+ --// basic IP validity check
+ IP_RX_FRAME_VALID: in std_logic;
+ -- As the IP frame validity is checked on-the-fly, the user should always check if
+ -- the IP_RX_FRAME_VALID is high AT THE END of the IP payload frame (IP_PAYLOAD_EOF) to confirm that the
+ -- ENTIRE IP frame is valid.
+ -- IP frame validity checks include:
+ -- (a) protocol is IP
+ -- (b) unicast or multicast destination IP address matches
+ -- (c) correct IP header checksum (IPv4 only)
+ -- (d) allowed IPv6
+ -- (e) Ethernet frame is valid (correct FCS, dest address)
+ -- Ready at IP_PAYLOAD_EOF
+
+ --// IP type, already parsed in PACKET_PARSING (shared code)
+ RX_IPv4_6n: in std_logic;
+ -- IP version. 4 or 6
+ RX_IP_PROTOCOL: in std_logic_vector(7 downto 0);
+ -- read between RX_IP_PROTOCOL_RDY (inclusive)(i.e. before IP_PAYLOAD_SOF) and IP_PAYLOAD_EOF (inclusive)
+ -- This component responds to protocol 6 = TCP
+ RX_IP_PROTOCOL_RDY: in std_logic;
+ -- 1 CLK wide pulse.
+
+ --// Packet origin, already parsed in PACKET_PARSING (shared code)
+ RX_SOURCE_MAC_ADDR: in std_logic_vector(47 downto 0);
+ RX_SOURCE_IP_ADDR: in std_logic_vector(127 downto 0);
+
+ --// TCP attributes, already parsed in PACKET_PARSING (shared code)
+ -- BEWARE!!!!!!!! WE ALSO RECEIVE PACKETS NOT DESTINED FOR THIS SESSION (NOT FOR THIS PORT)
+ -- IT IS THE IMPLEMENTATION'S RESPONSIBILITY TO DISCARD DATA NOT DESTINED FOR THIS TCP PORT.
+ VALID_TCP_CHECKSUM: in std_logic;
+ -- '1' when valid TCP checksum(including pseudo-header). Read at IP_RX_EOF_D2 = IP_PAYLOAD_EOF_D
+
+ --// RX TCP PAYLOAD -> EXTERNAL RX BUFFER
+ -- Latency: 1 CLK after the received IP payload frame.
+ RX_DATA: out std_logic_vector(63 downto 0);
+ -- TCP payload data field. Each byte validity is in RX_DATA_VALID(I)
+ -- IMPORTANT: always left aligned (MSB first): RX_DATA_VALID is x80,xc0,xe0,xf0,....x01,x00
+ RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- delineates the TCP payload data field
+ RX_SOF: out std_logic;
+ -- 1 CLK pulse indicating that RX_DATA is the first byte in the TCP data field.
+ RX_TCP_STREAM_SEL_OUT: out std_logic_vector(NTCPSTREAMS-1 downto 0);
+ -- output port based on the destination TCP port
+ RX_EOF: out std_logic;
+ -- 1 CLK pulse indicating that RX_DATA is the last byte in the TCP data field.
+ -- ALWAYS CHECK RX_FRAME_VALID at the end of packet (RX_EOF = '1') to confirm
+ -- that the TCP packet is valid. External buffer may have to backtrack to the the last
+ -- valid pointer to discard an invalid TCP packet.
+ -- Reason: we only knows about bad TCP packets at the end.
+ RX_FRAME_VALID: out std_logic;
+ -- verify the entire frame validity at the end of frame (RX_EOF = '1')
+ RX_FREE_SPACE: in SLV16xNTCPSTREAMStype;
+ -- External buffer available space, expressed in bytes.
+ -- Information is updated upon receiving the EOF of a valid rx frame.
+ -- The real-time available space is always larger
+
+ --// OUTPUTS to TX PACKET ASSEMBLY (via TCP_TX.vhd component)
+ TX_PACKET_SEQUENCE_START_OUT: out std_logic;
+ -- 1 CLK pulse to trigger packet transmission. The decision to transmit is taken by TCP_SERVER.
+ -- From this trigger pulse to the end of frame, this component assembles and send data bytes
+ -- like clockwork.
+ -- Note that the payload data has to be ready at exactly the right time to be appended.
+
+ -- These variables are read only at the start of packet, when TX_PACKET_SEQUENCE_START_OUT = '1'
+ -- They can change from packet to packet (internal code is memoryless).
+ TX_DEST_MAC_ADDR_OUT: out std_logic_vector(47 downto 0);
+ TX_DEST_IP_ADDR_OUT: out std_logic_vector(127 downto 0);
+ TX_DEST_PORT_NO_OUT: out std_logic_vector(15 downto 0);
+ TX_SOURCE_PORT_NO_OUT: out std_logic_vector(15 downto 0);
+ TX_IPv4_6n_OUT: out std_logic;
+ TX_SEQ_NO_OUT: out std_logic_vector(31 downto 0);
+ TX_ACK_NO_OUT: out std_logic_vector(31 downto 0);
+ TX_ACK_WINDOW_LENGTH_OUT: out std_logic_vector(15 downto 0);
+ TX_FLAGS_OUT: out std_logic_vector(7 downto 0);
+ TX_PACKET_TYPE_OUT : out std_logic_vector(1 downto 0);
+ -- 0 = undefined
+ -- 1 = SYN, no data, 24-byte header
+ -- 2 = ACK, no data, 20-byte header
+ -- 3 = payload data, 20-byte header
+
+
+
+
+-- --// TX TCP layer -> Transmit MAC Interface
+ MAC_TX_EOF: in std_logic; -- need to know when packet tx is complete
+ RTS: out std_logic := '0';
+ -- '1' when a frame is ready to be sent (tell the COM5402 arbiter)
+ -- When the MAC starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+ --// EXTERNAL TX BUFFER <-> TX TCP layer
+ -- upon receiving an ACK from the client, send rx window information to TXBUF for computing
+ -- the next packet size, boundaries, etc.
+ -- Partial computation (rx window size + RX_TCP_ACK_NO).
+ EFF_RX_WINDOW_SIZE_PARTIAL: out std_logic_vector(16 downto 0) := (others => '0');
+ -- Explanation: EFF_RX_WINDOW_SIZE_PARTIAL represents the maximum TX_SEQ_NO acceptable for the
+ -- TCP client (beyond which the rx buffers would be overflowing)
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM: out std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID: out std_logic; -- 1 CLK-wide pulse to indicate that the above information is valid
+ -- Let the TXBUF know where the next byte to be transmitted is located
+ -- computing the next frame size, boundaries, etc
+ TX_SEQ_NO: out SLV17xNTCPSTREAMStype := (others => (others => '0'));
+ TX_SEQ_NO_JUMP: out std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+ -- TX_SEQ_NO progresses regularly as new bytes are being transmitted, except when TX_SEQ_NO_JUMP(I) = '1'
+ RX_TCP_ACK_NO_D: out SLV17xNTCPSTREAMStype := (others => (others => '0'));
+ -- last acknowledged tx byte location
+
+
+ CONNECTED_FLAG: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- '1' when TCP-IP connection is in the 'connected' state, 0 otherwise
+ -- Main use: TXBUF should not store tx data until a connection is established
+
+ TX_STREAM_SEL: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- valid only when TX_PAYLOAD_RTS = '1', ignore otherwise
+ TX_PAYLOAD_RTS: in std_logic;
+ -- '1' when at least one stream has payload data available for transmission.
+ TX_PAYLOAD_SIZE: in std_logic_vector(15 downto 0);
+
+
+
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of TCP_SERVER_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+-- Suffix _D indicates a one CLK delayed version of the net with the same name
+-- Suffix _E indicates a one CLK early version of the net with the same name
+-- Suffix _X indicates an extended precision version of the net with the same name
+-- Suffix _N indicates an inverted version of the net with the same name
+
+--//===== COMMON ==========================================
+signal TICK_CNTR: unsigned(3 downto 0) := "0000";
+signal TICK_1S: std_logic := '0';
+
+--//===== NON-VOLATILE PORT-SPECIFIC DATA ==================
+-- (to be saved after a packet ends)
+-- state machine
+type STATEtype is array (integer range 0 to (NTCPSTREAMS-1)) of integer range 0 to 15; -- (i.e. 4-bits)
+signal TCP_STATE: STATEtype := (others => 0);
+signal TIMER1: U8xNTCPSTREAMStype := (others => (others => '0')); -- timer range 0 - 25.5s
+signal CONNECTED_FLAG_local: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+-- keep-alive timer
+signal TIMER2: U8xNTCPSTREAMStype := (others => (others => '0')); -- timer range 0 - 255s
+signal TIMER2_D: U8xNTCPSTREAMStype := (others => (others => '0')); -- timer range 0 - 255s
+signal KASTATE: U2xNTCPSTREAMStype:= (others => (others => '0')); -- keep alive state
+-- zero-window probe timer
+signal ZWS: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal TIMER3: U8xNTCPSTREAMStype := (others => (others => '0')); -- timer range 0 - 25.5s
+constant ZERO_WINDOW_PROBE_PERIOD: integer := 3; -- first interval to send zero-window probe (in 100ms units)
+signal ZWP_STATE: U4xNTCPSTREAMStype:= (others => (others => '0')); -- zero-window probe state
+signal ZWP_TRIGGER: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+
+-- relevant transmit destination information
+type MAC_ADDRtype is array (integer range 0 to (NTCPSTREAMS-1)) of std_logic_vector(47 downto 0);
+type IP_ADDRtype is array (integer range 0 to (NTCPSTREAMS-1)) of std_logic_vector(127 downto 0);
+signal TX_DEST_MAC_ADDR: MAC_ADDRtype := (others => (others => '0'));
+signal TX_DEST_IP_ADDR: IP_ADDRtype := (others => (others => '0'));
+signal TX_DEST_PORT_NO: SLV16xNTCPSTREAMStype := (others => (others => '0'));
+-- tx sequence numbers
+signal TX_SEQ_NO_INIT: unsigned(31 downto 0) := (others => '0');
+signal TX_ACK_NO: U32xNTCPSTREAMStype := (others => (others => '0'));
+signal TX_ACK_NO2: unsigned(31 downto 0) := (others => '0');
+signal TX_SEQ_NO_local: U32xNTCPSTREAMStype := (others => (others => '0'));
+signal TX_SEQ_NO_OUT_local: U32xNTCPSTREAMStype := (others => (others => '0'));
+signal FAST_REXMIT_SEQ_NO_START: U32xNTCPSTREAMStype := (others => (others => '0'));
+signal FAST_REXMIT_SEQ_NO_END: U32xNTCPSTREAMStype := (others => (others => '0'));
+-- received sequence number
+signal RX_TCP_ACK_NO_D_local: U32xNTCPSTREAMStype := (others => (others => '0'));
+signal RX_TCP_SEQ_NO_MAX: U32xNTCPSTREAMStype := (others => (others => '0'));
+signal RX_TCP_SEQ_NO_MIN: U32xNTCPSTREAMStype := (others => (others => '0'));
+signal RX_TCP_SEQ_NO_MAX2: unsigned(31 downto 0) := (others => '0');
+signal RX_TCP_SEQ_NO_MIN2: unsigned(31 downto 0) := (others => '0');
+signal TX_IPv4_6n: std_logic_vector((NTCPSTREAMS-1) downto 0);
+signal TX_PACKET_TYPE_QUEUED: SLV2xNTCPSTREAMStype := (others => (others => '0'));
+signal TX_PACKET_TYPE: std_logic_vector(1 downto 0) := "00";
+signal TX_FLAGS: SLV8xNTCPSTREAMStype := (others => (others => '0'));
+
+
+--//==== VARIABLES WITH A 1 PACKET LIFESPAN ==================
+signal IP_PAYLOAD_WORD_VALID: std_logic := '0';
+
+---- PARSE TCP HEADER ------------------
+signal RX_SOURCE_TCP_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal RX_DEST_TCP_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal RX_TCP_SEQ_NO: unsigned(31 downto 0) := (others => '0');
+signal RX_TCP_ACK_NO: unsigned(31 downto 0) := (others => '0');
+signal RX_TCP_DATA_OFFSET: std_logic_vector(3 downto 0) := (others => '0');
+signal RX_TCP_DATA_OFFSET_INC: unsigned(3 downto 0) := (others => '0');
+signal RX_TCP_DATA_OFFSET_DIV2_INC: unsigned(3 downto 0) := (others => '0');
+signal RX_TCP_FLAGS: std_logic_vector(7 downto 0) := (others => '0');
+signal RX_TCP_WINDOW_SIZE: unsigned(15 downto 0) := (others => '0');
+
+---- TCP stream identification ------------------
+signal RX_TCP_STREAM_SEL: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+signal RX_TCP_STREAM_SEL_D: std_logic_vector(NTCPSTREAMS-1 downto 0) := (others => '0');
+signal IP_PAYLOAD_EOF_D: std_logic := '0';
+signal VALID_RX_TCP0: std_logic := '0';
+signal VALID_RX_TCP_ALL: std_logic := '0';
+
+--// COPY RX TCP DATA TO BUFFER
+signal TCP_PAYLOAD_FLAG: std_logic := '0';
+signal TCP_SOF_FLAG: std_logic := '0';
+signal RX_TCP_NON_ZERO_DATA_LENGTH: std_logic := '0';
+signal IP_PAYLOAD_SOF_D: std_logic := '0';
+signal IP_PAYLOAD_SOF_D2: std_logic := '0';
+signal RX_DATA_VALID_local: std_logic_vector(7 downto 0) := (others => '0');
+signal RX_SOF_local: std_logic := '0';
+signal RX_EOF_local: std_logic := '0';
+signal RX_EOF_D: std_logic := '0';
+signal RX_FRAME_VALID_local: std_logic := '0';
+
+--// RX SEQUENCE NUMBER
+signal RX_TCP_SEQ_NO_INC: unsigned(31 downto 0) := (others => '0');
+signal RX_TCP_SEQ_NO_TRACK: unsigned(31 downto 0) := (others => '0');
+signal RX_TCP_SEQ_NO_INCREMENT: integer range 0 to 8 := 0;
+signal RX_OUTOFBOUND: std_logic := '0';
+signal RX_ZERO_WINDOW_PROBE: std_logic := '0';
+signal GAP_IN_RX_SEQ: std_logic := '0';
+signal RETRANSMIT_FLAG: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal TX_SEQ_NO_JUMP_local: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal RX_VALID_ACK_TIMOUT: U24xNTCPSTREAMStype;
+
+--// state machine
+signal TCP_STATE_localrx: integer range 0 to 15 := 0;
+signal EVENTS2: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS4: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS4A: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS4B: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS4C: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS5: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS7: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS10: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS11: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENTS12: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal EVENT1: std_logic:= '0';
+signal EVENT2: std_logic:= '0';
+signal EVENT4: std_logic:= '0';
+signal EVENT4A: std_logic:= '0';
+signal EVENT4B: std_logic:= '0';
+signal EVENT6: std_logic:= '0';
+signal EVENT8: std_logic:= '0';
+
+----// ACK generation
+signal SEND_ACK_NOW: std_logic:= '0';
+signal DUPLICATE_RX_TCP_ACK_CNTR: U2xNTCPSTREAMStype := (others => (others => '0'));
+
+-- Keep-Alive probe sequence detection
+signal KA_PROBE_DET: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+
+--// relevant transmit destination information
+signal ORIGINATOR_IDENTIFIED: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal RX_BUF_FULL: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal RX_BUF_1MSSFREE: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal TX_ACK_WINDOW_LENGTH: unsigned(15 downto 0) := (others => '0');
+signal RX_WINDOW_RESIZE_STATE: SLV2xNTCPSTREAMStype := (others => (others => '0'));
+signal SEND_RX_WINDOW_RESIZE: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal RX_WINDOW_RESIZE2_STATE: SLV2xNTCPSTREAMStype := (others => (others => '0'));
+signal SEND_RX_WINDOW_RESIZE2: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+
+
+--// Measure round-trip delay: client -> server -> client
+signal TXRX_DELAY_CNTR: U24xNTCPSTREAMStype := (others => (others => '0'));
+signal TXRX_DELAY: U24xNTCPSTREAMStype := (others => (others => '0'));
+signal TXRX_DELAY_STATE: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+
+
+--// transmit packet assembly
+signal TCP_ISN: unsigned(31 downto 0) := x"010ae614";
+signal TCP_ISN_D: unsigned(31 downto 0) := x"010ae614";
+constant TX_TCP_RTS: std_logic := '0'; -- temp
+
+-- TCP transmit flow control -------------------
+signal EFF_RX_WINDOW_SIZE_PARTIAL_local: unsigned(16 downto 0) := (others => '0');
+signal EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local: std_logic := '0';
+
+--//---- TX PACKET ASSEMBLY
+signal TCP_CONGESTION_WINDOW: U16xNTCPSTREAMStype;
+signal TCP_TX_SLOW_START: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal NEXT_TX_TCP_FRAME_QUEUED: std_logic := '0';
+signal NEXT_TX_TCP_STREAM_SEL: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal TX_TCP_STREAM_SEL: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal RTS_local: std_logic := '0';
+signal TX_PACKET_SEQUENCE_START: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+TICK_1S_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(TICK_100MS = '1') then
+ if(TICK_CNTR = 9) then
+ TICK_CNTR <= (others => '0');
+ TICK_1S <= '1';
+ else
+ TICK_CNTR <= TICK_CNTR + 1;
+ TICK_1S <= '0';
+ end if;
+ else
+ TICK_1S <= '0';
+ end if;
+ end if;
+end process;
+
+-------------------------------------------------
+---- PARSE TCP HEADER ------------------
+-------------------------------------------------
+IP_PAYLOAD_WORD_VALID <= '1' when (unsigned(IP_PAYLOAD_DATA_VALID) /= 0) else '0';
+
+-- These fields are read at the first IP payload word
+-- Available at IP_PAYLOAD_SOF_D
+TCP_DECODE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ -- TODO reset after end of frame
+ RX_SOURCE_TCP_PORT_NO <= (others => '0');
+ RX_DEST_TCP_PORT_NO <= (others => '0');
+ RX_TCP_SEQ_NO <= (others => '0');
+ elsif(IP_PAYLOAD_SOF = '1') then
+ RX_SOURCE_TCP_PORT_NO <= IP_PAYLOAD_DATA(63 downto 48);
+ RX_DEST_TCP_PORT_NO <= IP_PAYLOAD_DATA(47 downto 32);
+ RX_TCP_SEQ_NO <= unsigned(IP_PAYLOAD_DATA(31 downto 0));
+ end if;
+ end if;
+end process;
+
+-- These fields are available at the second IP payload word
+TCP_DECODE_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ -- TODO reset after end of frame for cleaner code
+ RX_TCP_ACK_NO <= (others => '0');
+ RX_TCP_DATA_OFFSET <= (others => '0');
+ RX_TCP_FLAGS <= (others => '0');
+ RX_TCP_WINDOW_SIZE <= (others => '0');
+ elsif(IP_PAYLOAD_WORD_VALID = '1') and (unsigned(IP_PAYLOAD_WORD_COUNT) = 2) then
+ RX_TCP_ACK_NO <= unsigned(IP_PAYLOAD_DATA(63 downto 32));
+ RX_TCP_DATA_OFFSET <= IP_PAYLOAD_DATA(31 downto 28);
+ RX_TCP_FLAGS <= IP_PAYLOAD_DATA(23 downto 16);
+ -- TCP flags (MSb) CWR/ECE/URG/ACK/PSH/RST/SYN/FIN (LSb)
+ RX_TCP_WINDOW_SIZE <= unsigned(IP_PAYLOAD_DATA(15 downto 0));
+ end if;
+ end if;
+end process;
+RX_TCP_DATA_OFFSET_INC <= unsigned(RX_TCP_DATA_OFFSET) + 1;
+RX_TCP_DATA_OFFSET_DIV2_INC <= resize(unsigned(RX_TCP_DATA_OFFSET(3 downto 1)),4) + 1;
+
+
+-------------------------------------------------
+---- TCP stream identification ------------------
+-------------------------------------------------
+-- Identify the stream based on the destination tcp port for each
+-- incoming frame.
+-- ready at IP_PAYLOAD_SOF_D
+STREAM_INDEX_001: process(RX_DEST_TCP_PORT_NO, TCP_LOCAL_PORTS)
+begin
+ for I in 0 to (NTCPSTREAMS-1) loop
+ if(RX_DEST_TCP_PORT_NO = TCP_LOCAL_PORTS(I)) then
+ RX_TCP_STREAM_SEL(I) <= '1';
+ else
+ RX_TCP_STREAM_SEL(I) <= '0';
+ end if;
+ end loop;
+end process;
+
+-- reclock for better timing
+-- ready at IP_PAYLOAD_SOF_D2
+STREAM_INDEX_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ RX_TCP_STREAM_SEL_D <= RX_TCP_STREAM_SEL;
+ end if;
+end process;
+
+-- Demux key fields based on the current rx stream
+DEMUX_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL_D(I) = '1') then
+ RX_TCP_SEQ_NO_MAX2 <= RX_TCP_SEQ_NO_MAX(I);
+ RX_TCP_SEQ_NO_MIN2 <= RX_TCP_SEQ_NO_MIN(I);
+ end if;
+ end loop;
+ end if;
+end process;
+
+-- *121218 simplify/do not delay
+DEMUX_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL_D(I) = '1') then
+ TX_ACK_NO2 <= unsigned(TX_ACK_NO(I));
+ end if;
+ end loop;
+ end if;
+end process;
+
+-------------------------------------------------
+---- Collect response information ---------------
+-------------------------------------------------
+-- save destination IP, destination port and other relevant information
+-- upon receiving SYN. The information will be kept until the connection is closed.
+-- valid at IP_PAYLOAD_EOF_D2
+INFO_X: for I in 0 to (NTCPSTREAMS-1) generate
+ INFO_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(RX_TCP_STREAM_SEL(I) = '1') and (TCP_STATE(I) = 0) and (EVENT1 = '1') then
+ -- Received valid SYN while in LISTEN state
+ -- Save the destination addresses during the connection
+ TX_DEST_MAC_ADDR(I) <= RX_SOURCE_MAC_ADDR;
+ TX_DEST_IP_ADDR(I) <= RX_SOURCE_IP_ADDR;
+ TX_DEST_PORT_NO(I) <= RX_SOURCE_TCP_PORT_NO;
+ TX_IPv4_6n(I) <= RX_IPv4_6n;
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- After the initial SYN message where the originator identification characteristics
+-- are collected (MAC/IP/PORT), the origination of subsequent messages addressed
+-- to this IP/Port is verified. (we don't want a third party to crash our connection
+-- by sending RST or other disrupting messages.
+-- Information is valid at the end of the TCP header until the next received packet.
+-- Valid at IP_PAYLOAD_SOF_D2
+ORIGIN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ for I in 0 to (NTCPSTREAMS-1) loop
+ if(TX_DEST_MAC_ADDR(I) = RX_SOURCE_MAC_ADDR) and
+ (TX_DEST_IP_ADDR(I) = RX_SOURCE_IP_ADDR) and
+ (TX_DEST_PORT_NO(I) = RX_SOURCE_TCP_PORT_NO) then
+ ORIGINATOR_IDENTIFIED(I) <= '1';
+ else
+ ORIGINATOR_IDENTIFIED(I) <= '0';
+ end if;
+ end loop;
+ end if;
+end process;
+
+---------------------------------------------------
+------ State Machine / Events ---------------------
+---------------------------------------------------
+-- independent state machine for each server
+TCP_STATE_X: for I in 0 to (NTCPSTREAMS-1) generate
+
+ -- EVENTS2(I)
+ -- End of TCP segment transmission. Exclude the end of data frames.
+ EVENTS2(I) <= '1' when (TX_TCP_STREAM_SEL(I) = '1') and (MAC_TX_EOF = '1') and (TX_PACKET_TYPE = "10") else '0';
+
+ -- EVENTS4(I): received valid ACK flag and ACK number from the connection client. Wait until the end of frame to confirm validity.
+ EVENTS4(I) <= EVENTS12(I) when (RX_TCP_FLAGS(4) = '1') else '0';
+ -- Events 4A: received valid non-duplicate ACK (a subset of EVENTS4)
+ EVENTS4A(I) <= EVENTS4(I) when (RX_TCP_ACK_NO_D_local(I)(15 downto 0) /= RX_TCP_ACK_NO(15 downto 0)) else '0';
+ -- Events 4B: received valid duplicate ACK (a subset of EVENTS4)
+ EVENTS4B(I) <= EVENTS4(I) when (RX_TCP_ACK_NO_D_local(I)(15 downto 0) = RX_TCP_ACK_NO(15 downto 0)) else '0';
+ -- Events 4C: received expected ACK number = previous transmit sequence number + 1 or payload length
+ -- deleted: too narrow a definition, we may already have started transmitting data to client.
+ --EVENTS4C(I) <= EVENTS4(I) when (TX_SEQ_NO_local(I)(15 downto 0) = RX_TCP_ACK_NO(15 downto 0)) else '0';
+
+ -- EVENTS5(I)
+ -- Received valid FIN flag from expected server. Wait until the end of frame to confirm validity.
+ EVENTS5(I) <= '1' when (EVENTS12(I) = '1') and (RX_TCP_FLAGS(0) = '1') else '0';
+
+ -- EVENTS7(I)
+ -- Received valid RST flag from the connection server
+ EVENTS7(I) <= EVENTS12(I) when (RX_TCP_FLAGS(2) = '1') else '0';
+
+ -- EVENTS10(I)
+ -- Window resizing (receive flow control), no segment to transmit. The receive buffer is no
+ -- longer empty. Send a single ACK with a non-zero window.
+ EVENTS10(I) <= '1' when (((SEND_RX_WINDOW_RESIZE(I) = '1') or (SEND_RX_WINDOW_RESIZE2(I) = '1')) and (TX_TCP_RTS = '0')) else '0';
+
+ -- EVENTS11(I)
+ -- keep-alive or zero-window check: RFC: "send a probe segment designed to elicit a response from the
+ -- peer TCP. Such a segment generally contains SEG.SEQ = SND.NXT-1
+ EVENTS11(I) <= '1' when ((TCP_KEEPALIVE_EN(I) = '1') and (TIMER2_D(I) /= 0) and (TIMER2(I) = 0) and (TX_TCP_RTS = '0')) else
+ ZWP_TRIGGER(I);
+
+ -- EVENTS12(I)
+ -- Receiving a valid TCP frame or ACK for stream I from expected client
+ EVENTS12(I) <= '1' when (IP_PAYLOAD_EOF_D = '1') and (RX_TCP_STREAM_SEL_D(I) = '1') and (VALID_RX_TCP_ALL = '1') and (ORIGINATOR_IDENTIFIED(I) = '1') else '0';
+
+ -- Note: removed state 2 because in the SYN/SYN ACK/ACK sequence
+ -- if the ACK and only the ACK is dropped, the connection becomes established. If more things are dropped, there is a reset.
+ TCP_STATE_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ -- reset all connections (abrupt, may cause server side to remain connected, thus preventing any further connection on that port)
+ TCP_STATE(I) <= 0;
+ elsif(CONNECTED_FLAG_local(I) = '1') and (CONNECTION_RESET(I) = '1') then
+ -- user-initiated selective connection request while connected
+ TCP_STATE(I) <= 6; -- send FIN
+ elsif(CONNECTED_FLAG_local(I) = '1') and (TCP_KEEPALIVE_EN(I) = '1') and (KASTATE(I) = 0) then
+ -- failed keepalive. Automatic disconnect.
+ TCP_STATE(I) <= 6; -- send FIN
+
+ -- rx-related events
+ elsif(EVENTS7(I) = '1') then
+ -- Reset / Abort (true in any state, as long as we verify the originator)
+ -- received RST
+ TCP_STATE(I) <= 0;
+ elsif(RX_TCP_STREAM_SEL_D(I) = '1') and (TCP_STATE(I) = 0) and (EVENT1 = '1') then
+ -- LISTEN
+ -- Received valid SYN
+ TCP_STATE(I) <= 1; -- SYN_RCVD. Transmitting SYN,ACK in progress
+-- elsif(TCP_STATE(I) = 2) and (EVENTS4C(I) = '1') then -- too narrow a definition. We may already have sent data to client. ack number is not just +1
+ elsif(TCP_STATE(I) = 2) and (EVENTS4(I) = '1') then
+ -- CONNECTION ESTABLISHMENT: Await ACK from client
+ -- received valid ACK and ACK number
+ TCP_STATE(I) <= 3; -- CONNECTED state
+ elsif(CONNECTED_FLAG_local(I) = '1') and (EVENTS5(I) = '1') then
+ -- client-initiated connection termination . Send ACK
+ TCP_STATE(I) <= 4; -- sending ACK
+ elsif (TCP_STATE(I) = 7) and (EVENTS5(I) = '1') then
+ -- received FIN after FIN. Send final ACK.
+ TCP_STATE(I) <= 8;
+ elsif (TCP_STATE(I) = 5) and (EVENTS4(I) = '1') then
+ -- received final ACK after FIN/ACK+FIN. Connection is properly closed.
+ TCP_STATE(I) <= 0;
+
+
+ -- tx-related events (end of transmission)
+ elsif (TCP_STATE(I) = 6) and (EVENTS2(I) = '1') and (TX_FLAGS(I)(0) = '1') then
+ -- sent FIN. Awaiting ACK + FIN
+ TCP_STATE(I) <= 7;
+ elsif (TCP_STATE(I) = 8) and (EVENTS2(I) = '1') and (TX_FLAGS(I)(4) = '1') then
+ -- Sent final ACK. Connection is properly closed
+ TCP_STATE(I) <= 0;
+ elsif (TCP_STATE(I) = 4) and (EVENTS2(I) = '1') and (TX_FLAGS(I)(4) = '1') then
+ -- sent ACK after receiving FIN. send final FIN. Await final ack.
+ TCP_STATE(I) <= 5;
+ elsif(TX_TCP_STREAM_SEL(I) = '1') and (TCP_STATE(I) = 1) and (EVENT2 = '1') then
+ -- Sent SYN/ACK. Awaiting ACK (not essential).
+ TCP_STATE(I) <= 2; -- CONNECTED state
+-- elsif(TX_TCP_STREAM_SEL(I) = '1') and (TCP_STATE(I) = 4) and (EVENT2 = '1') then
+-- -- CONNECTION TERMINATION: await end of ACK transmission
+-- -- completed ACK transmission
+-- TCP_STATE(I) <= 5; -- await end of FIN/ACK transmission
+-- elsif(TX_TCP_STREAM_SEL(I) = '1') and (TCP_STATE(I) = 5) and (EVENT2 = '1') then
+-- -- CONNECTION TERMINATION: await end of FIN/ACK transmission
+-- -- completed FIN/ACK transmission
+-- -- don't wait for an ACK from client (race condition: next connection SYN could arrive first)
+-- TCP_STATE(I) <= 0; -- LISTEN STATE
+
+ -- timeouts
+ elsif ((TCP_STATE(I) = 6) or (TCP_STATE(I) = 7) or (TCP_STATE(I) = 8)) and (TIMER1(I)= 0) then
+ -- timeout waiting for normal server-originated connection termination. Abnormal connection termination.
+ TCP_STATE(I) <= 0;
+ elsif ((TCP_STATE(I) = 4) or (TCP_STATE(I) = 5)) and (TIMER1(I)= 0) then
+ -- timeout waiting for normal client-originated connection termination. Abnormal connection termination.
+ TCP_STATE(I) <= 0;
+
+ end if;
+ end if;
+ end process;
+
+ --// TCP-IP connection status
+ -- report TCP-IP connection status to TCP_TXBUF
+ CONNECTED_FLAG_local(I) <= '1' when (TCP_STATE(I) = 3) or (TCP_STATE(I) = 2) else '0'; -- *120218
+ CONNECTED_FLAG(I) <= CONNECTED_FLAG_local(I);
+
+ -- state machine timer (so that we do not get stuck into a state)
+ TIMER1_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ -- reset all connections (abrupt, may cause server side to remain connected, thus preventing any further connection on that port)
+ -- idle state, clear timer to 'expired' (0)
+ TIMER1(I) <= (others => '0');
+ elsif(CONNECTED_FLAG_local(I) = '1') and (CONNECTION_RESET(I) = '1') then
+ -- user-initiated selective connection request while connected
+ TIMER1(I) <= to_unsigned(20, TIMER1(I)'length);
+ elsif(CONNECTED_FLAG_local(I) = '1') and (TCP_KEEPALIVE_EN(I) = '1') and (KASTATE(I) = 0) then
+ -- failed keepalive. Disconnect.
+ TIMER1(I) <= to_unsigned(20, TIMER1(I)'length);
+ elsif (CONNECTED_FLAG_local(I) = '1') and (EVENTS5(I) = '1') then
+ -- client-initiated connection termination .
+ TIMER1(I) <= to_unsigned(20, TIMER1(I)'length);
+ elsif(TCP_STATE(I) = 0) then
+ -- idle state, clear timer to 'expired' (0)
+ TIMER1(I) <= (others => '0');
+ elsif(TICK_100MS = '1') and (TIMER1(I) /= 0) then
+ -- decrement until timer has expired (0)
+ TIMER1(I) <= TIMER1(I) - 1;
+ end if;
+ end if;
+ end process;
+
+end generate;
+
+-- contextual TCP_STATE while receiving a frame
+RX_TCP_STATE_GEN: process(RX_TCP_STREAM_SEL, TCP_STATE)
+variable TCP_STATEv: integer;
+begin
+ TCP_STATEv := 0;
+ for I in 0 to (NTCPSTREAMS-1) loop
+ if(RX_TCP_STREAM_SEL(I) = '1') then
+ TCP_STATEv := TCP_STATE(I);
+ end if;
+ end loop;
+ TCP_STATE_localrx <= TCP_STATEv;
+end process;
+
+
+-- keep-alive timer
+-- Send zero-data length keep alive message when TIMER2 = 0
+-- TIMER2 is expressed in 1s units
+TIMER2_GEN_X: for I in 0 to (NTCPSTREAMS-1) generate
+ TIMER2_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ TIMER2_D(I) <= TIMER2(I);
+
+ if(SYNC_RESET = '1') or (TCP_STATE(I) /= 3) or (TCP_KEEPALIVE_EN(I) = '0') then
+ -- reset or not connected state or keepalive not enabled
+ TIMER2(I) <= to_unsigned(TCP_KEEPALIVE_PERIOD, TIMER2(I)'length);
+ elsif(EVENTS12(I) = '1') then
+ -- received data or ACK from client I. re-arm keepalive timer
+ TIMER2(I) <= to_unsigned(TCP_KEEPALIVE_PERIOD, TIMER2(I)'length);
+ elsif(NEXT_TX_TCP_STREAM_SEL(I) = '1') and (NEXT_TX_TCP_FRAME_QUEUED = '1') and (RTS_local = '0') then
+ -- sending a frame to client. re-arm keepalive timer
+ TIMER2(I) <= to_unsigned(TCP_KEEPALIVE_PERIOD, TIMER2(I)'length);
+ elsif((TICK_1S = '1') and (TIMER2(I) /= 0)) then
+ -- decrement until timer has expired (0)
+ TIMER2(I) <= TIMER2(I) - 1;
+ end if;
+ end if;
+ end process;
+
+-- detect broken connection: keepalive message sent, ack or no ack received
+-- Algo: set KASTATE to 3 when receiving ACK, decrement every timeout. Broken link when 0
+ TIMER2_GEN_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (TCP_STATE(I) /= 3) or (TCP_KEEPALIVE_EN(I) = '0') then
+ -- reset or not connected state or keepalive not enabled
+ KASTATE(I) <= "11"; -- awaiting ACK from client
+ elsif(EVENTS12(I) = '1') then
+ -- received data or ACK from client I
+ KASTATE(I) <= "11";
+ elsif((TICK_1S = '1') and (TIMER2(I) = 1)) then
+ -- keepalive timeout. Send a probe with no data
+ if(KASTATE(I) /= 0) then
+ KASTATE(I) <= KASTATE(I) - 1;
+ end if;
+ end if;
+ end if;
+ end process;
+end generate;
+-- connection status in KASTATE(I)(1)
+
+--// zero-window probe timer
+-- Keep track of zero-window sizes (yes/no) reported by the other side of the TCP connection
+-- Available at IP_PAYLOAD_EOF_D2
+ZWS_GEN_X: for I in 0 to (NTCPSTREAMS-1) generate
+ ZWS_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (TCP_STATE(I) /= 3) then
+ ZWS(I) <= '0';
+ elsif(EVENTS4(I) = '1') then
+ -- Valid ACK received for stream RX_TCP_STREAM_SEL_D
+ if(RX_TCP_WINDOW_SIZE = 0) then
+ ZWS(I) <= '1';
+ else
+ ZWS(I) <= '0';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ -- Send zero-window probe message when TIMER3 = 0
+ -- TIMER3 is expressed in 100ms units
+ -- ZERO_WINDOW_PROBE_PERIOD = minimum interval to send zero-window probe (in 100ms units)
+ TIMER3_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (TCP_STATE(I) /= 3) or (ZWS(I) = '0')then
+ -- reset or not connected state or keepalive not enabled
+ TIMER3(I) <= to_unsigned(ZERO_WINDOW_PROBE_PERIOD, TIMER3(I)'length);
+ elsif((TICK_100MS = '1') and (TIMER3(I) = 0) and (ZWP_STATE(I)(3) = '0')) then
+ -- timer3 expired (0) => send zero-window probe.
+ -- Re-arm timer3. Increase period between successive zero-window probes.
+ case ZWP_STATE(I) is
+ when "0000" => TIMER3(I) <= to_unsigned(ZERO_WINDOW_PROBE_PERIOD, TIMER3(I)'length); -- 0.3s
+ when "0001" => TIMER3(I) <= to_unsigned(2*ZERO_WINDOW_PROBE_PERIOD, TIMER3(I)'length);-- 0.6s
+ when "0010" => TIMER3(I) <= to_unsigned(4*ZERO_WINDOW_PROBE_PERIOD, TIMER3(I)'length);-- 1.2s
+ when "0011" => TIMER3(I) <= to_unsigned(8*ZERO_WINDOW_PROBE_PERIOD, TIMER3(I)'length);-- 2.4s
+ when others => TIMER3(I) <= to_unsigned(16*ZERO_WINDOW_PROBE_PERIOD, TIMER3(I)'length);-- 5.8s
+ end case;
+ elsif((TICK_100MS = '1') and (TIMER3(I) /= 0)) then
+ -- decrement until timer has expired (0)
+ TIMER3(I) <= TIMER3(I) - 1;
+ end if;
+ end if;
+ end process;
+
+ -- slowly increase time between successive zero window probes
+ -- ZWP_STATE(I) goes from 0 to 8 and stays there until connection is reset or zero-window condition disappears.
+ TIMER3_GEN_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (TCP_STATE(I) /= 3) or (ZWS(I) = '0')then
+ -- reset or not connected state or keepalive not enabled
+ ZWP_STATE(I) <= (others => '0');
+ elsif((TICK_100MS = '1') and (TIMER3(I) = 0) and (ZWP_STATE(I)(3) = '0')) then
+ -- slowly increase time between successive zero window probes
+ ZWP_STATE(I) <= ZWP_STATE(I) + 1;
+ end if;
+ end if;
+ end process;
+
+ ZWP_TRIGGER(I) <= '1' when ((TICK_100MS = '1') and (TIMER3(I) = 0)) else '0';
+
+end generate;
+
+---------------------------------------------------
+------ State Machine EVENTS -----------------------
+---------------------------------------------------
+-- Event 1: receive valid SYN flag (from anyone). Wait until the end of frame to confirm validity.
+-- design note: strengthen validity check w.r.t. previous 1G COM5402 implementation.
+EVENT1 <= '1' when (IP_PAYLOAD_EOF_D = '1') and (VALID_RX_TCP_ALL = '1') and (RX_TCP_FLAGS(1) = '1') else '0';
+
+-- Event 2: completed transmission of TCP segment.
+EVENT2 <= MAC_TX_EOF;
+
+-- EVENT4: received valid ACK flag and ACK number from the connection client for the TCP stream RX_TCP_STREAM_SEL_D(I) associated with the current rx frame
+EVENT4 <= '1' when unsigned(EVENTS4) /= 0 else '0';
+-- Events 4A: received valid non-duplicate ACK (a subset of EVENTS4)
+EVENT4A <= '1' when unsigned(EVENTS4A) /= 0 else '0';
+-- Events 4B: received valid duplicate ACK (a subset of EVENTS4)
+EVENT4B <= '1' when unsigned(EVENTS4B) /= 0 else '0';
+
+-- Event 6
+-- received valid segment, no segment to transmit. generate ACK only.
+EVENT6 <= '1' when ((SEND_ACK_NOW = '1') and (TX_TCP_RTS = '0')) else '0';
+
+-- Event 8
+-- data is ready to be transmitted over TCP. Send data. A distinct tx state machine is located
+-- in TCP_TXBUF together with the transmit buffers.
+-- Block sending until we receive a valid ACK from the previous transmission
+-- A frame is ready for transmission when
+-- (a) the effective client rx window size is non-zero
+-- (b) the tx buffer contains either the effective client rx window size or 1023 bytes or no new data received in the last 200us
+-- (c) TCP is not busy transmitting/assembling another packet
+-- implied condition: TCP is in connected state (3) otherwise TX_PAYLOAD_RTS = '0'
+EVENT8 <= '1' when ((TX_PAYLOAD_RTS = '1') and (RTS_local = '0')) else '0';
+
+-------------------------------------------------
+---- Receive data -------------------------------
+-------------------------------------------------
+
+--// CHECK RX TCP VALIDITY -----------------------------
+-- overall TCP validity. Can also be used in the case of zero-length TCP data fields)
+-- Partial verification done prior to the TCP payload field,
+-- Final verification is aligned with IP_PAYLOAD_EOF_D
+VALIDITY_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_PAYLOAD_EOF_D <= IP_PAYLOAD_EOF;
+
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_SOF = '1') then
+ if(unsigned(RX_IP_PROTOCOL) /= 6) then
+ -- not TCP
+ VALID_RX_TCP0 <= '0';
+ else
+ -- valid unless proven otherwise
+ VALID_RX_TCP0 <= '1';
+ end if;
+ elsif(IP_RX_FRAME_VALID = '0') then
+ -- did not pass one of the following validity criteria
+ -- (a) protocol is IP
+ -- (b) unicast or multicast destination IP address matches
+ -- (c) correct IP header checksum (IPv4 only)
+ -- (d) allowed IPv6
+ VALID_RX_TCP0 <= '0';
+ elsif (IP_PAYLOAD_SOF_D2 = '1') and (TCP_STATE_localrx = 3) and (ORIGINATOR_IDENTIFIED /= RX_TCP_STREAM_SEL_D) then
+ -- (g) TCP connection is established and origin MAC/IP/Port is inconsistent (spoof detection)
+ VALID_RX_TCP0 <= '0';
+ elsif (IP_PAYLOAD_SOF_D2 = '1') and (unsigned(RX_TCP_STREAM_SEL_D) = 0) then
+ -- destination port number does not match any of the specified TCP_LOCAL_PORTS
+ VALID_RX_TCP0 <= '0';
+ elsif(IP_PAYLOAD_EOF = '1') then
+ -- additional checks performed exclusively at the end of frame
+ -- mostly related to transmission errors (Ethernet FCS/CRC, TCP checksum)
+ if(IP_RX_FRAME_VALID = '0') then
+ -- did not pass one of the following validity criteria
+ -- (e) Ethernet frame is valid (correct FCS, dest address)
+ VALID_RX_TCP0 <= '0';
+ end if;
+ elsif(IP_PAYLOAD_EOF_D = '1') then
+ if(VALID_TCP_CHECKSUM = '0') then
+ VALID_RX_TCP0 <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+VALID_RX_TCP_ALL <= '0' when (IP_PAYLOAD_EOF_D = '1') and (VALID_TCP_CHECKSUM = '0') else VALID_RX_TCP0;
+ -- to account for the late arrival of VALID_TCP_CHECKSUM (due to timing)
+
+-- Note: additional checks must be performed to forward data to the output data sink (TCP state = connected,
+-- enough space in data sink to accept the data).
+
+
+--// COPY RX TCP DATA TO BUFFER ---------------------------------------------
+-- Algorithm: TCP header length is in RX_TCP_DATA_OFFSET: range 5-15 words of 32-bit
+
+-- sloppy but simple filtering of non-payload words
+-- IMPORTANT: always left aligned (MSB first): RX_DATA_VALID is x80,xc0,xe0,xf0,....x01,x00
+RX_PAYLOAD_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_SOF = '1') or (VALID_RX_TCP_ALL = '0') or (GAP_IN_RX_SEQ = '1') or (RX_OUTOFBOUND = '1') then
+ RX_DATA <= (others => '0');
+ elsif(IP_PAYLOAD_WORD_VALID = '1') and (TCP_PAYLOAD_FLAG = '1')then
+ if(RX_TCP_DATA_OFFSET(0) = '0') then
+ -- TCP header length is an exact integer multiple of words
+ RX_DATA <= IP_PAYLOAD_DATA;
+ else
+ -- offset by 1/2 a word
+ if (TCP_SOF_FLAG = '1') then
+ if (IP_PAYLOAD_DATA_VALID(3) = '0') then
+ -- zero length payload
+ RX_DATA <= (others => '0');
+ else
+ -- left-aligned
+ RX_DATA(63 downto 32) <= IP_PAYLOAD_DATA(31 downto 0);
+ RX_DATA(31 downto 0) <= (others => '0');
+ end if;
+ else
+ RX_DATA <= IP_PAYLOAD_DATA;
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+
+-- IMPORTANT: always left aligned (MSB first): RX_DATA_VALID is x80,xc0,xe0,xf0,....x01,x00
+RX_PAYLOAD_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_SOF = '1') or (VALID_RX_TCP_ALL = '0') or (GAP_IN_RX_SEQ = '1') or (RX_OUTOFBOUND = '1') then
+ RX_DATA_VALID_local <= (others => '0');
+ elsif(IP_PAYLOAD_WORD_VALID = '1') and (TCP_PAYLOAD_FLAG = '1') then
+ if(RX_TCP_DATA_OFFSET(0) = '0') then
+ -- TCP header length is an exact integer multiple of words
+ RX_DATA_VALID_local <= IP_PAYLOAD_DATA_VALID;
+ else
+ -- offset by 1/2 a word
+ if (TCP_SOF_FLAG = '1') then
+ if (IP_PAYLOAD_DATA_VALID(3) = '0') then
+ -- zero length payload
+ RX_DATA_VALID_local <= (others => '0');
+ else
+ -- left-aligned
+ RX_DATA_VALID_local(7 downto 4) <= IP_PAYLOAD_DATA_VALID(3 downto 0);
+ RX_DATA_VALID_local(3 downto 0) <= (others => '0');
+ end if;
+ else
+ RX_DATA_VALID_local <= IP_PAYLOAD_DATA_VALID;
+ end if;
+ end if;
+ else
+ RX_DATA_VALID_local <= (others => '0');
+ end if;
+ end if;
+end process;
+RX_DATA_VALID <= RX_DATA_VALID_local;
+
+TCP_PAYLOAD_FLAG <= '1' when (unsigned(IP_PAYLOAD_WORD_COUNT) > 2) and (unsigned(IP_PAYLOAD_WORD_COUNT) > unsigned(RX_TCP_DATA_OFFSET(3 downto 1))) else '0';
+-- wait until word#3 to assess possible presence of payload (since RX_TCP_DATA_OFFSET is only read at word #2
+-- Note: we don't check byte validity here, so payload could still be empty.
+
+-- Generate RX_SOF (looks like the above TCP_PAYLOAD_FLAG code, but is reset after the first payload word).
+-- Also keep track of whether the received packet has zero data length or not. (Needed to
+-- determine whether an ACK should be sent)
+RX_PAYLOAD_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_SOF = '1') then
+ TCP_SOF_FLAG <= '1'; -- Awaiting TCP_SOF word
+ elsif (IP_PAYLOAD_WORD_VALID = '1') and (TCP_PAYLOAD_FLAG = '1') then
+ -- reached the word where TCP_SOF is expected (if not empty frame)
+ TCP_SOF_FLAG <= '0';
+ end if;
+
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_SOF = '1') or (VALID_RX_TCP_ALL = '0') or (GAP_IN_RX_SEQ = '1') or (RX_OUTOFBOUND = '1') then
+ RX_SOF_local <= '0';
+ RX_TCP_STREAM_SEL_OUT <= (others => '0');
+-- RX_TCP_NON_ZERO_DATA_LENGTH <= '0';
+ elsif(IP_PAYLOAD_WORD_VALID = '1') and (TCP_PAYLOAD_FLAG = '1') and (TCP_SOF_FLAG = '1') then
+ -- generate SOF if non-zero data length in payload
+ if(RX_TCP_DATA_OFFSET(0) = '0') and (IP_PAYLOAD_DATA_VALID(7) = '1') then
+ -- TCP header length is an exact integer multiple of words and first payload word is not empty
+ RX_SOF_local <= '1';
+ RX_TCP_STREAM_SEL_OUT <= RX_TCP_STREAM_SEL_D;
+-- RX_TCP_NON_ZERO_DATA_LENGTH <= '1';
+ elsif (RX_TCP_DATA_OFFSET(0) = '1') and (IP_PAYLOAD_DATA_VALID(3) = '1') then
+ RX_SOF_local <= '1';
+ RX_TCP_STREAM_SEL_OUT <= RX_TCP_STREAM_SEL_D;
+-- RX_TCP_NON_ZERO_DATA_LENGTH <= '1';
+ else
+ -- first payload word but no data
+ RX_SOF_local <= '0';
+ RX_TCP_STREAM_SEL_OUT <= (others => '0');
+-- RX_TCP_NON_ZERO_DATA_LENGTH <= '0';
+ end if;
+ else
+ RX_SOF_local <= '0';
+ end if;
+ end if;
+end process;
+RX_SOF <= RX_SOF_local;
+
+-- detect non-zero data length: check the presence of the first payload byte
+RX_PAYLOAD_004: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_SOF = '1') then
+ -- RX_TCP_DATA_OFFSET is read at IP_PAYLOAD_WORD_COUNT = 2
+ RX_TCP_NON_ZERO_DATA_LENGTH <= '0';
+ elsif(IP_PAYLOAD_WORD_VALID = '1') and (TCP_PAYLOAD_FLAG = '1') and (TCP_SOF_FLAG = '1') then
+ if(RX_TCP_DATA_OFFSET(0) = '0') and (IP_PAYLOAD_DATA_VALID(7) = '1') then
+ -- TCP header length is an exact integer multiple of words and first payload word is not empty
+ RX_TCP_NON_ZERO_DATA_LENGTH <= '1';
+ elsif (RX_TCP_DATA_OFFSET(0) = '1') and (IP_PAYLOAD_DATA_VALID(3) = '1') then
+ RX_TCP_NON_ZERO_DATA_LENGTH <= '1';
+ else
+ -- first payload word but no data
+ RX_TCP_NON_ZERO_DATA_LENGTH <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+-- generate RX_EOF
+RX_PAYLOAD_005: process(CLK)
+begin
+ if rising_edge(CLK) then
+ RX_EOF_D <= RX_EOF_local;
+
+ if(SYNC_RESET = '1') or (IP_PAYLOAD_SOF = '1') or (VALID_RX_TCP_ALL = '0') or (GAP_IN_RX_SEQ = '1') or (RX_OUTOFBOUND = '1') then
+ RX_EOF_local <= '0';
+ elsif (IP_PAYLOAD_EOF = '1') and (TCP_PAYLOAD_FLAG = '1') then
+ -- detect empty frame
+ if(TCP_SOF_FLAG = '1') and (RX_TCP_DATA_OFFSET(0) = '0') and (IP_PAYLOAD_DATA_VALID(7) = '0') then
+ -- even length header, empty frame
+ RX_EOF_local <= '0';
+ elsif(TCP_SOF_FLAG = '1') and (RX_TCP_DATA_OFFSET(0) = '1') and (IP_PAYLOAD_DATA_VALID(3) = '0') then
+ -- odd length header, empty frame
+ RX_EOF_local <= '0';
+ else
+ -- end of non-empty frame
+ RX_EOF_local <= '1';
+ end if;
+ else
+ RX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+RX_EOF <= RX_EOF_local;
+
+RX_FRAME_VALID_local <= VALID_RX_TCP_ALL when (RX_TCP_NON_ZERO_DATA_LENGTH = '1') and (GAP_IN_RX_SEQ = '0') and (RX_OUTOFBOUND = '0') else '0';
+RX_FRAME_VALID <= RX_FRAME_VALID_local;
+ -- always verify the rx tcp frame validity at IP_PAYLOAD_EOF_D = RX_EOF
+ -- Do not forward data to the rx buffer if there is a gap in rx sequence or if the client
+ -- is doing a zero window-length probe (i.e. writing past the declared max)
+ -- No point in writing non-TCP data to the rx buffer in the first place (those pesky
+ -- NetBUI packets fill-up pretty fast, even if we rewind the write pointer at the next valid
+ -- TCP packet
+ -- Also block data if not connected.
+
+WPTR_GEN_001: process(RX_DATA_VALID_local)
+begin
+ if(RX_DATA_VALID_local(0) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 8;
+ elsif(RX_DATA_VALID_local(1) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 7;
+ elsif(RX_DATA_VALID_local(2) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 6;
+ elsif(RX_DATA_VALID_local(3) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 5;
+ elsif(RX_DATA_VALID_local(4) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 4;
+ elsif(RX_DATA_VALID_local(5) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 3;
+ elsif(RX_DATA_VALID_local(6) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 2;
+ elsif(RX_DATA_VALID_local(7) = '1') then
+ RX_TCP_SEQ_NO_INCREMENT <= 1;
+ else
+ RX_TCP_SEQ_NO_INCREMENT <= 0;
+ end if;
+end process;
+
+-- read the TCP client sequence number in the received TCP header.
+-- This is subsequently used as ack when replying or sending data to the TCP client
+RX_PAYLOAD_006: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_PAYLOAD_SOF_D <= IP_PAYLOAD_SOF;
+ IP_PAYLOAD_SOF_D2 <= IP_PAYLOAD_SOF_D;
+
+ if (IP_PAYLOAD_SOF_D = '1') then
+ RX_TCP_SEQ_NO_TRACK <= RX_TCP_SEQ_NO;
+ elsif(RX_DATA_VALID_local(7) = '1') then
+ -- at least one byte passed to rx elastic buffer
+ RX_TCP_SEQ_NO_TRACK <= RX_TCP_SEQ_NO_TRACK + RX_TCP_SEQ_NO_INCREMENT;
+ end if;
+ end if;
+end process;
+
+--// RX SEQUENCE NUMBER ------------------------
+RX_TCP_SEQ_NO_INC <= RX_TCP_SEQ_NO + 1;
+
+-- Manage tx ack number
+TX_ACK_GENx: for I in 0 to (NTCPSTREAMS-1) generate
+ TX_ACK_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(RX_TCP_STREAM_SEL(I) = '1') then
+ -- rx event
+ if(TCP_STATE(I) < 3) and (EVENT1 = '1') then -- *062716
+ -- Received valid SYN while in LISTEN state
+ -- ACK sequence number is the one received + 1
+ -- Extend the applicability to the case when we receive multiple SYN messages (could happen
+ -- when transmission delay is long) *062716
+ TX_ACK_NO(I) <= RX_TCP_SEQ_NO_INC;
+ elsif(CONNECTED_FLAG_local(I) = '1') and (EVENTS5(I) = '1') then
+ -- Received valid FIN while in CONNECTED state
+ -- ACK sequence number depends on whether FIN packets include data or not
+ TX_ACK_NO(I) <= RX_TCP_SEQ_NO_TRACK + 1;
+ elsif(RX_ZERO_WINDOW_PROBE = '1') then
+ -- TCP zero-window-length exception. sender may be testing whether the TX_ACK_WINDOW_LENGTH is
+ -- still zero by sending a 1-byte data. Treat as a zero-length packet
+ elsif(GAP_IN_RX_SEQ = '1') then
+ -- Do not update TX_ACK_NO if we have received a valid packet with unexpected RX_TCP_SEQ_NO (gap in sequence)
+ -- as data was not written to the rx buffer, but we still send an ACK.
+ elsif(RX_EOF_D = '1') and (RX_FRAME_VALID_local = '1') then
+ -- in CONNECTED state, received and successfully forwarded a rx segment.
+ -- TX_ACK_NO is the next expected number
+ TX_ACK_NO(I) <= RX_TCP_SEQ_NO_TRACK;
+ end if;
+ end if;
+ end if;
+ end process;
+end generate;
+
+
+------------------------------------------------
+---- TCP receive flow control -------------------
+-------------------------------------------------
+
+-- Detect when RX_TCP_SEQ_NO is beyond the TCP receive window (it happens, for example during TCP zero-window probes)
+RX_OUTOFBOUND_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_OUTOFBOUND <= '0';
+ -- rx window upper bound (RX_TCP_SEQ_NO_MAX) computed upon sending the last tx frame.
+ elsif(RX_TCP_SEQ_NO >= RX_TCP_SEQ_NO_MAX2) and
+ not((RX_TCP_SEQ_NO(31 downto 30) = "11") and (RX_TCP_SEQ_NO_MAX2(31 downto 30) = "00")) then
+ -- a bit complicated because of modulo 2^32 counters.
+ RX_OUTOFBOUND <= '1';
+ elsif(RX_TCP_SEQ_NO < RX_TCP_SEQ_NO_MIN2) and
+ not((RX_TCP_SEQ_NO(31 downto 30) = "00") and (RX_TCP_SEQ_NO_MIN2(31 downto 30) = "11")) then
+ RX_OUTOFBOUND <= '1';
+ else
+ RX_OUTOFBOUND <= '0';
+ end if;
+ end if;
+end process;
+
+-- Send ACK immediately upon receiving a valid data segment while TCP connected.
+-- Watch out for infinite loops! cannot send an ACK on an ACK
+-- Therefore, inhibit SEND_ACK_NOW if the last packet received has the ACK with zero-length.
+SEND_ACK_NOW <= VALID_RX_TCP_ALL when (TCP_STATE_localrx = 3) and (RX_TCP_NON_ZERO_DATA_LENGTH = '1') and (IP_PAYLOAD_EOF_D = '1') else '0'; -- *070118
+
+-- Detect when there is a gap in the RX_TCP_SEQ_NO, indicating a previous frame is missing
+-- In general, we expect RX_TCP_SEQ_NO to match TX_ACK_NO, the next expected rx sequence number.
+GAP_IN_RX_SEQ <= '1' when (RX_TCP_SEQ_NO /= TX_ACK_NO2) else '0'; -- ready at IP_PAYLOAD_SOF_D2
+
+-- Detect when client tries to send data past the end of the window (for example during
+-- TCP zero-window probing. Sender may be probing whether the TX_ACK_WINDOW_LENGTH is
+-- still zero by sending a 1-byte data past the end of the window.
+RX_ZERO_WINDOW_PROBE <= (VALID_RX_TCP_ALL and RX_OUTOFBOUND) when (TCP_STATE_localrx = 3) else '0';
+
+-- external receive buffer is full
+RX_BUF_FULL_GEN: for I in 0 to (NTCPSTREAMS-1) generate
+ RX_BUF_FULL(I) <= '1' when (unsigned(RX_FREE_SPACE(I)) = 0) else '0';
+end generate;
+
+-- external receive buffer has space for at least one MSS frame *071416
+RX_BUF_1MSSFREE_GEN: for I in 0 to (NTCPSTREAMS-1) generate
+ RX_BUF_1MSSFREE(I) <= '1' when (unsigned(RX_FREE_SPACE(I)) > MSS) else '0';
+end generate;
+
+-- flow control information is sent to the client within the ack
+-- using the TX_ACK_WINDOW_LENGTH window size FROZEN during packet transmission
+TX_ACK_WINDOW_LENGTH_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_ACK_WINDOW_LENGTH <= to_unsigned(MSS,TX_ACK_WINDOW_LENGTH'length); -- initial available is at least 1 MSS
+ elsif(RTS_local = '0') then
+ -- update TX_ACK_WINDOW_LENGTH when triggering a frame transmission back to a client
+ -- Two trigger events:
+ if(NEXT_TX_TCP_FRAME_QUEUED = '1') then
+ -- short (no payload data) tx packet for stream NEXT_TX_TCP_STREAM_SEL
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(NEXT_TX_TCP_STREAM_SEL(I) = '1') then
+ TX_ACK_WINDOW_LENGTH <= unsigned(RX_FREE_SPACE(I));
+ end if;
+ end loop;
+ elsif(EVENT8 = '1') then
+ -- long (with payload data) tx packet for stream TX_STREAM_SEL
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(TX_STREAM_SEL(I) = '1') then
+ TX_ACK_WINDOW_LENGTH <= unsigned(RX_FREE_SPACE(I));
+ end if;
+ end loop;
+ end if;
+ end if;
+ end if;
+end process;
+-- new *080818 take a margin of 4 samples = 32 bytes when reporting about the available space in the rx buffer
+-- as we are trying to shorten the time between RX_EOF and ack transmission.
+-- Reason: RX_FREE_SPACE information is 3 clocks late
+TX_ACK_WINDOW_LENGTH_GEN_002: process(TX_ACK_WINDOW_LENGTH)
+begin
+ if(TX_ACK_WINDOW_LENGTH >= 32) then
+ TX_ACK_WINDOW_LENGTH_OUT <= std_logic_vector(TX_ACK_WINDOW_LENGTH - 32);
+ else
+ TX_ACK_WINDOW_LENGTH_OUT <= (others => '0');
+ end if;
+end process;
+
+-- window resizing
+-- set when transmitting an ACK with TX_ACK_WINDOW_LENGTH = 0 indicating receiver buffer is full,
+-- clear when the input receive buffer is no longer empty.
+RX_WINDOW_RESIZE_STATEx: for I in 0 to (NTCPSTREAMS-1) generate
+ RX_WINDOW_RESIZE_STATE_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_WINDOW_RESIZE_STATE(I) <= "00";
+ SEND_RX_WINDOW_RESIZE(I) <= '0';
+ elsif(TX_PACKET_SEQUENCE_START = '1') and (TX_TCP_STREAM_SEL(I) = '1') and (RX_BUF_FULL(I) = '1') then
+ -- not enough room in rx buffer. Sending ACK with zero-width ACK window to client I.
+ RX_WINDOW_RESIZE_STATE(I) <= "01";
+ elsif(RX_WINDOW_RESIZE_STATE(I) = "01") and (MAC_TX_EOF = '1') and (TX_TCP_STREAM_SEL(I) = '1') then
+ -- completed transmission of the ACK with TX_ACK_WINDOW_LENGTH = 0 to client I
+ RX_WINDOW_RESIZE_STATE(I) <= "10";
+ elsif (RX_WINDOW_RESIZE_STATE(I) = "10") and (RX_BUF_FULL(I) = '0') then
+ -- Receive buffer has room for another segment.
+ -- time to send unsollicited ACKs to indicate window resizing. The receive window is no
+ -- longer empty, the clients are on-hold due to the previous ACK with zero-width ack window.
+ RX_WINDOW_RESIZE_STATE(I) <= "00";
+ SEND_RX_WINDOW_RESIZE(I) <= '1';
+ else
+ SEND_RX_WINDOW_RESIZE(I) <= '0';
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- window resizing2 *071416
+-- set when the receive buffer available space goes very low and no further data is received (Windows OS waits 5 seconds)
+-- clear when the input receive buffer has enough room for a full MSS-size frame
+-- The objective is to avoid waiting a long time (5s) until the Windows OS decides to send data again.
+RX_WINDOW_RESIZE2_STATEx: for I in 0 to (NTCPSTREAMS-1) generate
+ RX_WINDOW_RESIZE2_STATE_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_WINDOW_RESIZE2_STATE(I) <= "00";
+ SEND_RX_WINDOW_RESIZE2(I) <= '0';
+ elsif(TX_PACKET_SEQUENCE_START = '1') and (TX_TCP_STREAM_SEL(I) = '1') and (RX_BUF_1MSSFREE(I) = '0') then
+ -- rx buffer is getting full... wait
+ RX_WINDOW_RESIZE2_STATE(I) <= "01";
+ elsif(RX_WINDOW_RESIZE2_STATE(I) = "01") and (MAC_TX_EOF = '1') and (TX_TCP_STREAM_SEL(I) = '1') then
+ -- completed transmission of the ACK to client I
+ RX_WINDOW_RESIZE2_STATE(I) <= "10";
+ elsif(RX_WINDOW_RESIZE2_STATE(I) = "10") and (TX_TCP_STREAM_SEL(I) = '1') and (RX_BUF_1MSSFREE(I) = '1') then
+ -- receive buffer now has enough space on rx buffer for a full MSS-size frame. Go back to idle
+ RX_WINDOW_RESIZE2_STATE(I) <= "00";
+ SEND_RX_WINDOW_RESIZE2(I) <= '1';
+ else
+ SEND_RX_WINDOW_RESIZE2(I) <= '0';
+ end if;
+ end if;
+ end process;
+end generate;
+
+
+-- remember the receive window upper bound RX_TCP_SEQ_NO_MAX (exclusive)
+-- to compare with follow-on RX_TCP_SEQ_NO
+RX_WINDOW_UPPER_BOUNDx: for I in 0 to (NTCPSTREAMS-1) generate
+ RX_WINDOW_UPPER_BOUND_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RX_TCP_SEQ_NO_MAX(I) <= (others => '0');
+ elsif(TX_PACKET_SEQUENCE_START = '1') and (TX_TCP_STREAM_SEL(I) = '1') then
+ -- compute the receive address ceiling when sending the sequence ack to the client.
+ RX_TCP_SEQ_NO_MAX(I) <= TX_ACK_NO(I) + TX_ACK_WINDOW_LENGTH;
+ -- design note: TX_ACK_WINDOW_LENGTH is an aggregate value showing only space in the
+ -- common rx buffer (common to all streams). TODO: change when TCP_RXBUFNDEMUX is upgrade
+ -- with individual buffers for each channel.
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- RECEIVE CODE ABOVE ^^^^^^^^^^^^^^^^^^^
+--=============================================================================================
+--=============================================================================================
+--=============================================================================================
+--=============================================================================================
+-- TRANSMIT CODE BELOW VVVVVVVVVVVVVVVVVV
+
+---------------------------------------------------
+------ Transmit EVENTS ----------------------------
+---------------------------------------------------
+
+---------------------------------------------------
+--//---- TX SEQUENCER ----------------------------
+---------------------------------------------------
+-- First, schedule a TX frame based on RX events.
+-- The decision to transmit is made here and stored in non-volatile TX_PACKET_TYPE_QUEUED() variable until
+-- the actual frame transmission can take place. This is a kind of queue to avoid conflicts.
+-- Identify the stream based on the destination tcp port for each
+-- incoming frame.
+SCHEDULE_TX_FRAME_GENx: for I in 0 to (NTCPSTREAMS-1) generate
+ SCHEDULE_TX_FRAME_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_PACKET_TYPE_QUEUED(I) <= "00"; -- undefined tx packet type
+ elsif (NEXT_TX_TCP_STREAM_SEL(I) = '1') and (RTS_local = '0') and (NEXT_TX_TCP_FRAME_QUEUED = '1') then
+ -- scheduled for transmission, clear any tx frame queued
+ TX_PACKET_TYPE_QUEUED(I) <= "00"; -- undefined tx packet type
+ elsif (TCP_STATE(I) = 0) and (RX_TCP_STREAM_SEL_D(I) = '1') and (EVENT1 = '1') then
+ -- Connection establishment. send SYN/ACK
+ TX_PACKET_TYPE_QUEUED(I) <= "01"; -- SYN/ACK, 24 bytes TCP header, no TCP payload
+ -- send MSS option with the SYN message. TCP header is thus 24 byte long.
+ elsif(CONNECTED_FLAG_local(I) = '1') and (CONNECTION_RESET(I) = '1') then
+ -- user-initiated selective connection request while connected. Send FIN.
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ elsif(CONNECTED_FLAG_local(I) = '1') and (TCP_KEEPALIVE_EN(I) = '1') and (KASTATE(I) = 0) then
+ -- failed keepalive. Automatic disconnect. Send FIN.
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ elsif (TCP_STATE(I) = 7) and (EVENTS5(I) = '1') then
+ -- received FIN after FIN. Send final ACK.
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ elsif (CONNECTED_FLAG_local(I) = '1') and (EVENTS5(I) = '1') then
+ -- client-initiated connection termination . Send ACK
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ elsif (TCP_STATE(I) = 4) and (EVENTS2(I) = '1') and (TX_FLAGS(I)(4) = '1') then
+ -- sent ACK after receiving FIN. send final FIN
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ elsif ((CONNECTED_FLAG_local(I) = '1') and (EVENTS11(I) = '1')) then
+ -- keep-alive or zero-window check: send a probe segment (zero-length, TX_SEQ_NO = RX_TCP_ACK_NO -1)
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ elsif (KA_PROBE_DET(I) = '1') then
+ -- received a keep-alive probe segment. Send ack
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ elsif (CONNECTED_FLAG_local(I) = '1') and (RX_TCP_STREAM_SEL_D(I) = '1') and (EVENT6 = '1') then
+ -- received valid segment, no segment to transmit. generate ACK only.
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ -- default length
+ elsif (CONNECTED_FLAG_local(I) = '1') and (EVENTS10(I) = '1') then
+ -- Window resizing (receive flow control), no segment to transmit. The receive buffer is no
+ -- longer empty. Send a single ACK with a non-zero window.
+ TX_PACKET_TYPE_QUEUED(I) <= "10"; -- 40-byte long ACK, 20 bytes TCP header
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- Trigger response
+-- Which stream is next? Check if any non-payload packet is queued (TX_PACKET_TYPE_QUEUED(I) /= 0)
+NEXT_TCP_TX_STREAM_INDEX_001: process(TX_PACKET_TYPE_QUEUED)
+variable TX_STREAM_NO: std_logic_vector(NTCPSTREAMS-1 downto 0);
+variable TX_FRAME_QUEUED: std_logic := '0';
+begin
+ TX_STREAM_NO := (others => '0');
+ TX_FRAME_QUEUED := '0';
+ for I in 0 to (NTCPSTREAMS-1) loop
+ if(TX_FRAME_QUEUED = '0') and (TX_PACKET_TYPE_QUEUED(I) /= "00") then
+ TX_FRAME_QUEUED := '1';
+ TX_STREAM_NO(I) := '1'; -- rephrasing 081918
+ end if;
+ end loop;
+ NEXT_TX_TCP_STREAM_SEL <= TX_STREAM_NO;
+ NEXT_TX_TCP_FRAME_QUEUED <= TX_FRAME_QUEUED;
+end process;
+
+-- decision to transmit a frame (with or without payload) is made here.
+-- TX_PACKET_TYPE is valid during transmission from the TX_PACKET_SEQUENCE_START pulse (incl)
+-- to MAC_TX_EOF (incl), undefined otherwise.
+TX_PACKET_SEQUENCE_START_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RTS_local <= '0';
+ TX_PACKET_TYPE <= (others => '0'); -- undefined
+ elsif(RTS_local = '0') then
+ -- Prevent a new packet assembly/transmission until current assembly/transmission is complete.
+ if(NEXT_TX_TCP_FRAME_QUEUED = '1') then
+ -- short (no payload data) tx packet for stream NEXT_TX_TCP_STREAM_SEL
+ RTS_local <= '1';
+ TX_PACKET_SEQUENCE_START <='1';
+ TX_TCP_STREAM_SEL <= NEXT_TX_TCP_STREAM_SEL;
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(NEXT_TX_TCP_STREAM_SEL(I) = '1') then
+ TX_PACKET_TYPE <= TX_PACKET_TYPE_QUEUED(I);
+ end if;
+ end loop;
+ elsif(EVENT8 = '1') then
+ -- long (with payload data) tx packet for stream TX_STREAM_SEL
+ RTS_local <= '1';
+ TX_PACKET_SEQUENCE_START <='1';
+ TX_TCP_STREAM_SEL <= TX_STREAM_SEL;
+ TX_PACKET_TYPE <= "11"; -- tx data packet, 20 bytes TCP header
+ end if;
+ elsif(MAC_TX_EOF = '1') then
+ -- transmit is complete.
+ RTS_local <= '0';
+ TX_PACKET_TYPE <= (others => '0');
+ else
+ TX_PACKET_SEQUENCE_START <= '0'; -- make it a one-CLK pulse
+ end if;
+ end if;
+end process;
+RTS <= RTS_local; -- tell TCP_TX
+
+
+-- send all relevant information to TCP_TX so that it can format the transmit frame
+OUTPUT_GEN: process(TX_TCP_STREAM_SEL, TX_DEST_MAC_ADDR, TX_DEST_IP_ADDR, TX_DEST_PORT_NO, TCP_LOCAL_PORTS,
+ TX_IPv4_6n, TX_SEQ_NO_OUT_local, TX_ACK_NO, TX_FLAGS)
+variable TX_DEST_MAC_ADDRv: std_logic_vector(47 downto 0);
+variable TX_DEST_IP_ADDRv: std_logic_vector(127 downto 0);
+variable TX_DEST_PORT_NOv: std_logic_vector(15 downto 0);
+variable TCP_LOCAL_PORTSv: std_logic_vector(15 downto 0);
+variable TX_IPv4_6nv: std_logic;
+variable TX_SEQ_NO_OUTv: std_logic_vector(31 downto 0);
+variable TX_ACK_NOv: std_logic_vector(31 downto 0);
+variable TX_FLAGSv: std_logic_vector(7 downto 0);
+begin
+ TX_DEST_MAC_ADDRv := (others => '0');
+ TX_DEST_IP_ADDRv := (others => '0');
+ TX_DEST_PORT_NOv := (others => '0');
+ TCP_LOCAL_PORTSv := (others => '0');
+ TX_IPv4_6nv := '0';
+ TX_SEQ_NO_OUTv := (others => '0');
+ TX_ACK_NOv := (others => '0');
+ TX_FLAGSv := (others => '0');
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(TX_TCP_STREAM_SEL(I) = '1') then
+ TX_DEST_MAC_ADDRv := TX_DEST_MAC_ADDR(I);
+ TX_DEST_IP_ADDRv := TX_DEST_IP_ADDR(I);
+ TX_DEST_PORT_NOv := TX_DEST_PORT_NO(I);
+ TCP_LOCAL_PORTSv := TCP_LOCAL_PORTS(I);
+ TX_IPv4_6nv := TX_IPv4_6n(I);
+ TX_SEQ_NO_OUTv := std_logic_vector(TX_SEQ_NO_OUT_local(I));
+ TX_ACK_NOv := std_logic_vector(TX_ACK_NO(I));
+ TX_FLAGSv := TX_FLAGS(I);
+ end if;
+ TX_DEST_MAC_ADDR_OUT <= TX_DEST_MAC_ADDRv;
+ TX_DEST_IP_ADDR_OUT <= TX_DEST_IP_ADDRv;
+ TX_DEST_PORT_NO_OUT <= TX_DEST_PORT_NOv;
+ TX_SOURCE_PORT_NO_OUT <= TCP_LOCAL_PORTSv;
+ TX_IPv4_6n_OUT <= TX_IPv4_6nv;
+ TX_SEQ_NO_OUT <= TX_SEQ_NO_OUTv;
+ TX_ACK_NO_OUT <= TX_ACK_NOv;
+ TX_FLAGS_OUT <= TX_FLAGSv;
+ end loop;
+end process;
+TX_PACKET_SEQUENCE_START_OUT <= TX_PACKET_SEQUENCE_START;
+TX_PACKET_TYPE_OUT <= TX_PACKET_TYPE;
+
+
+
+-------------------------------------------------
+---- TCP transmit flow control -------------------
+-------------------------------------------------
+-- last byte sent : TX_SEQ_NO
+-- last byte ack'd: RX_TCP_ACK_NO
+-- advertised rx window: RX_TCP_WINDOW_SIZE
+-- sent and unacknowledged: TX_SEQ_NO - RX_TCP_ACK_NO
+
+-- The next TCP tx frame size is determined by
+-- (a) the maximum packet size in the MAC (assumed 9000 payload bytes in TCP_TXBUF) or
+-- (b) the effective TCP rx window size as reported by the receive side, or
+
+-- Effective TCP rx window size = advertised TCP rx window size - unacknowledged but sent data size
+-- changes at end of tx packet (TX_EOF_D2), and upon receiving a valid ack
+-- Partial computation upon receiving a valid ACK, complete computation upon frame transmission
+-- when TX_SEQ_NO is updated.
+-- The effective TCP rx window size can be temporarily reduced by the TCP congestion window.
+
+-- The TCP congestion window starts at 2 segments (see MSS) and doubles at each valid ACK.
+EFF_RX_WINDOW_SIZE_PARTIAL_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ EFF_RX_WINDOW_SIZE_PARTIAL_local <= (others => '0');
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM <= (others => '0');
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local <= '0';
+ elsif(TCP_STATE_localrx = 0) and (EVENT1 = '1') then -- *012020
+ -- Received valid SYN from client. First time we learn about window size
+ -- Note: window size advertized by client may change at the next ACK from client
+ -- Waste no time. We can start preparing transmit frames once we send the SYNC ACK to the client.
+ -- anticipate RX_TCP_ACK_NO before we receive it.
+ EFF_RX_WINDOW_SIZE_PARTIAL_local <= ("0" & RX_TCP_WINDOW_SIZE) + TX_SEQ_NO_INIT(16 downto 0) + 1;
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL_D(I) = '1') then
+ TCP_TX_SLOW_START(I) <= '0'; -- ignore slow-start phase TEST TEST TEST
+ end if;
+ end loop;
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM <= RX_TCP_STREAM_SEL_D;
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local <= '1';
+-- elsif(TCP_STATE_localrx = 2) and (EVENT4 = '1') then
+-- -- entering the 'connected' state
+-- -- enter slow start phase: TCP congestion window starts with 2 segment. increases after each ACK
+-- -- until we reach the effective window size advertized by the receive side.
+-- EFF_RX_WINDOW_SIZE_PARTIAL_local <= unsigned(RX_TCP_ACK_NO(16 downto 0)) + 2*MSS;
+-- EFF_RX_WINDOW_SIZE_PARTIAL_STREAM <= RX_TCP_STREAM_SEL_D;
+-- EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local <= '1';
+-- for I in 0 to NTCPSTREAMS-1 loop
+-- if(RX_TCP_STREAM_SEL_D(I) = '1') then
+-- TCP_CONGESTION_WINDOW(I) <= to_unsigned(2*MSS,16); -- remember it for each stream
+-- TCP_TX_SLOW_START(I) <= '1';
+-- end if;
+-- end loop;
+ elsif(EVENT4A = '1')and (RX_TCP_WINDOW_SIZE /= 0) then
+ -- Valid ACK received for stream RX_TCP_STREAM_SEL_D (not a duplicate ACK)
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL_D(I) = '1') then
+ if(TCP_TX_SLOW_START(I) = '1') and (TCP_CONGESTION_WINDOW(I)(15) = '0') and
+ (TCP_CONGESTION_WINDOW(I)(14 downto 0) < RX_TCP_WINDOW_SIZE(15 downto 1)) then -- *072818
+ -- double the next tx frame size until we reach the effective TCP rx window size
+ EFF_RX_WINDOW_SIZE_PARTIAL_local <= ("0" & TCP_CONGESTION_WINDOW(I)(14 downto 0) & "0") + unsigned(RX_TCP_ACK_NO(16 downto 0));
+ -- remember it here
+ TCP_CONGESTION_WINDOW(I) <= TCP_CONGESTION_WINDOW(I)(14 downto 0) & "0";
+ else
+ EFF_RX_WINDOW_SIZE_PARTIAL_local <= ("0" & RX_TCP_WINDOW_SIZE) + unsigned(RX_TCP_ACK_NO(16 downto 0));
+ TCP_TX_SLOW_START(I) <= '0'; -- end of slow-start phase
+ end if;
+ end if;
+ end loop;
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM <= RX_TCP_STREAM_SEL_D;
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local <= '1';
+ -- partial computation of the effective tcp rx window size
+ elsif(EVENT4B = '1') and (RX_TCP_WINDOW_SIZE /= 0) then
+ -- Duplicate ACK for stream RX_TCP_STREAM_SEL_D. Even though the RX_TCP_ACK_NO is the same, the
+ -- RX_TCP_WINDOW_SIZE may have changed (window resizing)
+ EFF_RX_WINDOW_SIZE_PARTIAL_local <= ("0" & RX_TCP_WINDOW_SIZE) + unsigned(RX_TCP_ACK_NO(16 downto 0));
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(RX_TCP_STREAM_SEL_D(I) = '1') then
+ TCP_TX_SLOW_START(I) <= '0'; -- end of slow-start phase
+ end if;
+ end loop;
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM <= RX_TCP_STREAM_SEL_D;
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local <= '1';
+ else
+ -- ignore duplicate ACKs.
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local <= '0';
+ end if;
+ end if;
+end process;
+EFF_RX_WINDOW_SIZE_PARTIAL <= std_logic_vector(EFF_RX_WINDOW_SIZE_PARTIAL_local);
+EFF_RX_WINDOW_SIZE_PARTIAL_VALID <= EFF_RX_WINDOW_SIZE_PARTIAL_VALID_local;
+
+-- detect duplicate ACKs (an indication that at least one of our tx packet got lost/collided)
+-- keep the flag up until (a) the condition disappears, or (b) we rewind and transmit a packet
+RX_VALID_ACK_GENx: for I in 0 to (NTCPSTREAMS-1) generate
+ -- send duplicate if we have received three ACKs in a row with the same ack no.
+ -- why 3? because it is normal to receive two acks without lost packet (regular ack + window adjustment for example).
+
+ -- tell TCP_TXBUF about the last acknowledged location.
+ RX_TCP_ACK_NO_D(I) <= std_logic_vector(RX_TCP_ACK_NO_D_local(I)(16 downto 0)); -- don't need the entire 32-bits
+
+ RX_VALID_ACK_GEN_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if (TCP_STATE(I) = 0) and (RX_TCP_STREAM_SEL_D(I) = '1') and (EVENT1 = '1') then -- *012020
+ -- Connection establishment. send SYN/ACK
+ -- tell TCP_TXBUF about the expected acknowledgment to compute the free space
+ -- (otherwise spurious transmissions may occur randomly after SYNC)
+ RX_TCP_ACK_NO_D_local(I) <= TX_SEQ_NO_INIT + 1;
+ elsif(EVENTS4(I) = '1') then
+ -- rx event:
+ -- save rx ack number (RX_TCP_ACK_NO is transient)
+ RX_TCP_ACK_NO_D_local(I) <= RX_TCP_ACK_NO;
+ end if;
+ end if;
+ end process;
+
+ RX_VALID_ACK_GEN_003: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(EVENTS4(I) = '1') then
+ -- rx event:
+ -- detect duplicates
+ if(RX_TCP_ACK_NO_D_local(I)(15 downto 0) = RX_TCP_ACK_NO(15 downto 0))
+ and (RX_TCP_ACK_NO(15 downto 0) /= TX_SEQ_NO_local(I)(15 downto 0))
+ and (RX_TCP_NON_ZERO_DATA_LENGTH = '0') then -- *120918
+ -- Note: no need to compare all 31 bits of ack and sequence numbers
+ -- Ignore duplicates when already matching the expected TX_SEQ_NO_local
+ -- Ignore duplicates due to multiple received payloads while still transmitting.
+ if(DUPLICATE_RX_TCP_ACK_CNTR(I) /= 3) then
+ DUPLICATE_RX_TCP_ACK_CNTR(I) <= DUPLICATE_RX_TCP_ACK_CNTR(I) + 1; -- counts from 0 to 3
+ end if;
+ else
+ -- received new or expected ack. condition is gone.
+ DUPLICATE_RX_TCP_ACK_CNTR(I) <= "00";
+ end if;
+ elsif (TX_TCP_STREAM_SEL(I) = '1') and (TX_PACKET_SEQUENCE_START = '1') and (TX_PACKET_TYPE = "11")
+ and (TX_SEQ_NO_local(I)(15 downto 0) = RX_TCP_ACK_NO_D_local(I)(15 downto 0)) then
+ -- tx event:
+ -- started retransmitting unacknowledged data. clear flag
+ DUPLICATE_RX_TCP_ACK_CNTR(I) <= "00";
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- detect keep-alive probe segment: RX_TCP_SEQ_NO is TX_ACK_NO -1 and no data
+KA_PROBE_DET_GENx: for I in 0 to (NTCPSTREAMS-1) generate
+ KA_PROBE_DET_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if ((CONNECTED_FLAG_local(I) = '1') and (EVENTS12(I) = '1') and (RX_TCP_NON_ZERO_DATA_LENGTH = '0') and
+ (RX_TCP_SEQ_NO_INC(15 downto 0) = TX_ACK_NO(I)(15 downto 0))) then
+ KA_PROBE_DET(I) <= '1';
+ else
+ KA_PROBE_DET(I) <= '0';
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- Retransmission timeout
+-- Compute timout since we have transmitted a packet and not received any ACK with different RX_TCP_ACK_NO.
+-- See RFC 2988 Section 5: Managing the RTO timer.
+-- At this time, we do not implement the RTO max(60s) nor the backing-off algorithm for
+-- repeated timeouts.
+RX_VALID_ACK_TIMEOUT_x: for I in 0 to (NTCPSTREAMS-1) generate
+ RX_VALID_ACK_TIMEOUT_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (TCP_STATE(I) = 0) or (TX_SEQ_NO_JUMP_local(I) = '1') then
+ -- clear at start of connection
+ -- clear RETRANSMIT_FLAG when the TCP_TXBUF is informed of the pointer rewind -- *042419
+ RX_VALID_ACK_TIMOUT(I) <= (others => '0');
+ elsif(TX_TCP_STREAM_SEL(I) = '1') and (TX_PACKET_TYPE = "11") and (TX_PACKET_SEQUENCE_START = '1') then -- *062716
+ -- tx event: just (re)transmitted 1 frame with payload data. must wait for ACK
+ -- arm timer
+ if(SIMULATION = '0') then
+ if(TXRX_DELAY(I)(18 downto 7) < x"03D") then -- timeout min = 1s *061019
+ RX_VALID_ACK_TIMOUT(I) <= x"03D000";
+ else
+ RX_VALID_ACK_TIMOUT(I) <= TXRX_DELAY(I)(18 downto 0) & "00000"; -- 32* the average round-trip delay -- *042419
+ end if;
+ else
+ -- shorten rexmit during simulation -- *042419
+ RX_VALID_ACK_TIMOUT(I) <= TXRX_DELAY(I)(21 downto 0) & "00"; -- 4* the average round-trip delay
+ end if;
+ elsif(EVENTS4(I) = '1') and (RX_TCP_ACK_NO(15 downto 0) = TX_SEQ_NO_local(I)(15 downto 0)) then --*062316
+ -- rx event: received a valid ACK, all outstanding data has been acknowledged
+ -- turn off the retransmission timer.
+ RX_VALID_ACK_TIMOUT(I) <= (others => '0');
+ elsif(EVENTS4A(I) = '1') and (RX_TCP_ACK_NO(15 downto 0) /= TX_SEQ_NO_local(I)(15 downto 0)) then
+ -- rx event: received a valid ACK, not a duplicate, acknowledging new data
+ -- re-arm timer
+ if(TXRX_DELAY(I)(18 downto 7) < x"03D") then -- timeout min = 1s *060919
+ RX_VALID_ACK_TIMOUT(I) <= x"03D000";
+ else
+ RX_VALID_ACK_TIMOUT(I) <= TXRX_DELAY(I)(19 downto 0) & "0000"; -- 16* the average round-trip delay
+ end if;
+ elsif(TICK_4US = '1') and (RX_VALID_ACK_TIMOUT(I) > 1) then
+ -- otherwise, decrement until counter reaches 1 (Re-transmit condition)
+ RX_VALID_ACK_TIMOUT(I) <= RX_VALID_ACK_TIMOUT(I) -1;
+ end if;
+ end if;
+ end process;
+
+ RETRANSMIT_FLAG(I) <= '1' when (RX_VALID_ACK_TIMOUT(I) = 1) and (TX_SEQ_NO_JUMP_local(I) = '0') else '0'; -- *042419
+end generate;
+
+-- Measure round-trip delay: server -> client -> server
+-- Units: 4us
+TXRX_DELAY_x: for I in 0 to (NTCPSTREAMS-1) generate
+ TXRX_DELAY_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TXRX_DELAY_STATE(I) <= '0';
+ TXRX_DELAY_CNTR(I) <= (others => '0');
+ TXRX_DELAY(I) <= x"01E848"; -- 0.5s worst case default (leave 6 extra MSBs for xX multiplication in timeout)
+ elsif(TCP_STATE(I) = 0) then
+ -- clear the last RT delay value at the start of connection
+ TXRX_DELAY_STATE(I) <= '0';
+ TXRX_DELAY_CNTR(I) <= (others => '0');
+ TXRX_DELAY(I) <= x"01E848"; -- 0.5s worst case default (leave 6 extra MSBs for xX multiplication in timeout)
+ elsif(TXRX_DELAY_STATE(I) = '0') and (TX_PACKET_SEQUENCE_START = '1') and (TX_TCP_STREAM_SEL(I) = '1') then
+ -- regular tx event
+ TXRX_DELAY_STATE(I) <= '1';
+ -- start the stop watch
+ TXRX_DELAY_CNTR(I) <= (others => '0');
+ elsif(TXRX_DELAY_STATE(I) = '1') and (EVENTS4(I) = '1') then
+ -- received ACK
+ TXRX_DELAY_STATE(I) <= '0';
+ -- set a minimum RT delay value (here 32us)
+ if(TXRX_DELAY_CNTR(I)(19 downto 3) = 0) then
+ TXRX_DELAY(I) <= x"000008";
+ else
+ TXRX_DELAY(I) <= TXRX_DELAY_CNTR(I);
+ end if;
+ elsif(TXRX_DELAY_STATE(I) = '1') and (TICK_4US = '1') then
+ -- increment stop watch up to 0.5s max
+ if(TXRX_DELAY_CNTR(I) < x"01E848") then
+ TXRX_DELAY_CNTR(I) <= TXRX_DELAY_CNTR(I) + 1;
+ else
+ -- reached the max value of 0.5s
+ TXRX_DELAY_STATE(I) <= '0';
+ TXRX_DELAY(I) <= TXRX_DELAY_CNTR(I);
+ end if;
+ end if;
+ end if;
+ end process;
+end generate;
+
+
+--
+-------------------------------------------------
+---- Transmit data ------------------------------
+-------------------------------------------------
+-- 32-bit initial sequence number to be used at TCP connection time.
+-- This is simply a counter incremented every 4 usec.
+TCP_ISN_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ TCP_ISN_D <= TCP_ISN; -- pipelining for better timing
+
+ if(TICK_4US = '1') then
+ TCP_ISN <= TCP_ISN + 1;
+ end if;
+ end if;
+end process;
+
+-- Manage tx sequence number. Changes based on INDEPENDENT rx and tx events (we may be receiving data about stream#1
+-- while transmitting data about stream#2).
+-- To prevent deadlocks, TX_SEQ_NO should only change upon completing a frame transmission or when
+-- no data is waiting for transmission in TCP_TXBUF.
+-- We keep two sets: TX_SEQ_NO_local has memory, TX_SEQ_NO_OUT_local is for output only, generally the same as TX_SEQ_NO_local
+-- but can vary in special cases like probing (see keep-alive)
+TX_SEQ_NO_INIT_GEN: process(TCP_ISN_D)
+begin
+ if(SIMULATION = '1') then
+ -- During simulations, set the TX_SEQ_NO so that it matches Wireshark captures
+ -- (sequence number in the SYN/ACK packet)
+-- TX_SEQ_NO_INIT <= x"17a872a6";
+ TX_SEQ_NO_INIT <= x"0644F6bd";
+-- TX_SEQ_NO_INIT <= x"00000000";
+ else
+ -- use a random number (time)
+ TX_SEQ_NO_INIT <= TCP_ISN_D;
+ end if;
+end process;
+
+TX_SEQ_NO_GENx: for I in 0 to (NTCPSTREAMS-1) generate
+ -- forward information to TXBUF (to compute effective rx window size and reposition the buffer read
+ -- pointer)
+ TX_SEQ_NO(I) <= std_logic_vector(TX_SEQ_NO_local(I)(16 downto 0)); -- don't need the entire 32-bits
+
+ TX_SEQ_NO_GENx_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(RX_TCP_STREAM_SEL(I) = '1') and (TCP_STATE(I) = 0) and (EVENT1 = '1') then
+ -- Received valid SYN while in LISTEN state
+ -- Save the initial sequence number
+ TX_SEQ_NO_local(I) <= TX_SEQ_NO_INIT;
+ TX_SEQ_NO_OUT_local(I) <= TX_SEQ_NO_INIT;
+ TX_SEQ_NO_JUMP_local(I) <= '1';
+ elsif(TX_TCP_STREAM_SEL(I) = '1') and (TX_PACKET_TYPE = "11") and (TX_PACKET_SEQUENCE_START = '1') then
+ -- regular tx event:
+ -- just triggered transmission of a frame with TX_PAYLOAD_SIZE payload bytes.
+ TX_SEQ_NO_local(I) <= TX_SEQ_NO_local(I) + resize(unsigned(TX_PAYLOAD_SIZE), TX_SEQ_NO_local(I)'length);
+ TX_SEQ_NO_OUT_local(I) <= TX_SEQ_NO_local(I) + resize(unsigned(TX_PAYLOAD_SIZE), TX_SEQ_NO_local(I)'length);
+ TX_SEQ_NO_JUMP_local(I) <= '0';
+ elsif(TX_TCP_STREAM_SEL(I) = '1') and (TX_PACKET_SEQUENCE_START = '1') and ((TX_FLAGS(I)(1) = '1') or (TX_FLAGS(I)(0) = '1'))then
+ -- tx event:
+ -- SYN and FIN flags consumes a sequence number
+ -- Update sequence number upon tx completion, getting ready for comparison with the RX_TCP_ACK_NO
+ TX_SEQ_NO_local(I) <= TX_SEQ_NO_local(I) + 1;
+ TX_SEQ_NO_OUT_local(I) <= TX_SEQ_NO_local(I) + 1;
+ TX_SEQ_NO_JUMP_local(I) <= '1';
+ elsif (RETRANSMIT_FLAG(I) = '1') and (CONNECTED_FLAG_local(I) = '1') then -- NEW 11/4/11 AZ. this re-transmission scheme works only during connected state.
+ -- tx event. timeout awaiting for ACK. Rewind TX_SEQ_NO which will indirectly cause a re-transmission since
+ -- TCP_TXBUF will declare data ready to send.
+ -- Rewind tx sequence number to the last acknowledged seq no at the start of retransmission
+ TX_SEQ_NO_local(I) <= RX_TCP_ACK_NO_D_local(I);
+ TX_SEQ_NO_OUT_local(I) <= RX_TCP_ACK_NO_D_local(I);
+ TX_SEQ_NO_JUMP_local(I) <= '1';
+ elsif (EVENTS4B(I) = '1') and (DUPLICATE_RX_TCP_ACK_CNTR(I) = 2) and
+ (RX_TCP_ACK_NO_D_local(I) /= FAST_REXMIT_SEQ_NO_START(I)) and
+ (RX_TCP_ACK_NO_D_local(I) /= FAST_REXMIT_SEQ_NO_END(I)) then
+ -- rx event: received 3 duplicate acks (could be a missed packet).
+ -- Do a TCP fast retransmission (while avoiding multiple fast retransmissions starting at the same tx seq no)
+ -- Rewind tx sequence number to the last acknowledged seq no at the start of retransmission
+ -- TCP_TXBUF will declare data ready to send.
+ TX_SEQ_NO_local(I) <= RX_TCP_ACK_NO_D_local(I);
+ TX_SEQ_NO_OUT_local(I) <= RX_TCP_ACK_NO_D_local(I);
+ TX_SEQ_NO_JUMP_local(I) <= '1';
+ elsif ((CONNECTED_FLAG_local(I) = '1') and (EVENTS11(I) = '1')) then
+ -- non-tx related events
+ -- keep-alive or zero-window check: send a probe segment (zero-length, TX_SEQ_NO = RX_TCP_ACK_NO -1)
+ TX_SEQ_NO_OUT_local(I) <= RX_TCP_ACK_NO_D_local(I) - 1;
+ elsif(TX_TCP_STREAM_SEL(I) = '1') and (MAC_TX_EOF = '1') then
+ -- after transmitting a probe segment , restore the normal TX_SEQ_NO
+ TX_SEQ_NO_OUT_local(I) <= TX_SEQ_NO_local(I);
+ else
+ TX_SEQ_NO_JUMP_local(I) <= '0';
+ end if;
+ end if;
+ end process;
+
+ -- remember the last rewind tx sequence number for TCP fast retransmission
+ -- This mechanism is to avoid multiple fast retransmission at the same tx sequence number
+ -- which would otherwise occur because of propagation delay (tx keep receiving duplicate acks after a fast rexmit)
+ FAST_REXMIT_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if (EVENTS4B(I) = '1') and (DUPLICATE_RX_TCP_ACK_CNTR(I) = 2) and
+ (RX_TCP_ACK_NO_D_local(I) /= FAST_REXMIT_SEQ_NO_START(I)) and
+ (RX_TCP_ACK_NO_D_local(I) /= FAST_REXMIT_SEQ_NO_END(I)) then
+ -- TCP fast retransmit. Rewind address
+ FAST_REXMIT_SEQ_NO_START(I) <= RX_TCP_ACK_NO_D_local(I);
+ FAST_REXMIT_SEQ_NO_END(I) <= TX_SEQ_NO_local(I);
+ end if;
+ end if;
+ end process;
+
+end generate;
+TX_SEQ_NO_JUMP <= TX_SEQ_NO_JUMP_local;
+
+
+
+-- Manage tx TCP flags:
+-- (MSb) CWR Congestion Window Reduced (CWR) flag/ECE - ECN-Echo/URG/ACK/PSH/RST/SYN/FIN (LSb)
+TX_FLAGS_GENx: for I in 0 to (NTCPSTREAMS-1) generate
+ TX_FLAGS_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_FLAGS(I) <= "00000000";
+ elsif(CONNECTED_FLAG_local(I) = '1') and (CONNECTION_RESET(I) = '1') then
+ -- user-initiated selective connection request while connected. Send FIN/ACK.
+ TX_FLAGS(I) <= "00010001";
+ elsif(CONNECTED_FLAG_local(I) = '1') and (TCP_KEEPALIVE_EN(I) = '1') and (KASTATE(I) = 0) then
+ -- failed keepalive. Automatic disconnect. Send FIN/ACK.
+ TX_FLAGS(I) <= "00010001";
+ elsif (TCP_STATE(I) = 7) and (EVENTS5(I) = '1') then
+ -- received FIN after FIN. Send final ACK.
+ TX_FLAGS(I) <= "00010000";
+ elsif (CONNECTED_FLAG_local(I) = '1') and (EVENTS5(I) = '1') then
+ -- client-initiated connection termination . Send ACK
+ TX_FLAGS(I) <= "00010000";
+ elsif (TCP_STATE(I) = 4) and (EVENTS2(I) = '1') and (TX_FLAGS(I)(4) = '1') then
+ -- sent ACK after receiving FIN. send final FIN/ACK
+ TX_FLAGS(I) <= "00010001";
+ elsif(TCP_STATE_localrx = 0) and (EVENT1 = '1') then
+ -- Received valid SYN while in LISTEN state
+ TX_FLAGS(I) <= "00010010"; -- SYN flag set in response
+ elsif (EVENT8 = '1') then
+ -- CONNECTED state(implied in EVENT8). send or re-send data. set PUSH flag
+ TX_FLAGS(I) <= "00011000"; -- flags in response
+ elsif (TCP_STATE_localrx = 3) and ((EVENTS5(I) = '1') or (EVENT6 = '1') or (EVENTS10(I) = '1') or (EVENTS11(I) = '1')) then
+ -- CONNECTED state. ACK only. clear PUSH flag
+ TX_FLAGS(I) <= "00010000"; -- flags in response
+ elsif(TCP_STATE_localrx = 4) and (EVENT2 = '1') then
+ -- Connection termination. Send FIN
+ TX_FLAGS(I) <= "00010001"; -- FIN/ACK flag set in response
+ elsif ((CONNECTED_FLAG_local(I) = '1') and (EVENTS11(I) = '1')) then
+ -- keep-alive or zero-window check: send a probe segment (zero-length, TX_SEQ_NO = RX_TCP_ACK_NO -1)
+ TX_FLAGS(I) <= "00000000"; -- flags in response
+ elsif (KA_PROBE_DET(I) = '1') then
+ -- received a keep-alive probe segment. Send ack
+ TX_FLAGS(I) <= "00010000"; -- flags in response
+ end if;
+ end if;
+ end process;
+end generate;
+
+--// Test Point
+-- tp_001: process(CLK)
+-- begin
+-- if rising_edge(CLK) then
+-- TP(1) <= EVENT1; -- connected
+-- TP(2) <= VALID_RX_TCP0; -- connected
+-- TP(3) <= VALID_TCP_CHECKSUM; -- connected
+-- TP(4) <= RX_TCP_FLAGS(1);
+-- TP(5) <= VALID_RX_TCP_ALL;
+-- TP(6) <= IP_RX_FRAME_VALID;
+-- TP(7) <= IP_PAYLOAD_WORD_VALID;
+-- TP(8) <= IP_PAYLOAD_WORD_COUNT(0);
+-- TP(9) <= IP_PAYLOAD_EOF_D;
+-- TP(10) <= IP_PAYLOAD_SOF;
+-- end if;
+-- end process;
+
+-- tp_001: process(CLK)
+-- begin
+-- if rising_edge(CLK) then
+-- TP(1) <= TX_PACKET_SEQUENCE_START;
+-- TP(2) <= TX_ACK_NO(0)(1);
+-- TP(3) <= RX_TCP_SEQ_NO(1);
+-- TP(4) <= IP_PAYLOAD_SOF_D;
+-- TP(6) <= TX_ACK_NO2(1);
+-- TP(7) <= TX_TCP_STREAM_SEL(0);
+-- TP(8) <= RX_EOF_D and RX_FRAME_VALID_local;
+-- TP(9) <= RX_TCP_SEQ_NO_TRACK(1);
+-- end if;
+-- end process;
+
+-- tp_002: process(CLK)
+-- begin
+-- if rising_edge(CLK) then
+-- TP(1) <= EVENTS4(0);
+-- TP(2) <= EVENTS4A(0);
+-- TP(3) <= EVENTS4B(0);
+-- TP(4) <= EVENTS4C(0);
+-- TP(6) <= RETRANSMIT_FLAG(0);
+-- if(unsigned(RX_VALID_ACK_TIMOUT(0)) = 0) then
+-- TP(7) <= '1';
+-- else
+-- TP(7) <= '0';
+-- end if;
+-- TP(8) <= TX_PACKET_SEQUENCE_START;
+-- TP(9) <= RX_VALID_ACK_TIMOUT(0)(0);
+-- end if;
+-- end process;
+
+
+ tp_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ -- GIS Edit : some signals are not available with only 1 TCP Stream
+ TP(1) <= EVENTS4B(0);
+ TP(2) <= TX_SEQ_NO_JUMP_local(0);
+ if(EVENTS4B(0) = '1') and (DUPLICATE_RX_TCP_ACK_CNTR(0) = 2) then
+ TP(3) <= '1';
+ else
+ TP(3) <= '0';
+ end if;
+ TP(4) <= RETRANSMIT_FLAG(0);
+ TP(5) <= EVENT2;
+ TP(10 downto 6) <= (others => '0');
+ end if;
+ end process;
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/tcp_tx_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/tcp_tx_10G.vhd
new file mode 100644
index 0000000..90e755f
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/tcp_tx_10G.vhd
@@ -0,0 +1,776 @@
+-------------------------------------------------------------
+-- MSS copyright 2018-2020
+-- Filename: TCP_TX_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 1
+-- Date last modified: 1/18/20
+-- Inheritance: COM-5402 (1G) TCP_TX.VHD rev2 12/10/15
+--
+-- description: Sends a TCP packet, including the IP and MAC headers. 10Gbits/s.
+-- All input information is available at the time of the transmit trigger.
+--
+-- Device utilization (MSS = 1460, IPv6_ENABLED='1')
+-- FF: 681
+-- LUT: 1331
+-- DSP48: 0
+-- 18Kb BRAM: 0
+-- BUFG: 1
+-- Minimum period: 6.408ns (Maximum Frequency: 156.055MHz) Artix7-100T -1 speed grade
+--
+-- Rev 1 1/18/20 AZ
+-- corrected bug in the TCP option field (MSS size)
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity TCP_TX_10G is
+ generic (
+ MSSv4: integer := 1460;
+ MSSv6: integer := 1440;
+ -- The Maximum Segment Size (MSS) is the largest segment of TCP data that can be transmitted.
+ -- Fixed as the Ethernet MTU (Maximum Transmission Unit) of 1500-9000 bytes - 40(IPv4) or -60(IPv6) overhead bytes
+ IPv6_ENABLED: std_logic := '1'
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ -- Must be a global clock. No BUFG instantiation within this component.
+ SYNC_RESET: in std_logic;
+ -- CLK-synchronous reset. MANDATORY!
+
+ --// CONFIGURATION PARAMETERS
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB) 0x000102030405 (LSB)
+ -- as transmitted in the Ethernet packet.
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+
+
+ --// INPUT: HEADERS
+ TX_PACKET_SEQUENCE_START: in std_logic;
+ -- 1 CLK pulse to trigger packet transmission. The decision to transmit is taken by TCP_SERVER.
+ -- From this trigger pulse to the end of frame, this component assembles and send data bytes
+ -- like clockwork.
+ -- Note that the payload data has to be ready at exactly the right time to be appended.
+
+ -- These variables MUST be fixed at the start of packet and not change until the transmit EOF.
+ -- They can change from packet to packet (internal code is entirely memoryless).
+ TX_DEST_MAC_ADDR_IN: in std_logic_vector(47 downto 0);
+ TX_DEST_IP_ADDR_IN: in std_logic_vector(127 downto 0);
+ TX_DEST_PORT_NO_IN: in std_logic_vector(15 downto 0);
+ TX_SOURCE_PORT_NO_IN: in std_logic_vector(15 downto 0);
+ TX_IPv4_6n_IN: in std_logic;
+ TX_SEQ_NO_IN: in std_logic_vector(31 downto 0);
+ TX_ACK_NO_IN: in std_logic_vector(31 downto 0);
+ TX_ACK_WINDOW_LENGTH_IN: in std_logic_vector(15 downto 0);
+ IP_ID_IN: in std_logic_vector(15 downto 0);
+ -- 16-bit IP ID, unique for each datagram. Incremented every time
+ -- an IP datagram is sent (not just for this socket).
+ TX_FLAGS_IN: in std_logic_vector(7 downto 0);
+ TX_PACKET_TYPE_IN : in std_logic_vector(1 downto 0);
+ -- 0 = undefined
+ -- 1 = SYN, no data, 24-byte header
+ -- 2 = ACK, no data, 20-byte header
+ -- 3 = payload data, 20-byte header
+
+
+ --// INPUT: EXTERNAL TX BUFFER -> TX TCP PAYLOAD
+ TX_PAYLOAD_DATA: in std_logic_vector(63 downto 0);
+ -- TCP payload data field when TX_PAYLOAD_DATA_VALID = '1'
+ TX_PAYLOAD_DATA_VALID: in std_logic_vector(7 downto 0);
+ TX_PAYLOAD_WORD_VALID: in std_logic;
+ -- delineates the TCP payload data field
+ TX_PAYLOAD_DATA_EOF: in std_logic;
+ -- End Of Frame. 1 CLK-wide pulse aligned with TX_PAYLOAD_DATA_VALID
+ TX_PAYLOAD_RTS: in std_logic;
+ -- '1' to tell TX TCP layer that the application has a packet ready to send
+ -- Must stay high at least until TX_CTS goes high, but not beyond TX_EOF.
+ TX_PAYLOAD_CTS: out std_logic;
+ -- clear to send. 2 CLK latency until 1st data byte is available at TX_PAYLOAD_DATA
+ TX_PAYLOAD_SIZE: in std_logic_vector(15 downto 0);
+ -- packet size (TCP payload data only). valid (and fixed) while TX_RTS = '1'.
+ TX_PAYLOAD_CHECKSUM: in std_logic_vector(17 downto 0);
+ -- partial TCP checksum computation. payload only, no header. bits 17:16 are the carry, add later.
+ -- valid only when TX_PAYLOAD_RTS = '1', ignore otherwise
+
+
+ --// OUTPUT: TX TCP layer -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended by MAC. Not supplied here.
+ -- Synchonous with the user-side CLK
+ MAC_TX_DATA: out std_logic_vector(63 downto 0) := (others => '0');
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID = '1'
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0) := x"00";
+ -- data valid
+ MAC_TX_EOF: out std_logic := '0';
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal, indicating room in the
+ -- MAC tx elastic buffer for a complete maximum size frame 1518B.
+ -- The user should check that this signal is high before deciding to send
+ -- sending the next frame.
+ -- Note: MAC_TX_CTS may go low while the frame is transfered in. Ignore it as space is guaranteed
+ -- at the start of frame.
+
+
+
+-- -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of TCP_TX_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+
+--//---- FREEZE INPUTS -----------------------
+signal TX_DEST_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal TX_DEST_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal TX_DEST_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal TX_SOURCE_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal TX_IPv4_6n: std_logic := '0';
+signal TX_TCP_HEADER_LENGTH: unsigned(3 downto 0) := (others => '0'); -- in 32-bit words
+--signal TX_TCP_HEADER_LENGTH_DEC: unsigned(3 downto 0) := (others => '0'); -- in 32-bit words
+signal TX_TCP_PAYLOAD_SIZE: std_logic_vector(15 downto 0) := (others => '0'); -- TCP payload size in bytes.
+signal TX_SEQ_NO: std_logic_vector(31 downto 0) := (others => '0');
+signal TX_ACK_NO: std_logic_vector(31 downto 0) := (others => '0');
+signal TX_ACK_WINDOW_LENGTH: std_logic_vector(15 downto 0) := (others => '0');
+signal IP_ID: std_logic_vector(15 downto 0) := (others => '0');
+signal TX_FLAGS: std_logic_vector(7 downto 0) := (others => '0');
+signal TX_PACKET_TYPE: unsigned(1 downto 0) := (others => '0');
+
+--// TX IP HEADER CHECKSUM ---------------------------------------------
+signal TX_PACKET_SEQUENCE_START_SHIFT: std_logic_vector(7 downto 0) := (others => '0');
+signal CKSUM_PART1: unsigned(18 downto 0) := (others => '0');
+signal CKSUM_SEQ_CNTR: unsigned(2 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM0: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM_PLUS: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM_FINAL: std_logic_vector(15 downto 0) := (others => '0');
+
+--//-- TCP TX CHECKSUM ---------------------------
+signal CKSUM4: unsigned(17 downto 0) := (others => '0');
+signal CKSUM5: unsigned(17 downto 0) := (others => '0');
+signal CKSUM6: unsigned(17 downto 0) := (others => '0');
+signal CKSUM7: unsigned(17 downto 0) := (others => '0');
+signal CKSUM8: unsigned(17 downto 0) := (others => '0');
+signal CKSUM_CARRY2: unsigned(3 downto 0) := (others => '0');
+signal CKSUM_CARRY4: unsigned(3 downto 0) := (others => '0');
+signal TCP_CHECKSUM: unsigned(15 downto 0) := (others => '0');
+
+--//---- TX PACKET ASSEMBLY ----------------------
+signal TX_PAYLOAD_CTS_FLAG: std_logic := '0';
+signal TCP_HEADER_BYTE12_13: std_logic_vector(15 downto 0) := (others => '0');
+signal TX_PAYLOAD_DATA_PREVIOUS: std_logic_vector(63 downto 0) := (others => '0');
+signal TX_PAYLOAD_DATA_VALID_PREVIOUS: std_logic_vector(7 downto 0) := (others => '0');
+signal TX_PAYLOAD_DATA_EOF_PREVIOUS: std_logic := '0';
+signal MAC_TX_CTS_D: std_logic := '0';
+signal MAC_TX_CTS_D2: std_logic := '0';
+signal TX_PAYLOAD_CTS_FLAG0: std_logic := '0';
+signal TX_ACTIVE0: std_logic := '0';
+signal TX_ACTIVE: std_logic := '0';
+signal TX_WORD_COUNTER: unsigned(10 downto 0) := (others => '0');
+signal TX_WORD_COUNTER_D: unsigned(10 downto 0) := (others => '0');
+signal MAC_TX_WORD_VALID_E2: std_logic := '0';
+signal MAC_TX_WORD_VALID_E: std_logic := '0';
+signal MAC_TX_WORD_VALID: std_logic := '0';
+
+signal MAC_TX_EOF_local: std_logic := '0';
+signal TX_TCP_LAST_HEADER_BYTE: std_logic := '0';
+signal TX_IP_LENGTH: unsigned(15 downto 0) := (others => '0');
+
+signal MAC_TX_DATA_D: std_logic_vector(7 downto 0) := (others => '0');
+
+--// TX TCP CHECKSUM ---------------------------------------------
+--signal TX_TCP_HEADER_D: std_logic := '0';
+--signal TX_TCP_CKSUM_DATA: std_logic_vector(15 downto 0) := (others => '0');
+--signal TX_TCP_CKSUM_FLAG: std_logic := '0';
+--signal TX_TCP_CHECKSUM: unsigned(16 downto 0) := (others => '0');
+--signal TX_TCP_CHECKSUM_FINAL: unsigned(15 downto 0) := (others => '0');
+signal TX_TCP_LENGTH: unsigned(15 downto 0) := (others => '0');
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--//---- FREEZE INPUTS -----------------------
+-- Latch in all key fields at the start trigger
+FREEZE_KEY_FIELDS_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(TX_PACKET_SEQUENCE_START = '1') then
+ -- Freeze parameters which can change
+ -- while we are sending the TCP packet to the MAC layer
+ TX_DEST_MAC_ADDR <= TX_DEST_MAC_ADDR_IN;
+ TX_DEST_IP_ADDR <= TX_DEST_IP_ADDR_IN;
+ TX_DEST_PORT_NO <= TX_DEST_PORT_NO_IN;
+ TX_SOURCE_PORT_NO <= TX_SOURCE_PORT_NO_IN;
+ TX_IPv4_6n <= TX_IPv4_6n_IN;
+ IP_ID <= IP_ID_IN;
+ end if;
+ end if;
+end process;
+
+FREEZE_KEY_FIELDS_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(TX_PACKET_SEQUENCE_START = '1') then
+ -- latch in key fields at start of packet assembly (they can change during packet assembly,
+ -- for example if an ACK is received).
+ TX_SEQ_NO <= TX_SEQ_NO_IN;
+ TX_ACK_NO <= TX_ACK_NO_IN;
+ TX_ACK_WINDOW_LENGTH <= TX_ACK_WINDOW_LENGTH_IN;
+ TX_FLAGS <= TX_FLAGS_IN;
+ TX_PACKET_TYPE <= unsigned(TX_PACKET_TYPE_IN);
+ if(unsigned(TX_PACKET_TYPE_IN) = 1) then
+ TX_TCP_HEADER_LENGTH <= x"6"; -- 24 bytes, includes MSS option.
+ else
+ -- default length
+ TX_TCP_HEADER_LENGTH <= x"5"; -- 20 bytes, default
+ end if;
+ if(unsigned(TX_PACKET_TYPE_IN) = 3) then
+ -- payload size from TCP_TXBUF
+ TX_TCP_PAYLOAD_SIZE <= TX_PAYLOAD_SIZE;
+ else
+ -- no payload
+ TX_TCP_PAYLOAD_SIZE <= (others => '0');
+ end if;
+ end if;
+ end if;
+end process;
+
+--//---- TX PACKET SIZE ---------------------------
+TX_PACKET_TYPE_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ TX_TCP_LENGTH <= unsigned("0000000000" & TX_TCP_HEADER_LENGTH & "00") + unsigned(TX_TCP_PAYLOAD_SIZE) ;
+ -- total TCP frame size, in bytes. Part of TCP pseudo-header needed for TCP checksum computation
+
+ -- total IP frame size, in bytes. IP header is always the standard size of 20 bytes (IPv4) or 40 bytes (IPv6)
+ -- ready at TX_PACKET_SEQUENCE_START_D3
+ if(TX_IPv4_6n = '1') then
+ TX_IP_LENGTH <= TX_TCP_LENGTH + 20;
+ else
+ TX_IP_LENGTH <= TX_TCP_LENGTH + 40;
+ end if;
+ end if;
+end process;
+
+--// IP HEADER CHECKSUM ----------------------
+-- Transmit IP packet header checksum. Only applies to IPv4 (no header checksum in IPv6)
+-- We must start the checksum early as the checksum field is not the last word in the header.
+-- perform 1's complement sum of all 16-bit words within the header.
+-- the checksum must be ready when TX_WORD_COUNTER_D=3
+---- Note: same code used in udp_tx.vhd
+
+IP_HEADER_CHECKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_HEADER_CHECKSUM0 <= ("01" & x"8406") + resize(unsigned(IPv4_ADDR(31 downto 16)),18) + resize(unsigned(IPv4_ADDR(15 downto 0)),18); -- x"4500" + x"4000" + x"FF06"
+
+ if (TX_PACKET_SEQUENCE_START = '1') and (TX_IPv4_6n_IN = '0') then
+ -- the IP header checksum applies only to IPv4
+ IP_HEADER_CHECKSUM <= (others => '0');
+ elsif (TX_PACKET_SEQUENCE_START = '1') and (TX_IPv4_6n_IN = '1') then
+ IP_HEADER_CHECKSUM <= resize(unsigned(IP_HEADER_CHECKSUM0(15 downto 0)),18) + resize(unsigned(IP_HEADER_CHECKSUM0(17 downto 16)),18) + resize(unsigned(IP_ID_IN),18);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(0) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS + resize(unsigned(TX_DEST_IP_ADDR(15 downto 0)),18);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(1) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS + resize(unsigned(TX_DEST_IP_ADDR(31 downto 16)),18);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(2) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS + resize(TX_IP_LENGTH,18);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(3) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS ;
+ end if;
+ end if;
+end process;
+IP_HEADER_CHECKSUM_PLUS <= resize(unsigned(IP_HEADER_CHECKSUM(15 downto 0)),18) + resize(unsigned(IP_HEADER_CHECKSUM(17 downto 16)),18);
+IP_HEADER_CHECKSUM_FINAL <= x"FFFF" when (IP_HEADER_CHECKSUM(16) = '1') and (IP_HEADER_CHECKSUM(0) = '0') else
+ x"FFFE" when (IP_HEADER_CHECKSUM(16) = '1') and (IP_HEADER_CHECKSUM(0) = '1') else
+ not(std_logic_vector(IP_HEADER_CHECKSUM(15 downto 0)));
+
+--//-- TCP TX CHECKSUM ---------------------------
+-- Compute the TCP payload checksum (excluding headers).
+-- Different pseudo-headers are used for IPv4 and IPv6
+
+-- for IPv6, pre-compute the IPv6 address checksum. Only once at reset.
+TCP_CKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CKSUM_SEQ_CNTR <= "110";
+ elsif(CKSUM_SEQ_CNTR > 0) then
+ CKSUM_SEQ_CNTR <= CKSUM_SEQ_CNTR - 1;
+ end if;
+ end if;
+end process;
+
+TCP_CKSUM_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ -- fixed part of the checksum is initialized at reset
+ if(SYNC_RESET = '1') then
+ CKSUM_PART1 <= resize(unsigned(IPv6_ADDR(127 downto 112)),19) + resize(unsigned(IPv6_ADDR(111 downto 96)),19);
+ elsif(CKSUM_SEQ_CNTR = "110") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(95 downto 80)),19);
+ elsif(CKSUM_SEQ_CNTR = "101") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(79 downto 64)),19);
+ elsif(CKSUM_SEQ_CNTR = "100") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(63 downto 48)),19);
+ elsif(CKSUM_SEQ_CNTR = "011") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(47 downto 32)),19);
+ elsif(CKSUM_SEQ_CNTR = "010") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(31 downto 16)),19);
+ elsif(CKSUM_SEQ_CNTR = "001") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(15 downto 0)),19);
+ end if;
+ end if;
+end process;
+
+
+
+-- Checksum computation must be complete by the time TX_WORD_COUNTER reaches 5(IPv4) or 7 (IPv6). So we only have 5 iterations maximum to sum the pseudo header.
+TCP_CKSUM_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ TX_PACKET_SEQUENCE_START_SHIFT(7 downto 0) <= TX_PACKET_SEQUENCE_START_SHIFT(6 downto 0) & TX_PACKET_SEQUENCE_START;
+
+ if(TX_PACKET_SEQUENCE_START = '1') then
+ if(unsigned(TX_PACKET_TYPE_IN) = 3) then
+ -- payload size from TCP_TXBUF
+ CKSUM4 <= resize(unsigned(TX_PAYLOAD_CHECKSUM(15 downto 0)),18) + x"0006"; -- data checksum + TCP protocol
+ elsif(unsigned(TX_PACKET_TYPE_IN) = 1) then
+ -- TCP option: MSS, no payload data
+ if(TX_IPv4_6n_IN = '1') then
+ CKSUM4 <= resize((MSSv4+ x"020A"),18); -- TCP protocol + MSS option
+ else
+ CKSUM4 <= resize((MSSv6+ x"020A"),18); -- TCP protocol + MSS option
+ end if;
+ else -- (unsigned(TX_PACKET_TYPE_IN) = 2) then
+ -- no payload data
+ CKSUM4 <= "00" & x"0006"; -- TCP protocol
+ end if;
+ CKSUM5 <= resize(unsigned(TX_SOURCE_PORT_NO_IN),18) + resize(unsigned(TX_DEST_PORT_NO_IN),18); -- src + dest ports
+ CKSUM6 <= resize(unsigned(TX_SEQ_NO_IN(31 downto 16)),18) + resize(unsigned(TX_SEQ_NO_IN(15 downto 0)),18);
+ CKSUM7 <= resize(unsigned(TX_ACK_NO_IN(31 downto 16)),18) + resize(unsigned(TX_ACK_NO_IN(15 downto 0)),18);
+ if(unsigned(TX_PACKET_TYPE_IN) = 3) then
+ -- payload size from TCP_TXBUF
+ CKSUM8 <= resize(unsigned(TX_PAYLOAD_CHECKSUM(17 downto 16)),18) ; -- carry bits
+ else
+ CKSUM8 <= (others => '0');
+ end if;
+ else
+ if(TX_IPv4_6n = '1') then -- IPv4
+ if(TX_PACKET_SEQUENCE_START_SHIFT(0) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(IPv4_ADDR(31 downto 16)),18); -- src IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(IPv4_ADDR(15 downto 0)),18); -- src IP address
+ CKSUM6 <= resize(CKSUM6(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(31 downto 16)),18); -- dest IP address
+ CKSUM7 <= resize(CKSUM7(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(15 downto 0)),18); -- dest IP address
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY4,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(1) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TCP_HEADER_BYTE12_13),18);
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_ACK_WINDOW_LENGTH),18);
+ CKSUM6 <= resize(CKSUM6(15 downto 0),18) + resize(TX_TCP_LENGTH,18); -- + TCP length
+ CKSUM7(17 downto 16) <= "00";
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY4,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(2) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM6(15 downto 0),18);
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(CKSUM7(15 downto 0),18);
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY4,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(3) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM5(15 downto 0),18);
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY2,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(4) = '1') then
+ CKSUM8 <= CKSUM8 + resize(CKSUM4(15 downto 0),18) + CKSUM4(17 downto 16);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(5) = '1') then
+ CKSUM8 <= resize(CKSUM8(15 downto 0),18) + CKSUM8(17 downto 16);
+ end if;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ if(TX_PACKET_SEQUENCE_START_SHIFT(0) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM_PART1(15 downto 0),18) ;
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(CKSUM_PART1(18 downto 16),18);
+ CKSUM6 <= resize(CKSUM6(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(127 downto 112)),18);
+ CKSUM7 <= resize(CKSUM7(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(111 downto 96)),18);
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY4,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(1) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(95 downto 80)),18); -- dest IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(79 downto 64)),18); -- dest IP address
+ CKSUM6 <= resize(CKSUM6(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(63 downto 48)),18);
+ CKSUM7 <= resize(CKSUM7(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(47 downto 32)),18);
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY4,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(2) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(31 downto 16)),18); -- dest IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(15 downto 0)),18); -- dest IP address
+ CKSUM6 <= resize(CKSUM6(15 downto 0),18) + resize(unsigned(TCP_HEADER_BYTE12_13),18);
+ CKSUM7 <= resize(CKSUM7(15 downto 0),18) + resize(unsigned(TX_ACK_WINDOW_LENGTH),18);
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY4,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(3) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(TX_TCP_LENGTH,18); -- + TCP length
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(CKSUM7(15 downto 0),18);
+ CKSUM6(17 downto 16) <= "00";
+ CKSUM7(17 downto 16) <= "00";
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY4,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(4) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM6(15 downto 0),18);
+ CKSUM5(17 downto 16) <= "00";
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY2,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(5) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM5(15 downto 0),18);
+ CKSUM8 <= CKSUM8 + resize(CKSUM_CARRY2,18); -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(6) = '1') then
+ CKSUM8 <= CKSUM8 + resize(CKSUM4(15 downto 0),18) + CKSUM4(17 downto 16);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(7) = '1') then
+ CKSUM8 <= resize(CKSUM8(15 downto 0),18) + CKSUM8(17 downto 16);
+ end if;
+ end if;
+ end if;
+ end if;
+end process;
+CKSUM_CARRY2 <= resize(CKSUM4(17 downto 16),4) + resize(CKSUM5(17 downto 16),4);
+CKSUM_CARRY4 <= resize(CKSUM4(17 downto 16),4) + resize(CKSUM5(17 downto 16),4) + resize(CKSUM6(17 downto 16),4) + resize(CKSUM7(17 downto 16),4);
+TCP_CHECKSUM <= not CKSUM8(15 downto 0);
+
+--//---- TX PACKET ASSEMBLY ---------------------
+-- Transmit packet is assembled on the fly, consistent with our design goal
+-- of minimizing storage in each TCP_SERVER component.
+-- The packet includes the lower layers, i.e. IP layer and Ethernet layer.
+--
+-- First, we tell the outsider arbitration that we are ready to send by raising RTS high.
+-- When the transmit path becomes available, the arbiter tells us to go ahead with the transmission MAC_TX_CTS = '1'
+
+STATE_MACHINE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_ACTIVE0 <= '0';
+ elsif (TX_PACKET_SEQUENCE_START = '1') then
+ TX_ACTIVE0 <= '1';
+ elsif(MAC_TX_EOF_local = '1') then
+ TX_ACTIVE0 <= '0';
+ end if;
+ end if;
+end process;
+TX_ACTIVE <= TX_ACTIVE0 and (not MAC_TX_EOF_local);
+
+TX_SCHEDULER_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+
+ if(SYNC_RESET = '1') then
+ TX_WORD_COUNTER <= (others => '1');
+ TX_WORD_COUNTER_D <= (others => '1');
+ MAC_TX_WORD_VALID_E2 <= '0';
+ MAC_TX_WORD_VALID_E <= '0';
+ else
+ MAC_TX_WORD_VALID_E <= MAC_TX_WORD_VALID_E2;
+ TX_WORD_COUNTER_D <= TX_WORD_COUNTER;
+
+ if (TX_PACKET_SEQUENCE_START = '1') then
+ TX_WORD_COUNTER <= (others => '1');
+ MAC_TX_WORD_VALID_E2 <= '0';
+ elsif(TX_ACTIVE = '1') and (MAC_TX_CTS = '1') then
+ TX_WORD_COUNTER <= TX_WORD_COUNTER + 1;
+ MAC_TX_WORD_VALID_E2 <= '1'; -- enable path to MAC
+ else
+ MAC_TX_WORD_VALID_E2 <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+TCP_HEADER_BYTE12_13(15 downto 12) <= std_logic_vector(TX_TCP_HEADER_LENGTH);
+TCP_HEADER_BYTE12_13(11 downto 8) <= "0000";
+TCP_HEADER_BYTE12_13(7 downto 0) <= TX_FLAGS;
+
+-- re-align bytes from payload data word to MAC_TX_DATA word
+WORD_ALIGN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ MAC_TX_CTS_D <= MAC_TX_CTS;
+ MAC_TX_CTS_D2 <= MAC_TX_CTS_D;
+
+ if(TX_PAYLOAD_WORD_VALID = '1') then -- = MAC_TX_CTS_D2 when there is payload data
+ TX_PAYLOAD_DATA_PREVIOUS <= TX_PAYLOAD_DATA;
+ TX_PAYLOAD_DATA_VALID_PREVIOUS <= TX_PAYLOAD_DATA_VALID;
+ TX_PAYLOAD_DATA_EOF_PREVIOUS <= TX_PAYLOAD_DATA_EOF;
+ elsif(TX_PAYLOAD_DATA_EOF_PREVIOUS = '1') and (MAC_TX_CTS_D2 = '1') then
+ TX_PAYLOAD_DATA_VALID_PREVIOUS <= x"00";
+ TX_PAYLOAD_DATA_EOF_PREVIOUS <= '0';
+ end if;
+ end if;
+end process;
+
+MAC_TX_DATA_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(TX_IPv4_6n = '1') then -- IPv4
+ case TX_WORD_COUNTER_D is
+ when "00000000000" =>
+ MAC_TX_DATA(63 downto 16) <= TX_DEST_MAC_ADDR;
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ when "00000000001" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ MAC_TX_DATA(31 downto 0) <= x"08004500";
+ when "00000000010" =>
+ MAC_TX_DATA(63 downto 48) <= std_logic_vector(TX_IP_LENGTH);
+ MAC_TX_DATA(47 downto 32) <= IP_ID;
+ MAC_TX_DATA(31 downto 0) <= x"4000FF06"; -- don't fragment, 255 hop limit, TCP
+ when "00000000011" =>
+ MAC_TX_DATA(63 downto 48) <= IP_HEADER_CHECKSUM_FINAL; -- IP header checksum
+ MAC_TX_DATA(47 downto 16) <= IPv4_ADDR; -- source IP address
+ MAC_TX_DATA(15 downto 0) <= TX_DEST_IP_ADDR(31 downto 16); -- destination IP address
+ when "00000000100" =>
+ MAC_TX_DATA(63 downto 48) <= TX_DEST_IP_ADDR(15 downto 0); -- destination IP address
+ MAC_TX_DATA(47 downto 32) <= TX_SOURCE_PORT_NO;
+ MAC_TX_DATA(31 downto 16) <= TX_DEST_PORT_NO;
+ MAC_TX_DATA(15 downto 0) <= TX_SEQ_NO(31 downto 16);
+ when "00000000101" =>
+ MAC_TX_DATA(63 downto 48) <= TX_SEQ_NO(15 downto 0);
+ MAC_TX_DATA(47 downto 16) <= TX_ACK_NO(31 downto 0); -- ack number;
+ MAC_TX_DATA(15 downto 0) <= TCP_HEADER_BYTE12_13;
+ when "00000000110" =>
+ MAC_TX_DATA(63 downto 48) <= TX_ACK_WINDOW_LENGTH;
+ MAC_TX_DATA(47 downto 32) <= std_logic_vector(TCP_CHECKSUM);
+ MAC_TX_DATA(31 downto 16) <= X"0000";
+ if(TX_PACKET_TYPE = 1) then
+ -- TCP option: MSS
+ MAC_TX_DATA(15 downto 0) <= x"0204";
+ elsif(TX_PACKET_TYPE = 3) and (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA(15 downto 0) <= TX_PAYLOAD_DATA(63 downto 48);
+ else
+ MAC_TX_DATA(15 downto 0) <= (others => '0');
+ end if;
+ when others =>
+ if(TX_WORD_COUNTER_D = 7) and (TX_PACKET_TYPE = 1) then
+ -- TCP option: MSS. No payload data
+ MAC_TX_DATA(63 downto 48) <= std_logic_vector(to_unsigned(MSSv4,16));
+ MAC_TX_DATA(47 downto 0) <= (others => '0');
+ elsif(TX_PACKET_TYPE = 3) then
+ if (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA(63 downto 16) <= TX_PAYLOAD_DATA_PREVIOUS(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= TX_PAYLOAD_DATA(63 downto 48);
+ elsif(MAC_TX_CTS_D2 = '1') and (TX_PAYLOAD_DATA_EOF_PREVIOUS = '1') and (TX_PAYLOAD_DATA_VALID_PREVIOUS(5) = '1') then
+ -- flush partial last word
+ MAC_TX_DATA(63 downto 16) <= TX_PAYLOAD_DATA_PREVIOUS(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= (others => '0');
+ end if;
+ end if;
+ end case;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ case TX_WORD_COUNTER_D is
+ when "00000000000" =>
+ MAC_TX_DATA(63 downto 16) <= TX_DEST_MAC_ADDR;
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ when "00000000001" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ MAC_TX_DATA(31 downto 0) <= x"86dd6000";
+ when "00000000010" =>
+ MAC_TX_DATA(63 downto 48) <= x"0000";
+ MAC_TX_DATA(47 downto 32) <= std_logic_vector(TX_TCP_LENGTH); -- payload length
+ MAC_TX_DATA(31 downto 16) <= x"06FF"; -- TCP, 255 hop limit
+ MAC_TX_DATA(15 downto 0) <= IPv6_ADDR(127 downto 112);
+ when "00000000011" =>
+ MAC_TX_DATA <= IPv6_ADDR(111 downto 48);
+ when "00000000100" =>
+ MAC_TX_DATA(63 downto 16) <= IPv6_ADDR(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= TX_DEST_IP_ADDR(127 downto 112);
+ when "00000000101" =>
+ MAC_TX_DATA <= TX_DEST_IP_ADDR(111 downto 48);
+ when "00000000110" =>
+ MAC_TX_DATA(63 downto 16) <= TX_DEST_IP_ADDR(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= TX_SOURCE_PORT_NO;
+ when "00000000111" =>
+ MAC_TX_DATA(63 downto 48) <= TX_DEST_PORT_NO;
+ MAC_TX_DATA(47 downto 16) <= TX_SEQ_NO(31 downto 0);
+ MAC_TX_DATA(15 downto 0) <= TX_ACK_NO(31 downto 16);
+ when "00000001000" =>
+ MAC_TX_DATA(63 downto 48) <= TX_ACK_NO(15 downto 0);
+ MAC_TX_DATA(47 downto 32) <= TCP_HEADER_BYTE12_13;
+ MAC_TX_DATA(31 downto 16) <= TX_ACK_WINDOW_LENGTH;
+ MAC_TX_DATA(15 downto 0) <= std_logic_vector(TCP_CHECKSUM);
+ when "00000001001" =>
+ MAC_TX_DATA(63 downto 48) <= x"0000";
+ if(TX_PACKET_TYPE = 1) then
+ -- TCP option: MSS
+ MAC_TX_DATA(47 downto 32) <= x"0240";
+ MAC_TX_DATA(31 downto 16) <= std_logic_vector(to_unsigned(MSSv6,16));
+ MAC_TX_DATA(15 downto 0) <= x"0000";
+ elsif(TX_PACKET_TYPE = 3) and (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA(47 downto 0) <= TX_PAYLOAD_DATA(63 downto 16);
+ else
+ MAC_TX_DATA(47 downto 0) <= (others => '0');
+ end if;
+ when others =>
+ if(TX_PACKET_TYPE = 3) then
+ if (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA(63 downto 48) <= TX_PAYLOAD_DATA_PREVIOUS(15 downto 0);
+ MAC_TX_DATA(47 downto 0) <= TX_PAYLOAD_DATA(63 downto 16);
+ elsif(MAC_TX_CTS_D2 = '1') and (TX_PAYLOAD_DATA_EOF_PREVIOUS = '1') and (TX_PAYLOAD_DATA_VALID_PREVIOUS(1) = '1') then
+ -- flush partial last word
+ MAC_TX_DATA(63 downto 48) <= TX_PAYLOAD_DATA_PREVIOUS(15 downto 0);
+ MAC_TX_DATA(47 downto 0) <= (others => '0');
+ end if;
+ end if;
+ end case;
+ end if;
+ end if;
+end process;
+
+MAC_TX_DATA_VALID_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ MAC_TX_WORD_VALID <= MAC_TX_WORD_VALID_E;
+
+ if(MAC_TX_WORD_VALID_E = '1') then
+ if(TX_IPv4_6n = '1') then -- IPv4
+ if(TX_WORD_COUNTER_D <= 5) then
+ MAC_TX_DATA_VALID <= x"FF";
+ elsif(TX_WORD_COUNTER_D = 6) then
+ if(TX_PACKET_TYPE = 1) then
+ -- TCP option: MSS
+ MAC_TX_DATA_VALID <= x"FF";
+ elsif(TX_PACKET_TYPE = 3) and (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA_VALID <="111111" & TX_PAYLOAD_DATA_VALID(7 downto 6);
+ else -- TX_PACKET_TYPE = 2
+ MAC_TX_DATA_VALID <= x"FC";
+ end if;
+ elsif(TX_WORD_COUNTER_D = 7) then
+ if(TX_PACKET_TYPE = 1) then
+ -- TCP option: MSS
+ MAC_TX_DATA_VALID <= x"C0";
+ elsif(TX_PACKET_TYPE = 3) then
+ if (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA_VALID <= TX_PAYLOAD_DATA_VALID_PREVIOUS(5 downto 0) & TX_PAYLOAD_DATA_VALID(7 downto 6);
+ elsif(MAC_TX_CTS_D2 = '1') then
+ -- flush partial last word
+ MAC_TX_DATA_VALID <= TX_PAYLOAD_DATA_VALID_PREVIOUS(5 downto 0) & "00";
+ end if;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ end if;
+ elsif(TX_PACKET_TYPE = 3) then
+ if (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA_VALID <= TX_PAYLOAD_DATA_VALID_PREVIOUS(5 downto 0) & TX_PAYLOAD_DATA_VALID(7 downto 6);
+ elsif(MAC_TX_CTS_D2 = '1') and (TX_PAYLOAD_DATA_EOF_PREVIOUS = '1') and (TX_PAYLOAD_DATA_VALID_PREVIOUS(5) = '1') then
+ -- flush partial last word
+ MAC_TX_DATA_VALID <= TX_PAYLOAD_DATA_VALID_PREVIOUS(5 downto 0) & "00";
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ end if;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ end if;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ if(TX_WORD_COUNTER_D <= 8) then
+ MAC_TX_DATA_VALID <= x"FF";
+ elsif(TX_WORD_COUNTER_D = 9) then
+ if(TX_PACKET_TYPE = 1) then
+ -- TCP option: MSS
+ MAC_TX_DATA_VALID <= x"FC";
+ elsif(TX_PACKET_TYPE = 3) and (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA_VALID <="11" & TX_PAYLOAD_DATA_VALID(7 downto 2);
+ else -- (including TX_PACKET_TYPE = 2)
+ MAC_TX_DATA_VALID <= x"C0";
+ end if;
+ elsif(TX_PACKET_TYPE = 3) then
+ if (TX_PAYLOAD_WORD_VALID = '1') then
+ MAC_TX_DATA_VALID <= TX_PAYLOAD_DATA_VALID_PREVIOUS(1 downto 0) & TX_PAYLOAD_DATA_VALID(7 downto 2);
+ elsif(MAC_TX_CTS_D2 = '1') and (TX_PAYLOAD_DATA_EOF_PREVIOUS = '1') and (TX_PAYLOAD_DATA_VALID_PREVIOUS(1) = '1') then
+ -- flush partial last word
+ MAC_TX_DATA_VALID <= TX_PAYLOAD_DATA_VALID_PREVIOUS(1 downto 0) & "000000";
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ end if;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ end if;
+ end if;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ end if;
+ end if;
+end process;
+
+MAC_TX_EOF_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_TX_EOF_local <= '0';
+ elsif(MAC_TX_WORD_VALID_E = '1') then
+ if(TX_IPv4_6n = '1') then
+ if(TX_WORD_COUNTER_D = 6) and (((TX_PAYLOAD_DATA_VALID(5) = '0') and (TX_PACKET_TYPE = 3)) or (TX_PACKET_TYPE = 2)) then
+ MAC_TX_EOF_local <= '1';
+ elsif(TX_WORD_COUNTER_D = 7) and (TX_PACKET_TYPE = 1) then
+ MAC_TX_EOF_local <= '1';
+ elsif (TX_PACKET_TYPE = 3) and (TX_WORD_COUNTER_D > 6) then
+ if (TX_PAYLOAD_WORD_VALID = '1') and (TX_PAYLOAD_DATA_VALID(5) = '0') then
+ MAC_TX_EOF_local <= '1';
+ elsif (MAC_TX_CTS_D2 = '1') and (TX_PAYLOAD_DATA_EOF_PREVIOUS = '1') and (TX_PAYLOAD_DATA_VALID_PREVIOUS(5) = '1') then
+ -- flush partial last word
+ MAC_TX_EOF_local <= '1';
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ if(TX_WORD_COUNTER_D = 9) and ((TX_PAYLOAD_DATA_VALID(1) = '0') or (TX_PACKET_TYPE = 1)) then
+ MAC_TX_EOF_local <= '1';
+ elsif (TX_PACKET_TYPE = 3) and (TX_WORD_COUNTER_D > 9) then
+ if (TX_PAYLOAD_WORD_VALID = '1') and (TX_PAYLOAD_DATA_VALID(1) = '0') then
+ MAC_TX_EOF_local <= '1';
+ elsif (MAC_TX_CTS_D2 = '1') and (TX_PAYLOAD_DATA_EOF_PREVIOUS = '1') and (TX_PAYLOAD_DATA_VALID_PREVIOUS(1) = '1') then
+ -- flush partial last word
+ MAC_TX_EOF_local <= '1';
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+-- when to ask for next word from TCP tx buffer
+TX_PAYLOAD_CTS_FLAG_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_PAYLOAD_CTS_FLAG0 <= '0';
+ elsif (TX_PACKET_SEQUENCE_START = '1') then
+ TX_PAYLOAD_CTS_FLAG0 <= '0';
+ elsif(MAC_TX_CTS = '1') and (TX_PACKET_TYPE = "11") and
+ (((TX_IPv4_6n = '1') and (TX_WORD_COUNTER = 4)) or ((IPv6_ENABLED = '1') and (TX_IPv4_6n = '0') and (TX_WORD_COUNTER = 7))) then
+ TX_PAYLOAD_CTS_FLAG0 <= '1';
+ elsif(TX_PAYLOAD_DATA_EOF = '1') then
+ -- received the last word in a frame from TCP_TXBUF
+ TX_PAYLOAD_CTS_FLAG0 <= '0';
+ end if;
+ end if;
+end process;
+TX_PAYLOAD_CTS_FLAG <= TX_PAYLOAD_CTS_FLAG0 and (not TX_PAYLOAD_DATA_EOF);
+
+-- clear to send. Ask TCP_TXBUF to send payload data
+TX_PAYLOAD_CTS <= MAC_TX_CTS and TX_PAYLOAD_CTS_FLAG;
+ -- 2 CLK latency until 1st data byte is available at TX_PAYLOAD_DATA
+ -- IPv4: first word has to arrive here when TX_WORD_COUNTER_D = 6
+ -- IPv6: first word has to arrive here when TX_WORD_COUNTER_D = 9
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/tcp_txbuf_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/tcp_txbuf_10G.vhd
new file mode 100644
index 0000000..364b23c
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/tcp_txbuf_10G.vhd
@@ -0,0 +1,1302 @@
+-------------------------------------------------------------
+-- MSS copyright 2019
+-- Filename: TCP_TXBUF_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 2
+-- Date last modified: 4/23/19
+-- Inheritance: COM-5402SOFT TCP_TXBUF.VHD 12/8/15
+--
+-- description: Buffer management for the transmit TCP payload data. 10G version.
+-- Payload data and partial checksum computation has to be ready immediately when requested by the TCP
+-- protocol engine (TCP_SERVER.vhd).
+-- This component segments the data stream into packets, raises the Ready-To-Send flag (RTS) and waits
+-- for trigger from the TCP protocol engine.
+-- The input stream is segmented into data packets. The packet transmission
+-- is triggered when one of two events occur:
+-- (a) full packet: the number of bytes waiting for transmission is greater than or equal to MSS = MTU-40 = 1460 for ethernet
+-- or, if less, the effective rx window as defined in the TCP protocol.
+-- (b) no-new-input timeout: there are a few bytes waiting for transmission but no new input
+-- bytes were received in the last 200us (or adjust constant TX_IDLE_TIMEOUT within).
+-- (c) the user application requested an immediate flush APP_DATA_FLUSH
+--
+-- The overall buffer size (which affects overall throughput) is user selected in the generic section (see ADDR_WIDTH).
+--
+-- A frame is ready for transmission when
+-- (a) the effective client rx window size is non-zero
+-- (b) the tx buffer contains either the effective client rx window size or MSS bytes or no new data received in the last 200us
+--
+-- Device utilization (NTCPSTREAMS=1, MSS = 1460, ADDR_WIDTH=11, IPv6_ENABLED='1')
+-- FF: 585
+-- LUT: 1184
+-- DSP48: 0
+-- 18Kb BRAM: 8
+-- BUFG: 1
+-- Minimum period: 5.513ns (Maximum Frequency: 181.389MHz) Artix7-100T -1 speed grade
+--
+-- Rev 1 12/11/18 AZ
+--
+-- Rev1 4/23/19 AZ
+-- Corrected sensitivity lists
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.numeric_std.ALL;
+use work.com5502pkg.all; -- defines global types, number of TCP streams, etc
+
+entity TCP_TXBUF_10G is
+ generic (
+ NTCPSTREAMS: integer := 1;
+ -- number of concurrent TCP streams handled by this component
+ MSS: integer := 1460;
+ -- The Maximum Segment Size (MSS) is the largest segment of TCP data that can be transmitted.
+ -- Fixed as the Ethernet MTU (Maximum Transmission Unit) of 1500-9000 bytes - 40(IPv4) or -60(IPv6) overhead bytes
+ -- IMPORTANT: MAKE SURE MSS is < buffer size 8*2^ADDR_WIDTH
+ ADDR_WIDTH: integer range 8 to 12:= 11;
+ -- size of the dual-port RAM buffers instantiated within for each stream = 64b * 2^ADDR_WIDTH
+ -- Trade-off buffer depth and overall TCP throughput.
+ -- IMPORTANT: current max is 12 (256 Kbits buffer per stream)
+ TX_IDLE_TIMEOUT: integer range 0 to 50:= 50;
+ -- inactive input timeout, expressed in 4us units. -- 50*4us = 200us
+ -- Controls the transmit stream segmentation: data in the elastic buffer will be transmitted if
+ -- no input is received within TX_IDLE_TIMEOUT, without waiting for the transmit frame to be filled with MSS data bytes.
+ SIMULATION: std_logic := '0'
+ -- mostly to shorten long timers during simulation
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ CLK: in std_logic; -- synchronous clock
+ -- Must be a global clocks. No BUFG instantiation within this component.
+ TICK_4US: in std_logic;
+ -- 1 CLK-wide pulse every 4us
+
+ --// APPLICATION INTERFACE -> TX BUFFER
+ -- NTCPSTREAMS can operate independently and concurrently. No scheduling arbitration needed here.
+ APP_DATA: in SLV64xNTCPSTREAMStype;
+ APP_DATA_VALID: in SLV8xNTCPSTREAMStype;
+ APP_CTS: out std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- Clear To Send = transmit flow control.
+ -- App is responsible for checking the CTS signal before sending APP_DATA
+ -- Any partial word must be left aligned (MSB first). Therefore, the only allowed valies for APP_DATA_VALID are
+ -- 0x00, 0x80, 0xc0, xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
+ APP_DATA_FLUSH: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- '1' to force the immediate transmission of any byte still in the elastic buffer.
+ -- This 1 CLK pulse can happen any time (not tied to APP_DATA_VALID)
+
+ --// TX BUFFER <-> TX TCP protocol layer
+ -- Part I: control path to/from TCP_SERVER engine
+ -- (a) TCP_SERVER sends rx window information upon receiving an ACK from the TCP client
+ -- Partial computation (rx window size + RX_TCP_ACK_NO)
+ EFF_RX_WINDOW_SIZE_PARTIAL_IN: in std_logic_vector(16 downto 0);
+ -- Explanation: EFF_RX_WINDOW_SIZE_PARTIAL_IN represents the maximum TX_SEQ_NO acceptable for the
+ -- TCP server (beyond which the rx buffers would be overflowing)
+ EFF_RX_WINDOW_SIZE_PARTIAL_STREAM: in std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+ EFF_RX_WINDOW_SIZE_PARTIAL_VALID: in std_logic; -- 1 CLK-wide pulse to indicate that the above information is valid
+ -- (b) TCP_SERVER sends location of next frame start. Warning: could rewind to an earlier location.
+ TX_SEQ_NO_IN: in SLV17xNTCPSTREAMStype;
+ TX_SEQ_NO_JUMP: in std_logic_vector(NTCPSTREAMS-1 downto 0);
+ -- TX_SEQ_NO progresses regularly as new bytes are being transmitted, except when TX_SEQ_NO_JUMP(I) = '1'
+ -- (c) for tx flow-control purposes, last acknowledged tx byte location
+ -- Units: bytes
+ RX_TCP_ACK_NO_D: in SLV17xNTCPSTREAMStype;
+ -- Units: bytes
+
+ -- (d) TCP_SERVER reports about TCP connection state.
+ -- '1' when TCP-IP connection is in the 'connected' state, 0 otherwise
+ -- Do not store tx data until a connection is established
+ CONNECTED_FLAG: in std_logic_vector((NTCPSTREAMS-1) downto 0);
+ -- (e) upon reaching TCP_TX_STATE = 2, tell the TCP protocol engine (TCP_SERVER)
+ -- which stream is ready to send data next, i.e. meets the following criteria:
+ -- (1) MSS bytes, or a lower size that meets the client effective rx window size, ready to send, OR
+ -- (2) some data to be sent but no additional data received in the last 200us
+ TX_STREAM_SEL: out std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+ -- valid only when TX_PAYLOAD_RTS = '1', ignore otherwise
+ TX_PAYLOAD_RTS: out std_logic;
+ -- '1' when at least one stream has payload data available for transmission.
+ TX_PAYLOAD_CHECKSUM: out std_logic_vector(17 downto 0) := (others => '0');
+ -- partial TCP checksum computation. payload only, no header. bits 17:16 are the carry, add later.
+ -- valid only when TX_PAYLOAD_RTS = '1', ignore otherwise
+ TX_PAYLOAD_SIZE: out std_logic_vector(15 downto 0) := (others => '0');
+ -- payload size in bytes for the next tx frame
+ -- valid only when TX_PAYLOAD_RTS = '1', ignore otherwise
+ -- range is 0 - MSS
+
+ -- Part II: data path to TCP_TX for frame formatting
+ TX_PAYLOAD_CTS: in std_logic;
+ -- clear to send payload data: go ahead signal for forwarding data from the TX_STREAM_SEL stream
+ -- to the TCP_TX component responsible for formatting the next transmit packet.
+ -- 2 CLK latency until 1st data byte is available at TX_PAYLOAD_DATA
+ -- The last CTS pulse does not trigger a TX_PAYLOAD_DATA_VALID (OBUF=0), thus marking the end of frame.
+ TX_PAYLOAD_DATA: out std_logic_vector(63 downto 0);
+ -- TCP payload data field when TX_PAYLOAD_DATA_VALID = '1'
+ TX_PAYLOAD_DATA_VALID: out std_logic_vector(7 downto 0);
+ TX_PAYLOAD_WORD_VALID: out std_logic;
+ -- delineates the TCP payload data field
+ TX_PAYLOAD_DATA_EOF: out std_logic;
+ -- End Of Frame. 1 CLK-wide pulse aligned with TX_PAYLOAD_DATA_VALID
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of TCP_TXBUF_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+ */
+ component tdp_ram is
+ generic (
+ ADDR_WIDTH : natural;
+ DATA_WIDTH : integer);
+ port (
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic := '1';
+ enb : in std_logic := '1';
+ wea : in std_logic;
+ web : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dib : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ doa : out std_logic_vector(DATA_WIDTH-1 downto 0);
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0));
+ end component tdp_ram;
+
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+
+--//-- INPUT IDLE DETECTION ---------------------------
+type CNTRtype is array (integer range 0 to (NTCPSTREAMS-1)) of integer range 0 to 50;
+signal TX_IDLE_TIMER: CNTRtype := (others => TX_IDLE_TIMEOUT);
+signal TX_IDLE: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+
+--//-- ELASTIC BUFFER ---------------------------
+signal APP_WORD_VALID: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal APP_WORD_VALID_D: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal APP_DATA_FLUSH_PENDING: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal APP_DATA_FLUSH_PENDING_D: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal APP_DATA_SHIFT: SLV128xNTCPSTREAMStype := (others => (others => '0'));
+signal APP_DATA_VALID1: SLV16xNTCPSTREAMStype := (others => (others => '0'));
+signal DIA: SLV64xNTCPSTREAMStype := (others => (others => '0'));
+signal DOB: SLV64xNTCPSTREAMStype := (others => (others => '0'));
+type PTRtype is array (integer range 0 to (NTCPSTREAMS-1)) of unsigned(ADDR_WIDTH+2 downto 0);
+signal WPTR: U17xNTCPSTREAMStype := (others => (others => '0'));
+signal WPTR_D: U17xNTCPSTREAMStype := (others => (others => '0'));
+signal RPTR: PTRtype := (others => (others => '0'));
+signal RPTR_MAX: unsigned(ADDR_WIDTH+2 downto 0) := (others => '0');
+signal RPTR_BEYOND_UPPER_LIMIT: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+type SIZEtype is array (integer range 0 to (NTCPSTREAMS-1)) of unsigned(ADDR_WIDTH+3 downto 0);
+ -- extend one bit to make signed signals
+signal BUF_SIZE: SIZEtype := (others => (others => '0'));
+signal NEXT_TX_FRAME_SIZE: PTRtype := (others => (others => '0'));
+signal AVAILABLE_BUF_SPACE: PTRtype := (others => (others => '0'));
+signal WEA: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal APP_CTS_local: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal CONNECTED_FLAG_D: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal CONNECTED_FLAG_D2: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+
+--// SEGMENT INPUT DATA INTO PACKETS
+signal SAMPLE2_CLK: std_logic := '0';
+signal SAMPLE2_CLK_D: std_logic := '0';
+signal DATA2: std_logic_vector(63 downto 0) := (others => '0');
+signal DATA2_SHIFT: std_logic_vector(127 downto 0) := (others => '0');
+signal BYTE_OFFSET2: unsigned(2 downto 0) := (others => '0');
+signal FRAME_SIZE2: unsigned(ADDR_WIDTH+2 downto 0):= (others => '0');
+signal WORD_CNTR2: unsigned(ADDR_WIDTH-1 downto 0):= (others => '0');
+signal DATA3: std_logic_vector(63 downto 0) := (others => '0');
+signal DATA3_VALID: std_logic_vector(7 downto 0) := (others => '0');
+signal DATA3_WORD_VALID: std_logic := '0';
+signal DATA3_WORD_VALID_D: std_logic := '0';
+signal TX_PAYLOAD_DATA_local: std_logic_vector(7 downto 0) := x"00";
+
+--// TCP_SERVER INTERFACE ------------------------
+signal EFF_RX_WINDOW_SIZE: U17xNTCPSTREAMStype := (others => (others => '0'));
+signal EFF_RX_WINDOW_SIZE_MSB: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EFF_RX_WINDOW_SIZE_PARTIAL: U17xNTCPSTREAMStype := (others => (others => '0'));
+signal TX_SEQ_NO: U17xNTCPSTREAMStype := (others => (others => '0'));
+
+--// TCP TX CHECKSUM ---------------------------
+signal CKSUM1: unsigned(17 downto 0):= (others => '0');
+signal CKSUM2: unsigned(17 downto 0):= (others => '0');
+signal CKSUM3: unsigned(17 downto 0):= (others => '0');
+signal CKSUM3PLUS: unsigned(17 downto 0):= (others => '0');
+signal TCP_CKSUM: unsigned(17 downto 0):= (others => '0');
+
+--// OUTPUT BUFFER --------------------------------
+signal OB_WEA: std_logic := '0';
+signal OB_ADDRA: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal OB_ADDRB: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WPTR_END: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal OBUF_SIZE: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal OBUF_SIZE_ZERO: std_logic := '0';
+signal OB_SAMPLE_CLK_E: std_logic := '0';
+signal OB_SAMPLE_CLK: std_logic := '0';
+signal OB_DIA: std_logic_vector(71 downto 0) := (others => '0');
+signal OB_DOB: std_logic_vector(71 downto 0) := (others => '0');
+signal TX_STREAM_SEL_local: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal TX_STREAM_SEL_local0: std_logic_vector((NTCPSTREAMS-1) downto 0):= (others => '0');
+signal TX_PAYLOAD_CHECKSUM0: std_logic_vector(17 downto 0) := (others => '0');
+signal TX_PAYLOAD_SIZE0: std_logic_vector(15 downto 0) := (others => '0');
+
+signal OUTPUT_STREAM_CONNECTED: std_logic := '0';
+
+--// TCP TX STATE MACHINE ---------------------------
+signal EVENTS0A: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS0B: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS0C: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS0D: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS0E: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS1A: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS1B: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS1: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS2: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS3: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENTS5: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal EVENT4: std_logic := '0';
+signal EVENT5: std_logic := '0';
+type STATEtype is array (integer range 0 to (NTCPSTREAMS-1)) of integer range 0 to 3;
+signal TCP_TX_STATE: STATEtype;
+type CNTR2type is array (integer range 0 to (NTCPSTREAMS-1)) of integer range 0 to 3;
+signal TIMER1: CNTR2type := (others => 0);
+
+--// CHECKSUM STATE MACHINE -------------------------
+signal CKSUM_STATE: integer range 0 to 3 := 0;
+signal CKSUM_STREAM_SEL: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal CKSUM_STREAM_SEL2: std_logic_vector((NTCPSTREAMS-1) downto 0) := (others => '0');
+signal CKSUM_START_TRIGGER: std_logic := '0';
+
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// SEGMENT INPUT DATA INTO PACKETS -----------------
+
+-- Raise a flag when no new Tx data is received in the last 200 us.
+-- Keep track for each stream.
+TX_IDLE_GENx: FOR I in 0 to (NTCPSTREAMS-1) generate
+ TX_IDLE_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (CONNECTED_FLAG(I) = '0') then
+ if(SIMULATION = '1') then
+ TX_IDLE_TIMER(I) <= 2; -- shortened timeout during simulation
+ else
+ TX_IDLE_TIMER(I) <= TX_IDLE_TIMEOUT;
+ end if;
+ elsif(APP_DATA_VALID(I) /= x"00") then
+ -- new transmit data, re-arm timer
+ if(SIMULATION = '1') then
+ TX_IDLE_TIMER(I) <= 2; -- shortened timeout during simulation
+ else
+ TX_IDLE_TIMER(I) <= TX_IDLE_TIMEOUT;
+ end if;
+ elsif(TICK_4US = '1') and (TX_IDLE_TIMER(I) /= 0) then
+ -- otherwise, decrement until counter reaches 0 (TX_IDLE condition)
+ TX_IDLE_TIMER(I) <= TX_IDLE_TIMER(I) -1;
+ end if;
+ end if;
+ end process;
+
+ TX_IDLE(I) <= '1' when (TX_IDLE_TIMER(I) = 0) and (APP_DATA_VALID(I) = x"00") else '0';
+end generate;
+
+--//-- INPUT ELASTIC BUFFER ---------------------------
+process(APP_DATA_VALID)
+begin
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(APP_DATA_VALID(I) /= x"00") then
+ APP_WORD_VALID(I) <= '1';
+ else
+ APP_WORD_VALID(I) <= '0';
+ end if;
+ end loop;
+end process;
+
+-- shift input word depending on the next write byte address WPTRA(2 downto 0)
+-- ready at RX_DATA_VALID_D2
+SHIFT_APP_DATA_IN_00X: for I in 0 to (NTCPSTREAMS-1) generate
+ SHIFT_APP_DATA_IN_001:process(CLK)
+ begin
+ if rising_edge(CLK) then
+ APP_WORD_VALID_D(I) <= APP_WORD_VALID(I);
+
+ if(CONNECTED_FLAG(I) = '0') then
+ -- on hold until WPTR is initialized
+ APP_DATA_VALID1(I) <= (others => '0');
+ WEA(I) <= '0';
+ elsif(APP_WORD_VALID(I) = '1') then
+ -- write shifted input
+ -- write a complete or partial word, or re-write (at the same location) if the previous word was incomplete
+ WEA(I) <= '1';
+
+ -- APP_DATA_VALID1 aligned with WEA and WPTR_D
+ case(WPTR(I)(2 downto 0)) is
+ when "000" => APP_DATA_VALID1(I) <= APP_DATA_VALID(I) & "00000000";
+ when "001" => APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(15 downto 15) & APP_DATA_VALID(I) & "0000000";
+ when "010" => APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(15 downto 14) & APP_DATA_VALID(I) & "000000";
+ when "011" => APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(15 downto 13) & APP_DATA_VALID(I) & "00000";
+ when "100" => APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(15 downto 12) & APP_DATA_VALID(I) & "0000";
+ when "101" => APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(15 downto 11) & APP_DATA_VALID(I) & "000";
+ when "110" => APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(15 downto 10) & APP_DATA_VALID(I) & "00";
+ when others => APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(15 downto 9) & APP_DATA_VALID(I) & "0";
+ end case;
+
+
+ --if(APP_DATA_VALID1(I)(8) = '1') then
+ if(WPTR_D(I)(3) /= WPTR(I)(3)) then
+ -- last write to memory was a full 64-bit word. Shift remainder by 8-bytes
+ -- Algo: this is when WPTR(3) toggles
+ case(WPTR(I)(2 downto 0)) is
+ when "000" => APP_DATA_SHIFT(I) <= APP_DATA(I) & x"0000000000000000";
+ when "001" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 56) & APP_DATA(I) & x"00000000000000";
+ when "010" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 48) & APP_DATA(I) & x"000000000000";
+ when "011" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 40) & APP_DATA(I) & x"0000000000";
+ when "100" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 32) & APP_DATA(I) & x"00000000";
+ when "101" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 24) & APP_DATA(I) & x"000000";
+ when "110" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 16) & APP_DATA(I) & x"0000";
+ when others => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 8) & APP_DATA(I) & x"00";
+ end case;
+ else
+ -- last write to memory was a partial < 8 byte word. Do not shift remainder
+ case(WPTR(I)(2 downto 0)) is
+ when "000" => APP_DATA_SHIFT(I) <= APP_DATA(I) & x"0000000000000000";
+ when "001" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(127 downto 120) & APP_DATA(I) & x"00000000000000";
+ when "010" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(127 downto 112) & APP_DATA(I) & x"000000000000";
+ when "011" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(127 downto 104) & APP_DATA(I) & x"0000000000";
+ when "100" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(127 downto 96) & APP_DATA(I) & x"00000000";
+ when "101" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(127 downto 88) & APP_DATA(I) & x"000000";
+ when "110" => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(127 downto 80) & APP_DATA(I) & x"0000";
+ when others => APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(127 downto 72) & APP_DATA(I) & x"00";
+ end case;
+ end if;
+ elsif(APP_WORD_VALID_D(I) = '1') and (APP_DATA_VALID1(I)(7) = '1' )then
+ -- additional write for left-over bits
+ APP_DATA_SHIFT(I) <= APP_DATA_SHIFT(I)(63 downto 0) & x"0000000000000000";
+ APP_DATA_VALID1(I) <= APP_DATA_VALID1(I)(7 downto 0) & x"00";
+ WEA(I) <= '1';
+ else
+ WEA(I) <= '0';
+ end if;
+ end if;
+ end process;
+
+ -- remember if a flush is pending
+ FLUSH_PENDING_001:process(CLK)
+ begin
+ if rising_edge(CLK) then
+ APP_DATA_FLUSH_PENDING_D(I) <= APP_DATA_FLUSH_PENDING(I); -- need extra clock until BUF_SIZE includes the latest word
+
+ if(APP_DATA_FLUSH(I) = '1') then
+ APP_DATA_FLUSH_PENDING(I) <= '1';
+ elsif(EVENTS1(I) = '1') then
+ -- decision to transmit is made. clear flush_pending
+ APP_DATA_FLUSH_PENDING(I) <= '0';
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- write pointer management. One for each stream.
+-- Definition: next memory location to be written to.
+WPTR_GENx: FOR I in 0 to (NTCPSTREAMS-1) generate
+ WPTR_GEN_001: process(CLK, APP_DATA_VALID)
+ variable WPTR_INCREMENT: integer range 0 to 8;
+ begin
+ if(APP_DATA_VALID(I)(0) = '1') then
+ WPTR_INCREMENT := 8;
+ elsif(APP_DATA_VALID(I)(1) = '1') then
+ WPTR_INCREMENT := 7;
+ elsif(APP_DATA_VALID(I)(2) = '1') then
+ WPTR_INCREMENT := 6;
+ elsif(APP_DATA_VALID(I)(3) = '1') then
+ WPTR_INCREMENT := 5;
+ elsif(APP_DATA_VALID(I)(4) = '1') then
+ WPTR_INCREMENT := 4;
+ elsif(APP_DATA_VALID(I)(5) = '1') then
+ WPTR_INCREMENT := 3;
+ elsif(APP_DATA_VALID(I)(6) = '1') then
+ WPTR_INCREMENT := 2;
+ elsif(APP_DATA_VALID(I)(7) = '1') then
+ WPTR_INCREMENT := 1;
+ else
+ WPTR_INCREMENT := 0;
+ end if;
+
+ if rising_edge(CLK) then
+ WPTR_D(I) <= WPTR(I);
+
+ if(CONNECTED_FLAG(I) = '0') then
+ -- near and up to the start of connection. TX_SEQ_NO_IN is ready to be read.
+ -- Pre-position the write and read memory pointers so that the addresses are consistent with the
+ -- TCP sequence numbers (which start with a random initial sequence number upon establishing a TCP connection).
+ WPTR(I) <= unsigned(TX_SEQ_NO_IN(I)); -- units: bytes
+ elsif(APP_WORD_VALID(I) = '1') then
+ WPTR(I) <= WPTR(I) + WPTR_INCREMENT;
+ end if;
+ end if;
+ end process;
+
+
+end generate;
+
+BRAM_DP2_X: for I in 0 to (NTCPSTREAMS-1) generate
+ DIA(I) <= APP_DATA_SHIFT(I)(127 downto 64);
+-- BRAM size is determined by ADDR_WIDTH
+ -- GIS Edit : replaced the memory model with one compatible with Intel devices
+ /*
+ BRAM_DP2_001: BRAM_DP2
+ GENERIC MAP(
+ DATA_WIDTHA => 64,
+ ADDR_WIDTHA => ADDR_WIDTH)
+ PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA(I), -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR_D(I)(ADDR_WIDTH+2 downto 3)),
+ DIA => DIA(I), -- Port A Data Input
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR(I)(ADDR_WIDTH+2 downto 3)), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ OEB => '1',
+ DOB => DOB(I) -- Port B Data Output
+ );
+ */
+ BRAM_DP2_001: TDP_RAM
+ GENERIC MAP(
+ DATA_WIDTH => 64,
+ ADDR_WIDTH => ADDR_WIDTH)
+ PORT MAP(
+ CLKA => CLK,
+ WEA => WEA(I), -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR_D(I)(ADDR_WIDTH+2 downto 3)),
+ DIA => DIA(I), -- Port A Data Input
+ DOA => open,
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR(I)(ADDR_WIDTH+2 downto 3)), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ DOB => DOB(I)); -- Port B Data Output
+end generate;
+
+-- read pointer management
+-- Rule #1: RPTR = TX_SEQ_NO(I) at start and upon client ack timeout (TX_SEQ_NO_JUMP)
+-- Rule #2: RPTR points to the next memory location to be read
+-- Rule #3: Clear all data within the elastic buffer after closing TCP connection
+
+RPTR_GENx: FOR I in 0 to (NTCPSTREAMS-1) generate
+ RPTR_GEN_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(CONNECTED_FLAG(I) = '0') then
+ -- At the same time as we set the WPTR -> cause the occupied size to be zero.
+ RPTR(I) <= unsigned(TX_SEQ_NO_IN(I)(ADDR_WIDTH+2 downto 0)); -- units: bytes
+ else
+ if(TCP_TX_STATE(I) = 0) then
+ -- idle state. re-position the read pointer
+ RPTR(I) <= TX_SEQ_NO(I)(ADDR_WIDTH+2 downto 0);
+ elsif(TCP_TX_STATE(I) = 2) and (CKSUM_STREAM_SEL2(I) = '1')then
+ -- read a frame to the checksum computation circuit and output buffer
+ if (EVENTS3(I) = '0') then
+ -- continue reading the frame
+ RPTR(I) <= RPTR(I) + 8;
+ else
+ -- completed checksum scan.
+ RPTR(I) <= RPTR_MAX; -- fine repositioning (because +8 increment is sometimes too much for the last word)
+ end if;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ -- detect the last read (actually the read attempt beyond the last valid data byte)
+ RPTR_BEYOND_UPPER_LIMIT(I) <= '1' when (RPTR(I)(ADDR_WIDTH+2 downto 3) = RPTR_MAX(ADDR_WIDTH+2 downto 3)) and (RPTR_MAX(2 downto 0) = 0) else
+ '1' when (RPTR(I)(ADDR_WIDTH+2 downto 3) = RPTR_MAX(ADDR_WIDTH+2 downto 3) + 1) else
+ '0';
+
+
+end generate;
+
+--// RE-ALIGN BUFFER OUTPUT WORDS ----------------
+-- Because we start reading the next payload words at an offset TX_SEQ_NO(I)(2 downto 0).
+
+-- One checksum computation circuit
+-- First mux streams into checksum computation
+MUX2CHECKSUM_001: process(CLK)
+variable S2_CLK: std_logic;
+begin
+ if rising_edge(CLK) then
+ S2_CLK := '0';
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(TCP_TX_STATE(I) = 2) and (EVENTS3(I) = '0') then
+ S2_CLK := '1';
+ end if;
+ end loop;
+ SAMPLE2_CLK <= S2_CLK;
+ end if;
+end process;
+
+MUX2CHECKSUM_002: process(CLK)
+variable FS2: unsigned(ADDR_WIDTH+2 downto 0);
+variable TSNO2: unsigned(ADDR_WIDTH+2 downto 0);
+begin
+ if rising_edge(CLK) then
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(EVENTS2(I) = '1') then
+ FS2 := NEXT_TX_FRAME_SIZE(I);
+ TSNO2 := TX_SEQ_NO(I)(ADDR_WIDTH+2 downto 0);
+ end if;
+ end loop;
+ if(SYNC_RESET = '1') or (unsigned(CKSUM_STREAM_SEL2) = 0) then
+ -- no checksum to compute
+ FRAME_SIZE2 <= (others => '0');
+ RPTR_MAX <= (others => '0');
+ BYTE_OFFSET2 <= (others => '0');
+ else
+ FRAME_SIZE2 <= FS2;
+ RPTR_MAX <= FS2 + TSNO2;
+ BYTE_OFFSET2 <= TSNO2(2 downto 0);
+ end if;
+ end if;
+end process;
+
+MUX2CHECKSUM_003: process(CKSUM_STREAM_SEL2, DOB)
+variable DATA2v: std_logic_vector(63 downto 0);
+begin
+ DATA2v := (others => '0');
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(CKSUM_STREAM_SEL2(I) = '1') then
+ DATA2v := DOB(I);
+ end if;
+ end loop;
+ DATA2 <= DATA2v;
+end process;
+
+SHIFT_RX_DATA_IN_001:process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(CKSUM_START_TRIGGER = '1') then
+ DATA2_SHIFT <= (others => '0');
+ elsif(SAMPLE2_CLK = '1') or (SAMPLE2_CLK_D = '1') then -- need one last shift
+ case(BYTE_OFFSET2) is
+ when "000" => DATA2_SHIFT <= DATA2_SHIFT(63 downto 0) & DATA2 ;
+ when "001" => DATA2_SHIFT <= DATA2_SHIFT(63 downto 8) & DATA2 & x"00";
+ when "010" => DATA2_SHIFT <= DATA2_SHIFT(63 downto 16) & DATA2 & x"0000";
+ when "011" => DATA2_SHIFT <= DATA2_SHIFT(63 downto 24) & DATA2 & x"000000";
+ when "100" => DATA2_SHIFT <= DATA2_SHIFT(63 downto 32) & DATA2 & x"00000000";
+ when "101" => DATA2_SHIFT <= DATA2_SHIFT(63 downto 40) & DATA2 & x"0000000000";
+ when "110" => DATA2_SHIFT <= DATA2_SHIFT(63 downto 48) & DATA2 & x"000000000000";
+ when others => DATA2_SHIFT <= DATA2_SHIFT(63 downto 56) & DATA2 & x"00000000000000";
+ end case;
+ end if;
+ end if;
+end process;
+
+-- zero unused bytes (important before checksum computation)
+DATA3_GEN: process(DATA2_SHIFT, DATA3_VALID)
+begin
+ for I in 0 to 7 loop
+ if(DATA3_VALID(I) = '1') then
+ DATA3(8*I+7 downto 8*I) <= DATA2_SHIFT(8*I+71 downto 8*I+64);
+ else
+ DATA3(8*I+7 downto 8*I) <= (others => '0');
+ end if;
+ end loop;
+end process;
+
+-- generate the DATA3_VALID
+DATA3_VALID_GEN:process(CLK)
+begin
+ if rising_edge(CLK) then
+ SAMPLE2_CLK_D <= SAMPLE2_CLK;
+
+ if(CKSUM_START_TRIGGER = '1') then
+ DATA3_VALID <= x"00";
+ WORD_CNTR2 <= (others => '0');
+ elsif(SAMPLE2_CLK_D = '1') then
+ WORD_CNTR2 <= WORD_CNTR2 + 1;
+ if(WORD_CNTR2 < FRAME_SIZE2(ADDR_WIDTH+2 downto 3)) then
+ DATA3_VALID <= x"FF";
+ elsif(WORD_CNTR2 = FRAME_SIZE2(ADDR_WIDTH+2 downto 3)) then
+ case FRAME_SIZE2(2 downto 0) is
+ when "000" => DATA3_VALID <= x"00";
+ when "001" => DATA3_VALID <= x"80";
+ when "010" => DATA3_VALID <= x"c0";
+ when "011" => DATA3_VALID <= x"e0";
+ when "100" => DATA3_VALID <= x"f0";
+ when "101" => DATA3_VALID <= x"f8";
+ when "110" => DATA3_VALID <= x"fc";
+ when others => DATA3_VALID <= x"fe";
+ end case;
+ else
+ DATA3_VALID <= x"00";
+ end if;
+ else
+ DATA3_VALID <= x"00";
+ end if;
+ end if;
+end process;
+DATA3_WORD_VALID <= '0' when (DATA3_VALID = x"00") else '1';
+
+--// TCP TX CHECKSUM ---------------------------
+-- Compute the TCP payload checksum (excluding headers which are included in the TCP_TX formatting component).
+-- for timing reasons, we limit ourselves to summing up to 3 16-bit fields per CLK
+UDP_CKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ DATA3_WORD_VALID_D <= DATA3_WORD_VALID;
+
+ if(CKSUM_START_TRIGGER = '1') then
+ CKSUM1 <= (others => '0');
+ CKSUM2 <= (others => '0');
+ CKSUM3 <= (others => '0'); -- carry
+ elsif(DATA3_WORD_VALID = '1') then
+ CKSUM3 <= CKSUM3PLUS;
+ CKSUM1 <= resize(CKSUM1(15 downto 0),18) + resize(unsigned(DATA3(63 downto 48)),18) + resize(unsigned(DATA3(47 downto 32)),18);
+ CKSUM2 <= resize(CKSUM2(15 downto 0),18) + resize(unsigned(DATA3(31 downto 16)),18) + resize(unsigned(DATA3(15 downto 0)),18);
+ end if;
+ end if;
+end process;
+CKSUM3PLUS <= CKSUM3 + resize(CKSUM1(17 downto 16),18) + resize(CKSUM2(17 downto 16),18);
+TCP_CKSUM <= resize(CKSUM1(15 downto 0),18) + resize(CKSUM2(15 downto 0),18) + CKSUM3PLUS;
+
+--// OUTPUT BUFFER --------------------------------
+OB_WEA <= DATA3_WORD_VALID;
+OB_DIA <= DATA3_VALID & DATA3;
+
+-- write pointer management
+OB_WPTR_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ OB_ADDRA <= (others => '0');
+ elsif(EVENT5 = '1') then -- *072718
+ -- disruption of current stream selected for checksum computation (server size asks to rewind)
+ OB_ADDRA <= WPTR_END; -- cancel partial output frame
+ elsif(DATA3_WORD_VALID = '1') and (CKSUM_STATE = 1) then
+ OB_ADDRA <= OB_ADDRA + 1;
+ end if;
+ end if;
+end process;
+
+--OB_001: BRAM_DP2
+--GENERIC MAP(
+-- DATA_WIDTHA => 72,
+-- ADDR_WIDTHA => ADDR_WIDTH,
+-- DATA_WIDTHB => 72,
+-- ADDR_WIDTHB => ADDR_WIDTH
+--
+--)
+--PORT MAP(
+-- CSA => '1',
+-- CLKA => CLK,
+-- WEA => OB_WEA, -- Port A Write Enable Input
+-- ADDRA => std_logic_vector(OB_ADDRA),
+-- DIA => OB_DIA, -- Port A Data Input
+-- OEA => '0',
+-- DOA => open,
+-- CSB => '1',
+-- CLKB => CLK,
+-- WEB => '0',
+-- ADDRB => std_logic_vector(OB_ADDRB), -- Port B Address Input
+-- DIB => (others => '0'), -- Port B ata Input
+-- OEB => '1',
+-- DOB => OB_DOB -- Port B Data Output
+--);
+
+-- slightly better timing when split into 3 block rams *081818
+-- GIS Edit : replaced the memory model with one compatible with Intel devices
+/*
+OB_001a: BRAM_DP2
+GENERIC MAP(
+ DATA_WIDTHA => 32,
+ ADDR_WIDTHA => ADDR_WIDTH,
+ DATA_WIDTHB => 32,
+ ADDR_WIDTHB => ADDR_WIDTH
+
+)
+PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => OB_WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(OB_ADDRA),
+ DIA => OB_DIA(31 downto 0), -- Port A Data Input
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(OB_ADDRB), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ OEB => '1',
+ DOB => OB_DOB(31 downto 0) -- Port B Data Output
+);
+OB_001b: BRAM_DP2
+GENERIC MAP(
+ DATA_WIDTHA => 32,
+ ADDR_WIDTHA => ADDR_WIDTH,
+ DATA_WIDTHB => 32,
+ ADDR_WIDTHB => ADDR_WIDTH
+
+)
+PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => OB_WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(OB_ADDRA),
+ DIA => OB_DIA(63 downto 32), -- Port A Data Input
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(OB_ADDRB), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ OEB => '1',
+ DOB => OB_DOB(63 downto 32) -- Port B Data Output
+);
+OB_001c: BRAM_DP2
+GENERIC MAP(
+ DATA_WIDTHA => 8,
+ ADDR_WIDTHA => ADDR_WIDTH,
+ DATA_WIDTHB => 8,
+ ADDR_WIDTHB => ADDR_WIDTH
+
+)
+PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => OB_WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(OB_ADDRA),
+ DIA => OB_DIA(71 downto 64), -- Port A Data Input
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(OB_ADDRB), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ OEB => '1',
+ DOB => OB_DOB(71 downto 64) -- Port B Data Output
+);
+*/
+
+OB_001a: TDP_RAM
+GENERIC MAP(
+ DATA_WIDTH => 32,
+ ADDR_WIDTH => ADDR_WIDTH)
+PORT MAP(
+ CLKA => CLK,
+ WEA => OB_WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(OB_ADDRA),
+ DIA => OB_DIA(31 downto 0), -- Port A Data Input
+ DOA => open,
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(OB_ADDRB), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ DOB => OB_DOB(31 downto 0) -- Port B Data Output
+);
+OB_001b: TDP_RAM
+GENERIC MAP(
+ DATA_WIDTH => 32,
+ ADDR_WIDTH => ADDR_WIDTH)
+PORT MAP(
+ CLKA => CLK,
+ WEA => OB_WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(OB_ADDRA),
+ DIA => OB_DIA(63 downto 32), -- Port A Data Input
+ DOA => open,
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(OB_ADDRB), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ DOB => OB_DOB(63 downto 32) -- Port B Data Output
+);
+OB_001c: TDP_RAM
+GENERIC MAP(
+ DATA_WIDTH => 8,
+ ADDR_WIDTH => ADDR_WIDTH)
+PORT MAP(
+ CLKA => CLK,
+ WEA => OB_WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(OB_ADDRA),
+ DIA => OB_DIA(71 downto 64), -- Port A Data Input
+ DOA => open,
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(OB_ADDRB), -- Port B Address Input
+ DIB => (others => '0'), -- Port B ata Input
+ DOB => OB_DOB(71 downto 64) -- Port B Data Output
+);
+
+
+
+TX_PAYLOAD_DATA <= OB_DOB(63 downto 0);
+TX_PAYLOAD_DATA_VALID <= OB_DOB(71 downto 64) when (OB_SAMPLE_CLK = '1') else (others => '0');
+TX_PAYLOAD_WORD_VALID <= OB_SAMPLE_CLK; -- '1' when TX_PAYLOAD_DATA_VALID /= 0
+TX_PAYLOAD_DATA_EOF <= OBUF_SIZE_ZERO and OB_SAMPLE_CLK;
+OBUF_SIZE <= WPTR_END + not(OB_ADDRB);
+
+-- output buffer read pointer
+OB_RPTR_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ OB_SAMPLE_CLK <= OB_SAMPLE_CLK_E;
+
+ if(SYNC_RESET = '1') then
+ OB_ADDRB <= (others => '1');
+ OB_SAMPLE_CLK_E <= '0';
+-- elsif(TX_PAYLOAD_CTS = '1') and (OBUF_SIZE /= 0) and (CKSUM_STATE /= 0) then
+-- test test test
+ elsif(TX_PAYLOAD_CTS = '1') and (OBUF_SIZE /= 0) then
+ OB_ADDRB <= OB_ADDRB + 1;
+ OB_SAMPLE_CLK_E <= '1';
+ else
+ OB_SAMPLE_CLK_E <= '0';
+ end if;
+
+ -- aligned with OB_SAMPLE_CLK
+ if(OBUF_SIZE = 0) then
+ OBUF_SIZE_ZERO <= '1';
+ else
+ OBUF_SIZE_ZERO <= '0';
+ end if;
+ end if;
+end process;
+
+
+
+
+
+--// TCP_SERVER INTERFACE ------------------------
+-- predict the next frame TX_SEQ_NO
+FREEZE_TX_SEQ_NO_x: for I in 0 to (NTCPSTREAMS - 1) generate
+ FREEZE_TX_SEQ_NO_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(TX_SEQ_NO_JUMP(I) = '1') then --*072718
+ -- force rewind. Abort any current read/checksum computation
+ -- update TCP_TX_NO after the server has reported a discontinuity (at connection time, or when the client
+ -- asks to retransmit). Update locally upon processing successive frames, unless a
+ -- discontinuity is requested.
+ TX_SEQ_NO(I) <= unsigned(TX_SEQ_NO_IN(I));
+ elsif(EVENTS3(I) = '1') then
+ -- completed reading a frame out of the memory to compute payload checksum
+ -- regular progress at the end of frame
+ TX_SEQ_NO(I) <= TX_SEQ_NO(I) + resize(FRAME_SIZE2, TX_SEQ_NO(I)'length);
+ end if;
+ end if;
+ end process;
+end generate;
+
+-- compute the Effective TCP rx window size = advertised TCP rx window size - unacknowledged but sent data size
+-- changes at end of tx frame, and upon receiving a valid ack
+EFF_RX_WINDOW_SIZE_GENx: for I in 0 to (NTCPSTREAMS - 1) generate
+ EFF_RX_WINDOW_SIZE_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(EFF_RX_WINDOW_SIZE_PARTIAL_VALID = '1') and (EFF_RX_WINDOW_SIZE_PARTIAL_STREAM(I) = '1') then
+ EFF_RX_WINDOW_SIZE_PARTIAL(I) <= unsigned(EFF_RX_WINDOW_SIZE_PARTIAL_IN);
+ end if;
+ end if;
+ end process;
+end generate;
+
+
+-- effective TCP rx window size is EFF_RX_WINDOW_SIZE_PARTIAL - TX_SEQ_NO
+-- This is the maximum number of bytes that the TCP client can accept.
+-- EFF_RX_WINDOW_SIZE is valid only up to the tx decision time (while TCP_TX_STATE = 0)
+EFF_RX_WINDOW_SIZE_GENy: for I in 0 to (NTCPSTREAMS - 1) generate
+ EFF_I_GEN: process(CLK, EFF_RX_WINDOW_SIZE)
+ begin
+ if rising_edge(CLK) then
+ if(CONNECTED_FLAG(I) = '0') then
+ EFF_RX_WINDOW_SIZE(I) <= (others => '0'); -- *121418
+ else
+ EFF_RX_WINDOW_SIZE(I) <= EFF_RX_WINDOW_SIZE_PARTIAL(I) - unsigned(TX_SEQ_NO(I));
+ end if;
+ end if;
+ EFF_RX_WINDOW_SIZE_MSB(I) <= EFF_RX_WINDOW_SIZE(I)(16);
+ -- detect if window size goes negative temporarily (can happen if the other side adjusts the rx window)
+ end process;
+end generate;
+
+--// TX EVENTS -------------------------------------
+-- has the input been idle for over 200us? see TX_IDLE
+
+-- How many bytes are waiting in the tx buffer?
+-- BUF_SIZE is valid only up to the tx decision time (while TCP_TX_STATE = 0)
+TX_BUFFER_SIZE_GENx: for I in 0 to (NTCPSTREAMS - 1) generate
+ BUF_SIZE_I_GEN: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ BUF_SIZE(I) <= WPTR(I)(ADDR_WIDTH+3 downto 0) - unsigned(TX_SEQ_NO(I)(ADDR_WIDTH+3 downto 0));
+ end if;
+ end process;
+end generate;
+
+-- Compute the next tx frame size
+-- two upper bounds for the tx frame size: MSS bytes and EFF_RX_WINDOW_SIZE
+NEXT_TX_FRAME_SIZE_GENx: for I in 0 to (NTCPSTREAMS - 1) generate
+ NEXT_TX_FRAME_SIZE_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ NEXT_TX_FRAME_SIZE(I) <= (others => '0');
+ elsif(CONNECTED_FLAG_D2(I) = '0') then
+ -- no TCP-IP connection yet, or pointer information not fully available yet. Nothing to send.
+ NEXT_TX_FRAME_SIZE(I) <= (others => '0');
+ elsif(TCP_TX_STATE(I) = 0) then
+ -- update frame size up to the tx decision time
+ -- Once the decision to transmit is taken, freeze NEXT_TX_FRAME_SIZE into FRAME_SIZE2 until the frame transmission is complete.
+ if(EVENTS0D(I) = '0') then
+ -- no space at receiving end
+ NEXT_TX_FRAME_SIZE(I) <= (others => '0');
+ elsif(EVENTS0B(I) = '0') and (EVENTS0C(I) = '0') and (BUF_SIZE(I)(ADDR_WIDTH+3) = '0') then
+ -- BUF_SIZE is positive, does not exceed MSS or the available space at the receiving end
+ NEXT_TX_FRAME_SIZE(I) <= BUF_SIZE(I)(ADDR_WIDTH+2 downto 0);
+ elsif(EVENTS0B(I) = '1') and (EVENTS0C(I) = '0') then
+ -- effective rx window size not the most stringent constraint.
+ -- maximum payload size is constrained by MSS byte ceiling
+ -- KEY ASSUMPTION: MSS is smaller than the instantiated buffer(s) address range.
+ NEXT_TX_FRAME_SIZE(I) <= to_unsigned(MSS,NEXT_TX_FRAME_SIZE(I)'length);
+ elsif(EVENTS0B(I) = '0') and (EVENTS0C(I) = '1') then
+ -- effective rx window size is the most stringent constraint.
+ NEXT_TX_FRAME_SIZE(I) <= EFF_RX_WINDOW_SIZE(I)(ADDR_WIDTH+2 downto 0);
+ elsif(EVENTS0E(I) = '1') then
+ -- effective rx window size limit
+ NEXT_TX_FRAME_SIZE(I) <= EFF_RX_WINDOW_SIZE(I)(ADDR_WIDTH+2 downto 0);
+ else
+ -- MSS limit
+ NEXT_TX_FRAME_SIZE(I) <= to_unsigned(MSS,NEXT_TX_FRAME_SIZE(I)'length);
+ end if;
+ end if;
+ end if;
+ end process;
+end generate;
+
+--// TX STATE MACHINE -------------------------------------
+-- Decision to send a packet is made here based on
+-- (a) input has been idle for more than 200 us, or
+-- (b) the packet size collected so far has reached its threshold of MSS bytes, or less if the effective
+-- rx window is smaller.
+-- (c) immediate flush request
+TCP_TX_STATE_GENx: for I in 0 to (NTCPSTREAMS - 1) generate
+ -- for timing purposes, reclock these trigger events
+ EVENTS0_I_GEN: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ -- data in buffer
+ if(BUF_SIZE(I) > 0) then
+ EVENTS0A(I) <= '1';
+ else
+ EVENTS0A(I) <= '0';
+ end if;
+
+ -- buffer size greater than MSS
+ if(BUF_SIZE(I) >= MSS) then
+ EVENTS0B(I) <= '1';
+ else
+ EVENTS0B(I) <= '0';
+ end if;
+
+ -- buffer size greater than EFF_RX_WINDOW_SIZE(I)
+ -- and EFF_RX_WINDOW_SIZE(I) is not negative (meaning zero space available at rx end)
+ if(BUF_SIZE(I) >= EFF_RX_WINDOW_SIZE(I)(ADDR_WIDTH+3 downto 0)) and (EFF_RX_WINDOW_SIZE_MSB(I) = '0') then
+ EVENTS0C(I) <= '1';
+ else
+ EVENTS0C(I) <= '0';
+ end if;
+
+ -- receiving end has space for more data
+ if(EFF_RX_WINDOW_SIZE(I) > 0) and (EFF_RX_WINDOW_SIZE_MSB(I) = '0') then
+ EVENTS0D(I) <= '1';
+ else
+ EVENTS0D(I) <= '0';
+ end if;
+
+ -- MSS greater than EFF_RX_WINDOW_SIZE(I)
+ if(EFF_RX_WINDOW_SIZE(I) < MSS) or (EFF_RX_WINDOW_SIZE_MSB(I) = '1') then
+ EVENTS0E(I) <= '1';
+ else
+ EVENTS0E(I) <= '0';
+ end if;
+
+ end if;
+ end process;
+
+ EVENTS1A(I) <= '1' when (CONNECTED_FLAG(I) = '1') and (TCP_TX_STATE(I) = 0) and (EVENTS0A(I) = '1') and
+ (EVENTS0D(I) = '1') and ((TX_IDLE(I) = '1') or (APP_DATA_FLUSH_PENDING_D(I) = '1')) else '0';
+ -- immediate flush request or no new data in 200us while data is waiting to be transmitted and rx end can accept new data.
+ -- Initiate transmission
+ EVENTS1B(I) <= '1' when (CONNECTED_FLAG(I) = '1') and (TCP_TX_STATE(I) = 0) and (EVENTS0A(I) = '1') and
+ (EVENTS0D(I) = '1') and ((EVENTS0B(I) = '1') or (EVENTS0C(I) = '1')) else '0';
+ -- enough data for a full tx frame or enough to fill the receiving end. don't wait.
+ -- Initiate transmission.
+-- old. seems uncessary
+-- EVENTS1C(I) <= '1' when (CONNECTED_FLAG(I) = '1') and (TCP_TX_STATE(I) = 0) and (EVENTS0A(I) = '1') and
+-- (EVENTS0D(I) = '1') and (APP_CTS_local(I) = '0') and (EVENTS0C(I) = '1') else '0';
+-- -- Elastic buffer is full and enough to fill the receiving end. don't wait.
+-- -- Initiate transmission.
+ EVENTS1(I) <= EVENTS1A(I) or EVENTS1B(I);
+ -- transmit decision time
+ EVENTS2(I) <= '1' when (CONNECTED_FLAG(I) = '1') and (TCP_TX_STATE(I) = 1) and (CKSUM_STREAM_SEL2(I) = '1') and (CKSUM_START_TRIGGER = '1') else '0';
+ -- start checksum computation
+ EVENTS3(I) <= '1' when (CONNECTED_FLAG(I) = '1') and (TCP_TX_STATE(I) = 2) and (CKSUM_STREAM_SEL2(I) = '1') and
+ (RPTR_BEYOND_UPPER_LIMIT(I) = '1') else '0';
+ -- completed reading a frame to the checksum computation circuit and output buffer
+
+ EVENTS5(I) <= '1' when (TX_SEQ_NO_JUMP(I) = '1') and (CKSUM_STREAM_SEL2(I) = '1') else '0';
+ -- disruption of current stream selected for checksum computation (server size asks to rewind)
+
+
+ TCP_TX_STATE_GEN_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (CONNECTED_FLAG(I) = '0') then
+ -- lost or no connection. Reset tx state machine, irrespective of the current state
+ TCP_TX_STATE(I) <= 0; -- back to idle
+ TIMER1(I) <= 0;
+ elsif(TX_SEQ_NO_JUMP(I) = '1') then --*072718
+ -- force rewind. Abort any current read/checksum computation
+ TCP_TX_STATE(I) <= 0; -- back to idle
+ TIMER1(I) <= 2; -- need one extra clock to compute BUF_SIZE
+
+ -- transmit decision time
+ elsif(EVENTS1(I) = '1') and (TIMER1(I) = 0) then
+ -- immediate flush request or no new data in 200us while data is waiting to be transmitted. Initiate transmission
+ -- or enough data for a full tx frame. don't wait. Initiate transmission.
+ TCP_TX_STATE(I) <= 1; -- awaiting checksum circuit trigger
+ elsif(EVENTS2(I) = '1') then
+ -- start checksum computation
+ TCP_TX_STATE(I) <= 2; -- reading data from the elastic buffer, computing checksum
+ elsif (EVENTS3(I) = '1') then
+ -- completed reading a frame out of the memory to compute payload checksum
+ TCP_TX_STATE(I) <= 3; -- delay until the next tx size is computed
+ TIMER1(I) <= 1; -- need one extra clock until key events are ready
+ elsif (TCP_TX_STATE(I) = 3) and (TIMER1(I) = 0) then
+ TCP_TX_STATE(I) <= 0; -- timer expired. back to idle
+ elsif(TIMER1(I) > 0) then
+ TIMER1(I) <= TIMER1(I) - 1;
+ end if;
+
+ end if;
+ end process;
+end generate;
+
+EVENT4 <= '1' when (DATA3_WORD_VALID_D = '1') and (DATA3_WORD_VALID = '0') else '0';
+ -- end of checksum computation
+
+EVENT5 <= '1' when (unsigned(EVENTS5) /= 0) else '0';
+ -- checksum computation disruption. Rewind.
+ -- disruption of current stream selected for checksum computation (server size asks to rewind)
+
+--// CHECKSUM STATE MACHINE -------------------------
+-- all streams out of the elastic buffers are multiplexed into a single checksum computation circuit based on
+-- CKSUM_STREAM_SEL. The checksum circuit state machine is below:
+CKSUM_STATE_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CKSUM_STATE <= 0;
+ CKSUM_START_TRIGGER <= '0';
+
+ elsif(EVENT5 = '1') then -- *072718
+ -- disruption of current stream selected for checksum computation (server size asks to rewind)
+ CKSUM_STATE <= 0;
+ elsif(CKSUM_STATE = 0) then
+ -- checksum circuit idle
+ -- is any stream awaiting checksum circuit trigger? If so, start computing checksum
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(CKSUM_STREAM_SEL(I) = '1') and (TCP_TX_STATE(I) = 1) and (CONNECTED_FLAG(I) = '1') then
+ -- freeze the ONE stream selected for checksum computation
+ CKSUM_STATE <= 1;
+ CKSUM_START_TRIGGER <= '1';
+ CKSUM_STREAM_SEL2 <= CKSUM_STREAM_SEL;
+ end if;
+ end loop;
+ elsif (CKSUM_STATE = 1) and (EVENT4 = '1') then
+ -- end of checksum computation
+ CKSUM_START_TRIGGER <= '0';
+ if(OBUF_SIZE /= 0) then
+ -- we are not yet done reading the previous frame. wait
+ CKSUM_STATE <= 2;
+ else
+ -- done with both checksum computation and previous frame out
+ -- we can trigger the next frame output processing
+ CKSUM_STATE <= 0;
+ WPTR_END <= OB_ADDRA; -- upper limit for next frame to be forwarded to TCP_TX
+ end if;
+ elsif (CKSUM_STATE = 2) and (OBUF_SIZE = 0) then
+ -- done with both checksum computation and previous frame out
+ -- Wait for one more word request (with no response from us) to mark the end of frame in TCP_TX_10G.vhd.
+ CKSUM_STATE <= 3;
+ elsif (CKSUM_STATE = 3) then
+ -- we can trigger the next frame output processing
+ CKSUM_STATE <= 0;
+ WPTR_END <= OB_ADDRA; -- upper limit for next frame to be forwarded to TCP_TX
+ else
+ CKSUM_START_TRIGGER <= '0';
+ -- also detect disconnection
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(CKSUM_STREAM_SEL2(I) = '1') and (CONNECTED_FLAG(I) = '0') then
+ CKSUM_STATE <= 0;
+ WPTR_END <= (others => '0');
+ CKSUM_STREAM_SEL2(I) <= '0';
+ end if;
+ end loop;
+ end if;
+ end if;
+end process;
+
+
+-- select the stream for the next checksum computation
+-- scan all possible streams until we reach TCP_TX_STATE(I) = 1 (awaiting checksum circuit trigger)
+-- THERE CAN BE ONLY ONE SINGLE STREAM SELECTED FOR THE CHECKSUM AND OUTPUT BUFFER
+NEXT_STREAM_SELECT_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CKSUM_STREAM_SEL(0) <= '1';
+ CKSUM_STREAM_SEL(CKSUM_STREAM_SEL'left downto 1) <= (others => '0');
+ elsif(NTCPSTREAMS > 1) then
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(CKSUM_STREAM_SEL(I) = '1') and ((TCP_TX_STATE(I) /= 1) or (CONNECTED_FLAG(I) = '0')) then
+ -- this stream is not awaiting checksum circuit trigger. move on.
+ -- or this stream just completed a checksum computation, back to the end of the line
+ -- circular rotation
+ CKSUM_STREAM_SEL(NTCPSTREAMS-1 downto 1) <= CKSUM_STREAM_SEL(NTCPSTREAMS-2 downto 0);
+ CKSUM_STREAM_SEL(0) <= CKSUM_STREAM_SEL(NTCPSTREAMS-1);
+ end if;
+ end loop;
+ end if;
+ end if;
+end process;
+
+-- tell the TCP_SERVER about the stream selected for the next tx frame, the partial checksum, the number of payload bytes.
+-- The information is valid when TX_PAYLOAD_RTS = '1'.
+TCP_SERVER_INFO_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_PAYLOAD_CHECKSUM <= (others => '0');
+ TX_PAYLOAD_SIZE <= (others => '0');
+ TX_STREAM_SEL_local <= (others => '0');
+ elsif (CKSUM_STATE = 1) and (EVENT4 = '1') then
+ if(OBUF_SIZE /= 0) then
+ -- we are not yet done reading the previous frame. wait
+ -- freeze info regarding the next tx frame until we are about to start next tx frame
+ TX_PAYLOAD_CHECKSUM0 <= std_logic_vector(TCP_CKSUM); -- up to 2 bits of carry
+ TX_PAYLOAD_SIZE0 <= std_logic_vector(resize(FRAME_SIZE2,16)); -- payload size in bytes
+ TX_STREAM_SEL_local0 <= CKSUM_STREAM_SEL2;
+ else
+ -- done with checksum computation. Previous frame is either being read out or completely read.
+ -- next tx frame is about to start
+ TX_PAYLOAD_CHECKSUM <= std_logic_vector(TCP_CKSUM); -- up to 2 bits of carry
+ TX_PAYLOAD_SIZE <= std_logic_vector(resize(FRAME_SIZE2,16)); -- payload size in bytes
+ TX_STREAM_SEL_local <= CKSUM_STREAM_SEL2;
+ end if;
+ elsif (CKSUM_STATE = 3) then
+ -- next tx frame is about to start
+ TX_PAYLOAD_CHECKSUM <= TX_PAYLOAD_CHECKSUM0;
+ TX_PAYLOAD_SIZE <= TX_PAYLOAD_SIZE0;
+ TX_STREAM_SEL_local <= TX_STREAM_SEL_local0;
+ end if;
+ end if;
+end process;
+TX_STREAM_SEL <= TX_STREAM_SEL_local;
+
+-- is the output stream still connected?
+OUTPUT_STREAM_CONNECTED_GEN: process(TX_STREAM_SEL_local, CONNECTED_FLAG)
+variable OSC: std_logic;
+begin
+ OSC := '0';
+ for I in 0 to NTCPSTREAMS-1 loop
+ if(TX_STREAM_SEL_local(I) = '1') and (CONNECTED_FLAG(I) = '1') then
+ OSC := '1';
+ end if;
+ end loop;
+ OUTPUT_STREAM_CONNECTED <= OSC;
+end process;
+TX_PAYLOAD_RTS <= OUTPUT_STREAM_CONNECTED when (OBUF_SIZE /= 0) else '0';
+ -- payload data is available for transmission AND TCP connection is still on.
+
+--// TCP TX FLOW CONTROL ---------------------------
+-- The basic tx flow control rule is that the buffer WPTR must never pass the last acknowledged tx byte location.
+AVAILABLE_BUF_SPACE_GENx: for I in 0 to (NTCPSTREAMS - 1) generate
+
+ AVAILABLE_BUF_SPACE_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ AVAILABLE_BUF_SPACE(I) <=(others => '0');
+ CONNECTED_FLAG_D(I) <= '0';
+ CONNECTED_FLAG_D2(I) <= '0';
+ else
+ CONNECTED_FLAG_D(I) <= CONNECTED_FLAG(I);
+ CONNECTED_FLAG_D2(I) <= CONNECTED_FLAG_D(I); -- align with AVAILABLE_BUF_SPACE
+ AVAILABLE_BUF_SPACE(I) <= unsigned(RX_TCP_ACK_NO_D(I)(ADDR_WIDTH+2 downto 0)) + not(WPTR(I)(ADDR_WIDTH+2 downto 0)); -- units: bytes
+ end if;
+ end if;
+ end process;
+
+ -- input flow control
+ -- no point in asking for data when there is no TCP connection and data is being discarded.
+ -- allow more tx data in if there is room for at least 512 bytes/64 words
+ APP_CTS_local(I) <= '0' when (CONNECTED_FLAG(I) = '0') else
+ '1' when (AVAILABLE_BUF_SPACE(I)(ADDR_WIDTH+2 downto 9) /= 0) else
+ '0';
+end generate;
+APP_CTS <= APP_CTS_local;
+-- allow more tx data in if there is room for at least 128 bytes
+
+----// TEST POINTS --------------------------------
+--TP(1) <= WPTR(0)(0);
+--TP(2) <= RPTR(0)(0);
+--TP(3) <= CONNECTED_FLAG(0);
+--TP(4) <= '1' when (TCP_TX_STATE(0) = 0) else '0';
+--TP(5) <= '1' when (RX_TCP_ACK_NO_D(0(ADDR_WIDTH-1 downto 0) = TX_SEQ_NO(0)(ADDR_WIDTH-1 downto 0)) else '0';
+--TP(6) <= '1' when (RX_TCP_ACK_NO_D(I)(ADDR_WIDTH-1 downto 0) = TX_SEQ_NO_IN(0)(ADDR_WIDTH-1 downto 0)) else '0';
+--TP(7) <= TX_SEQ_NO(0)(0);
+--TP(8) <= RX_TCP_ACK_NO_D(0)(0);
+--TP(9) <= SAMPLE3_CLK(0);
+--TP(10) <= TX_SEQ_NO_IN(0)(0);
+TP(1) <= WEA(0);
+TP(2) <= '1' when (TCP_TX_STATE(0) = 1) else '0';
+TP(3) <= '1' when (TCP_TX_STATE(0) = 3) else '0';
+TP(10 downto 4) <= (others => '0');
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/tdp_ram.vhd b/generic_ip/third_party_ip/tcp_server/src/tdp_ram.vhd
new file mode 100644
index 0000000..52ec6bd
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/tdp_ram.vhd
@@ -0,0 +1,76 @@
+-- True Dual-Port Block RAM with Two Clocks
+-- Correct Modelization with a Shared Variable
+-- File: true_dual_two_clocks.vhd
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.std_logic_unsigned.all;
+
+entity tdp_ram is
+ generic(
+ ADDR_WIDTH: natural := 11;
+ DATA_WIDTH: integer := 9);
+ port(
+ clka : in std_logic;
+ clkb : in std_logic;
+ ena : in std_logic;
+ enb : in std_logic;
+ wea : in std_logic;
+ web : in std_logic;
+ addra : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ addrb : in std_logic_vector(ADDR_WIDTH-1 downto 0);
+ dia : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ dib : in std_logic_vector(DATA_WIDTH-1 downto 0);
+ doa : out std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0');
+ dob : out std_logic_vector(DATA_WIDTH-1 downto 0) := (others => '0')
+ );
+end tdp_ram;
+
+architecture syn of tdp_ram is
+
+ type ram_type is array (2**ADDR_WIDTH-1 downto 0) of std_logic_vector(DATA_WIDTH-1 downto 0);
+ --shared variable RAM : ram_type;
+ signal RAM : ram_type := (others => (others => '0'));
+
+begin
+
+ -- dp_ram_inst : entity work.dp_ram_gis
+ -- generic map (
+ -- ADDR_WIDTH => ADDR_WIDTH,
+ -- DATA_WIDTH => DATA_WIDTH
+ -- )
+ -- port map
+ -- (
+ -- address_a => addra, -- : in std_logic_vector (11 downto 0);
+ -- address_b => addrb, -- : in std_logic_vector (11 downto 0);
+ -- clock => clka, -- : in std_logic := '1';
+ -- data_a => dia, -- : in std_logic_vector (63 downto 0);
+ -- data_b => dib, -- : in std_logic_vector (63 downto 0);
+ -- wren_a => wea, -- : in std_logic := '0';
+ -- wren_b => web, -- : in std_logic := '0';
+ -- q_a => doa, -- : out std_logic_vector (63 downto 0);
+ -- q_b => dob -- : out std_logic_vector (63 downto 0)
+ -- );
+
+ process(clka)
+ begin
+ if clka'event and clka = '1' then
+
+ doa <= RAM(conv_integer(addra));
+ dob <= RAM(conv_integer(addrb));
+
+ if ena = '1' then
+ if wea = '1' then
+ RAM(conv_integer(addra)) <= dia;
+ end if;
+ end if;
+
+ if enb = '1' then
+ if web = '1' then
+ RAM(conv_integer(addrb)) <= dib;
+ end if;
+ end if;
+
+ end if;
+ end process;
+
+end syn;
diff --git a/generic_ip/third_party_ip/tcp_server/src/timer_4us.vhd b/generic_ip/third_party_ip/tcp_server/src/timer_4us.vhd
new file mode 100644
index 0000000..0b92937
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/timer_4us.vhd
@@ -0,0 +1,100 @@
+-------------------------------------------------------------
+-- MSS copyright 2004-2015
+-- Filename: TIMER_1MS.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 5
+-- Date last modified: 12/10/15
+-- Inheritance: none
+--
+-- description: Creates a 4us timer tick which can be used to create other timers
+-- with 4us increment. Function is shared with all.
+--
+-- Rev 3 5/15/11 AZ
+-- Added 100ms tick
+--
+-- Rev 4 1/11/14 AZ
+-- Extended CLK_COUNTER precision to operate at higher FPGA clock frequency (from ?????? ???????)
+-- Switched to numeric_std.
+--
+-- Rev 5 12/10/15 AZ
+-- replaced ASYNC_RESET with SYNC_RESET
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity TIMER_4US is
+ generic (
+ CLK_FREQUENCY: integer := 120
+ -- CLK frequency in MHz. Needed to compute actual delays.
+ );
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ -- usage: specify the CLK frequency in MHz in the generic section above
+ SYNC_RESET: in std_logic;
+
+ TICK_4US: out std_logic;
+ TICK_100MS: out std_logic
+ -- 1 CLK-wide pulse every four microseconds and 100ms
+ );
+end entity;
+
+architecture Behavioral of TIMER_4US is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal CLK_COUNTER: unsigned(9 downto 0) := (others => '0');
+constant CLK_DIV: integer := (CLK_FREQUENCY * 4 - 1); -- CLK_FREQ MHz*4usec -1;
+signal TICK_4US_local: std_logic := '0';
+signal CLK_COUNTER2: unsigned(15 downto 0) := (others => '0');
+constant CLK_DIV2: integer := 24999; -- 100ms/4us - 1
+-- TEST TEST TEST TEST
+--constant CLK_DIV2: integer := 24; -- 100Us/4us - 1
+--constant CLK_DIV2: integer := 2; -- 10Us/4us - 1
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+CLK_DIV_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CLK_COUNTER <= (others => '0');
+ TICK_4US_local <= '0';
+ elsif(CLK_COUNTER /= CLK_DIV) then
+ CLK_COUNTER <= CLK_COUNTER + 1;
+ TICK_4US_local <= '0';
+ else
+ CLK_COUNTER <= (others => '0');
+ TICK_4US_local <= '1';
+ end if;
+ end if;
+end process;
+TICK_4US <= TICK_4US_local;
+
+TICK_100MS_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CLK_COUNTER2 <= (others => '0');
+ TICK_100MS <= '0';
+ elsif(TICK_4US_local = '1') then
+ if(CLK_COUNTER2 /= CLK_DIV2) then
+ CLK_COUNTER2 <= CLK_COUNTER2 + 1;
+ TICK_100MS <= '0';
+ else
+ CLK_COUNTER2 <= (others => '0');
+ TICK_100MS <= '1';
+ end if;
+ else
+ TICK_100MS <= '0';
+ end if;
+ end if;
+end process;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/udp_rx_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/udp_rx_10G.vhd
new file mode 100644
index 0000000..7f48193
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/udp_rx_10G.vhd
@@ -0,0 +1,215 @@
+-------------------------------------------------------------
+-- MSS copyright 2018
+-- Filename: UDP_RX_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 4/29/18
+-- Inheritance: COM-5402 UDP_RX.VHD 7/31/15
+--
+-- description: UDP protocol (receive-only) 10Gb, for IPv4 and IPv6
+-- Receives and validates UDP frames. The data segment of the UDP frame is immediately
+-- forwarded to the application without any intermediate storage in an elastic buffer.
+-- Thus the application must be capable of receiving data at full speed (156.25MHz/64-bit wide).
+--
+-- Various validation checks are performed in real-time while receiving a new frame.
+-- If any of the check fails, the UDP_RX_DATA_VALID is cleared. It is therefore IMPORTANT
+-- that the application rejects frame if UDP_RX_FRAME_VALID = '0' at the end of the frame
+-- (UDP_RX_EOF = '1').
+--
+-- Validation checks:
+-- MAC address, IP type, IP destination address, UDP protocol,
+-- UDP destination port, IP header checksum, UDP checksum
+--
+-- As there is no difference between IPv4 and IPv6 for UDP, this component is compatible with
+-- both IPv4 and IPv6.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.numeric_std.ALL;
+
+entity UDP_RX_10G is
+ Port (
+ --// CLK, RESET
+ CLK: in std_logic;
+ SYNC_RESET: in std_logic;
+
+ --// RECEIVED IP PAYLOAD ---------------------------------------------
+ -- Excludes MAC layer header, IP header.
+ IP_PAYLOAD_DATA: in std_logic_vector(63 downto 0);
+ IP_PAYLOAD_DATA_VALID: in std_logic_vector(7 downto 0);
+ IP_PAYLOAD_SOF: in std_logic;
+ IP_PAYLOAD_EOF: in std_logic;
+ IP_PAYLOAD_WORD_COUNT: in std_logic_vector(10 downto 0);
+
+ --// Partial checks (done in PACKET_PARSING common code)
+ --// basic IP validity check
+ IP_RX_FRAME_VALID: in std_logic;
+ -- As the IP frame validity is checked on-the-fly, the user should always check if
+ -- the IP_RX_FRAME_VALID is high AT THE END of the IP payload frame (IP_PAYLOAD_EOF) to confirm that the
+ -- ENTIRE IP frame is valid.
+ -- The received IP frame is presumed valid until proven otherwise.
+ -- IP frame validity checks include:
+ -- (a) protocol is IP
+ -- (b) unicast or multicast destination IP address matches
+ -- (c) correct IP header checksum (IPv4 only)
+ -- (d) allowed IPv6
+ -- (e) Ethernet frame is valid (correct FCS, dest address)
+ -- Ready at IP_RX_EOF_D2 = IP_PAYLOAD_EOF
+ RX_IP_PROTOCOL: in std_logic_vector(7 downto 0);
+ -- read between RX_IP_PROTOCOL_RDY (inclusive)(i.e. before IP_PAYLOAD_SOF) and IP_PAYLOAD_EOF (inclusive)
+ -- This component responds to protocol 17 = UDP
+ VALID_UDP_CHECKSUM: in std_logic;
+ -- '1' when valid UDP checksum. Read at IP_RX_EOF_D2 = IP_PAYLOAD_EOF_D
+
+ --// configuration
+ PORT_NO: in std_logic_vector(15 downto 0);
+ -- accepts UDP packets with a destination port PORT_NO
+ CHECK_UDP_RX_DEST_PORT_NO: in std_logic;
+ -- check the destination port number matches PORT_NO (1) or ignore it (0)
+ -- The latter case is useful when this component is shared among multiple UDP ports
+
+ --// Application interface
+ -- Latency: 0
+ UDP_RX_DATA: out std_logic_vector(63 downto 0);
+ -- UDP data field when UDP_RX_DATA_VALID = '1'
+ UDP_RX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- delineates the UDP data field
+ UDP_RX_SOF: out std_logic;
+ -- 1 CLK pulse indicating that UDP_RX_DATA is the first byte in the UDP data field.
+ UDP_RX_EOF: out std_logic;
+ -- 1 CLK pulse indicating that UDP_RX_DATA is the last byte in the UDP data field.
+ -- ALWAYS CHECK UDP_RX_FRAME_VALID at the end of packet (UDP_RX_EOF = '1') to confirm
+ -- that the UDP packet is valid. External buffer may have to backtrack to the the last
+ -- valid pointer to discard an invalid UDP packet.
+ -- Reason: we only knows about bad UDP packets at the end.
+ UDP_RX_FRAME_VALID: out std_logic;
+ -- check entire frame validity at UDP_RX_EOF
+ UDP_RX_SRC_PORT: out std_logic_vector(15 downto 0);
+ -- Identify the source UDP port. Read when UDP_RX_EOF = '1'
+ UDP_RX_DEST_PORT: out std_logic_vector(15 downto 0);
+ -- Identify the destination UDP port. Read when UDP_RX_EOF = '1'
+
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of UDP_RX_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+--// PARSE UDP HEADER --------------------------
+signal LENGTH: std_logic_vector(15 downto 0) := (others => '0');
+
+--// CHECK UDP VALIDITY -----------------------------
+signal VALID_RX_UDP0: std_logic := '0';
+signal VALID_RX_UDP: std_logic := '0';
+
+-- Remove UDP header
+signal UDP_PAYLOAD_FLAG: std_logic := '0';
+signal UDP_PAYLOAD_SOF_FLAG: std_logic := '0';
+signal UDP_RX_EOF_local: std_logic := '0';
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--// PARSE UDP HEADER --------------------------
+UDP_HEADER_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_PAYLOAD_SOF = '1') then
+ UDP_RX_SRC_PORT <= IP_PAYLOAD_DATA(63 downto 48);
+ UDP_RX_DEST_PORT <= IP_PAYLOAD_DATA(47 downto 32);
+ LENGTH <= IP_PAYLOAD_DATA(31 downto 16);
+ end if;
+ end if;
+end process;
+
+--// CHECK UDP VALIDITY -----------------------------
+-- The UDP packet reception is immediately cancelled if
+-- (a) the received packet type is not an IP datagram (done in common code PACKET_PARSING)
+-- (b) invalid destination IP (done in common code PACKET_PARSING)
+-- (c) incorrect IP header checksum (IPv4 only) (done in common code PACKET_PARSING)
+-- (d) the received IP type is not UDP
+-- (e) destination port number is not the specified PORT_NO (checking is user-enabled)
+-- (f) UDP checksum is incorrect
+
+VALIDITY_CHECK_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_PAYLOAD_SOF = '1') then
+ if(unsigned(RX_IP_PROTOCOL) /= 17) then
+ -- received protocol is not UDP
+ VALID_RX_UDP0 <= '0';
+ elsif(CHECK_UDP_RX_DEST_PORT_NO = '1') and (PORT_NO /= IP_PAYLOAD_DATA(47 downto 32)) then
+ -- user asked us to check the destination port number and it does not match.
+ -- Note: in some applications where UDP_RX_10G.vhd is shared by multiple UDP ports (DHCP server for example),
+ -- the destination port number check is better done outside this component.
+ VALID_RX_UDP0 <= '0';
+ else
+ VALID_RX_UDP0 <= '1';
+ end if;
+ elsif(IP_PAYLOAD_EOF = '1') and (IP_RX_FRAME_VALID = '0') then
+ VALID_RX_UDP0 <= '0';
+ end if;
+ end if;
+end process;
+UDP_RX_FRAME_VALID <= VALID_RX_UDP0 and VALID_UDP_CHECKSUM and UDP_RX_EOF_local; -- combine with the other checks done in parsing.vhd
+ -- validity assessment is complete at IP_PAYLOAD_EOF_D = UDP_RX_EOF
+
+
+--// COPY UDP DATA TO APPLICATION INTERFACE ------------------------
+-- Algorithm: UDP header is 8-byte long = 1 word. So just skip the first IP payload word.
+-- TODO: verify that in the case of very short (<60 bytes) Ethernet frames, the zero padding
+-- is removed in packet_parsing.vhd
+
+-- Remove UDP header
+UDP_PAYLOAD_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(IP_PAYLOAD_EOF = '1') then
+ UDP_PAYLOAD_FLAG <= '0';
+ elsif(IP_PAYLOAD_SOF = '1') then
+ UDP_PAYLOAD_FLAG <= '1';
+ end if;
+
+ if(IP_PAYLOAD_SOF = '1') and (IP_PAYLOAD_EOF = '0')then
+ UDP_PAYLOAD_SOF_FLAG <= '1';
+ elsif(unsigned(IP_PAYLOAD_DATA_VALID) /= 0) or (IP_PAYLOAD_EOF = '1') then
+ UDP_PAYLOAD_SOF_FLAG <= '0';
+ end if;
+ end if;
+end process;
+
+-- reclock to align UDP_RX_EOF with the late arrival of VALID_UDP_CHECKSUM
+OUTPUT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ UDP_RX_DATA <= IP_PAYLOAD_DATA;
+ if(UDP_PAYLOAD_FLAG = '1') and (VALID_RX_UDP0 = '1') then
+ UDP_RX_DATA_VALID <= IP_PAYLOAD_DATA_VALID ;
+ else
+ UDP_RX_DATA_VALID <= (others => '0');
+ end if;
+ if(UDP_PAYLOAD_SOF_FLAG = '1') and (VALID_RX_UDP0 = '1') and (unsigned(IP_PAYLOAD_DATA_VALID) /= 0) then
+ UDP_RX_SOF <= '1';
+ else
+ UDP_RX_SOF <= '0';
+ end if;
+ UDP_RX_EOF_local <= IP_PAYLOAD_EOF and UDP_PAYLOAD_FLAG and VALID_RX_UDP0;
+ end if;
+end process;
+UDP_RX_EOF <= UDP_RX_EOF_local;
+
+--// Test Point
+-- unused here
+-- TP(1) <= ...
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/udp_tx_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/udp_tx_10G.vhd
new file mode 100644
index 0000000..8410396
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/udp_tx_10G.vhd
@@ -0,0 +1,1011 @@
+-------------------------------------------------------------
+-- MSS copyright 2018
+-- Filename: UDP_TX_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 8/21/18
+-- Inheritance: COM5402 UDP_TX.VHD 5/10/17 rev7
+--
+-- description:
+-- The flexible UDP_TX.vhd component encapsulates a data packet into a UDP frame
+-- addressed from any port to any port/IP destination.
+-- 10Gbits/s.
+-- Supports IPv4 and IPv6.
+-- Portable VHDL
+--
+-- As we can't be sure that the destination is reachable or even in the routing table,
+-- input packet acceptance is signified by an ACK or NAK.
+-- Three cases:
+-- (a) destination IP address is a WAN address: the UDP frame is sent immediately to the gateway
+-- (b) destination IP address is a LAN address stored in the routing table. The UDP frame is sent between 0.1 and
+-- 1.33us after receiving the last byte.
+-- (c) destination IP address is not in the routing table. The routing table will send an ARP request (takes time).
+-- This component sends a NAK back to the application. It is up to the application to discard or retry later.
+--
+-- The application (layer above) is responsible for UDP frame segmentation.
+-- The maximum size is determined by the number of block RAMs instantiated within.
+--
+-- This component holds AT MOST TWO PACKETS at any given time in an elastic buffer. One packet being transferred in,
+-- another packet being transferred out.
+--
+-- The application must check the flow control flag APP_CTS before and while sending data to this component.
+-- The application should not send another UDP frame until receiving either an ACK or NAK regarding the previous
+-- UDP frame. For speed reason, the app can transfer in the next UDP frame while the previous one is being
+-- transferred out to the MAC layer. The component behaves as an A/B buffer.
+--
+-- The maximum overall throughput is reached when all packets have about the same size.
+--
+-- Device utilization (ADDR_WIDTH = 10, UDP_CKSUM_ENABLED='1',IPv6_ENABLED='1')
+-- FF: 639
+-- LUT: 1626
+-- DSP48: 0
+-- 18Kb BRAM: 2
+-- BUFG: 1
+-- Minimum period: 5.688ns (Maximum Frequency: 175.824MHz) Artix7-100T -1 speed grade
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity UDP_TX_10G is
+ generic (
+ ADDR_WIDTH: integer := 10;
+ -- allocates buffer space: 73 bits * 2^ADDR_WIDTH words
+ UDP_CKSUM_ENABLED: std_logic := '1';
+ -- IPv4 checksum computation is optional. 0 to save space, 1 to enable.
+ IPv6_ENABLED: std_logic := '1'
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ );
+ Port (
+ CLK: in std_logic;
+ -- CLK must be a global clock 156.25 MHz or faster to match the 10Gbps MAC speed.
+ SYNC_RESET: in std_logic;
+ -- CLK-synchronous reset. MANDATORY!
+ TICK_4US: in std_logic;
+
+ --// APPLICATION INTERFACE -> TX BUFFER
+ -- The application interface is synchronous with the application clock CLK
+ APP_DATA: in std_logic_vector(63 downto 0);
+ -- byte order: MSB first (reason: easier to read contents during simulation)
+ -- unused bytes are expected to be zeroed
+ APP_DATA_VALID: in std_logic_vector(7 downto 0);
+ -- example: 1 byte -> 0x80, 2 bytes -> 0xC0
+ APP_SOF: in std_logic; -- also resets internal state machine
+ APP_EOF: in std_logic;
+ -- IMPORTANT: always send an EOF to close the transaction.
+ APP_CTS: out std_logic;
+ -- Clear To Send = transmit flow control.
+ -- App is responsible for checking the CTS signal before sending APP_DATA
+ -- APP_SOF and APP_EOF are one CLK wide pulses indicating the first and last byte in the UDP frame.
+ -- Special case: Zero-length UDP frame: APP_SOF = '1', APP_EOF = '1' and APP_DATA_VALID = x"00"
+ -- Special case: 1 byte UDP frame: APP_SOF = '1', APP_EOF = '1', APP_DATA_VALID = x"80"
+ ACK: out std_logic;
+ -- previous UDP frame is accepted for transmission. Always after APP_SOF, but could happen before or
+ NAK: out std_logic;
+ -- no routing information available for the selected LAN destination IP. Try later.
+ -- ACK/NAK is sent anytime after APP_SOF, even before the input packet is fully transferred in
+
+ --// CONTROLS
+ DEST_IP_ADDR: in std_logic_vector(127 downto 0);
+ DEST_PORT_NO: in std_logic_vector(15 downto 0);
+ SOURCE_PORT_NO: in std_logic_vector(15 downto 0);
+ IPv4_6n: in std_logic;
+ -- routing information. Read at start of UDP frame (APP_SOF = '1')
+ -- It can at any other time.
+ -- Note: changing destination IP address may involve a timing penalty as this component
+ -- has to ask the routing table for routing information and possibly send an ARP request to
+ -- the target IP and wait for the ARP response.
+ IP_ID: in std_logic_vector(15 downto 0);
+ -- 16-bit IP ID, unique for each datagram. Incremented every time
+ -- an IP datagram is sent (not just for this socket).
+
+ --// CONFIGURATION
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- fixed (i.e. not changing from UDP frame to frame)
+
+ --// ROUTING INFO (interface with ARP_CACHE2)
+ -- (a) Query
+ RT_IP_ADDR: out std_logic_vector(127 downto 0);
+ -- user query: destination IP address to resolve (could be local or remote). read when RT_REQ_RTS = '1'
+ RT_IPv4_6n: out std_logic;
+ -- qualifier for RT_IP_ADDR: IPv4 (1) or IPv6 (0) address?
+ RT_REQ_RTS: out std_logic;
+ -- routing query ready to start
+ RT_REQ_CTS: in std_logic;
+ -- the top-level arbitration circuit passed the request to the routing table
+ -- (b) Reply
+ RT_MAC_REPLY: in std_logic_vector(47 downto 0);
+ -- Destination MAC address associated with the destination IP address RT_IP_ADDR.
+ -- Could be the Gateway MAC address if the destination IP address is outside the local area network.
+ RT_MAC_RDY: in std_logic;
+ -- 1 CLK pulse to read the MAC reply
+ -- If the routing table is idle, the worst case latency from the RT_REQ_RTS request is 0.85us
+ -- If there is no match in the table, no response will be provided. Calling routine should
+ -- therefore have a timeout timer to detect lack of response.
+ RT_NAK: in std_logic;
+ -- 1 CLK pulse indicating that no record matching the RT_IP_ADDR was found in the table.
+
+
+ --// OUTPUT: TX UDP layer -> Transmit MAC Interface
+ -- 32-bit CRC is automatically appended by MAC. Not supplied here.
+ MAC_TX_DATA: out std_logic_vector(63 downto 0) := (others => '0');
+ -- MAC reads the data at the rising edge of CLK when MAC_TX_DATA_VALID = '1'
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0) := x"00";
+ -- data valid
+ MAC_TX_EOF: out std_logic := '0';
+ -- '1' when sending the last byte in a packet to be transmitted.
+ -- Aligned with MAC_TX_DATA_VALID
+ MAC_TX_CTS: in std_logic;
+ -- MAC-generated Clear To Send flow control signal. The user should check that this
+ -- signal is high before sending the next MAC_TX_DATA byte.
+ RTS: out std_logic := '0';
+ -- '1' when a frame is ready to be sent (tell the COM5402 arbiter)
+ -- When the MAC starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+ --// TEST POINTS
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of UDP_TX_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+ COMPONENT BRAM_DP2
+ GENERIC(
+ DATA_WIDTHA: integer;
+ ADDR_WIDTHA: integer;
+ DATA_WIDTHB: integer;
+ ADDR_WIDTHB: integer
+ );
+ PORT(
+ CLKA : in std_logic;
+ CSA: in std_logic;
+ WEA : in std_logic;
+ OEA : in std_logic;
+ ADDRA : in std_logic_vector(ADDR_WIDTHA-1 downto 0);
+ DIA : in std_logic_vector(DATA_WIDTHA-1 downto 0);
+ DOA : out std_logic_vector(DATA_WIDTHA-1 downto 0);
+ CLKB : in std_logic;
+ CSB: in std_logic;
+ WEB : in std_logic;
+ OEB : in std_logic;
+ ADDRB : in std_logic_vector(ADDR_WIDTHB-1 downto 0);
+ DIB : in std_logic_vector(DATA_WIDTHB-1 downto 0);
+ DOB : out std_logic_vector(DATA_WIDTHB-1 downto 0)
+ );
+ END COMPONENT;
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+--//-- INPUT STATE MACHINE -------------------------------------
+signal STATE_A: integer range 0 to 5 := 0;
+signal LAST_IP: std_logic_vector(127 downto 0) := (others => '0');
+signal LAST_IPv4_6n: std_logic := '0';
+signal LAST_MAC: std_logic_vector(47 downto 0) := (others => '0');
+signal APP_EOF_FLAG0: std_logic := '0';
+signal APP_EOF_FLAG: std_logic := '0';
+signal TIMER_A: integer range 0 to 10 := 0; -- integer multiple of 4us
+signal RT_REQ_RTS_local: std_logic := '0';
+signal RT_REQ_RTS_TRIGGER: std_logic := '0';
+signal TX_PACKET_SEQUENCE_START: std_logic := '0';
+signal RTS_local: std_logic := '0';
+signal EVENT_TO_STATE_A4: std_logic := '0';
+
+--//-- UDP TX CHECKSUM ---------------------------
+signal TX_PACKET_SEQUENCE_START_SHIFT: std_logic_vector(6 downto 0) := (others => '0');
+signal CKSUM_PART1: unsigned(18 downto 0) := (others => '0');
+signal CKSUM_SEQ_CNTR: unsigned(2 downto 0) := (others => '0');
+signal CKSUM1: unsigned(17 downto 0) := (others => '0');
+signal CKSUM1A: unsigned(17 downto 0) := (others => '0');
+signal CKSUM1B: unsigned(17 downto 0) := (others => '0');
+signal CKSUM2: unsigned(17 downto 0) := (others => '0');
+signal CKSUM3: unsigned(17 downto 0) := (others => '0');
+signal CKSUM4: unsigned(17 downto 0) := (others => '0');
+signal CKSUM5: unsigned(17 downto 0) := (others => '0');
+signal CKSUM6: unsigned(17 downto 0) := (others => '0');
+signal CKSUM3PLUS: unsigned(17 downto 0) := (others => '0');
+signal CKSUM6PLUS: unsigned(17 downto 0) := (others => '0');
+signal UDP_CHECKSUM: unsigned(15 downto 0) := (others => '0');
+signal PAYLOAD_SIZE: unsigned(15 downto 0) := (others => '0'); -- in bytes
+signal PAYLOAD_SIZE_PLUS8: unsigned(15 downto 0) := (others => '0'); -- in bytes
+signal PAYLOAD_SIZE0: unsigned(15 downto 0) := (others => '0'); -- in bytes
+signal PAYLOAD_SIZE_D: unsigned(15 downto 0) := (others => '0'); -- in bytes
+
+--//-- ELASTIC BUFFER -----------------
+signal WPTR: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WPTR_SOF: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WPTR0: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal WEA: std_logic := '0';
+signal WEA_D: std_logic := '0';
+signal APP_SOF_D: std_logic := '0';
+signal RPTR: unsigned(ADDR_WIDTH-1 downto 0) := (others => '1');
+signal BUF_SIZE: unsigned(ADDR_WIDTH-1 downto 0) := (others => '0');
+signal DIA: std_logic_vector(71 downto 0) := (others => '0');
+signal DOB: std_logic_vector(71 downto 0) := (others => '0');
+signal DOB_PREVIOUS: std_logic_vector(71 downto 0) := (others => '0');
+signal DOB_SAMPLE_CLK_E: std_logic := '0';
+signal DOB_SAMPLE_CLK: std_logic := '0';
+signal TX_PAYLOAD_DATA: std_logic_vector(63 downto 0) := (others => '0');
+
+
+--//-- FREEZE INPUTS -----------------------
+signal TX_DEST_MAC_ADDR: std_logic_vector(47 downto 0) := (others => '0');
+signal IPv4_6n_D: std_logic := '0';
+signal DEST_IP_ADDR_D: std_logic_vector(127 downto 0):= (others => '0');
+signal DEST_PORT_NO_D: std_logic_vector(15 downto 0):= (others => '0');
+signal SOURCE_PORT_NO_D: std_logic_vector(15 downto 0):= (others => '0');
+signal TX_DEST_IP_ADDR: std_logic_vector(127 downto 0):= (others => '0');
+signal IP_ID_D: std_logic_vector(15 downto 0);
+signal TX_IPv4_6n: std_logic := '0';
+signal TX_DEST_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal TX_SOURCE_IP_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal TX_SOURCE_PORT_NO: std_logic_vector(15 downto 0) := (others => '0');
+signal TX_IP_ID: std_logic_vector(15 downto 0);
+signal IPv4_TOTAL_LENGTH: unsigned(15 downto 0) := (others => '0');
+signal IPv6_PAYLOAD_LENGTH: unsigned(15 downto 0) := (others => '0');
+signal UDP_LENGTH: unsigned(15 downto 0) := (others => '0');
+
+--//-- TX PACKET ASSEMBLY ----------------------
+signal TX_ACTIVE0: std_logic := '0';
+signal TX_ACTIVE: std_logic := '0';
+signal TX_WORD_COUNTER: unsigned(10 downto 0) := (others => '0');
+signal TX_WORD_COUNTER_D: unsigned(10 downto 0) := (others => '0');
+signal MAC_TX_WORD_VALID_E2: std_logic := '0';
+signal MAC_TX_WORD_VALID_E: std_logic := '0';
+signal MAC_TX_WORD_VALID: std_logic := '0';
+signal TX_UDP_PAYLOAD: std_logic := '0';
+signal MAC_TX_WORD_FLUSH_E2: std_logic := '0';
+
+
+signal TX_UDP_PAYLOAD_D: std_logic := '0';
+signal MAC_TX_EOF_local: std_logic := '0';
+
+signal UDP_LAST_HEADER_BYTE: std_logic := '0';
+
+--// TX IP HEADER CHECKSUM ---------------------------------------------
+signal IP_HEADER_CHECKSUM: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM0: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM_PLUS: unsigned(17 downto 0) := (others => '0');
+signal IP_HEADER_CHECKSUM_FINAL: std_logic_vector(15 downto 0) := (others => '0');
+
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+--//-- INPUT STATE MACHINE -------------------------------------
+-- A-side of the dual-port block RAM
+STATE_A_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ STATE_A <= 0;
+ TIMER_A <= 0;
+ NAK <= '0';
+ elsif (APP_SOF = '1') then
+ -- App starts transferring a new UDP frame. Resets the state machine.
+ -- Do we already know the destination MAC address here (in this component?)
+ if(DEST_IP_ADDR = LAST_IP) and (IPv4_6n = LAST_IPv4_6n) then
+ -- same destination as the previous frame. No need to ask the ARP cache (use LAST_MAC).
+ if (APP_EOF_FLAG = '1') then
+ -- input UDP frame is complete.
+ STATE_A <= 3; -- await complete MAC transmission of previous frame.
+ else
+ STATE_A <= 2; -- awaiting complete input UDP frame
+ end if;
+ else
+ -- request the destination MAC address from the routing table (ARP_CACHE2)
+ -- Set timer to avoid being stuck waiting for a missing event.
+ TIMER_A <= 10;
+ STATE_A <= 1; -- awaiting routing info
+ end if;
+ elsif (STATE_A = 0) then
+ NAK <= '0';
+ elsif (STATE_A = 1) and (RT_MAC_RDY = '1') then
+ -- received destination MAC address for the specified destination IP address
+ if (APP_EOF_FLAG = '1') then
+ -- input UDP frame is complete.
+ STATE_A <= 3; -- await complete MAC transmission of previous frame.
+ else
+ STATE_A <= 2; -- awaiting complete input UDP frame
+ end if;
+ elsif (STATE_A = 1) and (RT_NAK = '1') then
+ -- no entry in the routing table. Tell application (please try again later)
+ STATE_A <= 5; -- await EOF
+ NAK <= '1';
+ elsif (STATE_A = 1) and (TIMER_A = 0) then
+ -- timeout waiting for a response from routing table (traffic congestion?)
+ -- tell application (please try again later)
+ STATE_A <= 5; -- Await EOF
+ NAK <= '1';
+ elsif (STATE_A = 2) and (APP_EOF_FLAG = '1') then
+ -- input UDP frame is complete.
+ if ((RTS_local = '0') or (MAC_TX_EOF_local = '1')) then
+ -- input UDP frame is complete & previous frame transmission is complete.
+ STATE_A <= 4;
+ else
+ STATE_A <= 3; -- await complete MAC transmission of previous frame.
+ end if;
+ elsif (STATE_A = 3) and ((RTS_local = '0') or (MAC_TX_EOF_local = '1')) then
+ -- input UDP frame is complete & previous frame transmission is complete.
+ -- Ask MAC to send this new frame (raise RTS) and await MAC_TX_CTS.
+ STATE_A <= 4;
+ elsif (STATE_A = 4) and (MAC_TX_CTS = '1') then
+ -- starting transmission to MAC layer (TX_PACKET_SEQUENCE_START). Ready for another input UDP frame.
+ STATE_A <= 0;
+ elsif (STATE_A = 5) then
+ -- Received NAK. Awaiting EOF.
+ NAK <= '0';
+ if (APP_EOF_FLAG = '1') then
+ -- discard previous frame. back to idle
+ STATE_A <= 0;
+ end if;
+ elsif(TICK_4US = '1') and (TIMER_A /= 0) then
+ TIMER_A <= TIMER_A - 1;
+ end if;
+ end if;
+end process;
+EVENT_TO_STATE_A4 <= '1' when (STATE_A = 2) and (APP_EOF_FLAG = '1') and ((RTS_local = '0') or (MAC_TX_EOF_local = '1')) else
+ '1' when (STATE_A = 3) and ((RTS_local = '0') or (MAC_TX_EOF_local = '1')) else
+ '0';
+
+-- flow control: stop input flow immediately upon receiving the last packet byte. Resume when
+APP_CTS <= '1' when (TX_PACKET_SEQUENCE_START = '1') else
+ '0' when (APP_EOF = '1') or (APP_EOF_FLAG = '1') or (STATE_A = 3) else
+ '1';
+
+ACK <= TX_PACKET_SEQUENCE_START; -- send ACK to the App (same as start of UDP packet assembly).
+
+-- Ask for MAC transmit resources as soon as a complete UDP frame is stored in the elastic buffer
+-- and the previous frame was completely transferred to the MAC
+-- and routing information is available.
+RTS_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RTS_local <= '0';
+ elsif (EVENT_TO_STATE_A4 = '1') then
+ -- complete UDP frame waiting for tx in elastic buffer and previous frame transmission is complete
+ RTS_local <= '1';
+ elsif(MAC_TX_EOF_local = '1') then
+ -- no complete UDP frame waiting for tx
+ RTS_local <= '0';
+ end if;
+ end if;
+end process;
+RTS <= RTS_local or EVENT_TO_STATE_A4;
+
+--//-- ROUTING -------------------------------------
+-- send routing request
+RT_REQ_RTS_TRIGGER <= '1' when (STATE_A = 0) and (APP_SOF = '1') and ((DEST_IP_ADDR /= LAST_IP) or (IPv4_6n /= LAST_IPv4_6n)) else '0';
+RT_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RT_REQ_RTS_local <= '0';
+ elsif (RT_REQ_RTS_TRIGGER = '1') then
+ -- new UDP tx packet, different destination.
+ -- request the destination MAC address from the routing table (ARP_CACHE2)
+ RT_REQ_RTS_local <= '1';
+ elsif (RT_REQ_CTS = '1') then
+ -- routing request in progress.
+ RT_REQ_RTS_local <= '0';
+ end if;
+ end if;
+end process;
+RT_REQ_RTS <= RT_REQ_RTS_local or RT_REQ_RTS_TRIGGER;
+
+RT_002: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RT_IP_ADDR <= (others => '0');
+ elsif (RT_REQ_RTS_TRIGGER = '1') then
+ -- new UDP tx packet, different destination.
+ -- request the destination MAC address from the routing table (ARP_CACHE2)
+ RT_IP_ADDR <= DEST_IP_ADDR;
+ RT_IPv4_6n <= IPv4_6n;
+ end if;
+ end if;
+end process;
+
+-- DOUBT ABOUT TIMING... HOW TO MATCH RT_MAC_REPLY WITH DEST_IP_ADDR??????
+-- Remember the last set of destination IP/MAC addresses to minimize traffic at the cache memory
+RT_003: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ LAST_IP <= (others => '0');
+ LAST_IPv4_6n <= '0';
+ LAST_MAC <= (others => '0');
+ elsif (STATE_A = 1) and (RT_MAC_RDY = '1') then
+ -- received destination MAC address for the specified destination IP address
+ LAST_IP <= DEST_IP_ADDR;
+ LAST_IPv4_6n <= IPv4_6n;
+ LAST_MAC <= RT_MAC_REPLY;
+ end if;
+ end if;
+end process;
+
+-- Is the UDP frame completely in?
+-- This process works even in the special case of zero-length UDP frame
+APP_EOF_FLAG_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ APP_EOF_FLAG0 <= '0';
+ -- the events order is important here.
+ elsif (STATE_A = 5) and (APP_EOF_FLAG = '1') then
+ -- NAK. Discard frame
+ APP_EOF_FLAG0 <= '0';
+ elsif(APP_EOF = '1') then
+ APP_EOF_FLAG0 <= '1';
+ elsif(TX_PACKET_SEQUENCE_START = '1') then
+ -- idle
+ APP_EOF_FLAG0 <= '0';
+ end if;
+ end if;
+end process;
+APP_EOF_FLAG <= APP_EOF_FLAG0 or APP_EOF;
+
+--//-- UDP TX CHECKSUM ---------------------------
+UDP_TX_CKSUM_1: if(UDP_CKSUM_ENABLED = '1') generate
+ -- Compute the UDP payload checksum (excluding headers).
+ -- This PARTIAL checksum is ready 1(even number of bytes in payload) or 2 (odd number) into STATE_A = 3.
+ -- So the checksum will always be ready when needed.
+
+ -- for timing reasons, we limit ourselves to summing up to 3 16-bit fields per CLK
+ UDP_CKSUM_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ -- rephrased for better timing. *080718
+ CKSUM1A <= resize(unsigned(APP_DATA(63 downto 48)),18) + resize(unsigned(APP_DATA(47 downto 32)),18);
+ CKSUM1B <= resize(unsigned(APP_DATA(31 downto 16)),18) + resize(unsigned(APP_DATA(15 downto 0)),18);
+ if(APP_SOF_D = '1') then
+ -- start of frame
+ CKSUM1 <= CKSUM1A;
+ CKSUM2 <= CKSUM1B;
+ CKSUM3 <= ("00" & x"00_11"); -- UDP protocol
+ elsif(WEA_D = '1') then
+ CKSUM1 <= resize(CKSUM1(15 downto 0),18) + CKSUM1A;
+ CKSUM2 <= resize(CKSUM2(15 downto 0),18) + CKSUM1B;
+ CKSUM3 <= CKSUM3PLUS;
+ end if;
+ end if;
+ end process;
+ CKSUM3PLUS <= CKSUM3 + resize(CKSUM1(17 downto 16),18) + resize(CKSUM2(17 downto 16),18);
+
+ -- for IPv6, pre-compute the IPv6 address checksum. Only once at reset.
+ UDP_CKSUM_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CKSUM_SEQ_CNTR <= "110";
+ elsif(CKSUM_SEQ_CNTR > 0) then
+ CKSUM_SEQ_CNTR <= CKSUM_SEQ_CNTR - 1;
+ end if;
+ end if;
+ end process;
+
+ UDP_CKSUM_003: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ -- fixed part of the checksum is initialized at reset
+ if(SYNC_RESET = '1') then
+ CKSUM_PART1 <= resize(unsigned(IPv6_ADDR(127 downto 112)),19) + resize(unsigned(IPv6_ADDR(111 downto 96)),19);
+ elsif(CKSUM_SEQ_CNTR = "110") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(95 downto 80)),19);
+ elsif(CKSUM_SEQ_CNTR = "101") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(79 downto 64)),19);
+ elsif(CKSUM_SEQ_CNTR = "100") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(63 downto 48)),19);
+ elsif(CKSUM_SEQ_CNTR = "011") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(47 downto 32)),19);
+ elsif(CKSUM_SEQ_CNTR = "010") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(31 downto 16)),19);
+ elsif(CKSUM_SEQ_CNTR = "001") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(15 downto 0)),19);
+ end if;
+ end if;
+ end process;
+
+
+ -- Different pseudo-headers are used for IPv4 and IPv6
+ -- Checksum computation must be complete by the time TX_WORD_COUNTER reaches 5(IPv4) or 7 (IPv6). So we only have 5 iterations maximum to sum the pseudo header.
+ UDP_CKSUM_004: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ TX_PACKET_SEQUENCE_START_SHIFT(6 downto 0) <= TX_PACKET_SEQUENCE_START_SHIFT(5 downto 0) & TX_PACKET_SEQUENCE_START;
+ if(TX_PACKET_SEQUENCE_START = '1') then
+ CKSUM4 <= resize(unsigned(SOURCE_PORT_NO_D),18) + resize(unsigned(DEST_PORT_NO_D),18);
+ CKSUM6 <= (others => '0');
+ if(IPv4_6n_D = '1') then -- IPv4
+ CKSUM5 <= resize(unsigned(IPv4_ADDR(31 downto 16)),18) + resize(unsigned(IPv4_ADDR(15 downto 0)),18) + resize(PAYLOAD_SIZE_PLUS8 & "0",18); -- src IP address + 2*UDP length
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ CKSUM5 <= resize(CKSUM_PART1(15 downto 0),18) + resize(CKSUM_PART1(18 downto 16),18) + resize(PAYLOAD_SIZE_PLUS8 & "0",18); -- src IP address + 2*UDP length
+ end if;
+ else
+ if(TX_IPv4_6n = '1') then -- IPv4
+ if(TX_PACKET_SEQUENCE_START_SHIFT(0) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM1(15 downto 0),18);
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(CKSUM2(15 downto 0),18);
+ CKSUM6 <= CKSUM6PLUS + CKSUM3PLUS; -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(1) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(15 downto 0)),18); -- dst IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(31 downto 16)),18);
+ CKSUM6 <= CKSUM6PLUS; -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(2) = '1') then
+ CKSUM6 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM5(15 downto 0),18) + CKSUM6PLUS;
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(3) = '1') then
+ CKSUM6 <= resize(CKSUM6(15 downto 0),18) + CKSUM6(17 downto 16);
+ end if;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ if(TX_PACKET_SEQUENCE_START_SHIFT(0) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM1(15 downto 0),18);
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(CKSUM2(15 downto 0),18);
+ CKSUM6 <= CKSUM6PLUS + CKSUM3PLUS; -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(1) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(127 downto 112)),18); -- dest IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(95 downto 80)),18); -- dest IP address
+ CKSUM6 <= CKSUM6PLUS; -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(2) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(111 downto 96)),18); -- dest IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(79 downto 64)),18); -- dest IP address
+ CKSUM6 <= CKSUM6PLUS; -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(3) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(63 downto 48)),18); -- dest IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(31 downto 16)),18); -- dest IP address
+ CKSUM6 <= CKSUM6PLUS; -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(4) = '1') then
+ CKSUM4 <= resize(CKSUM4(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(47 downto 32)),18); -- dest IP address
+ CKSUM5 <= resize(CKSUM5(15 downto 0),18) + resize(unsigned(TX_DEST_IP_ADDR(15 downto 0)),18); -- dest IP address
+ CKSUM6 <= CKSUM6PLUS; -- carry
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(5) = '1') then
+ CKSUM6 <= resize(CKSUM4(15 downto 0),18) + resize(CKSUM5(15 downto 0),18) + CKSUM6PLUS;
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(6) = '1') then
+ CKSUM6 <= resize(CKSUM6(15 downto 0),18) + CKSUM6(17 downto 16);
+ end if;
+ end if;
+ end if;
+ end if;
+ end process;
+ CKSUM6PLUS <= CKSUM6 + resize(CKSUM4(17 downto 16),18) + resize(CKSUM5(17 downto 16),18);
+ UDP_CHECKSUM <= not CKSUM6(15 downto 0);
+end generate;
+UDP_TX_CKSUM_0: if(UDP_CKSUM_ENABLED = '0') generate
+ UDP_CHECKSUM <= x"0000";
+end generate;
+
+PAYLOAD_SIZE_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(WEA = '1') then
+ -- new word
+ if(APP_DATA_VALID(0) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 8;
+ elsif(APP_DATA_VALID(1) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 7;
+ elsif(APP_DATA_VALID(2) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 6;
+ elsif(APP_DATA_VALID(3) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 5;
+ elsif(APP_DATA_VALID(4) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 4;
+ elsif(APP_DATA_VALID(5) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 3;
+ elsif(APP_DATA_VALID(6) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 2;
+ elsif(APP_DATA_VALID(7) = '1') then
+ PAYLOAD_SIZE <= PAYLOAD_SIZE0 + 1;
+-- else
+-- -- illegal
+-- PAYLOAD_SIZE <= PAYLOAD_SIZE0;
+ end if;
+ end if;
+ end if;
+end process;
+PAYLOAD_SIZE_PLUS8 <= PAYLOAD_SIZE + 8;
+PAYLOAD_SIZE0 <= PAYLOAD_SIZE when (APP_SOF = '0') else (others => '0');
+
+--//-- ELASTIC BUFFER ----------------------------
+WPTR_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ WEA_D <= WEA;
+ APP_SOF_D <= APP_SOF;
+
+ if(SYNC_RESET = '1') then
+ WPTR <= (others => '0');
+ elsif(WEA = '1') then
+ WPTR <= WPTR + 1;
+ end if;
+ end if;
+end process;
+
+-- remember SOF location
+WPTR_SOF_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ WPTR_SOF <= (others => '0');
+ elsif(APP_SOF = '1') then
+ WPTR_SOF <= WPTR;
+ end if;
+ end if;
+end process;
+
+
+WEA <= '1' when (unsigned(APP_DATA_VALID) /= 0) else '0';
+DIA <= APP_DATA_VALID & APP_DATA;
+BRAM_DP2_001: BRAM_DP2
+GENERIC MAP(
+ DATA_WIDTHA => 72,
+ ADDR_WIDTHA => ADDR_WIDTH,
+ DATA_WIDTHB => 72,
+ ADDR_WIDTHB => ADDR_WIDTH
+
+)
+PORT MAP(
+ CSA => '1',
+ CLKA => CLK,
+ WEA => WEA, -- Port A Write Enable Input
+ ADDRA => std_logic_vector(WPTR), -- Port A Address Input
+ DIA => DIA, -- Port A Data Input
+ OEA => '0',
+ DOA => open,
+ CSB => '1',
+ CLKB => CLK,
+ WEB => '0',
+ ADDRB => std_logic_vector(RPTR), -- Port B Address Input
+ DIB => (others => '0'), -- Port B Data Input
+ OEB => '1',
+ DOB => DOB -- Port B Data Output
+);
+
+TX_PAYLOAD_DATA <= DOB(63 downto 0);
+BUF_SIZE <= WPTR0 + not RPTR;
+
+-- read pointer management
+RPTR_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RPTR <= (others => '1');
+ DOB_SAMPLE_CLK_E <= '0';
+ else
+ TX_UDP_PAYLOAD_D <= TX_UDP_PAYLOAD;
+ DOB_SAMPLE_CLK <= DOB_SAMPLE_CLK_E;
+
+ if(TX_PACKET_SEQUENCE_START = '1') then
+ RPTR <= WPTR_SOF - 1; -- points to one address before the start of UDP payload
+ DOB_SAMPLE_CLK_E <= '0';
+ elsif(TX_ACTIVE = '1') and (MAC_TX_CTS = '1') and (TX_UDP_PAYLOAD = '1') then
+ RPTR <= RPTR + 1; -- read follow-on UDP payload bytes
+ DOB_SAMPLE_CLK_E <= '1';
+ else
+ DOB_SAMPLE_CLK_E <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+
+-- remember previous word
+DOB_PREVIOUS_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(DOB_SAMPLE_CLK = '1') then
+ DOB_PREVIOUS <= DOB;
+ end if;
+ end if;
+end process;
+
+--//-- FREEZE INPUTS -----------------------
+-- Latch in all key fields at the start trigger, or at the latest during the Ethernet header.
+
+-- 1st latch info at the input start from app
+INFO_011: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(APP_SOF ='1') then
+ DEST_IP_ADDR_D <= DEST_IP_ADDR;
+ DEST_PORT_NO_D <= DEST_PORT_NO;
+ SOURCE_PORT_NO_D <= SOURCE_PORT_NO;
+ IPv4_6n_D <= IPv4_6n;
+ IP_ID_D <= IP_ID;
+ end if;
+ end if;
+end process;
+
+-- latch a second time upon start of output frame to MAC
+INFO_012: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(TX_PACKET_SEQUENCE_START = '1') then
+ -- Freeze parameters which can change on the A-side of the block ram
+ -- while we are sending the UDP packet to the MAC layer
+ PAYLOAD_SIZE_D <= PAYLOAD_SIZE; -- latch in payload size
+ TX_DEST_MAC_ADDR <= LAST_MAC;
+ TX_DEST_IP_ADDR <= DEST_IP_ADDR_D;
+ TX_IPv4_6n <= IPv4_6n_D;
+ TX_DEST_PORT_NO <= DEST_PORT_NO_D;
+ TX_SOURCE_PORT_NO <= SOURCE_PORT_NO_D;
+ TX_IP_ID <= IP_ID_D;
+ IPv6_PAYLOAD_LENGTH <= PAYLOAD_SIZE_PLUS8; -- same as UDP length
+ IPv4_TOTAL_LENGTH <= PAYLOAD_SIZE + 28;
+ WPTR0 <= WPTR; -- remember memory location for the last byte
+ end if;
+ end if;
+end process;
+
+--// IP HEADER CHECKSUM ----------------------
+-- Transmit IP packet header checksum. Only applies to IPv4 (no header checksum in IPv6)
+-- We must start the checksum early as the checksum field is not the last word in the header.
+-- perform 1's complement sum of all 16-bit words within the header.
+-- the checksum must be ready when TX_WORD_COUNTER_D=3
+
+IP_HEADER_CHECKSUM_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ IP_HEADER_CHECKSUM0 <= ("01" & x"8411") + resize(unsigned(IPv4_ADDR(31 downto 16)),18) + resize(unsigned(IPv4_ADDR(15 downto 0)),18); -- x"4500" + +x"4000" + x"FF11"
+
+ if (TX_PACKET_SEQUENCE_START = '1') and (IPv4_6n_D = '0') then
+ -- the IP header checksum applies only to IPv4
+ IP_HEADER_CHECKSUM <= (others => '0');
+ elsif (TX_PACKET_SEQUENCE_START = '1') and (IPv4_6n_D = '1') then
+ IP_HEADER_CHECKSUM <= resize(unsigned(IP_HEADER_CHECKSUM0(15 downto 0)),18) + resize(unsigned(IP_HEADER_CHECKSUM0(17 downto 16)),18) + resize(unsigned(IP_ID_D),18);
+ elsif(TX_IPv4_6n = '1') then
+ if(TX_PACKET_SEQUENCE_START_SHIFT(0) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS + resize(IPv4_TOTAL_LENGTH,18);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(1) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS + resize(unsigned(TX_DEST_IP_ADDR(15 downto 0)),18);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(2) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS + resize(unsigned(TX_DEST_IP_ADDR(31 downto 16)),18);
+ elsif(TX_PACKET_SEQUENCE_START_SHIFT(3) = '1') then
+ IP_HEADER_CHECKSUM <= IP_HEADER_CHECKSUM_PLUS ;
+ end if;
+ end if;
+
+ end if;
+end process;
+IP_HEADER_CHECKSUM_PLUS <= resize(unsigned(IP_HEADER_CHECKSUM(15 downto 0)),18) + resize(unsigned(IP_HEADER_CHECKSUM(17 downto 16)),18);
+IP_HEADER_CHECKSUM_FINAL <= x"FFFF" when (IP_HEADER_CHECKSUM(16) = '1') and (IP_HEADER_CHECKSUM(0) = '0') else
+ x"FFFE" when (IP_HEADER_CHECKSUM(16) = '1') and (IP_HEADER_CHECKSUM(0) = '1') else
+ not(std_logic_vector(IP_HEADER_CHECKSUM(15 downto 0)));
+--//-- TX PACKET ASSEMBLY ----------------------
+-- Transmit packet is assembled on the fly, consistent with our design goal
+-- of minimizing storage in each UDP_TX component.
+-- The packet includes the lower layers, i.e. IP layer and Ethernet layer.
+--
+-- First, we tell the outsider arbitration that we are ready to send by raising RTS high.
+-- When the transmit path becomes available, the arbiter tells us to go ahead with the transmission MAC_TX_CTS = '1'
+
+TX_PACKET_SEQUENCE_START <= '1' when (STATE_A = 4) and (MAC_TX_CTS = '1') else '0';
+ -- Starting sending the Ethernet/IP/UDP packet to the MAC layer.
+
+STATE_MACHINE_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_ACTIVE0 <= '0';
+ elsif (TX_PACKET_SEQUENCE_START = '1') then
+ TX_ACTIVE0 <= '1';
+ elsif(MAC_TX_EOF_local = '1') then
+ TX_ACTIVE0 <= '0';
+ end if;
+ end if;
+end process;
+TX_ACTIVE <= TX_ACTIVE0 and (not MAC_TX_EOF_local);
+
+TX_SCHEDULER_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ TX_WORD_COUNTER <= (others => '0');
+ TX_WORD_COUNTER_D <= (others => '0');
+ MAC_TX_WORD_VALID_E2 <= '0';
+ MAC_TX_WORD_VALID_E <= '0';
+ MAC_TX_WORD_FLUSH_E2 <= '0';
+ else
+ MAC_TX_WORD_VALID_E <= MAC_TX_WORD_VALID_E2;
+ TX_WORD_COUNTER_D <= TX_WORD_COUNTER; -- must keep the alignment with RPTR/DOB
+
+-- if(MAC_TX_EOF_E = '1') then
+-- -- end of UDP frame transmission
+-- -- For clarity, wait 1 CLK after the end of the previous packet to do anything.
+-- TX_WORD_COUNTER <= (others => '0');
+-- MAC_TX_WORD_VALID_E2 <= '0';
+ if (TX_PACKET_SEQUENCE_START = '1') then
+ -- UDP frame ready to send in the elastic buffer
+ -- initiating tx request. Reset counters.
+ TX_WORD_COUNTER <= (others => '0');
+ MAC_TX_WORD_VALID_E2 <= '1';
+ MAC_TX_WORD_FLUSH_E2 <= '0';
+ elsif(TX_ACTIVE = '1') and (MAC_TX_CTS = '1') and (BUF_SIZE /= 0) then
+ -- one packet is ready to send and MAC requests another byte
+ MAC_TX_WORD_VALID_E2 <= '1'; -- enable path to MAC
+ TX_WORD_COUNTER <= TX_WORD_COUNTER + 1;
+ elsif(TX_ACTIVE = '1') and (MAC_TX_CTS = '1') and (BUF_SIZE = 0) and (MAC_TX_WORD_FLUSH_E2 = '0') then
+ -- possible last word (to be confirmed later)
+ TX_WORD_COUNTER <= TX_WORD_COUNTER + 1;
+ MAC_TX_WORD_FLUSH_E2 <= '1';
+ MAC_TX_WORD_VALID_E2 <= '1'; -- enable path to MAC (to be confirmed later
+ else
+ MAC_TX_WORD_VALID_E2 <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+TX_UDP_PAYLOAD <= '0' when (BUF_SIZE = 0) else
+ '1' when (TX_IPv4_6n = '1') and (TX_WORD_COUNTER >= "00000000100") else
+ '1' when (IPv6_ENABLED = '1') and (TX_IPv4_6n = '0') and (TX_WORD_COUNTER >= "00000000110") else
+ '0';
+
+MAC_TX_DATA_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(TX_IPv4_6n = '1') then -- IPv4
+ case TX_WORD_COUNTER_D is
+ when "00000000000" =>
+ MAC_TX_DATA(63 downto 16) <= TX_DEST_MAC_ADDR;
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ when "00000000001" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ MAC_TX_DATA(31 downto 0) <= x"08004500";
+ when "00000000010" =>
+ MAC_TX_DATA(63 downto 48) <= std_logic_vector(IPv4_TOTAL_LENGTH);
+ MAC_TX_DATA(47 downto 32) <= TX_IP_ID;
+ MAC_TX_DATA(31 downto 0) <= x"4000FF11"; -- don't fragment, 255 hop limit, UDP
+ when "00000000011" =>
+ MAC_TX_DATA(63 downto 48) <= IP_HEADER_CHECKSUM_FINAL; -- IP header checksum
+ MAC_TX_DATA(47 downto 16) <= IPv4_ADDR; -- source IP address
+ MAC_TX_DATA(15 downto 0) <= TX_DEST_IP_ADDR(31 downto 16); -- destination IP address
+ when "00000000100" =>
+ MAC_TX_DATA(63 downto 48) <= TX_DEST_IP_ADDR(15 downto 0); -- destination IP address
+ MAC_TX_DATA(47 downto 32) <= TX_SOURCE_PORT_NO;
+ MAC_TX_DATA(31 downto 16) <= TX_DEST_PORT_NO;
+ MAC_TX_DATA(15 downto 0) <= std_logic_vector(IPv6_PAYLOAD_LENGTH); -- = UDP frame length
+ when "00000000101" =>
+ MAC_TX_DATA(63 downto 48) <= std_logic_vector(UDP_CHECKSUM);
+ MAC_TX_DATA(47 downto 0) <= DOB(63 downto 16);
+ when others =>
+ if(DOB_SAMPLE_CLK = '1') then
+ MAC_TX_DATA(63 downto 48) <= DOB_PREVIOUS(15 downto 0);
+ MAC_TX_DATA(47 downto 0) <= DOB(63 downto 16);
+ else
+ -- flush partial last word
+ MAC_TX_DATA(63 downto 48) <= DOB(15 downto 0);
+ MAC_TX_DATA(47 downto 0) <= (others => '0');
+ end if;
+ end case;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ case TX_WORD_COUNTER_D is
+ when "00000000000" =>
+ MAC_TX_DATA(63 downto 16) <= TX_DEST_MAC_ADDR;
+ MAC_TX_DATA(15 downto 0) <= MAC_ADDR(47 downto 32);
+ when "00000000001" =>
+ MAC_TX_DATA(63 downto 32) <= MAC_ADDR(31 downto 0);
+ MAC_TX_DATA(31 downto 0) <= x"86dd6000";
+ when "00000000010" =>
+ MAC_TX_DATA(63 downto 48) <= x"0000";
+ MAC_TX_DATA(47 downto 32) <= std_logic_vector(IPv6_PAYLOAD_LENGTH); -- payload length
+ MAC_TX_DATA(31 downto 16) <= x"11FF"; -- UDP, 255 hop limit
+ MAC_TX_DATA(15 downto 0) <= IPv6_ADDR(127 downto 112);
+ when "00000000011" =>
+ MAC_TX_DATA <= IPv6_ADDR(111 downto 48);
+ when "00000000100" =>
+ MAC_TX_DATA(63 downto 16) <= IPv6_ADDR(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= TX_DEST_IP_ADDR(127 downto 112);
+ when "00000000101" =>
+ MAC_TX_DATA <= TX_DEST_IP_ADDR(111 downto 48);
+ when "00000000110" =>
+ MAC_TX_DATA(63 downto 16) <= TX_DEST_IP_ADDR(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= TX_SOURCE_PORT_NO;
+ when "00000000111" =>
+ MAC_TX_DATA(63 downto 48) <= TX_DEST_PORT_NO;
+ MAC_TX_DATA(47 downto 32) <= std_logic_vector(IPv6_PAYLOAD_LENGTH);
+ MAC_TX_DATA(31 downto 16) <= std_logic_vector(UDP_CHECKSUM);
+ MAC_TX_DATA(15 downto 0) <= DOB(63 downto 48);
+ when others =>
+ if(DOB_SAMPLE_CLK = '1') then
+ MAC_TX_DATA(63 downto 16) <= DOB_PREVIOUS(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= DOB(63 downto 48);
+ else
+ -- flush partial last word
+ MAC_TX_DATA(63 downto 16) <= DOB(47 downto 0);
+ MAC_TX_DATA(15 downto 0) <= (others => '0');
+ end if;
+ end case;
+ end if;
+ end if;
+end process;
+
+MAC_TX_DATA_VALID_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ MAC_TX_WORD_VALID <= MAC_TX_WORD_VALID_E;
+
+ if(MAC_TX_WORD_VALID_E = '1') then
+ if(TX_IPv4_6n = '1') then -- IPv4
+ if(TX_WORD_COUNTER_D <= 4) then
+ MAC_TX_DATA_VALID <= x"FF";
+ elsif(TX_WORD_COUNTER_D = 5) then
+ MAC_TX_DATA_VALID <="11" & DOB(71 downto 66);
+ elsif(DOB_SAMPLE_CLK = '1') then
+ MAC_TX_DATA_VALID <= DOB_PREVIOUS(65 downto 64) & DOB(71 downto 66);
+ else
+ -- flush partial last word
+ MAC_TX_DATA_VALID <= DOB(65 downto 64) & "000000";
+ end if;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ if(TX_WORD_COUNTER_D <= 6) then
+ MAC_TX_DATA_VALID <= x"FF";
+ elsif(TX_WORD_COUNTER_D = 7) then
+ MAC_TX_DATA_VALID <="111111" & DOB(71 downto 70);
+ elsif(DOB_SAMPLE_CLK = '1') then
+ MAC_TX_DATA_VALID <= DOB_PREVIOUS(69 downto 64) & DOB(71 downto 70);
+ else
+ -- flush partial last word
+ MAC_TX_DATA_VALID <= DOB(69 downto 64) & "00";
+ end if;
+ end if;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ end if;
+ end if;
+end process;
+
+MAC_TX_EOF_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_TX_EOF_local <= '0';
+ elsif(MAC_TX_WORD_VALID_E = '1') then
+ if(TX_IPv4_6n = '1') then
+ if(TX_WORD_COUNTER_D = 5) and (DOB(65) = '0') then
+ MAC_TX_EOF_local <= '1';
+ elsif (TX_WORD_COUNTER_D > 5) and (DOB_SAMPLE_CLK = '1') and (DOB(65) = '0') then
+ MAC_TX_EOF_local <= '1';
+ elsif (TX_WORD_COUNTER_D > 5) and (DOB_SAMPLE_CLK = '0') and (DOB_PREVIOUS(65) = '1') then
+ -- flush partial last word
+ MAC_TX_EOF_local <= '1';
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ elsif(IPv6_ENABLED = '1') then -- IPv6
+ if(TX_WORD_COUNTER_D = 7) and (DOB(69) = '0') then
+ MAC_TX_EOF_local <= '1';
+ elsif (TX_WORD_COUNTER_D > 7) and (DOB_SAMPLE_CLK = '1') and (DOB(69) = '0') then
+ MAC_TX_EOF_local <= '1';
+ elsif (TX_WORD_COUNTER_D > 7) and (DOB_SAMPLE_CLK = '0') and (DOB_PREVIOUS(69) = '0') then
+ -- flush partial last word
+ MAC_TX_EOF_local <= '1';
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+--//-- TEST POINTS ---------------------------------
+TP(1) <= '1' when (STATE_A = 0) else '0';
+TP(2) <= '1' when (STATE_A = 3) else '0';
+TP(3) <= RTS_local;
+TP(4) <= MAC_TX_EOF_local;
+TP(5) <= MAC_TX_CTS;
+TP(7) <= RT_MAC_RDY;
+TP(8) <= RT_NAK;
+TP(9) <= TX_PACKET_SEQUENCE_START;
+TP(10) <= TX_ACTIVE;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/tcp_server/src/whois2_10G.vhd b/generic_ip/third_party_ip/tcp_server/src/whois2_10G.vhd
new file mode 100644
index 0000000..e661b1c
--- /dev/null
+++ b/generic_ip/third_party_ip/tcp_server/src/whois2_10G.vhd
@@ -0,0 +1,293 @@
+-------------------------------------------------------------
+-- MSS copyright 2018
+-- Filename: WHOIS2_10G.VHD
+-- Author: Alain Zarembowitch / MSS
+-- Version: 0
+-- Date last modified: 7/30/18
+-- Inheritance: COM-5402 WHOIS2.VHD rev1 8/8/12
+--
+-- description: Asks around who is (given IP address) using the
+-- Address Resolution Protocol (ARP) for IPv4 or Neighbor Discovery Protocol (NDP) for IPv6. 10Gb.
+---------------------------------------------------------------
+library IEEE;
+use IEEE.STD_LOGIC_1164.ALL;
+use IEEE.NUMERIC_STD.ALL;
+
+entity WHOIS2_10G is
+ generic (
+ IPv6_ENABLED: std_logic := '0'
+ -- 0 to minimize size, 1 to allow IPv6 in addition to IPv4 (larger size)
+ );
+ Port (
+ --// CLK, RESET
+ SYNC_RESET: in std_logic;
+ CLK: in std_logic;
+
+ --// User interface
+ WHOIS_IP_ADDR: in std_logic_vector(127 downto 0);
+ -- user query: IP address to resolve. read at WHOIS_START
+ -- use 32LSbs for IPv4
+ WHOIS_IPv4_6n: in std_logic;
+ -- address type IPv4(1) or IPv6(0)
+ WHOIS_START: in std_logic;
+ -- 1 CLK pulse to start the ARP query
+ -- new WHOIS requests will be ignored until the module is
+ -- finished with the previous request/reply transaction.
+ WHOIS_RDY: out std_logic;
+ -- always check WHOIS_RDY before requesting a WHOIS transaction with WHOIS_START, otherwise
+ -- there is risk that WHOIS is busy and that the request will be ignored.
+
+ --// Configuration data: IP address, MAC address
+ MAC_ADDR: in std_logic_vector(47 downto 0);
+ -- MAC address. Unique for each network interface card.
+ -- Natural byte order: (MSB = REG32) 0x000102030405 (LSB = REG37)
+ -- as transmitted in the Ethernet packet.
+ IPv4_ADDR: in std_logic_vector(31 downto 0);
+ IPv6_ADDR: in std_logic_vector(127 downto 0);
+ -- local IP address. 4 bytes for IPv4, 16 bytes for IPv6
+ -- Natural order (MSB) 172.16.1.128 (LSB) as transmitted in the IP frame.
+
+ --// Transmit frame/packet
+ MAC_TX_DATA: out std_logic_vector(63 downto 0);
+ MAC_TX_DATA_VALID: out std_logic_vector(7 downto 0);
+ -- one CLK-wide pulse indicating a new word is sent on MAC_TX_DATA
+ MAC_TX_EOF: out std_logic;
+ -- End of Frame: one CLK-wide pulse indicating the last word in the transmit frame.
+ -- aligned with MAC_TX_DATA_VALID.
+ MAC_TX_CTS: in std_logic;
+ -- 1 CLK-wide pulse requesting output samples. Check RTS first.
+ RTS: out std_logic;
+ -- '1' when a full or partial packet is ready to be read.
+ -- '0' when output buffer is empty.
+ -- When the user starts reading the output buffer, it is expected that it will be
+ -- read until empty.
+
+ -- Test Points
+ TP: out std_logic_vector(10 downto 1)
+
+ );
+end entity;
+
+architecture Behavioral of WHOIS2_10G is
+--------------------------------------------------------
+-- COMPONENTS
+--------------------------------------------------------
+--------------------------------------------------------
+-- SIGNALS
+--------------------------------------------------------
+signal WHOIS_STATE: std_logic := '0';
+signal WHOIS_IP_ADDR_D: std_logic_vector(127 downto 0) := (others => '0');
+signal DEST_IPv6_ADDR: std_logic_vector(127 downto 0) := (others => '0');
+signal WHOIS_IPv4_6n_D: std_logic := '0';
+
+--// ICMP CHECKSUM -----------------
+signal CKSUM_SEQ_CNTR: unsigned(2 downto 0) := "000";
+signal CKSUM_PART1: unsigned(19 downto 0) := (others => '0');
+signal CKSUM_PART2: unsigned(19 downto 0) := (others => '0');
+signal CKSUM: std_logic_vector(15 downto 0) := (others => '0');
+
+--// ARP request
+signal TX_PACKET_SEQUENCE: unsigned(4 downto 0) := (others => '1'); -- 42 bytes max IPv4, ? IPv6
+signal MAC_TX_DATA_VALID_E: std_logic := '0';
+signal MAC_TX_EOF_local: std_logic := '0';
+signal RTS_local: std_logic := '0';
+--------------------------------------------------------
+-- IMPLEMENTATION
+--------------------------------------------------------
+begin
+
+DEST_IPv6_ADDR <= x"FF0200000000000000000001FF" & WHOIS_IP_ADDR_D(23 downto 0);
+
+--// Generate ARP/NDP query
+ARP_RESP_GEN_001: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ MAC_TX_DATA <= (others => '0');
+ elsif(WHOIS_IPv4_6n_D = '1') then
+ -- IPv4 address -> send an ARP request. 42 bytes.
+ case(TX_PACKET_SEQUENCE) is
+ -- Ethernet header
+ when "00000" => MAC_TX_DATA <= x"FFFFFFFFFFFF" & MAC_ADDR(47 downto 32);
+ -- destination MAC address: broadcast. fixed at the time of connection establishment.
+ when "00001" => MAC_TX_DATA <= MAC_ADDR(31 downto 0) & x"08060001";
+ -- source Ethernet address + Ethernet type + hardware type
+ when "00010" => MAC_TX_DATA <= x"080006040001" & MAC_ADDR(47 downto 32);
+ -- protocol type + hardware size, protocol size + op field. ARP request + sender Ethernet address
+ when "00011" => MAC_TX_DATA <= MAC_ADDR(31 downto 0) & IPv4_ADDR;
+ -- sender Ethernet address + sender IP address
+ when "00100" => MAC_TX_DATA <= x"000000000000" & WHOIS_IP_ADDR_D(31 downto 16);
+ -- target Ethernet address + target IP address
+ when "00101" => MAC_TX_DATA <= WHOIS_IP_ADDR_D(15 downto 0) & x"000000000000";
+ -- target IP address
+ when others => MAC_TX_DATA <= (others => '0'); -- default & trailer
+ end case;
+ elsif(IPv6_ENABLED = '1') then
+ -- IPv6 address -> send a Neighbor solicitation message.86 bytes
+ case(TX_PACKET_SEQUENCE) is
+ -- Ethernet header
+ when "00000" => MAC_TX_DATA <= x"3333ff" & WHOIS_IP_ADDR_D(23 downto 0) & MAC_ADDR(47 downto 32);
+ -- destination MAC address: broadcast. fixed at the time of connection establishment.
+ when "00001" => MAC_TX_DATA <= MAC_ADDR(31 downto 0) & x"86DD6000";
+ -- source Ethernet address + Ethernet type IPv6 + hardware type
+ when "00010" => MAC_TX_DATA <= x"000000203AFF" & IPv6_ADDR(127 downto 112);
+ -- payload length (32), next header ICMPv6 (58), hop limit (255), source IP address
+ when "00011" => MAC_TX_DATA <= IPv6_ADDR(111 downto 48);
+ -- source IP address
+ when "00100" => MAC_TX_DATA <= IPv6_ADDR(47 downto 0) & x"FF02";
+ -- source IP address, destination IP address
+ when "00101" => MAC_TX_DATA <= x"0000000000000000";
+ -- destination IP address
+ when "00110" => MAC_TX_DATA <= x"0001FF" & WHOIS_IP_ADDR_D(23 downto 0) & x"8700";
+ -- destination IP address, ICMPv6 neighbor solicitation
+ when "00111" => MAC_TX_DATA <= CKSUM & x"00000000" & WHOIS_IP_ADDR_D(127 downto 112);
+ -- checksum, target address
+ when "01000" => MAC_TX_DATA <= WHOIS_IP_ADDR_D(111 downto 48);
+ -- target address
+ when "01001" => MAC_TX_DATA <= WHOIS_IP_ADDR_D(47 downto 0) & x"0101";
+ -- target IP address, ICMPv6 option
+ when "01010" => MAC_TX_DATA <= MAC_ADDR & x"0000";
+ -- link layer address
+ when others => MAC_TX_DATA <= (others => '0'); -- default & trailer
+ end case;
+
+ end if;
+ end if;
+end process;
+
+--// ICMP CHECKSUM -----------------
+-- The ICMP reply checksum is computed in two parts: one part at reset, based on the IPv6_ADDR and MAC_ADDR.
+-- The second part is computed for each valid received ICMP message.
+IPv6ONLY: if(IPv6_ENABLED = '1') generate
+ CKSUM_001: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ CKSUM_SEQ_CNTR <= "101";
+ elsif(CKSUM_SEQ_CNTR > 0) then
+ CKSUM_SEQ_CNTR <= CKSUM_SEQ_CNTR - 1;
+ end if;
+ end if;
+ end process;
+
+ CKSUM_002: process(CLK)
+ begin
+ if rising_edge(CLK) then
+ -- fixed part of the checksum is initialized at reset
+ if(SYNC_RESET = '1') then
+ CKSUM_PART1 <= resize(unsigned(IPv6_ADDR(127 downto 112)),20) + resize(unsigned(IPv6_ADDR(111 downto 96)),20);
+ elsif(CKSUM_SEQ_CNTR = "101") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(95 downto 80)),20) + resize(unsigned(IPv6_ADDR(79 downto 64)),20);
+ elsif(CKSUM_SEQ_CNTR = "100") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(63 downto 48)),20) + resize(unsigned(IPv6_ADDR(47 downto 32)),20);
+ elsif(CKSUM_SEQ_CNTR = "011") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(IPv6_ADDR(31 downto 16)),20) + resize(unsigned(IPv6_ADDR(15 downto 0)),20);
+ elsif(CKSUM_SEQ_CNTR = "010") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(MAC_ADDR(47 downto 32)),20) + resize(unsigned(MAC_ADDR(31 downto 16)),20);
+ elsif(CKSUM_SEQ_CNTR = "001") then
+ CKSUM_PART1 <= CKSUM_PART1 + resize(unsigned(MAC_ADDR(15 downto 0)),20) + x"875F";
+ -- constant is the sum of 3A + 20 + 8700 + 0101 + FF02 + 0001
+ end if;
+
+ if(MAC_TX_CTS = '1') then
+ -- variable part of the checksum depends on the ICMP message originator
+ case(TX_PACKET_SEQUENCE) is
+ when "11111" =>
+ CKSUM_PART2 <= CKSUM_PART1 + resize(unsigned(WHOIS_IP_ADDR_D(127 downto 112)),20) + resize(unsigned(WHOIS_IP_ADDR_D(111 downto 96)),20);
+ when "00000" =>
+ CKSUM_PART2 <= CKSUM_PART2 + resize(unsigned(WHOIS_IP_ADDR_D(95 downto 80)),20) + resize(unsigned(WHOIS_IP_ADDR_D(79 downto 64)),20);
+ when "00001" =>
+ CKSUM_PART2 <= CKSUM_PART2 + resize(unsigned(WHOIS_IP_ADDR_D(63 downto 48)),20) + resize(unsigned(WHOIS_IP_ADDR_D(47 downto 32)),20);
+ when "00010" =>
+ CKSUM_PART2 <= CKSUM_PART2 + resize(unsigned(WHOIS_IP_ADDR_D(31 downto 16)),20) + resize(unsigned(WHOIS_IP_ADDR_D(15 downto 0) & "0"),20); -- the 2 LSBs are summed twice
+ when "00011" =>
+ CKSUM_PART2 <= resize(unsigned(CKSUM_PART2(15 downto 0)),20) + resize(unsigned(CKSUM_PART2(19 downto 16)),20) + resize(unsigned(DEST_IPv6_ADDR(31 downto 16)),20);
+ when "00100" =>
+ CKSUM_PART2 <= resize(unsigned(CKSUM_PART2(15 downto 0)),20) + resize(unsigned(CKSUM_PART2(19 downto 16)),20);
+ when others => null;
+ end case;
+ end if;
+ end if;
+ end process;
+ CKSUM <= std_logic_vector(not CKSUM_PART2(15 downto 0));
+end generate;
+
+TX_SEQUENCE_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or ((WHOIS_START = '1') and (WHOIS_STATE = '0')) or (MAC_TX_EOF_local = '1') then -- *073018
+ TX_PACKET_SEQUENCE <= (others => '1');
+ MAC_TX_DATA_VALID_E <= '0';
+ elsif(WHOIS_STATE = '1') and (MAC_TX_CTS = '1') then
+ -- read the next word
+ TX_PACKET_SEQUENCE <= TX_PACKET_SEQUENCE + 1;
+ MAC_TX_DATA_VALID_E <= '1';
+ else
+ MAC_TX_DATA_VALID_E <= '0';
+ end if;
+ end if;
+end process;
+
+-- aligned with MAC_TX_DATA_VALID
+MAX_TX_EOF_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') or (MAC_TX_EOF_local = '1') then
+ MAC_TX_EOF_local <= '0';
+ MAC_TX_DATA_VALID <= x"00";
+ elsif(MAC_TX_DATA_VALID_E = '1') then
+ if(WHOIS_IPv4_6n_D = '1') and (TX_PACKET_SEQUENCE = 5) then
+ -- IPv4 ARP done. transmitting the last word (42-bytes)
+ MAC_TX_DATA_VALID <= x"c0"; -- last word contains only 2 bytes
+ MAC_TX_EOF_local <= '1';
+ elsif(WHOIS_IPv4_6n_D = '0') and (TX_PACKET_SEQUENCE = 10) then
+ -- IPv6 Neighbor solicitation done. transmitting the last word (86-bytes)
+ MAC_TX_DATA_VALID <= x"fc"; -- last word contains only 6 bytes
+ MAC_TX_EOF_local <= '1';
+ else
+ MAC_TX_DATA_VALID <= x"ff";
+ MAC_TX_EOF_local <= '0';
+ end if;
+ else
+ MAC_TX_DATA_VALID <= x"00";
+ MAC_TX_EOF_local <= '0';
+ end if;
+ end if;
+end process;
+MAC_TX_EOF <= MAC_TX_EOF_local;
+
+-- WHOIS state machine
+RTS_GEN: process(CLK)
+begin
+ if rising_edge(CLK) then
+ if(SYNC_RESET = '1') then
+ RTS_local <= '0';
+ WHOIS_STATE <= '0';
+ else
+ if(WHOIS_START = '1') and (WHOIS_STATE = '0') then
+ -- new transaction. Sending ARP or NDP request
+ RTS_local <= '1';
+ WHOIS_STATE <= '1';
+ -- freeze whois IP address and IPversion
+ WHOIS_IP_ADDR_D <= WHOIS_IP_ADDR;
+ WHOIS_IPv4_6n_D <= WHOIS_IPv4_6n;
+ elsif(MAC_TX_EOF_local = '1') then
+ -- done. transmitting the last word
+ RTS_local <= '0';
+ WHOIS_STATE <= '0';
+ end if;
+ end if;
+ end if;
+end process;
+RTS <= RTS_local;
+WHOIS_RDY <= RTS_local or WHOIS_START;
+
+
+--// Test Point
+TP(1) <= WHOIS_START;
+TP(2) <= MAC_TX_CTS;
+--TP(3) <= MAC_TX_DATA_VALID_E;
+TP(4) <= MAC_TX_EOF_local;
+TP(5) <= RTS_local;
+
+end Behavioral;
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/XAUI-Transceiver PHY IP Core User GuideV-Series Transceiver PHY IP Core User Guide - xcvr_user_guide.pdf b/generic_ip/third_party_ip/xaui_phy_itf/src/XAUI-Transceiver PHY IP Core User GuideV-Series Transceiver PHY IP Core User Guide - xcvr_user_guide.pdf
new file mode 100644
index 0000000..9d86b81
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/XAUI-Transceiver PHY IP Core User GuideV-Series Transceiver PHY IP Core User Guide - xcvr_user_guide.pdf differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf.vhd b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf.vhd
new file mode 100644
index 0000000..67649cc
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf.vhd
@@ -0,0 +1,303 @@
+-- megafunction wizard: %XAUI PHY Intel FPGA IP v18.1%
+-- GENERATION: XML
+-- xaui_phy_itf.vhd
+
+-- Generated using ACDS version 18.1 625
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+entity xaui_phy_itf is
+ port (
+ pll_ref_clk : in std_logic := '0'; -- pll_ref_clk.clk
+ xgmii_tx_clk : in std_logic := '0'; -- xgmii_tx_clk.clk
+ xgmii_rx_clk : out std_logic; -- xgmii_rx_clk.clk
+ xgmii_rx_dc : out std_logic_vector(71 downto 0); -- xgmii_rx_dc.data
+ xgmii_tx_dc : in std_logic_vector(71 downto 0) := (others => '0'); -- xgmii_tx_dc.data
+ xaui_rx_serial_data : in std_logic_vector(3 downto 0) := (others => '0'); -- xaui_rx_serial_data.export
+ xaui_tx_serial_data : out std_logic_vector(3 downto 0); -- xaui_tx_serial_data.export
+ rx_ready : out std_logic; -- rx_ready.export
+ tx_ready : out std_logic; -- tx_ready.export
+ phy_mgmt_clk : in std_logic := '0'; -- phy_mgmt_clk.clk
+ phy_mgmt_clk_reset : in std_logic := '0'; -- phy_mgmt_clk_reset.reset
+ phy_mgmt_address : in std_logic_vector(8 downto 0) := (others => '0'); -- phy_mgmt.address
+ phy_mgmt_read : in std_logic := '0'; -- .read
+ phy_mgmt_readdata : out std_logic_vector(31 downto 0); -- .readdata
+ phy_mgmt_write : in std_logic := '0'; -- .write
+ phy_mgmt_writedata : in std_logic_vector(31 downto 0) := (others => '0'); -- .writedata
+ phy_mgmt_waitrequest : out std_logic; -- .waitrequest
+ reconfig_from_xcvr : out std_logic_vector(229 downto 0); -- reconfig_from_xcvr.data
+ reconfig_to_xcvr : in std_logic_vector(349 downto 0) := (others => '0') -- reconfig_to_xcvr.data
+ );
+end entity xaui_phy_itf;
+
+architecture rtl of xaui_phy_itf is
+ component altera_xcvr_xaui is
+ generic (
+ device_family : string := "Stratix IV";
+ starting_channel_number : integer := 0;
+ interface_type : string := "Select";
+ data_rate : string := "3125 Mbps";
+ xaui_pll_type : string := "AUTO";
+ BASE_DATA_RATE : string := "";
+ en_synce_support : integer := 0;
+ use_control_and_status_ports : integer := 0;
+ external_pma_ctrl_reconf : integer := 0;
+ recovered_clk_out : integer := 0;
+ number_of_interfaces : integer := 1;
+ reconfig_interfaces : integer := 1;
+ use_rx_rate_match : integer := 0;
+ tx_termination : string := "OCT_100_OHMS";
+ tx_vod_selection : integer := 4;
+ tx_preemp_pretap : integer := 0;
+ tx_preemp_pretap_inv : string := "false";
+ tx_preemp_tap_1 : integer := 0;
+ tx_preemp_tap_2 : integer := 0;
+ tx_preemp_tap_2_inv : string := "false";
+ rx_common_mode : string := "0.82v";
+ rx_termination : string := "OCT_100_OHMS";
+ rx_eq_dc_gain : integer := 0;
+ rx_eq_ctrl : integer := 0;
+ pll_external_enable : integer := 0;
+ en_dual_fifo : integer := 0;
+ enable_rx_coreclkin : integer := 0;
+ disable_embedded_sdc : integer := 1;
+ mgmt_clk_in_mhz : integer := 150
+ );
+ port (
+ pll_ref_clk : in std_logic := 'X'; -- clk
+ xgmii_tx_clk : in std_logic := 'X'; -- clk
+ xgmii_rx_clk : out std_logic; -- clk
+ xgmii_rx_dc : out std_logic_vector(71 downto 0); -- data
+ xgmii_tx_dc : in std_logic_vector(71 downto 0) := (others => 'X'); -- data
+ xaui_rx_serial_data : in std_logic_vector(3 downto 0) := (others => 'X'); -- export
+ xaui_tx_serial_data : out std_logic_vector(3 downto 0); -- export
+ rx_ready : out std_logic; -- export
+ tx_ready : out std_logic; -- export
+ phy_mgmt_clk : in std_logic := 'X'; -- clk
+ phy_mgmt_clk_reset : in std_logic := 'X'; -- reset
+ phy_mgmt_address : in std_logic_vector(8 downto 0) := (others => 'X'); -- address
+ phy_mgmt_read : in std_logic := 'X'; -- read
+ phy_mgmt_readdata : out std_logic_vector(31 downto 0); -- readdata
+ phy_mgmt_write : in std_logic := 'X'; -- write
+ phy_mgmt_writedata : in std_logic_vector(31 downto 0) := (others => 'X'); -- writedata
+ phy_mgmt_waitrequest : out std_logic; -- waitrequest
+ reconfig_from_xcvr : out std_logic_vector(229 downto 0); -- data
+ reconfig_to_xcvr : in std_logic_vector(349 downto 0) := (others => 'X'); -- data
+ rx_recovered_clk : out std_logic_vector(3 downto 0); -- export
+ tx_clk312_5 : out std_logic; -- export
+ rx_digitalreset : in std_logic := 'X'; -- export
+ tx_digitalreset : in std_logic := 'X'; -- export
+ rx_channelaligned : out std_logic; -- export
+ rx_syncstatus : out std_logic_vector(7 downto 0); -- export
+ rx_disperr : out std_logic_vector(7 downto 0); -- export
+ rx_errdetect : out std_logic_vector(7 downto 0); -- export
+ rx_analogreset : in std_logic := 'X'; -- export
+ rx_invpolarity : in std_logic_vector(3 downto 0) := (others => 'X'); -- export
+ rx_set_locktodata : in std_logic_vector(3 downto 0) := (others => 'X'); -- export
+ rx_set_locktoref : in std_logic_vector(3 downto 0) := (others => 'X'); -- export
+ rx_seriallpbken : in std_logic_vector(3 downto 0) := (others => 'X'); -- export
+ tx_invpolarity : in std_logic_vector(3 downto 0) := (others => 'X'); -- export
+ rx_is_lockedtodata : out std_logic_vector(3 downto 0); -- export
+ rx_phase_comp_fifo_error : out std_logic_vector(3 downto 0); -- export
+ rx_is_lockedtoref : out std_logic_vector(3 downto 0); -- export
+ rx_rlv : out std_logic_vector(3 downto 0); -- export
+ rx_rmfifoempty : out std_logic_vector(3 downto 0); -- export
+ rx_rmfifofull : out std_logic_vector(3 downto 0); -- export
+ tx_phase_comp_fifo_error : out std_logic_vector(3 downto 0); -- export
+ rx_patterndetect : out std_logic_vector(7 downto 0); -- export
+ rx_rmfifodatadeleted : out std_logic_vector(7 downto 0); -- export
+ rx_rmfifodatainserted : out std_logic_vector(7 downto 0); -- export
+ rx_runningdisp : out std_logic_vector(7 downto 0); -- export
+ cal_blk_powerdown : in std_logic := 'X'; -- export
+ pll_powerdown : in std_logic := 'X'; -- export
+ gxb_powerdown : in std_logic := 'X'; -- export
+ pll_locked : out std_logic; -- export
+ cdr_ref_clk : in std_logic := 'X'; -- export
+ pll_locked_i : in std_logic := 'X'; -- export
+ ext_pll_clk : in std_logic_vector(3 downto 0) := (others => 'X'); -- export
+ rx_coreclkin : in std_logic := 'X'; -- export
+ reconfig_clk : in std_logic := 'X'; -- export
+ reconfig_reset : in std_logic := 'X'; -- export
+ reconfig_address : in std_logic_vector(11 downto 0) := (others => 'X'); -- export
+ reconfig_read : in std_logic := 'X'; -- export
+ reconfig_write : in std_logic := 'X'; -- export
+ reconfig_writedata : in std_logic_vector(31 downto 0) := (others => 'X'); -- export
+ reconfig_readdata : out std_logic_vector(31 downto 0); -- export
+ reconfig_waitrequest : out std_logic; -- export
+ tx_bonding_clocks : in std_logic_vector(5 downto 0) := (others => 'X'); -- export
+ pll_powerdown_o : out std_logic; -- export
+ pll_cal_busy_i : in std_logic := 'X'; -- export
+ xgmii_rx_inclk : in std_logic := 'X' -- export
+ );
+ end component altera_xcvr_xaui;
+
+begin
+
+ xaui_phy_itf_inst : component altera_xcvr_xaui
+ generic map (
+ device_family => "Cyclone V",
+ starting_channel_number => 0,
+ interface_type => "Soft XAUI",
+ data_rate => "3125 Mbps",
+ xaui_pll_type => "CMU",
+ BASE_DATA_RATE => "3125 Mbps",
+ en_synce_support => 0,
+ use_control_and_status_ports => 0,
+ external_pma_ctrl_reconf => 0,
+ recovered_clk_out => 0,
+ number_of_interfaces => 1,
+ reconfig_interfaces => 5,
+ use_rx_rate_match => 0,
+ tx_termination => "OCT_100_OHMS",
+ tx_vod_selection => 4,
+ tx_preemp_pretap => 0,
+ tx_preemp_pretap_inv => "false",
+ tx_preemp_tap_1 => 0,
+ tx_preemp_tap_2 => 0,
+ tx_preemp_tap_2_inv => "false",
+ rx_common_mode => "0.82v",
+ rx_termination => "OCT_100_OHMS",
+ rx_eq_dc_gain => 0,
+ rx_eq_ctrl => 0,
+ pll_external_enable => 0,
+ en_dual_fifo => 0,
+ enable_rx_coreclkin => 0,
+ disable_embedded_sdc => 1,
+ mgmt_clk_in_mhz => 150
+ )
+ port map (
+ pll_ref_clk => pll_ref_clk, -- pll_ref_clk.clk
+ xgmii_tx_clk => xgmii_tx_clk, -- xgmii_tx_clk.clk
+ xgmii_rx_clk => xgmii_rx_clk, -- xgmii_rx_clk.clk
+ xgmii_rx_dc => xgmii_rx_dc, -- xgmii_rx_dc.data
+ xgmii_tx_dc => xgmii_tx_dc, -- xgmii_tx_dc.data
+ xaui_rx_serial_data => xaui_rx_serial_data, -- xaui_rx_serial_data.export
+ xaui_tx_serial_data => xaui_tx_serial_data, -- xaui_tx_serial_data.export
+ rx_ready => rx_ready, -- rx_ready.export
+ tx_ready => tx_ready, -- tx_ready.export
+ phy_mgmt_clk => phy_mgmt_clk, -- phy_mgmt_clk.clk
+ phy_mgmt_clk_reset => phy_mgmt_clk_reset, -- phy_mgmt_clk_reset.reset
+ phy_mgmt_address => phy_mgmt_address, -- phy_mgmt.address
+ phy_mgmt_read => phy_mgmt_read, -- .read
+ phy_mgmt_readdata => phy_mgmt_readdata, -- .readdata
+ phy_mgmt_write => phy_mgmt_write, -- .write
+ phy_mgmt_writedata => phy_mgmt_writedata, -- .writedata
+ phy_mgmt_waitrequest => phy_mgmt_waitrequest, -- .waitrequest
+ reconfig_from_xcvr => reconfig_from_xcvr, -- reconfig_from_xcvr.data
+ reconfig_to_xcvr => reconfig_to_xcvr, -- reconfig_to_xcvr.data
+ rx_recovered_clk => open, -- (terminated)
+ tx_clk312_5 => open, -- (terminated)
+ rx_digitalreset => '0', -- (terminated)
+ tx_digitalreset => '0', -- (terminated)
+ rx_channelaligned => open, -- (terminated)
+ rx_syncstatus => open, -- (terminated)
+ rx_disperr => open, -- (terminated)
+ rx_errdetect => open, -- (terminated)
+ rx_analogreset => '0', -- (terminated)
+ rx_invpolarity => "0000", -- (terminated)
+ rx_set_locktodata => "0000", -- (terminated)
+ rx_set_locktoref => "0000", -- (terminated)
+ rx_seriallpbken => "0000", -- (terminated)
+ tx_invpolarity => "0000", -- (terminated)
+ rx_is_lockedtodata => open, -- (terminated)
+ rx_phase_comp_fifo_error => open, -- (terminated)
+ rx_is_lockedtoref => open, -- (terminated)
+ rx_rlv => open, -- (terminated)
+ rx_rmfifoempty => open, -- (terminated)
+ rx_rmfifofull => open, -- (terminated)
+ tx_phase_comp_fifo_error => open, -- (terminated)
+ rx_patterndetect => open, -- (terminated)
+ rx_rmfifodatadeleted => open, -- (terminated)
+ rx_rmfifodatainserted => open, -- (terminated)
+ rx_runningdisp => open, -- (terminated)
+ cal_blk_powerdown => '0', -- (terminated)
+ pll_powerdown => '0', -- (terminated)
+ gxb_powerdown => '0', -- (terminated)
+ pll_locked => open, -- (terminated)
+ cdr_ref_clk => '0', -- (terminated)
+ pll_locked_i => '0', -- (terminated)
+ ext_pll_clk => "0000", -- (terminated)
+ rx_coreclkin => '0', -- (terminated)
+ reconfig_clk => '0', -- (terminated)
+ reconfig_reset => '0', -- (terminated)
+ reconfig_address => "000000000000", -- (terminated)
+ reconfig_read => '0', -- (terminated)
+ reconfig_write => '0', -- (terminated)
+ reconfig_writedata => "00000000000000000000000000000000", -- (terminated)
+ reconfig_readdata => open, -- (terminated)
+ reconfig_waitrequest => open, -- (terminated)
+ tx_bonding_clocks => "000000", -- (terminated)
+ pll_powerdown_o => open, -- (terminated)
+ pll_cal_busy_i => '0', -- (terminated)
+ xgmii_rx_inclk => '0' -- (terminated)
+ );
+
+end architecture rtl; -- of xaui_phy_itf
+-- Retrieval info:
+--
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- Retrieval info:
+-- IPFS_FILES : xaui_phy_itf.vho
+-- RELATED_FILES: xaui_phy_itf.vhd, altera_xcvr_functions.sv, alt_pma_functions.sv, altera_xcvr_xaui.sv, hxaui_csr_h.sv, hxaui_csr.sv, alt_xcvr_mgmt2dec_phyreconfig.sv, alt_xcvr_mgmt2dec_xaui.sv, alt_pma_controller_tgx.v, alt_reset_ctrl_lego.sv, alt_reset_ctrl_tgx_cdrauto.sv, alt_xcvr_resync.sv, alt_xcvr_csr_common_h.sv, alt_xcvr_csr_common.sv, alt_xcvr_csr_pcs8g_h.sv, alt_xcvr_csr_pcs8g.sv, alt_xcvr_csr_selector.sv, alt_xcvr_mgmt2dec.sv, altera_wait_generate.v, altera_xcvr_reset_control.sv, alt_xcvr_reset_counter.sv, alt_soft_xaui_pcs.v, alt_soft_xaui_reset.v, alt_soft_xaui_rx.v, alt_soft_xaui_rx_8b10b_dec.v, alt_soft_xaui_rx_channel_synch.v, alt_soft_xaui_rx_deskew.v, alt_soft_xaui_rx_deskew_channel.v, alt_soft_xaui_rx_deskew_ram.v, altera_soft_xaui_rx_deskew_ram.v, alt_soft_xaui_rx_invalid_code_det.v, alt_soft_xaui_rx_parity.v, alt_soft_xaui_rx_parity_4b.v, alt_soft_xaui_rx_parity_6b.v, alt_soft_xaui_rx_rate_match.v, alt_soft_xaui_rx_rate_match_ram.v, alt_soft_xaui_rx_rl_chk_6g.v, alt_soft_xaui_rx_sm.v, alt_soft_xaui_tx.v, alt_soft_xaui_tx_8b10b_enc.v, alt_soft_xaui_tx_idle_conv.v, l_modules.v, serdes_4_unit_lc_siv.v, serdes_4_unit_siv.v, serdes_4unit.v, altera_std_synchronizer_nocut.v, sxaui.v, cv_xcvr_xaui.sv, av_xcvr_low_latency_phy_nr.sv, sv_reconfig_bundle_to_xcvr.sv, sv_reconfig_bundle_to_ip.sv, sv_reconfig_bundle_merger.sv, av_xcvr_h.sv, av_xcvr_avmm_csr.sv, av_tx_pma_ch.sv, av_tx_pma.sv, av_rx_pma.sv, av_pma.sv, av_pcs_ch.sv, av_pcs.sv, av_xcvr_avmm.sv, av_xcvr_native.sv, av_xcvr_plls.sv, av_xcvr_data_adapter.sv, av_reconfig_bundle_to_basic.sv, av_reconfig_bundle_to_xcvr.sv, av_hssi_8g_rx_pcs_rbc.sv, av_hssi_8g_tx_pcs_rbc.sv, av_hssi_common_pcs_pma_interface_rbc.sv, av_hssi_common_pld_pcs_interface_rbc.sv, av_hssi_pipe_gen1_2_rbc.sv, av_hssi_rx_pcs_pma_interface_rbc.sv, av_hssi_rx_pld_pcs_interface_rbc.sv, av_hssi_tx_pcs_pma_interface_rbc.sv, av_hssi_tx_pld_pcs_interface_rbc.sv, av_xcvr_custom_native.sv, alt_xcvr_arbiter.sv, alt_xcvr_m2s.sv
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_pma_controller_tgx.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_pma_controller_tgx.v
new file mode 100644
index 0000000..717bfcd
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_pma_controller_tgx.v
@@ -0,0 +1,198 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+`timescale 1ns/10ps
+module alt_pma_controller_tgx #(
+ parameter number_of_plls = 1,// One controller only control the possible merged pll. If more pll is needed, user can use multiplier controller for none share plls.
+ parameter tx_pll_reset_hold_time = 0,// ignored - now calculated according to system clock
+ parameter sync_depth = 2,
+ parameter sys_clk_in_mhz = 50 // needed for 1us and 4us delay timers
+)
+(
+ input rst, // controller logic reset
+ output tx_pll_ready,
+
+ // user data (avalon-MM formatted)
+ input wire clk,
+ input wire [1:0] pma_mgmt_address,
+ input wire pma_mgmt_read,
+ output reg [31:0] pma_mgmt_readdata,
+ input wire pma_mgmt_write,
+ input wire [31:0] pma_mgmt_writedata,
+ output wire pma_mgmt_waitrequest,
+
+ // user data (avalon-clock formatted)
+ input wire cal_blk_clk,
+
+ // user data: pll control (avalon-ST formatted)
+ output wire cal_blk_pdn,//sync with cal_blk_clk
+ output wire gx_pdn,//sync with clk
+ output wire [number_of_plls-1:0] pll_pdn, //sync with clk
+ input wire [number_of_plls-1:0] pll_locked //
+);
+
+localparam clk_in_mhz =
+`ifdef QUARTUS__SIMGEN
+ 2; // simulation-only value
+`elsif ALTERA_RESERVED_QIS
+ sys_clk_in_mhz; // use real counter lengths for normal Quartus synthesis
+`else
+ 2; // simulation-only value
+`endif
+localparam t_pll_powerdown = clk_in_mhz; // 1 us minimum
+localparam t_ltd_auto = clk_in_mhz*4; // 4 us minimum
+
+wire [number_of_plls-1:0] pll_locked_sync;
+reg cal_blk_pdn_reg;
+reg read_delay;
+reg gx_pdn_reg;
+reg pll_pdn_resetall_avmm;
+wire pll_pdn_int;
+reg pll_pdn_reg;
+
+wire gx_pdn_int;
+wire gx_pdn_done;
+
+altera_wait_generate wait_gen(
+ .rst(rst),
+.clk(clk),
+.launch_signal(pma_mgmt_read),
+.wait_req(pma_mgmt_waitrequest)
+ );
+
+alt_reset_ctrl_lego
+#(
+.reset_hold_cycles (t_pll_powerdown) // reset pulse length in clock cycles
+) pll_pdn_rst
+(
+.clock(clk),
+.start(1'b1 ),
+.reset(pll_pdn_int),
+.rdone(pll_locked), // reset done signal
+.aclr(rst),
+.sdone(tx_pll_ready) // sequence done for this lego
+);
+
+alt_reset_ctrl_lego
+#(
+.reset_hold_cycles (2) // reset pulse length in clock cycles
+) gx_pdn_rst
+(
+.clock(clk),
+.start(1'b1 ),
+.reset(gx_pdn_int),
+.rdone(1'b1), // reset done signal
+.aclr(rst),
+.sdone(gx_pdn_done) // sequence done for this lego
+);
+
+assign pll_pdn= pll_pdn_reg | {number_of_plls{pll_pdn_int}} ;
+
+initial
+begin
+ pll_pdn_reg <= 0;
+end
+always @ (posedge clk, posedge rst)
+begin
+ if(rst) begin
+ pll_pdn_reg <= 1'b0;
+ end
+ else if (pma_mgmt_write==1'b1 & pma_mgmt_address==2'b00) begin
+ pll_pdn_reg <= pma_mgmt_writedata[number_of_plls -1 :0];
+ end
+end
+
+initial
+begin
+ pma_mgmt_readdata <= 0;
+end
+always @ (posedge clk, posedge rst)
+begin
+ if(rst) begin
+ pma_mgmt_readdata <= 0;
+ end
+ else if (pma_mgmt_read==1'b1 & pma_mgmt_address==2'b00) begin
+ pma_mgmt_readdata[number_of_plls -1 :0] <= pll_pdn;
+ end
+ else if (pma_mgmt_read==1'b1 & pma_mgmt_address==2'b01) begin
+ pma_mgmt_readdata[0] <= cal_blk_pdn_reg;
+ pma_mgmt_readdata[1] <= gx_pdn;
+ end
+ else if (pma_mgmt_read==1'b1 & pma_mgmt_address==2'b10) begin
+ pma_mgmt_readdata[number_of_plls -1 :0] <= pll_locked_sync;
+ end
+ else
+ pma_mgmt_readdata <= 0;
+end
+
+generate
+genvar i;
+for (i=0; i=48) && (tmp<=57)) begin
+ magnitude = (magnitude * 10) + digit;
+ point_pos = point_pos *10;
+ end
+ end
+ if(point_pos > 0)
+ mega2k = magnitude*unit_mag/point_pos;
+ else
+ mega2k = magnitude*unit_mag;
+ end
+ endfunction
+
+endpackage
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_reset_ctrl_lego.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_reset_ctrl_lego.sv
new file mode 100644
index 0000000..a42b06a
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_reset_ctrl_lego.sv
@@ -0,0 +1,265 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Reset controller building block.
+//
+// Handles a single reset stage. Can be daisy-chained with other blocks for purely sequential resets.
+// Options include reset pulse length in clock cycles, and a counter for sdone stability checking.
+//
+// $Header$
+//
+
+`timescale 1 ns / 1 ns
+
+module alt_reset_ctrl_lego
+#(
+ parameter reset_hold_til_rdone = 0, // 1 means reset stays high until rdone arrives
+ // 0 means fixed pulse length, defined by reset_hold_cycles
+ parameter reset_hold_cycles = 1, // reset pulse length in clock cycles
+ parameter sdone_delay_cycles = 0, // optional delay from rdone received til sdone sent to next block
+ parameter rdone_is_edge_sensitive = 0 // default is level sensitive rdone
+)
+(
+ // clocks and PLLs
+ input wire clock,
+ input wire start,
+ input tri0 aclr, // active-high asynchronous reset
+ output wire reset,
+ input tri0 rdone, // reset done signal
+ output reg sdone // sequence done for this lego
+);
+ localparam max_precision = 32; // VCS requires this declaration outside the function
+ function integer ceil_log2;
+ input [max_precision-1:0] input_num;
+ integer i;
+ reg [max_precision-1:0] try_result;
+ begin
+ i = 0;
+ try_result = 1;
+ while ((try_result << i) < input_num && i < max_precision)
+ i = i + 1;
+ ceil_log2 = i;
+ end
+ endfunction
+
+ // How many bits are needed for 'reset_hold_cycles' counter?
+ localparam rhc_bits = ceil_log2(reset_hold_cycles);
+ localparam rhc_load_constant = (1 << rhc_bits) | (reset_hold_cycles-1);
+ // How many bits are needed for 'sdone_delay_cycles' counter?
+ localparam sdc_bits = ceil_log2(sdone_delay_cycles);
+ localparam sdc_load_constant = (1 << sdc_bits)
+ | ((rdone_is_edge_sensitive == 1 && sdone_delay_cycles > 1) ? sdone_delay_cycles-2 : sdone_delay_cycles-1);
+ localparam sdone_stable_cycles = (sdone_delay_cycles > 1 ? sdone_delay_cycles+1 : 0);
+
+ wire spulse; // synchronous detection of 'start' 0-to-1 transition
+ wire rhold;
+ wire timed_reset_in_progress;
+ wire rinit_next; // combinatorial input to rinit DFF
+ wire rdonei; // internal selector between rdone and rdsave (rdone_is_edge_sensitive==1)
+ wire rdpulse; // synchronous detection of 'rdone' 0-to-1 transition, when rdone_is_edge_sensitive==1
+
+ reg zstart = 0; // delayed value of 'start' input, used for detection of 0-to-1 transition
+ reg rinit = 0; // state bit that indicates sequence is in progress
+
+ initial begin
+ sdone = 0; // 1 indicates sequence is done
+ end
+
+
+ // 'start' input, detect 0-to-1 transition that triggers sequence
+ assign spulse = start & ~zstart;
+ always @(posedge clock or posedge aclr)
+ if (aclr == 1'b1)
+ zstart <= 0;
+ else
+ zstart <= start;
+
+ // rinit state bit, triggered by spulse, waits while rhold = 1
+ assign rinit_next = spulse | (rinit & (rhold | ~rdonei | rdpulse)) | timed_reset_in_progress;
+ always @(posedge clock or posedge aclr)
+ if (aclr == 1'b1)
+ rinit <= 0;
+ else
+ rinit <= rinit_next;
+
+ // optional internal 'rdone' generation logic, if rdone_is_edge_sensitive==1
+ generate
+ if (rdone_is_edge_sensitive == 0) begin
+ assign rdpulse = 0;
+ assign rdonei = rdone;
+ end
+ else begin
+ // instantiate synchronous edge-detection logic for rdone
+ reg zrdone = 0; // for edge-sensitive rdone, detect 0-to-1 transition synchronously
+ reg rdsave = 0; // for edge-sensitive rdone, use this as internal rdone
+ always @(posedge clock or posedge aclr) begin
+ if (aclr == 1'b1) begin
+ zrdone <= 0;
+ rdsave <= 0;
+ end
+ else begin
+ zrdone <= rdone; // previous value of rdone for synchronous edge detection
+ rdsave <= ~spulse & (rdpulse | rdsave);
+ end
+ end
+ assign rdpulse = rdone & ~zrdone;
+ assign rdonei = rdsave;
+ end
+ endgenerate
+
+ // rhold depends on sdone_delay_cycles and rdone_is_edge_sensitive
+ generate
+ if (sdone_delay_cycles == 0 || (sdone_delay_cycles == 1 && rdone_is_edge_sensitive == 1))
+ assign rhold = ~rdonei; // sdone_delay_cycles=0
+ else begin
+ // declare only when needed to avoid Quartus synthesis warnings
+ reg [sdc_bits:0] rhold_reg = 0; // for sdone_delay_cycles > 0
+ if (sdone_delay_cycles == 1) begin
+ always @(posedge clock or posedge aclr) begin
+ if (aclr == 1'b1)
+ rhold_reg <= 0;
+ else
+ rhold_reg <= ~(rinit & rdonei);
+ end
+ assign rhold = rhold_reg[0]; // sdone_delay_cycles=1
+ end
+ else begin
+ // need to count cycles to make sure rdone is stable
+ always @(posedge clock or posedge aclr)
+ begin
+ if (aclr == 1'b1)
+ rhold_reg <= 0;
+ else if ((rinit & rdonei & ~rdpulse) == 0)
+ // keep load value until rinit & rdone both high, and no new rdone pulses
+ rhold_reg <= sdc_load_constant[sdc_bits:0];
+ else
+ rhold_reg <= rhold_reg - 1'b1;
+ end
+ assign rhold = rhold_reg[sdc_bits]; // sdone_delay_cycles > 1
+ end
+ end
+ endgenerate
+
+ // sdone state bit indicates that reset sequence completed. Clear again on 'start'
+ always @(posedge clock or posedge aclr)
+ if (aclr == 1'b1)
+ sdone <= 0;
+ else
+ sdone <= ~spulse & (sdone | (rinit & ~rinit_next));
+
+ // reset pulse generation logic depends on 2 parameters
+ generate
+ if (reset_hold_til_rdone == 1) begin
+ assign reset = rinit;
+ assign timed_reset_in_progress = 0;
+ end
+ else if (reset_hold_cycles < 1) begin // 0 is legal, but catch negative (illegal) values too
+ assign reset = spulse;
+ assign timed_reset_in_progress = 0;
+ end
+ else begin
+ // declare only when needed to avoid Quartus synthesis warnings
+ reg [rhc_bits:0] zspulse = 0; // bits for reset pulse if fixed length
+ assign timed_reset_in_progress = zspulse[rhc_bits];
+ assign reset = zspulse[rhc_bits];
+
+ if (reset_hold_cycles == 1)
+ // a single-cycle reset pulse needs 1 register
+ always @(posedge clock or posedge aclr)
+ if (aclr == 1'b1)
+ zspulse <= 0;
+ else
+ zspulse <= spulse;
+ else begin
+ // multi-cycle reset pulse needs a counter
+ always @(posedge clock or posedge aclr)
+ begin
+ if (aclr == 1'b1)
+ zspulse <= 0;
+ else if (spulse == 1)
+ zspulse <= rhc_load_constant[rhc_bits:0];
+ else if (zspulse[rhc_bits] == 1)
+ zspulse <= zspulse - 1'b1;
+ end
+ end
+ end
+ endgenerate
+
+// generate
+// case (reset_hold_til_rdone)
+// 0 : m1 U1 (a, b, c);
+// 2 : m2 U1 (a, b, c);
+// default : m3 U1 (a, b, c);
+// endcase
+// endgenerate
+
+ // general assertions
+ //synopsys translate_off
+ // vlog/vcs/ncverilog: +define+ALTERA_XCVR_ASSERTIONS
+`ifdef ALTERA_XCVR_ASSERTIONS
+ // when rdone is edge sensitive, last rdone +ve edge triggers sdone +ve edge,
+ // 'sdone_delay_cycles' later. "##1 1" is an always-true cycle to match $rise(sdone)
+ sequence rdone_last_edge;
+ @(posedge clock) $rose(rdone) ##1 !$rose(rdone) [*sdone_delay_cycles] ##1 1;
+ endsequence
+
+ // when rdone is level sensitive, stable rdone for 'sdone_delay_cycles' consecutive cycles
+ // triggers sdone +ve edge. "##1 1" is an always-true cycle to match $rise(sdone)
+ sequence rdone_stable_level;
+ @(posedge clock) rdone [*(sdone_delay_cycles+1)] ##1 1;
+ endsequence
+
+// Most assertions aren't valid when 'aclr' is active
+//`define assert_awake(arg) assert property (disable iff (aclr) arg )
+ always @(aclr)
+ if (aclr) $assertkill;
+ else $asserton;
+
+ generate
+ always @(posedge clock) begin
+ // A rising edge on start will result in reset high within 1 clock cycle
+ assert property ($rose(start & ~aclr) |-> ##[0:1] reset);
+ // A rising edge on reset will result in sdone low within 1 clock cycle
+ assert property ($rose(reset) |-> ##[0:1] !sdone);
+
+ // assertions for optional behavior: reset pulse length options
+ if (reset_hold_til_rdone == 0 && reset_hold_cycles > 1)
+ // Verify fixed-length reset pulse option
+ assert property ($rose(reset) |-> reset [*reset_hold_cycles] ##1 !reset)
+ else $error("Reset pulse length should be %d", reset_hold_cycles);
+ if (reset_hold_til_rdone == 0 && reset_hold_cycles == 1)
+ // Verify fixed 1-length reset pulse option
+ assert property ($rose(reset) |=> !reset);
+ if (reset_hold_til_rdone == 0 && reset_hold_cycles == 0)
+ // Verify minimal-length reset pulse option, which mirrors 'start' edge detection
+ assert property ($rose(start & ~aclr) |-> reset ##1 !reset);
+ if (reset_hold_til_rdone == 1) begin
+ // with hold-til-rdone, reset should not deassert until after rdone asserts, then deassert immediately
+ assert property ($rose(reset) && !rdone |=> $stable(reset) [*0:$] ##1 (reset && rdone) ##1 !reset);
+ assert property ($rose(reset) && rdone ##1 rdone [*sdone_delay_cycles] |=> !reset); // rdone was already high
+ //assert property ($rose(reset) && !rdone |-> ##[0:$] rdone ##1 !reset);
+ end
+
+ // assertions for optional behavior: sdone delay options and rdone edge sensitive option
+ if (rdone_is_edge_sensitive == 1)
+ // rdone edge-sensitive option only has an effect when sdone_delay_cycles > 0
+ assert property ($rose(sdone) |-> rdone_last_edge.ended);
+ if (rdone_is_edge_sensitive == 0)
+ // rdone defaults to level-sensitive
+ assert property ($rose(sdone) |-> (rdone_stable_level.ended or $past($fell(reset),1)));
+ end
+ endgenerate
+`endif // ALTERA_XCVR_ASSERTIONS
+ //synopsys translate_on
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_reset_ctrl_tgx_cdrauto.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_reset_ctrl_tgx_cdrauto.sv
new file mode 100644
index 0000000..0a2ba87
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_reset_ctrl_tgx_cdrauto.sv
@@ -0,0 +1,201 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Reset controller for Stratix IV transceivers with RX CDR in auto-lock mode.
+//
+// Uses alt_reset_ctrl_lego to handle each reset stage, with 3 required for the overall sequence.
+// Parameter defaults for pll-powerdown and lock-to-data-auto timers assume 50 MHz system clock
+//
+// $Header$
+//
+
+`timescale 1 ns / 1 ns
+
+(* altera_attribute = "-name MERGE_TX_PLL_DRIVEN_BY_REGISTERS_WITH_SAME_CLEAR ON -to \"alt_reset_ctrl_lego:lego_pll_powerdown|zspulse\" " *)
+module alt_reset_ctrl_tgx_cdrauto
+#(
+ parameter sys_clk_in_mhz = 50 // needed for 1us and 4us delay timers
+)
+(
+ // User inputs and outputs
+ input wire clock,
+ input wire reset_all,
+ input tri0 reset_tx_digital,
+ input tri0 reset_rx_digital,
+ input wire powerdown_all,
+ output wire tx_ready,
+ output wire rx_ready,
+
+ // I/O to Stratix IV transceiver control & status
+ output wire pll_powerdown, // reset TX PLL
+ output wire tx_digitalreset, // reset TX PCS
+ output wire rx_analogreset, // reset RX PMA
+ output wire rx_digitalreset, // reset RX PCS
+ output wire gxb_powerdown, // powerdown whole quad
+ input wire pll_is_locked, // TX PLL is locked status
+ input tri0 tx_cal_busy, // TX channel calibration status
+ input tri0 rx_cal_busy, // RX channel calibration status
+ input tri0 rx_is_lockedtodata, // RX CDR PLL is locked to data status
+ input tri0 manual_mode // 0=Automatically reset RX after loss of rx_is_lockedtodata
+);
+
+localparam clk_in_mhz =
+`ifdef QUARTUS__SIMGEN
+ 2; // simulation-only value
+`elsif ALTERA_RESERVED_QIS
+ sys_clk_in_mhz; // use real counter lengths for normal Quartus synthesis
+`else
+ 2; // simulation-only value
+`endif
+localparam t_pll_powerdown = clk_in_mhz; // 1 us minimum
+localparam t_ltd_auto = clk_in_mhz*4; // 4 us minimum
+
+
+wire pll_is_locked_r; // pll_is_locked resynchronized
+wire tx_cal_busy_r; // tx_cal_busy resynchronized
+wire rx_cal_busy_r; // rx_cal_busy resynchronized
+wire rx_is_lockedtodata_r; // rx_is_lockedtodata resynchronized
+
+wire sdone_lego_pll_powerdown; // 'sequence done' output of pll_powerdown lego
+wire sdone_lego_tx_digitalreset;// 'sequence done' output of tx_digitalreset lego
+wire sdone_lego_rx_digitalreset;// 'sequence done' output of rx_digitalreset lego
+wire sdone_lego_rx_analogreset; // 'sequence done' output of rx_analogreset lego
+wire wire_tx_digital_only_reset;// reset output for TX digital-only
+wire wire_rx_digital_only_reset;// reset output for RX digital-only
+wire wire_tx_digitalreset; // TX digital full-reset source
+wire wire_rx_digitalreset; // RX digital full-reset source
+wire wire_rx_digital_retrigger; // Trigger new RX digital sequence after main sequence completes, and lose lock-to-data
+
+// Resynchronize input signals
+alt_xcvr_resync #(
+ .WIDTH(2)
+ ) alt_xcvr_resync_inst_0 (
+ .clk (clock),
+ .reset (1'b0),
+ .d ({pll_is_locked ,rx_is_lockedtodata }),
+ .q ({pll_is_locked_r,rx_is_lockedtodata_r})
+);
+
+alt_xcvr_resync #(
+ .WIDTH(2),
+ .INIT_VALUE(1)
+ ) alt_xcvr_resync_inst_1 (
+ .clk (clock),
+ .reset (1'b0),
+ .d ({rx_cal_busy,tx_cal_busy}),
+ .q ({rx_cal_busy_r,tx_cal_busy_r})
+);
+
+// First reset ctrl sequencer lego is for pll_powerdown generation
+alt_reset_ctrl_lego #(
+ .reset_hold_cycles(t_pll_powerdown) // hold pll_powerdown for 1us
+ ) lego_pll_powerdown ( .clock(clock),
+ .start(reset_all), // Do not use resynched version of reset_all here
+ .aclr(powerdown_all),
+ .reset(pll_powerdown),
+ .rdone(pll_is_locked_r),
+ .sdone(sdone_lego_pll_powerdown));
+
+// next reset ctrl sequencer lego is for tx_digitalreset generation
+alt_reset_ctrl_lego #(
+ .reset_hold_til_rdone(1) // hold until rdone arrives for this test case
+ ) lego_tx_digitalreset ( .clock(clock),
+ .start(reset_all),
+ .aclr(powerdown_all),
+ .reset(wire_tx_digitalreset),
+ .rdone(sdone_lego_pll_powerdown & ~tx_cal_busy_r),
+ .sdone(sdone_lego_tx_digitalreset));
+
+// next reset ctrl sequencer lego is for rx_analogreset generation
+alt_reset_ctrl_lego #(
+ .reset_hold_til_rdone(1), // hold until rdone arrives for this test case
+ .sdone_delay_cycles(2) // hold rx_analogreset 2 parallel_clock cycles after offset cancellation done
+ ) lego_rx_analogreset ( .clock(clock),
+ .start(reset_all),
+ .aclr(powerdown_all),
+ .reset(rx_analogreset),
+ .rdone(sdone_lego_tx_digitalreset & ~rx_cal_busy_r),
+ .sdone(sdone_lego_rx_analogreset));
+
+// last reset ctrl sequencer lego is for rx_digitalreset generation
+alt_reset_ctrl_lego #(
+ .reset_hold_til_rdone(1), // hold until rdone arrives for this test case
+ .sdone_delay_cycles(t_ltd_auto) // hold rx_digitalreset for 4us
+ ) lego_rx_digitalreset ( .clock(clock),
+ .start(~manual_mode & reset_all | wire_rx_digital_retrigger),
+ .aclr(powerdown_all),
+ .reset(wire_rx_digitalreset),
+ .rdone(sdone_lego_rx_analogreset & rx_is_lockedtodata_r),
+ .sdone(sdone_lego_rx_digitalreset));
+
+//////////// digital-only reset ////////////
+// separate reset ctrl sequencer lego for digital-only reset generation
+alt_reset_ctrl_lego #(
+ .reset_hold_cycles(3) // hold 2 parallel clock cycles (assumes sysclk slower or same freq as parallel clock)
+ ) lego_tx_digitalonly ( .clock(clock),
+ .start(reset_tx_digital | reset_all),
+ .aclr(powerdown_all),
+ .reset(wire_tx_digital_only_reset),
+ .rdone(sdone_lego_tx_digitalreset),
+ .sdone(tx_ready)); // TX status indicator for user
+
+alt_reset_ctrl_lego #(
+ .reset_hold_cycles(3) // hold 2 parallel clock cycles (assumes sysclk slower or same freq as parallel clock)
+ ) lego_rx_digitalonly ( .clock(clock),
+ .start(reset_rx_digital | (reset_all & ~manual_mode) | wire_rx_digital_retrigger),
+ .aclr(powerdown_all),
+ .reset(wire_rx_digital_only_reset),
+ .rdone(sdone_lego_rx_digitalreset),
+ .sdone(rx_ready)); // RX status indicator for user
+
+// digital resets have 2 possible sources: full-reset or digital-only
+assign tx_digitalreset = wire_tx_digitalreset | wire_tx_digital_only_reset;
+assign rx_digitalreset = wire_rx_digitalreset | wire_rx_digital_only_reset;
+
+// re-trigger RX digital sequence when main sequence is complete (indicated by sdone_lego_rx_digitalreset)
+// not manual mode, and lose lock-to-data
+assign wire_rx_digital_retrigger = ~manual_mode & sdone_lego_rx_digitalreset & ~rx_is_lockedtodata_r;
+
+// Quad power-down
+assign gxb_powerdown = powerdown_all;
+
+
+////////////////////////
+// general assertions
+//synopsys translate_off
+// vlog/vcs/ncverilog: +define+ALTERA_XCVR_ASSERTIONS
+`ifdef ALTERA_XCVR_ASSERTIONS
+always @(posedge clock) begin
+ // reset_all starts by triggering CMU PLL powerdown
+ assert property ($rose(reset_all) |=> $rose(pll_powerdown));
+ // While CMU PLL powerdown is asserted, all other resets must be asserted
+ assert property (pll_powerdown |-> (tx_digitalreset & rx_analogreset & rx_digitalreset));
+ // While rx_analogreset is asserted, rx_digitalreset must be asserted
+ assert property (rx_analogreset |-> rx_digitalreset);
+ // When pll_is_locked is asserted, tx_digitalreset must be deasserted
+ assert property ($rose(pll_is_locked_r) |-> ##[0:2] !tx_digitalreset);
+ // During a reset, rx_digitalreset should remain high for t_ltd_auto after rx_is_lockedtodata rising edge
+ assert property ($rose(rx_is_lockedtodata_r) & ~manual_mode|-> rx_digitalreset [*(t_ltd_auto+1)] ##1 !rx_digitalreset);
+ assert property ($rose(rx_is_lockedtodata_r) & manual_mode|->!rx_digitalreset);
+ // reset_tx_digital results in only a brief pulse on tx_digitalreset
+ assert property ($rose(reset_tx_digital) |=> tx_digitalreset [*3] );
+ assert property ($rose(reset_tx_digital) & tx_ready |=> tx_digitalreset [*3] ##1 ~tx_digitalreset ##1 $rose(tx_ready) );
+ // reset_rx_digital results in only a brief pulse on rx_digitalreset
+ assert property ($rose(reset_rx_digital) |=> rx_digitalreset [*3] );
+ assert property ($rose(reset_rx_digital) & rx_ready |=> rx_digitalreset [*3] ##1 ~rx_digitalreset ##1 $rose(rx_ready) );
+end
+`endif
+//synopsys translate_on
+
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_pcs.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_pcs.v
new file mode 100644
index 0000000..927f794
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_pcs.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_reset.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_reset.v
new file mode 100644
index 0000000..b03c675
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_reset.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx.v
new file mode 100644
index 0000000..00e15bf
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_8b10b_dec.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_8b10b_dec.v
new file mode 100644
index 0000000..ebdcf84
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_8b10b_dec.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_channel_synch.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_channel_synch.v
new file mode 100644
index 0000000..9ce0de0
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_channel_synch.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew.v
new file mode 100644
index 0000000..7465f86
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew_channel.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew_channel.v
new file mode 100644
index 0000000..22c52e1
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew_channel.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew_ram.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew_ram.v
new file mode 100644
index 0000000..dadc44e
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_deskew_ram.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_invalid_code_det.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_invalid_code_det.v
new file mode 100644
index 0000000..67a3c3d
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_invalid_code_det.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity.v
new file mode 100644
index 0000000..55b1a01
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity_4b.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity_4b.v
new file mode 100644
index 0000000..c528b60
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity_4b.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity_6b.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity_6b.v
new file mode 100644
index 0000000..22ff647
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_parity_6b.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rate_match.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rate_match.v
new file mode 100644
index 0000000..f3c95f2
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rate_match.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rate_match_ram.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rate_match_ram.v
new file mode 100644
index 0000000..adbaf17
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rate_match_ram.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rl_chk_6g.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rl_chk_6g.v
new file mode 100644
index 0000000..254d74b
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_rl_chk_6g.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_sm.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_sm.v
new file mode 100644
index 0000000..37bd091
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_rx_sm.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx.v
new file mode 100644
index 0000000..8cab1fb
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx_8b10b_enc.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx_8b10b_enc.v
new file mode 100644
index 0000000..e58f8d3
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx_8b10b_enc.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx_idle_conv.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx_idle_conv.v
new file mode 100644
index 0000000..49e7aa7
Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_soft_xaui_tx_idle_conv.v differ
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xaui_phy_top.sdc b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xaui_phy_top.sdc
new file mode 100644
index 0000000..8af75e8
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xaui_phy_top.sdc
@@ -0,0 +1,98 @@
+# (C) 2001-2018 Intel Corporation. All rights reserved.
+# Your use of Intel Corporation's design tools, logic functions and other
+# software and tools, and its AMPP partner logic functions, and any output
+# files from any of the foregoing (including device programming or simulation
+# files), and any associated documentation or information are expressly subject
+# to the terms and conditions of the Intel Program License Subscription
+# Agreement, Intel FPGA IP License Agreement, or other applicable
+# license agreement, including, without limitation, that your use is for the
+# sole purpose of programming logic devices manufactured by Intel and sold by
+# Intel or its authorized distributors. Please refer to the applicable
+# agreement for further details.
+
+
+#-----------------------------------------------------------------------------
+#
+# Description: SDC file for alt_xaui
+#
+# Authors: bauyeung
+#
+# Copyright (c) Altera Corporation 1997 - 2010
+# All rights reserved.
+#
+#
+#-----------------------------------------------------------------------------
+
+#set_time_format -unit ns -decimal_places 3
+#derive_pll_clocks
+#derive_clock_uncertainty
+
+#
+# input clocks
+#
+#create_clock -name {xgmii_tx_clk} \
+# -period 6.400 -waveform {0.000 3.2} \
+# [ get_ports {xgmii_tx_clk} ]
+#create_clock -name {phy_mgmt_clk} \
+# -period 20.000 -waveform {0.000 10.0} \
+# [ get_ports {phy_mgmt_clk} ]
+#create_clock -name {refclk} \
+# -period 6.400 -waveform {0.000 3.2} \
+# [ get_ports {pll_ref_clk} ]
+
+
+proc alt_xcvr_xaui_constraint_ptrs {from_node_list to_node_list} {
+ set_net_delay -from $from_node_list -to $to_node_list -max 6ns
+ set_max_delay -from $from_node_list -to $to_node_list 100
+ set_min_delay -from $from_node_list -to $to_node_list -100
+}
+
+set TQ2 [get_global_assignment -name TIMEQUEST2]
+
+if {$TQ2=="ON"} {
+
+ # Cut path
+ set_false_path -from [get_registers {*a10_xcvr_xaui*hxaui_csr*hxaui_csr_reset0q[1]}] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*tx_reset*]
+ set_false_path -from [get_registers {*a10_xcvr_xaui*hxaui_csr*hxaui_csr_reset0q[1]}] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*rx_reset*]
+ set_false_path -from [get_registers {*a10_xcvr_xaui*hxaui_csr*hxaui_csr_simulation_flag0q}] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*pcs_reset*simulation_flag_f]
+
+ set_false_path -from [get_registers *alt_soft_xaui_pcs|tx_reset_n] -to [get_registers *xaui_tx|reset_tx_clk_n]
+ set_false_path -from [get_registers *alt_soft_xaui_pcs|tx_reset_n] -to [get_registers *xaui_tx|reset_tx_clk_n_meta]
+
+ set_false_path -from [get_registers *sxaui_0*alt_soft_xaui_pcs*rx_reset_n] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*xaui_rx*reset_channel_n_meta]
+ set_false_path -from [get_registers *sxaui_0*alt_soft_xaui_pcs*rx_reset_n] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*xaui_rx*reset_channel_n]
+ set_false_path -from [get_registers *sxaui_0*alt_soft_xaui_pcs*rx_reset_n] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*xaui_rx*reset_sysclk_n_meta]
+ set_false_path -from [get_registers *sxaui_0*alt_soft_xaui_pcs*rx_reset_n] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*xaui_rx*reset_sysclk_n]
+
+
+ # Check for instances
+ set from_path pcs_rate_match
+ set from_reg flag_rd
+ set inst [get_registers -nowarn *$from_path*$from_reg]
+
+ set inst_list [query_collection -list -all $inst]
+ foreach each_inst $inst_list {
+ # Get the path to instance
+ regexp "(.*${from_path}.*|)(${from_reg})" $each_inst reg_path inst_path reg_name
+
+ # Set delay
+ alt_xcvr_xaui_constraint_ptrs [get_registers "${inst_path}*flag_rd"] [get_registers "${inst_path}*sync_flag_rd_wr*din_s1"]
+ alt_xcvr_xaui_constraint_ptrs [get_registers "${inst_path}*flag_wr"] [get_registers "${inst_path}*sync_flag_wr_rd*din_s1"]
+
+ alt_xcvr_xaui_constraint_ptrs [get_registers "${inst_path}*wr_ptr_latched_del[*]"] [get_registers "${inst_path}*wr_ptr_rd[*]"]
+ alt_xcvr_xaui_constraint_ptrs [get_registers "${inst_path}*rd_ptr_latched_del[*]"] [get_registers "${inst_path}*rd_ptr_wr[*]"]
+
+ # Set skew
+ set_max_skew -from [get_registers "${inst_path}flag_rd ${inst_path}rd_ptr_latched_del[*]"] -to [get_registers "${inst_path}*sync_flag_rd_wr*din_s1 ${inst_path}rd_ptr_wr[*]"] 6.4ns
+ set_max_skew -from [get_registers "${inst_path}flag_wr ${inst_path}wr_ptr_latched_del[*]"] -to [get_registers "${inst_path}*sync_flag_wr_rd*din_s1 ${inst_path}wr_ptr_rd[*]"] 6.4ns
+
+ }
+
+
+}
+
+
+
+
+
+
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_arbiter.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_arbiter.sv
new file mode 100644
index 0000000..de0d18b
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_arbiter.sv
@@ -0,0 +1,68 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+// Clocked priority encoder with state
+//
+// On each clock cycle, updates state to show which request is granted.
+// Most recent grant holder is always the highest priority.
+// If current grant holder is not making a request, while others are,
+// then new grant holder is always the requester with lowest bit number.
+// If no requests, current grant holder retains grant state
+
+// $Header$
+
+`timescale 1 ns / 1 ns
+
+module alt_xcvr_arbiter #(
+ parameter width = 2
+) (
+ input wire clock,
+ input wire [width-1:0] req, // req[n] requests for this cycle
+ output reg [width-1:0] grant // grant[n] means requester n is grantee in this cycle
+);
+
+ wire idle; // idle when no requests
+ wire [width-1:0] keep; // keep[n] means requester n is requesting, and already has the grant
+ // Note: current grantee is always highest priority for next grant
+ wire [width-1:0] take; // take[n] means requester n is requesting, and there are no higher-priority requests
+
+ assign keep = req & grant; // current grantee is always highest priority for next grant
+ assign idle = ~| req; // idle when no requests
+
+ initial begin
+ grant = 0;
+ end
+
+ // grant next state depends on current grant and take priority
+ always @(posedge clock) begin
+ grant <=
+// synthesis translate_off
+ (grant === {width{1'bx}})? {width{1'b0}} :
+// synthesis translate_on
+ keep // if current grantee is requesting, gets to keep grant
+ | ({width{idle}} & grant) // if no requests, grant state remains unchanged
+ | take; // take applies only if current grantee is not requesting
+ end
+
+ // 'take' bus encodes priority. Request with lowest bit number wins when current grantee not requesting
+ assign take[0] = req[0]
+ & (~| (keep & ({width{1'b1}} << 1))); // no 'keep' from lower-priority inputs
+ genvar i;
+ generate
+ for (i=1; i < width; i = i + 1) begin : arb
+ assign take[i] = req[i]
+ & (~| (keep & ({width{1'b1}} << (i+1)))) // no 'keep' from lower-priority inputs
+ & (~| (req & {i{1'b1}})); // no 'req' from higher-priority inputs
+ end
+ endgenerate
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_common.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_common.sv
new file mode 100644
index 0000000..5874d12
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_common.sv
@@ -0,0 +1,238 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Common control & status register map for transceiver PHY IP
+// Applies to Stratix V-generation basic PHY components
+//
+// $Header$
+//
+
+`timescale 1 ps / 1 ps
+
+module alt_xcvr_csr_common #(
+ parameter lanes = 1,
+ parameter plls = 1,
+ parameter rpc = 0 // reset per channel
+)
+(
+ // user data (avalon-MM formatted)
+ input wire clk,
+ input tri0 reset,
+ input wire [7:0] address,
+ input tri0 read,
+ output reg [31:0] readdata = 0,
+ input tri0 write,
+ input wire [31:0] writedata,
+
+ // transceiver status inputs to this CSR
+ input wire [plls - 1 : 0] pll_locked,
+ input wire [lanes - 1 : 0] rx_is_lockedtoref,
+ input wire [lanes - 1 : 0] rx_is_lockedtodata,
+ input wire [lanes - 1 : 0] rx_signaldetect,
+
+ // reset controller outputs
+ input wire reset_controller_tx_ready,
+ input wire reset_controller_rx_ready,
+ input wire reset_controller_pll_powerdown,
+ input wire [(rpc?lanes:1)-1:0]reset_controller_tx_digitalreset,
+ input wire [(rpc?lanes:1)-1:0]reset_controller_rx_analogreset,
+ input wire [(rpc?lanes:1)-1:0]reset_controller_rx_digitalreset,
+
+ // read/write control registers
+ // to reset controller
+ output reg csr_reset_tx_digital = 0,
+ output reg csr_reset_rx_digital = 0,
+ output reg csr_reset_all = 1, // power-up to 1 to trigger auto-init sequence
+ // to PMA and PCS reset inputs
+ output wire csr_pll_powerdown, // reset controller or manual
+ output wire [lanes - 1 : 0] csr_tx_digitalreset, // reset controller or manual
+ output wire [lanes - 1 : 0] csr_rx_analogreset, // reset controller or manual
+ output wire [lanes - 1 : 0] csr_rx_digitalreset, // reset controller or manual
+ // common PMA controls
+ output reg [lanes - 1 : 0] csr_phy_loopback_serial = 0,
+ output reg [lanes - 1 : 0] csr_rx_set_locktoref = 0,
+ output reg [lanes - 1 : 0] csr_rx_set_locktodata = 0
+);
+ import alt_xcvr_csr_common_h::*;
+
+ localparam sync_stages = 2; // number of sync stages for transceiver status signals
+ localparam sync_stages_str = sync_stages[7:0] + 8'd48; // number of sync stages specified as string (for timing constraints)
+
+ integer stage;
+
+ // Parameter strings for embedded timing constraints
+ localparam CSR_PLLLOCKED_CONSTRAINT = {"-name SDC_STATEMENT \"set regs [get_registers -nowarn *alt_xcvr_csr_common*csr_pll_locked*[",sync_stages_str,"]*]; if {[llength [query_collection -report -all $regs]] > 0} {set_false_path -to $regs}\""};
+ localparam CSR_RXISLOCKED_CONSTRAINT = {"-name SDC_STATEMENT \"set regs [get_registers -nowarn *alt_xcvr_csr_common*csr_rx_is_locked*[",sync_stages_str,"]*]; if {[llength [query_collection -report -all $regs]] > 0} {set_false_path -to $regs}\""};
+ localparam CSR_RXSIGNALDET_CONSTRAINT = {"-name SDC_STATEMENT \"set regs [get_registers -nowarn *alt_xcvr_csr_common*csr_rx_signaldetect*[",sync_stages_str,"]*]; if {[llength [query_collection -report -all $regs]] > 0} {set_false_path -to $regs}\""};
+ localparam SDC_CONSTRAINTS = {CSR_PLLLOCKED_CONSTRAINT,";",CSR_RXISLOCKED_CONSTRAINT,";",CSR_RXSIGNALDET_CONSTRAINT};
+
+ // internal control registers
+ reg [lanes - 1 : 0] csr_interrupt_ch_bitmask = {lanes{1'b1}};
+ // fine reset control. 'OR' with reset controller equivalent signals
+ reg csr_reset_or_pll_powerdown = 0; // fine reset control
+ reg csr_reset_or_reset_tx_digital = 0; // fine reset control
+ reg csr_reset_or_reset_rx_analog = 0; // fine reset control
+ reg csr_reset_or_reset_rx_digital = 0; // fine reset control
+ reg [lanes - 1 : 0] csr_reset_ch_bitmask = {lanes{1'b1}};
+ reg [1:0] csr_reset_tx_digital_r;
+ reg [1:0] csr_reset_rx_digital_r;
+
+ // read-only status registers
+ // These are synchronized forms of transceiver status signals
+ // async inputs go to reg [sync_stages], and come out synchronized at reg [1]
+ (* altera_attribute = SDC_CONSTRAINTS *) // Apply timing constraints (does not matter which node)
+ reg [plls - 1 : 0] csr_pll_locked [sync_stages:1];
+ reg [lanes - 1 : 0] csr_rx_is_lockedtoref [sync_stages:1];
+ reg [lanes - 1 : 0] csr_rx_is_lockedtodata [sync_stages:1];
+ reg [lanes - 1 : 0] csr_rx_signaldetect [sync_stages:1];
+
+ // Internal expansion of reset controller inputs
+ wire [lanes-1:0] w_reset_controller_tx_digitalreset;
+ wire [lanes-1:0] w_reset_controller_rx_analogreset;
+ wire [lanes-1:0] w_reset_controller_rx_digitalreset;
+ // Internal expansion of reset override registers
+ wire [lanes-1:0] w_csr_reset_or_reset_tx_digital; // fine reset control
+ wire [lanes-1:0] w_csr_reset_or_reset_rx_analog; // fine reset control
+ wire [lanes-1:0] w_csr_reset_or_reset_rx_digital; // fine reset control
+
+ // Synchronization registers
+ always @(posedge clk) begin
+ // synchronization registers for status signals from transceivers
+ csr_pll_locked [sync_stages] <= pll_locked; // input from transceiver
+ csr_rx_is_lockedtoref [sync_stages] <= rx_is_lockedtoref;
+ csr_rx_is_lockedtodata[sync_stages] <= rx_is_lockedtodata;
+ csr_rx_signaldetect [sync_stages] <= rx_signaldetect;
+ for (stage=2; stage <= sync_stages; stage = stage + 1) begin
+ // additional sync stages
+ csr_pll_locked [stage-1] <= csr_pll_locked [stage];
+ csr_rx_is_lockedtoref [stage-1] <= csr_rx_is_lockedtoref [stage];
+ csr_rx_is_lockedtodata[stage-1] <= csr_rx_is_lockedtodata [stage];
+ csr_rx_signaldetect [stage-1] <= csr_rx_signaldetect [stage];
+ end
+ end
+
+ always @(posedge clk or posedge reset) begin
+ if (reset == 1) begin
+ readdata <= 0;
+ csr_interrupt_ch_bitmask <= {lanes{1'b1}};
+
+ csr_reset_tx_digital <= 0;
+ csr_reset_rx_digital <= 0;
+ csr_reset_tx_digital_r <= 2'b00;
+ csr_reset_rx_digital_r <= 2'b00;
+ csr_reset_all <= 1; // reset to 1 to trigger auto-init sequence
+ csr_reset_ch_bitmask <= {lanes{1'b1}};
+ csr_reset_or_pll_powerdown <= 0; // fine reset control
+ csr_reset_or_reset_tx_digital <= 0; // fine reset control
+ csr_reset_or_reset_rx_analog <= 0; // fine reset control
+ csr_reset_or_reset_rx_digital <= 0; // fine reset control
+
+ csr_phy_loopback_serial <= 0;
+ csr_rx_set_locktoref <= 0;
+ csr_rx_set_locktodata <= 0;
+ end
+ else begin
+ // decode read & write for each supported address
+ case (address)
+ // interrupt control
+ ADDR_INTERRUPT_CH_BITMASK: begin
+ readdata <= (32'd0 | csr_interrupt_ch_bitmask);
+ if (write) csr_interrupt_ch_bitmask <= writedata[lanes-1:0];
+ end
+
+ // reset control
+ ADDR_RESET_CONTROL: begin
+ // on read, returns two bits: bit0: TX ready, bit1: RX ready
+ readdata <= (32'd0 | {reset_controller_rx_ready, reset_controller_tx_ready});
+ // on write, bit0 is 'reset_tx_digital', bit1 is 'reset_rx_digital', bit2 is 'reset_all'
+ //if (write) begin
+ // reset_all write side-effect: when write a '1', force all reset_ch_bitmask bits to '1'
+ // csr_reset_ch_bitmask <= csr_reset_ch_bitmask | {(lanes){writedata[2]}};
+ //end
+ end
+ ADDR_RESET_CH_BITMASK: begin
+ readdata <= (32'd0 | csr_reset_ch_bitmask);
+ if (write) csr_reset_ch_bitmask <= writedata[lanes-1:0];
+ end
+
+ // loopback control
+ ADDR_PHY_LOOPBACK_SERIAL,
+ ADDR_PMA_LOOPBACK_SERIAL: begin
+ readdata <= (32'd0 | csr_phy_loopback_serial);
+ if (write) csr_phy_loopback_serial <= writedata[lanes-1:0];
+ end
+
+ // PMA control and status
+ ADDR_PMA_RX_SET_LOCKTOREF: begin
+ readdata <= (32'd0 | csr_rx_set_locktoref);
+ if (write) csr_rx_set_locktoref <= writedata[lanes-1:0];
+ end
+ ADDR_PMA_RX_SET_LOCKTODATA: begin
+ readdata <= (32'd0 | csr_rx_set_locktodata);
+ if (write) csr_rx_set_locktodata <= writedata[lanes-1:0];
+ end
+ // PMA status (read-only)
+ ADDR_PMA_PLL_IS_LOCKED: readdata <= (32'd0 | csr_pll_locked[1]);
+ ADDR_PMA_RX_IS_LOCKEDTOREF: readdata <= (32'd0 | csr_rx_is_lockedtoref[1]);
+ ADDR_PMA_RX_IS_LOCKEDTODATA: readdata <= (32'd0 | csr_rx_is_lockedtodata[1]);
+ ADDR_PMA_RX_SIGNALDETECT: readdata <= (32'd0 | csr_rx_signaldetect[1]);
+
+ // Fine reset control - device dependent
+ ADDR_RESET_FINE_CONTROL: begin
+ // bit 0: 'pll_powerdown', 1: 'reset_tx_digital', 2: 'reset_rx_analog', 3: 'reset_rx_digital'
+
+ readdata <= (32'd0 | {csr_reset_or_reset_rx_digital, csr_reset_or_reset_rx_analog,
+ csr_reset_or_reset_tx_digital, csr_reset_or_pll_powerdown});
+ if (write) begin
+ csr_reset_or_pll_powerdown <= writedata[0]; // fine reset control
+ csr_reset_or_reset_tx_digital <= writedata[1]; // fine reset control
+ csr_reset_or_reset_rx_analog <= writedata[2]; // fine reset control
+ csr_reset_or_reset_rx_digital <= writedata[3]; // fine reset control
+ end
+ end
+
+
+ default: readdata <= ~ 32'd0; // use too many LEs?
+ endcase
+
+ // special handling for registers that must auto-clear on cycle after a write
+ // reset control. on write, bit0 is 'reset_tx_digital', bit1 is 'reset_rx_digital', bit2 is 'reset_all'
+ {csr_reset_tx_digital,csr_reset_tx_digital_r} <= ((address == ADDR_RESET_CONTROL) & write & writedata[0])
+ ? 3'b111 : {csr_reset_tx_digital_r,1'b0};
+ {csr_reset_rx_digital,csr_reset_rx_digital_r} <= ((address == ADDR_RESET_CONTROL) & write & writedata[1])
+ ? 3'b111 : {csr_reset_rx_digital_r,1'b0};
+ csr_reset_all <= (address == ADDR_RESET_CONTROL) & write & writedata[2];
+
+ end
+ end
+
+ // combine reset controller and CSR manual reset control settings
+ assign w_reset_controller_tx_digitalreset = {(rpc?1:lanes){reset_controller_tx_digitalreset}};
+ assign w_reset_controller_rx_analogreset = {(rpc?1:lanes){reset_controller_rx_analogreset}};
+ assign w_reset_controller_rx_digitalreset = {(rpc?1:lanes){reset_controller_rx_digitalreset}};
+
+ assign w_csr_reset_or_reset_tx_digital = {lanes{csr_reset_or_reset_tx_digital}}; // fine reset control
+ assign w_csr_reset_or_reset_rx_analog = {lanes{csr_reset_or_reset_rx_analog}}; // fine reset control
+ assign w_csr_reset_or_reset_rx_digital = {lanes{csr_reset_or_reset_rx_digital}}; // fine reset control
+
+ assign csr_pll_powerdown = reset_controller_pll_powerdown; // cut manual PLL reset path
+ // | csr_reset_or_pll_powerdown;
+ assign csr_tx_digitalreset = csr_reset_ch_bitmask &
+ (w_reset_controller_tx_digitalreset | w_csr_reset_or_reset_tx_digital);
+ assign csr_rx_analogreset = csr_reset_ch_bitmask &
+ (w_reset_controller_rx_analogreset | w_csr_reset_or_reset_rx_analog);
+ assign csr_rx_digitalreset = csr_reset_ch_bitmask &
+ (w_reset_controller_rx_digitalreset | w_csr_reset_or_reset_rx_digital);
+
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_common_h.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_common_h.sv
new file mode 100644
index 0000000..64646ac
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_common_h.sv
@@ -0,0 +1,61 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Common control & status register map for transceiver PHY IP
+// Applies to Stratix V-generation basic PHY components
+//
+// $Header$
+//
+// PACKAGE DECLARATION
+
+`timescale 1 ps / 1 ps
+
+package alt_xcvr_csr_common_h;
+
+ localparam alt_xcvr_csr_addr_width = 8;
+
+ // register bitmap ---------------------------------------------------------
+ // common blocks, interrupt control
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_INTERRUPT_CH_BITMASK = 1;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_INTERRUPT_ENABLE_BITMASK = 2;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_INTERRUPT_SOURCE = 3;
+
+ // common blocks, loopback control
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PHY_LOOPBACK_SERIAL = 6;
+
+ // common blocks, reset control
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_RESET_CONTROL_BASE = 64;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_RESET_CH_BITMASK = ADDR_RESET_CONTROL_BASE + 8'd1;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_RESET_CONTROL = ADDR_RESET_CONTROL_BASE + 8'd2;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_RESET_FINE_CONTROL = ADDR_RESET_CONTROL_BASE + 8'd4;
+
+ // common blocks, PMA common control & status
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_COMMON_BASE = 32;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_PLL_IS_LOCKED = ADDR_PMA_COMMON_BASE + 8'd2;
+ // common blocks, PMA channel control & status
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_CHANNEL_BASE = 96;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_LOOPBACK_SERIAL = ADDR_PMA_CHANNEL_BASE + 8'd1;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_RX_SIGNALDETECT = ADDR_PMA_CHANNEL_BASE + 8'd3;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_RX_SET_LOCKTODATA = ADDR_PMA_CHANNEL_BASE + 8'd4;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_RX_SET_LOCKTOREF = ADDR_PMA_CHANNEL_BASE + 8'd5;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_RX_IS_LOCKEDTODATA = ADDR_PMA_CHANNEL_BASE + 8'd6;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PMA_RX_IS_LOCKEDTOREF = ADDR_PMA_CHANNEL_BASE + 8'd7;
+
+ // external block for PCS control & status
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS_BASE = 128; // 128-255
+
+ // First word in every PCS CSR is lane # (or lane group # as appropriate)
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS_LANE_GROUP = ADDR_PCS_BASE + 8'd0;
+
+endpackage
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_pcs8g.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_pcs8g.sv
new file mode 100644
index 0000000..b55363b
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_pcs8g.sv
@@ -0,0 +1,351 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Common control & status register map for transceiver PHY IP
+// Applies to Stratix V-generation basic PHY components
+//
+// $Header$
+//
+
+`timescale 1 ns / 1 ns
+
+module alt_xcvr_csr_pcs8g #(
+ parameter lanes = 1,
+ parameter words = 2, // for status bits that are per-word, like 8B10B status
+ parameter boundary_width = 5
+)
+(
+ // user data (avalon-MM formatted)
+ input wire clk,
+ input tri0 reset,
+ input wire [7:0] address,
+ input tri0 read,
+ output reg [31:0] readdata = 0,
+ input tri0 write,
+ input wire [31:0] writedata,
+
+ input wire rx_clk, // to synchronize rx control outputs
+ input wire tx_clk, // to synchronize tx control outputs
+
+ // transceiver status inputs to this CSR
+ input wire [lanes*words - 1 : 0] rx_patterndetect,
+ input wire [lanes*words - 1 : 0] rx_syncstatus,
+ input wire [lanes*words - 1 : 0] rx_errdetect,
+ input wire [lanes*words - 1 : 0] rx_disperr,
+ input wire [lanes - 1 : 0] rx_phase_comp_fifo_error,
+ input wire [lanes - 1 : 0] tx_phase_comp_fifo_error,
+ input wire [lanes*boundary_width - 1: 0] rx_bitslipboundaryselectout,
+ input wire [lanes - 1 : 0] rlv,
+ input wire [lanes*words - 1 : 0] rx_a1a2sizeout,
+
+ // read/write control outputs
+ // PCS controls
+ output wire [lanes - 1 : 0] csr_tx_invpolarity,
+ output wire [lanes*boundary_width - 1 : 0] csr_tx_bitslipboundaryselect,
+ output wire [lanes - 1 : 0] csr_rx_invpolarity,
+ output wire [lanes - 1 : 0] csr_rx_enapatternalign,
+ output wire [lanes - 1 : 0] csr_rx_bitreversalenable,
+ output wire [lanes - 1 : 0] csr_rx_bytereversalenable,
+ output wire [lanes - 1 : 0] csr_rx_bitslip,
+ output wire [lanes - 1 : 0] csr_rx_a1a2size
+);
+ import alt_xcvr_csr_common_h::*;
+ import alt_xcvr_csr_pcs8g_h::*;
+
+ localparam sync_stages = 2; // number of sync stages for transceiver status signals
+ localparam sync_stages_str = sync_stages[7:0] + 8'd48; // number of sync stages specified as string (for timing constraints)
+ localparam LANE_REGW = 5;
+
+ // Parameter strings for embedded timing constraints
+ localparam SYNC_RX_CONSTRAINT = {"-name SDC_STATEMENT \"set regs [get_registers -nowarn *alt_xcvr_csr_pcs8g*sync_rx_*[",sync_stages_str,"]*]; if {[llength [query_collection -report -all $regs]] > 0} {set_false_path -to $regs}\""};
+ localparam SYNC_TX_CONSTRAINT = {"-name SDC_STATEMENT \"set regs [get_registers -nowarn *alt_xcvr_csr_pcs8g*sync_tx_*[",sync_stages_str,"]*]; if {[llength [query_collection -report -all $regs]] > 0} {set_false_path -to $regs}\""};
+ localparam CSR_REG_CONSTRAINT = {"-name SDC_STATEMENT \"set regs [get_registers -nowarn *alt_xcvr_csr_pcs8g*csr_indexed_read_only_reg*sreg[",sync_stages_str,"]*]; if {[llength [query_collection -report -all $regs]] > 0} {set_false_path -to $regs}\""};
+ localparam SDC_CONSTRAINTS = {SYNC_RX_CONSTRAINT,";",SYNC_TX_CONSTRAINT,";",CSR_REG_CONSTRAINT};
+
+ // internal registers
+ reg [LANE_REGW-1:0] reg_lane_number = 0; // lane or group number for indirection
+
+ ////////////////////////////////////////////////////////
+ // Read/Write CSR registers with lane indirection
+ ////////////////////////////////////////////////////////
+ // Apply false path timing constraints to synchronization registers. (It does not matter as to which node these are applied).
+ (* altera_attribute = SDC_CONSTRAINTS *)
+ reg [lanes - 1 : 0] reg_tx_invpolarity = 0;
+ reg [lanes - 1 : 0] sync_tx_invpolarity [sync_stages:1]; // synchronize to tx_clk
+ wire [lanes - 1 : 0] write_tx_invpolarity; // indexed write group muxed in
+ wire [0 : 0] lane_tx_invpolarity; // selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .init_value(0))
+ wmux_tx_invpolarity(.in_narrow(writedata[0]),
+ .in_wide(reg_tx_invpolarity), .sel(reg_lane_number),
+ .out_narrow(lane_tx_invpolarity), .out_wide(write_tx_invpolarity));
+
+ reg [lanes*boundary_width - 1 : 0] reg_tx_bitslipboundaryselect = 0;
+ reg [lanes*boundary_width - 1 : 0] sync_tx_bitslipboundaryselect [sync_stages:1]; //synchronize to tx_clk
+ wire [lanes*boundary_width - 1 : 0] write_tx_bitslipboundaryselect; //indexed write group muxed in
+ wire [boundary_width-1:0] lane_tx_bitslipboundaryselect; //selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(boundary_width), .sel_size(LANE_REGW), .init_value(0))
+ wmux_tx_bitslipboundaryselect(.in_narrow(writedata[boundary_width:1]),
+ .in_wide(reg_tx_bitslipboundaryselect), .sel(reg_lane_number),
+ .out_narrow(lane_tx_bitslipboundaryselect), .out_wide(write_tx_bitslipboundaryselect));
+
+ reg [lanes - 1 : 0] reg_rx_invpolarity = 0;
+ reg [lanes - 1 : 0] sync_rx_invpolarity [sync_stages:1]; // synchronize to rx_clk
+ wire [lanes - 1 : 0] write_rx_invpolarity; // indexed write group muxed in
+ wire [0 : 0] lane_rx_invpolarity; // selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .init_value(0))
+ wmux_rx_invpolarity(.in_narrow(writedata[0]),
+ .in_wide(reg_rx_invpolarity), .sel(reg_lane_number),
+ .out_narrow(lane_rx_invpolarity), .out_wide(write_rx_invpolarity));
+
+ reg [lanes - 1 : 0] reg_rx_enapatternalign = 0;
+ reg [lanes - 1 : 0] sync_rx_enapatternalign [sync_stages:1]; // synchronize to rx_clk
+ wire [lanes - 1 : 0] write_rx_enapatternalign; // indexed write group muxed in
+ wire [0 : 0] lane_rx_enapatternalign; // selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .init_value(0))
+ wmux_rx_enapatternalign(.in_narrow(writedata[0]),
+ .in_wide(reg_rx_enapatternalign), .sel(reg_lane_number),
+ .out_narrow(lane_rx_enapatternalign), .out_wide(write_rx_enapatternalign));
+
+ reg [lanes - 1 : 0] reg_rx_bitreversalenable = 0;
+ reg [lanes - 1 : 0] sync_rx_bitreversalenable [sync_stages:1]; // synchronize to rx_clk
+ wire [lanes - 1 : 0] write_rx_bitreversalenable; // indexed write group muxed in
+ wire [0 : 0] lane_rx_bitreversalenable; // selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .init_value(0))
+ wmux_rx_bitreversalenable(.in_narrow(writedata[1]),
+ .in_wide(reg_rx_bitreversalenable), .sel(reg_lane_number),
+ .out_narrow(lane_rx_bitreversalenable), .out_wide(write_rx_bitreversalenable));
+
+ reg [lanes - 1 : 0] reg_rx_bytereversalenable = 0;
+ reg [lanes - 1 : 0] sync_rx_bytereversalenable [sync_stages:1]; // synchronize to rx_clk
+ wire [lanes - 1 : 0] write_rx_bytereversalenable; // indexed write group muxed in
+ wire [0 : 0] lane_rx_bytereversalenable; // selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .init_value(0))
+ wmux_rx_bytereversalenable(.in_narrow(writedata[2]),
+ .in_wide(reg_rx_bytereversalenable), .sel(reg_lane_number),
+ .out_narrow(lane_rx_bytereversalenable), .out_wide(write_rx_bytereversalenable));
+
+ reg [lanes - 1 : 0] reg_rx_bitslip = 0;
+ reg [lanes - 1 : 0] sync_rx_bitslip [sync_stages:1]; // synchronize to rx_clk
+ wire [lanes - 1 : 0] write_rx_bitslip; // indexed write group muxed in
+ wire [0 : 0] lane_rx_bitslip; // selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .init_value(0))
+ wmux_rx_bitslip(.in_narrow(writedata[3]),
+ .in_wide(reg_rx_bitslip), .sel(reg_lane_number),
+ .out_narrow(lane_rx_bitslip), .out_wide(write_rx_bitslip));
+
+ reg [lanes - 1 : 0] reg_rx_a1a2size = 0;
+ reg [lanes - 1 : 0] sync_rx_a1a2size [sync_stages:1]; // synchronize to rx_clk
+ wire [lanes - 1 : 0] write_rx_a1a2size; // indexed write group muxed in
+ wire [0 : 0] lane_rx_a1a2size; // selected group indexed for output
+ csr_indexed_write_mux #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .init_value(0))
+ wmux_rx_a1a2size(.in_narrow(writedata[3]),
+ .in_wide(reg_rx_a1a2size), .sel(reg_lane_number),
+ .out_narrow(lane_rx_a1a2size), .out_wide(write_rx_a1a2size));
+
+ ////////////////////////////////////////////////////////
+ // Read-only CSR registers with lane indirection
+ ////////////////////////////////////////////////////////
+ // read-only status registers are synchronized forms of transceiver status signals
+ // async inputs go to reg [sync_stages], and come out synchronized at reg [1]
+ ////////////////////////////////////////////////////////
+ // read selectors (muxes) that index using the indirect lane (group) number
+ wire [words-1 : 0] lane_rx_patterndetect;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(words), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rx_patterndetect(.clk(clk), .async_in_wide(rx_patterndetect),
+ .sel(reg_lane_number), .out_narrow(lane_rx_patterndetect));
+
+ wire [words-1 : 0] lane_rx_syncstatus;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(words), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rx_syncstatus(.clk(clk), .async_in_wide(rx_syncstatus),
+ .sel(reg_lane_number), .out_narrow(lane_rx_syncstatus));
+
+ wire [words-1 : 0] lane_rx_errdetect;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(words), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rx_errdetect(.clk(clk), .async_in_wide(rx_errdetect),
+ .sel(reg_lane_number), .out_narrow(lane_rx_errdetect));
+
+ wire [words-1 : 0] lane_rx_disperr;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(words), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rx_disperr(.clk(clk), .async_in_wide(rx_disperr),
+ .sel(reg_lane_number), .out_narrow(lane_rx_disperr));
+
+ wire [words-1 : 0] lane_rx_a1a2sizeout;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(words), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rx_a1a2sizeout(.clk(clk), .async_in_wide(rx_a1a2sizeout),
+ .sel(reg_lane_number), .out_narrow(lane_rx_a1a2sizeout));
+
+ wire [0 : 0] lane_rx_phase_comp_fifo_error;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rx_phase_comp_fifo_error(.clk(clk), .async_in_wide(rx_phase_comp_fifo_error),
+ .sel(reg_lane_number), .out_narrow(lane_rx_phase_comp_fifo_error));
+
+ wire [boundary_width-1 : 0] lane_rx_bitslipboundaryselectout;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(boundary_width), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rx_bitslipboundaryselectout(.clk(clk), .async_in_wide(rx_bitslipboundaryselectout),
+ .sel(reg_lane_number), .out_narrow(lane_rx_bitslipboundaryselectout));
+
+ wire [0 : 0] lane_tx_phase_comp_fifo_error;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_tx_phase_comp_fifo_error(.clk(clk), .async_in_wide(tx_phase_comp_fifo_error),
+ .sel(reg_lane_number), .out_narrow(lane_tx_phase_comp_fifo_error));
+
+ wire [0 : 0] lane_rlv;
+ csr_indexed_read_only_reg #(.groups(lanes), .grp_size(1), .sel_size(LANE_REGW), .sync_stages(sync_stages))
+ mux_rlv(.clk(clk), .async_in_wide(rlv),
+ .sel(reg_lane_number), .out_narrow(lane_rlv));
+
+
+ always @(posedge clk or posedge reset) begin
+ if (reset == 1) begin
+ readdata <= 0;
+ reg_lane_number <= 0;
+ reg_tx_invpolarity <= 0;
+ reg_tx_bitslipboundaryselect <= 0;
+ reg_rx_invpolarity <= 0;
+ reg_rx_enapatternalign <= 0;
+ reg_rx_bitreversalenable <= 0;
+ reg_rx_bytereversalenable <= 0;
+ reg_rx_bitslip <= 0;
+ reg_rx_a1a2size <= 0;
+
+ // no need to clear synchronization registers, since they do not store state
+ end
+ else begin
+ // decode read & write for each supported address
+ case (address)
+ // lane or group number for indirection
+ ADDR_PCS_LANE_GROUP: begin
+ readdata <= (32'd0 | reg_lane_number);
+ if (write) reg_lane_number <= writedata[LANE_REGW-1:0];
+ end
+
+ // offset + 1, read-only RX status bits
+ // bit 0, rx_phase_comp_fifo_error
+ // bit boundary_width:1, rx_bitslipboundaryselectout
+ ADDR_PCS8G_RX_STATUS: begin
+ readdata <= (32'd0 |
+ {lane_rx_bitslipboundaryselectout, //bit boundary_width-1
+ lane_rx_phase_comp_fifo_error}); // bit 0
+ end
+
+ // offset + 2, read-only TX status bits
+ // bit 0, tx_phase_comp_fifo_error
+ ADDR_PCS8G_TX_STATUS: begin
+ readdata <= (32'd0 | lane_tx_phase_comp_fifo_error); // bit 0
+ end
+
+ // offset + 3, read/write TX control bits
+ // bit 0, tx_invpolarity
+ // bit boundary_width:1, tx_bitslipboundaryselect
+ ADDR_PCS8G_TX_CONTROL: begin
+ readdata <= (32'd0 | {lane_tx_bitslipboundaryselect, lane_tx_invpolarity});
+ if (write)
+ begin
+ reg_tx_invpolarity <= write_tx_invpolarity;
+ reg_tx_bitslipboundaryselect <= write_tx_bitslipboundaryselect;
+ end
+ end
+
+ // offset + 4, read/write RX control bits
+ // bit 0, rx_invpolarity
+ ADDR_PCS8G_RX_CONTROL: begin
+ readdata <= (32'd0 | lane_rx_invpolarity);
+ if (write) reg_rx_invpolarity <= write_rx_invpolarity;
+ end
+
+ // offset + 5, read/write RX WA control bits
+ // bit 0, rx_enapatternalign
+ // bit 1, rx_bitreversalenable
+ // bit 2, rx_bytereversalenable
+ // bit 3, rx_bitslip
+ // bit 4, rx_a1a2size
+ ADDR_PCS8G_RX_WA_CONTROL: begin
+ readdata <= (32'd0 | { lane_rx_a1a2size, // bit 4
+ lane_rx_bitslip, // bit 3
+ lane_rx_bytereversalenable, // bit 2
+ lane_rx_bitreversalenable, // bit 1
+ lane_rx_enapatternalign}); // bit 0
+ if (write)
+ begin
+ reg_rx_enapatternalign <= write_rx_enapatternalign;
+ reg_rx_bitreversalenable <= write_rx_bitreversalenable;
+ reg_rx_bytereversalenable <= write_rx_bytereversalenable;
+ reg_rx_bitslip <= write_rx_bitslip;
+ reg_rx_a1a2size <= write_rx_a1a2size;
+ end
+ end
+
+ // offset + 5, read RX WA status bits
+ // bit 3:0, rx_errdetect
+ // bit 7:4, rx_syncstatus
+ // bit 11:8, rx_disperr
+ // bit 15:12, rx_patterndetect
+ // bit 16, rlv
+ // bit 23:20, rx_a1a2sizeout
+ ADDR_PCS8G_RX_WA_STATUS: begin
+ readdata <= (32'd0 | {(4'b0 | lane_rx_a1a2sizeout), // bit 23:20
+ (4'b0 | lane_rlv), // bit 16
+ (4'b0 | lane_rx_patterndetect), // bit 15:12
+ (4'b0 | lane_rx_disperr), // bit 11:8
+ (4'b0 | lane_rx_syncstatus), // bit 7:4
+ (4'b0 | lane_rx_errdetect)}); // bit 3:0
+ end
+
+ default: readdata <= ~ 32'd0; // use too many LEs?
+ endcase
+ end
+ end
+
+ // synchronize TX controls to tx_clk before generating output
+ // sysclk-sync'ed input enters at [sync_stages], and tx_clk-sync'ed output exist at [1]
+ integer stage;
+ always @(posedge tx_clk) begin
+ sync_tx_invpolarity[sync_stages] <= reg_tx_invpolarity;
+ sync_tx_bitslipboundaryselect[sync_stages] <= reg_tx_bitslipboundaryselect;
+ for (stage=2; stage <= sync_stages; stage = stage + 1) begin
+ // additional sync stages
+ sync_tx_invpolarity[stage-1] <= sync_tx_invpolarity[stage];
+ sync_tx_bitslipboundaryselect[stage-1] <= sync_tx_bitslipboundaryselect[stage];
+ end
+ end
+ assign csr_tx_invpolarity = sync_tx_invpolarity[1];
+ assign csr_tx_bitslipboundaryselect = sync_tx_bitslipboundaryselect[1];
+
+ // synchronize RX controls to rx_clk before generating output
+ // sysclk-sync'ed input enters at [sync_stages], and rx_clk-sync'ed output exist at [1]
+ always @(posedge rx_clk) begin
+ sync_rx_invpolarity[sync_stages] <= reg_rx_invpolarity;
+ sync_rx_enapatternalign[sync_stages] <= reg_rx_enapatternalign;
+ sync_rx_bitreversalenable[sync_stages] <= reg_rx_bitreversalenable;
+ sync_rx_bytereversalenable[sync_stages] <= reg_rx_bytereversalenable;
+ sync_rx_bitslip[sync_stages] <= reg_rx_bitslip;
+ sync_rx_a1a2size[sync_stages] <= reg_rx_a1a2size;
+ for (stage=2; stage <= sync_stages; stage = stage + 1) begin
+ // additional sync stages
+ sync_rx_invpolarity[stage-1] <= sync_rx_invpolarity[stage];
+ sync_rx_enapatternalign[stage-1] <= sync_rx_enapatternalign[stage];
+ sync_rx_bitreversalenable[stage-1] <= sync_rx_bitreversalenable[stage];
+ sync_rx_bytereversalenable[stage-1] <= sync_rx_bytereversalenable[stage];
+ sync_rx_bitslip[stage-1] <= sync_rx_bitslip[stage];
+ sync_rx_a1a2size[stage-1] <= sync_rx_a1a2size[stage];
+ end
+ end
+ assign csr_rx_invpolarity = sync_rx_invpolarity[1];
+ assign csr_rx_enapatternalign = sync_rx_enapatternalign[1];
+ assign csr_rx_bitreversalenable = sync_rx_bitreversalenable[1];
+ assign csr_rx_bytereversalenable = sync_rx_bytereversalenable[1];
+ assign csr_rx_bitslip = sync_rx_bitslip[1];
+ assign csr_rx_a1a2size = sync_rx_a1a2size[1];
+
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_pcs8g_h.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_pcs8g_h.sv
new file mode 100644
index 0000000..6ace173
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_pcs8g_h.sv
@@ -0,0 +1,33 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Common control & status register map for transceiver PHY IP
+// Applies to Stratix V-generation basic PHY components
+//
+// $Header$
+//
+// PACKAGE DECLARATION
+package alt_xcvr_csr_pcs8g_h;
+
+ import alt_xcvr_csr_common_h::*;
+
+ // 8G PCS, a.k.a. "Standard PCS", control and status bits
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS8G_RX_STATUS = ADDR_PCS_BASE + 8'd1;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS8G_TX_STATUS = ADDR_PCS_BASE + 8'd2;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS8G_TX_CONTROL = ADDR_PCS_BASE + 8'd3;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS8G_RX_CONTROL = ADDR_PCS_BASE + 8'd4;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS8G_RX_WA_CONTROL = ADDR_PCS_BASE + 8'd5;
+ localparam [alt_xcvr_csr_addr_width-1:0] ADDR_PCS8G_RX_WA_STATUS = ADDR_PCS_BASE + 8'd6;
+
+endpackage
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_selector.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_selector.sv
new file mode 100644
index 0000000..f4502a1
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_csr_selector.sv
@@ -0,0 +1,122 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Select a sub-group from a wide register
+// Useful for indirection indexing
+//
+// $Header$
+//
+
+`timescale 1 ns / 1 ns
+
+module csr_mux #(
+ parameter groups = 2,
+ parameter grp_size = 1,
+ parameter sel_size = 1
+)
+(
+ input wire [groups*grp_size-1:0] in_wide,
+ input tri0 [sel_size-1:0] sel,
+ output wire [grp_size-1:0] out_narrow
+);
+// lpm_mux #(.lpm_size(groups), .lpm_width(grp_size), .lpm_widths(sel_size))
+// mux (.data(in_wide), .sel(sel), .result(out_narrow));
+ wire [grp_size-1:0] in_groups [groups-1:0];
+
+ // a synthesizable mux, with a parameterized number of inputs
+ genvar i;
+ assign in_groups[0] = in_wide[grp_size-1:0] & {grp_size{sel == 0}};
+ generate for (i=1; i 0} {set_false_path -to $regs}\""};
+ localparam SDC_CONSTRAINTS = {SYNC_SREG_CONSTRAINT};
+
+ // read-only status registers are synchronized forms of async status signals
+ // async inputs go to sreg [sync_stages], and come out synchronized at sreg [1]
+ // Apply false path timing constraints to synchronization registers.
+ (* altera_attribute = SDC_CONSTRAINTS *)
+ reg [groups*grp_size-1:0] sreg [sync_stages:1];
+ integer stage;
+ always @(posedge clk) begin
+ sreg[sync_stages] <= async_in_wide;
+ for (stage=2; stage <= sync_stages; stage = stage + 1) begin
+ // additional sync stages
+ sreg[stage-1] <= sreg[stage];
+ end
+ end
+
+ // generate out_narrow as ordinary mux of out_wide
+ csr_mux #(.groups(groups), .grp_size(grp_size), .sel_size(sel_size))
+ o_narrow(.in_wide(sreg[1]), .sel(sel), .out_narrow(out_narrow));
+
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_m2s.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_m2s.sv
new file mode 100644
index 0000000..2bc900e
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_m2s.sv
@@ -0,0 +1,61 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+// Master-to-slave access fabric
+//
+// Combined with external multi-master arbitration, this block gates
+// master read, write, address, and writedata outputs, and generates
+// a waitrequest when arbiter indicates access is not granted
+
+// $Header$
+
+`timescale 1 ns / 1 ns
+
+module alt_xcvr_m2s #(
+ parameter width_addr = 3,
+ parameter width_data = 32
+) (
+ input wire clock,
+ output wire req, // request to arbiter for slave access
+ input wire grant,
+
+ // signals from/to master
+ input wire m_read,
+ input wire m_write,
+ input wire [width_addr-1:0] m_address,
+ input wire [width_data-1:0] m_writedata,
+ output wire [width_data-1:0] m_readdata,
+ output wire m_waitrequest,
+
+ // signals from/to slave
+ output wire s_read,
+ output wire s_write,
+ output wire [width_addr-1:0] s_address,
+ output wire [width_data-1:0] s_writedata,
+ input wire [width_data-1:0] s_readdata,
+ input wire s_waitrequest
+);
+
+ // If master is requesting access, generate waitreq until granted
+ assign req = m_read | m_write; // master access requests
+ assign m_waitrequest = grant ? s_waitrequest : req;
+
+ // gate outputs to slave with grant signal
+ assign s_read = m_read & grant;
+ assign s_write = m_write & grant;
+ assign s_address = m_address & {width_addr{grant}};
+ assign s_writedata = m_writedata & {width_data{grant}};
+
+ // slave data outputs pass through directly
+ assign m_readdata = s_readdata;
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec.sv
new file mode 100644
index 0000000..f628176
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec.sv
@@ -0,0 +1,90 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+// Management interface address decoder for Altera Transceiver PHY
+//
+// Addresses common case of 2 modules to be stitched together:
+// - 'top' PHY channel blocks (includes reset control, CSR, ...)
+// - dynamic reconfiguration block
+
+// $Header$
+
+`timescale 1 ns / 1 ns
+
+module alt_xcvr_mgmt2dec (
+
+ // user-visible external management interface
+ input wire mgmt_clk_reset,
+ input wire mgmt_clk,
+
+ input wire [8:0] mgmt_address,
+ input wire mgmt_read,
+ output reg [31:0] mgmt_readdata = ~32'd0,
+ output reg mgmt_waitrequest = 0,
+ input wire mgmt_write,
+
+ // internal interface to 'top' csr block
+ output wire [7:0] topcsr_address,
+ output wire topcsr_read,
+ input wire [31:0] topcsr_readdata,
+ input wire topcsr_waitrequest,
+ output wire topcsr_write,
+
+ // internal interface to 'top' csr block
+ output wire [7:0] reconf_address,
+ output wire reconf_read,
+ input wire [31:0] reconf_readdata,
+ input wire reconf_waitrequest,
+ output wire reconf_write
+);
+ localparam width_swa = 7; // word address width of interface to slaves (2 for top.CSR and 1 for reconfig)
+ localparam dec_count = 2; // count of the total number of sub-components that can act
+ // as slaves to the mgmt interface
+ localparam dec_topcsr = 0; // uses 2 128-word address blocks
+ localparam dec_reconf = 1; // uses 1 128-word address block
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Decoder for multiple slaves of reconfig_mgmt interface
+ ///////////////////////////////////////////////////////////////////////
+ wire [dec_count-1:0] r_decode;
+ assign r_decode =
+ (mgmt_address[8:width_swa+1] == dec_topcsr) ? (({dec_count-dec_topcsr{1'b0}} | 1'b1) << dec_topcsr)
+ : (mgmt_address[8:width_swa] == 2'd2) ? (({dec_count-dec_reconf{1'b0}} | 1'b1) << dec_reconf)
+ : {dec_count{1'b0}};
+
+ // reconfig_mgmt output generation is muxing of decoded slave output
+ always @(*) begin
+ if (r_decode[dec_topcsr] == 1'b1) begin
+ mgmt_readdata = topcsr_readdata;
+ mgmt_waitrequest = topcsr_waitrequest;
+ end else if (r_decode[dec_reconf] == 1'b1) begin
+ mgmt_readdata = reconf_readdata;
+ mgmt_waitrequest = reconf_waitrequest;
+ end else begin
+ mgmt_readdata = -1;
+ mgmt_waitrequest = 1'b0;
+ end
+ end
+
+ // internal interface to 'top' csr block
+ assign topcsr_address = mgmt_address[width_swa:0]; // top.csr uses 2 128-word blocks
+ assign topcsr_read = mgmt_read & r_decode[dec_topcsr];
+ assign topcsr_write = mgmt_write & r_decode[dec_topcsr];
+
+ // internal interface to 'top' csr block
+ assign reconf_address = mgmt_address[width_swa-1:0]; // reconfig uses 1 128-word block
+ assign reconf_read = mgmt_read & r_decode[dec_reconf];
+ assign reconf_write = mgmt_write & r_decode[dec_reconf];
+
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec_phyreconfig.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec_phyreconfig.sv
new file mode 100644
index 0000000..3a8c2ff
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec_phyreconfig.sv
@@ -0,0 +1,110 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//-----------------------------------------------------------------------------
+//
+// Description: Custom management interface address decoder for Altera
+// transciever PHY. Addresses common case of 2 modules to be stitched together:
+// - 'top' PHY channel blocks (includes reset control, CSR, ...)
+// - dynamic reconfiguration block
+//
+// Authors: dunnikri 19-Aug-2010
+//
+// Copyright (c) Altera Corporation 1997 - 2010
+// All rights reserved.
+//
+//
+//-----------------------------------------------------------------------------
+
+`timescale 1 ns / 1 ns
+
+module alt_xcvr_mgmt2dec_phyreconfig (
+
+ // user-visible external management interface
+ input wire mgmt_clk_reset,
+ input wire mgmt_clk,
+
+ input wire [8:0] mgmt_address,
+ input wire mgmt_read,
+ output reg [31:0] mgmt_readdata = ~32'd0,
+ output reg mgmt_waitrequest = 0,
+ input wire mgmt_write,
+
+ // internal interface to xaui phy block
+ output wire [7:0] sc_phy_address,
+ output wire sc_phy_read,
+ input wire [31:0] sc_phy_readdata,
+ input wire sc_phy_waitrequest,
+ output wire sc_phy_write,
+
+ // internal interface to reconfig block
+ output wire [6:0] sc_reconf_address,
+ output wire sc_reconf_read,
+ input wire [31:0] sc_reconf_readdata,
+ input wire sc_reconf_waitrequest,
+ output wire sc_reconf_write
+);
+ localparam width_swa = 7; // word address width of interface to slaves (2 for phy and 1 for reconfig)
+ localparam dec_count = 2; // count of the total number of sub-components that can act
+ // as slaves to the mgmt interface
+ localparam dec_sc_phy = 0; //
+ localparam dec_reconf = 1; //
+
+ ///////////////////////////////////////////////////////////////////////
+ // Decoder for multiple slaves of reconfig_mgmt interface
+ ///////////////////////////////////////////////////////////////////////
+ wire [dec_count-1:0] r_decode; //1-hot encoding
+
+ //-----------------------Memory Map Reference-------------------------
+ //--------------------------------------------------------------------
+ //Block | Word Address | Byte Address |
+ //-------------------------------------------------------------------
+ //PHY Common | 0x0 | 0x0 |
+ //PMA Controller | 0x20 | 0x80 |
+ //Reset Controller | 0x40 | 0x100 |
+ //PMA Channel Controller | 0x60 | 0x180 |
+ //PCS | 0x80 | 0x200 |
+ //XCVR Reconfig | 0x100 | 0x400 |
+ //--------------------------------------------------------------------
+
+ //Decoding is based on memory map word address
+ assign r_decode =
+ (mgmt_address[8:width_swa+1] == dec_sc_phy) ? (({dec_count-dec_sc_phy{1'b0}} | 1'b1) << dec_sc_phy)
+ : (mgmt_address[8:width_swa] == 2'd2) ? (({dec_count-dec_reconf{1'b0}} | 1'b1) << dec_reconf)
+ : {dec_count{1'b0}};
+
+ // reconfig_mgmt output generation is muxing of decoded slave output
+ always @(*) begin
+ if (r_decode[dec_sc_phy] == 1'b1) begin
+ mgmt_readdata = sc_phy_readdata;
+ mgmt_waitrequest = sc_phy_waitrequest;
+ end else if (r_decode[dec_reconf] == 1'b1) begin
+ mgmt_readdata = sc_reconf_readdata;
+ mgmt_waitrequest = sc_reconf_waitrequest;
+ end else begin
+ mgmt_readdata = -1;
+ mgmt_waitrequest = 1'b0;
+ end
+ end
+
+ // internal interface to 'top' phy block
+ assign sc_phy_address = mgmt_address[width_swa:0];
+ assign sc_phy_read = mgmt_read & r_decode[dec_sc_phy];
+ assign sc_phy_write = mgmt_write & r_decode[dec_sc_phy];
+
+ // internal interface to 'top' reconfig block
+ assign sc_reconf_address = mgmt_address[width_swa-1:0];
+ assign sc_reconf_read = mgmt_read & r_decode[dec_reconf];
+ assign sc_reconf_write = mgmt_write & r_decode[dec_reconf];
+
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec_xaui.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec_xaui.sv
new file mode 100644
index 0000000..8c50aeb
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_mgmt2dec_xaui.sv
@@ -0,0 +1,134 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//-----------------------------------------------------------------------------
+//
+// Description: Custom management interface address decoder for Altera
+// transciever PHY. Addresses common case of 3 modules to be stitched together:
+// - CSR, Alt_PMA controller, Alt_PMA_Channel controller
+//
+// Authors: dunnikri 19-Aug-2010
+//
+// Copyright (c) Altera Corporation 1997 - 2010
+// All rights reserved.
+//
+//
+//-----------------------------------------------------------------------------
+
+`timescale 1 ps / 1 ps
+
+module alt_xcvr_mgmt2dec_xaui (
+
+ // user-visible external management interface
+ input wire mgmt_clk_reset,
+ input wire mgmt_clk,
+
+ input wire [7:0] mgmt_address,
+ input wire mgmt_read,
+ output reg [31:0] mgmt_readdata = ~32'd0,
+ output reg mgmt_waitrequest = 0,
+ input wire mgmt_write,
+
+ // internal interface to xaui pma channel controller
+ output wire [5:0] sc_pma_ch_controller_address,
+ output wire sc_pma_ch_controller_read,
+ input wire [31:0] sc_pma_ch_controller_readdata,
+ input wire sc_pma_ch_controller_waitrequest,
+ output wire sc_pma_ch_controller_write,
+
+ // internal interface to pma controller block
+ output wire [1:0] sc_pma_controller_address,
+ output wire sc_pma_controller_read,
+ input wire [31:0] sc_pma_controller_readdata,
+ input wire sc_pma_controller_waitrequest,
+ output wire sc_pma_controller_write,
+
+ // internal interface to hxaui csr block
+ output wire [4:0] sc_csr_address,
+ output wire sc_csr_read,
+ input wire [31:0] sc_csr_readdata,
+ input wire sc_csr_waitrequest,
+ output wire sc_csr_write
+);
+ localparam width_swa = 7; // word address width of interface to slaves (2 for phy and 1 for reconfig)
+ localparam dec_count = 3; // count of the total number of sub-components that can act
+ // as slaves to the mgmt interface
+
+ localparam dec_pma_control = 0;
+ localparam dec_csr = 1;
+ localparam dec_pma_ch_control = 2;
+
+ //--------------------------------------------------------------------
+ //Block | Word Address | Byte Address |
+ //-------------------------------------------------------------------
+ //PHY Common | 0x0 | 0x0 |
+ //PMA Controller | 0x20 | 0x80 |
+ //Reset Controller | 0x40 | 0x100 |
+ //PMA Channel Controller | 0x60 | 0x180 |
+ //PCS | 0x80 | 0x200 |
+ //XCVR Reconfig | 0x100 | 0x400 |
+ //-------------------------------------------------------------------
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Decoder for multiple slaves of reconfig_mgmt interface
+ ///////////////////////////////////////////////////////////////////////
+ wire [dec_count-1:0] r_decode; //1-hot encoding
+
+ //PMA Controller - 0x20 (0010 0000)
+ //Reset Controller - 0x40 (0100 0000)
+ //Channel Controller - 0x60 (0110 0000)
+ //PCS - 0x80 (1000 0000)
+ //Consider first 3 MSBs for decoding
+ /*assign r_decode =
+ (mgmt_address[7:5] == 3'd1) ? (({dec_count-dec_pma_control{1'b0}} | 1'b1) << dec_pma_control)
+ : (mgmt_address[7:5] == 3'd4) ? (({dec_count-dec_csr{1'b0}} | 1'b1) << dec_csr)
+ : (mgmt_address[7:5] == 3'd3) ? (({dec_count-dec_pma_ch_control{1'b0}} | 1'b1) << dec_pma_ch_control)
+ : {dec_count{1'b0}};*/
+
+ assign r_decode[0] = (!mgmt_address[7]) & (!mgmt_address[6]) & (mgmt_address[5]);
+ assign r_decode[1] = (mgmt_address[7]) & (!mgmt_address[6]) & (!mgmt_address[5]);
+ assign r_decode[2] = (!mgmt_address[7]) & (mgmt_address[6]);
+
+
+ always @(*) begin
+ if (r_decode[dec_pma_ch_control] == 1'b1) begin
+ mgmt_readdata = sc_pma_ch_controller_readdata;
+ mgmt_waitrequest = sc_pma_ch_controller_waitrequest;
+ end else if (r_decode[dec_pma_control] == 1'b1) begin
+ mgmt_readdata = sc_pma_controller_readdata;
+ mgmt_waitrequest = sc_pma_controller_waitrequest;
+ end else if (r_decode[dec_csr] == 1'b1) begin
+ mgmt_readdata = sc_csr_readdata;
+ mgmt_waitrequest = sc_csr_waitrequest;
+ end else begin
+ mgmt_readdata = -1;
+ mgmt_waitrequest = 1'b0;
+ end
+ end
+
+ // internal interface to alt_pma_ch_control block
+ assign sc_pma_ch_controller_address = mgmt_address[5:0]; //6 bit address
+ assign sc_pma_ch_controller_read = mgmt_read & r_decode[dec_pma_ch_control];
+ assign sc_pma_ch_controller_write = mgmt_write & r_decode[dec_pma_ch_control];
+
+ // internal interface to pma_control block
+ assign sc_pma_controller_address = mgmt_address[1:0]; // 2 bit address
+ assign sc_pma_controller_read = mgmt_read & r_decode[dec_pma_control];
+ assign sc_pma_controller_write = mgmt_write & r_decode[dec_pma_control];
+
+ // internal interface to csr block
+ assign sc_csr_address = mgmt_address[4:0]; // 5 bit address
+ assign sc_csr_read = mgmt_read & r_decode[dec_csr];
+ assign sc_csr_write = mgmt_write & r_decode[dec_csr];
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_reset_counter.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_reset_counter.sv
new file mode 100644
index 0000000..5aa5f28
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_reset_counter.sv
@@ -0,0 +1,127 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+
+// File Name: alt_xcvr_reset_counter
+//
+// Description:
+//
+// A simple counter targeted for a reset controller. The parameters specify the clock domain's
+// clock frequency and the desired reset period specified in nanoseconds. The caller may specify
+// the active level of the internal reset flop.
+//
+// The async_req input signal is active high. The reset outputs
+// will remain asserted while async_req is asserted and will not deassert
+// until the specified reset period has expired.
+// The sync_req input behaves similar to the async_req but is sampled
+// synchronously with the clock.
+// The "reset_or" input does not reset the counter but directly asserts the reset output flop.
+// The reset outputs will remain asserted so long as "reset_or" is asserted.
+//
+// Revision History:
+//
+// Special notes:
+//
+
+`timescale 1ns / 1ns
+
+module alt_xcvr_reset_counter #(
+ parameter CLKS_PER_SEC = 25000000, // Clock frequency in Hz
+ parameter RESET_PER_NS = 1000000, // Reset period in ns
+ parameter RESET_COUNT = 0, // Overrides RESET_PER_NS
+ parameter ACTIVE_LEVEL = 1 //
+) (
+ input clk,
+ input async_req, // asynchronous reset request (restart sequence)
+ input sync_req, // synchronous reset request
+ input reset_or, // auxilliary reset override (assert only)
+
+ output reset, // synchronous reset out
+ output reset_n, // negation of reset
+ output reset_stat // reset status (intended for control logic)
+);
+
+// Determine unrounded counter limit based on passed frequency
+localparam [63:0] INITIAL_COUNT = (CLKS_PER_SEC * RESET_PER_NS) / 1000000000;
+// Round counter limit up if needed
+localparam [63:0] ROUND_COUNT = (((INITIAL_COUNT * 1000000000) / CLKS_PER_SEC) < RESET_PER_NS)
+ ? (INITIAL_COUNT + 1) : INITIAL_COUNT;
+// Use given counter limit if provided (RESET_COUNT), otherwise use calculated counter limit
+localparam MAX_CNT = (RESET_COUNT == 0) ? ROUND_COUNT - 1 : RESET_COUNT - 1;
+localparam CNT_WIDTH = altera_xcvr_functions::clogb2(MAX_CNT);
+// 1 bit wide active level
+localparam LCL_ACTIVE_LEVEL = (ACTIVE_LEVEL == 0) ? 1'b0 : 1'b1;
+
+// Counter signals
+reg [CNT_WIDTH-1:0] count = {CNT_WIDTH{1'b0}};
+wire count_lim;
+
+// Internal reset signals
+(* dont_merge *)
+reg r_reset; // Reset output register
+reg r_reset_stat; // Reset status register
+wire reset_cond; // Condition for reset
+
+// Reset counter
+//***************************************************************************
+//**************************** Reset counter ********************************
+assign count_lim = (count == MAX_CNT);
+always @(posedge clk or posedge async_req)
+ if(async_req) count <= {CNT_WIDTH{1'b0}};
+ else if(sync_req) count <= {CNT_WIDTH{1'b0}};
+ else if(~count_lim) count <= count + 1'b1;
+//************************** End Reset counter ******************************
+//***************************************************************************
+
+
+//***************************************************************************
+//********************** Internal reset register ****************************
+// The condition for a reset (other than asynchrnous reset) are:
+// 1 - Synchronous reset request
+// 2 - Timer has not expired.
+// 3 - Reset override is asserted
+assign reset_cond = (sync_req | ~count_lim | reset_or);
+
+// Reset register
+always @(posedge clk or posedge async_req)
+ if(async_req) r_reset <= LCL_ACTIVE_LEVEL;
+ else r_reset <= ~(reset_cond ^ LCL_ACTIVE_LEVEL);
+
+// External reset status generation. We create a status of the reset
+// output simply so we can allow the actual reset output to drive resets
+// with limited fanout to other logic. This status output is intended
+// to be used for reset control logic.
+assign reset_stat = r_reset_stat;
+always @(posedge clk or posedge async_req)
+ if(async_req) r_reset_stat <= 1'b1;
+ else r_reset_stat <= reset_cond;
+//******************** End Internal reset register **************************
+//***************************************************************************
+
+
+//***************************************************************************
+//*********************** Reset output generation ***************************
+// External reset generation
+generate if (ACTIVE_LEVEL == 0) begin : g_active_low_resets
+ assign reset = ~r_reset;
+ assign reset_n = r_reset;
+end else begin : g_active_high_resets
+ assign reset = r_reset;
+ assign reset_n = ~r_reset;
+end
+endgenerate
+//********************* End Reset output generation *************************
+//***************************************************************************
+
+endmodule
+
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_resync.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_resync.sv
new file mode 100644
index 0000000..57d3a20
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/alt_xcvr_resync.sv
@@ -0,0 +1,97 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+// Module: alt_xcvr_resync
+//
+// Description:
+// A general purpose resynchronization module.
+//
+// Parameters:
+// SYNC_CHAIN_LENGTH
+// - Specifies the length of the synchronizer chain for metastability
+// retiming.
+// WIDTH
+// - Specifies the number of bits you want to synchronize. Controls the width of the
+// d and q ports.
+// SLOW_CLOCK - USE WITH CAUTION.
+// - Leaving this setting at its default will create a standard resynch circuit that
+// merely passes the input data through a chain of flip-flops. This setting assumes
+// that the input data has a pulse width longer than one clock cycle sufficient to
+// satisfy setup and hold requirements on at least one clock edge.
+// - By setting this to 1 (USE CAUTION) you are creating an asynchronous
+// circuit that will capture the input data regardless of the pulse width and
+// its relationship to the clock. However it is more difficult to apply static
+// timing constraints as it ties the data input to the clock input of the flop.
+// This implementation assumes the data rate is slow enough
+// INIT_VALUE
+// - Specifies the initial values of the synchronization registers.
+//
+// Apply embedded false path timing constraint
+(* altera_attribute = "-name SDC_STATEMENT \"set regs [get_registers -nowarn *alt_xcvr_resync*sync_r[0]]; if {[llength [query_collection -report -all $regs]] > 0} {set_false_path -to $regs}\"" *)
+
+`timescale 1ps/1ps
+
+module alt_xcvr_resync #(
+ parameter SYNC_CHAIN_LENGTH = 2, // Number of flip-flops for retiming. Must be >1
+ parameter WIDTH = 1, // Number of bits to resync
+ parameter SLOW_CLOCK = 0, // See description above
+ parameter INIT_VALUE = 0
+ ) (
+ input wire clk,
+ input wire reset,
+ input wire [WIDTH-1:0] d,
+ output wire [WIDTH-1:0] q
+ );
+
+localparam INT_LEN = (SYNC_CHAIN_LENGTH > 1) ? SYNC_CHAIN_LENGTH : 2;
+localparam [INT_LEN-1:0] L_INIT_VALUE = (INIT_VALUE == 1) ? {INT_LEN{1'b1}} : {INT_LEN{1'b0}};
+
+genvar ig;
+
+// Generate a synchronizer chain for each bit
+generate begin
+ for(ig=0;ig= 2 !
+ parameter rst_value = 0;
+
+ input clk;
+ input reset_n;
+ input din;
+ output dout;
+
+ // QuartusII synthesis directives:
+ // 1. Preserve all registers ie. do not touch them.
+ // 2. Do not merge other flip-flops with synchronizer flip-flops.
+ // QuartusII TimeQuest directives:
+ // 1. Identify all flip-flops in this module as members of the synchronizer
+ // to enable automatic metastability MTBF analysis.
+
+ (* altera_attribute = {"-name ADV_NETLIST_OPT_ALLOWED NEVER_ALLOW; -name SYNCHRONIZER_IDENTIFICATION FORCED; -name DONT_MERGE_REGISTER ON; -name PRESERVE_REGISTER ON "} *) reg din_s1;
+
+ (* altera_attribute = {"-name ADV_NETLIST_OPT_ALLOWED NEVER_ALLOW; -name DONT_MERGE_REGISTER ON; -name PRESERVE_REGISTER ON"} *) reg [depth-2:0] dreg;
+
+ //synthesis translate_off
+ initial begin
+ if (depth <2) begin
+ $display("%m: Error: synchronizer length: %0d less than 2.", depth);
+ end
+ end
+
+ // the first synchronizer register is either a simple D flop for synthesis
+ // and non-metastable simulation or a D flop with a method to inject random
+ // metastable events resulting in random delay of [0,1] cycles
+
+`ifdef __ALTERA_STD__METASTABLE_SIM
+
+ reg[31:0] RANDOM_SEED = 123456;
+ wire next_din_s1;
+ wire dout;
+ reg din_last;
+ reg random;
+ event metastable_event; // hook for debug monitoring
+
+ initial begin
+ $display("%m: Info: Metastable event injection simulation mode enabled");
+ end
+
+ always @(posedge clk) begin
+ if (reset_n == 0)
+ random <= $random(RANDOM_SEED);
+ else
+ random <= $random;
+ end
+
+ assign next_din_s1 = (din_last ^ din) ? random : din;
+
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_last <= (rst_value == 0)? 1'b0 : 1'b1;
+ else
+ din_last <= din;
+ end
+
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_s1 <= (rst_value == 0)? 1'b0 : 1'b1;
+ else
+ din_s1 <= next_din_s1;
+ end
+
+`else
+
+ //synthesis translate_on
+ generate if (rst_value == 0)
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_s1 <= 1'b0;
+ else
+ din_s1 <= din;
+ end
+ endgenerate
+
+ generate if (rst_value == 1)
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_s1 <= 1'b1;
+ else
+ din_s1 <= din;
+ end
+ endgenerate
+ //synthesis translate_off
+
+`endif
+
+`ifdef __ALTERA_STD__METASTABLE_SIM_VERBOSE
+ always @(*) begin
+ if (reset_n && (din_last != din) && (random != din)) begin
+ $display("%m: Verbose Info: metastable event @ time %t", $time);
+ ->metastable_event;
+ end
+ end
+`endif
+
+ //synthesis translate_on
+
+ // the remaining synchronizer registers form a simple shift register
+ // of length depth-1
+ generate if (rst_value == 0)
+ if (depth < 3) begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b0}};
+ else
+ dreg <= din_s1;
+ end
+ end else begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b0}};
+ else
+ dreg <= {dreg[depth-3:0], din_s1};
+ end
+ end
+ endgenerate
+
+ generate if (rst_value == 1)
+ if (depth < 3) begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b1}};
+ else
+ dreg <= din_s1;
+ end
+ end else begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b1}};
+ else
+ dreg <= {dreg[depth-3:0], din_s1};
+ end
+ end
+ endgenerate
+
+ assign dout = dreg[depth-2];
+
+endmodule
+
+
+
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_std_synchronizer_nocut.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_std_synchronizer_nocut.v
new file mode 100644
index 0000000..60175c1
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_std_synchronizer_nocut.v
@@ -0,0 +1,195 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+// $Id: //acds/main/ip/sopc/components/primitives/altera_std_synchronizer/altera_std_synchronizer.v#8 $
+// $Revision: #8 $
+// $Date: 2009/02/18 $
+// $Author: pscheidt $
+//-----------------------------------------------------------------------------
+//
+// File: altera_std_synchronizer_nocut.v
+//
+// Abstract: Single bit clock domain crossing synchronizer. Exactly the same
+// as altera_std_synchronizer.v, except that the embedded false
+// path constraint is removed in this module. If you use this
+// module, you will have to apply the appropriate timing
+// constraints.
+//
+// We expect to make this a standard Quartus atom eventually.
+//
+// Composed of two or more flip flops connected in series.
+// Random metastable condition is simulated when the
+// __ALTERA_STD__METASTABLE_SIM macro is defined.
+// Use +define+__ALTERA_STD__METASTABLE_SIM argument
+// on the Verilog simulator compiler command line to
+// enable this mode. In addition, define the macro
+// __ALTERA_STD__METASTABLE_SIM_VERBOSE to get console output
+// with every metastable event generated in the synchronizer.
+//
+// Copyright (C) Altera Corporation 2009, All Rights Reserved
+//-----------------------------------------------------------------------------
+
+`timescale 1ns / 1ns
+
+module altera_std_synchronizer_nocut (
+ clk,
+ reset_n,
+ din,
+ dout
+ );
+
+ parameter depth = 3; // This value must be >= 2 !
+ parameter rst_value = 0;
+
+ input clk;
+ input reset_n;
+ input din;
+ output dout;
+
+ // QuartusII synthesis directives:
+ // 1. Preserve all registers ie. do not touch them.
+ // 2. Do not merge other flip-flops with synchronizer flip-flops.
+ // QuartusII TimeQuest directives:
+ // 1. Identify all flip-flops in this module as members of the synchronizer
+ // to enable automatic metastability MTBF analysis.
+
+ (* altera_attribute = {"-name ADV_NETLIST_OPT_ALLOWED NEVER_ALLOW; -name SYNCHRONIZER_IDENTIFICATION FORCED; -name DONT_MERGE_REGISTER ON; -name PRESERVE_REGISTER ON "} *) reg din_s1;
+
+ (* altera_attribute = {"-name ADV_NETLIST_OPT_ALLOWED NEVER_ALLOW; -name DONT_MERGE_REGISTER ON; -name PRESERVE_REGISTER ON"} *) reg [depth-2:0] dreg;
+
+ //synthesis translate_off
+ initial begin
+ if (depth <2) begin
+ $display("%m: Error: synchronizer length: %0d less than 2.", depth);
+ end
+ end
+
+ // the first synchronizer register is either a simple D flop for synthesis
+ // and non-metastable simulation or a D flop with a method to inject random
+ // metastable events resulting in random delay of [0,1] cycles
+
+`ifdef __ALTERA_STD__METASTABLE_SIM
+
+ reg[31:0] RANDOM_SEED = 123456;
+ wire next_din_s1;
+ wire dout;
+ reg din_last;
+ reg random;
+ event metastable_event; // hook for debug monitoring
+
+ initial begin
+ $display("%m: Info: Metastable event injection simulation mode enabled");
+ end
+
+ always @(posedge clk) begin
+ if (reset_n == 0)
+ random <= $random(RANDOM_SEED);
+ else
+ random <= $random;
+ end
+
+ assign next_din_s1 = (din_last ^ din) ? random : din;
+
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_last <= (rst_value == 0)? 1'b0 : 1'b1;
+ else
+ din_last <= din;
+ end
+
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_s1 <= (rst_value == 0)? 1'b0 : 1'b1;
+ else
+ din_s1 <= next_din_s1;
+ end
+
+`else
+
+ //synthesis translate_on
+ generate if (rst_value == 0)
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_s1 <= 1'b0;
+ else
+ din_s1 <= din;
+ end
+ endgenerate
+
+ generate if (rst_value == 1)
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ din_s1 <= 1'b1;
+ else
+ din_s1 <= din;
+ end
+ endgenerate
+ //synthesis translate_off
+
+`endif
+
+`ifdef __ALTERA_STD__METASTABLE_SIM_VERBOSE
+ always @(*) begin
+ if (reset_n && (din_last != din) && (random != din)) begin
+ $display("%m: Verbose Info: metastable event @ time %t", $time);
+ ->metastable_event;
+ end
+ end
+`endif
+
+ //synthesis translate_on
+
+ // the remaining synchronizer registers form a simple shift register
+ // of length depth-1
+ generate if (rst_value == 0)
+ if (depth < 3) begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b0}};
+ else
+ dreg <= din_s1;
+ end
+ end else begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b0}};
+ else
+ dreg <= {dreg[depth-3:0], din_s1};
+ end
+ end
+ endgenerate
+
+ generate if (rst_value == 1)
+ if (depth < 3) begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b1}};
+ else
+ dreg <= din_s1;
+ end
+ end else begin
+ always @(posedge clk or negedge reset_n) begin
+ if (reset_n == 0)
+ dreg <= {depth-1{1'b1}};
+ else
+ dreg <= {dreg[depth-3:0], din_s1};
+ end
+ end
+ endgenerate
+
+ assign dout = dreg[depth-2];
+
+endmodule
+
+
+
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_wait_generate.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_wait_generate.v
new file mode 100644
index 0000000..d470a8b
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_wait_generate.v
@@ -0,0 +1,48 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+`timescale 1 ps / 1 ps
+module altera_wait_generate
+//#(
+//This code only works when wait_cycle =1, if need other case, you need to modify this code.
+//please set wait_cycle default value as 1 to keep old design works.
+// parameter wait_cycle =1
+// )
+(
+ input wire rst,
+ input wire clk,
+ input wire launch_signal,
+ output wire wait_req
+ );
+reg launch_reg = 0;
+reg wait_reg = 0;
+always @ (posedge clk, posedge rst) begin
+ if(rst) launch_reg <= 1'b0;
+ else launch_reg <= launch_signal;
+end
+always @ (posedge clk, posedge rst) begin
+ if(rst) wait_reg <= 1'b0;
+ else wait_reg <= launch_signal & launch_reg & (! wait_reg & !wait_req);
+end
+
+
+// waitrequest should be asserted during reset - note that in the reconfig
+// controller, reset is locally synchronized. If you are using this module
+// outside the reconfig controller, you may want to ensure that the reset
+// signal is synchronized to prevent glitches, as waitrequest is not
+// necessarily a registered output.
+wire reset_sync;
+alt_xcvr_resync #(.INIT_VALUE (1)) rst_sync (.clk(clk),.reset(rst),.d(1'b0),.q(reset_sync));
+
+assign wait_req = reset_sync | (launch_signal & ~launch_reg) | (wait_reg & launch_signal ) ;
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_xcvr_functions.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_xcvr_functions.sv
new file mode 100644
index 0000000..1416fe7
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_xcvr_functions.sv
@@ -0,0 +1,906 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+//
+// Common functions for transceiver PHY IP
+//
+// $Header$
+//
+// PACKAGE DECLARATION
+package altera_xcvr_functions;
+ localparam integer MAX_CHARS = 86; // To accomodate LONG parameter lists.
+ localparam integer MAX_STRS = 16;
+ localparam integer MAX_XCVR_CHANNELS = 64;
+
+
+ // Reconfiguration bundle widths per family
+ localparam integer W_S5_RECONFIG_BUNDLE_TO_XCVR = 70;
+ localparam integer W_S5_RECONFIG_BUNDLE_FROM_XCVR = 46;
+ localparam integer W_A5_RECONFIG_BUNDLE_TO_XCVR = 70;
+ localparam integer W_A5_RECONFIG_BUNDLE_FROM_XCVR = 46;
+ localparam integer W_S4_RECONFIG_BUNDLE_TO_XCVR = 4;
+ localparam integer W_S4_RECONFIG_BUNDLE_FROM_XCVR = 17;
+ localparam integer W_C4_RECONFIG_BUNDLE_TO_XCVR = 4;
+ localparam integer W_C4_RECONFIG_BUNDLE_FROM_XCVR = 17;
+
+ // Reconfiguration bundle widths per family
+ localparam integer W_S5_RECONFIG_BUNDLE_TO_GXB = W_S5_RECONFIG_BUNDLE_TO_XCVR;
+ localparam integer W_S5_RECONFIG_BUNDLE_FROM_GXB = W_S5_RECONFIG_BUNDLE_FROM_XCVR;
+ localparam integer W_A5_RECONFIG_BUNDLE_TO_GXB = W_A5_RECONFIG_BUNDLE_TO_XCVR;
+ localparam integer W_A5_RECONFIG_BUNDLE_FROM_GXB = W_A5_RECONFIG_BUNDLE_FROM_XCVR;
+ localparam integer W_S4_RECONFIG_BUNDLE_TO_GXB = W_S4_RECONFIG_BUNDLE_TO_XCVR;
+ localparam integer W_S4_RECONFIG_BUNDLE_FROM_GXB = W_S4_RECONFIG_BUNDLE_FROM_XCVR;
+ localparam integer W_C4_RECONFIG_BUNDLE_TO_GXB = W_C4_RECONFIG_BUNDLE_TO_XCVR;
+ localparam integer W_C4_RECONFIG_BUNDLE_FROM_GXB = W_C4_RECONFIG_BUNDLE_FROM_XCVR;
+
+ // convert frequency string into integer Hz. Fractional Hz are truncated
+ // Must remain a constant function - can't use string.atoi().
+ function time str2hz (
+ input [8*MAX_CHARS:1] s
+ );
+
+ integer i;
+ integer c; // temp char storage for frequency conversion
+ integer unit_tens; // assume already Hz
+ integer is_numeric;
+ integer saw_dot;
+
+ reg [8:1] c_dot; // = ".";
+ reg [8:1] c_space; // = " ";
+ reg [8:1] c_a; // = 8'h61; //"a";
+ reg [8:1] c_z; // = 8'h7a; //"z";
+ reg [8*4:1] s_unit;
+ reg [8*MAX_CHARS:1] s_shift;
+
+ begin
+ // frequency ratio calculations
+ str2hz = 0;
+ unit_tens = 0; // assume already Hz
+ is_numeric = 1;
+ saw_dot = 0;
+ s_unit = "";
+
+ // Modelsim optimizer bug forces us to initialize these non-statically
+ c_dot = ".";
+ c_space = " ";
+ c_a = "a";
+ c_z = "z";
+ for (i=(MAX_CHARS-1); i>=0; i=i-1) begin
+ s_shift = (s >> (i*8));
+ c = s_shift[8:1] & 8'hff;
+ if (c > 0) begin
+ //$display("[%d] => '%1s',", i, c);
+ if (c >= 8'h30 && c <= 8'h39 && is_numeric) begin
+ str2hz = (str2hz * 10) + (c & 8'h0f);
+ if (saw_dot) unit_tens = unit_tens - 1; // count digits after decimal point
+ end else if (c == c_dot) saw_dot = 1;
+ else if (c != c_space) begin
+ is_numeric = 0; // stop accepting new numeric digits in value
+ // if it's a-z, convert to upper case A-Z
+ if (c >= c_a && c <= c_z) c = (c & 8'h5f); // convert a-z (lower) to A-Z (upper)
+ s_unit = (s_unit << 8) | c;
+ end
+ end
+ end
+ //$display("numeric = %d x 10**(%2d), unit = '%0s'", str2hz, unit_tens, s_unit);
+
+ // account for frequency unit
+ if (s_unit == "GHZ" || s_unit == "GBPS") unit_tens = unit_tens + 9; // 10**9
+ else if (s_unit == "MHZ" || s_unit == "MBPS") unit_tens = unit_tens + 6; // 10**6
+ else if (s_unit == "KHZ" || s_unit == "KBPS") unit_tens = unit_tens + 3; // 10**3
+ else if (s_unit != "HZ" && s_unit != "BPS") begin
+ $display("Invalid frequency unit '%0s', assuming %d x 10**(%2d) 'Hz'", s_unit, str2hz, unit_tens);
+ end
+ //$display("numeric in Hz = %d x 10**(%2d)", str2hz, unit_tens);
+
+ // align numeric to Hz
+ if (unit_tens < 0) begin
+ //str2hz = str2hz / (10**(-unit_tens));
+ for (i=0; i>unit_tens; i=i-1) begin
+ str2hz = str2hz / 10;
+ end
+ end else begin
+ //str2hz = str2hz * (10**unit_tens);
+ for (i=0; i 0; pos = pos + 1) begin
+ if (f_unit == 0) begin
+ hz2str[pos*8 +: 8] = 8'h2e; // add "." character
+ pos = pos + 1;
+ end
+ f_unit = f_unit - 1;
+ hz_mod_10 = (hz % 10);
+ hz2str[pos*8 +: 8] = hz_mod_10[7:0] | 8'h30;
+ hz = hz / 10;
+ //$display("hz2str() => so far '%s', pos (%d), f_unit(%d) ", hz2str, pos, f_unit);
+ end
+ //$display("hz2str() returns '%s'", hz2str);
+ end
+ endfunction
+
+ // Convert a string to an integer
+ // Uses pre-existing str2hz function
+ function integer str2int(
+ input [MAX_CHARS*8-1:0] instring
+ );
+ time temp;
+ temp = str2hz(instring); // str2hz assume Hertz as default unit. Don't need to add 'Hz' to input.
+ str2int = temp[31:0];
+ endfunction
+
+
+ // Convert an integer to a string
+ function [MAX_CHARS*8-1:0] int2str(
+ input integer in_int
+ );
+ integer i;
+ integer this_char;
+ i = 0;
+ int2str = "";
+ do
+ begin
+ this_char = (in_int % 10) + 48;
+ int2str[i*8+:8] = this_char[7:0];
+ i=i+1;
+ in_int = in_int / 10;
+ end
+ while(in_int > 0);
+ endfunction
+
+ // function to convert at most 40-bit long string to binary
+ function [39 : 0] m_str_to_bin;
+ input [40*8 : 1] s;
+ reg [40*8 : 1] reg_s;
+ reg [40:1] res;
+
+ integer m;
+ begin
+
+ reg_s = s;
+ for (m = 40; m > 0; m = m-1 )
+ begin
+ res[m] = reg_s[313];
+ reg_s = reg_s << 8;
+ end
+
+ m_str_to_bin = res;
+ end
+ endfunction
+
+
+ //////////////////////////////
+ // Convert the argument string to a 64-bit binary value
+ // @hex_str The string to be converted specified as an ASCII hexadecimal string
+ function [63:0] m_hex_to_bin (
+ input [8*MAX_CHARS-1:0] hex_str
+ );
+ integer i;
+
+ reg [63:0] out; // = 64'h0000_0000_0000_0000;
+ reg [7:0] this_char;
+
+ begin
+
+ out = 64'h0000_0000_0000_0000;
+
+ for(i=0; i<16; i=i+1) begin
+ this_char = hex_str[i*8+:8];
+ if(this_char >= 48 && this_char <= 57)
+ out[i*4+:4] = this_char - 48;
+ else if(this_char >= 65 && this_char <= 70)
+ out[i*4+:4] = this_char - 55;
+ else if(this_char >= 97 && this_char <= 102)
+ out[i*4+:4] = this_char - 87;
+ else begin
+ out[i*4+:4] = 0;
+ end
+ end
+ end
+ m_hex_to_bin = out;
+ endfunction
+
+
+
+ ////////////////////////////////////////////////////////////////////
+ // Verify that the string value is contained in the legal set.
+ //
+ // The 'set' can consist of a single string with no delimiters, e.g. "individual",
+ // or multiple values, separated by commas, and surrounded by parens, e.g. "(one,two,three,four,five)"
+ //
+ // Returns 1 if the value is in the set, and 0 otherwise
+ function integer is_in_legal_set(
+ input [MAX_CHARS*8-1:0] value,
+ input [MAX_STRS*MAX_CHARS*8-1:0] set
+ );
+ if (value == "")
+ is_in_legal_set = 1;
+ else if (value == "")
+ is_in_legal_set = (set[7:0] == 8'h29) ? 0 : 1; // 8'h29 is closing parenthesis char
+ else if (value == set)
+ is_in_legal_set = 1; // value matches single value in set
+ else begin
+ // check value against each in set
+ integer close_pos; // end of string marker can be comma or closing paren
+ integer open_pos; // open paren is start of set, if appropriate
+ reg [MAX_STRS*MAX_CHARS*8-1:0] legalstr;
+
+ is_in_legal_set = 0;
+ open_pos = MAX_STRS*MAX_CHARS-1;
+ // Remove closing parenthesis if exists
+ if(set[7:0] == 8'h29) begin
+ set = (set >> 8);
+ set[(MAX_STRS*MAX_CHARS*8-1)-:8] = 8'h00;
+ end
+ // look for first non-null and non open paren character
+ while (open_pos > 0 && (set[open_pos*8 +: 8] == 8'h00 || set[open_pos*8 +: 8] == 8'h28)) // look for first non-null
+ open_pos = open_pos - 1;
+
+ while (is_in_legal_set == 0 && open_pos >= 0) begin
+ close_pos = open_pos;
+ while (close_pos > 0
+ && set[close_pos*8 +: 8] != 8'h2c) // look for comma (8'h2c)
+ close_pos = close_pos - 1;
+ if (close_pos >= 0) begin
+ close_pos = close_pos == 0 ? 0 : close_pos + 1;
+ legalstr = ((set & ((1'b1 << open_pos*8+8)-1)) >> close_pos*8);
+ if (value == legalstr)
+ is_in_legal_set = 1;
+ end
+ open_pos = close_pos-2; // prepare to look for next legal string
+ end
+ end
+ //$display("is_in_legal_set(): returns %d", is_in_legal_set);
+ endfunction
+
+
+ // Accepts a string list of comma seperated numbers and returns a binary
+ // field where each bit indicates whether the index corresponding to that bit
+ // was found in the legal set.
+ //
+ // @param count - The number of integer indexes to check for in the set
+ // or the highest integer minus 1.
+ // @param set - The list containing the integer values to search for
+ // @return - A bitfield where each bit indicates whether the corresponding
+ // integer was found in the legal set.
+ function [MAX_XCVR_CHANNELS-1:0] map_numerical_is_in_legal_set(
+ input integer count,
+ input [MAX_STRS*MAX_CHARS*8-1:0] set
+ );
+ integer index;
+ reg [MAX_XCVR_CHANNELS-1:0] retval;
+
+ // Validate count parameter
+ if(count > MAX_XCVR_CHANNELS)
+ $display("Error: [map_numerical_is_in_legal_set]: Invalid value for count: %0d",count);
+
+ map_numerical_is_in_legal_set = {MAX_XCVR_CHANNELS{1'b0}};
+ retval = {MAX_XCVR_CHANNELS{1'b0}};
+ for(index = 0; index < count; index = index + 1) begin
+ if(is_in_legal_set(int2str(index),set))
+ retval = retval | (({MAX_XCVR_CHANNELS{1'b0}} | 1'b1) << index);
+ end
+ map_numerical_is_in_legal_set = retval;
+ endfunction
+
+
+ // Accepts a string list of comma seperated numbers and returns a binary
+ // field where each byte contains the corresponding number found in the
+ // list.
+ //
+ // @param count - The number of elements in the list.
+ // @param set - The list containing the integer values.
+ // @return - A bitfield where each byte contains the corresponding number found
+ // at that location in the list.
+ function [MAX_XCVR_CHANNELS*8-1:0] map_numerical_legal_set(
+ input integer count,
+ input [MAX_STRS*MAX_CHARS*8-1:0] set
+ );
+ integer index;
+ reg [MAX_XCVR_CHANNELS-1:0] retval;
+ reg [MAX_CHARS*8-1:0] str_val;
+ reg [7:0] int_val;
+
+ // Validate count parameter
+ if(count > MAX_XCVR_CHANNELS || count > 256)
+ $display("Error: [map_numerical_legal_set]: Invalid value for count: %0d",count);
+
+ map_numerical_legal_set = {MAX_XCVR_CHANNELS{8'd0}};
+ retval = {MAX_XCVR_CHANNELS{8'd0}};
+ for(index = 0; index < count; index = index + 1) begin
+ str_val = get_value_at_index(index,set);
+ if(str_val != "NA") begin
+ int_val = str2int(str_val);
+ if(int_val > 255)
+ $display("Error: [map_numerical_legal_set]: Invalid string contains non-numerical item or value:%0d",int_val);
+ else begin
+ retval = retval | ( ( {MAX_XCVR_CHANNELS{8'd0}} | int_val ) << (index * 8));
+ end
+ end
+ end
+ map_numerical_legal_set = retval;
+ endfunction
+
+
+ // Accepts a comma separated list of string values and returns the element
+ // found at the specified index. If the index is invalid, "NA" is returned
+ //
+ // @param index - The index of the value to return within "set"
+ // @param set - A comma separated list of string values. The entire list may
+ // be surrounded by parenthesis("(item0,item1,item2)")
+ function [MAX_CHARS*8-1:0] get_value_at_index(
+ input integer index,
+ input [MAX_STRS*MAX_CHARS*8-1:0] set
+ );
+ // check value against each in set
+ integer close_pos; // end of string marker can be comma or closing paren
+ integer open_pos; // open paren is start of set, if appropriate
+ reg [MAX_STRS*MAX_CHARS*8-1:0] legalstr;
+ integer cur_index;
+
+ get_value_at_index = "";
+ legalstr = "NA";
+ cur_index = 0;
+ open_pos = MAX_STRS*MAX_CHARS-1;
+ // Remove closing parenthesis if exists
+ if(set[7:0] == 8'h29) begin
+ set = (set >> 8);
+ set[(MAX_STRS*MAX_CHARS*8-1)-:8] = 8'h00;
+ end
+ // Find the start of the string
+ while (open_pos >= 1 && (set[open_pos*8 +: 8] == 8'h00 || set[open_pos*8 +: 8] == 8'h28)) // look for first non-null
+ open_pos = open_pos - 1;
+
+ // Iterate through list until the string is found or we've reached the end of the list
+ while (legalstr == "NA" && open_pos >= 0 && cur_index <= index) begin
+ close_pos = open_pos;
+ // Move the close iterator to the end of the current value (or end of string)
+ while (close_pos > 0
+ && set[close_pos*8 +: 8] != 8'h2c) // look for comma (8'h2c)
+ close_pos = close_pos - 1;
+ if (close_pos >= 0) begin
+ close_pos = close_pos == 0 ? 0 : close_pos + 1;
+ if(index == cur_index) begin
+ legalstr = ((set & ((1'b1 << open_pos*8+8)-1)) >> close_pos*8);
+ end
+ open_pos = close_pos-2; // prepare to look for next legal string
+ end
+ cur_index = cur_index + 1;
+ end
+
+ cur_index = 0;
+ while(legalstr[cur_index*8+:8] != 0) begin
+ get_value_at_index[cur_index*8+:8] = legalstr[cur_index*8+:8];
+ cur_index = cur_index + 1;
+ end
+
+ //$display("is_in_legal_set(): returns %d", is_in_legal_set);
+ endfunction
+
+ // The goal was to return one of the values, does not matter which one.
+ // ~45 times faster than get_value_at_index( 0, set );
+ function [MAX_CHARS*8-1:0] get_first_enum_value( input [MAX_STRS*MAX_CHARS*8-1:0] set );
+
+ int start_pos, cur_idx;
+ bit [7:0] cur_set_char;
+
+ // Ensure null-terminating the string.
+ // MODIFIED: Work around for a QuestaSim vopt bug: set[(MAX_STRS*MAX_CHARS*8-8) +: 8 ] = 8'h00;
+ set [ ( MAX_STRS * MAX_CHARS * 8 -1) : ( MAX_STRS * MAX_CHARS * 8 - 8) ] = 8 'h00 ;
+
+ start_pos = set[7:0] == 8'h29 ? 8 : 0;
+ cur_idx = 0;
+
+ get_first_enum_value = "";
+
+ forever
+ begin
+ cur_set_char = set[ cur_idx + start_pos +: 8 ];
+
+ // comma, par or 0
+ if ( cur_set_char == 8'h2c || cur_set_char == 8'h28 || cur_set_char == 8'h00 )
+ break;
+
+ get_first_enum_value[ cur_idx +: 8 ] = cur_set_char;
+ cur_idx = cur_idx + 8;
+ end
+
+ // get_first_enum_value = get_value_at_index( 0, set );
+
+ endfunction
+
+ // This functions is ~12 times faster than is_in_legal_set
+ function integer is_enum_in_legal_set( input [MAX_CHARS*8-1:0] value, input [MAX_STRS*MAX_CHARS*8-1:0] set );
+
+ if ( value == "" )
+ return 1;
+ else if (value == "")
+ return (set[7:0] == 8'h29) ? 0 : 1; // 8'h29 is closing parenthesis char
+ else if (value == set)
+ return 1; // value matches single value in set
+ else
+ begin
+ // ')'
+ int set_pos;
+ set_pos = 0;
+ if ( set[7:0] == 8'h29 )
+ set_pos = 8;
+
+ // Ensure null-terminating the string.
+ set[(MAX_STRS*MAX_CHARS*8-8) +: 8 ] = 8'h00;
+
+ forever
+ begin
+ int cur_cmp_len;
+ cur_cmp_len = 0;
+
+ // $display( "set_pos ", set_pos/8 );
+
+ forever
+ begin
+
+ int cur_val_char, cur_set_char;
+ cur_val_char = value[ cur_cmp_len +: 8 ];
+ cur_set_char = set[ set_pos +: 8 ];
+
+ // $display( "comparing ", set_pos/8, cur_cmp_len/8, " " , value[ cur_cmp_len +: 8 ], " ", set[ set_pos +: 8 ] );
+
+ if ( cur_val_char == 0 )
+ // The end of value reached, check whether set has comma, par or 0
+ if ( cur_set_char == 8'h2c || cur_set_char == 8'h28 || cur_set_char == 8'h00 )
+ return 1;
+
+ if ( cur_val_char != cur_set_char )
+ break;
+
+ cur_cmp_len = cur_cmp_len + 8;
+ set_pos = set_pos + 8;
+ end
+
+ forever
+ begin
+ int cur_set_char;
+ cur_set_char = set[ set_pos +: 8 ];
+
+ // $display( "skipping ", set_pos/8 );
+
+ // ','
+ if ( cur_set_char == 8'h2c )
+ begin
+ set_pos = set_pos + 8;
+ break;
+ end
+
+ if ( cur_set_char == 8'h00 )
+ return 0;
+
+ set_pos = set_pos + 8;
+
+ end
+ end
+ end
+
+ endfunction
+
+ // The first parameter is just a number, NOT a string
+ function integer is_numeric_in_legal_set( input [MAX_CHARS*8-1:0] value, input [MAX_STRS*MAX_CHARS*8-1:0] set );
+ is_numeric_in_legal_set = 1;
+ endfunction
+
+ // AP stubs --- end
+
+
+ ////////////////////////////////////////////////////////////////////////
+ // Returns ceil_log2() value
+ localparam integer MAX_PRECISION = 32; // VCS requires this declaration outside the function
+ function integer ceil_log2;
+ input [MAX_PRECISION-1:0] input_num;
+ integer i;
+ reg [MAX_PRECISION-1:0] try_result;
+ begin
+ i = 0;
+ try_result = 1;
+ while ((try_result << i) < input_num && i < MAX_PRECISION)
+ i = i + 1;
+ ceil_log2 = i;
+ end
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Return the number of bits required to represent an integer
+ // E.g. 0->1; 1->1; 2->2; 3->2 ... 31->5; 32->6
+ //
+ function integer clogb2;
+ input [MAX_PRECISION-1:0] input_num;
+ begin
+ for (clogb2=0; input_num>0 && clogb2> 1;
+ if(clogb2 == 0)
+ clogb2 = 1;
+ end
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Return current device family string for display purposes
+ `ifndef XCVR_DEV_FAM
+ `ifdef ALTERA_RESERVED_QIS_FAMILY
+ `define XCVR_DEV_FAM `ALTERA_RESERVED_QIS_FAMILY // synthesis: use QIS-defined value
+ `else
+ `define XCVR_DEV_FAM device_family // simulation: use passed-in value
+ `endif
+ `endif
+ function [MAX_CHARS*8-1:0] current_device_family (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ current_device_family = `XCVR_DEV_FAM;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Match device family against standard family name strings
+ //
+ // Returns 1 if the names feature is present in the given device family
+ function integer has_s4_style_hssi (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ has_s4_style_hssi = ( (`XCVR_DEV_FAM == "Stratix IV")
+ || (`XCVR_DEV_FAM == "Arria II")
+ || (`XCVR_DEV_FAM == "Cyclone IV GX") // not exact, but close enough
+ || (`XCVR_DEV_FAM == "Arria II GX")
+ || (`XCVR_DEV_FAM == "Arria II GZ")
+ || (`XCVR_DEV_FAM == "HardCopy IV")
+ ) ? 1 : 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Match device family against standard family name strings
+ //
+ // Returns 1 if the names feature is present in the given device family
+ function integer has_s5_style_hssi (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ has_s5_style_hssi = ( (`XCVR_DEV_FAM == "Stratix V") || (`XCVR_DEV_FAM == "Arria V GZ")
+ ) ? 1 : 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Match device family against standard family name strings
+ //
+ // Returns 1 if the names feature is present in the given device family
+ function integer has_a5_style_hssi (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ has_a5_style_hssi = ( (`XCVR_DEV_FAM == "Arria V")
+ ) ? 1 : 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Match device family against standard family name strings
+ //
+ // Returns 1 if the names feature is present in the given device family
+ function integer has_c5_style_hssi (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ has_c5_style_hssi = ( (`XCVR_DEV_FAM == "Cyclone V")
+ ) ? 1 : 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Match device family against standard family name strings
+ //
+ // Returns 1 if the names feature is present in the given device family
+ function integer has_c4_style_hssi (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ has_c4_style_hssi = ( (`XCVR_DEV_FAM == "Cyclone IV GX")
+ ) ? 1 : 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_to_gxb bundle width for specified device family
+ //
+ // Returns 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_to_gxb bundle for that family
+ function integer get_reconfig_to_gxb_width (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ if (has_s5_style_hssi(device_family) || has_a5_style_hssi(device_family) || has_c5_style_hssi(device_family))
+ get_reconfig_to_gxb_width = W_S5_RECONFIG_BUNDLE_TO_XCVR;
+ else if (has_s4_style_hssi(device_family))
+ get_reconfig_to_gxb_width = W_S4_RECONFIG_BUNDLE_TO_XCVR;
+ else if (has_c4_style_hssi(device_family))
+ get_reconfig_to_gxb_width = W_C4_RECONFIG_BUNDLE_TO_XCVR;
+ else
+ get_reconfig_to_gxb_width = 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_from_gxb bundle width for specified device family
+ //
+ // Returns 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_gxb bundle for that family
+ function integer get_reconfig_from_gxb_width (
+ input [MAX_CHARS*8-1:0] device_family
+ );
+ if (has_s5_style_hssi(device_family) || has_a5_style_hssi(device_family) || has_c5_style_hssi(device_family))
+ get_reconfig_from_gxb_width = W_S5_RECONFIG_BUNDLE_FROM_XCVR;
+ else if (has_s4_style_hssi(device_family))
+ get_reconfig_from_gxb_width = W_S4_RECONFIG_BUNDLE_FROM_XCVR;
+ else if (has_c4_style_hssi(device_family))
+ get_reconfig_from_gxb_width = W_C4_RECONFIG_BUNDLE_FROM_XCVR;
+ else
+ get_reconfig_from_gxb_width = 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_to_xcvr total port width for specified device family
+ //
+ // Returns 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_to_xcvr port for that family
+ function integer get_reconfig_to_width (
+ input [MAX_CHARS*8-1:0] device_family,
+ input integer reconfig_interfaces
+ );
+ if (has_s5_style_hssi(device_family) || has_a5_style_hssi(device_family) || has_c5_style_hssi(device_family))
+ get_reconfig_to_width = get_s5_reconfig_to_width(reconfig_interfaces);
+ else if (has_s4_style_hssi(device_family))
+ get_reconfig_to_width = W_S4_RECONFIG_BUNDLE_TO_XCVR;
+ else if (has_c4_style_hssi(device_family))
+ get_reconfig_to_width = W_C4_RECONFIG_BUNDLE_TO_XCVR;
+ else
+ get_reconfig_to_width = 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_to_xcvr total port width for Stratix V device family
+ //
+ function integer get_s5_reconfig_to_width (
+ input integer reconfig_interfaces
+ );
+ get_s5_reconfig_to_width = reconfig_interfaces * get_reconfig_to_gxb_width("Stratix V");
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_from_xcvr total port width for specified device family
+ //
+ // Returns 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_xcvr port for that family
+ function integer get_reconfig_from_width (
+ input [MAX_CHARS*8-1:0] device_family,
+ input integer reconfig_interfaces
+ );
+ if (has_s5_style_hssi(device_family) || has_a5_style_hssi(device_family) || has_c5_style_hssi(device_family))
+ get_reconfig_from_width = reconfig_interfaces * get_reconfig_from_gxb_width(device_family);
+ else if (has_s4_style_hssi(device_family))
+ get_reconfig_from_width = reconfig_interfaces * get_reconfig_from_gxb_width(device_family);
+ else if (has_c4_style_hssi(device_family))
+ get_reconfig_from_width = reconfig_interfaces * get_reconfig_from_gxb_width(device_family);
+ else
+ get_reconfig_from_width = 0;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_from_xcvr total port width for Stratix V device family
+ //
+ function integer get_s5_reconfig_from_width (
+ input integer reconfig_interfaces
+ );
+ get_s5_reconfig_from_width = reconfig_interfaces * get_reconfig_from_gxb_width("Stratix V");
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get number of reconfig interfaces for Custom PHY
+ // NOTE - !!Has since been used by other PHY IP!!
+ //
+ // @param device_family - Desired device family
+ // @param operation_mode - "Duplex","Rx","Tx" or "duplex", "rx_only", "tx_only" in 10gbaser
+ // @param lanes - Number of channels
+ // @param plls - Number of TX plls (per channel)
+ // @param bonded_group_size - Size of bonded group (1 or lanes)
+ // @param data_path_type - Abuse of function by overloading for ATT support
+ // - Carry on the abuse
+ //
+ // @return 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_xcvr port for that family
+ function integer get_custom_reconfig_interfaces(
+ input [MAX_CHARS*8-1:0] device_family,
+ input [MAX_CHARS*8-1:0] operation_mode,
+ input integer lanes,
+ input integer plls,
+ input integer bonded_group_size,
+ input [MAX_CHARS*8-1:0] data_path_type = "",
+ input [MAX_CHARS*8-1:0] bonded_mode = "xN"
+ );
+ integer reconfig_interfaces;
+ reconfig_interfaces = 0;
+ if (has_s5_style_hssi(device_family) || has_a5_style_hssi(device_family) || has_c5_style_hssi(device_family)) begin
+ // ATT specific calculations
+ if( data_path_type == "ATT" ) begin
+ if((operation_mode == "RX_ONLY") || (operation_mode == "rx_only") || (operation_mode == "Rx") || (operation_mode == "RX") || (operation_mode == "rx")) begin
+ reconfig_interfaces = lanes;
+ end else if((operation_mode == "TX_ONLY") || (operation_mode == "tx_only") || (operation_mode == "Tx") || (operation_mode == "TX") || (operation_mode == "tx")) begin
+ reconfig_interfaces = 2*lanes;
+ end else begin
+ reconfig_interfaces = 3*lanes;
+ end
+ end else begin
+ // Custom PHY calculations
+ if((operation_mode == "RX") || (operation_mode == "Rx") || (operation_mode == "rx_only"))
+ reconfig_interfaces = lanes;
+ else begin
+ bonded_group_size = (bonded_mode == "fb_compensation") ? 1 :
+ (bonded_mode == "non_bonded") ? 1 : bonded_group_size;
+ reconfig_interfaces = lanes+(plls*(lanes/bonded_group_size));
+ end
+ end
+ end
+ get_custom_reconfig_interfaces = reconfig_interfaces;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_to_xcvr total port width for Custom PHY
+ //
+ // @param device_family - Desired device family
+ // @param operation_mode - "Duplex","Rx","Tx" or "duplex", "rx_only", "tx_only" in 10gbaser
+ // @param lanes - Number of transceiver channels
+ // @param plls - Number of plls per bonded group
+ // @param bonded_group_size - Size of bonded group (1 or lanes)
+ // @param data_path_type - Abuse of function to support ATT
+ //
+ // @return - 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_xcvr port for that family
+ function integer get_custom_reconfig_to_width(
+ input [MAX_CHARS*8-1:0] device_family,
+ input [MAX_CHARS*8-1:0] operation_mode,
+ input integer lanes,
+ input integer plls,
+ input integer bonded_group_size,
+ input [MAX_CHARS*8-1:0] data_path_type = "",
+ input [MAX_CHARS*8-1:0] bonded_mode = "xN"
+ );
+ integer reconfig_interfaces;
+ reconfig_interfaces = get_custom_reconfig_interfaces(device_family,operation_mode,lanes,plls,bonded_group_size, data_path_type, bonded_mode );
+ get_custom_reconfig_to_width = get_s5_reconfig_to_width(reconfig_interfaces);
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_from_xcvr total port width for Custom PHY
+ //
+ // @param device_family - Desired device family
+ // @param operation_mode - "Duplex","Rx","Tx" or "duplex", "rx_only", "tx_only" in 10gbaser
+ // @param lanes - Number of transceiver channels
+ // @param plls - Number of plls per bonded group
+ // @param bonded_group_size - Size of bonded group (1 or lanes)
+ // @param data_path_type - Abuse of function to support ATT
+ //
+ // @return - 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_xcvr port for that family
+ function integer get_custom_reconfig_from_width(
+ input [MAX_CHARS*8-1:0] device_family,
+ input [MAX_CHARS*8-1:0] operation_mode,
+ input integer lanes,
+ input integer plls,
+ input integer bonded_group_size,
+ input [MAX_CHARS*8-1:0] data_path_type = "",
+ input [MAX_CHARS*8-1:0] bonded_mode = "xN"
+ );
+ integer reconfig_interfaces;
+ reconfig_interfaces = get_custom_reconfig_interfaces(device_family,operation_mode,lanes,plls,bonded_group_size, data_path_type, bonded_mode);
+ get_custom_reconfig_from_width = get_s5_reconfig_from_width(reconfig_interfaces);
+ endfunction
+
+
+ ////////////////////////////////////////////////////////////////////
+ // Start Interlaken Specific functions for calculating reconfig interfaces
+ // and reconfig_to_gxb, reconfig_from_gxb widths
+
+ ////////////////////////////////////////////////////////////////////
+ // Get number of reconfig interfaces for Interlaken PHY
+ //
+ // @param device_family - Desired device family
+ // @param operation_mode - "Duplex","Rx","Tx" or "duplex", "rx_only", "tx_only" in 10gbaser
+ // Returns 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_xcvr port for that family
+ function integer get_interlaken_reconfig_interfaces(
+ input [MAX_CHARS*8-1:0] device_family,
+ input [MAX_CHARS*8-1:0] operation_mode,
+ input integer bonded_group_size,
+ input integer lanes
+ );
+ integer reconfig_interfaces;
+ integer xslices;
+ integer xremain;
+ integer totalplls;
+
+ reconfig_interfaces = 0;
+ if (has_s5_style_hssi(device_family) || has_a5_style_hssi(device_family) || has_c5_style_hssi(device_family)) begin
+ if((operation_mode == "RX") || (operation_mode == "Rx") || (operation_mode == "rx_only"))
+ reconfig_interfaces = lanes;
+ else begin
+ xslices = lanes/bonded_group_size;
+ xremain = lanes % bonded_group_size;
+
+ if (xremain >0)
+ totalplls = xslices +1;
+ else
+ totalplls = xslices;
+ reconfig_interfaces = lanes+totalplls;
+ end // else: !if((operation_mode == "RX") || (operation_mode == "Rx") || (operation_mode == "rx_only"))
+ end // if (has_s5_style_hssi(device_family))
+ get_interlaken_reconfig_interfaces = reconfig_interfaces;
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_to_xcvr total port width for Interlaken PHY
+ //
+ // @param device_family - Desired device family
+ // @param operation_mode - "Duplex","Rx","Tx" or "duplex", "rx_only", "tx_only" in 10gbaser
+ // @param lanes - Number of transceiver channels
+ // Returns 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_xcvr port for that family
+ function integer get_interlaken_reconfig_to_width(
+ input [MAX_CHARS*8-1:0] device_family,
+ input [MAX_CHARS*8-1:0] operation_mode,
+ input integer bonded_group_size,
+ input integer lanes
+ );
+ integer reconfig_interfaces;
+ reconfig_interfaces = get_interlaken_reconfig_interfaces(device_family,operation_mode,bonded_group_size,lanes);
+ get_interlaken_reconfig_to_width = get_s5_reconfig_to_width(reconfig_interfaces);
+ endfunction
+
+ ////////////////////////////////////////////////////////////////////
+ // Get reconfig_from_xcvr total port width for Custom PHY
+ //
+ // @param device_family - Desired device family
+ // @param operation_mode - "Duplex","Rx","Tx" or "duplex", "rx_only", "tx_only" in 10gbaser
+ // Returns 0 if the device_family argument is invalid, otherwise
+ // it returns the width of the reconfig_from_xcvr port for that family
+ function integer get_interlaken_reconfig_from_width(
+ input [MAX_CHARS*8-1:0] device_family,
+ input [MAX_CHARS*8-1:0] operation_mode,
+ input integer bonded_group_size,
+ input integer lanes
+ );
+ integer reconfig_interfaces;
+ reconfig_interfaces = get_interlaken_reconfig_interfaces(device_family,operation_mode,bonded_group_size,lanes);
+ get_interlaken_reconfig_from_width = get_s5_reconfig_from_width(reconfig_interfaces);
+ endfunction
+
+ // End Interlaken specific functions
+ ////////////////////////////////////////////////////////////////////
+
+
+
+
+
+endpackage
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_xcvr_reset_control.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_xcvr_reset_control.sv
new file mode 100644
index 0000000..07bdfb9
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/altera_xcvr_reset_control.sv
@@ -0,0 +1,441 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+
+// File Name: altera_xcvr_reset_control.sv
+//
+// Description:
+//
+// A configurable reset controller intended to drive resets for HSSI transceiver PLLs and CHANNELS.
+// The reset controller makes use of individual reset counters to control reset timing for the various reset
+// outputs.
+//
+// Features:
+// - Optional TX,RX,PLL reset control.
+// - Optional synchronization of the reset input
+// - Optional hysteresis for the pll_locked status inputs
+// - Reset control per channel or shared. (E.g. separate rx_digitalreset control for each channel
+// or one control for all channels)
+// - Configurable reset timings
+// - Optional automatic or manual reset control mode
+// (For TX, tx_digitalreset can automatically be restarted on loss of pll_locked)
+// (For RX, rx_digitalreset can automatically be restarted on loss of rx_is_lockedtodata)
+
+`timescale 1ns / 1ns
+`ifndef ALTERA_RESERVED_QIS_FAMILY_ARRIA10
+(* altera_attribute = "-name MERGE_TX_PLL_DRIVEN_BY_REGISTERS_WITH_SAME_CLEAR ON -to \"alt_xcvr_reset_counter:g_pll.counter_pll_powerdown|r_reset\" " *)
+`endif
+//altera message_off 10036
+module altera_xcvr_reset_control
+#(
+ // General Options
+ parameter CHANNELS = 1, // Number of CHANNELS
+ parameter PLLS = 1, // Number of TX PLLs. For pll_powerdown and pll_locked
+ parameter SYS_CLK_IN_MHZ = 250, // Clock frequency in MHz. Required for reset timers
+ parameter SYNCHRONIZE_RESET = 1, // (0,1) Synchronize the reset input
+ parameter REDUCED_SIM_TIME = 1, // (0,1) 1=Reduced reset timings for simulation
+ // PLL options
+ parameter TX_PLL_ENABLE = 0, // (0,1) Enable TX PLL reset
+ parameter T_PLL_POWERDOWN = 1000, // pll_powerdown period in ns
+ parameter SYNCHRONIZE_PLL_RESET = 0,// (0,1) Use synchronized reset input for PLL powerdown
+ // !NOTE! Will prevent PLL merging across reset controllers
+ // !NOTE! Requires SYNCHRONIZE_RESET == 1
+ // TX options
+ parameter TX_ENABLE = 0, // (0,1) Enable TX resets
+ parameter TX_PER_CHANNEL = 0, // (0,1) 1=separate TX reset per channel
+ parameter T_TX_ANALOGRESET = 0, // tx_analogreset period (after reset removal)
+ parameter T_TX_DIGITALRESET = 20, // tx_digitalreset period (after pll_powerdown)
+ parameter T_PLL_LOCK_HYST = 0, // Amount of hysteresis to add to pll_locked status signal
+ // RX options
+ parameter RX_ENABLE = 0, // (0,1) Enable RX resets
+ parameter RX_PER_CHANNEL = 0, // (0,1) 1=separate RX reset per channel
+ parameter T_RX_ANALOGRESET = 40, // rx_analogreset period
+ parameter T_RX_DIGITALRESET = 4000, // rx_digitalreset period (after rx_is_lockedtodata)
+ // CAL BUSY option
+ parameter EN_PLL_CAL_BUSY = 0
+) (
+ // User inputs and outputs
+ input wire clock, // System clock
+ input wire reset, // Asynchronous reset
+
+ // Reset signals
+ output wire [PLLS-1:0] pll_powerdown, // reset TX PLL (to PHY/PLL)
+ output wire [CHANNELS-1:0] tx_analogreset, // reset TX PMA (to PHY)
+ output wire [CHANNELS-1:0] tx_digitalreset, // reset TX PCS (to PHY)
+ output wire [CHANNELS-1:0] rx_analogreset, // reset RX PMA (to PHY)
+ output wire [CHANNELS-1:0] rx_digitalreset, // reset RX PCS (to PHY)
+ // Status output
+ output wire [CHANNELS-1:0] tx_ready, // TX is not in reset
+ output wire [CHANNELS-1:0] rx_ready, // RX is not in reset
+
+ // Digital reset override inputs (must by synchronous with clock)
+ input wire [CHANNELS-1:0] tx_digitalreset_or, // reset request for tx_digitalreset
+ input wire [CHANNELS-1:0] rx_digitalreset_or, // reset request for rx_digitalreset
+
+ // TX control inputs
+ input wire [PLLS-1:0] pll_locked, // TX PLL lock status (from PHY/PLL)
+ input wire [pll_select_width(PLLS,TX_PER_CHANNEL,CHANNELS)-1:0] pll_select, // Select TX PLL locked signal
+ input wire [CHANNELS-1:0] tx_cal_busy, // TX channel calibration status (from PHY/Reconfig)
+ input wire [PLLS-1:0] pll_cal_busy, // TX PLL calibration status (from PLL)
+ input wire [CHANNELS-1:0] tx_manual, // 0 = Automatically restart tx_digitalreset
+ // when pll_locked deasserts.
+ // 1 = Do nothing when pll_locked deasserts
+ // RX control inputs
+ input wire [CHANNELS-1:0] rx_is_lockedtodata, // RX CDR PLL locked-to-data status (from PHY)
+ input wire [CHANNELS-1:0] rx_cal_busy, // RX channel calibration status (from PHY/Reconfig)
+ input wire [CHANNELS-1:0] rx_manual // 0 = Automatically restart rx_digitalreset
+ // when rx_is_lockedtodata deasserts
+ // 1 = Do nothing when rx_is_lockedtodata deasserts
+);
+
+// Faster reset time for simulation if indicated
+localparam SYNTH_CLK_IN_HZ = SYS_CLK_IN_MHZ * 1000000;
+localparam SIM_CLK_IN_HZ = (REDUCED_SIM_TIME == 1)
+ ? 2 * 1000000 : SYNTH_CLK_IN_HZ;
+`ifdef ALTERA_RESERVED_QIS
+ localparam SYS_CLK_IN_HZ = SYNTH_CLK_IN_HZ;
+`else
+ localparam SYS_CLK_IN_HZ = SIM_CLK_IN_HZ;
+`endif
+
+// Calculate delays
+wire reset_sync; // Synchronized reset input
+wire stat_pll_powerdown; // PLL powerdown status
+
+genvar ig;
+
+//**************************************************************************
+//************************ Synchronize Reset Input *************************
+generate if(SYNCHRONIZE_RESET == 1) begin: g_reset_sync
+ // Synchronize reset input
+ alt_xcvr_resync #(
+ .SYNC_CHAIN_LENGTH(2), // Number of flip-flops for retiming
+ .WIDTH (1), // Number of bits to resync
+ .INIT_VALUE (1'b1)
+ ) alt_xcvr_resync_reset (
+ .clk (clock ),
+ .reset (reset ),
+ .d (1'b0 ),
+ .q (reset_sync )
+ );
+end else begin: g_no_reset_sync
+ assign reset_sync = reset;
+end
+endgenerate
+//************************ Synchronize Reset Input *************************
+//**************************************************************************
+
+
+//***************************************************************************
+//*************************** TX PLL Reset Logic ****************************
+generate if(TX_PLL_ENABLE) begin: g_pll
+ wire lcl_pll_powerdown;
+ wire reset_pll;
+ assign pll_powerdown = {PLLS{lcl_pll_powerdown}};
+ if(SYNCHRONIZE_PLL_RESET == 1) begin : g_sync_pll_reset
+ assign reset_pll = reset_sync;
+ end else begin : g_no_sync_pll_reset
+ assign reset_pll = reset;
+ end
+ // pll_powerdown
+ alt_xcvr_reset_counter #(
+ .CLKS_PER_SEC (SYS_CLK_IN_HZ ), // Clock frequency in Hz
+ .RESET_PER_NS (T_PLL_POWERDOWN ), // Reset period in ns
+ .ACTIVE_LEVEL (0 )
+ ) counter_pll_powerdown (
+ .clk (clock ),
+ .async_req (reset_pll ), // asynchronous reset request
+ .sync_req (1'b0 ), // synchronous reset request
+ .reset_or (1'b0 ),
+ .reset (lcl_pll_powerdown ), // synchronous reset out
+ .reset_n (/*unused*/ ),
+ .reset_stat (stat_pll_powerdown )
+ );
+end else begin : g_no_pll
+ assign pll_powerdown = {PLLS{1'b0}};
+ assign stat_pll_powerdown = 1'b0;
+end
+endgenerate
+//************************* End TX PLL Reset Logic **************************
+//***************************************************************************
+
+
+//***************************************************************************
+//***************************** TX Reset Logic ******************************
+generate if(TX_ENABLE) begin: g_tx
+ localparam PLL_SEL_WIDTH = altera_xcvr_functions::clogb2(PLLS-1);
+
+ for (ig=0;ig 1) ? pll_select
+ : 1'b0;
+
+ assign tx_or_pll_cal_busy_sync = tx_cal_busy_sync | pll_cal_busy_sync;
+
+ // Synchonize TX inputs
+ alt_xcvr_resync #(
+ .SYNC_CHAIN_LENGTH(2), // Number of flip-flops for retiming
+ .WIDTH (4),
+ .INIT_VALUE (0)
+ ) resync_tx_cal_busy (
+ .clk (clock ),
+ .reset (reset_sync ),
+ .d ({lcl_tx_cal_busy ,lcl_pll_cal_busy ,lcl_tx_manual ,lcl_pll_locked }),
+ .q ({tx_cal_busy_sync,pll_cal_busy_sync,tx_manual_sync,pll_locked_sync})
+ );
+
+ // Add hysteresis to pll_locked if needed
+ // Reset counter works fine for hysteresis
+ if(T_PLL_LOCK_HYST != 0) begin : g_pll_locked_hyst
+ alt_xcvr_reset_counter #(
+ .CLKS_PER_SEC (SYS_CLK_IN_HZ ), // Clock frequency in Hz
+ .RESET_PER_NS (T_PLL_LOCK_HYST) // Reset period in ns
+ ) counter_pll_locked_hyst (
+ .clk (clock ),
+ .async_req (reset_sync ), // asynchronous reset request
+ .sync_req (~pll_locked_sync ), // synchronous reset request
+ .reset_or (1'b0 ),
+ .reset (/*unused*/ ), // synchronous reset out
+ .reset_n (pll_locked_hyst ),
+ .reset_stat (/*unused*/ )
+ );
+ end else begin : g_no_pll_locked_hyst
+ // No hysteresis added; use synchronized pll_locked directly.
+ assign pll_locked_hyst = pll_locked_sync;
+ end
+
+ // Add one-shot latch to pll_locked for initial reset sequence
+ always @(posedge clock or posedge reset_sync)
+ if(reset_sync) pll_locked_latch <= 1'b0;
+ else if(pll_locked_hyst & ~tx_cal_busy_sync)
+ pll_locked_latch <= 1'b1;
+
+ // tx_analogreset
+ if(T_TX_ANALOGRESET == 0) begin
+ // Tie tx_analogreset to pll_powerdown if used, otherwise tie to reset input (which may be synchronized)
+ assign tx_analogreset[ig] = TX_PLL_ENABLE ? pll_powerdown[0] : reset_sync;
+ assign stat_tx_analogreset = stat_pll_powerdown;
+ end else begin
+ // Assert rx_analogreset during RX calibration and for "T_RX_ANALOGRESET" ns thereafter
+ alt_xcvr_reset_counter #(
+ .CLKS_PER_SEC (SYS_CLK_IN_HZ ), // Clock frequency in Hz
+ .RESET_PER_NS (T_TX_ANALOGRESET ) // Reset period in ns
+ ) counter_tx_analogreset (
+ .clk (clock ),
+ .async_req (reset_sync ), // asynchronous reset request
+ .sync_req (tx_or_pll_cal_busy_sync), // synchronous reset request
+ .reset_or (1'b0 ), // auxilliary reset override
+ .reset (tx_analogreset [ig] ), // synchronous reset out
+ .reset_n (/*unused*/ ),
+ .reset_stat (stat_tx_analogreset )
+ );
+ end
+
+ // tx_digitalreset
+ // Assert tx_digitalreset while any of the following
+ // 1 - pll_powerdown is asserted.
+ // 2 - TX calibration is in progress
+ // 3 - PLL has not reached initial lock (pll_locked_latch)
+ // 4 - PLL is not locked AND TX reset is NOT under manual control
+ // 5 - Reset override
+ alt_xcvr_reset_counter #(
+ .CLKS_PER_SEC (SYS_CLK_IN_HZ ), // Clock frequency in Hz
+ .RESET_PER_NS (T_TX_DIGITALRESET ) // Reset period in ns
+ ) counter_tx_digitalreset (
+ .clk (clock ),
+ .async_req (reset_sync ), // asynchronous reset request
+ .sync_req (stat_tx_analogreset | tx_cal_busy_sync | ~pll_locked_latch | (~pll_locked_hyst&~tx_manual_sync)), // synchronous reset request
+ .reset_or (lcl_tx_digitalreset_or ), // auxilliary reset override
+ .reset (tx_digitalreset[ig] ), // synchronous reset out
+ .reset_n (/*unused*/ ),
+ .reset_stat (stat_tx_digitalreset )
+ );
+
+ // tx_ready
+ alt_xcvr_reset_counter #(
+ .RESET_COUNT(3)
+ ) counter_tx_ready (
+ .clk (clock ),
+ .async_req (reset_sync ), // asynchronous reset request
+ .sync_req (stat_tx_digitalreset ), // synchronous reset request
+ .reset_or (1'b0 ), // auxilliary reset override
+ .reset (/*unused*/ ), // synchronous reset out
+ .reset_n (tx_ready [ig] ),
+ .reset_stat (/*unused*/ ) // reset status
+ );
+ end else begin : g_fanout_tx
+ assign tx_analogreset [ig] = tx_analogreset [0];
+ assign tx_digitalreset [ig] = tx_digitalreset [0];
+ assign tx_ready [ig] = tx_ready [0];
+ end
+ end
+end else begin : g_no_tx
+ assign tx_analogreset = {CHANNELS{1'b0}};
+ assign tx_digitalreset = {CHANNELS{1'b0}};
+ assign tx_ready = {CHANNELS{1'b0}};
+end
+endgenerate
+//*************************** End TX Reset Logic ****************************
+//***************************************************************************
+
+
+//***************************************************************************
+//***************************** RX Reset Logic ******************************
+generate if (RX_ENABLE) begin : g_rx
+ for (ig=0;ig non-bonded 4=> bonded
+ .bonded_mode ("xN"), /// allowed values "xN" and "fb_compensation"
+ .enable_rx_coreclkin (enable_rx_coreclkin)
+ ) alt_xaui_phy (
+ .pll_ref_clk (pll_ref_clk), // refclk.clk
+ .cdr_ref_clk (cdr_ref_clk), // used only in SyncE mode
+ .xgmii_tx_clk (xgmii_tx_clk), // xgmii_tx_clk.clk
+ .xgmii_rx_clk (xgmii_rx_clk), // xgmii_rx_clk.clk
+ .phy_mgmt_clk (phy_mgmt_clk), // mgmt_clk.clk
+ .phy_mgmt_clk_reset (phy_mgmt_clk_reset), // mgmt_clk_rst.reset_n
+ .phy_mgmt_address (sc_phy_address), // phy_mgmt.address
+ .phy_mgmt_waitrequest (sc_phy_waitrequest), // .waitrequest
+ .phy_mgmt_read (sc_phy_read), // .read
+ .phy_mgmt_readdata (sc_phy_readdata), // .readdata
+ .phy_mgmt_write (sc_phy_write), // .write
+ .phy_mgmt_writedata (phy_mgmt_writedata), // .writedata
+ .xgmii_tx_dc (xgmii_tx_dc), // xgmii_tx_dc.data
+ .xgmii_rx_dc (xgmii_rx_dc), // xgmii_rx_dc.data
+ .xaui_tx_serial_data (xaui_tx_serial_data), // xaui_tx_serial.export
+ .xaui_rx_serial_data (xaui_rx_serial_data), // xaui_rx_serial.export
+ .rx_digitalreset (rx_digitalreset), // rx_digitalreset.data
+ .tx_digitalreset (tx_digitalreset), // tx_digitalreset.data
+ .rx_channelaligned (rx_channelaligned), // rx_channelaligned.data
+ .rx_syncstatus (rx_syncstatus), // rx_syncstatus.data
+ .rx_disperr (rx_disperr), // rx_disperr.data
+ .rx_errdetect (rx_errdetect), // rx_errdetect.data
+ .rx_ready (rx_ready), // rx_pma_ready.data
+ .tx_ready (tx_ready), // tx_pma_ready.data
+ .reconfig_to_xcvr (l_reconfig_to_xcvr),
+ .reconfig_from_xcvr (l_reconfig_from_xcvr),
+ .rx_recovered_clk (rx_recovered_clk),
+ .rx_coreclkin (rx_coreclkin)
+ );
+ assign tx_clk312_5 = 1'b0 ;
+ end else if (device_family == "Arria V") begin
+ av_xcvr_xaui #(
+ .device_family (device_family),
+ .starting_channel_number (starting_channel_number),
+ .interface_type (interface_type),
+ .reconfig_interfaces (reconfig_interfaces),
+ .mgmt_clk_in_mhz (mgmt_clk_in_mhz),
+ .data_rate (data_rate),
+ .xaui_pll_type (xaui_pll_type),
+ //.base_data_rate ("3125 Mbps"),
+ .en_synce_support (en_synce_support), //expose CDR ref-clk in this mode
+ .use_control_and_status_ports (use_control_and_status_ports),
+ .tx_termination (tx_termination),
+ .rx_termination (rx_termination),
+ .tx_preemp_pretap (tx_preemp_pretap),
+ .tx_preemp_pretap_inv (tx_preemp_pretap_inv),
+ .tx_preemp_tap_1 (tx_preemp_tap_1),
+ .tx_preemp_tap_2 (tx_preemp_tap_2),
+ .tx_preemp_tap_2_inv (tx_preemp_tap_2_inv),
+ .tx_vod_selection (tx_vod_selection),
+ .rx_eq_dc_gain (rx_eq_dc_gain),
+ .rx_eq_ctrl (rx_eq_ctrl),
+ .rx_common_mode (rx_common_mode),
+ .bonded_group_size (4), /// allowed values 1=> non-bonded 4=> bonded
+ .bonded_mode ("xN"), /// allowed values "xN" and "fb_compensation"
+ .pll_external_enable (pll_external_enable)
+ ) alt_xaui_phy (
+ .pll_ref_clk (pll_ref_clk), // refclk.clk
+ .cdr_ref_clk (cdr_ref_clk), // used only in SyncE mode
+ .xgmii_tx_clk (xgmii_tx_clk), // xgmii_tx_clk.clk
+ .xgmii_rx_clk (xgmii_rx_clk), // xgmii_rx_clk.clk
+ .phy_mgmt_clk (phy_mgmt_clk), // mgmt_clk.clk
+ .phy_mgmt_clk_reset (phy_mgmt_clk_reset), // mgmt_clk_rst.reset_n
+ .phy_mgmt_address (sc_phy_address), // phy_mgmt.address
+ .phy_mgmt_waitrequest (sc_phy_waitrequest), // .waitrequest
+ .phy_mgmt_read (sc_phy_read), // .read
+ .phy_mgmt_readdata (sc_phy_readdata), // .readdata
+ .phy_mgmt_write (sc_phy_write), // .write
+ .phy_mgmt_writedata (phy_mgmt_writedata), // .writedata
+ .xgmii_tx_dc (xgmii_tx_dc), // xgmii_tx_dc.data
+ .xgmii_rx_dc (xgmii_rx_dc), // xgmii_rx_dc.data
+ .xaui_tx_serial_data (xaui_tx_serial_data), // xaui_tx_serial.export
+ .xaui_rx_serial_data (xaui_rx_serial_data), // xaui_rx_serial.export
+ .rx_digitalreset (rx_digitalreset), // rx_digitalreset.data
+ .tx_digitalreset (tx_digitalreset), // tx_digitalreset.data
+ .rx_channelaligned (rx_channelaligned), // rx_channelaligned.data
+ .rx_syncstatus (rx_syncstatus), // rx_syncstatus.data
+ .rx_disperr (rx_disperr), // rx_disperr.data
+ .rx_errdetect (rx_errdetect), // rx_errdetect.data
+ .rx_ready (rx_ready), // rx_pma_ready.data
+ .tx_ready (tx_ready), // tx_pma_ready.data
+ .reconfig_to_xcvr (reconfig_to_xcvr),
+ .reconfig_from_xcvr (reconfig_from_xcvr),
+ .pll_locked_i (pll_locked_i),
+ .ext_pll_clk (ext_pll_clk),
+ .rx_recovered_clk (rx_recovered_clk)
+ );
+ assign tx_clk312_5 = 1'b0 ;
+ end else if (device_family == "Cyclone V") begin
+ cv_xcvr_xaui #(
+ .device_family (device_family),
+ .starting_channel_number (starting_channel_number),
+ .interface_type (interface_type),
+ .reconfig_interfaces (reconfig_interfaces),
+ .mgmt_clk_in_mhz (mgmt_clk_in_mhz),
+ .data_rate (data_rate),
+ .xaui_pll_type (xaui_pll_type),
+ //.base_data_rate ("3125 Mbps"),
+ .en_synce_support (en_synce_support), //expose CDR ref-clk in this mode
+ .use_control_and_status_ports (use_control_and_status_ports),
+ .tx_termination (tx_termination),
+ .rx_termination (rx_termination),
+ .tx_preemp_pretap (tx_preemp_pretap),
+ .tx_preemp_pretap_inv (tx_preemp_pretap_inv),
+ .tx_preemp_tap_1 (tx_preemp_tap_1),
+ .tx_preemp_tap_2 (tx_preemp_tap_2),
+ .tx_preemp_tap_2_inv (tx_preemp_tap_2_inv),
+ .tx_vod_selection (tx_vod_selection),
+ .rx_eq_dc_gain (rx_eq_dc_gain),
+ .rx_eq_ctrl (rx_eq_ctrl),
+ .rx_common_mode (rx_common_mode),
+ .bonded_group_size (4), /// allowed values 1=> non-bonded 4=> bonded
+ .bonded_mode ("xN") /// allowed values "xN" and "fb_compensation"
+ ) alt_xaui_phy (
+ .pll_ref_clk (pll_ref_clk), // refclk.clk
+ .cdr_ref_clk (cdr_ref_clk), // used only in SyncE mode
+ .xgmii_tx_clk (xgmii_tx_clk), // xgmii_tx_clk.clk
+ .xgmii_rx_clk (xgmii_rx_clk), // xgmii_rx_clk.clk
+ .phy_mgmt_clk (phy_mgmt_clk), // mgmt_clk.clk
+ .phy_mgmt_clk_reset (phy_mgmt_clk_reset), // mgmt_clk_rst.reset_n
+ .phy_mgmt_address (sc_phy_address), // phy_mgmt.address
+ .phy_mgmt_waitrequest (sc_phy_waitrequest), // .waitrequest
+ .phy_mgmt_read (sc_phy_read), // .read
+ .phy_mgmt_readdata (sc_phy_readdata), // .readdata
+ .phy_mgmt_write (sc_phy_write), // .write
+ .phy_mgmt_writedata (phy_mgmt_writedata), // .writedata
+ .xgmii_tx_dc (xgmii_tx_dc), // xgmii_tx_dc.data
+ .xgmii_rx_dc (xgmii_rx_dc), // xgmii_rx_dc.data
+ .xaui_tx_serial_data (xaui_tx_serial_data), // xaui_tx_serial.export
+ .xaui_rx_serial_data (xaui_rx_serial_data), // xaui_rx_serial.export
+ .rx_digitalreset (rx_digitalreset), // rx_digitalreset.data
+ .tx_digitalreset (tx_digitalreset), // tx_digitalreset.data
+ .rx_channelaligned (rx_channelaligned), // rx_channelaligned.data
+ .rx_syncstatus (rx_syncstatus), // rx_syncstatus.data
+ .rx_disperr (rx_disperr), // rx_disperr.data
+ .rx_errdetect (rx_errdetect), // rx_errdetect.data
+ .rx_ready (rx_ready), // rx_pma_ready.data
+ .tx_ready (tx_ready), // tx_pma_ready.data
+ .reconfig_to_xcvr (reconfig_to_xcvr),
+ .reconfig_from_xcvr (reconfig_from_xcvr),
+ .rx_recovered_clk (rx_recovered_clk)
+ );
+ assign tx_clk312_5 = 1'b0 ;
+ end else if ((interface_type == "DDR XAUI") && (device_family == "Stratix IV")) begin
+ dxaui_siv #(
+ .device_family (device_family),
+ .starting_channel_number (starting_channel_number),
+ .interface_type (interface_type),
+ .number_of_interfaces (1),
+ .reconfig_interfaces (reconfig_interfaces),
+ .sys_clk_in_mhz (mgmt_clk_in_mhz),
+ .xaui_pll_type (xaui_pll_type),
+ .use_control_and_status_ports (use_control_and_status_ports),
+ .external_pma_ctrl_reconf (external_pma_ctrl_reconf),
+ .tx_termination (tx_termination),
+ .tx_vod_selection (tx_vod_selection),
+ .tx_preemp_pretap (tx_preemp_pretap),
+ .tx_preemp_pretap_inv (tx_preemp_pretap_inv),
+ .tx_preemp_tap_1 (tx_preemp_tap_1),
+ .tx_preemp_tap_2 (tx_preemp_tap_2),
+ .tx_preemp_tap_2_inv (tx_preemp_tap_2_inv),
+ .rx_common_mode (rx_common_mode),
+ .rx_termination (rx_termination),
+ .rx_eq_dc_gain (rx_eq_dc_gain),
+ .rx_eq_ctrl (rx_eq_ctrl),
+ .use_rx_rate_match (use_rx_rate_match)
+) dxaui_siv (
+ .pll_ref_clk (pll_ref_clk), // i
+ .xgmii_tx_clk (xgmii_tx_clk), // i
+ .xgmii_rx_clk (xgmii_rx_clk), // o
+ .tx_clk312_5 (tx_clk312_5), // o
+ .phy_mgmt_clk (phy_mgmt_clk), // i
+ .phy_mgmt_clk_reset (phy_mgmt_clk_reset), // i
+ .phy_mgmt_address (sc_phy_address), // i
+ .phy_mgmt_waitrequest (sc_phy_waitrequest), // o
+ .phy_mgmt_read (sc_phy_read), // i
+ .phy_mgmt_readdata (sc_phy_readdata), // o
+ .phy_mgmt_write (sc_phy_write), // i
+ .phy_mgmt_writedata (phy_mgmt_writedata), // i
+ .xgmii_tx_dc (xgmii_tx_dc), // i
+ .xgmii_rx_dc (xgmii_rx_dc), // o
+ .xaui_tx_serial_data (xaui_tx_serial_data), // o
+ .xaui_rx_serial_data (xaui_rx_serial_data), // i
+ .rx_ready (rx_ready), // o
+ .tx_ready (tx_ready), // o
+ .rx_recovered_clk (rx_recovered_clk), // o
+ .reconfig_from_xcvr (l_reconfig_from_xcvr), // o
+ .reconfig_to_xcvr (l_reconfig_to_xcvr), // i
+ .rx_analogreset (rx_analogreset), // i
+ .rx_digitalreset (rx_digitalreset), // i
+ .tx_digitalreset (tx_digitalreset), // i
+ .rx_channelaligned (rx_channelaligned), // o
+ .rx_invpolarity (rx_invpolarity), // i
+ .rx_set_locktodata (rx_set_locktodata), // i
+ .rx_set_locktoref (rx_set_locktoref), // i
+ .rx_seriallpbken (rx_seriallpbken), // i
+ .tx_invpolarity (tx_invpolarity), // i
+ .rx_is_lockedtodata (rx_is_lockedtodata), // o
+ .rx_phase_comp_fifo_error (rx_phase_comp_fifo_error), // o
+ .rx_is_lockedtoref (rx_is_lockedtoref), // o
+ .rx_rlv (rx_rlv), // o
+ .rx_rmfifoempty (rx_rmfifoempty), // o
+ .rx_rmfifofull (rx_rmfifofull), // o
+ .tx_phase_comp_fifo_error (tx_phase_comp_fifo_error), // o
+ .rx_disperr (rx_disperr), // o
+ .rx_errdetect (rx_errdetect), // o
+ .rx_patterndetect (rx_patterndetect), // o
+ .rx_rmfifodatadeleted (rx_rmfifodatadeleted), // o
+ .rx_rmfifodatainserted (rx_rmfifodatainserted), // o
+ .rx_runningdisp (rx_runningdisp), // o
+ .rx_syncstatus (rx_syncstatus), // o
+ .pll_locked (pll_locked), // o
+ .cal_blk_powerdown (cal_blk_powerdown), // i
+ .gxb_powerdown (gxb_powerdown), // i
+ .pll_powerdown (pll_powerdown) // i
+); // module dxaui_siv
+ end else if ((device_family == "Stratix IV") || (device_family == "HardCopy IV") ||(device_family == "Arria II GX") || (device_family == "Arria II GZ")) begin
+ siv_xcvr_xaui #(
+ .device_family (device_family),
+ .starting_channel_number (starting_channel_number),
+ .interface_type (interface_type),
+ .number_of_interfaces (1),
+ .reconfig_interfaces (reconfig_interfaces),
+ .sys_clk_in_mhz (mgmt_clk_in_mhz),
+ .xaui_pll_type (xaui_pll_type),
+ .use_control_and_status_ports (use_control_and_status_ports),
+ .external_pma_ctrl_reconf (external_pma_ctrl_reconf),
+ .tx_termination (tx_termination),
+ .rx_termination (rx_termination),
+ .tx_preemp_pretap (tx_preemp_pretap),
+ .tx_preemp_pretap_inv (tx_preemp_pretap_inv),
+ .tx_preemp_tap_1 (tx_preemp_tap_1),
+ .tx_preemp_tap_2 (tx_preemp_tap_2),
+ .tx_preemp_tap_2_inv (tx_preemp_tap_2_inv),
+ .tx_vod_selection (tx_vod_selection),
+ .rx_eq_dc_gain (rx_eq_dc_gain),
+ .rx_eq_ctrl (rx_eq_ctrl),
+ .rx_common_mode (rx_common_mode)
+ ) xaui_phy (
+ .pll_ref_clk (pll_ref_clk),
+ .xgmii_rx_clk (xgmii_rx_clk),
+ .xgmii_tx_clk (xgmii_tx_clk),
+ .phy_mgmt_clk (phy_mgmt_clk),
+ .phy_mgmt_clk_reset (phy_mgmt_clk_reset),
+ .phy_mgmt_address (sc_phy_address),
+ .phy_mgmt_read (sc_phy_read),
+ .phy_mgmt_readdata (sc_phy_readdata),
+ .phy_mgmt_waitrequest (sc_phy_waitrequest),
+ .phy_mgmt_write (sc_phy_write),
+ .phy_mgmt_writedata (phy_mgmt_writedata),
+ .xaui_rx_serial_data (xaui_rx_serial_data),
+ .xaui_tx_serial_data (xaui_tx_serial_data),
+ .xgmii_rx_dc (xgmii_rx_dc),
+ .xgmii_tx_dc (xgmii_tx_dc),
+ .rx_ready (rx_ready),
+ .tx_ready (tx_ready),
+ .rx_recovered_clk (rx_recovered_clk), //o
+ .reconfig_from_xcvr (l_reconfig_from_xcvr),
+ .reconfig_to_xcvr (l_reconfig_to_xcvr),
+
+// optional control and status ports - will be terminated by tri0 if unconnected
+ .rx_analogreset (rx_analogreset), // input wire
+ .rx_digitalreset (rx_digitalreset), // input wire [3:0]
+ .tx_digitalreset (tx_digitalreset), // input wire [3:0]
+ .rx_channelaligned (rx_channelaligned), // output wire
+ .rx_invpolarity (rx_invpolarity), // input wire [3:0]
+ .rx_set_locktodata (rx_set_locktodata), // input wire [3:0]
+ .rx_set_locktoref (rx_set_locktoref), // input wire [3:0]
+ .rx_seriallpbken (rx_seriallpbken), // input wire [3:0]
+ .tx_invpolarity (tx_invpolarity), // input wire [3:0]
+ .rx_is_lockedtodata (rx_is_lockedtodata), // output wire [3:0]
+ .rx_phase_comp_fifo_error (rx_phase_comp_fifo_error), // output wire [3:0]
+ .rx_is_lockedtoref (rx_is_lockedtoref), // output wire [3:0]
+ .rx_rlv (rx_rlv), // output wire [3:0]
+ .rx_rmfifoempty (rx_rmfifoempty), // output wire [3:0]
+ .rx_rmfifofull (rx_rmfifofull), // output wire [3:0]
+ .tx_phase_comp_fifo_error (tx_phase_comp_fifo_error), // output wire [3:0]
+ .rx_disperr (rx_disperr), // output wire [7:0]
+ .rx_errdetect (rx_errdetect), // output wire [7:0]
+ .rx_patterndetect (rx_patterndetect), // output wire [7:0]
+ .rx_rmfifodatadeleted (rx_rmfifodatadeleted), // output wire [7:0]
+ .rx_rmfifodatainserted (rx_rmfifodatainserted), // output wire [7:0]
+ .rx_runningdisp (rx_runningdisp), // output wire [7:0]
+ .rx_syncstatus (rx_syncstatus), // output wire [7:0]
+
+// external_pma_ctrl_reconf
+ .pll_locked (pll_locked), // output wire
+ .cal_blk_powerdown (cal_blk_powerdown), // input wire
+ .gxb_powerdown (gxb_powerdown), // input wire
+ .pll_powerdown (pll_powerdown) // input wire
+ );
+ assign tx_clk312_5 = 1'b0 ;
+ end else if (device_family == "Cyclone IV GX") begin
+// need to add the extra optional ports for c&s and ext_pma
+ civ_xcvr_xaui #(
+ .device_family (device_family),
+ .starting_channel_number (starting_channel_number),
+ .interface_type (interface_type),
+ .number_of_interfaces (1),
+ .sys_clk_in_mhz (mgmt_clk_in_mhz),
+ .xaui_pll_type (xaui_pll_type),
+ .use_control_and_status_ports (use_control_and_status_ports),
+ .external_pma_ctrl_reconf (external_pma_ctrl_reconf),
+ .tx_termination (tx_termination),
+ .rx_termination (rx_termination),
+ .tx_preemp_pretap (tx_preemp_pretap),
+ .tx_preemp_pretap_inv (tx_preemp_pretap_inv),
+ .tx_preemp_tap_1 (tx_preemp_tap_1),
+ .tx_preemp_tap_2 (tx_preemp_tap_2),
+ .tx_preemp_tap_2_inv (tx_preemp_tap_2_inv),
+ .tx_vod_selection (tx_vod_selection),
+ .rx_eq_dc_gain (rx_eq_dc_gain),
+ .rx_eq_ctrl (rx_eq_ctrl),
+ .rx_common_mode (rx_common_mode)
+ ) xaui_phy (
+ .pll_ref_clk (pll_ref_clk),
+ .xgmii_rx_clk (xgmii_rx_clk),
+ .xgmii_tx_clk (xgmii_tx_clk),
+ .phy_mgmt_clk (phy_mgmt_clk),
+ .phy_mgmt_clk_reset (phy_mgmt_clk_reset),
+ .phy_mgmt_address (sc_phy_address),
+ .phy_mgmt_read (sc_phy_read),
+ .phy_mgmt_readdata (sc_phy_readdata),
+ .phy_mgmt_waitrequest (sc_phy_waitrequest),
+ .phy_mgmt_write (sc_phy_write),
+ .phy_mgmt_writedata (phy_mgmt_writedata),
+ .xaui_rx_serial_data (xaui_rx_serial_data),
+ .xaui_tx_serial_data (xaui_tx_serial_data),
+ .xgmii_rx_dc (xgmii_rx_dc),
+ .xgmii_tx_dc (xgmii_tx_dc),
+ .rx_ready (rx_ready),
+ .tx_ready (tx_ready),
+ .rx_recovered_clk (rx_recovered_clk), //o
+ .reconfig_from_xcvr (l_reconfig_from_xcvr[16:0]),
+ .reconfig_to_xcvr (l_reconfig_to_xcvr),
+
+// optional control and status ports - will be terminated by tri0 if unconnected
+ .rx_analogreset (rx_analogreset), // input wire
+ .rx_digitalreset (rx_digitalreset), // input wire [3:0]
+ .tx_digitalreset (tx_digitalreset), // input wire [3:0]
+ .rx_channelaligned (rx_channelaligned), // output wire
+ .rx_invpolarity (rx_invpolarity), // input wire [3:0]
+ .rx_set_locktodata (rx_set_locktodata), // input wire [3:0]
+ .rx_set_locktoref (rx_set_locktoref), // input wire [3:0]
+ .rx_seriallpbken (rx_seriallpbken), // input wire [3:0]
+ .tx_invpolarity (tx_invpolarity), // input wire [3:0]
+ .rx_is_lockedtodata (rx_is_lockedtodata), // output wire [3:0]
+ .rx_phase_comp_fifo_error (rx_phase_comp_fifo_error), // output wire [3:0]
+ .rx_is_lockedtoref (rx_is_lockedtoref), // output wire [3:0]
+ .rx_rlv (rx_rlv), // output wire [3:0]
+ .rx_rmfifoempty (rx_rmfifoempty), // output wire [3:0]
+ .rx_rmfifofull (rx_rmfifofull), // output wire [3:0]
+ .tx_phase_comp_fifo_error (tx_phase_comp_fifo_error), // output wire [3:0]
+ .rx_disperr (rx_disperr), // output wire [7:0]
+ .rx_errdetect (rx_errdetect), // output wire [7:0]
+ .rx_patterndetect (rx_patterndetect), // output wire [7:0]
+ .rx_rmfifodatadeleted (rx_rmfifodatadeleted), // output wire [7:0]
+ .rx_rmfifodatainserted (rx_rmfifodatainserted), // output wire [7:0]
+ .rx_runningdisp (rx_runningdisp), // output wire [7:0]
+ .rx_syncstatus (rx_syncstatus), // output wire [7:0]
+
+// external_pma_ctrl_reconf
+ .pll_locked (pll_locked), // output wire
+ .cal_blk_powerdown (cal_blk_powerdown), // input wire
+ .gxb_powerdown (gxb_powerdown), // input wire
+ .pll_powerdown (pll_powerdown) // input wire
+ );
+ assign tx_clk312_5 = 1'b0 ;
+ end
+ else if (device_family == "Arria 10") begin
+ a10_xcvr_xaui #(
+ .device_family (device_family),
+ .interface_type (interface_type),
+ .mgmt_clk_in_mhz (mgmt_clk_in_mhz),
+ .data_rate (data_rate),
+ .en_synce_support (en_synce_support), //expose CDR ref-clk in this mode
+ .use_control_and_status_ports (use_control_and_status_ports),
+ .tx_termination (tx_termination),
+ .rx_termination (rx_termination),
+ .tx_preemp_pretap (tx_preemp_pretap),
+ .tx_preemp_pretap_inv (tx_preemp_pretap_inv),
+ .tx_preemp_tap_1 (tx_preemp_tap_1),
+ .tx_preemp_tap_2 (tx_preemp_tap_2),
+ .tx_preemp_tap_2_inv (tx_preemp_tap_2_inv),
+ .tx_vod_selection (tx_vod_selection),
+ .rx_eq_dc_gain (rx_eq_dc_gain),
+ .rx_eq_ctrl (rx_eq_ctrl),
+ .rx_common_mode (rx_common_mode),
+ .bonded_group_size (4), /// allowed values 1=> non-bonded 4=> bonded
+ .bonded_mode ("xN"), /// allowed values "xN" and "fb_compensation"
+ .en_dual_fifo (en_dual_fifo),
+ .disable_embedded_sdc (disable_embedded_sdc)
+ ) alt_xaui_phy (
+ .pll_ref_clk (pll_ref_clk), // refclk.clk
+ .cdr_ref_clk (cdr_ref_clk), // used only in SyncE mode
+ .xgmii_tx_clk (xgmii_tx_clk), // xgmii_tx_clk.clk
+ .xgmii_rx_clk (xgmii_rx_clk), // xgmii_rx_clk.clk
+ .xgmii_rx_inclk (xgmii_rx_inclk),
+ .phy_mgmt_clk (phy_mgmt_clk), // mgmt_clk.clk
+ .phy_mgmt_clk_reset (phy_mgmt_clk_reset), // mgmt_clk_rst.reset_n
+ .phy_mgmt_address (sc_phy_address), // phy_mgmt.address
+ .phy_mgmt_waitrequest (sc_phy_waitrequest), // .waitrequest
+ .phy_mgmt_read (sc_phy_read), // .read
+ .phy_mgmt_readdata (sc_phy_readdata), // .readdata
+ .phy_mgmt_write (sc_phy_write), // .write
+ .phy_mgmt_writedata (phy_mgmt_writedata), // .writedata
+ .xgmii_tx_dc (xgmii_tx_dc), // xgmii_tx_dc.data
+ .xgmii_rx_dc (xgmii_rx_dc), // xgmii_rx_dc.data
+ .xaui_tx_serial_data (xaui_tx_serial_data), // xaui_tx_serial.export
+ .xaui_rx_serial_data (xaui_rx_serial_data), // xaui_rx_serial.export
+ .rx_digitalreset (rx_digitalreset), // rx_digitalreset.data
+ .tx_digitalreset (tx_digitalreset), // tx_digitalreset.data
+ .rx_channelaligned (rx_channelaligned), // rx_channelaligned.data
+ .rx_syncstatus (rx_syncstatus), // rx_syncstatus.data
+ .rx_disperr (rx_disperr), // rx_disperr.data
+ .rx_errdetect (rx_errdetect), // rx_errdetect.data
+ .rx_ready (rx_ready), // rx_pma_ready.data
+ .tx_ready (tx_ready), // tx_pma_ready.data
+ .rx_recovered_clk (rx_recovered_clk),
+ .tx_bonding_clocks (tx_bonding_clocks),
+ .pll_powerdown (pll_powerdown_o),
+ .pll_locked (pll_locked_i),
+ .pll_cal_busy (pll_cal_busy_i),
+ .reconfig_clk (reconfig_clk), // reconfig_clk.clk
+ .reconfig_reset (reconfig_reset), // reconfig_reset.reset
+ .reconfig_write (reconfig_write), // reconfig_avmm.write
+ .reconfig_read (reconfig_read), // .read
+ .reconfig_address (reconfig_address), // .address
+ .reconfig_writedata (reconfig_writedata), // .writedata
+ .reconfig_readdata (reconfig_readdata),
+ .reconfig_waitrequest (reconfig_waitrequest)
+ );
+ assign tx_clk312_5 = 1'b0 ;
+ end
+ endgenerate
+
+endmodule
diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_8g_rx_pcs_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_8g_rx_pcs_rbc.sv
new file mode 100644
index 0000000..f901242
--- /dev/null
+++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_8g_rx_pcs_rbc.sv
@@ -0,0 +1,1550 @@
+// (C) 2001-2018 Intel Corporation. All rights reserved.
+// Your use of Intel Corporation's design tools, logic functions and other
+// software and tools, and its AMPP partner logic functions, and any output
+// files from any of the foregoing (including device programming or simulation
+// files), and any associated documentation or information are expressly subject
+// to the terms and conditions of the Intel Program License Subscription
+// Agreement, Intel FPGA IP License Agreement, or other applicable
+// license agreement, including, without limitation, that your use is for the
+// sole purpose of programming logic devices manufactured by Intel and sold by
+// Intel or its authorized distributors. Please refer to the applicable
+// agreement for further details.
+
+
+// Verilog RBC parameter resolution wrapper for arriav_hssi_8g_rx_pcs
+//
+
+`timescale 1 ns / 1 ps
+
+module av_hssi_8g_rx_pcs_rbc #(
+ // unconstrained parameters
+ parameter prot_mode = "", // basic, cpri, cpri_rx_tx, disabled_prot_mode, gige, pipe_g1, pipe_g2, srio_2p1, test, xaui
+ parameter sup_mode = "", // engineering_mode, user_mode
+
+ // extra unconstrained parameters found in atom map
+ parameter avmm_group_channel_index = 0, // 0..2
+ parameter bo_pad = 10'b0, // 10
+ parameter bo_pattern = 20'b0, // 20
+ parameter channel_number = 0, // 0..65
+ parameter cid_pattern_len = 8'b0, // 8
+ parameter clkcmp_pattern_n = 20'b0, // 20
+ parameter clkcmp_pattern_p = 20'b0, // 20
+ parameter deskew_pattern = 10'b1101101000, // 10
+ parameter fixed_pat_num = 4'b1111, // 4
+ parameter mask_cnt = 10'h3ff, // 10
+ parameter pma_done_count = 18'b0, // 18
+ parameter runlength_val = 6'b0, // 6
+ parameter use_default_base_address = "true", // false, true
+ parameter user_base_address = 0, // 0..2047
+ parameter wa_clk_slip_spacing_data = 10'b10000, // 10
+ parameter wa_pd_data = 40'b0, // 40
+ parameter wa_renumber_data = 6'b0, // 6
+ parameter wa_rgnumber_data = 8'b0, // 8
+ parameter wa_rknumber_data = 8'b0, // 8
+ parameter wa_rosnumber_data = 2'b0, // 2
+ parameter wa_rvnumber_data = 13'b0, // 13
+ parameter wait_cnt = 8'b0, // 8
+
+ // constrained parameters
+ parameter test_mode = "", // bist, dont_care_test, prbs
+ parameter hip_mode = "", // dis_hip, en_hip
+ parameter pcs_bypass = "", // dis_pcs_bypass, en_pcs_bypass
+ parameter pma_dw = "", // eight_bit, sixteen_bit, ten_bit, twenty_bit
+ parameter pipe_if_enable = "", // dis_pipe_rx, en_pipe_rx
+ parameter prbs_ver = "", // dis_prbs, prbs_10, prbs_15, prbs_23_dw, prbs_23_sw, prbs_31, prbs_7_dw, prbs_7_sw, prbs_8, prbs_hf_dw, prbs_hf_sw, prbs_lf_dw, prbs_lf_sw, prbs_mf_dw, prbs_mf_sw
+ parameter wa_boundary_lock_ctrl = "", // auto_align_pld_ctrl, bit_slip, deterministic_latency, sync_sm
+ parameter wa_pld_controlled = "", // dis_pld_ctrl, level_sensitive_dw, pld_ctrl_sw, rising_edge_sensitive_dw
+ parameter wa_pd_polarity = "", // dis_pd_both_pol, dont_care_both_pol, en_pd_both_pol
+ parameter wa_pd = "", // dont_care_wa_pd_0, dont_care_wa_pd_1, prbs10_fixed_wa, prbs15_fixed_wa_pd_16_dw, prbs15_fixed_wa_pd_16_sw, prbs15_fixed_wa_pd_20_dw, prbs23_fixed_wa_pd_16_sw, prbs23_fixed_wa_pd_32_dw, prbs23_fixed_wa_pd_40_dw, prbs31_fixed_wa_pd_10_sw, prbs31_fixed_wa_pd_16_dw, prbs31_fixed_wa_pd_16_sw, prbs31_fixed_wa_pd_40_dw, prbs7_fixed_wa_pd_16_dw, prbs7_fixed_wa_pd_16_sw, prbs7_fixed_wa_pd_20_dw, prbs8_fixed_wa, wa_pd_10, wa_pd_16_dw, wa_pd_16_sw, wa_pd_20, wa_pd_32, wa_pd_40, wa_pd_7, wa_pd_8_dw, wa_pd_8_sw, wa_pd_fixed_10_k28p5, wa_pd_fixed_16_a1a2_dw, wa_pd_fixed_16_a1a2_sw, wa_pd_fixed_32_a1a1a2a2, wa_pd_fixed_7_k28p5
+ parameter wa_sync_sm_ctrl = "", // dw_basic_sync_sm, fibre_channel_sync_sm, gige_sync_sm, pipe_sync_sm, srio1p3_sync_sm, srio2p1_sync_sm, sw_basic_sync_sm, xaui_sync_sm
+ parameter wa_kchar = "", // dis_kchar, en_kchar
+ parameter fixed_pat_det = "", // dis_fixed_patdet, en_fixed_patdet
+ parameter ibm_invalid_code = "", // dis_ibm_invalid_code, en_ibm_invalid_code
+ parameter force_signal_detect = "", // dis_force_signal_detect, en_force_signal_detect
+ parameter wa_det_latency_sync_status_beh = "", // assert_sync_status_imm, assert_sync_status_non_imm, dont_care_assert_sync
+ parameter wa_clk_slip_spacing = "", // min_clk_slip_spacing, user_programmable_clk_slip_spacing
+ parameter eightb_tenb_decoder = "", // dis_8b10b, en_8b10b_ibm, en_8b10b_sgx
+ parameter wa_disp_err_flag = "", // dis_disp_err_flag, en_disp_err_flag
+ parameter polarity_inversion = "", // dis_pol_inv, en_pol_inv
+ parameter bit_reversal = "", // dis_bit_reversal, en_bit_reversal
+ parameter symbol_swap = "", // dis_symbol_swap, en_symbol_swap
+ parameter runlength_check = "", // dis_runlength, en_runlength_dw, en_runlength_sw
+ parameter ctrl_plane_bonding_consumption = "", // bundled_master, bundled_slave_above, bundled_slave_below, individual
+ parameter deskew = "", // dis_deskew, en_srio_v2p1, en_xaui
+ parameter deskew_prog_pattern_only = "", // dis_deskew_prog_pat_only, en_deskew_prog_pat_only
+ parameter rate_match = "", // dis_rm, dw_basic_rm, gige_rm, pipe_rm, pipe_rm_0ppm, srio_v2p1_rm, srio_v2p1_rm_0ppm, sw_basic_rm, xaui_rm
+ parameter err_flags_sel = "", // err_flags_8b10b, err_flags_wa
+ parameter polinv_8b10b_dec = "", // dis_polinv_8b10b_dec, en_polinv_8b10b_dec
+ parameter eightbtenb_decoder_output_sel = "", // data_8b10b_decoder, data_xaui_sm
+ parameter invalid_code_flag_only = "", // dis_invalid_code_only, en_invalid_code_only
+ parameter auto_error_replacement = "", // dis_err_replace, en_err_replace
+ parameter pad_or_edb_error_replace = "", // replace_edb, replace_edb_dynamic, replace_pad
+ parameter byte_deserializer = "", // dis_bds, en_bds_by_2, en_bds_by_2_det
+ parameter byte_order = "", // dis_bo, en_pcs_ctrl_eight_bit_bo, en_pcs_ctrl_nine_bit_bo, en_pcs_ctrl_ten_bit_bo, en_pld_ctrl_eight_bit_bo, en_pld_ctrl_nine_bit_bo, en_pld_ctrl_ten_bit_bo
+ parameter dw_one_or_two_symbol_bo = "", // donot_care_one_two_bo, one_symbol_bo, two_symbol_bo_eight_bit, two_symbol_bo_nine_bit, two_symbol_bo_ten_bit
+ parameter re_bo_on_wa = "", // dis_re_bo_on_wa, en_re_bo_on_wa
+ parameter phase_compensation_fifo = "", // low_latency, normal_latency, pld_ctrl_low_latency, pld_ctrl_normal_latency, register_fifo
+ parameter tx_rx_parallel_loopback = "", // dis_plpbk, en_plpbk
+ parameter prbs_ver_clr_flag = "", // dis_prbs_clr_flag, en_prbs_clr_flag
+ parameter cid_pattern = "", // cid_pattern_0, cid_pattern_1
+ parameter bist_ver = "", // cjpat, crpat, dis_bist, incremental
+ parameter bist_ver_clr_flag = "", // dis_bist_clr_flag, en_bist_clr_flag
+ parameter cdr_ctrl = "", // dis_cdr_ctrl, en_cdr_ctrl, en_cdr_ctrl_w_cid
+ parameter cdr_ctrl_rxvalid_mask = "", // dis_rxvalid_mask, en_rxvalid_mask
+ parameter auto_speed_nego = "", // dis_asn, en_asn_g2_freq_scal
+ parameter eidle_entry_iei = "", // dis_eidle_iei, en_eidle_iei
+ parameter eidle_entry_sd = "", // dis_eidle_sd, en_eidle_sd
+ parameter eidle_entry_eios = "", // dis_eidle_eios, en_eidle_eios
+ parameter ctrl_plane_bonding_distribution = "", // master_chnl_distr, not_master_chnl_distr
+ parameter ctrl_plane_bonding_compensation = "", // dis_compensation, en_compensation
+ parameter bypass_pipeline_reg = "", // dis_bypass_pipeline, en_bypass_pipeline
+ parameter rx_refclk = "", // dis_refclk_sel, en_refclk_sel
+ parameter rx_rcvd_clk = "", // rcvd_clk_rcvd_clk, tx_pma_clock_rcvd_clk
+ parameter agg_block_sel = "", // other_smrt_pack, same_smrt_pack
+ parameter rx_clk1 = "", // rcvd_clk_agg_clk1, rcvd_clk_agg_top_or_bottom_clk1, rcvd_clk_clk1, tx_pma_clock_clk1
+ parameter rx_clk2 = "", // rcvd_clk_clk2, refclk_dig2_clk2, tx_pma_clock_clk2
+ parameter rx_wr_clk = "", // rx_clk2_div_1_2_4, txfifo_rd_clk
+ parameter rx_rd_clk = "", // pld_rx_clk, rx_clk
+ parameter clock_gate_bist = "", // dis_bist_clk_gating, en_bist_clk_gating
+ parameter clock_gate_sw_wa = "", // dis_sw_wa_clk_gating, en_sw_wa_clk_gating
+ parameter clock_gate_dw_wa = "", // dis_dw_wa_clk_gating, en_dw_wa_clk_gating
+ parameter clock_gate_sw_dskw_wr = "", // dis_sw_dskw_wrclk_gating, en_sw_dskw_wrclk_gating
+ parameter clock_gate_dw_dskw_wr = "", // dis_dw_dskw_wrclk_gating, en_dw_dskw_wrclk_gating
+ parameter clock_gate_prbs = "", // dis_prbs_clk_gating, en_prbs_clk_gating
+ parameter clock_gate_cdr_eidle = "", // dis_cdr_eidle_clk_gating, en_cdr_eidle_clk_gating
+ parameter clock_gate_dskw_rd = "", // dis_dskw_rdclk_gating, en_dskw_rdclk_gating
+ parameter clock_gate_sw_rm_wr = "", // dis_sw_rm_wrclk_gating, en_sw_rm_wrclk_gating
+ parameter clock_gate_sw_rm_rd = "", // dis_sw_rm_rdclk_gating, en_sw_rm_rdclk_gating
+ parameter clock_gate_dw_rm_rd = "", // dis_dw_rm_rdclk_gating, en_dw_rm_rdclk_gating
+ parameter clock_gate_dw_rm_wr = "", // dis_dw_rm_wrclk_gating, en_dw_rm_wrclk_gating
+ parameter clock_gate_bds_dec_asn = "", // dis_bds_dec_asn_clk_gating, en_bds_dec_asn_clk_gating
+ parameter clock_gate_byteorder = "", // dis_byteorder_clk_gating, en_byteorder_clk_gating
+ parameter clock_gate_sw_pc_wrclk = "", // dis_sw_pc_wrclk_gating, en_sw_pc_wrclk_gating
+ parameter clock_gate_dw_pc_wrclk = "", // dis_dw_pc_wrclk_gating, en_dw_pc_wrclk_gating
+ parameter clock_gate_pc_rdclk = "", // dis_pc_rdclk_gating, en_pc_rdclk_gating
+ parameter rx_pcs_urst = "", // dis_rx_pcs_urst, en_rx_pcs_urst
+ parameter rx_clk_free_running = "", // dis_rx_clk_free_run, en_rx_clk_free_run
+ parameter comp_fifo_rst_pld_ctrl = "", // dis_comp_fifo_rst_pld_ctrl, en_comp_fifo_rst_pld_ctrl
+ parameter pc_fifo_rst_pld_ctrl = "", // dis_pc_fifo_rst_pld_ctrl, en_pc_fifo_rst_pld_ctrl
+ parameter test_bus_sel = "" // agg_testbus, deskew_testbus, pcie_ctrl_testbus, prbs_bist_testbus, rm_testbus, rx_ctrl_plane_testbus, rx_ctrl_testbus, tx_ctrl_plane_testbus, tx_testbus, wa_testbus
+) (
+ // ports
+ output wire [3:0] a1a2k1k2flag,
+ input wire a1a2size,
+ output wire aggrxpcsrst,
+ input wire [15:0] aggtestbus,
+ output wire [1:0] aligndetsync,
+ input wire alignstatus,
+ output wire alignstatuspld,
+ output wire alignstatussync,
+ input wire alignstatussync0,
+ input wire alignstatussync0toporbot,
+ input wire alignstatustoporbot,
+ input wire [10:0] avmmaddress,
+ input wire [1:0] avmmbyteen,
+ input wire avmmclk,
+ input wire avmmread,
+ output wire [15:0] avmmreaddata,
+ input wire avmmrstn,
+ input wire avmmwrite,
+ input wire [15:0] avmmwritedata,
+ output wire bistdone,
+ output wire bisterr,
+ input wire bitreversalenable,
+ input wire bitslip,
+ output wire blockselect,
+ input wire byteorder,
+ output wire byteordflag,
+ input wire bytereversalenable,
+ input wire cgcomprddall,
+ input wire cgcomprddalltoporbot,
+ output wire [1:0] cgcomprddout,
+ input wire cgcompwrall,
+ input wire cgcompwralltoporbot,
+ output wire [1:0] cgcompwrout,
+ output wire [19:0] channeltestbusout,
+ output wire clocktopld,
+ input wire configselinchnldown,
+ input wire configselinchnlup,
+ output wire configseloutchnldown,
+ output wire configseloutchnlup,
+ input wire ctrlfromaggblock,
+ input wire [7:0] datafrinaggblock,
+ input wire [19:0] datain,
+ output wire [63:0] dataout,
+ output wire decoderctrl,
+ output wire [7:0] decoderdata,
+ output wire decoderdatavalid,
+ input wire delcondmet0,
+ input wire delcondmet0toporbot,
+ output wire delcondmetout,
+ output wire disablepcfifobyteserdes,
+ input wire dynclkswitchn,
+ output wire earlyeios,
+ output wire eidledetected,
+ output wire eidleexit,
+ input wire [2:0] eidleinfersel,
+ input wire enablecommadetect,
+ input wire endskwqd,
+ input wire endskwqdtoporbot,
+ input wire endskwrdptrs,
+ input wire endskwrdptrstoporbot,
+ output wire [1:0] errctrl,
+ output wire [15:0] errdata,
+ input wire fifoovr0,
+ input wire fifoovr0toporbot,
+ output wire fifoovrout,
+ input wire fifordincomp0toporbot,
+ output wire fifordoutcomp,
+ input wire fiforstrdqd,
+ input wire fiforstrdqdtoporbot,
+ input wire gen2ngen1,
+ input wire hrdrst,
+ input wire insertincomplete0,
+ input wire insertincomplete0toporbot,
+ output wire insertincompleteout,
+ input wire latencycomp0,
+ input wire latencycomp0toporbot,
+ output wire latencycompout,
+ output wire ltr,
+ output wire observablebyteserdesclock,
+ input wire [19:0] parallelloopback,
+ output wire [19:0] parallelrevloopback,
+ output wire pcfifoempty,
+ output wire pcfifofull,
+ input wire pcfifordenable,
+ output wire pcieswitch,
+ input wire phfifouserrst,
+ output wire phystatus,
+ input wire phystatusinternal,
+ input wire phystatuspcsgen3,
+ output wire [63:0] pipedata,
+ input wire pipeloopbk,
+ input wire pldltr,
+ input wire pldrxclk,
+ input wire polinvrx,
+ input wire prbscidenable,
+ output wire prbsdone,
+ output wire prbserrlt,
+ input wire pxfifowrdisable,
+ input wire rateswitchcontrol,
+ input wire rcvdclkagg,
+ input wire rcvdclkaggtoporbot,
+ input wire rcvdclkpma,
+ output wire [1:0] rdalign,
+ input wire rdenableinchnldown,
+ input wire rdenableinchnlup,
+ output wire rdenableoutchnldown,
+ output wire rdenableoutchnlup,
+ input wire refclkdig,
+ input wire refclkdig2,
+ output wire resetpcptrs,
+ input wire resetpcptrsinchnldown,
+ output wire resetpcptrsinchnldownpipe,
+ input wire resetpcptrsinchnlup,
+ output wire resetpcptrsinchnluppipe,
+ output wire resetpcptrsoutchnldown,
+ output wire resetpcptrsoutchnlup,
+ input wire resetppmcntrsinchnldown,
+ input wire resetppmcntrsinchnlup,
+ output wire resetppmcntrsoutchnldown,
+ output wire resetppmcntrsoutchnlup,
+ output wire resetppmcntrspcspma,
+ output wire rlvlt,
+ output wire rmfifoempty,
+ output wire rmfifofull,
+ output wire rmfifopartialempty,
+ output wire rmfifopartialfull,
+ input wire rmfifordincomp0,
+ input wire rmfiforeadenable,
+ input wire rmfifouserrst,
+ input wire rmfifowriteenable,
+ output wire runlengthviolation,
+ output wire [1:0] runningdisparity,
+ output wire [3:0] rxblkstart,
+ output wire rxclkslip,
+ input wire rxcontrolrstoporbot,
+ input wire [7:0] rxdatarstoporbot,
+ output wire [3:0] rxdatavalid,
+ input wire [1:0] rxdivsyncinchnldown,
+ input wire [1:0] rxdivsyncinchnlup,
+ output wire [1:0] rxdivsyncoutchnldown,
+ output wire [1:0] rxdivsyncoutchnlup,
+ input wire rxpcsrst,
+ output wire rxpipeclk,
+ output wire rxpipesoftreset,
+ output wire [2:0] rxstatus,
+ input wire [2:0] rxstatusinternal,
+ output wire [1:0] rxsynchdr,
+ input wire [1:0] rxsynchdrpcsgen3,
+ output wire rxvalid,
+ input wire rxvalidinternal,
+ input wire [1:0] rxweinchnldown,
+ input wire [1:0] rxweinchnlup,
+ output wire [1:0] rxweoutchnldown,
+ output wire [1:0] rxweoutchnlup,
+ input wire scanmode,
+ output wire selftestdone,
+ output wire selftesterr,
+ input wire sigdetfrompma,
+ output wire signaldetectout,
+ output wire speedchange,
+ input wire speedchangeinchnldown,
+ output wire speedchangeinchnldownpipe,
+ input wire speedchangeinchnlup,
+ output wire speedchangeinchnluppipe,
+ output wire speedchangeoutchnldown,
+ output wire speedchangeoutchnlup,
+ output wire syncdatain,
+ input wire syncsmen,
+ output wire syncstatus,
+ input wire [19:0] txctrlplanetestbus,
+ input wire [1:0] txdivsync,
+ input wire txpmaclk,
+ input wire [19:0] txtestbus,
+ output wire [4:0] wordalignboundary,
+ input wire wrenableinchnldown,
+ input wire wrenableinchnlup,
+ output wire wrenableoutchnldown,
+ output wire wrenableoutchnlup
+);
+ import altera_xcvr_functions::*;
+
+ // prot_mode external parameter (no RBC)
+ localparam rbc_all_prot_mode = "(basic,cpri,cpri_rx_tx,disabled_prot_mode,gige,pipe_g1,pipe_g2,srio_2p1,test,xaui)";
+ localparam rbc_any_prot_mode = "gige";
+ localparam fnl_prot_mode = (prot_mode == "" || prot_mode == "") ? rbc_any_prot_mode : prot_mode;
+
+ // sup_mode external parameter (no RBC)
+ localparam rbc_all_sup_mode = "(engineering_mode,user_mode)";
+ localparam rbc_any_sup_mode = "user_mode";
+ localparam fnl_sup_mode = (sup_mode == "" || sup_mode == "") ? rbc_any_sup_mode : sup_mode;
+
+ // use_default_base_address external parameter (no RBC)
+ localparam rbc_all_use_default_base_address = "(false,true)";
+ localparam rbc_any_use_default_base_address = "true";
+ localparam fnl_use_default_base_address = (use_default_base_address == "" || use_default_base_address == "") ? rbc_any_use_default_base_address : use_default_base_address;
+
+ // test_mode, RBC-validated
+ localparam rbc_all_test_mode = (fnl_prot_mode == "test") ? ("(prbs,bist)") : "dont_care_test";
+ localparam rbc_any_test_mode = (fnl_prot_mode == "test") ? ("prbs") : "dont_care_test";
+ localparam fnl_test_mode = (test_mode == "" || test_mode == "") ? rbc_any_test_mode : test_mode;
+
+ // hip_mode, RBC-validated
+ localparam rbc_all_hip_mode = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" ) ? ("(dis_hip,en_hip)") : "dis_hip";
+ localparam rbc_any_hip_mode = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" ) ? ("dis_hip") : "dis_hip";
+ localparam fnl_hip_mode = (hip_mode == "" || hip_mode == "") ? rbc_any_hip_mode : hip_mode;
+
+ // pcs_bypass, RBC-validated
+ localparam rbc_all_pcs_bypass = ((fnl_prot_mode == "basic" ) || (fnl_prot_mode == "cpri_rx_tx") ) ? ("(dis_pcs_bypass,en_pcs_bypass)") : "dis_pcs_bypass";
+ localparam rbc_any_pcs_bypass = ((fnl_prot_mode == "basic" ) || (fnl_prot_mode == "cpri_rx_tx") ) ? ("dis_pcs_bypass") : "dis_pcs_bypass";
+ localparam fnl_pcs_bypass = (pcs_bypass == "" || pcs_bypass == "") ? rbc_any_pcs_bypass : pcs_bypass;
+
+ // pma_dw, RBC-validated
+ localparam rbc_all_pma_dw = ( fnl_prot_mode == "srio_2p1" ) ? ("twenty_bit")
+ : ( (fnl_prot_mode == "basic") || (fnl_test_mode == "prbs") ) ? ("(eight_bit,ten_bit,sixteen_bit,twenty_bit)")
+ : ( (fnl_test_mode == "bist" ) || ( fnl_prot_mode == "cpri") || (fnl_prot_mode == "cpri_rx_tx")) ? ("(ten_bit,twenty_bit)") : "ten_bit";
+ localparam rbc_any_pma_dw = ( fnl_prot_mode == "srio_2p1" ) ? ("twenty_bit")
+ : ( (fnl_prot_mode == "basic") || (fnl_test_mode == "prbs") ) ? ("eight_bit")
+ : ( (fnl_test_mode == "bist" ) || ( fnl_prot_mode == "cpri") || (fnl_prot_mode == "cpri_rx_tx")) ? ("ten_bit") : "ten_bit";
+ localparam fnl_pma_dw = (pma_dw == "" || pma_dw == "") ? rbc_any_pma_dw : pma_dw;
+
+ // pipe_if_enable, RBC-validated
+ localparam rbc_all_pipe_if_enable = ( (fnl_prot_mode == "pipe_g1" ) || (fnl_prot_mode == "pipe_g2" )) ? ("en_pipe_rx") : "dis_pipe_rx";
+ localparam rbc_any_pipe_if_enable = ( (fnl_prot_mode == "pipe_g1" ) || (fnl_prot_mode == "pipe_g2" )) ? ("en_pipe_rx") : "dis_pipe_rx";
+ localparam fnl_pipe_if_enable = (pipe_if_enable == "" || pipe_if_enable == "") ? rbc_any_pipe_if_enable : pipe_if_enable;
+
+ // prbs_ver, RBC-validated
+ localparam rbc_all_prbs_ver = ( fnl_test_mode == "prbs") ?
+ (
+ (fnl_pma_dw == "eight_bit") ? ("(prbs_7_sw,prbs_8,prbs_23_sw,prbs_hf_sw,prbs_15,prbs_31)")
+ : (fnl_pma_dw == "ten_bit") ? ("(prbs_10,prbs_hf_sw,prbs_lf_sw,prbs_15,prbs_31)")
+ : (fnl_pma_dw == "sixteen_bit") ? ("(prbs_7_dw,prbs_23_dw,prbs_hf_dw,prbs_15,prbs_31)") : "(prbs_7_dw,prbs_23_dw,prbs_hf_dw,prbs_lf_dw,prbs_15,prbs_31)"
+ ) : "dis_prbs";
+ localparam rbc_any_prbs_ver = ( fnl_test_mode == "prbs") ?
+ (
+ (fnl_pma_dw == "eight_bit") ? ("prbs_7_sw")
+ : (fnl_pma_dw == "ten_bit") ? ("prbs_10")
+ : (fnl_pma_dw == "sixteen_bit") ? ("prbs_7_dw") : "prbs_7_dw"
+ ) : "dis_prbs";
+ localparam fnl_prbs_ver = (prbs_ver == "" || prbs_ver == "") ? rbc_any_prbs_ver : prbs_ver;
+
+ // wa_boundary_lock_ctrl, RBC-validated
+ localparam rbc_all_wa_boundary_lock_ctrl = ((fnl_pcs_bypass == "dis_pcs_bypass") && ( fnl_pma_dw == "eight_bit" || fnl_pma_dw == "sixteen_bit" || fnl_pma_dw == "twenty_bit") && ( fnl_prot_mode == "basic") ) ? ("(bit_slip,auto_align_pld_ctrl)")
+ : ( (fnl_pcs_bypass == "dis_pcs_bypass") && ( fnl_prot_mode == "basic") ) ? ("(bit_slip,sync_sm,auto_align_pld_ctrl)")
+ : ( (fnl_pcs_bypass == "en_pcs_bypass") || (fnl_prbs_ver == "prbs_lf_sw" ) || (fnl_prbs_ver == "prbs_hf_sw" ) || (fnl_prbs_ver == "prbs_lf_dw" ) || (fnl_prbs_ver == "prbs_hf_dw" ) ) ? ("bit_slip")
+ : (fnl_prot_mode == "cpri") ? ("deterministic_latency")
+ : ( fnl_prot_mode == "cpri_rx_tx" || ( fnl_test_mode == "bist" && fnl_pma_dw == "twenty_bit" ) || ( fnl_test_mode == "prbs" ) ) ? ("auto_align_pld_ctrl") : "sync_sm";
+ localparam rbc_any_wa_boundary_lock_ctrl = ((fnl_pcs_bypass == "dis_pcs_bypass") && ( fnl_pma_dw == "eight_bit" || fnl_pma_dw == "sixteen_bit" || fnl_pma_dw == "twenty_bit") && ( fnl_prot_mode == "basic") ) ? ("bit_slip")
+ : ( (fnl_pcs_bypass == "dis_pcs_bypass") && ( fnl_prot_mode == "basic") ) ? ("bit_slip")
+ : ( (fnl_pcs_bypass == "en_pcs_bypass") || (fnl_prbs_ver == "prbs_lf_sw" ) || (fnl_prbs_ver == "prbs_hf_sw" ) || (fnl_prbs_ver == "prbs_lf_dw" ) || (fnl_prbs_ver == "prbs_hf_dw" ) ) ? ("bit_slip")
+ : (fnl_prot_mode == "cpri") ? ("deterministic_latency")
+ : ( fnl_prot_mode == "cpri_rx_tx" || ( fnl_test_mode == "bist" && fnl_pma_dw == "twenty_bit" ) || ( fnl_test_mode == "prbs" ) ) ? ("auto_align_pld_ctrl") : "sync_sm";
+ localparam fnl_wa_boundary_lock_ctrl = (wa_boundary_lock_ctrl == "" || wa_boundary_lock_ctrl == "") ? rbc_any_wa_boundary_lock_ctrl : wa_boundary_lock_ctrl;
+
+ // wa_pld_controlled, RBC-validated
+ localparam rbc_all_wa_pld_controlled = ( fnl_wa_boundary_lock_ctrl == "sync_sm" || fnl_wa_boundary_lock_ctrl == "deterministic_latency" ) ? ("dis_pld_ctrl")
+ : ( fnl_pma_dw == "eight_bit" || fnl_pma_dw == "ten_bit") ? ("pld_ctrl_sw") : "rising_edge_sensitive_dw";
+ localparam rbc_any_wa_pld_controlled = ( fnl_wa_boundary_lock_ctrl == "sync_sm" || fnl_wa_boundary_lock_ctrl == "deterministic_latency" ) ? ("dis_pld_ctrl")
+ : ( fnl_pma_dw == "eight_bit" || fnl_pma_dw == "ten_bit") ? ("pld_ctrl_sw") : "rising_edge_sensitive_dw";
+ localparam fnl_wa_pld_controlled = (wa_pld_controlled == "" || wa_pld_controlled == "") ? rbc_any_wa_pld_controlled : wa_pld_controlled;
+
+ // wa_pd_polarity, RBC-validated
+ localparam rbc_all_wa_pd_polarity = ( fnl_pma_dw == "eight_bit" || fnl_pma_dw == "ten_bit" ) ? ("dont_care_both_pol")
+ : ( (fnl_pma_dw == "sixteen_bit") || (fnl_test_mode == "prbs") ) ? ("dis_pd_both_pol") : "en_pd_both_pol";
+ localparam rbc_any_wa_pd_polarity = ( fnl_pma_dw == "eight_bit" || fnl_pma_dw == "ten_bit" ) ? ("dont_care_both_pol")
+ : ( (fnl_pma_dw == "sixteen_bit") || (fnl_test_mode == "prbs") ) ? ("dis_pd_both_pol") : "en_pd_both_pol";
+ localparam fnl_wa_pd_polarity = (wa_pd_polarity == "" || wa_pd_polarity == "") ? rbc_any_wa_pd_polarity : wa_pd_polarity;
+
+ // wa_pd, RBC-validated
+ localparam rbc_all_wa_pd = ( fnl_wa_boundary_lock_ctrl != "bit_slip" ) ?
+ (
+ (fnl_prot_mode == "gige" || fnl_prot_mode == "xaui" || fnl_prot_mode == "srio_2p1" ) ? ("(wa_pd_fixed_7_k28p5,wa_pd_fixed_10_k28p5)")
+ : ( fnl_prot_mode == "basic" ) ?
+ (
+ (fnl_pma_dw == "eight_bit") ? ("(wa_pd_8_sw,wa_pd_16_sw,wa_pd_fixed_16_a1a2_sw)")
+ : (fnl_pma_dw == "ten_bit") ? ("(wa_pd_7,wa_pd_10,wa_pd_fixed_7_k28p5,wa_pd_fixed_10_k28p5)")
+ : (fnl_pma_dw == "sixteen_bit") ? ("(wa_pd_8_dw,wa_pd_16_dw,wa_pd_32,wa_pd_fixed_16_a1a2_dw,wa_pd_fixed_32_a1a1a2a2)")
+ : ( fnl_wa_boundary_lock_ctrl != "sync_sm" ) ? ("(wa_pd_7,wa_pd_10,wa_pd_20,wa_pd_40,wa_pd_fixed_7_k28p5,wa_pd_fixed_10_k28p5)") : "(wa_pd_7,wa_pd_10,wa_pd_20,wa_pd_fixed_7_k28p5,wa_pd_fixed_10_k28p5)"
+ )
+ : ( fnl_test_mode == "prbs" ) ?
+ (
+ ( fnl_prbs_ver == "prbs_7_sw" ) ? ("prbs7_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_7_dw") && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs7_fixed_wa_pd_16_dw")
+ : ( (fnl_prbs_ver == "prbs_7_dw") && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs7_fixed_wa_pd_20_dw")
+ : ( fnl_prbs_ver == "prbs_23_sw" ) ? ("prbs23_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_23_dw") && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs23_fixed_wa_pd_32_dw")
+ : ( (fnl_prbs_ver == "prbs_23_dw") && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs23_fixed_wa_pd_40_dw")
+ : ( (fnl_prbs_ver == "prbs_15" ) && ( fnl_pma_dw == "eight_bit" ) ) ? ("prbs15_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_15" ) && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs15_fixed_wa_pd_16_dw")
+ : ( (fnl_prbs_ver == "prbs_15" ) && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs15_fixed_wa_pd_20_dw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "eight_bit" ) ) ? ("prbs31_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "ten_bit" ) ) ? ("prbs31_fixed_wa_pd_10_sw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs31_fixed_wa_pd_16_dw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs31_fixed_wa_pd_40_dw")
+ : (fnl_prbs_ver == "prbs_8" ) ? ("prbs8_fixed_wa")
+ : (fnl_prbs_ver == "prbs_10" ) ? ("prbs10_fixed_wa") : "dont_care_wa_pd_0"
+ )
+ : ( fnl_test_mode == "bist" ) ? ("wa_pd_fixed_10_k28p5") : "wa_pd_fixed_10_k28p5"
+ )
+ : (fnl_pma_dw == "sixteen_bit") ? ("dont_care_wa_pd_1") : "dont_care_wa_pd_0";
+ localparam rbc_any_wa_pd = ( fnl_wa_boundary_lock_ctrl != "bit_slip" ) ?
+ (
+ (fnl_prot_mode == "gige" || fnl_prot_mode == "xaui" || fnl_prot_mode == "srio_2p1" ) ? ("wa_pd_fixed_7_k28p5")
+ : ( fnl_prot_mode == "basic" ) ?
+ (
+ (fnl_pma_dw == "eight_bit") ? ("wa_pd_8_sw")
+ : (fnl_pma_dw == "ten_bit") ? ("wa_pd_10")
+ : (fnl_pma_dw == "sixteen_bit") ? ("wa_pd_8_dw")
+ : ( fnl_wa_boundary_lock_ctrl != "sync_sm" ) ? ("wa_pd_10") : "wa_pd_10"
+ )
+ : ( fnl_test_mode == "prbs" ) ?
+ (
+ ( fnl_prbs_ver == "prbs_7_sw" ) ? ("prbs7_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_7_dw") && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs7_fixed_wa_pd_16_dw")
+ : ( (fnl_prbs_ver == "prbs_7_dw") && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs7_fixed_wa_pd_20_dw")
+ : ( fnl_prbs_ver == "prbs_23_sw" ) ? ("prbs23_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_23_dw") && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs23_fixed_wa_pd_32_dw")
+ : ( (fnl_prbs_ver == "prbs_23_dw") && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs23_fixed_wa_pd_40_dw")
+ : ( (fnl_prbs_ver == "prbs_15" ) && ( fnl_pma_dw == "eight_bit" ) ) ? ("prbs15_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_15" ) && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs15_fixed_wa_pd_16_dw")
+ : ( (fnl_prbs_ver == "prbs_15" ) && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs15_fixed_wa_pd_20_dw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "eight_bit" ) ) ? ("prbs31_fixed_wa_pd_16_sw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "ten_bit" ) ) ? ("prbs31_fixed_wa_pd_10_sw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "sixteen_bit" ) ) ? ("prbs31_fixed_wa_pd_16_dw")
+ : ( (fnl_prbs_ver == "prbs_31" ) && ( fnl_pma_dw == "twenty_bit" ) ) ? ("prbs31_fixed_wa_pd_40_dw")
+ : (fnl_prbs_ver == "prbs_8" ) ? ("prbs8_fixed_wa")
+ : (fnl_prbs_ver == "prbs_10" ) ? ("prbs10_fixed_wa") : "dont_care_wa_pd_0"
+ )
+ : ( fnl_test_mode == "bist" ) ? ("wa_pd_fixed_10_k28p5") : "wa_pd_fixed_10_k28p5"
+ )
+ : (fnl_pma_dw == "sixteen_bit") ? ("dont_care_wa_pd_1") : "dont_care_wa_pd_0";
+ localparam fnl_wa_pd = (wa_pd == "" || wa_pd == "") ? rbc_any_wa_pd : wa_pd;
+
+ // wa_sync_sm_ctrl, RBC-validated
+ localparam rbc_all_wa_sync_sm_ctrl = ( fnl_wa_boundary_lock_ctrl == "sync_sm" ) ?
+ (
+ (fnl_prot_mode == "gige") ? ("gige_sync_sm")
+ : (fnl_prot_mode == "xaui") ? ("xaui_sync_sm")
+ : (fnl_prot_mode == "srio_2p1") ? ("srio2p1_sync_sm")
+ : (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" ) ? ("pipe_sync_sm")
+ : (fnl_test_mode == "bist") ? ("sw_basic_sync_sm")
+ : ( (fnl_prot_mode == "basic") && ( fnl_pma_dw == "ten_bit") ) ? ("sw_basic_sync_sm")
+ : ( (fnl_prot_mode == "basic") && ( fnl_pma_dw == "twenty_bit") ) ? ("(dw_basic_sync_sm,srio2p1_sync_sm)") : "gige_sync_sm"
+ ) : "gige_sync_sm";
+ localparam rbc_any_wa_sync_sm_ctrl = ( fnl_wa_boundary_lock_ctrl == "sync_sm" ) ?
+ (
+ (fnl_prot_mode == "gige") ? ("gige_sync_sm")
+ : (fnl_prot_mode == "xaui") ? ("xaui_sync_sm")
+ : (fnl_prot_mode == "srio_2p1") ? ("srio2p1_sync_sm")
+ : (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" ) ? ("pipe_sync_sm")
+ : (fnl_test_mode == "bist") ? ("sw_basic_sync_sm")
+ : ( (fnl_prot_mode == "basic") && ( fnl_pma_dw == "ten_bit") ) ? ("sw_basic_sync_sm")
+ : ( (fnl_prot_mode == "basic") && ( fnl_pma_dw == "twenty_bit") ) ? ("dw_basic_sync_sm") : "gige_sync_sm"
+ ) : "gige_sync_sm";
+ localparam fnl_wa_sync_sm_ctrl = (wa_sync_sm_ctrl == "" || wa_sync_sm_ctrl == "") ? rbc_any_wa_sync_sm_ctrl : wa_sync_sm_ctrl;
+
+ // wa_kchar, RBC-validated
+ localparam rbc_all_wa_kchar = "dis_kchar";
+ localparam rbc_any_wa_kchar = "dis_kchar";
+ localparam fnl_wa_kchar = (wa_kchar == "" || wa_kchar == "") ? rbc_any_wa_kchar : wa_kchar;
+
+ // fixed_pat_det, RBC-validated
+ localparam rbc_all_fixed_pat_det = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ?
+ (
+ (fnl_sup_mode == "engineering_mode") ? ("(dis_fixed_patdet,en_fixed_patdet)") : "dis_fixed_patdet"
+ ) : "dis_fixed_patdet";
+ localparam rbc_any_fixed_pat_det = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ?
+ (
+ (fnl_sup_mode == "engineering_mode") ? ("dis_fixed_patdet") : "dis_fixed_patdet"
+ ) : "dis_fixed_patdet";
+ localparam fnl_fixed_pat_det = (fixed_pat_det == "" || fixed_pat_det == "") ? rbc_any_fixed_pat_det : fixed_pat_det;
+
+ // ibm_invalid_code, RBC-validated
+ localparam rbc_all_ibm_invalid_code = "dis_ibm_invalid_code";
+ localparam rbc_any_ibm_invalid_code = "dis_ibm_invalid_code";
+ localparam fnl_ibm_invalid_code = (ibm_invalid_code == "" || ibm_invalid_code == "") ? rbc_any_ibm_invalid_code : ibm_invalid_code;
+
+ // force_signal_detect, RBC-validated
+ localparam rbc_all_force_signal_detect = "en_force_signal_detect";
+ localparam rbc_any_force_signal_detect = "en_force_signal_detect";
+ localparam fnl_force_signal_detect = (force_signal_detect == "" || force_signal_detect == "") ? rbc_any_force_signal_detect : force_signal_detect;
+
+ // wa_det_latency_sync_status_beh, RBC-validated
+ localparam rbc_all_wa_det_latency_sync_status_beh = (fnl_prot_mode == "cpri") ? ("(assert_sync_status_imm,assert_sync_status_non_imm)") : "dont_care_assert_sync";
+ localparam rbc_any_wa_det_latency_sync_status_beh = (fnl_prot_mode == "cpri") ? ("assert_sync_status_non_imm") : "dont_care_assert_sync";
+ localparam fnl_wa_det_latency_sync_status_beh = (wa_det_latency_sync_status_beh == "" || wa_det_latency_sync_status_beh == "") ? rbc_any_wa_det_latency_sync_status_beh : wa_det_latency_sync_status_beh;
+
+ // wa_clk_slip_spacing, RBC-validated
+ localparam rbc_all_wa_clk_slip_spacing = (fnl_prot_mode == "cpri") ? ("(min_clk_slip_spacing,user_programmable_clk_slip_spacing)") : "min_clk_slip_spacing";
+ localparam rbc_any_wa_clk_slip_spacing = (fnl_prot_mode == "cpri") ? ("min_clk_slip_spacing") : "min_clk_slip_spacing";
+ localparam fnl_wa_clk_slip_spacing = (wa_clk_slip_spacing == "" || wa_clk_slip_spacing == "") ? rbc_any_wa_clk_slip_spacing : wa_clk_slip_spacing;
+
+ // eightb_tenb_decoder, RBC-validated
+ localparam rbc_all_eightb_tenb_decoder = ( (fnl_pma_dw == "eight_bit") || (fnl_pma_dw == "sixteen_bit") || (fnl_pcs_bypass == "en_pcs_bypass") || (fnl_test_mode == "prbs") ) ? ("dis_8b10b")
+ : (fnl_prot_mode == "basic" || fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx") ? ("(dis_8b10b,en_8b10b_ibm)") : "en_8b10b_ibm";
+ localparam rbc_any_eightb_tenb_decoder = ( (fnl_pma_dw == "eight_bit") || (fnl_pma_dw == "sixteen_bit") || (fnl_pcs_bypass == "en_pcs_bypass") || (fnl_test_mode == "prbs") ) ? ("dis_8b10b")
+ : (fnl_prot_mode == "basic" || fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx") ? ("dis_8b10b") : "en_8b10b_ibm";
+ localparam fnl_eightb_tenb_decoder = (eightb_tenb_decoder == "" || eightb_tenb_decoder == "") ? rbc_any_eightb_tenb_decoder : eightb_tenb_decoder;
+
+ // wa_disp_err_flag, RBC-validated
+ localparam rbc_all_wa_disp_err_flag = ( (fnl_prot_mode == "basic" ) && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") ) ? ("(dis_disp_err_flag,en_disp_err_flag)")
+ : (fnl_eightb_tenb_decoder == "dis_8b10b" ) ? ("dis_disp_err_flag") : "en_disp_err_flag";
+ localparam rbc_any_wa_disp_err_flag = ( (fnl_prot_mode == "basic" ) && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") ) ? ("dis_disp_err_flag")
+ : (fnl_eightb_tenb_decoder == "dis_8b10b" ) ? ("dis_disp_err_flag") : "en_disp_err_flag";
+ localparam fnl_wa_disp_err_flag = (wa_disp_err_flag == "" || wa_disp_err_flag == "") ? rbc_any_wa_disp_err_flag : wa_disp_err_flag;
+
+ // polarity_inversion, RBC-validated
+ localparam rbc_all_polarity_inversion = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("dis_pol_inv")
+ : (fnl_prot_mode == "test") ?
+ (
+ ( (fnl_test_mode == "prbs") && (fnl_prbs_ver == "prbs_31")) ? ("(dis_pol_inv,en_pol_inv)") : "dis_pol_inv"
+ ) : "(dis_pol_inv,en_pol_inv)";
+ localparam rbc_any_polarity_inversion = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("dis_pol_inv")
+ : (fnl_prot_mode == "test") ?
+ (
+ ( (fnl_test_mode == "prbs") && (fnl_prbs_ver == "prbs_31")) ? ("dis_pol_inv") : "dis_pol_inv"
+ ) : "dis_pol_inv";
+ localparam fnl_polarity_inversion = (polarity_inversion == "" || polarity_inversion == "") ? rbc_any_polarity_inversion : polarity_inversion;
+
+ // bit_reversal, RBC-validated
+ localparam rbc_all_bit_reversal = (fnl_prot_mode == "basic" ) ? ("(dis_bit_reversal,en_bit_reversal)") : "dis_bit_reversal";
+ localparam rbc_any_bit_reversal = (fnl_prot_mode == "basic" ) ? ("dis_bit_reversal") : "dis_bit_reversal";
+ localparam fnl_bit_reversal = (bit_reversal == "" || bit_reversal == "") ? rbc_any_bit_reversal : bit_reversal;
+
+ // symbol_swap, RBC-validated
+ localparam rbc_all_symbol_swap = (fnl_prot_mode == "basic" && (fnl_pma_dw == "sixteen_bit" || fnl_pma_dw == "twenty_bit") ) ? ("(dis_symbol_swap,en_symbol_swap)") : "dis_symbol_swap";
+ localparam rbc_any_symbol_swap = (fnl_prot_mode == "basic" && (fnl_pma_dw == "sixteen_bit" || fnl_pma_dw == "twenty_bit") ) ? ("dis_symbol_swap") : "dis_symbol_swap";
+ localparam fnl_symbol_swap = (symbol_swap == "" || symbol_swap == "") ? rbc_any_symbol_swap : symbol_swap;
+
+ // runlength_check, RBC-validated
+ localparam rbc_all_runlength_check = ((fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "eight_bit") ) ? ("en_runlength_sw") : "en_runlength_dw";
+ localparam rbc_any_runlength_check = ((fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "eight_bit") ) ? ("en_runlength_sw") : "en_runlength_dw";
+ localparam fnl_runlength_check = (runlength_check == "" || runlength_check == "") ? rbc_any_runlength_check : runlength_check;
+
+ // ctrl_plane_bonding_consumption, RBC-validated
+ localparam rbc_all_ctrl_plane_bonding_consumption = ( (fnl_prot_mode == "test") || (fnl_prot_mode == "basic") || (fnl_prot_mode == "cpri") || (fnl_prot_mode == "cpri_rx_tx") || (fnl_prot_mode == "gige") || (fnl_prot_mode == "disabled_prot_mode") ) ? ("individual")
+ : (fnl_prot_mode == "xaui") ? ("(bundled_master,bundled_slave_below,bundled_slave_above)") : "(individual,bundled_master,bundled_slave_below,bundled_slave_above)";
+ localparam rbc_any_ctrl_plane_bonding_consumption = ( (fnl_prot_mode == "test") || (fnl_prot_mode == "basic") || (fnl_prot_mode == "cpri") || (fnl_prot_mode == "cpri_rx_tx") || (fnl_prot_mode == "gige") || (fnl_prot_mode == "disabled_prot_mode") ) ? ("individual")
+ : (fnl_prot_mode == "xaui") ? ("bundled_master") : "individual";
+ localparam fnl_ctrl_plane_bonding_consumption = (ctrl_plane_bonding_consumption == "" || ctrl_plane_bonding_consumption == "") ? rbc_any_ctrl_plane_bonding_consumption : ctrl_plane_bonding_consumption;
+
+ // deskew, RBC-validated
+ localparam rbc_all_deskew = ( (fnl_prot_mode == "srio_2p1") && (fnl_ctrl_plane_bonding_consumption != "individual") ) ? ("en_srio_v2p1")
+ : (fnl_prot_mode == "xaui") ? ("en_xaui") : "dis_deskew";
+ localparam rbc_any_deskew = ( (fnl_prot_mode == "srio_2p1") && (fnl_ctrl_plane_bonding_consumption != "individual") ) ? ("en_srio_v2p1")
+ : (fnl_prot_mode == "xaui") ? ("en_xaui") : "dis_deskew";
+ localparam fnl_deskew = (deskew == "" || deskew == "") ? rbc_any_deskew : deskew;
+
+ // deskew_prog_pattern_only, RBC-validated
+ localparam rbc_all_deskew_prog_pattern_only = "dis_deskew_prog_pat_only";
+ localparam rbc_any_deskew_prog_pattern_only = "dis_deskew_prog_pat_only";
+ localparam fnl_deskew_prog_pattern_only = (deskew_prog_pattern_only == "" || deskew_prog_pattern_only == "") ? rbc_any_deskew_prog_pattern_only : deskew_prog_pattern_only;
+
+ // rate_match, RBC-validated
+ localparam rbc_all_rate_match = (fnl_prot_mode == "gige") ? ("(dis_rm,gige_rm)")
+ : (fnl_prot_mode == "xaui") ? ("xaui_rm")
+ : ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("(pipe_rm,pipe_rm_0ppm)")
+ : (fnl_prot_mode == "srio_2p1") ? ("(srio_v2p1_rm,srio_v2p1_rm_0ppm)")
+ : ( (fnl_prot_mode == "basic") && (fnl_pma_dw == "ten_bit") && (fnl_wa_boundary_lock_ctrl == "sync_sm") && (fnl_pcs_bypass == "dis_pcs_bypass") ) ? ("(dis_rm,sw_basic_rm)")
+ : ( (fnl_prot_mode == "basic") && (fnl_pma_dw == "twenty_bit") && (fnl_wa_boundary_lock_ctrl == "auto_align_pld_ctrl") && (fnl_pcs_bypass == "dis_pcs_bypass") ) ? ("(dis_rm,dw_basic_rm)") : "dis_rm";
+ localparam rbc_any_rate_match = (fnl_prot_mode == "gige") ? ("dis_rm")
+ : (fnl_prot_mode == "xaui") ? ("xaui_rm")
+ : ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("pipe_rm")
+ : (fnl_prot_mode == "srio_2p1") ? ("srio_v2p1_rm")
+ : ( (fnl_prot_mode == "basic") && (fnl_pma_dw == "ten_bit") && (fnl_wa_boundary_lock_ctrl == "sync_sm") && (fnl_pcs_bypass == "dis_pcs_bypass") ) ? ("dis_rm")
+ : ( (fnl_prot_mode == "basic") && (fnl_pma_dw == "twenty_bit") && (fnl_wa_boundary_lock_ctrl == "auto_align_pld_ctrl") && (fnl_pcs_bypass == "dis_pcs_bypass") ) ? ("dis_rm") : "dis_rm";
+ localparam fnl_rate_match = (rate_match == "" || rate_match == "") ? rbc_any_rate_match : rate_match;
+
+ // err_flags_sel, RBC-validated
+ localparam rbc_all_err_flags_sel = ( (fnl_prot_mode == "basic") && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") ) ? ("(err_flags_wa,err_flags_8b10b)") : "err_flags_wa";
+ localparam rbc_any_err_flags_sel = ( (fnl_prot_mode == "basic") && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") ) ? ("err_flags_wa") : "err_flags_wa";
+ localparam fnl_err_flags_sel = (err_flags_sel == "" || err_flags_sel == "") ? rbc_any_err_flags_sel : err_flags_sel;
+
+ // polinv_8b10b_dec, RBC-validated
+ localparam rbc_all_polinv_8b10b_dec = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("en_polinv_8b10b_dec") : "dis_polinv_8b10b_dec";
+ localparam rbc_any_polinv_8b10b_dec = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("en_polinv_8b10b_dec") : "dis_polinv_8b10b_dec";
+ localparam fnl_polinv_8b10b_dec = (polinv_8b10b_dec == "" || polinv_8b10b_dec == "") ? rbc_any_polinv_8b10b_dec : polinv_8b10b_dec;
+
+ // eightbtenb_decoder_output_sel, RBC-validated
+ localparam rbc_all_eightbtenb_decoder_output_sel = (fnl_prot_mode == "xaui") ? ("data_xaui_sm") : "data_8b10b_decoder";
+ localparam rbc_any_eightbtenb_decoder_output_sel = (fnl_prot_mode == "xaui") ? ("data_xaui_sm") : "data_8b10b_decoder";
+ localparam fnl_eightbtenb_decoder_output_sel = (eightbtenb_decoder_output_sel == "" || eightbtenb_decoder_output_sel == "") ? rbc_any_eightbtenb_decoder_output_sel : eightbtenb_decoder_output_sel;
+
+ // invalid_code_flag_only, RBC-validated
+ localparam rbc_all_invalid_code_flag_only = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("(dis_invalid_code_only,en_invalid_code_only)") : "dis_invalid_code_only";
+ localparam rbc_any_invalid_code_flag_only = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("dis_invalid_code_only") : "dis_invalid_code_only";
+ localparam fnl_invalid_code_flag_only = (invalid_code_flag_only == "" || invalid_code_flag_only == "") ? rbc_any_invalid_code_flag_only : invalid_code_flag_only;
+
+ // auto_error_replacement, RBC-validated
+ localparam rbc_all_auto_error_replacement = ((fnl_prot_mode == "basic") && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") && ( (fnl_pma_dw == "ten_bit" && fnl_wa_boundary_lock_ctrl == "sync_sm") || (fnl_pma_dw == "twenty_bit" && fnl_wa_boundary_lock_ctrl == "auto_align_pld_ctrl")) ) ? ("(dis_err_replace,en_err_replace)")
+ : ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("en_err_replace") : "dis_err_replace";
+ localparam rbc_any_auto_error_replacement = ((fnl_prot_mode == "basic") && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") && ( (fnl_pma_dw == "ten_bit" && fnl_wa_boundary_lock_ctrl == "sync_sm") || (fnl_pma_dw == "twenty_bit" && fnl_wa_boundary_lock_ctrl == "auto_align_pld_ctrl")) ) ? ("dis_err_replace")
+ : ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("en_err_replace") : "dis_err_replace";
+ localparam fnl_auto_error_replacement = (auto_error_replacement == "" || auto_error_replacement == "") ? rbc_any_auto_error_replacement : auto_error_replacement;
+
+ // pad_or_edb_error_replace, RBC-validated
+ localparam rbc_all_pad_or_edb_error_replace = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("replace_edb_dynamic") : "replace_edb";
+ localparam rbc_any_pad_or_edb_error_replace = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("replace_edb_dynamic") : "replace_edb";
+ localparam fnl_pad_or_edb_error_replace = (pad_or_edb_error_replace == "" || pad_or_edb_error_replace == "") ? rbc_any_pad_or_edb_error_replace : pad_or_edb_error_replace;
+
+ // byte_deserializer, RBC-validated
+ localparam rbc_all_byte_deserializer = ( fnl_prot_mode == "cpri" ) ? ("(dis_bds,en_bds_by_2)")
+ : ( (fnl_test_mode == "prbs") || (fnl_test_mode == "bist" && fnl_pma_dw == "twenty_bit") || (fnl_prot_mode == "disabled_prot_mode") || (fnl_hip_mode == "en_hip") ) ? ("dis_bds")
+ : ( (fnl_prot_mode == "xaui") || (fnl_test_mode == "bist" && fnl_pma_dw == "ten_bit" ) || ( fnl_prot_mode == "pipe_g2" )) ? ("en_bds_by_2") : "(dis_bds,en_bds_by_2)";
+ localparam rbc_any_byte_deserializer = ( fnl_prot_mode == "cpri" ) ? ("dis_bds")
+ : ( (fnl_test_mode == "prbs") || (fnl_test_mode == "bist" && fnl_pma_dw == "twenty_bit") || (fnl_prot_mode == "disabled_prot_mode") || (fnl_hip_mode == "en_hip") ) ? ("dis_bds")
+ : ( (fnl_prot_mode == "xaui") || (fnl_test_mode == "bist" && fnl_pma_dw == "ten_bit" ) || ( fnl_prot_mode == "pipe_g2" )) ? ("en_bds_by_2") : "dis_bds";
+ localparam fnl_byte_deserializer = (byte_deserializer == "" || byte_deserializer == "") ? rbc_any_byte_deserializer : byte_deserializer;
+
+ // byte_order, RBC-validated
+ localparam rbc_all_byte_order = ( ( fnl_byte_deserializer == "en_bds_by_2" ) && (fnl_pcs_bypass == "dis_pcs_bypass") && (fnl_wa_boundary_lock_ctrl != "deterministic_latency" ) ) ?
+ (
+ (fnl_prot_mode == "basic") ?
+ (
+ ( (fnl_pma_dw == "eight_bit") || (fnl_pma_dw == "sixteen_bit") ) ?
+ (
+ (fnl_wa_boundary_lock_ctrl == "bit_slip" ) ? ("(dis_bo,en_pld_ctrl_eight_bit_bo)") : "(dis_bo,en_pcs_ctrl_eight_bit_bo,en_pld_ctrl_eight_bit_bo)"
+ )
+ : ( ( (fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "twenty_bit") ) && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") ) ?
+ (
+ (fnl_wa_boundary_lock_ctrl == "bit_slip" ) ? ("(dis_bo,en_pld_ctrl_nine_bit_bo)") : "(dis_bo,en_pcs_ctrl_nine_bit_bo,en_pld_ctrl_nine_bit_bo)"
+ )
+ : (fnl_wa_boundary_lock_ctrl == "bit_slip" ) ? ("(dis_bo,en_pld_ctrl_ten_bit_bo)") : "(dis_bo,en_pcs_ctrl_ten_bit_bo,en_pld_ctrl_ten_bit_bo)"
+ )
+ : ( (fnl_test_mode == "bist") && (fnl_pma_dw == "ten_bit") ) ? ("en_pcs_ctrl_nine_bit_bo") : "dis_bo"
+ ) : "dis_bo";
+ localparam rbc_any_byte_order = ( ( fnl_byte_deserializer == "en_bds_by_2" ) && (fnl_pcs_bypass == "dis_pcs_bypass") && (fnl_wa_boundary_lock_ctrl != "deterministic_latency" ) ) ?
+ (
+ (fnl_prot_mode == "basic") ?
+ (
+ ( (fnl_pma_dw == "eight_bit") || (fnl_pma_dw == "sixteen_bit") ) ?
+ (
+ (fnl_wa_boundary_lock_ctrl == "bit_slip" ) ? ("dis_bo") : "dis_bo"
+ )
+ : ( ( (fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "twenty_bit") ) && (fnl_eightb_tenb_decoder == "en_8b10b_ibm") ) ?
+ (
+ (fnl_wa_boundary_lock_ctrl == "bit_slip" ) ? ("dis_bo") : "dis_bo"
+ )
+ : (fnl_wa_boundary_lock_ctrl == "bit_slip" ) ? ("dis_bo") : "dis_bo"
+ )
+ : ( (fnl_test_mode == "bist") && (fnl_pma_dw == "ten_bit") ) ? ("en_pcs_ctrl_nine_bit_bo") : "dis_bo"
+ ) : "dis_bo";
+ localparam fnl_byte_order = (byte_order == "" || byte_order == "") ? rbc_any_byte_order : byte_order;
+
+ // dw_one_or_two_symbol_bo, RBC-validated
+ localparam rbc_all_dw_one_or_two_symbol_bo = ( (fnl_pma_dw == "sixteen_bit") && ( (fnl_byte_order != "dis_bo" ) ) ) ? ("(one_symbol_bo,two_symbol_bo_eight_bit)")
+ : ( (fnl_pma_dw == "twenty_bit") && ( (fnl_byte_order == "en_pcs_ctrl_nine_bit_bo" ) || (fnl_byte_order == "en_pld_ctrl_nine_bit_bo" ) ) ) ? ("(one_symbol_bo,two_symbol_bo_nine_bit)")
+ : ( (fnl_pma_dw == "twenty_bit") && ( (fnl_byte_order == "en_pcs_ctrl_ten_bit_bo" ) || (fnl_byte_order == "en_pld_ctrl_ten_bit_bo" ) ) ) ? ("(one_symbol_bo,two_symbol_bo_ten_bit)") : "donot_care_one_two_bo";
+ localparam rbc_any_dw_one_or_two_symbol_bo = ( (fnl_pma_dw == "sixteen_bit") && ( (fnl_byte_order != "dis_bo" ) ) ) ? ("one_symbol_bo")
+ : ( (fnl_pma_dw == "twenty_bit") && ( (fnl_byte_order == "en_pcs_ctrl_nine_bit_bo" ) || (fnl_byte_order == "en_pld_ctrl_nine_bit_bo" ) ) ) ? ("one_symbol_bo")
+ : ( (fnl_pma_dw == "twenty_bit") && ( (fnl_byte_order == "en_pcs_ctrl_ten_bit_bo" ) || (fnl_byte_order == "en_pld_ctrl_ten_bit_bo" ) ) ) ? ("one_symbol_bo") : "donot_care_one_two_bo";
+ localparam fnl_dw_one_or_two_symbol_bo = (dw_one_or_two_symbol_bo == "" || dw_one_or_two_symbol_bo == "") ? rbc_any_dw_one_or_two_symbol_bo : dw_one_or_two_symbol_bo;
+
+ // re_bo_on_wa, RBC-validated
+ localparam rbc_all_re_bo_on_wa = "dis_re_bo_on_wa";
+ localparam rbc_any_re_bo_on_wa = "dis_re_bo_on_wa";
+ localparam fnl_re_bo_on_wa = (re_bo_on_wa == "" || re_bo_on_wa == "") ? rbc_any_re_bo_on_wa : re_bo_on_wa;
+
+ // phase_compensation_fifo, RBC-validated
+ localparam rbc_all_phase_compensation_fifo = (fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx" || fnl_hip_mode == "en_hip" ) ? ("register_fifo")
+ : ( (fnl_prot_mode == "basic") || (fnl_prot_mode == "gige") ) ? ("(low_latency,register_fifo)") : "low_latency";
+ localparam rbc_any_phase_compensation_fifo = (fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx" || fnl_hip_mode == "en_hip" ) ? ("register_fifo")
+ : ( (fnl_prot_mode == "basic") || (fnl_prot_mode == "gige") ) ? ("low_latency") : "low_latency";
+ localparam fnl_phase_compensation_fifo = (phase_compensation_fifo == "" || phase_compensation_fifo == "") ? rbc_any_phase_compensation_fifo : phase_compensation_fifo;
+
+ // tx_rx_parallel_loopback, RBC-validated
+ localparam rbc_all_tx_rx_parallel_loopback = ( (fnl_sup_mode == "engineering_mode" ) && (fnl_ctrl_plane_bonding_consumption == "individual") ) ? ("(dis_plpbk,en_plpbk)")
+ : (fnl_test_mode == "bist") ? ("en_plpbk") : "dis_plpbk";
+ localparam rbc_any_tx_rx_parallel_loopback = ( (fnl_sup_mode == "engineering_mode" ) && (fnl_ctrl_plane_bonding_consumption == "individual") ) ? ("dis_plpbk")
+ : (fnl_test_mode == "bist") ? ("en_plpbk") : "dis_plpbk";
+ localparam fnl_tx_rx_parallel_loopback = (tx_rx_parallel_loopback == "" || tx_rx_parallel_loopback == "") ? rbc_any_tx_rx_parallel_loopback : tx_rx_parallel_loopback;
+
+ // prbs_ver_clr_flag, RBC-validated
+ localparam rbc_all_prbs_ver_clr_flag = ( fnl_test_mode == "prbs") ? ("(dis_prbs_clr_flag,en_prbs_clr_flag)") : "dis_prbs_clr_flag";
+ localparam rbc_any_prbs_ver_clr_flag = ( fnl_test_mode == "prbs") ? ("dis_prbs_clr_flag") : "dis_prbs_clr_flag";
+ localparam fnl_prbs_ver_clr_flag = (prbs_ver_clr_flag == "" || prbs_ver_clr_flag == "") ? rbc_any_prbs_ver_clr_flag : prbs_ver_clr_flag;
+
+ // cid_pattern, RBC-validated
+ localparam rbc_all_cid_pattern = (fnl_prbs_ver == "prbs_8" ) ? ("(cid_pattern_0,cid_pattern_1)") : "cid_pattern_0";
+ localparam rbc_any_cid_pattern = (fnl_prbs_ver == "prbs_8" ) ? ("cid_pattern_0") : "cid_pattern_0";
+ localparam fnl_cid_pattern = (cid_pattern == "" || cid_pattern == "") ? rbc_any_cid_pattern : cid_pattern;
+
+ // bist_ver, RBC-validated
+ localparam rbc_all_bist_ver = ( (fnl_test_mode == "bist") && (fnl_sup_mode == "user_mode") ) ? ("incremental")
+ : ( (fnl_test_mode == "bist") && (fnl_sup_mode == "engineering_mode") ) ? ("(cjpat,crpat)") : "dis_bist";
+ localparam rbc_any_bist_ver = ( (fnl_test_mode == "bist") && (fnl_sup_mode == "user_mode") ) ? ("incremental")
+ : ( (fnl_test_mode == "bist") && (fnl_sup_mode == "engineering_mode") ) ? ("cjpat") : "dis_bist";
+ localparam fnl_bist_ver = (bist_ver == "" || bist_ver == "") ? rbc_any_bist_ver : bist_ver;
+
+ // bist_ver_clr_flag, RBC-validated
+ localparam rbc_all_bist_ver_clr_flag = ( fnl_test_mode == "bist") ? ("(dis_bist_clr_flag,en_bist_clr_flag)") : "dis_bist_clr_flag";
+ localparam rbc_any_bist_ver_clr_flag = ( fnl_test_mode == "bist") ? ("dis_bist_clr_flag") : "dis_bist_clr_flag";
+ localparam fnl_bist_ver_clr_flag = (bist_ver_clr_flag == "" || bist_ver_clr_flag == "") ? rbc_any_bist_ver_clr_flag : bist_ver_clr_flag;
+
+ // cdr_ctrl, RBC-validated
+ localparam rbc_all_cdr_ctrl = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2" ) ) ? ("(dis_cdr_ctrl,en_cdr_ctrl,en_cdr_ctrl_w_cid)") : "dis_cdr_ctrl";
+ localparam rbc_any_cdr_ctrl = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2" ) ) ? ("dis_cdr_ctrl") : "dis_cdr_ctrl";
+ localparam fnl_cdr_ctrl = (cdr_ctrl == "" || cdr_ctrl == "") ? rbc_any_cdr_ctrl : cdr_ctrl;
+
+ // cdr_ctrl_rxvalid_mask, RBC-validated
+ localparam rbc_all_cdr_ctrl_rxvalid_mask = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2" ) ) ? ("(dis_rxvalid_mask,en_rxvalid_mask)") : "dis_rxvalid_mask";
+ localparam rbc_any_cdr_ctrl_rxvalid_mask = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2" ) ) ? ("dis_rxvalid_mask") : "dis_rxvalid_mask";
+ localparam fnl_cdr_ctrl_rxvalid_mask = (cdr_ctrl_rxvalid_mask == "" || cdr_ctrl_rxvalid_mask == "") ? rbc_any_cdr_ctrl_rxvalid_mask : cdr_ctrl_rxvalid_mask;
+
+ // auto_speed_nego, RBC-validated
+ localparam rbc_all_auto_speed_nego = ( (fnl_prot_mode == "pipe_g2" ) && ( (fnl_ctrl_plane_bonding_consumption == "individual") || (fnl_ctrl_plane_bonding_consumption == "bundled_master")) ) ? ("en_asn_g2_freq_scal") : "dis_asn";
+ localparam rbc_any_auto_speed_nego = ( (fnl_prot_mode == "pipe_g2" ) && ( (fnl_ctrl_plane_bonding_consumption == "individual") || (fnl_ctrl_plane_bonding_consumption == "bundled_master")) ) ? ("en_asn_g2_freq_scal") : "dis_asn";
+ localparam fnl_auto_speed_nego = (auto_speed_nego == "" || auto_speed_nego == "") ? rbc_any_auto_speed_nego : auto_speed_nego;
+
+ // eidle_entry_iei, RBC-validated
+ localparam rbc_all_eidle_entry_iei = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("(dis_eidle_iei,en_eidle_iei)") : "dis_eidle_iei";
+ localparam rbc_any_eidle_entry_iei = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("dis_eidle_iei") : "dis_eidle_iei";
+ localparam fnl_eidle_entry_iei = (eidle_entry_iei == "" || eidle_entry_iei == "") ? rbc_any_eidle_entry_iei : eidle_entry_iei;
+
+ // eidle_entry_sd, RBC-validated
+ localparam rbc_all_eidle_entry_sd = ( fnl_eidle_entry_iei == "en_eidle_iei") ? ("(dis_eidle_sd,en_eidle_sd)") : "dis_eidle_sd";
+ localparam rbc_any_eidle_entry_sd = ( fnl_eidle_entry_iei == "en_eidle_iei") ? ("dis_eidle_sd") : "dis_eidle_sd";
+ localparam fnl_eidle_entry_sd = (eidle_entry_sd == "" || eidle_entry_sd == "") ? rbc_any_eidle_entry_sd : eidle_entry_sd;
+
+ // eidle_entry_eios, RBC-validated
+ localparam rbc_all_eidle_entry_eios = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("(dis_eidle_eios,en_eidle_eios)") : "dis_eidle_eios";
+ localparam rbc_any_eidle_entry_eios = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("dis_eidle_eios") : "dis_eidle_eios";
+ localparam fnl_eidle_entry_eios = (eidle_entry_eios == "" || eidle_entry_eios == "") ? rbc_any_eidle_entry_eios : eidle_entry_eios;
+
+ // ctrl_plane_bonding_distribution, RBC-validated
+ localparam rbc_all_ctrl_plane_bonding_distribution = ( fnl_ctrl_plane_bonding_consumption == "bundled_master") ? ("master_chnl_distr") : "not_master_chnl_distr";
+ localparam rbc_any_ctrl_plane_bonding_distribution = ( fnl_ctrl_plane_bonding_consumption == "bundled_master") ? ("master_chnl_distr") : "not_master_chnl_distr";
+ localparam fnl_ctrl_plane_bonding_distribution = (ctrl_plane_bonding_distribution == "" || ctrl_plane_bonding_distribution == "") ? rbc_any_ctrl_plane_bonding_distribution : ctrl_plane_bonding_distribution;
+
+ // ctrl_plane_bonding_compensation, RBC-validated
+ localparam rbc_all_ctrl_plane_bonding_compensation = "dis_compensation";
+ localparam rbc_any_ctrl_plane_bonding_compensation = "dis_compensation";
+ localparam fnl_ctrl_plane_bonding_compensation = (ctrl_plane_bonding_compensation == "" || ctrl_plane_bonding_compensation == "") ? rbc_any_ctrl_plane_bonding_compensation : ctrl_plane_bonding_compensation;
+
+ // bypass_pipeline_reg, RBC-validated
+ localparam rbc_all_bypass_pipeline_reg = "dis_bypass_pipeline";
+ localparam rbc_any_bypass_pipeline_reg = "dis_bypass_pipeline";
+ localparam fnl_bypass_pipeline_reg = (bypass_pipeline_reg == "" || bypass_pipeline_reg == "") ? rbc_any_bypass_pipeline_reg : bypass_pipeline_reg;
+
+ // rx_refclk, RBC-validated
+ localparam rbc_all_rx_refclk = (fnl_sup_mode == "engineering_mode") ? ("(dis_refclk_sel,en_refclk_sel)") : "dis_refclk_sel";
+ localparam rbc_any_rx_refclk = (fnl_sup_mode == "engineering_mode") ? ("dis_refclk_sel") : "dis_refclk_sel";
+ localparam fnl_rx_refclk = (rx_refclk == "" || rx_refclk == "") ? rbc_any_rx_refclk : rx_refclk;
+
+ // rx_rcvd_clk, RBC-validated
+ localparam rbc_all_rx_rcvd_clk = (fnl_tx_rx_parallel_loopback == "en_plpbk") ? ("tx_pma_clock_rcvd_clk") : "rcvd_clk_rcvd_clk";
+ localparam rbc_any_rx_rcvd_clk = (fnl_tx_rx_parallel_loopback == "en_plpbk") ? ("tx_pma_clock_rcvd_clk") : "rcvd_clk_rcvd_clk";
+ localparam fnl_rx_rcvd_clk = (rx_rcvd_clk == "" || rx_rcvd_clk == "") ? rbc_any_rx_rcvd_clk : rx_rcvd_clk;
+
+ // agg_block_sel, RBC-validated
+ localparam rbc_all_agg_block_sel = ( (fnl_prot_mode == "xaui") || ( (fnl_prot_mode == "srio_2p1") && (fnl_ctrl_plane_bonding_consumption != "individual") ) ) ? ("(same_smrt_pack,other_smrt_pack)") : "same_smrt_pack";
+ localparam rbc_any_agg_block_sel = ( (fnl_prot_mode == "xaui") || ( (fnl_prot_mode == "srio_2p1") && (fnl_ctrl_plane_bonding_consumption != "individual") ) ) ? ("same_smrt_pack") : "same_smrt_pack";
+ localparam fnl_agg_block_sel = (agg_block_sel == "" || agg_block_sel == "") ? rbc_any_agg_block_sel : agg_block_sel;
+
+ // rx_clk1, RBC-validated
+ localparam rbc_all_rx_clk1 = (fnl_tx_rx_parallel_loopback == "en_plpbk") ? ("tx_pma_clock_clk1")
+ : (fnl_deskew == "dis_deskew") ? ("rcvd_clk_clk1")
+ : (fnl_agg_block_sel == "same_smrt_pack") ? ("rcvd_clk_agg_clk1") : "rcvd_clk_agg_top_or_bottom_clk1";
+ localparam rbc_any_rx_clk1 = (fnl_tx_rx_parallel_loopback == "en_plpbk") ? ("tx_pma_clock_clk1")
+ : (fnl_deskew == "dis_deskew") ? ("rcvd_clk_clk1")
+ : (fnl_agg_block_sel == "same_smrt_pack") ? ("rcvd_clk_agg_clk1") : "rcvd_clk_agg_top_or_bottom_clk1";
+ localparam fnl_rx_clk1 = (rx_clk1 == "" || rx_clk1 == "") ? rbc_any_rx_clk1 : rx_clk1;
+
+ // rx_clk2, RBC-validated
+ localparam rbc_all_rx_clk2 = ( (fnl_sup_mode == "engineering_mode") && (fnl_rate_match == "dis_rm")) ? ("rcvd_clk_clk2")
+ : ( (fnl_sup_mode == "engineering_mode") && (fnl_rate_match != "dis_rm")) ? ("(tx_pma_clock_clk2,refclk_dig2_clk2)")
+ : ( (fnl_tx_rx_parallel_loopback == "en_plpbk") || (fnl_rate_match != "dis_rm") ) ? ("tx_pma_clock_clk2") : "rcvd_clk_clk2";
+ localparam rbc_any_rx_clk2 = ( (fnl_sup_mode == "engineering_mode") && (fnl_rate_match == "dis_rm")) ? ("rcvd_clk_clk2")
+ : ( (fnl_sup_mode == "engineering_mode") && (fnl_rate_match != "dis_rm")) ? ("tx_pma_clock_clk2")
+ : ( (fnl_tx_rx_parallel_loopback == "en_plpbk") || (fnl_rate_match != "dis_rm") ) ? ("tx_pma_clock_clk2") : "rcvd_clk_clk2";
+ localparam fnl_rx_clk2 = (rx_clk2 == "" || rx_clk2 == "") ? rbc_any_rx_clk2 : rx_clk2;
+
+ // rx_wr_clk, RBC-validated
+ localparam rbc_all_rx_wr_clk = ( fnl_hip_mode == "en_hip" ) ? ("txfifo_rd_clk") : "rx_clk2_div_1_2_4";
+ localparam rbc_any_rx_wr_clk = ( fnl_hip_mode == "en_hip" ) ? ("txfifo_rd_clk") : "rx_clk2_div_1_2_4";
+ localparam fnl_rx_wr_clk = (rx_wr_clk == "" || rx_wr_clk == "") ? rbc_any_rx_wr_clk : rx_wr_clk;
+
+ // rx_rd_clk, RBC-validated
+ localparam rbc_all_rx_rd_clk = ( fnl_phase_compensation_fifo == "register_fifo" || fnl_test_mode == "bist" ) ? ("rx_clk") : "pld_rx_clk";
+ localparam rbc_any_rx_rd_clk = ( fnl_phase_compensation_fifo == "register_fifo" || fnl_test_mode == "bist" ) ? ("rx_clk") : "pld_rx_clk";
+ localparam fnl_rx_rd_clk = (rx_rd_clk == "" || rx_rd_clk == "") ? rbc_any_rx_rd_clk : rx_rd_clk;
+
+ // clock_gate_bist, RBC-validated
+ localparam rbc_all_clock_gate_bist = (fnl_test_mode != "bist" ) ? ("en_bist_clk_gating") : "dis_bist_clk_gating";
+ localparam rbc_any_clock_gate_bist = (fnl_test_mode != "bist" ) ? ("en_bist_clk_gating") : "dis_bist_clk_gating";
+ localparam fnl_clock_gate_bist = (clock_gate_bist == "" || clock_gate_bist == "") ? rbc_any_clock_gate_bist : clock_gate_bist;
+
+ // clock_gate_sw_wa, RBC-validated
+ localparam rbc_all_clock_gate_sw_wa = (fnl_prot_mode == "disabled_prot_mode" ) ? ("en_sw_wa_clk_gating") : "dis_sw_wa_clk_gating";
+ localparam rbc_any_clock_gate_sw_wa = (fnl_prot_mode == "disabled_prot_mode" ) ? ("en_sw_wa_clk_gating") : "dis_sw_wa_clk_gating";
+ localparam fnl_clock_gate_sw_wa = (clock_gate_sw_wa == "" || clock_gate_sw_wa == "") ? rbc_any_clock_gate_sw_wa : clock_gate_sw_wa;
+
+ // clock_gate_dw_wa, RBC-validated
+ localparam rbc_all_clock_gate_dw_wa = ((fnl_pma_dw == "eight_bit") || (fnl_pma_dw == "ten_bit")) ? ("en_dw_wa_clk_gating") : "dis_dw_wa_clk_gating";
+ localparam rbc_any_clock_gate_dw_wa = ((fnl_pma_dw == "eight_bit") || (fnl_pma_dw == "ten_bit")) ? ("en_dw_wa_clk_gating") : "dis_dw_wa_clk_gating";
+ localparam fnl_clock_gate_dw_wa = (clock_gate_dw_wa == "" || clock_gate_dw_wa == "") ? rbc_any_clock_gate_dw_wa : clock_gate_dw_wa;
+
+ // clock_gate_sw_dskw_wr, RBC-validated
+ localparam rbc_all_clock_gate_sw_dskw_wr = (fnl_deskew == "dis_deskew" ) ? ("en_sw_dskw_wrclk_gating") : "dis_sw_dskw_wrclk_gating";
+ localparam rbc_any_clock_gate_sw_dskw_wr = (fnl_deskew == "dis_deskew" ) ? ("en_sw_dskw_wrclk_gating") : "dis_sw_dskw_wrclk_gating";
+ localparam fnl_clock_gate_sw_dskw_wr = (clock_gate_sw_dskw_wr == "" || clock_gate_sw_dskw_wr == "") ? rbc_any_clock_gate_sw_dskw_wr : clock_gate_sw_dskw_wr;
+
+ // clock_gate_dw_dskw_wr, RBC-validated
+ localparam rbc_all_clock_gate_dw_dskw_wr = (fnl_deskew != "en_srio_v2p1") ? ("en_dw_dskw_wrclk_gating") : "dis_dw_dskw_wrclk_gating";
+ localparam rbc_any_clock_gate_dw_dskw_wr = (fnl_deskew != "en_srio_v2p1") ? ("en_dw_dskw_wrclk_gating") : "dis_dw_dskw_wrclk_gating";
+ localparam fnl_clock_gate_dw_dskw_wr = (clock_gate_dw_dskw_wr == "" || clock_gate_dw_dskw_wr == "") ? rbc_any_clock_gate_dw_dskw_wr : clock_gate_dw_dskw_wr;
+
+ // clock_gate_prbs, RBC-validated
+ localparam rbc_all_clock_gate_prbs = (fnl_test_mode != "prbs" ) ? ("en_prbs_clk_gating") : "dis_prbs_clk_gating";
+ localparam rbc_any_clock_gate_prbs = (fnl_test_mode != "prbs" ) ? ("en_prbs_clk_gating") : "dis_prbs_clk_gating";
+ localparam fnl_clock_gate_prbs = (clock_gate_prbs == "" || clock_gate_prbs == "") ? rbc_any_clock_gate_prbs : clock_gate_prbs;
+
+ // clock_gate_cdr_eidle, RBC-validated
+ localparam rbc_all_clock_gate_cdr_eidle = ((fnl_prot_mode != "pipe_g1" ) && (fnl_prot_mode != "pipe_g2")) ? ("en_cdr_eidle_clk_gating") : "dis_cdr_eidle_clk_gating";
+ localparam rbc_any_clock_gate_cdr_eidle = ((fnl_prot_mode != "pipe_g1" ) && (fnl_prot_mode != "pipe_g2")) ? ("en_cdr_eidle_clk_gating") : "dis_cdr_eidle_clk_gating";
+ localparam fnl_clock_gate_cdr_eidle = (clock_gate_cdr_eidle == "" || clock_gate_cdr_eidle == "") ? rbc_any_clock_gate_cdr_eidle : clock_gate_cdr_eidle;
+
+ // clock_gate_dskw_rd, RBC-validated
+ localparam rbc_all_clock_gate_dskw_rd = (fnl_deskew == "dis_deskew") ? ("en_dskw_rdclk_gating") : "dis_dskw_rdclk_gating";
+ localparam rbc_any_clock_gate_dskw_rd = (fnl_deskew == "dis_deskew") ? ("en_dskw_rdclk_gating") : "dis_dskw_rdclk_gating";
+ localparam fnl_clock_gate_dskw_rd = (clock_gate_dskw_rd == "" || clock_gate_dskw_rd == "") ? rbc_any_clock_gate_dskw_rd : clock_gate_dskw_rd;
+
+ // clock_gate_sw_rm_wr, RBC-validated
+ localparam rbc_all_clock_gate_sw_rm_wr = (fnl_rate_match == "dis_rm" ) ? ("en_sw_rm_wrclk_gating") : "dis_sw_rm_wrclk_gating";
+ localparam rbc_any_clock_gate_sw_rm_wr = (fnl_rate_match == "dis_rm" ) ? ("en_sw_rm_wrclk_gating") : "dis_sw_rm_wrclk_gating";
+ localparam fnl_clock_gate_sw_rm_wr = (clock_gate_sw_rm_wr == "" || clock_gate_sw_rm_wr == "") ? rbc_any_clock_gate_sw_rm_wr : clock_gate_sw_rm_wr;
+
+ // clock_gate_sw_rm_rd, RBC-validated
+ localparam rbc_all_clock_gate_sw_rm_rd = (fnl_rate_match == "dis_rm" ) ? ("en_sw_rm_rdclk_gating") : "dis_sw_rm_rdclk_gating";
+ localparam rbc_any_clock_gate_sw_rm_rd = (fnl_rate_match == "dis_rm" ) ? ("en_sw_rm_rdclk_gating") : "dis_sw_rm_rdclk_gating";
+ localparam fnl_clock_gate_sw_rm_rd = (clock_gate_sw_rm_rd == "" || clock_gate_sw_rm_rd == "") ? rbc_any_clock_gate_sw_rm_rd : clock_gate_sw_rm_rd;
+
+ // clock_gate_dw_rm_rd, RBC-validated
+ localparam rbc_all_clock_gate_dw_rm_rd = ((fnl_rate_match != "dw_basic_rm") && (fnl_rate_match != "srio_v2p1_rm") && (fnl_rate_match != "srio_v2p1_rm_0ppm")) ? ("en_dw_rm_rdclk_gating") : "dis_dw_rm_rdclk_gating";
+ localparam rbc_any_clock_gate_dw_rm_rd = ((fnl_rate_match != "dw_basic_rm") && (fnl_rate_match != "srio_v2p1_rm") && (fnl_rate_match != "srio_v2p1_rm_0ppm")) ? ("en_dw_rm_rdclk_gating") : "dis_dw_rm_rdclk_gating";
+ localparam fnl_clock_gate_dw_rm_rd = (clock_gate_dw_rm_rd == "" || clock_gate_dw_rm_rd == "") ? rbc_any_clock_gate_dw_rm_rd : clock_gate_dw_rm_rd;
+
+ // clock_gate_dw_rm_wr, RBC-validated
+ localparam rbc_all_clock_gate_dw_rm_wr = ((fnl_rate_match != "dw_basic_rm") && (fnl_rate_match != "srio_v2p1_rm") && (fnl_rate_match != "srio_v2p1_rm_0ppm")) ? ("en_dw_rm_wrclk_gating") : "dis_dw_rm_wrclk_gating";
+ localparam rbc_any_clock_gate_dw_rm_wr = ((fnl_rate_match != "dw_basic_rm") && (fnl_rate_match != "srio_v2p1_rm") && (fnl_rate_match != "srio_v2p1_rm_0ppm")) ? ("en_dw_rm_wrclk_gating") : "dis_dw_rm_wrclk_gating";
+ localparam fnl_clock_gate_dw_rm_wr = (clock_gate_dw_rm_wr == "" || clock_gate_dw_rm_wr == "") ? rbc_any_clock_gate_dw_rm_wr : clock_gate_dw_rm_wr;
+
+ // clock_gate_bds_dec_asn, RBC-validated
+ localparam rbc_all_clock_gate_bds_dec_asn = (fnl_prot_mode == "disabled_prot_mode" ) ? ("en_bds_dec_asn_clk_gating") : "dis_bds_dec_asn_clk_gating";
+ localparam rbc_any_clock_gate_bds_dec_asn = (fnl_prot_mode == "disabled_prot_mode" ) ? ("en_bds_dec_asn_clk_gating") : "dis_bds_dec_asn_clk_gating";
+ localparam fnl_clock_gate_bds_dec_asn = (clock_gate_bds_dec_asn == "" || clock_gate_bds_dec_asn == "") ? rbc_any_clock_gate_bds_dec_asn : clock_gate_bds_dec_asn;
+
+ // clock_gate_byteorder, RBC-validated
+ localparam rbc_all_clock_gate_byteorder = ( (fnl_prot_mode == "disabled_prot_mode" ) || (fnl_pcs_bypass == "en_pcs_bypass") ) ? ("en_byteorder_clk_gating") : "dis_byteorder_clk_gating";
+ localparam rbc_any_clock_gate_byteorder = ( (fnl_prot_mode == "disabled_prot_mode" ) || (fnl_pcs_bypass == "en_pcs_bypass") ) ? ("en_byteorder_clk_gating") : "dis_byteorder_clk_gating";
+ localparam fnl_clock_gate_byteorder = (clock_gate_byteorder == "" || clock_gate_byteorder == "") ? rbc_any_clock_gate_byteorder : clock_gate_byteorder;
+
+ // clock_gate_sw_pc_wrclk, RBC-validated
+ localparam rbc_all_clock_gate_sw_pc_wrclk = (fnl_prot_mode == "disabled_prot_mode") ? ("en_sw_pc_wrclk_gating") : "dis_sw_pc_wrclk_gating";
+ localparam rbc_any_clock_gate_sw_pc_wrclk = (fnl_prot_mode == "disabled_prot_mode") ? ("en_sw_pc_wrclk_gating") : "dis_sw_pc_wrclk_gating";
+ localparam fnl_clock_gate_sw_pc_wrclk = (clock_gate_sw_pc_wrclk == "" || clock_gate_sw_pc_wrclk == "") ? rbc_any_clock_gate_sw_pc_wrclk : clock_gate_sw_pc_wrclk;
+
+ // clock_gate_dw_pc_wrclk, RBC-validated
+ localparam rbc_all_clock_gate_dw_pc_wrclk = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_phase_compensation_fifo == "register_fifo") || (fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "eight_bit") ) ? ("en_dw_pc_wrclk_gating") : "dis_dw_pc_wrclk_gating";
+ localparam rbc_any_clock_gate_dw_pc_wrclk = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_phase_compensation_fifo == "register_fifo") || (fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "eight_bit") ) ? ("en_dw_pc_wrclk_gating") : "dis_dw_pc_wrclk_gating";
+ localparam fnl_clock_gate_dw_pc_wrclk = (clock_gate_dw_pc_wrclk == "" || clock_gate_dw_pc_wrclk == "") ? rbc_any_clock_gate_dw_pc_wrclk : clock_gate_dw_pc_wrclk;
+
+ // clock_gate_pc_rdclk, RBC-validated
+ localparam rbc_all_clock_gate_pc_rdclk = (fnl_prot_mode == "disabled_prot_mode") ? ("en_pc_rdclk_gating") : "dis_pc_rdclk_gating";
+ localparam rbc_any_clock_gate_pc_rdclk = (fnl_prot_mode == "disabled_prot_mode") ? ("en_pc_rdclk_gating") : "dis_pc_rdclk_gating";
+ localparam fnl_clock_gate_pc_rdclk = (clock_gate_pc_rdclk == "" || clock_gate_pc_rdclk == "") ? rbc_any_clock_gate_pc_rdclk : clock_gate_pc_rdclk;
+
+ // rx_pcs_urst, RBC-validated
+ localparam rbc_all_rx_pcs_urst = "en_rx_pcs_urst";
+ localparam rbc_any_rx_pcs_urst = "en_rx_pcs_urst";
+ localparam fnl_rx_pcs_urst = (rx_pcs_urst == "" || rx_pcs_urst == "") ? rbc_any_rx_pcs_urst : rx_pcs_urst;
+
+ // rx_clk_free_running, RBC-validated
+ localparam rbc_all_rx_clk_free_running = "en_rx_clk_free_run";
+ localparam rbc_any_rx_clk_free_running = "en_rx_clk_free_run";
+ localparam fnl_rx_clk_free_running = (rx_clk_free_running == "