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 == "" || rx_clk_free_running == "") ? rbc_any_rx_clk_free_running : rx_clk_free_running; + + // comp_fifo_rst_pld_ctrl, RBC-validated + localparam rbc_all_comp_fifo_rst_pld_ctrl = "dis_comp_fifo_rst_pld_ctrl"; + localparam rbc_any_comp_fifo_rst_pld_ctrl = "dis_comp_fifo_rst_pld_ctrl"; + localparam fnl_comp_fifo_rst_pld_ctrl = (comp_fifo_rst_pld_ctrl == "" || comp_fifo_rst_pld_ctrl == "") ? rbc_any_comp_fifo_rst_pld_ctrl : comp_fifo_rst_pld_ctrl; + + // pc_fifo_rst_pld_ctrl, RBC-validated + localparam rbc_all_pc_fifo_rst_pld_ctrl = "dis_pc_fifo_rst_pld_ctrl"; + localparam rbc_any_pc_fifo_rst_pld_ctrl = "dis_pc_fifo_rst_pld_ctrl"; + localparam fnl_pc_fifo_rst_pld_ctrl = (pc_fifo_rst_pld_ctrl == "" || pc_fifo_rst_pld_ctrl == "") ? rbc_any_pc_fifo_rst_pld_ctrl : pc_fifo_rst_pld_ctrl; + + // test_bus_sel, RBC-validated + localparam rbc_all_test_bus_sel = (fnl_sup_mode == "user_mode") ? ("tx_testbus") : "(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)"; + localparam rbc_any_test_bus_sel = (fnl_sup_mode == "user_mode") ? ("tx_testbus") : "prbs_bist_testbus"; + localparam fnl_test_bus_sel = (test_bus_sel == "" || test_bus_sel == "") ? rbc_any_test_bus_sel : test_bus_sel; + + // Validate input parameters against known values or RBC values + initial begin + //$display("prot_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", prot_mode, rbc_any_prot_mode, rbc_all_prot_mode, fnl_prot_mode); + if (!is_in_legal_set(prot_mode, rbc_all_prot_mode)) begin + $display("Critical Warning: parameter 'prot_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prot_mode, rbc_all_prot_mode, fnl_prot_mode); + end + //$display("sup_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", sup_mode, rbc_any_sup_mode, rbc_all_sup_mode, fnl_sup_mode); + if (!is_in_legal_set(sup_mode, rbc_all_sup_mode)) begin + $display("Critical Warning: parameter 'sup_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", sup_mode, rbc_all_sup_mode, fnl_sup_mode); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + //$display("test_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", test_mode, rbc_any_test_mode, rbc_all_test_mode, fnl_test_mode); + if (!is_in_legal_set(test_mode, rbc_all_test_mode)) begin + $display("Critical Warning: parameter 'test_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", test_mode, rbc_all_test_mode, fnl_test_mode); + end + //$display("hip_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", hip_mode, rbc_any_hip_mode, rbc_all_hip_mode, fnl_hip_mode); + if (!is_in_legal_set(hip_mode, rbc_all_hip_mode)) begin + $display("Critical Warning: parameter 'hip_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", hip_mode, rbc_all_hip_mode, fnl_hip_mode); + end + //$display("pcs_bypass = orig: '%s', any:'%s', all:'%s', final: '%s'", pcs_bypass, rbc_any_pcs_bypass, rbc_all_pcs_bypass, fnl_pcs_bypass); + if (!is_in_legal_set(pcs_bypass, rbc_all_pcs_bypass)) begin + $display("Critical Warning: parameter 'pcs_bypass' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pcs_bypass, rbc_all_pcs_bypass, fnl_pcs_bypass); + end + //$display("pma_dw = orig: '%s', any:'%s', all:'%s', final: '%s'", pma_dw, rbc_any_pma_dw, rbc_all_pma_dw, fnl_pma_dw); + if (!is_in_legal_set(pma_dw, rbc_all_pma_dw)) begin + $display("Critical Warning: parameter 'pma_dw' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pma_dw, rbc_all_pma_dw, fnl_pma_dw); + end + //$display("pipe_if_enable = orig: '%s', any:'%s', all:'%s', final: '%s'", pipe_if_enable, rbc_any_pipe_if_enable, rbc_all_pipe_if_enable, fnl_pipe_if_enable); + if (!is_in_legal_set(pipe_if_enable, rbc_all_pipe_if_enable)) begin + $display("Critical Warning: parameter 'pipe_if_enable' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pipe_if_enable, rbc_all_pipe_if_enable, fnl_pipe_if_enable); + end + //$display("prbs_ver = orig: '%s', any:'%s', all:'%s', final: '%s'", prbs_ver, rbc_any_prbs_ver, rbc_all_prbs_ver, fnl_prbs_ver); + if (!is_in_legal_set(prbs_ver, rbc_all_prbs_ver)) begin + $display("Critical Warning: parameter 'prbs_ver' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prbs_ver, rbc_all_prbs_ver, fnl_prbs_ver); + end + //$display("wa_boundary_lock_ctrl = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_boundary_lock_ctrl, rbc_any_wa_boundary_lock_ctrl, rbc_all_wa_boundary_lock_ctrl, fnl_wa_boundary_lock_ctrl); + if (!is_in_legal_set(wa_boundary_lock_ctrl, rbc_all_wa_boundary_lock_ctrl)) begin + $display("Critical Warning: parameter 'wa_boundary_lock_ctrl' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_boundary_lock_ctrl, rbc_all_wa_boundary_lock_ctrl, fnl_wa_boundary_lock_ctrl); + end + //$display("wa_pld_controlled = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_pld_controlled, rbc_any_wa_pld_controlled, rbc_all_wa_pld_controlled, fnl_wa_pld_controlled); + if (!is_in_legal_set(wa_pld_controlled, rbc_all_wa_pld_controlled)) begin + $display("Critical Warning: parameter 'wa_pld_controlled' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_pld_controlled, rbc_all_wa_pld_controlled, fnl_wa_pld_controlled); + end + //$display("wa_pd_polarity = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_pd_polarity, rbc_any_wa_pd_polarity, rbc_all_wa_pd_polarity, fnl_wa_pd_polarity); + if (!is_in_legal_set(wa_pd_polarity, rbc_all_wa_pd_polarity)) begin + $display("Critical Warning: parameter 'wa_pd_polarity' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_pd_polarity, rbc_all_wa_pd_polarity, fnl_wa_pd_polarity); + end + //$display("wa_pd = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_pd, rbc_any_wa_pd, rbc_all_wa_pd, fnl_wa_pd); + if (!is_in_legal_set(wa_pd, rbc_all_wa_pd)) begin + $display("Critical Warning: parameter 'wa_pd' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_pd, rbc_all_wa_pd, fnl_wa_pd); + end + //$display("wa_sync_sm_ctrl = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_sync_sm_ctrl, rbc_any_wa_sync_sm_ctrl, rbc_all_wa_sync_sm_ctrl, fnl_wa_sync_sm_ctrl); + if (!is_in_legal_set(wa_sync_sm_ctrl, rbc_all_wa_sync_sm_ctrl)) begin + $display("Critical Warning: parameter 'wa_sync_sm_ctrl' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_sync_sm_ctrl, rbc_all_wa_sync_sm_ctrl, fnl_wa_sync_sm_ctrl); + end + //$display("wa_kchar = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_kchar, rbc_any_wa_kchar, rbc_all_wa_kchar, fnl_wa_kchar); + if (!is_in_legal_set(wa_kchar, rbc_all_wa_kchar)) begin + $display("Critical Warning: parameter 'wa_kchar' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_kchar, rbc_all_wa_kchar, fnl_wa_kchar); + end + //$display("fixed_pat_det = orig: '%s', any:'%s', all:'%s', final: '%s'", fixed_pat_det, rbc_any_fixed_pat_det, rbc_all_fixed_pat_det, fnl_fixed_pat_det); + if (!is_in_legal_set(fixed_pat_det, rbc_all_fixed_pat_det)) begin + $display("Critical Warning: parameter 'fixed_pat_det' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", fixed_pat_det, rbc_all_fixed_pat_det, fnl_fixed_pat_det); + end + //$display("ibm_invalid_code = orig: '%s', any:'%s', all:'%s', final: '%s'", ibm_invalid_code, rbc_any_ibm_invalid_code, rbc_all_ibm_invalid_code, fnl_ibm_invalid_code); + if (!is_in_legal_set(ibm_invalid_code, rbc_all_ibm_invalid_code)) begin + $display("Critical Warning: parameter 'ibm_invalid_code' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ibm_invalid_code, rbc_all_ibm_invalid_code, fnl_ibm_invalid_code); + end + //$display("force_signal_detect = orig: '%s', any:'%s', all:'%s', final: '%s'", force_signal_detect, rbc_any_force_signal_detect, rbc_all_force_signal_detect, fnl_force_signal_detect); + if (!is_in_legal_set(force_signal_detect, rbc_all_force_signal_detect)) begin + $display("Critical Warning: parameter 'force_signal_detect' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", force_signal_detect, rbc_all_force_signal_detect, fnl_force_signal_detect); + end + //$display("wa_det_latency_sync_status_beh = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_det_latency_sync_status_beh, rbc_any_wa_det_latency_sync_status_beh, rbc_all_wa_det_latency_sync_status_beh, fnl_wa_det_latency_sync_status_beh); + if (!is_in_legal_set(wa_det_latency_sync_status_beh, rbc_all_wa_det_latency_sync_status_beh)) begin + $display("Critical Warning: parameter 'wa_det_latency_sync_status_beh' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_det_latency_sync_status_beh, rbc_all_wa_det_latency_sync_status_beh, fnl_wa_det_latency_sync_status_beh); + end + //$display("wa_clk_slip_spacing = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_clk_slip_spacing, rbc_any_wa_clk_slip_spacing, rbc_all_wa_clk_slip_spacing, fnl_wa_clk_slip_spacing); + if (!is_in_legal_set(wa_clk_slip_spacing, rbc_all_wa_clk_slip_spacing)) begin + $display("Critical Warning: parameter 'wa_clk_slip_spacing' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_clk_slip_spacing, rbc_all_wa_clk_slip_spacing, fnl_wa_clk_slip_spacing); + end + //$display("eightb_tenb_decoder = orig: '%s', any:'%s', all:'%s', final: '%s'", eightb_tenb_decoder, rbc_any_eightb_tenb_decoder, rbc_all_eightb_tenb_decoder, fnl_eightb_tenb_decoder); + if (!is_in_legal_set(eightb_tenb_decoder, rbc_all_eightb_tenb_decoder)) begin + $display("Critical Warning: parameter 'eightb_tenb_decoder' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", eightb_tenb_decoder, rbc_all_eightb_tenb_decoder, fnl_eightb_tenb_decoder); + end + //$display("wa_disp_err_flag = orig: '%s', any:'%s', all:'%s', final: '%s'", wa_disp_err_flag, rbc_any_wa_disp_err_flag, rbc_all_wa_disp_err_flag, fnl_wa_disp_err_flag); + if (!is_in_legal_set(wa_disp_err_flag, rbc_all_wa_disp_err_flag)) begin + $display("Critical Warning: parameter 'wa_disp_err_flag' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", wa_disp_err_flag, rbc_all_wa_disp_err_flag, fnl_wa_disp_err_flag); + end + //$display("polarity_inversion = orig: '%s', any:'%s', all:'%s', final: '%s'", polarity_inversion, rbc_any_polarity_inversion, rbc_all_polarity_inversion, fnl_polarity_inversion); + if (!is_in_legal_set(polarity_inversion, rbc_all_polarity_inversion)) begin + $display("Critical Warning: parameter 'polarity_inversion' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", polarity_inversion, rbc_all_polarity_inversion, fnl_polarity_inversion); + end + //$display("bit_reversal = orig: '%s', any:'%s', all:'%s', final: '%s'", bit_reversal, rbc_any_bit_reversal, rbc_all_bit_reversal, fnl_bit_reversal); + if (!is_in_legal_set(bit_reversal, rbc_all_bit_reversal)) begin + $display("Critical Warning: parameter 'bit_reversal' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", bit_reversal, rbc_all_bit_reversal, fnl_bit_reversal); + end + //$display("symbol_swap = orig: '%s', any:'%s', all:'%s', final: '%s'", symbol_swap, rbc_any_symbol_swap, rbc_all_symbol_swap, fnl_symbol_swap); + if (!is_in_legal_set(symbol_swap, rbc_all_symbol_swap)) begin + $display("Critical Warning: parameter 'symbol_swap' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", symbol_swap, rbc_all_symbol_swap, fnl_symbol_swap); + end + //$display("runlength_check = orig: '%s', any:'%s', all:'%s', final: '%s'", runlength_check, rbc_any_runlength_check, rbc_all_runlength_check, fnl_runlength_check); + if (!is_in_legal_set(runlength_check, rbc_all_runlength_check)) begin + $display("Critical Warning: parameter 'runlength_check' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", runlength_check, rbc_all_runlength_check, fnl_runlength_check); + end + //$display("ctrl_plane_bonding_consumption = orig: '%s', any:'%s', all:'%s', final: '%s'", ctrl_plane_bonding_consumption, rbc_any_ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption, fnl_ctrl_plane_bonding_consumption); + if (!is_in_legal_set(ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption)) begin + $display("Critical Warning: parameter 'ctrl_plane_bonding_consumption' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption, fnl_ctrl_plane_bonding_consumption); + end + //$display("deskew = orig: '%s', any:'%s', all:'%s', final: '%s'", deskew, rbc_any_deskew, rbc_all_deskew, fnl_deskew); + if (!is_in_legal_set(deskew, rbc_all_deskew)) begin + $display("Critical Warning: parameter 'deskew' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", deskew, rbc_all_deskew, fnl_deskew); + end + //$display("deskew_prog_pattern_only = orig: '%s', any:'%s', all:'%s', final: '%s'", deskew_prog_pattern_only, rbc_any_deskew_prog_pattern_only, rbc_all_deskew_prog_pattern_only, fnl_deskew_prog_pattern_only); + if (!is_in_legal_set(deskew_prog_pattern_only, rbc_all_deskew_prog_pattern_only)) begin + $display("Critical Warning: parameter 'deskew_prog_pattern_only' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", deskew_prog_pattern_only, rbc_all_deskew_prog_pattern_only, fnl_deskew_prog_pattern_only); + end + //$display("rate_match = orig: '%s', any:'%s', all:'%s', final: '%s'", rate_match, rbc_any_rate_match, rbc_all_rate_match, fnl_rate_match); + if (!is_in_legal_set(rate_match, rbc_all_rate_match)) begin + $display("Critical Warning: parameter 'rate_match' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rate_match, rbc_all_rate_match, fnl_rate_match); + end + //$display("err_flags_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", err_flags_sel, rbc_any_err_flags_sel, rbc_all_err_flags_sel, fnl_err_flags_sel); + if (!is_in_legal_set(err_flags_sel, rbc_all_err_flags_sel)) begin + $display("Critical Warning: parameter 'err_flags_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", err_flags_sel, rbc_all_err_flags_sel, fnl_err_flags_sel); + end + //$display("polinv_8b10b_dec = orig: '%s', any:'%s', all:'%s', final: '%s'", polinv_8b10b_dec, rbc_any_polinv_8b10b_dec, rbc_all_polinv_8b10b_dec, fnl_polinv_8b10b_dec); + if (!is_in_legal_set(polinv_8b10b_dec, rbc_all_polinv_8b10b_dec)) begin + $display("Critical Warning: parameter 'polinv_8b10b_dec' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", polinv_8b10b_dec, rbc_all_polinv_8b10b_dec, fnl_polinv_8b10b_dec); + end + //$display("eightbtenb_decoder_output_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", eightbtenb_decoder_output_sel, rbc_any_eightbtenb_decoder_output_sel, rbc_all_eightbtenb_decoder_output_sel, fnl_eightbtenb_decoder_output_sel); + if (!is_in_legal_set(eightbtenb_decoder_output_sel, rbc_all_eightbtenb_decoder_output_sel)) begin + $display("Critical Warning: parameter 'eightbtenb_decoder_output_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", eightbtenb_decoder_output_sel, rbc_all_eightbtenb_decoder_output_sel, fnl_eightbtenb_decoder_output_sel); + end + //$display("invalid_code_flag_only = orig: '%s', any:'%s', all:'%s', final: '%s'", invalid_code_flag_only, rbc_any_invalid_code_flag_only, rbc_all_invalid_code_flag_only, fnl_invalid_code_flag_only); + if (!is_in_legal_set(invalid_code_flag_only, rbc_all_invalid_code_flag_only)) begin + $display("Critical Warning: parameter 'invalid_code_flag_only' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", invalid_code_flag_only, rbc_all_invalid_code_flag_only, fnl_invalid_code_flag_only); + end + //$display("auto_error_replacement = orig: '%s', any:'%s', all:'%s', final: '%s'", auto_error_replacement, rbc_any_auto_error_replacement, rbc_all_auto_error_replacement, fnl_auto_error_replacement); + if (!is_in_legal_set(auto_error_replacement, rbc_all_auto_error_replacement)) begin + $display("Critical Warning: parameter 'auto_error_replacement' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", auto_error_replacement, rbc_all_auto_error_replacement, fnl_auto_error_replacement); + end + //$display("pad_or_edb_error_replace = orig: '%s', any:'%s', all:'%s', final: '%s'", pad_or_edb_error_replace, rbc_any_pad_or_edb_error_replace, rbc_all_pad_or_edb_error_replace, fnl_pad_or_edb_error_replace); + if (!is_in_legal_set(pad_or_edb_error_replace, rbc_all_pad_or_edb_error_replace)) begin + $display("Critical Warning: parameter 'pad_or_edb_error_replace' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pad_or_edb_error_replace, rbc_all_pad_or_edb_error_replace, fnl_pad_or_edb_error_replace); + end + //$display("byte_deserializer = orig: '%s', any:'%s', all:'%s', final: '%s'", byte_deserializer, rbc_any_byte_deserializer, rbc_all_byte_deserializer, fnl_byte_deserializer); + if (!is_in_legal_set(byte_deserializer, rbc_all_byte_deserializer)) begin + $display("Critical Warning: parameter 'byte_deserializer' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", byte_deserializer, rbc_all_byte_deserializer, fnl_byte_deserializer); + end + //$display("byte_order = orig: '%s', any:'%s', all:'%s', final: '%s'", byte_order, rbc_any_byte_order, rbc_all_byte_order, fnl_byte_order); + if (!is_in_legal_set(byte_order, rbc_all_byte_order)) begin + $display("Critical Warning: parameter 'byte_order' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", byte_order, rbc_all_byte_order, fnl_byte_order); + end + //$display("dw_one_or_two_symbol_bo = orig: '%s', any:'%s', all:'%s', final: '%s'", dw_one_or_two_symbol_bo, rbc_any_dw_one_or_two_symbol_bo, rbc_all_dw_one_or_two_symbol_bo, fnl_dw_one_or_two_symbol_bo); + if (!is_in_legal_set(dw_one_or_two_symbol_bo, rbc_all_dw_one_or_two_symbol_bo)) begin + $display("Critical Warning: parameter 'dw_one_or_two_symbol_bo' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", dw_one_or_two_symbol_bo, rbc_all_dw_one_or_two_symbol_bo, fnl_dw_one_or_two_symbol_bo); + end + //$display("re_bo_on_wa = orig: '%s', any:'%s', all:'%s', final: '%s'", re_bo_on_wa, rbc_any_re_bo_on_wa, rbc_all_re_bo_on_wa, fnl_re_bo_on_wa); + if (!is_in_legal_set(re_bo_on_wa, rbc_all_re_bo_on_wa)) begin + $display("Critical Warning: parameter 're_bo_on_wa' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", re_bo_on_wa, rbc_all_re_bo_on_wa, fnl_re_bo_on_wa); + end + //$display("phase_compensation_fifo = orig: '%s', any:'%s', all:'%s', final: '%s'", phase_compensation_fifo, rbc_any_phase_compensation_fifo, rbc_all_phase_compensation_fifo, fnl_phase_compensation_fifo); + if (!is_in_legal_set(phase_compensation_fifo, rbc_all_phase_compensation_fifo)) begin + $display("Critical Warning: parameter 'phase_compensation_fifo' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", phase_compensation_fifo, rbc_all_phase_compensation_fifo, fnl_phase_compensation_fifo); + end + //$display("tx_rx_parallel_loopback = orig: '%s', any:'%s', all:'%s', final: '%s'", tx_rx_parallel_loopback, rbc_any_tx_rx_parallel_loopback, rbc_all_tx_rx_parallel_loopback, fnl_tx_rx_parallel_loopback); + if (!is_in_legal_set(tx_rx_parallel_loopback, rbc_all_tx_rx_parallel_loopback)) begin + $display("Critical Warning: parameter 'tx_rx_parallel_loopback' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", tx_rx_parallel_loopback, rbc_all_tx_rx_parallel_loopback, fnl_tx_rx_parallel_loopback); + end + //$display("prbs_ver_clr_flag = orig: '%s', any:'%s', all:'%s', final: '%s'", prbs_ver_clr_flag, rbc_any_prbs_ver_clr_flag, rbc_all_prbs_ver_clr_flag, fnl_prbs_ver_clr_flag); + if (!is_in_legal_set(prbs_ver_clr_flag, rbc_all_prbs_ver_clr_flag)) begin + $display("Critical Warning: parameter 'prbs_ver_clr_flag' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prbs_ver_clr_flag, rbc_all_prbs_ver_clr_flag, fnl_prbs_ver_clr_flag); + end + //$display("cid_pattern = orig: '%s', any:'%s', all:'%s', final: '%s'", cid_pattern, rbc_any_cid_pattern, rbc_all_cid_pattern, fnl_cid_pattern); + if (!is_in_legal_set(cid_pattern, rbc_all_cid_pattern)) begin + $display("Critical Warning: parameter 'cid_pattern' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", cid_pattern, rbc_all_cid_pattern, fnl_cid_pattern); + end + //$display("bist_ver = orig: '%s', any:'%s', all:'%s', final: '%s'", bist_ver, rbc_any_bist_ver, rbc_all_bist_ver, fnl_bist_ver); + if (!is_in_legal_set(bist_ver, rbc_all_bist_ver)) begin + $display("Critical Warning: parameter 'bist_ver' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", bist_ver, rbc_all_bist_ver, fnl_bist_ver); + end + //$display("bist_ver_clr_flag = orig: '%s', any:'%s', all:'%s', final: '%s'", bist_ver_clr_flag, rbc_any_bist_ver_clr_flag, rbc_all_bist_ver_clr_flag, fnl_bist_ver_clr_flag); + if (!is_in_legal_set(bist_ver_clr_flag, rbc_all_bist_ver_clr_flag)) begin + $display("Critical Warning: parameter 'bist_ver_clr_flag' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", bist_ver_clr_flag, rbc_all_bist_ver_clr_flag, fnl_bist_ver_clr_flag); + end + //$display("cdr_ctrl = orig: '%s', any:'%s', all:'%s', final: '%s'", cdr_ctrl, rbc_any_cdr_ctrl, rbc_all_cdr_ctrl, fnl_cdr_ctrl); + if (!is_in_legal_set(cdr_ctrl, rbc_all_cdr_ctrl)) begin + $display("Critical Warning: parameter 'cdr_ctrl' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", cdr_ctrl, rbc_all_cdr_ctrl, fnl_cdr_ctrl); + end + //$display("cdr_ctrl_rxvalid_mask = orig: '%s', any:'%s', all:'%s', final: '%s'", cdr_ctrl_rxvalid_mask, rbc_any_cdr_ctrl_rxvalid_mask, rbc_all_cdr_ctrl_rxvalid_mask, fnl_cdr_ctrl_rxvalid_mask); + if (!is_in_legal_set(cdr_ctrl_rxvalid_mask, rbc_all_cdr_ctrl_rxvalid_mask)) begin + $display("Critical Warning: parameter 'cdr_ctrl_rxvalid_mask' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", cdr_ctrl_rxvalid_mask, rbc_all_cdr_ctrl_rxvalid_mask, fnl_cdr_ctrl_rxvalid_mask); + end + //$display("auto_speed_nego = orig: '%s', any:'%s', all:'%s', final: '%s'", auto_speed_nego, rbc_any_auto_speed_nego, rbc_all_auto_speed_nego, fnl_auto_speed_nego); + if (!is_in_legal_set(auto_speed_nego, rbc_all_auto_speed_nego)) begin + $display("Critical Warning: parameter 'auto_speed_nego' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", auto_speed_nego, rbc_all_auto_speed_nego, fnl_auto_speed_nego); + end + //$display("eidle_entry_iei = orig: '%s', any:'%s', all:'%s', final: '%s'", eidle_entry_iei, rbc_any_eidle_entry_iei, rbc_all_eidle_entry_iei, fnl_eidle_entry_iei); + if (!is_in_legal_set(eidle_entry_iei, rbc_all_eidle_entry_iei)) begin + $display("Critical Warning: parameter 'eidle_entry_iei' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", eidle_entry_iei, rbc_all_eidle_entry_iei, fnl_eidle_entry_iei); + end + //$display("eidle_entry_sd = orig: '%s', any:'%s', all:'%s', final: '%s'", eidle_entry_sd, rbc_any_eidle_entry_sd, rbc_all_eidle_entry_sd, fnl_eidle_entry_sd); + if (!is_in_legal_set(eidle_entry_sd, rbc_all_eidle_entry_sd)) begin + $display("Critical Warning: parameter 'eidle_entry_sd' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", eidle_entry_sd, rbc_all_eidle_entry_sd, fnl_eidle_entry_sd); + end + //$display("eidle_entry_eios = orig: '%s', any:'%s', all:'%s', final: '%s'", eidle_entry_eios, rbc_any_eidle_entry_eios, rbc_all_eidle_entry_eios, fnl_eidle_entry_eios); + if (!is_in_legal_set(eidle_entry_eios, rbc_all_eidle_entry_eios)) begin + $display("Critical Warning: parameter 'eidle_entry_eios' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", eidle_entry_eios, rbc_all_eidle_entry_eios, fnl_eidle_entry_eios); + end + //$display("ctrl_plane_bonding_distribution = orig: '%s', any:'%s', all:'%s', final: '%s'", ctrl_plane_bonding_distribution, rbc_any_ctrl_plane_bonding_distribution, rbc_all_ctrl_plane_bonding_distribution, fnl_ctrl_plane_bonding_distribution); + if (!is_in_legal_set(ctrl_plane_bonding_distribution, rbc_all_ctrl_plane_bonding_distribution)) begin + $display("Critical Warning: parameter 'ctrl_plane_bonding_distribution' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ctrl_plane_bonding_distribution, rbc_all_ctrl_plane_bonding_distribution, fnl_ctrl_plane_bonding_distribution); + end + //$display("ctrl_plane_bonding_compensation = orig: '%s', any:'%s', all:'%s', final: '%s'", ctrl_plane_bonding_compensation, rbc_any_ctrl_plane_bonding_compensation, rbc_all_ctrl_plane_bonding_compensation, fnl_ctrl_plane_bonding_compensation); + if (!is_in_legal_set(ctrl_plane_bonding_compensation, rbc_all_ctrl_plane_bonding_compensation)) begin + $display("Critical Warning: parameter 'ctrl_plane_bonding_compensation' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ctrl_plane_bonding_compensation, rbc_all_ctrl_plane_bonding_compensation, fnl_ctrl_plane_bonding_compensation); + end + //$display("bypass_pipeline_reg = orig: '%s', any:'%s', all:'%s', final: '%s'", bypass_pipeline_reg, rbc_any_bypass_pipeline_reg, rbc_all_bypass_pipeline_reg, fnl_bypass_pipeline_reg); + if (!is_in_legal_set(bypass_pipeline_reg, rbc_all_bypass_pipeline_reg)) begin + $display("Critical Warning: parameter 'bypass_pipeline_reg' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", bypass_pipeline_reg, rbc_all_bypass_pipeline_reg, fnl_bypass_pipeline_reg); + end + //$display("rx_refclk = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_refclk, rbc_any_rx_refclk, rbc_all_rx_refclk, fnl_rx_refclk); + if (!is_in_legal_set(rx_refclk, rbc_all_rx_refclk)) begin + $display("Critical Warning: parameter 'rx_refclk' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_refclk, rbc_all_rx_refclk, fnl_rx_refclk); + end + //$display("rx_rcvd_clk = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_rcvd_clk, rbc_any_rx_rcvd_clk, rbc_all_rx_rcvd_clk, fnl_rx_rcvd_clk); + if (!is_in_legal_set(rx_rcvd_clk, rbc_all_rx_rcvd_clk)) begin + $display("Critical Warning: parameter 'rx_rcvd_clk' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_rcvd_clk, rbc_all_rx_rcvd_clk, fnl_rx_rcvd_clk); + end + //$display("agg_block_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", agg_block_sel, rbc_any_agg_block_sel, rbc_all_agg_block_sel, fnl_agg_block_sel); + if (!is_in_legal_set(agg_block_sel, rbc_all_agg_block_sel)) begin + $display("Critical Warning: parameter 'agg_block_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", agg_block_sel, rbc_all_agg_block_sel, fnl_agg_block_sel); + end + //$display("rx_clk1 = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_clk1, rbc_any_rx_clk1, rbc_all_rx_clk1, fnl_rx_clk1); + if (!is_in_legal_set(rx_clk1, rbc_all_rx_clk1)) begin + $display("Critical Warning: parameter 'rx_clk1' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_clk1, rbc_all_rx_clk1, fnl_rx_clk1); + end + //$display("rx_clk2 = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_clk2, rbc_any_rx_clk2, rbc_all_rx_clk2, fnl_rx_clk2); + if (!is_in_legal_set(rx_clk2, rbc_all_rx_clk2)) begin + $display("Critical Warning: parameter 'rx_clk2' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_clk2, rbc_all_rx_clk2, fnl_rx_clk2); + end + //$display("rx_wr_clk = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_wr_clk, rbc_any_rx_wr_clk, rbc_all_rx_wr_clk, fnl_rx_wr_clk); + if (!is_in_legal_set(rx_wr_clk, rbc_all_rx_wr_clk)) begin + $display("Critical Warning: parameter 'rx_wr_clk' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_wr_clk, rbc_all_rx_wr_clk, fnl_rx_wr_clk); + end + //$display("rx_rd_clk = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_rd_clk, rbc_any_rx_rd_clk, rbc_all_rx_rd_clk, fnl_rx_rd_clk); + if (!is_in_legal_set(rx_rd_clk, rbc_all_rx_rd_clk)) begin + $display("Critical Warning: parameter 'rx_rd_clk' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_rd_clk, rbc_all_rx_rd_clk, fnl_rx_rd_clk); + end + //$display("clock_gate_bist = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_bist, rbc_any_clock_gate_bist, rbc_all_clock_gate_bist, fnl_clock_gate_bist); + if (!is_in_legal_set(clock_gate_bist, rbc_all_clock_gate_bist)) begin + $display("Critical Warning: parameter 'clock_gate_bist' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_bist, rbc_all_clock_gate_bist, fnl_clock_gate_bist); + end + //$display("clock_gate_sw_wa = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_sw_wa, rbc_any_clock_gate_sw_wa, rbc_all_clock_gate_sw_wa, fnl_clock_gate_sw_wa); + if (!is_in_legal_set(clock_gate_sw_wa, rbc_all_clock_gate_sw_wa)) begin + $display("Critical Warning: parameter 'clock_gate_sw_wa' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_sw_wa, rbc_all_clock_gate_sw_wa, fnl_clock_gate_sw_wa); + end + //$display("clock_gate_dw_wa = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_dw_wa, rbc_any_clock_gate_dw_wa, rbc_all_clock_gate_dw_wa, fnl_clock_gate_dw_wa); + if (!is_in_legal_set(clock_gate_dw_wa, rbc_all_clock_gate_dw_wa)) begin + $display("Critical Warning: parameter 'clock_gate_dw_wa' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_dw_wa, rbc_all_clock_gate_dw_wa, fnl_clock_gate_dw_wa); + end + //$display("clock_gate_sw_dskw_wr = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_sw_dskw_wr, rbc_any_clock_gate_sw_dskw_wr, rbc_all_clock_gate_sw_dskw_wr, fnl_clock_gate_sw_dskw_wr); + if (!is_in_legal_set(clock_gate_sw_dskw_wr, rbc_all_clock_gate_sw_dskw_wr)) begin + $display("Critical Warning: parameter 'clock_gate_sw_dskw_wr' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_sw_dskw_wr, rbc_all_clock_gate_sw_dskw_wr, fnl_clock_gate_sw_dskw_wr); + end + //$display("clock_gate_dw_dskw_wr = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_dw_dskw_wr, rbc_any_clock_gate_dw_dskw_wr, rbc_all_clock_gate_dw_dskw_wr, fnl_clock_gate_dw_dskw_wr); + if (!is_in_legal_set(clock_gate_dw_dskw_wr, rbc_all_clock_gate_dw_dskw_wr)) begin + $display("Critical Warning: parameter 'clock_gate_dw_dskw_wr' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_dw_dskw_wr, rbc_all_clock_gate_dw_dskw_wr, fnl_clock_gate_dw_dskw_wr); + end + //$display("clock_gate_prbs = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_prbs, rbc_any_clock_gate_prbs, rbc_all_clock_gate_prbs, fnl_clock_gate_prbs); + if (!is_in_legal_set(clock_gate_prbs, rbc_all_clock_gate_prbs)) begin + $display("Critical Warning: parameter 'clock_gate_prbs' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_prbs, rbc_all_clock_gate_prbs, fnl_clock_gate_prbs); + end + //$display("clock_gate_cdr_eidle = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_cdr_eidle, rbc_any_clock_gate_cdr_eidle, rbc_all_clock_gate_cdr_eidle, fnl_clock_gate_cdr_eidle); + if (!is_in_legal_set(clock_gate_cdr_eidle, rbc_all_clock_gate_cdr_eidle)) begin + $display("Critical Warning: parameter 'clock_gate_cdr_eidle' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_cdr_eidle, rbc_all_clock_gate_cdr_eidle, fnl_clock_gate_cdr_eidle); + end + //$display("clock_gate_dskw_rd = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_dskw_rd, rbc_any_clock_gate_dskw_rd, rbc_all_clock_gate_dskw_rd, fnl_clock_gate_dskw_rd); + if (!is_in_legal_set(clock_gate_dskw_rd, rbc_all_clock_gate_dskw_rd)) begin + $display("Critical Warning: parameter 'clock_gate_dskw_rd' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_dskw_rd, rbc_all_clock_gate_dskw_rd, fnl_clock_gate_dskw_rd); + end + //$display("clock_gate_sw_rm_wr = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_sw_rm_wr, rbc_any_clock_gate_sw_rm_wr, rbc_all_clock_gate_sw_rm_wr, fnl_clock_gate_sw_rm_wr); + if (!is_in_legal_set(clock_gate_sw_rm_wr, rbc_all_clock_gate_sw_rm_wr)) begin + $display("Critical Warning: parameter 'clock_gate_sw_rm_wr' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_sw_rm_wr, rbc_all_clock_gate_sw_rm_wr, fnl_clock_gate_sw_rm_wr); + end + //$display("clock_gate_sw_rm_rd = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_sw_rm_rd, rbc_any_clock_gate_sw_rm_rd, rbc_all_clock_gate_sw_rm_rd, fnl_clock_gate_sw_rm_rd); + if (!is_in_legal_set(clock_gate_sw_rm_rd, rbc_all_clock_gate_sw_rm_rd)) begin + $display("Critical Warning: parameter 'clock_gate_sw_rm_rd' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_sw_rm_rd, rbc_all_clock_gate_sw_rm_rd, fnl_clock_gate_sw_rm_rd); + end + //$display("clock_gate_dw_rm_rd = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_dw_rm_rd, rbc_any_clock_gate_dw_rm_rd, rbc_all_clock_gate_dw_rm_rd, fnl_clock_gate_dw_rm_rd); + if (!is_in_legal_set(clock_gate_dw_rm_rd, rbc_all_clock_gate_dw_rm_rd)) begin + $display("Critical Warning: parameter 'clock_gate_dw_rm_rd' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_dw_rm_rd, rbc_all_clock_gate_dw_rm_rd, fnl_clock_gate_dw_rm_rd); + end + //$display("clock_gate_dw_rm_wr = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_dw_rm_wr, rbc_any_clock_gate_dw_rm_wr, rbc_all_clock_gate_dw_rm_wr, fnl_clock_gate_dw_rm_wr); + if (!is_in_legal_set(clock_gate_dw_rm_wr, rbc_all_clock_gate_dw_rm_wr)) begin + $display("Critical Warning: parameter 'clock_gate_dw_rm_wr' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_dw_rm_wr, rbc_all_clock_gate_dw_rm_wr, fnl_clock_gate_dw_rm_wr); + end + //$display("clock_gate_bds_dec_asn = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_bds_dec_asn, rbc_any_clock_gate_bds_dec_asn, rbc_all_clock_gate_bds_dec_asn, fnl_clock_gate_bds_dec_asn); + if (!is_in_legal_set(clock_gate_bds_dec_asn, rbc_all_clock_gate_bds_dec_asn)) begin + $display("Critical Warning: parameter 'clock_gate_bds_dec_asn' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_bds_dec_asn, rbc_all_clock_gate_bds_dec_asn, fnl_clock_gate_bds_dec_asn); + end + //$display("clock_gate_byteorder = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_byteorder, rbc_any_clock_gate_byteorder, rbc_all_clock_gate_byteorder, fnl_clock_gate_byteorder); + if (!is_in_legal_set(clock_gate_byteorder, rbc_all_clock_gate_byteorder)) begin + $display("Critical Warning: parameter 'clock_gate_byteorder' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_byteorder, rbc_all_clock_gate_byteorder, fnl_clock_gate_byteorder); + end + //$display("clock_gate_sw_pc_wrclk = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_sw_pc_wrclk, rbc_any_clock_gate_sw_pc_wrclk, rbc_all_clock_gate_sw_pc_wrclk, fnl_clock_gate_sw_pc_wrclk); + if (!is_in_legal_set(clock_gate_sw_pc_wrclk, rbc_all_clock_gate_sw_pc_wrclk)) begin + $display("Critical Warning: parameter 'clock_gate_sw_pc_wrclk' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_sw_pc_wrclk, rbc_all_clock_gate_sw_pc_wrclk, fnl_clock_gate_sw_pc_wrclk); + end + //$display("clock_gate_dw_pc_wrclk = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_dw_pc_wrclk, rbc_any_clock_gate_dw_pc_wrclk, rbc_all_clock_gate_dw_pc_wrclk, fnl_clock_gate_dw_pc_wrclk); + if (!is_in_legal_set(clock_gate_dw_pc_wrclk, rbc_all_clock_gate_dw_pc_wrclk)) begin + $display("Critical Warning: parameter 'clock_gate_dw_pc_wrclk' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_dw_pc_wrclk, rbc_all_clock_gate_dw_pc_wrclk, fnl_clock_gate_dw_pc_wrclk); + end + //$display("clock_gate_pc_rdclk = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_pc_rdclk, rbc_any_clock_gate_pc_rdclk, rbc_all_clock_gate_pc_rdclk, fnl_clock_gate_pc_rdclk); + if (!is_in_legal_set(clock_gate_pc_rdclk, rbc_all_clock_gate_pc_rdclk)) begin + $display("Critical Warning: parameter 'clock_gate_pc_rdclk' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_pc_rdclk, rbc_all_clock_gate_pc_rdclk, fnl_clock_gate_pc_rdclk); + end + //$display("rx_pcs_urst = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_pcs_urst, rbc_any_rx_pcs_urst, rbc_all_rx_pcs_urst, fnl_rx_pcs_urst); + if (!is_in_legal_set(rx_pcs_urst, rbc_all_rx_pcs_urst)) begin + $display("Critical Warning: parameter 'rx_pcs_urst' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_pcs_urst, rbc_all_rx_pcs_urst, fnl_rx_pcs_urst); + end + //$display("rx_clk_free_running = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_clk_free_running, rbc_any_rx_clk_free_running, rbc_all_rx_clk_free_running, fnl_rx_clk_free_running); + if (!is_in_legal_set(rx_clk_free_running, rbc_all_rx_clk_free_running)) begin + $display("Critical Warning: parameter 'rx_clk_free_running' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_clk_free_running, rbc_all_rx_clk_free_running, fnl_rx_clk_free_running); + end + //$display("comp_fifo_rst_pld_ctrl = orig: '%s', any:'%s', all:'%s', final: '%s'", comp_fifo_rst_pld_ctrl, rbc_any_comp_fifo_rst_pld_ctrl, rbc_all_comp_fifo_rst_pld_ctrl, fnl_comp_fifo_rst_pld_ctrl); + if (!is_in_legal_set(comp_fifo_rst_pld_ctrl, rbc_all_comp_fifo_rst_pld_ctrl)) begin + $display("Critical Warning: parameter 'comp_fifo_rst_pld_ctrl' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", comp_fifo_rst_pld_ctrl, rbc_all_comp_fifo_rst_pld_ctrl, fnl_comp_fifo_rst_pld_ctrl); + end + //$display("pc_fifo_rst_pld_ctrl = orig: '%s', any:'%s', all:'%s', final: '%s'", pc_fifo_rst_pld_ctrl, rbc_any_pc_fifo_rst_pld_ctrl, rbc_all_pc_fifo_rst_pld_ctrl, fnl_pc_fifo_rst_pld_ctrl); + if (!is_in_legal_set(pc_fifo_rst_pld_ctrl, rbc_all_pc_fifo_rst_pld_ctrl)) begin + $display("Critical Warning: parameter 'pc_fifo_rst_pld_ctrl' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pc_fifo_rst_pld_ctrl, rbc_all_pc_fifo_rst_pld_ctrl, fnl_pc_fifo_rst_pld_ctrl); + end + //$display("test_bus_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", test_bus_sel, rbc_any_test_bus_sel, rbc_all_test_bus_sel, fnl_test_bus_sel); + if (!is_in_legal_set(test_bus_sel, rbc_all_test_bus_sel)) begin + $display("Critical Warning: parameter 'test_bus_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", test_bus_sel, rbc_all_test_bus_sel, fnl_test_bus_sel); + end + end + + arriav_hssi_8g_rx_pcs #( + .prot_mode(fnl_prot_mode), + .sup_mode(fnl_sup_mode), + .avmm_group_channel_index(avmm_group_channel_index), + .bo_pad(bo_pad), + .bo_pattern(bo_pattern), + .channel_number(channel_number), + .cid_pattern_len(cid_pattern_len), + .clkcmp_pattern_n(clkcmp_pattern_n), + .clkcmp_pattern_p(clkcmp_pattern_p), + .deskew_pattern(deskew_pattern), + .fixed_pat_num(fixed_pat_num), + .mask_cnt(mask_cnt), + .pma_done_count(pma_done_count), + .runlength_val(runlength_val), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address), + .wa_clk_slip_spacing_data(wa_clk_slip_spacing_data), + .wa_pd_data(wa_pd_data), + .wa_renumber_data(wa_renumber_data), + .wa_rgnumber_data(wa_rgnumber_data), + .wa_rknumber_data(wa_rknumber_data), + .wa_rosnumber_data(wa_rosnumber_data), + .wa_rvnumber_data(wa_rvnumber_data), + .wait_cnt(wait_cnt), + .test_mode(fnl_test_mode), + .hip_mode(fnl_hip_mode), + .pcs_bypass(fnl_pcs_bypass), + .pma_dw(fnl_pma_dw), + .pipe_if_enable(fnl_pipe_if_enable), + .prbs_ver(fnl_prbs_ver), + .wa_boundary_lock_ctrl(fnl_wa_boundary_lock_ctrl), + .wa_pld_controlled(fnl_wa_pld_controlled), + .wa_pd_polarity(fnl_wa_pd_polarity), + .wa_pd(fnl_wa_pd), + .wa_sync_sm_ctrl(fnl_wa_sync_sm_ctrl), + .wa_kchar(fnl_wa_kchar), + .fixed_pat_det(fnl_fixed_pat_det), + .ibm_invalid_code(fnl_ibm_invalid_code), + .force_signal_detect(fnl_force_signal_detect), + .wa_det_latency_sync_status_beh(fnl_wa_det_latency_sync_status_beh), + .wa_clk_slip_spacing(fnl_wa_clk_slip_spacing), + .eightb_tenb_decoder(fnl_eightb_tenb_decoder), + .wa_disp_err_flag(fnl_wa_disp_err_flag), + .polarity_inversion(fnl_polarity_inversion), + .bit_reversal(fnl_bit_reversal), + .symbol_swap(fnl_symbol_swap), + .runlength_check(fnl_runlength_check), + .ctrl_plane_bonding_consumption(fnl_ctrl_plane_bonding_consumption), + .deskew(fnl_deskew), + .deskew_prog_pattern_only(fnl_deskew_prog_pattern_only), + .rate_match(fnl_rate_match), + .err_flags_sel(fnl_err_flags_sel), + .polinv_8b10b_dec(fnl_polinv_8b10b_dec), + .eightbtenb_decoder_output_sel(fnl_eightbtenb_decoder_output_sel), + .invalid_code_flag_only(fnl_invalid_code_flag_only), + .auto_error_replacement(fnl_auto_error_replacement), + .pad_or_edb_error_replace(fnl_pad_or_edb_error_replace), + .byte_deserializer(fnl_byte_deserializer), + .byte_order(fnl_byte_order), + .dw_one_or_two_symbol_bo(fnl_dw_one_or_two_symbol_bo), + .re_bo_on_wa(fnl_re_bo_on_wa), + .phase_compensation_fifo(fnl_phase_compensation_fifo), + .tx_rx_parallel_loopback(fnl_tx_rx_parallel_loopback), + .prbs_ver_clr_flag(fnl_prbs_ver_clr_flag), + .cid_pattern(fnl_cid_pattern), + .bist_ver(fnl_bist_ver), + .bist_ver_clr_flag(fnl_bist_ver_clr_flag), + .cdr_ctrl(fnl_cdr_ctrl), + .cdr_ctrl_rxvalid_mask(fnl_cdr_ctrl_rxvalid_mask), + .auto_speed_nego(fnl_auto_speed_nego), + .eidle_entry_iei(fnl_eidle_entry_iei), + .eidle_entry_sd(fnl_eidle_entry_sd), + .eidle_entry_eios(fnl_eidle_entry_eios), + .ctrl_plane_bonding_distribution(fnl_ctrl_plane_bonding_distribution), + .ctrl_plane_bonding_compensation(fnl_ctrl_plane_bonding_compensation), + .bypass_pipeline_reg(fnl_bypass_pipeline_reg), + .rx_refclk(fnl_rx_refclk), + .rx_rcvd_clk(fnl_rx_rcvd_clk), + .agg_block_sel(fnl_agg_block_sel), + .rx_clk1(fnl_rx_clk1), + .rx_clk2(fnl_rx_clk2), + .rx_wr_clk(fnl_rx_wr_clk), + .rx_rd_clk(fnl_rx_rd_clk), + .clock_gate_bist(fnl_clock_gate_bist), + .clock_gate_sw_wa(fnl_clock_gate_sw_wa), + .clock_gate_dw_wa(fnl_clock_gate_dw_wa), + .clock_gate_sw_dskw_wr(fnl_clock_gate_sw_dskw_wr), + .clock_gate_dw_dskw_wr(fnl_clock_gate_dw_dskw_wr), + .clock_gate_prbs(fnl_clock_gate_prbs), + .clock_gate_cdr_eidle(fnl_clock_gate_cdr_eidle), + .clock_gate_dskw_rd(fnl_clock_gate_dskw_rd), + .clock_gate_sw_rm_wr(fnl_clock_gate_sw_rm_wr), + .clock_gate_sw_rm_rd(fnl_clock_gate_sw_rm_rd), + .clock_gate_dw_rm_rd(fnl_clock_gate_dw_rm_rd), + .clock_gate_dw_rm_wr(fnl_clock_gate_dw_rm_wr), + .clock_gate_bds_dec_asn(fnl_clock_gate_bds_dec_asn), + .clock_gate_byteorder(fnl_clock_gate_byteorder), + .clock_gate_sw_pc_wrclk(fnl_clock_gate_sw_pc_wrclk), + .clock_gate_dw_pc_wrclk(fnl_clock_gate_dw_pc_wrclk), + .clock_gate_pc_rdclk(fnl_clock_gate_pc_rdclk), + .rx_pcs_urst(fnl_rx_pcs_urst), + .rx_clk_free_running(fnl_rx_clk_free_running), + .comp_fifo_rst_pld_ctrl(fnl_comp_fifo_rst_pld_ctrl), + .pc_fifo_rst_pld_ctrl(fnl_pc_fifo_rst_pld_ctrl), + .test_bus_sel(fnl_test_bus_sel) + ) wys ( + // ports + .a1a2k1k2flag(a1a2k1k2flag), + .a1a2size(a1a2size), + .aggrxpcsrst(aggrxpcsrst), + .aggtestbus(aggtestbus), + .aligndetsync(aligndetsync), + .alignstatus(alignstatus), + .alignstatuspld(alignstatuspld), + .alignstatussync(alignstatussync), + .alignstatussync0(alignstatussync0), + .alignstatussync0toporbot(alignstatussync0toporbot), + .alignstatustoporbot(alignstatustoporbot), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .bistdone(bistdone), + .bisterr(bisterr), + .bitreversalenable(bitreversalenable), + .bitslip(bitslip), + .blockselect(blockselect), + .byteorder(byteorder), + .byteordflag(byteordflag), + .bytereversalenable(bytereversalenable), + .cgcomprddall(cgcomprddall), + .cgcomprddalltoporbot(cgcomprddalltoporbot), + .cgcomprddout(cgcomprddout), + .cgcompwrall(cgcompwrall), + .cgcompwralltoporbot(cgcompwralltoporbot), + .cgcompwrout(cgcompwrout), + .channeltestbusout(channeltestbusout), + .clocktopld(clocktopld), + .configselinchnldown(configselinchnldown), + .configselinchnlup(configselinchnlup), + .configseloutchnldown(configseloutchnldown), + .configseloutchnlup(configseloutchnlup), + .ctrlfromaggblock(ctrlfromaggblock), + .datafrinaggblock(datafrinaggblock), + .datain(datain), + .dataout(dataout), + .decoderctrl(decoderctrl), + .decoderdata(decoderdata), + .decoderdatavalid(decoderdatavalid), + .delcondmet0(delcondmet0), + .delcondmet0toporbot(delcondmet0toporbot), + .delcondmetout(delcondmetout), + .disablepcfifobyteserdes(disablepcfifobyteserdes), + .dynclkswitchn(dynclkswitchn), + .earlyeios(earlyeios), + .eidledetected(eidledetected), + .eidleexit(eidleexit), + .eidleinfersel(eidleinfersel), + .enablecommadetect(enablecommadetect), + .endskwqd(endskwqd), + .endskwqdtoporbot(endskwqdtoporbot), + .endskwrdptrs(endskwrdptrs), + .endskwrdptrstoporbot(endskwrdptrstoporbot), + .errctrl(errctrl), + .errdata(errdata), + .fifoovr0(fifoovr0), + .fifoovr0toporbot(fifoovr0toporbot), + .fifoovrout(fifoovrout), + .fifordincomp0toporbot(fifordincomp0toporbot), + .fifordoutcomp(fifordoutcomp), + .fiforstrdqd(fiforstrdqd), + .fiforstrdqdtoporbot(fiforstrdqdtoporbot), + .gen2ngen1(gen2ngen1), + .hrdrst(hrdrst), + .insertincomplete0(insertincomplete0), + .insertincomplete0toporbot(insertincomplete0toporbot), + .insertincompleteout(insertincompleteout), + .latencycomp0(latencycomp0), + .latencycomp0toporbot(latencycomp0toporbot), + .latencycompout(latencycompout), + .ltr(ltr), + .observablebyteserdesclock(observablebyteserdesclock), + .parallelloopback(parallelloopback), + .parallelrevloopback(parallelrevloopback), + .pcfifoempty(pcfifoempty), + .pcfifofull(pcfifofull), + .pcfifordenable(pcfifordenable), + .pcieswitch(pcieswitch), + .phfifouserrst(phfifouserrst), + .phystatus(phystatus), + .phystatusinternal(phystatusinternal), + .phystatuspcsgen3(phystatuspcsgen3), + .pipedata(pipedata), + .pipeloopbk(pipeloopbk), + .pldltr(pldltr), + .pldrxclk(pldrxclk), + .polinvrx(polinvrx), + .prbscidenable(prbscidenable), + .prbsdone(prbsdone), + .prbserrlt(prbserrlt), + .pxfifowrdisable(pxfifowrdisable), + .rateswitchcontrol(rateswitchcontrol), + .rcvdclkagg(rcvdclkagg), + .rcvdclkaggtoporbot(rcvdclkaggtoporbot), + .rcvdclkpma(rcvdclkpma), + .rdalign(rdalign), + .rdenableinchnldown(rdenableinchnldown), + .rdenableinchnlup(rdenableinchnlup), + .rdenableoutchnldown(rdenableoutchnldown), + .rdenableoutchnlup(rdenableoutchnlup), + .refclkdig(refclkdig), + .refclkdig2(refclkdig2), + .resetpcptrs(resetpcptrs), + .resetpcptrsinchnldown(resetpcptrsinchnldown), + .resetpcptrsinchnldownpipe(resetpcptrsinchnldownpipe), + .resetpcptrsinchnlup(resetpcptrsinchnlup), + .resetpcptrsinchnluppipe(resetpcptrsinchnluppipe), + .resetpcptrsoutchnldown(resetpcptrsoutchnldown), + .resetpcptrsoutchnlup(resetpcptrsoutchnlup), + .resetppmcntrsinchnldown(resetppmcntrsinchnldown), + .resetppmcntrsinchnlup(resetppmcntrsinchnlup), + .resetppmcntrsoutchnldown(resetppmcntrsoutchnldown), + .resetppmcntrsoutchnlup(resetppmcntrsoutchnlup), + .resetppmcntrspcspma(resetppmcntrspcspma), + .rlvlt(rlvlt), + .rmfifoempty(rmfifoempty), + .rmfifofull(rmfifofull), + .rmfifopartialempty(rmfifopartialempty), + .rmfifopartialfull(rmfifopartialfull), + .rmfifordincomp0(rmfifordincomp0), + .rmfiforeadenable(rmfiforeadenable), + .rmfifouserrst(rmfifouserrst), + .rmfifowriteenable(rmfifowriteenable), + .runlengthviolation(runlengthviolation), + .runningdisparity(runningdisparity), + .rxblkstart(rxblkstart), + .rxclkslip(rxclkslip), + .rxcontrolrstoporbot(rxcontrolrstoporbot), + .rxdatarstoporbot(rxdatarstoporbot), + .rxdatavalid(rxdatavalid), + .rxdivsyncinchnldown(rxdivsyncinchnldown), + .rxdivsyncinchnlup(rxdivsyncinchnlup), + .rxdivsyncoutchnldown(rxdivsyncoutchnldown), + .rxdivsyncoutchnlup(rxdivsyncoutchnlup), + .rxpcsrst(rxpcsrst), + .rxpipeclk(rxpipeclk), + .rxpipesoftreset(rxpipesoftreset), + .rxstatus(rxstatus), + .rxstatusinternal(rxstatusinternal), + .rxsynchdr(rxsynchdr), + .rxsynchdrpcsgen3(rxsynchdrpcsgen3), + .rxvalid(rxvalid), + .rxvalidinternal(rxvalidinternal), + .rxweinchnldown(rxweinchnldown), + .rxweinchnlup(rxweinchnlup), + .rxweoutchnldown(rxweoutchnldown), + .rxweoutchnlup(rxweoutchnlup), + .scanmode(scanmode), + .selftestdone(selftestdone), + .selftesterr(selftesterr), + .sigdetfrompma(sigdetfrompma), + .signaldetectout(signaldetectout), + .speedchange(speedchange), + .speedchangeinchnldown(speedchangeinchnldown), + .speedchangeinchnldownpipe(speedchangeinchnldownpipe), + .speedchangeinchnlup(speedchangeinchnlup), + .speedchangeinchnluppipe(speedchangeinchnluppipe), + .speedchangeoutchnldown(speedchangeoutchnldown), + .speedchangeoutchnlup(speedchangeoutchnlup), + .syncdatain(syncdatain), + .syncsmen(syncsmen), + .syncstatus(syncstatus), + .txctrlplanetestbus(txctrlplanetestbus), + .txdivsync(txdivsync), + .txpmaclk(txpmaclk), + .txtestbus(txtestbus), + .wordalignboundary(wordalignboundary), + .wrenableinchnldown(wrenableinchnldown), + .wrenableinchnlup(wrenableinchnlup), + .wrenableoutchnldown(wrenableoutchnldown), + .wrenableoutchnlup(wrenableoutchnlup) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_8g_tx_pcs_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_8g_tx_pcs_rbc.sv new file mode 100644 index 0000000..bba8e4e --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_8g_tx_pcs_rbc.sv @@ -0,0 +1,735 @@ +// (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_tx_pcs +// + +`timescale 1 ns / 1 ps + +module av_hssi_8g_tx_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 channel_number = 0, // 0..65 + parameter cid_pattern_len = 8'b0, // 8 + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0, // 0..2047 + + // constrained parameters + parameter test_mode = "", // bist, dont_care_test, prbs + parameter hip_mode = "", // dis_hip, en_hip + parameter pma_dw = "", // eight_bit, sixteen_bit, ten_bit, twenty_bit + parameter pcs_bypass = "", // dis_pcs_bypass, en_pcs_bypass + parameter phase_compensation_fifo = "", // low_latency, normal_latency, pld_ctrl_low_latency, pld_ctrl_normal_latency, register_fifo + parameter tx_compliance_controlled_disparity = "", // dis_txcompliance, en_txcompliance_pipe2p0 + parameter force_kchar = "", // dis_force_kchar, en_force_kchar + parameter force_echar = "", // dis_force_echar, en_force_echar + parameter byte_serializer = "", // dis_bs, en_bs_by_2 + parameter data_selection_8b10b_encoder_input = "", // gige_idle_conversion, normal_data_path, xaui_sm + parameter eightb_tenb_disp_ctrl = "", // dis_disp_ctrl, en_disp_ctrl, en_ib_disp_ctrl + parameter eightb_tenb_encoder = "", // dis_8b10b, en_8b10b_ibm, en_8b10b_sgx + parameter prbs_gen = "", // 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 cid_pattern = "", // cid_pattern_0, cid_pattern_1 + parameter bist_gen = "", // cjpat, crpat, dis_bist, incremental + parameter bit_reversal = "", // dis_bit_reversal, en_bit_reversal + parameter symbol_swap = "", // dis_symbol_swap, en_symbol_swap + parameter polarity_inversion = "", // dis_polinv, enable_polinv + parameter tx_bitslip = "", // dis_tx_bitslip, en_tx_bitslip + parameter ctrl_plane_bonding_consumption = "", // bundled_master, bundled_slave_above, bundled_slave_below, individual + parameter agg_block_sel = "", // other_smrt_pack, same_smrt_pack + 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 clock_gate_bs_enc = "", // dis_bs_enc_clk_gating, en_bs_enc_clk_gating + parameter clock_gate_prbs = "", // dis_prbs_clk_gating, en_prbs_clk_gating + parameter clock_gate_bist = "", // dis_bist_clk_gating, en_bist_clk_gating + parameter clock_gate_sw_fifowr = "", // dis_sw_fifowr_clk_gating, en_sw_fifowr_clk_gating + parameter clock_gate_dw_fifowr = "", // dis_dw_fifowr_clk_gating, en_dw_fifowr_clk_gating + parameter clock_gate_fiford = "", // dis_fiford_clk_gating, en_fiford_clk_gating + parameter revloop_back_rm = "", // dis_rev_loopback_rx_rm, en_rev_loopback_rx_rm + parameter phfifo_write_clk_sel = "", // pld_tx_clk, tx_clk + parameter refclk_b_clk_sel = "", // refclk_dig, tx_pma_clock + parameter dynamic_clk_switch = "", // dis_dyn_clk_switch, en_dyn_clk_switch + parameter auto_speed_nego_gen2 = "", // dis_asn_g2, en_asn_g2_freq_scal + parameter txclk_freerun = "", // dis_freerun_tx, en_freerun_tx + parameter pcfifo_urst = "", // dis_pcfifourst, en_pcfifourst + parameter txpcs_urst = "" // dis_txpcs_urst, en_txpcs_urst +) ( + // ports + output wire aggtxpcsrst, + 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, + input wire [4:0] bitslipboundaryselect, + output wire blockselect, + output wire clkout, + input wire coreclk, + input wire [43:0] datain, + output wire [19:0] dataout, + input wire detectrxloopin, + output wire detectrxloopout, + input wire dispcbyte, + output wire dynclkswitchn, + input wire [2:0] elecidleinfersel, + input wire enrevparallellpbk, + input wire [1:0] fifoselectinchnldown, + input wire [1:0] fifoselectinchnlup, + output wire [1:0] fifoselectoutchnldown, + output wire [1:0] fifoselectoutchnlup, + output wire [2:0] grayelecidleinferselout, + input wire hrdrst, + input wire invpol, + output wire observablebyteserdesclock, + output wire [19:0] parallelfdbkout, + output wire phfifooverflow, + input wire phfiforddisable, + input wire phfiforeset, + output wire phfifotxdeemph, + output wire [2:0] phfifotxmargin, + output wire phfifotxswing, + output wire phfifounderflow, + input wire phfifowrenable, + input wire pipeenrevparallellpbkin, + output wire pipeenrevparallellpbkout, + output wire [1:0] pipepowerdownout, + input wire pipetxdeemph, + input wire [2:0] pipetxmargin, + input wire pipetxswing, + input wire polinvrxin, + output wire polinvrxout, + input wire [1:0] powerdn, + input wire prbscidenable, + input wire rateswitch, + input wire rdenableinchnldown, + input wire rdenableinchnlup, + output wire rdenableoutchnldown, + output wire rdenableoutchnlup, + output wire rdenablesync, + output wire refclkb, + output wire refclkbreset, + input wire refclkdig, + input wire resetpcptrs, + input wire resetpcptrsinchnldown, + input wire resetpcptrsinchnlup, + input wire [19:0] revparallellpbkdata, + input wire rxpolarityin, + output wire rxpolarityout, + input wire scanmode, + output wire syncdatain, + input wire [3:0] txblkstart, + output wire [3:0] txblkstartout, + output wire txcomplianceout, + output wire [19:0] txctrlplanetestbus, + output wire [3:0] txdatakouttogen3, + output wire [31:0] txdataouttogen3, + input wire [3:0] txdatavalid, + output wire [3:0] txdatavalidouttogen3, + output wire [1:0] txdivsync, + input wire [1:0] txdivsyncinchnldown, + input wire [1:0] txdivsyncinchnlup, + output wire [1:0] txdivsyncoutchnldown, + output wire [1:0] txdivsyncoutchnlup, + output wire txelecidleout, + input wire txpcsreset, + output wire txpipeclk, + output wire txpipeelectidle, + output wire txpipesoftreset, + input wire txpmalocalclk, + input wire [1:0] txsynchdr, + output wire [1:0] txsynchdrout, + output wire [19:0] txtestbus, + input wire wrenableinchnldown, + input wire wrenableinchnlup, + output wire wrenableoutchnldown, + output wire wrenableoutchnlup, + input wire xgmctrl, + output wire xgmctrlenable, + input wire xgmctrltoporbottom, + input wire [7:0] xgmdatain, + input wire [7:0] xgmdataintoporbottom, + output wire [7:0] xgmdataout +); + 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 = "basic"; + 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") ? ("dont_care_test") : "(prbs,bist)"; + localparam rbc_any_test_mode = (fnl_prot_mode != "test") ? ("dont_care_test") : "prbs"; + 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; + + // 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; + + // 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; + + // 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_compliance_controlled_disparity, RBC-validated + localparam rbc_all_tx_compliance_controlled_disparity = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("en_txcompliance_pipe2p0") : "dis_txcompliance"; + localparam rbc_any_tx_compliance_controlled_disparity = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("en_txcompliance_pipe2p0") : "dis_txcompliance"; + localparam fnl_tx_compliance_controlled_disparity = (tx_compliance_controlled_disparity == "" || tx_compliance_controlled_disparity == "") ? rbc_any_tx_compliance_controlled_disparity : tx_compliance_controlled_disparity; + + // force_kchar, RBC-validated + localparam rbc_all_force_kchar = "dis_force_kchar"; + localparam rbc_any_force_kchar = "dis_force_kchar"; + localparam fnl_force_kchar = (force_kchar == "" || force_kchar == "") ? rbc_any_force_kchar : force_kchar; + + // force_echar, RBC-validated + localparam rbc_all_force_echar = "dis_force_echar"; + localparam rbc_any_force_echar = "dis_force_echar"; + localparam fnl_force_echar = (force_echar == "" || force_echar == "") ? rbc_any_force_echar : force_echar; + + // byte_serializer, RBC-validated + localparam rbc_all_byte_serializer = ( (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_bs") + : ( (fnl_prot_mode == "xaui") || (fnl_test_mode == "bist" && fnl_pma_dw == "ten_bit" ) || ( fnl_prot_mode == "pipe_g2" ) ) ? ("en_bs_by_2") : "(dis_bs,en_bs_by_2)"; + localparam rbc_any_byte_serializer = ( (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_bs") + : ( (fnl_prot_mode == "xaui") || (fnl_test_mode == "bist" && fnl_pma_dw == "ten_bit" ) || ( fnl_prot_mode == "pipe_g2" ) ) ? ("en_bs_by_2") : "dis_bs"; + localparam fnl_byte_serializer = (byte_serializer == "" || byte_serializer == "") ? rbc_any_byte_serializer : byte_serializer; + + // data_selection_8b10b_encoder_input, RBC-validated + localparam rbc_all_data_selection_8b10b_encoder_input = (fnl_prot_mode == "gige") ? ("gige_idle_conversion") + : (fnl_prot_mode == "xaui") ? ("xaui_sm") : "normal_data_path"; + localparam rbc_any_data_selection_8b10b_encoder_input = (fnl_prot_mode == "gige") ? ("gige_idle_conversion") + : (fnl_prot_mode == "xaui") ? ("xaui_sm") : "normal_data_path"; + localparam fnl_data_selection_8b10b_encoder_input = (data_selection_8b10b_encoder_input == "" || data_selection_8b10b_encoder_input == "") ? rbc_any_data_selection_8b10b_encoder_input : data_selection_8b10b_encoder_input; + + // eightb_tenb_disp_ctrl, RBC-validated + localparam rbc_all_eightb_tenb_disp_ctrl = ( fnl_prot_mode == "basic") ? ("(dis_disp_ctrl,en_disp_ctrl)") + : (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" ) ? ("en_disp_ctrl") : "dis_disp_ctrl"; + localparam rbc_any_eightb_tenb_disp_ctrl = ( fnl_prot_mode == "basic") ? ("dis_disp_ctrl") + : (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" ) ? ("en_disp_ctrl") : "dis_disp_ctrl"; + localparam fnl_eightb_tenb_disp_ctrl = (eightb_tenb_disp_ctrl == "" || eightb_tenb_disp_ctrl == "") ? rbc_any_eightb_tenb_disp_ctrl : eightb_tenb_disp_ctrl; + + // eightb_tenb_encoder, RBC-validated + localparam rbc_all_eightb_tenb_encoder = ( (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_pcs_bypass == "dis_pcs_bypass") && (fnl_sup_mode == "user_mode")) || fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx" ) ? ("(dis_8b10b,en_8b10b_ibm)") + : ( (fnl_prot_mode == "basic" ) && (fnl_pcs_bypass == "dis_pcs_bypass") && (fnl_sup_mode == "engineering_mode") ) ? ("(dis_8b10b,en_8b10b_ibm,en_8b10b_sgx)") : "en_8b10b_ibm"; + localparam rbc_any_eightb_tenb_encoder = ( (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_pcs_bypass == "dis_pcs_bypass") && (fnl_sup_mode == "user_mode")) || fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx" ) ? ("dis_8b10b") + : ( (fnl_prot_mode == "basic" ) && (fnl_pcs_bypass == "dis_pcs_bypass") && (fnl_sup_mode == "engineering_mode") ) ? ("dis_8b10b") : "en_8b10b_ibm"; + localparam fnl_eightb_tenb_encoder = (eightb_tenb_encoder == "" || eightb_tenb_encoder == "") ? rbc_any_eightb_tenb_encoder : eightb_tenb_encoder; + + // prbs_gen, RBC-validated + localparam rbc_all_prbs_gen = ( 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_gen = ( 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_gen = (prbs_gen == "" || prbs_gen == "") ? rbc_any_prbs_gen : prbs_gen; + + // cid_pattern, RBC-validated + localparam rbc_all_cid_pattern = (fnl_prbs_gen == "prbs_8" ) ? ("(cid_pattern_0,cid_pattern_1)") : "cid_pattern_0"; + localparam rbc_any_cid_pattern = (fnl_prbs_gen == "prbs_8" ) ? ("cid_pattern_0") : "cid_pattern_0"; + localparam fnl_cid_pattern = (cid_pattern == "" || cid_pattern == "") ? rbc_any_cid_pattern : cid_pattern; + + // bist_gen, RBC-validated + localparam rbc_all_bist_gen = ( (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_gen = ( (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_gen = (bist_gen == "" || bist_gen == "") ? rbc_any_bist_gen : bist_gen; + + // bit_reversal, RBC-validated + localparam rbc_all_bit_reversal = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" || fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx" || fnl_prot_mode == "gige" || fnl_prot_mode == "xaui" || fnl_prot_mode == "srio_2p1" || fnl_prot_mode == "test" ) ? ("dis_bit_reversal") + : (fnl_prot_mode == "basic") ? ("(dis_bit_reversal,en_bit_reversal)") : "dis_bit_reversal"; + localparam rbc_any_bit_reversal = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" || fnl_prot_mode == "cpri" || fnl_prot_mode == "cpri_rx_tx" || fnl_prot_mode == "gige" || fnl_prot_mode == "xaui" || fnl_prot_mode == "srio_2p1" || fnl_prot_mode == "test" ) ? ("dis_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; + + // polarity_inversion, RBC-validated + localparam rbc_all_polarity_inversion = (fnl_prot_mode == "disabled_prot_mode") ? ("dis_polinv") + : (fnl_prot_mode == "test") ? + ( + ( (fnl_test_mode == "prbs") && (fnl_prbs_gen == "prbs_31")) ? ("(dis_polinv,enable_polinv)") : "dis_polinv" + ) : "(dis_polinv,enable_polinv)"; + localparam rbc_any_polarity_inversion = (fnl_prot_mode == "disabled_prot_mode") ? ("dis_polinv") + : (fnl_prot_mode == "test") ? + ( + ( (fnl_test_mode == "prbs") && (fnl_prbs_gen == "prbs_31")) ? ("dis_polinv") : "dis_polinv" + ) : "dis_polinv"; + localparam fnl_polarity_inversion = (polarity_inversion == "" || polarity_inversion == "") ? rbc_any_polarity_inversion : polarity_inversion; + + // tx_bitslip, RBC-validated + localparam rbc_all_tx_bitslip = (fnl_prot_mode == "cpri_rx_tx") ? ("en_tx_bitslip") + : (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" || fnl_prot_mode == "gige" || fnl_prot_mode == "xaui" || fnl_prot_mode == "test") ? ("dis_tx_bitslip") + : ( (fnl_prot_mode == "basic") || (fnl_prot_mode == "srio_2p1") || (fnl_prot_mode == "cpri") ) ? ("(en_tx_bitslip,dis_tx_bitslip)") : "dis_tx_bitslip"; + localparam rbc_any_tx_bitslip = (fnl_prot_mode == "cpri_rx_tx") ? ("en_tx_bitslip") + : (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2" || fnl_prot_mode == "gige" || fnl_prot_mode == "xaui" || fnl_prot_mode == "test") ? ("dis_tx_bitslip") + : ( (fnl_prot_mode == "basic") || (fnl_prot_mode == "srio_2p1") || (fnl_prot_mode == "cpri") ) ? ("dis_tx_bitslip") : "dis_tx_bitslip"; + localparam fnl_tx_bitslip = (tx_bitslip == "" || tx_bitslip == "") ? rbc_any_tx_bitslip : tx_bitslip; + + // ctrl_plane_bonding_consumption, RBC-validated + localparam rbc_all_ctrl_plane_bonding_consumption = ( (fnl_prot_mode == "test") || (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 == "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; + + // 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; + + // 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; + + // clock_gate_bs_enc, RBC-validated + localparam rbc_all_clock_gate_bs_enc = (fnl_prot_mode == "disabled_prot_mode") ? ("en_bs_enc_clk_gating") : "dis_bs_enc_clk_gating"; + localparam rbc_any_clock_gate_bs_enc = (fnl_prot_mode == "disabled_prot_mode") ? ("en_bs_enc_clk_gating") : "dis_bs_enc_clk_gating"; + localparam fnl_clock_gate_bs_enc = (clock_gate_bs_enc == "" || clock_gate_bs_enc == "") ? rbc_any_clock_gate_bs_enc : clock_gate_bs_enc; + + // 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_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_fifowr, RBC-validated + localparam rbc_all_clock_gate_sw_fifowr = ( (fnl_prot_mode == "disabled_prot_mode") ||((fnl_phase_compensation_fifo == "register_fifo") && (fnl_hip_mode == "dis_hip")) ) ? ("en_sw_fifowr_clk_gating") : "dis_sw_fifowr_clk_gating"; + localparam rbc_any_clock_gate_sw_fifowr = ( (fnl_prot_mode == "disabled_prot_mode") ||((fnl_phase_compensation_fifo == "register_fifo") && (fnl_hip_mode == "dis_hip")) ) ? ("en_sw_fifowr_clk_gating") : "dis_sw_fifowr_clk_gating"; + localparam fnl_clock_gate_sw_fifowr = (clock_gate_sw_fifowr == "" || clock_gate_sw_fifowr == "") ? rbc_any_clock_gate_sw_fifowr : clock_gate_sw_fifowr; + + // clock_gate_dw_fifowr, RBC-validated + localparam rbc_all_clock_gate_dw_fifowr = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_phase_compensation_fifo == "register_fifo") || (fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "eight_bit") ) ? ("en_dw_fifowr_clk_gating") : "dis_dw_fifowr_clk_gating"; + localparam rbc_any_clock_gate_dw_fifowr = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_phase_compensation_fifo == "register_fifo") || (fnl_pma_dw == "ten_bit") || (fnl_pma_dw == "eight_bit") ) ? ("en_dw_fifowr_clk_gating") : "dis_dw_fifowr_clk_gating"; + localparam fnl_clock_gate_dw_fifowr = (clock_gate_dw_fifowr == "" || clock_gate_dw_fifowr == "") ? rbc_any_clock_gate_dw_fifowr : clock_gate_dw_fifowr; + + // clock_gate_fiford, RBC-validated + localparam rbc_all_clock_gate_fiford = (fnl_prot_mode == "disabled_prot_mode") ? ("en_fiford_clk_gating") : "dis_fiford_clk_gating"; + localparam rbc_any_clock_gate_fiford = (fnl_prot_mode == "disabled_prot_mode") ? ("en_fiford_clk_gating") : "dis_fiford_clk_gating"; + localparam fnl_clock_gate_fiford = (clock_gate_fiford == "" || clock_gate_fiford == "") ? rbc_any_clock_gate_fiford : clock_gate_fiford; + + // revloop_back_rm, RBC-validated + localparam rbc_all_revloop_back_rm = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("en_rev_loopback_rx_rm") : "dis_rev_loopback_rx_rm"; + localparam rbc_any_revloop_back_rm = ((fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2")) ? ("en_rev_loopback_rx_rm") : "dis_rev_loopback_rx_rm"; + localparam fnl_revloop_back_rm = (revloop_back_rm == "" || revloop_back_rm == "") ? rbc_any_revloop_back_rm : revloop_back_rm; + + // phfifo_write_clk_sel, RBC-validated + localparam rbc_all_phfifo_write_clk_sel = ((fnl_prot_mode == "test") || (fnl_phase_compensation_fifo == "register_fifo") ) ? ("tx_clk") : "pld_tx_clk"; + localparam rbc_any_phfifo_write_clk_sel = ((fnl_prot_mode == "test") || (fnl_phase_compensation_fifo == "register_fifo") ) ? ("tx_clk") : "pld_tx_clk"; + localparam fnl_phfifo_write_clk_sel = (phfifo_write_clk_sel == "" || phfifo_write_clk_sel == "") ? rbc_any_phfifo_write_clk_sel : phfifo_write_clk_sel; + + // refclk_b_clk_sel, RBC-validated + localparam rbc_all_refclk_b_clk_sel = (fnl_sup_mode == "engineering_mode") ? ("(refclk_dig,tx_pma_clock)") : "tx_pma_clock"; + localparam rbc_any_refclk_b_clk_sel = (fnl_sup_mode == "engineering_mode") ? ("tx_pma_clock") : "tx_pma_clock"; + localparam fnl_refclk_b_clk_sel = (refclk_b_clk_sel == "" || refclk_b_clk_sel == "") ? rbc_any_refclk_b_clk_sel : refclk_b_clk_sel; + + // dynamic_clk_switch, RBC-validated + localparam rbc_all_dynamic_clk_switch = "dis_dyn_clk_switch"; + localparam rbc_any_dynamic_clk_switch = "dis_dyn_clk_switch"; + localparam fnl_dynamic_clk_switch = (dynamic_clk_switch == "" || dynamic_clk_switch == "") ? rbc_any_dynamic_clk_switch : dynamic_clk_switch; + + // auto_speed_nego_gen2, RBC-validated + localparam rbc_all_auto_speed_nego_gen2 = ( (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_g2"; + localparam rbc_any_auto_speed_nego_gen2 = ( (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_g2"; + localparam fnl_auto_speed_nego_gen2 = (auto_speed_nego_gen2 == "" || auto_speed_nego_gen2 == "") ? rbc_any_auto_speed_nego_gen2 : auto_speed_nego_gen2; + + // txclk_freerun, RBC-validated + localparam rbc_all_txclk_freerun = "en_freerun_tx"; + localparam rbc_any_txclk_freerun = "en_freerun_tx"; + localparam fnl_txclk_freerun = (txclk_freerun == "" || txclk_freerun == "") ? rbc_any_txclk_freerun : txclk_freerun; + + // pcfifo_urst, RBC-validated + localparam rbc_all_pcfifo_urst = "dis_pcfifourst"; + localparam rbc_any_pcfifo_urst = "dis_pcfifourst"; + localparam fnl_pcfifo_urst = (pcfifo_urst == "" || pcfifo_urst == "") ? rbc_any_pcfifo_urst : pcfifo_urst; + + // txpcs_urst, RBC-validated + localparam rbc_all_txpcs_urst = "en_txpcs_urst"; + localparam rbc_any_txpcs_urst = "en_txpcs_urst"; + localparam fnl_txpcs_urst = (txpcs_urst == "" || txpcs_urst == "") ? rbc_any_txpcs_urst : txpcs_urst; + + // Validate input parameters against known values or RBC values + initial begin + //$display("prot_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", prot_mode, rbc_any_prot_mode, rbc_all_prot_mode, fnl_prot_mode); + if (!is_in_legal_set(prot_mode, rbc_all_prot_mode)) begin + $display("Critical Warning: parameter 'prot_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prot_mode, rbc_all_prot_mode, fnl_prot_mode); + end + //$display("sup_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", sup_mode, rbc_any_sup_mode, rbc_all_sup_mode, fnl_sup_mode); + if (!is_in_legal_set(sup_mode, rbc_all_sup_mode)) begin + $display("Critical Warning: parameter 'sup_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", sup_mode, rbc_all_sup_mode, fnl_sup_mode); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + //$display("test_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", test_mode, rbc_any_test_mode, rbc_all_test_mode, fnl_test_mode); + if (!is_in_legal_set(test_mode, rbc_all_test_mode)) begin + $display("Critical Warning: parameter 'test_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", test_mode, rbc_all_test_mode, fnl_test_mode); + end + //$display("hip_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", hip_mode, rbc_any_hip_mode, rbc_all_hip_mode, fnl_hip_mode); + if (!is_in_legal_set(hip_mode, rbc_all_hip_mode)) begin + $display("Critical Warning: parameter 'hip_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", hip_mode, rbc_all_hip_mode, fnl_hip_mode); + end + //$display("pma_dw = orig: '%s', any:'%s', all:'%s', final: '%s'", pma_dw, rbc_any_pma_dw, rbc_all_pma_dw, fnl_pma_dw); + if (!is_in_legal_set(pma_dw, rbc_all_pma_dw)) begin + $display("Critical Warning: parameter 'pma_dw' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pma_dw, rbc_all_pma_dw, fnl_pma_dw); + end + //$display("pcs_bypass = orig: '%s', any:'%s', all:'%s', final: '%s'", pcs_bypass, rbc_any_pcs_bypass, rbc_all_pcs_bypass, fnl_pcs_bypass); + if (!is_in_legal_set(pcs_bypass, rbc_all_pcs_bypass)) begin + $display("Critical Warning: parameter 'pcs_bypass' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pcs_bypass, rbc_all_pcs_bypass, fnl_pcs_bypass); + end + //$display("phase_compensation_fifo = orig: '%s', any:'%s', all:'%s', final: '%s'", phase_compensation_fifo, rbc_any_phase_compensation_fifo, rbc_all_phase_compensation_fifo, fnl_phase_compensation_fifo); + if (!is_in_legal_set(phase_compensation_fifo, rbc_all_phase_compensation_fifo)) begin + $display("Critical Warning: parameter 'phase_compensation_fifo' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", phase_compensation_fifo, rbc_all_phase_compensation_fifo, fnl_phase_compensation_fifo); + end + //$display("tx_compliance_controlled_disparity = orig: '%s', any:'%s', all:'%s', final: '%s'", tx_compliance_controlled_disparity, rbc_any_tx_compliance_controlled_disparity, rbc_all_tx_compliance_controlled_disparity, fnl_tx_compliance_controlled_disparity); + if (!is_in_legal_set(tx_compliance_controlled_disparity, rbc_all_tx_compliance_controlled_disparity)) begin + $display("Critical Warning: parameter 'tx_compliance_controlled_disparity' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", tx_compliance_controlled_disparity, rbc_all_tx_compliance_controlled_disparity, fnl_tx_compliance_controlled_disparity); + end + //$display("force_kchar = orig: '%s', any:'%s', all:'%s', final: '%s'", force_kchar, rbc_any_force_kchar, rbc_all_force_kchar, fnl_force_kchar); + if (!is_in_legal_set(force_kchar, rbc_all_force_kchar)) begin + $display("Critical Warning: parameter 'force_kchar' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", force_kchar, rbc_all_force_kchar, fnl_force_kchar); + end + //$display("force_echar = orig: '%s', any:'%s', all:'%s', final: '%s'", force_echar, rbc_any_force_echar, rbc_all_force_echar, fnl_force_echar); + if (!is_in_legal_set(force_echar, rbc_all_force_echar)) begin + $display("Critical Warning: parameter 'force_echar' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", force_echar, rbc_all_force_echar, fnl_force_echar); + end + //$display("byte_serializer = orig: '%s', any:'%s', all:'%s', final: '%s'", byte_serializer, rbc_any_byte_serializer, rbc_all_byte_serializer, fnl_byte_serializer); + if (!is_in_legal_set(byte_serializer, rbc_all_byte_serializer)) begin + $display("Critical Warning: parameter 'byte_serializer' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", byte_serializer, rbc_all_byte_serializer, fnl_byte_serializer); + end + //$display("data_selection_8b10b_encoder_input = orig: '%s', any:'%s', all:'%s', final: '%s'", data_selection_8b10b_encoder_input, rbc_any_data_selection_8b10b_encoder_input, rbc_all_data_selection_8b10b_encoder_input, fnl_data_selection_8b10b_encoder_input); + if (!is_in_legal_set(data_selection_8b10b_encoder_input, rbc_all_data_selection_8b10b_encoder_input)) begin + $display("Critical Warning: parameter 'data_selection_8b10b_encoder_input' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", data_selection_8b10b_encoder_input, rbc_all_data_selection_8b10b_encoder_input, fnl_data_selection_8b10b_encoder_input); + end + //$display("eightb_tenb_disp_ctrl = orig: '%s', any:'%s', all:'%s', final: '%s'", eightb_tenb_disp_ctrl, rbc_any_eightb_tenb_disp_ctrl, rbc_all_eightb_tenb_disp_ctrl, fnl_eightb_tenb_disp_ctrl); + if (!is_in_legal_set(eightb_tenb_disp_ctrl, rbc_all_eightb_tenb_disp_ctrl)) begin + $display("Critical Warning: parameter 'eightb_tenb_disp_ctrl' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", eightb_tenb_disp_ctrl, rbc_all_eightb_tenb_disp_ctrl, fnl_eightb_tenb_disp_ctrl); + end + //$display("eightb_tenb_encoder = orig: '%s', any:'%s', all:'%s', final: '%s'", eightb_tenb_encoder, rbc_any_eightb_tenb_encoder, rbc_all_eightb_tenb_encoder, fnl_eightb_tenb_encoder); + if (!is_in_legal_set(eightb_tenb_encoder, rbc_all_eightb_tenb_encoder)) begin + $display("Critical Warning: parameter 'eightb_tenb_encoder' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", eightb_tenb_encoder, rbc_all_eightb_tenb_encoder, fnl_eightb_tenb_encoder); + end + //$display("prbs_gen = orig: '%s', any:'%s', all:'%s', final: '%s'", prbs_gen, rbc_any_prbs_gen, rbc_all_prbs_gen, fnl_prbs_gen); + if (!is_in_legal_set(prbs_gen, rbc_all_prbs_gen)) begin + $display("Critical Warning: parameter 'prbs_gen' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prbs_gen, rbc_all_prbs_gen, fnl_prbs_gen); + end + //$display("cid_pattern = orig: '%s', any:'%s', all:'%s', final: '%s'", cid_pattern, rbc_any_cid_pattern, rbc_all_cid_pattern, fnl_cid_pattern); + if (!is_in_legal_set(cid_pattern, rbc_all_cid_pattern)) begin + $display("Critical Warning: parameter 'cid_pattern' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", cid_pattern, rbc_all_cid_pattern, fnl_cid_pattern); + end + //$display("bist_gen = orig: '%s', any:'%s', all:'%s', final: '%s'", bist_gen, rbc_any_bist_gen, rbc_all_bist_gen, fnl_bist_gen); + if (!is_in_legal_set(bist_gen, rbc_all_bist_gen)) begin + $display("Critical Warning: parameter 'bist_gen' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", bist_gen, rbc_all_bist_gen, fnl_bist_gen); + end + //$display("bit_reversal = orig: '%s', any:'%s', all:'%s', final: '%s'", bit_reversal, rbc_any_bit_reversal, rbc_all_bit_reversal, fnl_bit_reversal); + if (!is_in_legal_set(bit_reversal, rbc_all_bit_reversal)) begin + $display("Critical Warning: parameter 'bit_reversal' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", bit_reversal, rbc_all_bit_reversal, fnl_bit_reversal); + end + //$display("symbol_swap = orig: '%s', any:'%s', all:'%s', final: '%s'", symbol_swap, rbc_any_symbol_swap, rbc_all_symbol_swap, fnl_symbol_swap); + if (!is_in_legal_set(symbol_swap, rbc_all_symbol_swap)) begin + $display("Critical Warning: parameter 'symbol_swap' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", symbol_swap, rbc_all_symbol_swap, fnl_symbol_swap); + end + //$display("polarity_inversion = orig: '%s', any:'%s', all:'%s', final: '%s'", polarity_inversion, rbc_any_polarity_inversion, rbc_all_polarity_inversion, fnl_polarity_inversion); + if (!is_in_legal_set(polarity_inversion, rbc_all_polarity_inversion)) begin + $display("Critical Warning: parameter 'polarity_inversion' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", polarity_inversion, rbc_all_polarity_inversion, fnl_polarity_inversion); + end + //$display("tx_bitslip = orig: '%s', any:'%s', all:'%s', final: '%s'", tx_bitslip, rbc_any_tx_bitslip, rbc_all_tx_bitslip, fnl_tx_bitslip); + if (!is_in_legal_set(tx_bitslip, rbc_all_tx_bitslip)) begin + $display("Critical Warning: parameter 'tx_bitslip' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", tx_bitslip, rbc_all_tx_bitslip, fnl_tx_bitslip); + end + //$display("ctrl_plane_bonding_consumption = orig: '%s', any:'%s', all:'%s', final: '%s'", ctrl_plane_bonding_consumption, rbc_any_ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption, fnl_ctrl_plane_bonding_consumption); + if (!is_in_legal_set(ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption)) begin + $display("Critical Warning: parameter 'ctrl_plane_bonding_consumption' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption, fnl_ctrl_plane_bonding_consumption); + end + //$display("agg_block_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", agg_block_sel, rbc_any_agg_block_sel, rbc_all_agg_block_sel, fnl_agg_block_sel); + if (!is_in_legal_set(agg_block_sel, rbc_all_agg_block_sel)) begin + $display("Critical Warning: parameter 'agg_block_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", agg_block_sel, rbc_all_agg_block_sel, fnl_agg_block_sel); + end + //$display("ctrl_plane_bonding_distribution = orig: '%s', any:'%s', all:'%s', final: '%s'", ctrl_plane_bonding_distribution, rbc_any_ctrl_plane_bonding_distribution, rbc_all_ctrl_plane_bonding_distribution, fnl_ctrl_plane_bonding_distribution); + if (!is_in_legal_set(ctrl_plane_bonding_distribution, rbc_all_ctrl_plane_bonding_distribution)) begin + $display("Critical Warning: parameter 'ctrl_plane_bonding_distribution' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ctrl_plane_bonding_distribution, rbc_all_ctrl_plane_bonding_distribution, fnl_ctrl_plane_bonding_distribution); + end + //$display("ctrl_plane_bonding_compensation = orig: '%s', any:'%s', all:'%s', final: '%s'", ctrl_plane_bonding_compensation, rbc_any_ctrl_plane_bonding_compensation, rbc_all_ctrl_plane_bonding_compensation, fnl_ctrl_plane_bonding_compensation); + if (!is_in_legal_set(ctrl_plane_bonding_compensation, rbc_all_ctrl_plane_bonding_compensation)) begin + $display("Critical Warning: parameter 'ctrl_plane_bonding_compensation' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ctrl_plane_bonding_compensation, rbc_all_ctrl_plane_bonding_compensation, fnl_ctrl_plane_bonding_compensation); + end + //$display("bypass_pipeline_reg = orig: '%s', any:'%s', all:'%s', final: '%s'", bypass_pipeline_reg, rbc_any_bypass_pipeline_reg, rbc_all_bypass_pipeline_reg, fnl_bypass_pipeline_reg); + if (!is_in_legal_set(bypass_pipeline_reg, rbc_all_bypass_pipeline_reg)) begin + $display("Critical Warning: parameter 'bypass_pipeline_reg' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", bypass_pipeline_reg, rbc_all_bypass_pipeline_reg, fnl_bypass_pipeline_reg); + end + //$display("clock_gate_bs_enc = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_bs_enc, rbc_any_clock_gate_bs_enc, rbc_all_clock_gate_bs_enc, fnl_clock_gate_bs_enc); + if (!is_in_legal_set(clock_gate_bs_enc, rbc_all_clock_gate_bs_enc)) begin + $display("Critical Warning: parameter 'clock_gate_bs_enc' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_bs_enc, rbc_all_clock_gate_bs_enc, fnl_clock_gate_bs_enc); + end + //$display("clock_gate_prbs = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_prbs, rbc_any_clock_gate_prbs, rbc_all_clock_gate_prbs, fnl_clock_gate_prbs); + if (!is_in_legal_set(clock_gate_prbs, rbc_all_clock_gate_prbs)) begin + $display("Critical Warning: parameter 'clock_gate_prbs' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_prbs, rbc_all_clock_gate_prbs, fnl_clock_gate_prbs); + end + //$display("clock_gate_bist = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_bist, rbc_any_clock_gate_bist, rbc_all_clock_gate_bist, fnl_clock_gate_bist); + if (!is_in_legal_set(clock_gate_bist, rbc_all_clock_gate_bist)) begin + $display("Critical Warning: parameter 'clock_gate_bist' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_bist, rbc_all_clock_gate_bist, fnl_clock_gate_bist); + end + //$display("clock_gate_sw_fifowr = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_sw_fifowr, rbc_any_clock_gate_sw_fifowr, rbc_all_clock_gate_sw_fifowr, fnl_clock_gate_sw_fifowr); + if (!is_in_legal_set(clock_gate_sw_fifowr, rbc_all_clock_gate_sw_fifowr)) begin + $display("Critical Warning: parameter 'clock_gate_sw_fifowr' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_sw_fifowr, rbc_all_clock_gate_sw_fifowr, fnl_clock_gate_sw_fifowr); + end + //$display("clock_gate_dw_fifowr = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_dw_fifowr, rbc_any_clock_gate_dw_fifowr, rbc_all_clock_gate_dw_fifowr, fnl_clock_gate_dw_fifowr); + if (!is_in_legal_set(clock_gate_dw_fifowr, rbc_all_clock_gate_dw_fifowr)) begin + $display("Critical Warning: parameter 'clock_gate_dw_fifowr' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_dw_fifowr, rbc_all_clock_gate_dw_fifowr, fnl_clock_gate_dw_fifowr); + end + //$display("clock_gate_fiford = orig: '%s', any:'%s', all:'%s', final: '%s'", clock_gate_fiford, rbc_any_clock_gate_fiford, rbc_all_clock_gate_fiford, fnl_clock_gate_fiford); + if (!is_in_legal_set(clock_gate_fiford, rbc_all_clock_gate_fiford)) begin + $display("Critical Warning: parameter 'clock_gate_fiford' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clock_gate_fiford, rbc_all_clock_gate_fiford, fnl_clock_gate_fiford); + end + //$display("revloop_back_rm = orig: '%s', any:'%s', all:'%s', final: '%s'", revloop_back_rm, rbc_any_revloop_back_rm, rbc_all_revloop_back_rm, fnl_revloop_back_rm); + if (!is_in_legal_set(revloop_back_rm, rbc_all_revloop_back_rm)) begin + $display("Critical Warning: parameter 'revloop_back_rm' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", revloop_back_rm, rbc_all_revloop_back_rm, fnl_revloop_back_rm); + end + //$display("phfifo_write_clk_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", phfifo_write_clk_sel, rbc_any_phfifo_write_clk_sel, rbc_all_phfifo_write_clk_sel, fnl_phfifo_write_clk_sel); + if (!is_in_legal_set(phfifo_write_clk_sel, rbc_all_phfifo_write_clk_sel)) begin + $display("Critical Warning: parameter 'phfifo_write_clk_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", phfifo_write_clk_sel, rbc_all_phfifo_write_clk_sel, fnl_phfifo_write_clk_sel); + end + //$display("refclk_b_clk_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", refclk_b_clk_sel, rbc_any_refclk_b_clk_sel, rbc_all_refclk_b_clk_sel, fnl_refclk_b_clk_sel); + if (!is_in_legal_set(refclk_b_clk_sel, rbc_all_refclk_b_clk_sel)) begin + $display("Critical Warning: parameter 'refclk_b_clk_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", refclk_b_clk_sel, rbc_all_refclk_b_clk_sel, fnl_refclk_b_clk_sel); + end + //$display("dynamic_clk_switch = orig: '%s', any:'%s', all:'%s', final: '%s'", dynamic_clk_switch, rbc_any_dynamic_clk_switch, rbc_all_dynamic_clk_switch, fnl_dynamic_clk_switch); + if (!is_in_legal_set(dynamic_clk_switch, rbc_all_dynamic_clk_switch)) begin + $display("Critical Warning: parameter 'dynamic_clk_switch' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", dynamic_clk_switch, rbc_all_dynamic_clk_switch, fnl_dynamic_clk_switch); + end + //$display("auto_speed_nego_gen2 = orig: '%s', any:'%s', all:'%s', final: '%s'", auto_speed_nego_gen2, rbc_any_auto_speed_nego_gen2, rbc_all_auto_speed_nego_gen2, fnl_auto_speed_nego_gen2); + if (!is_in_legal_set(auto_speed_nego_gen2, rbc_all_auto_speed_nego_gen2)) begin + $display("Critical Warning: parameter 'auto_speed_nego_gen2' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", auto_speed_nego_gen2, rbc_all_auto_speed_nego_gen2, fnl_auto_speed_nego_gen2); + end + //$display("txclk_freerun = orig: '%s', any:'%s', all:'%s', final: '%s'", txclk_freerun, rbc_any_txclk_freerun, rbc_all_txclk_freerun, fnl_txclk_freerun); + if (!is_in_legal_set(txclk_freerun, rbc_all_txclk_freerun)) begin + $display("Critical Warning: parameter 'txclk_freerun' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", txclk_freerun, rbc_all_txclk_freerun, fnl_txclk_freerun); + end + //$display("pcfifo_urst = orig: '%s', any:'%s', all:'%s', final: '%s'", pcfifo_urst, rbc_any_pcfifo_urst, rbc_all_pcfifo_urst, fnl_pcfifo_urst); + if (!is_in_legal_set(pcfifo_urst, rbc_all_pcfifo_urst)) begin + $display("Critical Warning: parameter 'pcfifo_urst' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pcfifo_urst, rbc_all_pcfifo_urst, fnl_pcfifo_urst); + end + //$display("txpcs_urst = orig: '%s', any:'%s', all:'%s', final: '%s'", txpcs_urst, rbc_any_txpcs_urst, rbc_all_txpcs_urst, fnl_txpcs_urst); + if (!is_in_legal_set(txpcs_urst, rbc_all_txpcs_urst)) begin + $display("Critical Warning: parameter 'txpcs_urst' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", txpcs_urst, rbc_all_txpcs_urst, fnl_txpcs_urst); + end + end + + arriav_hssi_8g_tx_pcs #( + .prot_mode(fnl_prot_mode), + .sup_mode(fnl_sup_mode), + .avmm_group_channel_index(avmm_group_channel_index), + .channel_number(channel_number), + .cid_pattern_len(cid_pattern_len), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address), + .test_mode(fnl_test_mode), + .hip_mode(fnl_hip_mode), + .pma_dw(fnl_pma_dw), + .pcs_bypass(fnl_pcs_bypass), + .phase_compensation_fifo(fnl_phase_compensation_fifo), + .tx_compliance_controlled_disparity(fnl_tx_compliance_controlled_disparity), + .force_kchar(fnl_force_kchar), + .force_echar(fnl_force_echar), + .byte_serializer(fnl_byte_serializer), + .data_selection_8b10b_encoder_input(fnl_data_selection_8b10b_encoder_input), + .eightb_tenb_disp_ctrl(fnl_eightb_tenb_disp_ctrl), + .eightb_tenb_encoder(fnl_eightb_tenb_encoder), + .prbs_gen(fnl_prbs_gen), + .cid_pattern(fnl_cid_pattern), + .bist_gen(fnl_bist_gen), + .bit_reversal(fnl_bit_reversal), + .symbol_swap(fnl_symbol_swap), + .polarity_inversion(fnl_polarity_inversion), + .tx_bitslip(fnl_tx_bitslip), + .ctrl_plane_bonding_consumption(fnl_ctrl_plane_bonding_consumption), + .agg_block_sel(fnl_agg_block_sel), + .ctrl_plane_bonding_distribution(fnl_ctrl_plane_bonding_distribution), + .ctrl_plane_bonding_compensation(fnl_ctrl_plane_bonding_compensation), + .bypass_pipeline_reg(fnl_bypass_pipeline_reg), + .clock_gate_bs_enc(fnl_clock_gate_bs_enc), + .clock_gate_prbs(fnl_clock_gate_prbs), + .clock_gate_bist(fnl_clock_gate_bist), + .clock_gate_sw_fifowr(fnl_clock_gate_sw_fifowr), + .clock_gate_dw_fifowr(fnl_clock_gate_dw_fifowr), + .clock_gate_fiford(fnl_clock_gate_fiford), + .revloop_back_rm(fnl_revloop_back_rm), + .phfifo_write_clk_sel(fnl_phfifo_write_clk_sel), + .refclk_b_clk_sel(fnl_refclk_b_clk_sel), + .dynamic_clk_switch(fnl_dynamic_clk_switch), + .auto_speed_nego_gen2(fnl_auto_speed_nego_gen2), + .txclk_freerun(fnl_txclk_freerun), + .pcfifo_urst(fnl_pcfifo_urst), + .txpcs_urst(fnl_txpcs_urst) + ) wys ( + // ports + .aggtxpcsrst(aggtxpcsrst), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .bitslipboundaryselect(bitslipboundaryselect), + .blockselect(blockselect), + .clkout(clkout), + .coreclk(coreclk), + .datain(datain), + .dataout(dataout), + .detectrxloopin(detectrxloopin), + .detectrxloopout(detectrxloopout), + .dispcbyte(dispcbyte), + .dynclkswitchn(dynclkswitchn), + .elecidleinfersel(elecidleinfersel), + .enrevparallellpbk(enrevparallellpbk), + .fifoselectinchnldown(fifoselectinchnldown), + .fifoselectinchnlup(fifoselectinchnlup), + .fifoselectoutchnldown(fifoselectoutchnldown), + .fifoselectoutchnlup(fifoselectoutchnlup), + .grayelecidleinferselout(grayelecidleinferselout), + .hrdrst(hrdrst), + .invpol(invpol), + .observablebyteserdesclock(observablebyteserdesclock), + .parallelfdbkout(parallelfdbkout), + .phfifooverflow(phfifooverflow), + .phfiforddisable(phfiforddisable), + .phfiforeset(phfiforeset), + .phfifotxdeemph(phfifotxdeemph), + .phfifotxmargin(phfifotxmargin), + .phfifotxswing(phfifotxswing), + .phfifounderflow(phfifounderflow), + .phfifowrenable(phfifowrenable), + .pipeenrevparallellpbkin(pipeenrevparallellpbkin), + .pipeenrevparallellpbkout(pipeenrevparallellpbkout), + .pipepowerdownout(pipepowerdownout), + .pipetxdeemph(pipetxdeemph), + .pipetxmargin(pipetxmargin), + .pipetxswing(pipetxswing), + .polinvrxin(polinvrxin), + .polinvrxout(polinvrxout), + .powerdn(powerdn), + .prbscidenable(prbscidenable), + .rateswitch(rateswitch), + .rdenableinchnldown(rdenableinchnldown), + .rdenableinchnlup(rdenableinchnlup), + .rdenableoutchnldown(rdenableoutchnldown), + .rdenableoutchnlup(rdenableoutchnlup), + .rdenablesync(rdenablesync), + .refclkb(refclkb), + .refclkbreset(refclkbreset), + .refclkdig(refclkdig), + .resetpcptrs(resetpcptrs), + .resetpcptrsinchnldown(resetpcptrsinchnldown), + .resetpcptrsinchnlup(resetpcptrsinchnlup), + .revparallellpbkdata(revparallellpbkdata), + .rxpolarityin(rxpolarityin), + .rxpolarityout(rxpolarityout), + .scanmode(scanmode), + .syncdatain(syncdatain), + .txblkstart(txblkstart), + .txblkstartout(txblkstartout), + .txcomplianceout(txcomplianceout), + .txctrlplanetestbus(txctrlplanetestbus), + .txdatakouttogen3(txdatakouttogen3), + .txdataouttogen3(txdataouttogen3), + .txdatavalid(txdatavalid), + .txdatavalidouttogen3(txdatavalidouttogen3), + .txdivsync(txdivsync), + .txdivsyncinchnldown(txdivsyncinchnldown), + .txdivsyncinchnlup(txdivsyncinchnlup), + .txdivsyncoutchnldown(txdivsyncoutchnldown), + .txdivsyncoutchnlup(txdivsyncoutchnlup), + .txelecidleout(txelecidleout), + .txpcsreset(txpcsreset), + .txpipeclk(txpipeclk), + .txpipeelectidle(txpipeelectidle), + .txpipesoftreset(txpipesoftreset), + .txpmalocalclk(txpmalocalclk), + .txsynchdr(txsynchdr), + .txsynchdrout(txsynchdrout), + .txtestbus(txtestbus), + .wrenableinchnldown(wrenableinchnldown), + .wrenableinchnlup(wrenableinchnlup), + .wrenableoutchnldown(wrenableoutchnldown), + .wrenableoutchnlup(wrenableoutchnlup), + .xgmctrl(xgmctrl), + .xgmctrlenable(xgmctrlenable), + .xgmctrltoporbottom(xgmctrltoporbottom), + .xgmdatain(xgmdatain), + .xgmdataintoporbottom(xgmdataintoporbottom), + .xgmdataout(xgmdataout) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_common_pcs_pma_interface_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_common_pcs_pma_interface_rbc.sv new file mode 100644 index 0000000..3582a2f --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_common_pcs_pma_interface_rbc.sv @@ -0,0 +1,525 @@ +// (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_common_pcs_pma_interface +// + +`timescale 1 ns / 1 ps + +module av_hssi_common_pcs_pma_interface_rbc #( + // unconstrained parameters + parameter func_mode = "", // disable, eightg_only_hip, eightg_only_pld, hrdrstctrl_cmu, pma_direct + parameter prot_mode = "", // disabled_prot_mode, other_protocols, pipe_g1, pipe_g2 + parameter sup_mode = "", // engineering_mode, user_mode + + // extra unconstrained parameters found in atom map + parameter avmm_group_channel_index = 0, // 0..2 + parameter pma_if_dft_en = "dft_dis", // dft_dis + parameter pma_if_dft_val = "dft_0", // dft_0 + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0, // 0..2047 + + // constrained parameters + parameter pipe_if_g3pcs = "", // pipe_if_8gpcs + parameter selectpcs = "", // eight_g_pcs + parameter force_freqdet = "", // force0_freqdet_en, force1_freqdet_en, force_freqdet_dis + parameter ppmsel = "", // ppm_other, ppmsel_100, ppmsel_1000, ppmsel_125, ppmsel_200, ppmsel_250, ppmsel_300, ppmsel_500, ppmsel_62p5, ppmsel_default + parameter auto_speed_ena = "", // dis_auto_speed_ena, en_auto_speed_ena + parameter ppm_cnt_rst = "", // ppm_cnt_rst_dis, ppm_cnt_rst_en + parameter ppm_gen1_2_cnt = "", // cnt_32k, cnt_64k + parameter ppm_post_eidle_delay = "", // cnt_200_cycles, cnt_400_cycles + parameter ppm_deassert_early = "" // deassert_early_dis, deassert_early_en +) ( + // ports + output wire [1:0] aggaligndetsync, + input wire aggalignstatus, + output wire aggalignstatussync, + input wire aggalignstatussync0, + input wire aggalignstatussync0toporbot, + input wire aggalignstatustoporbot, + input wire aggcgcomprddall, + input wire aggcgcomprddalltoporbot, + output wire [1:0] aggcgcomprddout, + input wire aggcgcompwrall, + input wire aggcgcompwralltoporbot, + output wire [1:0] aggcgcompwrout, + output wire aggdecctl, + output wire [7:0] aggdecdata, + output wire aggdecdatavalid, + input wire aggdelcondmet0, + input wire aggdelcondmet0toporbot, + output wire aggdelcondmetout, + input wire aggendskwqd, + input wire aggendskwqdtoporbot, + input wire aggendskwrdptrs, + input wire aggendskwrdptrstoporbot, + input wire aggfifoovr0, + input wire aggfifoovr0toporbot, + output wire aggfifoovrout, + input wire aggfifordincomp0, + input wire aggfifordincomp0toporbot, + output wire aggfifordoutcomp, + input wire aggfiforstrdqd, + input wire aggfiforstrdqdtoporbot, + input wire agginsertincomplete0, + input wire agginsertincomplete0toporbot, + output wire agginsertincompleteout, + input wire agglatencycomp0, + input wire agglatencycomp0toporbot, + output wire agglatencycompout, + input wire aggrcvdclkagg, + input wire aggrcvdclkaggtoporbot, + output wire [1:0] aggrdalign, + output wire aggrdenablesync, + output wire aggrefclkdig, + output wire [1:0] aggrunningdisp, + input wire aggrxcontrolrs, + input wire aggrxcontrolrstoporbot, + input wire [7:0] aggrxdatars, + input wire [7:0] aggrxdatarstoporbot, + output wire aggrxpcsrst, + output wire aggscanmoden, + output wire aggscanshiftn, + output wire aggsyncstatus, + input wire [15:0] aggtestbus, + input wire aggtestsotopldin, + output wire aggtestsotopldout, + output wire aggtxctltc, + input wire aggtxctlts, + input wire aggtxctltstoporbot, + output wire [7:0] aggtxdatatc, + input wire [7:0] aggtxdatats, + input wire [7:0] aggtxdatatstoporbot, + output wire aggtxpcsrst, + output wire asynchdatain, + 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 blockselect, + input wire clklow, + input wire fref, + output wire freqlock, + input wire hardreset, + input wire pcs8gearlyeios, + input wire pcs8geidleexit, + output wire pcs8ggen2ngen1, + input wire pcs8gltrpma, + input wire pcs8gpcieswitch, + input wire [17:0] pcs8gpmacurrentcoeff, + output wire pcs8gpmarxfound, + output wire pcs8gpowerstatetransitiondone, + output wire pcs8grxdetectvalid, + input wire pcs8gtxdetectrx, + input wire pcs8gtxelecidle, + input wire [1:0] pcsaggaligndetsync, + output wire pcsaggalignstatus, + input wire pcsaggalignstatussync, + output wire pcsaggalignstatussync0, + output wire pcsaggalignstatussync0toporbot, + output wire pcsaggalignstatustoporbot, + output wire pcsaggcgcomprddall, + output wire pcsaggcgcomprddalltoporbot, + input wire [1:0] pcsaggcgcomprddout, + output wire pcsaggcgcompwrall, + output wire pcsaggcgcompwralltoporbot, + input wire [1:0] pcsaggcgcompwrout, + input wire pcsaggdecctl, + input wire [7:0] pcsaggdecdata, + input wire pcsaggdecdatavalid, + output wire pcsaggdelcondmet0, + output wire pcsaggdelcondmet0toporbot, + input wire pcsaggdelcondmetout, + output wire pcsaggendskwqd, + output wire pcsaggendskwqdtoporbot, + output wire pcsaggendskwrdptrs, + output wire pcsaggendskwrdptrstoporbot, + output wire pcsaggfifoovr0, + output wire pcsaggfifoovr0toporbot, + input wire pcsaggfifoovrout, + output wire pcsaggfifordincomp0, + output wire pcsaggfifordincomp0toporbot, + input wire pcsaggfifordoutcomp, + output wire pcsaggfiforstrdqd, + output wire pcsaggfiforstrdqdtoporbot, + output wire pcsagginsertincomplete0, + output wire pcsagginsertincomplete0toporbot, + input wire pcsagginsertincompleteout, + output wire pcsagglatencycomp0, + output wire pcsagglatencycomp0toporbot, + input wire pcsagglatencycompout, + output wire pcsaggrcvdclkagg, + output wire pcsaggrcvdclkaggtoporbot, + input wire [1:0] pcsaggrdalign, + input wire pcsaggrdenablesync, + input wire pcsaggrefclkdig, + input wire [1:0] pcsaggrunningdisp, + output wire pcsaggrxcontrolrs, + output wire pcsaggrxcontrolrstoporbot, + output wire [7:0] pcsaggrxdatars, + output wire [7:0] pcsaggrxdatarstoporbot, + input wire pcsaggrxpcsrst, + input wire pcsaggscanmoden, + input wire pcsaggscanshiftn, + input wire pcsaggsyncstatus, + output wire [15:0] pcsaggtestbus, + input wire pcsaggtxctltc, + output wire pcsaggtxctlts, + output wire pcsaggtxctltstoporbot, + input wire [7:0] pcsaggtxdatatc, + output wire [7:0] pcsaggtxdatats, + output wire [7:0] pcsaggtxdatatstoporbot, + input wire pcsaggtxpcsrst, + input wire pcsrefclkdig, + input wire pcsscanmoden, + input wire pcsscanshiftn, + output wire pldhclkout, + input wire pldnfrzdrv, + input wire pldpartialreconfig, + input wire pldtestsitoaggin, + output wire pldtestsitoaggout, + output wire pmaclklowout, + output wire [17:0] pmacurrentcoeff, + output wire pmaearlyeios, + output wire pmafrefout, + input wire pmahclk, + output wire [9:0] pmaiftestbus, + output wire pmaltr, + output wire pmanfrzdrv, + output wire pmapartialreconfig, + input wire [1:0] pmapcieswdone, + output wire [1:0] pmapcieswitch, + input wire pmarxdetectvalid, + input wire pmarxfound, + input wire pmarxpmarstb, + output wire pmatxdetectrx, + output wire pmatxelecidle, + input wire resetppmcntrs +); + import altera_xcvr_functions::*; + + // func_mode external parameter (no RBC) + localparam rbc_all_func_mode = "(disable,eightg_only_hip,eightg_only_pld,hrdrstctrl_cmu,pma_direct)"; + localparam rbc_any_func_mode = "disable"; + localparam fnl_func_mode = (func_mode == "" || func_mode == "") ? rbc_any_func_mode : func_mode; + + // prot_mode external parameter (no RBC) + localparam rbc_all_prot_mode = "(disabled_prot_mode,other_protocols,pipe_g1,pipe_g2)"; + localparam rbc_any_prot_mode = "disabled_prot_mode"; + 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; + + // pipe_if_g3pcs, RBC-validated + localparam rbc_all_pipe_if_g3pcs = "pipe_if_8gpcs"; + localparam rbc_any_pipe_if_g3pcs = "pipe_if_8gpcs"; + localparam fnl_pipe_if_g3pcs = (pipe_if_g3pcs == "" || pipe_if_g3pcs == "") ? rbc_any_pipe_if_g3pcs : pipe_if_g3pcs; + + // selectpcs, RBC-validated + localparam rbc_all_selectpcs = "eight_g_pcs"; + localparam rbc_any_selectpcs = "eight_g_pcs"; + localparam fnl_selectpcs = (selectpcs == "" || selectpcs == "") ? rbc_any_selectpcs : selectpcs; + + // force_freqdet, RBC-validated + localparam rbc_all_force_freqdet = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") || (fnl_func_mode == "hrdrstctrl_cmu")) ? ("force_freqdet_dis") : "(force0_freqdet_en,force1_freqdet_en,force_freqdet_dis)"; + localparam rbc_any_force_freqdet = ( (fnl_prot_mode == "disabled_prot_mode") || (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") || (fnl_func_mode == "hrdrstctrl_cmu")) ? ("force_freqdet_dis") : "force_freqdet_dis"; + localparam fnl_force_freqdet = (force_freqdet == "" || force_freqdet == "") ? rbc_any_force_freqdet : force_freqdet; + + // ppmsel, RBC-validated + localparam rbc_all_ppmsel = ( (fnl_force_freqdet != "force_freqdet_dis") || (fnl_prot_mode == "disabled_prot_mode") || (fnl_func_mode == "hrdrstctrl_cmu")) ? ("ppmsel_default") : "(ppm_other,ppmsel_100,ppmsel_1000,ppmsel_125,ppmsel_200,ppmsel_250,ppmsel_300,ppmsel_500,ppmsel_62p5,ppmsel_default)"; + localparam rbc_any_ppmsel = ( (fnl_force_freqdet != "force_freqdet_dis") || (fnl_prot_mode == "disabled_prot_mode") || (fnl_func_mode == "hrdrstctrl_cmu")) ? ("ppmsel_default") : "ppmsel_default"; + localparam fnl_ppmsel = (ppmsel == "" || ppmsel == "") ? rbc_any_ppmsel : ppmsel; + + // auto_speed_ena, RBC-validated + localparam rbc_all_auto_speed_ena = (fnl_prot_mode == "pipe_g2") ? ("en_auto_speed_ena") : "dis_auto_speed_ena"; + localparam rbc_any_auto_speed_ena = (fnl_prot_mode == "pipe_g2") ? ("en_auto_speed_ena") : "dis_auto_speed_ena"; + localparam fnl_auto_speed_ena = (auto_speed_ena == "" || auto_speed_ena == "") ? rbc_any_auto_speed_ena : auto_speed_ena; + + // ppm_cnt_rst, RBC-validated + localparam rbc_all_ppm_cnt_rst = "ppm_cnt_rst_dis"; + localparam rbc_any_ppm_cnt_rst = "ppm_cnt_rst_dis"; + localparam fnl_ppm_cnt_rst = (ppm_cnt_rst == "" || ppm_cnt_rst == "") ? rbc_any_ppm_cnt_rst : ppm_cnt_rst; + + // ppm_gen1_2_cnt, RBC-validated + localparam rbc_all_ppm_gen1_2_cnt = ((fnl_sup_mode == "engineering_mode") && ((fnl_prot_mode == "pipe_g2") || (fnl_prot_mode == "pipe_g1"))) ? ("(cnt_32k,cnt_64k)") : "cnt_32k"; + localparam rbc_any_ppm_gen1_2_cnt = ((fnl_sup_mode == "engineering_mode") && ((fnl_prot_mode == "pipe_g2") || (fnl_prot_mode == "pipe_g1"))) ? ("cnt_32k") : "cnt_32k"; + localparam fnl_ppm_gen1_2_cnt = (ppm_gen1_2_cnt == "" || ppm_gen1_2_cnt == "") ? rbc_any_ppm_gen1_2_cnt : ppm_gen1_2_cnt; + + // ppm_post_eidle_delay, RBC-validated + localparam rbc_all_ppm_post_eidle_delay = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2") ? ("(cnt_200_cycles,cnt_400_cycles)") : "cnt_200_cycles"; + localparam rbc_any_ppm_post_eidle_delay = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2") ? ("cnt_200_cycles") : "cnt_200_cycles"; + localparam fnl_ppm_post_eidle_delay = (ppm_post_eidle_delay == "" || ppm_post_eidle_delay == "") ? rbc_any_ppm_post_eidle_delay : ppm_post_eidle_delay; + + // ppm_deassert_early, RBC-validated + localparam rbc_all_ppm_deassert_early = "deassert_early_dis"; + localparam rbc_any_ppm_deassert_early = "deassert_early_dis"; + localparam fnl_ppm_deassert_early = (ppm_deassert_early == "" || ppm_deassert_early == "") ? rbc_any_ppm_deassert_early : ppm_deassert_early; + + // Validate input parameters against known values or RBC values + initial begin + //$display("func_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", func_mode, rbc_any_func_mode, rbc_all_func_mode, fnl_func_mode); + if (!is_in_legal_set(func_mode, rbc_all_func_mode)) begin + $display("Critical Warning: parameter 'func_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", func_mode, rbc_all_func_mode, fnl_func_mode); + end + //$display("prot_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", prot_mode, rbc_any_prot_mode, rbc_all_prot_mode, fnl_prot_mode); + if (!is_in_legal_set(prot_mode, rbc_all_prot_mode)) begin + $display("Critical Warning: parameter 'prot_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prot_mode, rbc_all_prot_mode, fnl_prot_mode); + end + //$display("sup_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", sup_mode, rbc_any_sup_mode, rbc_all_sup_mode, fnl_sup_mode); + if (!is_in_legal_set(sup_mode, rbc_all_sup_mode)) begin + $display("Critical Warning: parameter 'sup_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", sup_mode, rbc_all_sup_mode, fnl_sup_mode); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + //$display("pipe_if_g3pcs = orig: '%s', any:'%s', all:'%s', final: '%s'", pipe_if_g3pcs, rbc_any_pipe_if_g3pcs, rbc_all_pipe_if_g3pcs, fnl_pipe_if_g3pcs); + if (!is_in_legal_set(pipe_if_g3pcs, rbc_all_pipe_if_g3pcs)) begin + $display("Critical Warning: parameter 'pipe_if_g3pcs' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pipe_if_g3pcs, rbc_all_pipe_if_g3pcs, fnl_pipe_if_g3pcs); + end + //$display("selectpcs = orig: '%s', any:'%s', all:'%s', final: '%s'", selectpcs, rbc_any_selectpcs, rbc_all_selectpcs, fnl_selectpcs); + if (!is_in_legal_set(selectpcs, rbc_all_selectpcs)) begin + $display("Critical Warning: parameter 'selectpcs' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", selectpcs, rbc_all_selectpcs, fnl_selectpcs); + end + //$display("force_freqdet = orig: '%s', any:'%s', all:'%s', final: '%s'", force_freqdet, rbc_any_force_freqdet, rbc_all_force_freqdet, fnl_force_freqdet); + if (!is_in_legal_set(force_freqdet, rbc_all_force_freqdet)) begin + $display("Critical Warning: parameter 'force_freqdet' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", force_freqdet, rbc_all_force_freqdet, fnl_force_freqdet); + end + //$display("ppmsel = orig: '%s', any:'%s', all:'%s', final: '%s'", ppmsel, rbc_any_ppmsel, rbc_all_ppmsel, fnl_ppmsel); + if (!is_in_legal_set(ppmsel, rbc_all_ppmsel)) begin + $display("Critical Warning: parameter 'ppmsel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ppmsel, rbc_all_ppmsel, fnl_ppmsel); + end + //$display("auto_speed_ena = orig: '%s', any:'%s', all:'%s', final: '%s'", auto_speed_ena, rbc_any_auto_speed_ena, rbc_all_auto_speed_ena, fnl_auto_speed_ena); + if (!is_in_legal_set(auto_speed_ena, rbc_all_auto_speed_ena)) begin + $display("Critical Warning: parameter 'auto_speed_ena' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", auto_speed_ena, rbc_all_auto_speed_ena, fnl_auto_speed_ena); + end + //$display("ppm_cnt_rst = orig: '%s', any:'%s', all:'%s', final: '%s'", ppm_cnt_rst, rbc_any_ppm_cnt_rst, rbc_all_ppm_cnt_rst, fnl_ppm_cnt_rst); + if (!is_in_legal_set(ppm_cnt_rst, rbc_all_ppm_cnt_rst)) begin + $display("Critical Warning: parameter 'ppm_cnt_rst' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ppm_cnt_rst, rbc_all_ppm_cnt_rst, fnl_ppm_cnt_rst); + end + //$display("ppm_gen1_2_cnt = orig: '%s', any:'%s', all:'%s', final: '%s'", ppm_gen1_2_cnt, rbc_any_ppm_gen1_2_cnt, rbc_all_ppm_gen1_2_cnt, fnl_ppm_gen1_2_cnt); + if (!is_in_legal_set(ppm_gen1_2_cnt, rbc_all_ppm_gen1_2_cnt)) begin + $display("Critical Warning: parameter 'ppm_gen1_2_cnt' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ppm_gen1_2_cnt, rbc_all_ppm_gen1_2_cnt, fnl_ppm_gen1_2_cnt); + end + //$display("ppm_post_eidle_delay = orig: '%s', any:'%s', all:'%s', final: '%s'", ppm_post_eidle_delay, rbc_any_ppm_post_eidle_delay, rbc_all_ppm_post_eidle_delay, fnl_ppm_post_eidle_delay); + if (!is_in_legal_set(ppm_post_eidle_delay, rbc_all_ppm_post_eidle_delay)) begin + $display("Critical Warning: parameter 'ppm_post_eidle_delay' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ppm_post_eidle_delay, rbc_all_ppm_post_eidle_delay, fnl_ppm_post_eidle_delay); + end + //$display("ppm_deassert_early = orig: '%s', any:'%s', all:'%s', final: '%s'", ppm_deassert_early, rbc_any_ppm_deassert_early, rbc_all_ppm_deassert_early, fnl_ppm_deassert_early); + if (!is_in_legal_set(ppm_deassert_early, rbc_all_ppm_deassert_early)) begin + $display("Critical Warning: parameter 'ppm_deassert_early' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ppm_deassert_early, rbc_all_ppm_deassert_early, fnl_ppm_deassert_early); + end + end + + arriav_hssi_common_pcs_pma_interface #( + .func_mode(fnl_func_mode), + .prot_mode(fnl_prot_mode), + .sup_mode(fnl_sup_mode), + .avmm_group_channel_index(avmm_group_channel_index), + .pma_if_dft_en(pma_if_dft_en), + .pma_if_dft_val(pma_if_dft_val), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address), + .pipe_if_g3pcs(fnl_pipe_if_g3pcs), + .selectpcs(fnl_selectpcs), + .force_freqdet(fnl_force_freqdet), + .ppmsel(fnl_ppmsel), + .auto_speed_ena(fnl_auto_speed_ena), + .ppm_cnt_rst(fnl_ppm_cnt_rst), + .ppm_gen1_2_cnt(fnl_ppm_gen1_2_cnt), + .ppm_post_eidle_delay(fnl_ppm_post_eidle_delay), + .ppm_deassert_early(fnl_ppm_deassert_early) + ) wys ( + // ports + .aggaligndetsync(aggaligndetsync), + .aggalignstatus(aggalignstatus), + .aggalignstatussync(aggalignstatussync), + .aggalignstatussync0(aggalignstatussync0), + .aggalignstatussync0toporbot(aggalignstatussync0toporbot), + .aggalignstatustoporbot(aggalignstatustoporbot), + .aggcgcomprddall(aggcgcomprddall), + .aggcgcomprddalltoporbot(aggcgcomprddalltoporbot), + .aggcgcomprddout(aggcgcomprddout), + .aggcgcompwrall(aggcgcompwrall), + .aggcgcompwralltoporbot(aggcgcompwralltoporbot), + .aggcgcompwrout(aggcgcompwrout), + .aggdecctl(aggdecctl), + .aggdecdata(aggdecdata), + .aggdecdatavalid(aggdecdatavalid), + .aggdelcondmet0(aggdelcondmet0), + .aggdelcondmet0toporbot(aggdelcondmet0toporbot), + .aggdelcondmetout(aggdelcondmetout), + .aggendskwqd(aggendskwqd), + .aggendskwqdtoporbot(aggendskwqdtoporbot), + .aggendskwrdptrs(aggendskwrdptrs), + .aggendskwrdptrstoporbot(aggendskwrdptrstoporbot), + .aggfifoovr0(aggfifoovr0), + .aggfifoovr0toporbot(aggfifoovr0toporbot), + .aggfifoovrout(aggfifoovrout), + .aggfifordincomp0(aggfifordincomp0), + .aggfifordincomp0toporbot(aggfifordincomp0toporbot), + .aggfifordoutcomp(aggfifordoutcomp), + .aggfiforstrdqd(aggfiforstrdqd), + .aggfiforstrdqdtoporbot(aggfiforstrdqdtoporbot), + .agginsertincomplete0(agginsertincomplete0), + .agginsertincomplete0toporbot(agginsertincomplete0toporbot), + .agginsertincompleteout(agginsertincompleteout), + .agglatencycomp0(agglatencycomp0), + .agglatencycomp0toporbot(agglatencycomp0toporbot), + .agglatencycompout(agglatencycompout), + .aggrcvdclkagg(aggrcvdclkagg), + .aggrcvdclkaggtoporbot(aggrcvdclkaggtoporbot), + .aggrdalign(aggrdalign), + .aggrdenablesync(aggrdenablesync), + .aggrefclkdig(aggrefclkdig), + .aggrunningdisp(aggrunningdisp), + .aggrxcontrolrs(aggrxcontrolrs), + .aggrxcontrolrstoporbot(aggrxcontrolrstoporbot), + .aggrxdatars(aggrxdatars), + .aggrxdatarstoporbot(aggrxdatarstoporbot), + .aggrxpcsrst(aggrxpcsrst), + .aggscanmoden(aggscanmoden), + .aggscanshiftn(aggscanshiftn), + .aggsyncstatus(aggsyncstatus), + .aggtestbus(aggtestbus), + .aggtestsotopldin(aggtestsotopldin), + .aggtestsotopldout(aggtestsotopldout), + .aggtxctltc(aggtxctltc), + .aggtxctlts(aggtxctlts), + .aggtxctltstoporbot(aggtxctltstoporbot), + .aggtxdatatc(aggtxdatatc), + .aggtxdatats(aggtxdatats), + .aggtxdatatstoporbot(aggtxdatatstoporbot), + .aggtxpcsrst(aggtxpcsrst), + .asynchdatain(asynchdatain), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .blockselect(blockselect), + .clklow(clklow), + .fref(fref), + .freqlock(freqlock), + .hardreset(hardreset), + .pcs8gearlyeios(pcs8gearlyeios), + .pcs8geidleexit(pcs8geidleexit), + .pcs8ggen2ngen1(pcs8ggen2ngen1), + .pcs8gltrpma(pcs8gltrpma), + .pcs8gpcieswitch(pcs8gpcieswitch), + .pcs8gpmacurrentcoeff(pcs8gpmacurrentcoeff), + .pcs8gpmarxfound(pcs8gpmarxfound), + .pcs8gpowerstatetransitiondone(pcs8gpowerstatetransitiondone), + .pcs8grxdetectvalid(pcs8grxdetectvalid), + .pcs8gtxdetectrx(pcs8gtxdetectrx), + .pcs8gtxelecidle(pcs8gtxelecidle), + .pcsaggaligndetsync(pcsaggaligndetsync), + .pcsaggalignstatus(pcsaggalignstatus), + .pcsaggalignstatussync(pcsaggalignstatussync), + .pcsaggalignstatussync0(pcsaggalignstatussync0), + .pcsaggalignstatussync0toporbot(pcsaggalignstatussync0toporbot), + .pcsaggalignstatustoporbot(pcsaggalignstatustoporbot), + .pcsaggcgcomprddall(pcsaggcgcomprddall), + .pcsaggcgcomprddalltoporbot(pcsaggcgcomprddalltoporbot), + .pcsaggcgcomprddout(pcsaggcgcomprddout), + .pcsaggcgcompwrall(pcsaggcgcompwrall), + .pcsaggcgcompwralltoporbot(pcsaggcgcompwralltoporbot), + .pcsaggcgcompwrout(pcsaggcgcompwrout), + .pcsaggdecctl(pcsaggdecctl), + .pcsaggdecdata(pcsaggdecdata), + .pcsaggdecdatavalid(pcsaggdecdatavalid), + .pcsaggdelcondmet0(pcsaggdelcondmet0), + .pcsaggdelcondmet0toporbot(pcsaggdelcondmet0toporbot), + .pcsaggdelcondmetout(pcsaggdelcondmetout), + .pcsaggendskwqd(pcsaggendskwqd), + .pcsaggendskwqdtoporbot(pcsaggendskwqdtoporbot), + .pcsaggendskwrdptrs(pcsaggendskwrdptrs), + .pcsaggendskwrdptrstoporbot(pcsaggendskwrdptrstoporbot), + .pcsaggfifoovr0(pcsaggfifoovr0), + .pcsaggfifoovr0toporbot(pcsaggfifoovr0toporbot), + .pcsaggfifoovrout(pcsaggfifoovrout), + .pcsaggfifordincomp0(pcsaggfifordincomp0), + .pcsaggfifordincomp0toporbot(pcsaggfifordincomp0toporbot), + .pcsaggfifordoutcomp(pcsaggfifordoutcomp), + .pcsaggfiforstrdqd(pcsaggfiforstrdqd), + .pcsaggfiforstrdqdtoporbot(pcsaggfiforstrdqdtoporbot), + .pcsagginsertincomplete0(pcsagginsertincomplete0), + .pcsagginsertincomplete0toporbot(pcsagginsertincomplete0toporbot), + .pcsagginsertincompleteout(pcsagginsertincompleteout), + .pcsagglatencycomp0(pcsagglatencycomp0), + .pcsagglatencycomp0toporbot(pcsagglatencycomp0toporbot), + .pcsagglatencycompout(pcsagglatencycompout), + .pcsaggrcvdclkagg(pcsaggrcvdclkagg), + .pcsaggrcvdclkaggtoporbot(pcsaggrcvdclkaggtoporbot), + .pcsaggrdalign(pcsaggrdalign), + .pcsaggrdenablesync(pcsaggrdenablesync), + .pcsaggrefclkdig(pcsaggrefclkdig), + .pcsaggrunningdisp(pcsaggrunningdisp), + .pcsaggrxcontrolrs(pcsaggrxcontrolrs), + .pcsaggrxcontrolrstoporbot(pcsaggrxcontrolrstoporbot), + .pcsaggrxdatars(pcsaggrxdatars), + .pcsaggrxdatarstoporbot(pcsaggrxdatarstoporbot), + .pcsaggrxpcsrst(pcsaggrxpcsrst), + .pcsaggscanmoden(pcsaggscanmoden), + .pcsaggscanshiftn(pcsaggscanshiftn), + .pcsaggsyncstatus(pcsaggsyncstatus), + .pcsaggtestbus(pcsaggtestbus), + .pcsaggtxctltc(pcsaggtxctltc), + .pcsaggtxctlts(pcsaggtxctlts), + .pcsaggtxctltstoporbot(pcsaggtxctltstoporbot), + .pcsaggtxdatatc(pcsaggtxdatatc), + .pcsaggtxdatats(pcsaggtxdatats), + .pcsaggtxdatatstoporbot(pcsaggtxdatatstoporbot), + .pcsaggtxpcsrst(pcsaggtxpcsrst), + .pcsrefclkdig(pcsrefclkdig), + .pcsscanmoden(pcsscanmoden), + .pcsscanshiftn(pcsscanshiftn), + .pldhclkout(pldhclkout), + .pldnfrzdrv(pldnfrzdrv), + .pldpartialreconfig(pldpartialreconfig), + .pldtestsitoaggin(pldtestsitoaggin), + .pldtestsitoaggout(pldtestsitoaggout), + .pmaclklowout(pmaclklowout), + .pmacurrentcoeff(pmacurrentcoeff), + .pmaearlyeios(pmaearlyeios), + .pmafrefout(pmafrefout), + .pmahclk(pmahclk), + .pmaiftestbus(pmaiftestbus), + .pmaltr(pmaltr), + .pmanfrzdrv(pmanfrzdrv), + .pmapartialreconfig(pmapartialreconfig), + .pmapcieswdone(pmapcieswdone), + .pmapcieswitch(pmapcieswitch), + .pmarxdetectvalid(pmarxdetectvalid), + .pmarxfound(pmarxfound), + .pmarxpmarstb(pmarxpmarstb), + .pmatxdetectrx(pmatxdetectrx), + .pmatxelecidle(pmatxelecidle), + .resetppmcntrs(resetppmcntrs) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_common_pld_pcs_interface_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_common_pld_pcs_interface_rbc.sv new file mode 100644 index 0000000..6d0d108 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_common_pld_pcs_interface_rbc.sv @@ -0,0 +1,421 @@ +// (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_common_pld_pcs_interface +// + +`timescale 1 ns / 1 ps + +module av_hssi_common_pld_pcs_interface_rbc #( + // unconstrained parameters + + // extra unconstrained parameters found in atom map + parameter avmm_group_channel_index = 0, // 0..2 + parameter hip_enable = "hip_disable", // hip_disable, hip_enable + parameter hrdrstctrl_en_cfg = "hrst_dis_cfg", // hrst_dis_cfg, hrst_en_cfg + parameter hrdrstctrl_en_cfgusr = "hrst_dis_cfgusr", // hrst_dis_cfgusr, hrst_en_cfgusr + parameter pld_side_data_source = "pld", // hip, pld + parameter pld_side_reserved_source0 = "pld_res0", // hip_res0, pld_res0 + parameter pld_side_reserved_source1 = "pld_res1", // hip_res1, pld_res1 + parameter pld_side_reserved_source10 = "pld_res10", // hip_res10, pld_res10 + parameter pld_side_reserved_source11 = "pld_res11", // hip_res11, pld_res11 + parameter pld_side_reserved_source2 = "pld_res2", // hip_res2, pld_res2 + parameter pld_side_reserved_source3 = "pld_res3", // hip_res3, pld_res3 + parameter pld_side_reserved_source4 = "pld_res4", // hip_res4, pld_res4 + parameter pld_side_reserved_source5 = "pld_res5", // hip_res5, pld_res5 + parameter pld_side_reserved_source6 = "pld_res6", // hip_res6, pld_res6 + parameter pld_side_reserved_source7 = "pld_res7", // hip_res7, pld_res7 + parameter pld_side_reserved_source8 = "pld_res8", // hip_res8, pld_res8 + parameter pld_side_reserved_source9 = "pld_res9", // hip_res9, pld_res9 + parameter testbus_sel = "eight_g_pcs", // eight_g_pcs, pma_if + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0, // 0..2047 + parameter usrmode_sel4rst = "usermode" // last_frz, usermode + + // constrained parameters +) ( + // ports + output wire asynchdatain, + 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 blockselect, + output wire [2:0] emsipcomclkout, + input wire [37:0] emsipcomin, + output wire [26:0] emsipcomout, + output wire emsipenablediocsrrdydly, + input wire [19:0] pcs8gchnltestbusout, + output wire [2:0] pcs8geidleinfersel, + output wire pcs8ghardreset, + output wire pcs8gltr, + input wire pcs8gphystatus, + output wire [3:0] pcs8gpldextrain, + input wire [2:0] pcs8gpldextraout, + output wire [1:0] pcs8gpowerdown, + output wire pcs8gprbsciden, + output wire pcs8grate, + output wire pcs8grefclkdig, + output wire pcs8grefclkdig2, + input wire pcs8grxelecidle, + output wire pcs8grxpolarity, + input wire [2:0] pcs8grxstatus, + input wire pcs8grxvalid, + output wire pcs8gscanmoden, + output wire pcs8gscanshift, + output wire [5:0] pcs8gtestsi, + input wire [5:0] pcs8gtestso, + output wire pcs8gtxdeemph, + output wire pcs8gtxdetectrxloopback, + output wire pcs8gtxelecidle, + output wire [2:0] pcs8gtxmargin, + output wire pcs8gtxswing, + output wire pcsaggrefclkdig, + output wire pcsaggscanmoden, + output wire pcsaggscanshift, + output wire pcsaggtestsi, + input wire pcsaggtestso, + output wire pcspcspmaifrefclkdig, + output wire pcspcspmaifscanmoden, + output wire pcspcspmaifscanshiftn, + output wire pcspmaifhardreset, + input wire [9:0] pcspmaiftestbusout, + output wire pcspmaiftestsi, + input wire pcspmaiftestso, + output wire pld8gphystatus, + input wire [1:0] pld8gpowerdown, + input wire pld8gprbsciden, + input wire pld8grefclkdig, + input wire pld8grefclkdig2, + output wire pld8grxelecidle, + input wire pld8grxpolarity, + output wire [2:0] pld8grxstatus, + output wire pld8grxvalid, + input wire pld8gtxdeemph, + input wire pld8gtxdetectrxloopback, + input wire pld8gtxelecidle, + input wire [2:0] pld8gtxmargin, + input wire pld8gtxswing, + input wire pldaggrefclkdig, + output wire pldclklow, + input wire [2:0] pldeidleinfersel, + output wire pldfref, + input wire pldhclkin, + input wire pldltr, + output wire pldnfrzdrv, + input wire pldpartialreconfigin, + output wire pldpartialreconfigout, + input wire pldpcspmaifrefclkdig, + input wire pldrate, + input wire [11:0] pldreservedin, + output wire [10:0] pldreservedout, + input wire pldscanmoden, + input wire pldscanshiftn, + output wire [19:0] pldtestdata, + input wire pmaclklow, + input wire pmafref, + output wire rstsel, + output wire usrrstsel +); + import altera_xcvr_functions::*; + + // hip_enable external parameter (no RBC) + localparam rbc_all_hip_enable = "(hip_disable,hip_enable)"; + localparam rbc_any_hip_enable = "hip_disable"; + localparam fnl_hip_enable = (hip_enable == "" || hip_enable == "") ? rbc_any_hip_enable : hip_enable; + + // hrdrstctrl_en_cfg external parameter (no RBC) + localparam rbc_all_hrdrstctrl_en_cfg = "(hrst_dis_cfg,hrst_en_cfg)"; + localparam rbc_any_hrdrstctrl_en_cfg = "hrst_dis_cfg"; + localparam fnl_hrdrstctrl_en_cfg = (hrdrstctrl_en_cfg == "" || hrdrstctrl_en_cfg == "") ? rbc_any_hrdrstctrl_en_cfg : hrdrstctrl_en_cfg; + + // hrdrstctrl_en_cfgusr external parameter (no RBC) + localparam rbc_all_hrdrstctrl_en_cfgusr = "(hrst_dis_cfgusr,hrst_en_cfgusr)"; + localparam rbc_any_hrdrstctrl_en_cfgusr = "hrst_dis_cfgusr"; + localparam fnl_hrdrstctrl_en_cfgusr = (hrdrstctrl_en_cfgusr == "" || hrdrstctrl_en_cfgusr == "") ? rbc_any_hrdrstctrl_en_cfgusr : hrdrstctrl_en_cfgusr; + + // pld_side_data_source external parameter (no RBC) + localparam rbc_all_pld_side_data_source = "(hip,pld)"; + localparam rbc_any_pld_side_data_source = "pld"; + localparam fnl_pld_side_data_source = (pld_side_data_source == "" || pld_side_data_source == "") ? rbc_any_pld_side_data_source : pld_side_data_source; + + // pld_side_reserved_source0 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source0 = "(hip_res0,pld_res0)"; + localparam rbc_any_pld_side_reserved_source0 = "pld_res0"; + localparam fnl_pld_side_reserved_source0 = (pld_side_reserved_source0 == "" || pld_side_reserved_source0 == "") ? rbc_any_pld_side_reserved_source0 : pld_side_reserved_source0; + + // pld_side_reserved_source1 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source1 = "(hip_res1,pld_res1)"; + localparam rbc_any_pld_side_reserved_source1 = "pld_res1"; + localparam fnl_pld_side_reserved_source1 = (pld_side_reserved_source1 == "" || pld_side_reserved_source1 == "") ? rbc_any_pld_side_reserved_source1 : pld_side_reserved_source1; + + // pld_side_reserved_source10 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source10 = "(hip_res10,pld_res10)"; + localparam rbc_any_pld_side_reserved_source10 = "pld_res10"; + localparam fnl_pld_side_reserved_source10 = (pld_side_reserved_source10 == "" || pld_side_reserved_source10 == "") ? rbc_any_pld_side_reserved_source10 : pld_side_reserved_source10; + + // pld_side_reserved_source11 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source11 = "(hip_res11,pld_res11)"; + localparam rbc_any_pld_side_reserved_source11 = "pld_res11"; + localparam fnl_pld_side_reserved_source11 = (pld_side_reserved_source11 == "" || pld_side_reserved_source11 == "") ? rbc_any_pld_side_reserved_source11 : pld_side_reserved_source11; + + // pld_side_reserved_source2 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source2 = "(hip_res2,pld_res2)"; + localparam rbc_any_pld_side_reserved_source2 = "pld_res2"; + localparam fnl_pld_side_reserved_source2 = (pld_side_reserved_source2 == "" || pld_side_reserved_source2 == "") ? rbc_any_pld_side_reserved_source2 : pld_side_reserved_source2; + + // pld_side_reserved_source3 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source3 = "(hip_res3,pld_res3)"; + localparam rbc_any_pld_side_reserved_source3 = "pld_res3"; + localparam fnl_pld_side_reserved_source3 = (pld_side_reserved_source3 == "" || pld_side_reserved_source3 == "") ? rbc_any_pld_side_reserved_source3 : pld_side_reserved_source3; + + // pld_side_reserved_source4 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source4 = "(hip_res4,pld_res4)"; + localparam rbc_any_pld_side_reserved_source4 = "pld_res4"; + localparam fnl_pld_side_reserved_source4 = (pld_side_reserved_source4 == "" || pld_side_reserved_source4 == "") ? rbc_any_pld_side_reserved_source4 : pld_side_reserved_source4; + + // pld_side_reserved_source5 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source5 = "(hip_res5,pld_res5)"; + localparam rbc_any_pld_side_reserved_source5 = "pld_res5"; + localparam fnl_pld_side_reserved_source5 = (pld_side_reserved_source5 == "" || pld_side_reserved_source5 == "") ? rbc_any_pld_side_reserved_source5 : pld_side_reserved_source5; + + // pld_side_reserved_source6 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source6 = "(hip_res6,pld_res6)"; + localparam rbc_any_pld_side_reserved_source6 = "pld_res6"; + localparam fnl_pld_side_reserved_source6 = (pld_side_reserved_source6 == "" || pld_side_reserved_source6 == "") ? rbc_any_pld_side_reserved_source6 : pld_side_reserved_source6; + + // pld_side_reserved_source7 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source7 = "(hip_res7,pld_res7)"; + localparam rbc_any_pld_side_reserved_source7 = "pld_res7"; + localparam fnl_pld_side_reserved_source7 = (pld_side_reserved_source7 == "" || pld_side_reserved_source7 == "") ? rbc_any_pld_side_reserved_source7 : pld_side_reserved_source7; + + // pld_side_reserved_source8 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source8 = "(hip_res8,pld_res8)"; + localparam rbc_any_pld_side_reserved_source8 = "pld_res8"; + localparam fnl_pld_side_reserved_source8 = (pld_side_reserved_source8 == "" || pld_side_reserved_source8 == "") ? rbc_any_pld_side_reserved_source8 : pld_side_reserved_source8; + + // pld_side_reserved_source9 external parameter (no RBC) + localparam rbc_all_pld_side_reserved_source9 = "(hip_res9,pld_res9)"; + localparam rbc_any_pld_side_reserved_source9 = "pld_res9"; + localparam fnl_pld_side_reserved_source9 = (pld_side_reserved_source9 == "" || pld_side_reserved_source9 == "") ? rbc_any_pld_side_reserved_source9 : pld_side_reserved_source9; + + // testbus_sel external parameter (no RBC) + localparam rbc_all_testbus_sel = "(eight_g_pcs,pma_if)"; + localparam rbc_any_testbus_sel = "eight_g_pcs"; + localparam fnl_testbus_sel = (testbus_sel == "" || testbus_sel == "") ? rbc_any_testbus_sel : testbus_sel; + + // 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; + + // usrmode_sel4rst external parameter (no RBC) + localparam rbc_all_usrmode_sel4rst = "(last_frz,usermode)"; + localparam rbc_any_usrmode_sel4rst = "usermode"; + localparam fnl_usrmode_sel4rst = (usrmode_sel4rst == "" || usrmode_sel4rst == "") ? rbc_any_usrmode_sel4rst : usrmode_sel4rst; + + // Validate input parameters against known values or RBC values + initial begin + //$display("hip_enable = orig: '%s', any:'%s', all:'%s', final: '%s'", hip_enable, rbc_any_hip_enable, rbc_all_hip_enable, fnl_hip_enable); + if (!is_in_legal_set(hip_enable, rbc_all_hip_enable)) begin + $display("Critical Warning: parameter 'hip_enable' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", hip_enable, rbc_all_hip_enable, fnl_hip_enable); + end + //$display("hrdrstctrl_en_cfg = orig: '%s', any:'%s', all:'%s', final: '%s'", hrdrstctrl_en_cfg, rbc_any_hrdrstctrl_en_cfg, rbc_all_hrdrstctrl_en_cfg, fnl_hrdrstctrl_en_cfg); + if (!is_in_legal_set(hrdrstctrl_en_cfg, rbc_all_hrdrstctrl_en_cfg)) begin + $display("Critical Warning: parameter 'hrdrstctrl_en_cfg' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", hrdrstctrl_en_cfg, rbc_all_hrdrstctrl_en_cfg, fnl_hrdrstctrl_en_cfg); + end + //$display("hrdrstctrl_en_cfgusr = orig: '%s', any:'%s', all:'%s', final: '%s'", hrdrstctrl_en_cfgusr, rbc_any_hrdrstctrl_en_cfgusr, rbc_all_hrdrstctrl_en_cfgusr, fnl_hrdrstctrl_en_cfgusr); + if (!is_in_legal_set(hrdrstctrl_en_cfgusr, rbc_all_hrdrstctrl_en_cfgusr)) begin + $display("Critical Warning: parameter 'hrdrstctrl_en_cfgusr' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", hrdrstctrl_en_cfgusr, rbc_all_hrdrstctrl_en_cfgusr, fnl_hrdrstctrl_en_cfgusr); + end + //$display("pld_side_data_source = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_data_source, rbc_any_pld_side_data_source, rbc_all_pld_side_data_source, fnl_pld_side_data_source); + if (!is_in_legal_set(pld_side_data_source, rbc_all_pld_side_data_source)) begin + $display("Critical Warning: parameter 'pld_side_data_source' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_data_source, rbc_all_pld_side_data_source, fnl_pld_side_data_source); + end + //$display("pld_side_reserved_source0 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source0, rbc_any_pld_side_reserved_source0, rbc_all_pld_side_reserved_source0, fnl_pld_side_reserved_source0); + if (!is_in_legal_set(pld_side_reserved_source0, rbc_all_pld_side_reserved_source0)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source0' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source0, rbc_all_pld_side_reserved_source0, fnl_pld_side_reserved_source0); + end + //$display("pld_side_reserved_source1 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source1, rbc_any_pld_side_reserved_source1, rbc_all_pld_side_reserved_source1, fnl_pld_side_reserved_source1); + if (!is_in_legal_set(pld_side_reserved_source1, rbc_all_pld_side_reserved_source1)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source1' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source1, rbc_all_pld_side_reserved_source1, fnl_pld_side_reserved_source1); + end + //$display("pld_side_reserved_source10 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source10, rbc_any_pld_side_reserved_source10, rbc_all_pld_side_reserved_source10, fnl_pld_side_reserved_source10); + if (!is_in_legal_set(pld_side_reserved_source10, rbc_all_pld_side_reserved_source10)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source10' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source10, rbc_all_pld_side_reserved_source10, fnl_pld_side_reserved_source10); + end + //$display("pld_side_reserved_source11 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source11, rbc_any_pld_side_reserved_source11, rbc_all_pld_side_reserved_source11, fnl_pld_side_reserved_source11); + if (!is_in_legal_set(pld_side_reserved_source11, rbc_all_pld_side_reserved_source11)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source11' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source11, rbc_all_pld_side_reserved_source11, fnl_pld_side_reserved_source11); + end + //$display("pld_side_reserved_source2 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source2, rbc_any_pld_side_reserved_source2, rbc_all_pld_side_reserved_source2, fnl_pld_side_reserved_source2); + if (!is_in_legal_set(pld_side_reserved_source2, rbc_all_pld_side_reserved_source2)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source2' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source2, rbc_all_pld_side_reserved_source2, fnl_pld_side_reserved_source2); + end + //$display("pld_side_reserved_source3 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source3, rbc_any_pld_side_reserved_source3, rbc_all_pld_side_reserved_source3, fnl_pld_side_reserved_source3); + if (!is_in_legal_set(pld_side_reserved_source3, rbc_all_pld_side_reserved_source3)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source3' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source3, rbc_all_pld_side_reserved_source3, fnl_pld_side_reserved_source3); + end + //$display("pld_side_reserved_source4 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source4, rbc_any_pld_side_reserved_source4, rbc_all_pld_side_reserved_source4, fnl_pld_side_reserved_source4); + if (!is_in_legal_set(pld_side_reserved_source4, rbc_all_pld_side_reserved_source4)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source4' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source4, rbc_all_pld_side_reserved_source4, fnl_pld_side_reserved_source4); + end + //$display("pld_side_reserved_source5 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source5, rbc_any_pld_side_reserved_source5, rbc_all_pld_side_reserved_source5, fnl_pld_side_reserved_source5); + if (!is_in_legal_set(pld_side_reserved_source5, rbc_all_pld_side_reserved_source5)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source5' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source5, rbc_all_pld_side_reserved_source5, fnl_pld_side_reserved_source5); + end + //$display("pld_side_reserved_source6 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source6, rbc_any_pld_side_reserved_source6, rbc_all_pld_side_reserved_source6, fnl_pld_side_reserved_source6); + if (!is_in_legal_set(pld_side_reserved_source6, rbc_all_pld_side_reserved_source6)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source6' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source6, rbc_all_pld_side_reserved_source6, fnl_pld_side_reserved_source6); + end + //$display("pld_side_reserved_source7 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source7, rbc_any_pld_side_reserved_source7, rbc_all_pld_side_reserved_source7, fnl_pld_side_reserved_source7); + if (!is_in_legal_set(pld_side_reserved_source7, rbc_all_pld_side_reserved_source7)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source7' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source7, rbc_all_pld_side_reserved_source7, fnl_pld_side_reserved_source7); + end + //$display("pld_side_reserved_source8 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source8, rbc_any_pld_side_reserved_source8, rbc_all_pld_side_reserved_source8, fnl_pld_side_reserved_source8); + if (!is_in_legal_set(pld_side_reserved_source8, rbc_all_pld_side_reserved_source8)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source8' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source8, rbc_all_pld_side_reserved_source8, fnl_pld_side_reserved_source8); + end + //$display("pld_side_reserved_source9 = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_reserved_source9, rbc_any_pld_side_reserved_source9, rbc_all_pld_side_reserved_source9, fnl_pld_side_reserved_source9); + if (!is_in_legal_set(pld_side_reserved_source9, rbc_all_pld_side_reserved_source9)) begin + $display("Critical Warning: parameter 'pld_side_reserved_source9' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_reserved_source9, rbc_all_pld_side_reserved_source9, fnl_pld_side_reserved_source9); + end + //$display("testbus_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", testbus_sel, rbc_any_testbus_sel, rbc_all_testbus_sel, fnl_testbus_sel); + if (!is_in_legal_set(testbus_sel, rbc_all_testbus_sel)) begin + $display("Critical Warning: parameter 'testbus_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", testbus_sel, rbc_all_testbus_sel, fnl_testbus_sel); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + //$display("usrmode_sel4rst = orig: '%s', any:'%s', all:'%s', final: '%s'", usrmode_sel4rst, rbc_any_usrmode_sel4rst, rbc_all_usrmode_sel4rst, fnl_usrmode_sel4rst); + if (!is_in_legal_set(usrmode_sel4rst, rbc_all_usrmode_sel4rst)) begin + $display("Critical Warning: parameter 'usrmode_sel4rst' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", usrmode_sel4rst, rbc_all_usrmode_sel4rst, fnl_usrmode_sel4rst); + end + end + + arriav_hssi_common_pld_pcs_interface #( + .avmm_group_channel_index(avmm_group_channel_index), + .hip_enable(fnl_hip_enable), + .hrdrstctrl_en_cfg(fnl_hrdrstctrl_en_cfg), + .hrdrstctrl_en_cfgusr(fnl_hrdrstctrl_en_cfgusr), + .pld_side_data_source(fnl_pld_side_data_source), + .pld_side_reserved_source0(fnl_pld_side_reserved_source0), + .pld_side_reserved_source1(fnl_pld_side_reserved_source1), + .pld_side_reserved_source10(fnl_pld_side_reserved_source10), + .pld_side_reserved_source11(fnl_pld_side_reserved_source11), + .pld_side_reserved_source2(fnl_pld_side_reserved_source2), + .pld_side_reserved_source3(fnl_pld_side_reserved_source3), + .pld_side_reserved_source4(fnl_pld_side_reserved_source4), + .pld_side_reserved_source5(fnl_pld_side_reserved_source5), + .pld_side_reserved_source6(fnl_pld_side_reserved_source6), + .pld_side_reserved_source7(fnl_pld_side_reserved_source7), + .pld_side_reserved_source8(fnl_pld_side_reserved_source8), + .pld_side_reserved_source9(fnl_pld_side_reserved_source9), + .testbus_sel(fnl_testbus_sel), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address), + .usrmode_sel4rst(fnl_usrmode_sel4rst) + ) wys ( + // ports + .asynchdatain(asynchdatain), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .blockselect(blockselect), + .emsipcomclkout(emsipcomclkout), + .emsipcomin(emsipcomin), + .emsipcomout(emsipcomout), + .emsipenablediocsrrdydly(emsipenablediocsrrdydly), + .pcs8gchnltestbusout(pcs8gchnltestbusout), + .pcs8geidleinfersel(pcs8geidleinfersel), + .pcs8ghardreset(pcs8ghardreset), + .pcs8gltr(pcs8gltr), + .pcs8gphystatus(pcs8gphystatus), + .pcs8gpldextrain(pcs8gpldextrain), + .pcs8gpldextraout(pcs8gpldextraout), + .pcs8gpowerdown(pcs8gpowerdown), + .pcs8gprbsciden(pcs8gprbsciden), + .pcs8grate(pcs8grate), + .pcs8grefclkdig(pcs8grefclkdig), + .pcs8grefclkdig2(pcs8grefclkdig2), + .pcs8grxelecidle(pcs8grxelecidle), + .pcs8grxpolarity(pcs8grxpolarity), + .pcs8grxstatus(pcs8grxstatus), + .pcs8grxvalid(pcs8grxvalid), + .pcs8gscanmoden(pcs8gscanmoden), + .pcs8gscanshift(pcs8gscanshift), + .pcs8gtestsi(pcs8gtestsi), + .pcs8gtestso(pcs8gtestso), + .pcs8gtxdeemph(pcs8gtxdeemph), + .pcs8gtxdetectrxloopback(pcs8gtxdetectrxloopback), + .pcs8gtxelecidle(pcs8gtxelecidle), + .pcs8gtxmargin(pcs8gtxmargin), + .pcs8gtxswing(pcs8gtxswing), + .pcsaggrefclkdig(pcsaggrefclkdig), + .pcsaggscanmoden(pcsaggscanmoden), + .pcsaggscanshift(pcsaggscanshift), + .pcsaggtestsi(pcsaggtestsi), + .pcsaggtestso(pcsaggtestso), + .pcspcspmaifrefclkdig(pcspcspmaifrefclkdig), + .pcspcspmaifscanmoden(pcspcspmaifscanmoden), + .pcspcspmaifscanshiftn(pcspcspmaifscanshiftn), + .pcspmaifhardreset(pcspmaifhardreset), + .pcspmaiftestbusout(pcspmaiftestbusout), + .pcspmaiftestsi(pcspmaiftestsi), + .pcspmaiftestso(pcspmaiftestso), + .pld8gphystatus(pld8gphystatus), + .pld8gpowerdown(pld8gpowerdown), + .pld8gprbsciden(pld8gprbsciden), + .pld8grefclkdig(pld8grefclkdig), + .pld8grefclkdig2(pld8grefclkdig2), + .pld8grxelecidle(pld8grxelecidle), + .pld8grxpolarity(pld8grxpolarity), + .pld8grxstatus(pld8grxstatus), + .pld8grxvalid(pld8grxvalid), + .pld8gtxdeemph(pld8gtxdeemph), + .pld8gtxdetectrxloopback(pld8gtxdetectrxloopback), + .pld8gtxelecidle(pld8gtxelecidle), + .pld8gtxmargin(pld8gtxmargin), + .pld8gtxswing(pld8gtxswing), + .pldaggrefclkdig(pldaggrefclkdig), + .pldclklow(pldclklow), + .pldeidleinfersel(pldeidleinfersel), + .pldfref(pldfref), + .pldhclkin(pldhclkin), + .pldltr(pldltr), + .pldnfrzdrv(pldnfrzdrv), + .pldpartialreconfigin(pldpartialreconfigin), + .pldpartialreconfigout(pldpartialreconfigout), + .pldpcspmaifrefclkdig(pldpcspmaifrefclkdig), + .pldrate(pldrate), + .pldreservedin(pldreservedin), + .pldreservedout(pldreservedout), + .pldscanmoden(pldscanmoden), + .pldscanshiftn(pldscanshiftn), + .pldtestdata(pldtestdata), + .pmaclklow(pmaclklow), + .pmafref(pmafref), + .rstsel(rstsel), + .usrrstsel(usrrstsel) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_pipe_gen1_2_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_pipe_gen1_2_rbc.sv new file mode 100644 index 0000000..9bfc2fc --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_pipe_gen1_2_rbc.sv @@ -0,0 +1,321 @@ +// (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_pipe_gen1_2 +// + +`timescale 1 ns / 1 ps + +module av_hssi_pipe_gen1_2_rbc #( + // unconstrained parameters + parameter prot_mode = "", // basic, disabled_prot_mode, pipe_g1, pipe_g2, srio_2p1 + + // extra unconstrained parameters found in atom map + parameter avmm_group_channel_index = 0, // 0..2 + parameter ctrl_plane_bonding_consumption = "individual", // bundled_master, bundled_slave_above, bundled_slave_below, individual + parameter elec_idle_delay_val = 3'b0, // 3 + parameter elecidle_delay = "elec_idle_delay", // elec_idle_delay + parameter phy_status_delay = "phystatus_delay", // phystatus_delay + parameter phystatus_delay_val = 3'b0, // 3 + parameter rpre_emph_a_val = 6'b0, // 6 + parameter rpre_emph_b_val = 6'b0, // 6 + parameter rpre_emph_c_val = 6'b0, // 6 + parameter rpre_emph_d_val = 6'b0, // 6 + parameter rpre_emph_e_val = 6'b0, // 6 + parameter rpre_emph_settings = 6'b0, // 6 + parameter rvod_sel_a_val = 6'b0, // 6 + parameter rvod_sel_b_val = 6'b0, // 6 + parameter rvod_sel_c_val = 6'b0, // 6 + parameter rvod_sel_d_val = 6'b0, // 6 + parameter rvod_sel_e_val = 6'b0, // 6 + parameter rvod_sel_settings = 6'b0, // 6 + parameter sup_mode = "user_mode", // engineering_mode, user_mode + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0, // 0..2047 + + // constrained parameters + parameter hip_mode = "", // dis_hip, en_hip + parameter tx_pipe_enable = "", // dis_pipe_tx, en_pipe_tx + parameter rx_pipe_enable = "", // dis_pipe_rx, en_pipe_rx + parameter pipe_byte_de_serializer_en = "", // dis_bds, dont_care_bds, en_bds_by_2 + parameter txswing = "", // dis_txswing, en_txswing + parameter rxdetect_bypass = "", // dis_rxdetect_bypass, en_rxdetect_bypass + parameter error_replace_pad = "", // replace_edb, replace_pad + parameter ind_error_reporting = "", // dis_ind_error_reporting, en_ind_error_reporting + parameter phystatus_rst_toggle = "" // dis_phystatus_rst_toggle, en_phystatus_rst_toggle +) ( + // ports + 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 blockselect, + output wire [17:0] currentcoeff, + input wire pcieswitch, + output wire phystatus, + input wire piperxclk, + input wire pipetxclk, + input wire polinvrx, + output wire polinvrxint, + input wire [1:0] powerdown, + input wire powerstatetransitiondone, + input wire powerstatetransitiondoneena, + input wire refclkb, + input wire refclkbreset, + input wire revloopback, + output wire revloopbk, + input wire revloopbkpcsgen3, + input wire [63:0] rxd, + output wire [63:0] rxdch, + input wire rxdetectvalid, + output wire rxelecidle, + input wire rxelectricalidle, + output wire rxelectricalidleout, + input wire rxfound, + input wire rxpipereset, + input wire rxpolarity, + output wire [2:0] rxstatus, + output wire rxvalid, + input wire sigdetni, + input wire speedchange, + input wire speedchangechnldown, + input wire speedchangechnlup, + output wire speedchangeout, + output wire [43:0] txd, + input wire [43:0] txdch, + input wire txdeemph, + output wire txdetectrx, + input wire txdetectrxloopback, + input wire txelecidlecomp, + input wire txelecidlein, + output wire txelecidleout, + input wire [2:0] txmargin, + input wire txpipereset, + input wire txswingport +); + import altera_xcvr_functions::*; + + // prot_mode external parameter (no RBC) + localparam rbc_all_prot_mode = "(basic,disabled_prot_mode,pipe_g1,pipe_g2,srio_2p1)"; + localparam rbc_any_prot_mode = "pipe_g1"; + localparam fnl_prot_mode = (prot_mode == "" || prot_mode == "") ? rbc_any_prot_mode : prot_mode; + + // ctrl_plane_bonding_consumption external parameter (no RBC) + localparam rbc_all_ctrl_plane_bonding_consumption = "(bundled_master,bundled_slave_above,bundled_slave_below,individual)"; + localparam rbc_any_ctrl_plane_bonding_consumption = "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; + + // 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; + + // 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; + + // tx_pipe_enable, RBC-validated + localparam rbc_all_tx_pipe_enable = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("en_pipe_tx") : "dis_pipe_tx"; + localparam rbc_any_tx_pipe_enable = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("en_pipe_tx") : "dis_pipe_tx"; + localparam fnl_tx_pipe_enable = (tx_pipe_enable == "" || tx_pipe_enable == "") ? rbc_any_tx_pipe_enable : tx_pipe_enable; + + // rx_pipe_enable, RBC-validated + localparam rbc_all_rx_pipe_enable = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("en_pipe_rx") : "dis_pipe_rx"; + localparam rbc_any_rx_pipe_enable = ( (fnl_prot_mode == "pipe_g1") || (fnl_prot_mode == "pipe_g2") ) ? ("en_pipe_rx") : "dis_pipe_rx"; + localparam fnl_rx_pipe_enable = (rx_pipe_enable == "" || rx_pipe_enable == "") ? rbc_any_rx_pipe_enable : rx_pipe_enable; + + // pipe_byte_de_serializer_en, RBC-validated + localparam rbc_all_pipe_byte_de_serializer_en = ((fnl_rx_pipe_enable == "en_pipe_rx") && (fnl_hip_mode != "en_hip")) ? ("(dis_bds,en_bds_by_2)") + : ((fnl_rx_pipe_enable == "en_pipe_rx") && (fnl_hip_mode == "en_hip")) ? ("dis_bds") : "dont_care_bds"; + localparam rbc_any_pipe_byte_de_serializer_en = ((fnl_rx_pipe_enable == "en_pipe_rx") && (fnl_hip_mode != "en_hip")) ? ("dis_bds") + : ((fnl_rx_pipe_enable == "en_pipe_rx") && (fnl_hip_mode == "en_hip")) ? ("dis_bds") : "dont_care_bds"; + localparam fnl_pipe_byte_de_serializer_en = (pipe_byte_de_serializer_en == "" || pipe_byte_de_serializer_en == "") ? rbc_any_pipe_byte_de_serializer_en : pipe_byte_de_serializer_en; + + // txswing, RBC-validated + localparam rbc_all_txswing = (fnl_rx_pipe_enable == "en_pipe_rx") ? ("(en_txswing,dis_txswing)") : "dis_txswing"; + localparam rbc_any_txswing = (fnl_rx_pipe_enable == "en_pipe_rx") ? ("dis_txswing") : "dis_txswing"; + localparam fnl_txswing = (txswing == "" || txswing == "") ? rbc_any_txswing : txswing; + + // rxdetect_bypass, RBC-validated + localparam rbc_all_rxdetect_bypass = (fnl_rx_pipe_enable == "en_pipe_rx") ? ("(dis_rxdetect_bypass,en_rxdetect_bypass)") : "dis_rxdetect_bypass"; + localparam rbc_any_rxdetect_bypass = (fnl_rx_pipe_enable == "en_pipe_rx") ? ("dis_rxdetect_bypass") : "dis_rxdetect_bypass"; + localparam fnl_rxdetect_bypass = (rxdetect_bypass == "" || rxdetect_bypass == "") ? rbc_any_rxdetect_bypass : rxdetect_bypass; + + // error_replace_pad, RBC-validated + localparam rbc_all_error_replace_pad = "replace_edb"; + localparam rbc_any_error_replace_pad = "replace_edb"; + localparam fnl_error_replace_pad = (error_replace_pad == "" || error_replace_pad == "") ? rbc_any_error_replace_pad : error_replace_pad; + + // ind_error_reporting, RBC-validated + localparam rbc_all_ind_error_reporting = (fnl_rx_pipe_enable == "en_pipe_rx") ? ("(en_ind_error_reporting,dis_ind_error_reporting)") : "dis_ind_error_reporting"; + localparam rbc_any_ind_error_reporting = (fnl_rx_pipe_enable == "en_pipe_rx") ? ("dis_ind_error_reporting") : "dis_ind_error_reporting"; + localparam fnl_ind_error_reporting = (ind_error_reporting == "" || ind_error_reporting == "") ? rbc_any_ind_error_reporting : ind_error_reporting; + + // phystatus_rst_toggle, RBC-validated + localparam rbc_all_phystatus_rst_toggle = "dis_phystatus_rst_toggle"; + localparam rbc_any_phystatus_rst_toggle = "dis_phystatus_rst_toggle"; + localparam fnl_phystatus_rst_toggle = (phystatus_rst_toggle == "" || phystatus_rst_toggle == "") ? rbc_any_phystatus_rst_toggle : phystatus_rst_toggle; + + // Validate input parameters against known values or RBC values + initial begin + //$display("prot_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", prot_mode, rbc_any_prot_mode, rbc_all_prot_mode, fnl_prot_mode); + if (!is_in_legal_set(prot_mode, rbc_all_prot_mode)) begin + $display("Critical Warning: parameter 'prot_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prot_mode, rbc_all_prot_mode, fnl_prot_mode); + end + //$display("ctrl_plane_bonding_consumption = orig: '%s', any:'%s', all:'%s', final: '%s'", ctrl_plane_bonding_consumption, rbc_any_ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption, fnl_ctrl_plane_bonding_consumption); + if (!is_in_legal_set(ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption)) begin + $display("Critical Warning: parameter 'ctrl_plane_bonding_consumption' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ctrl_plane_bonding_consumption, rbc_all_ctrl_plane_bonding_consumption, fnl_ctrl_plane_bonding_consumption); + end + //$display("sup_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", sup_mode, rbc_any_sup_mode, rbc_all_sup_mode, fnl_sup_mode); + if (!is_in_legal_set(sup_mode, rbc_all_sup_mode)) begin + $display("Critical Warning: parameter 'sup_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", sup_mode, rbc_all_sup_mode, fnl_sup_mode); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + //$display("hip_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", hip_mode, rbc_any_hip_mode, rbc_all_hip_mode, fnl_hip_mode); + if (!is_in_legal_set(hip_mode, rbc_all_hip_mode)) begin + $display("Critical Warning: parameter 'hip_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", hip_mode, rbc_all_hip_mode, fnl_hip_mode); + end + //$display("tx_pipe_enable = orig: '%s', any:'%s', all:'%s', final: '%s'", tx_pipe_enable, rbc_any_tx_pipe_enable, rbc_all_tx_pipe_enable, fnl_tx_pipe_enable); + if (!is_in_legal_set(tx_pipe_enable, rbc_all_tx_pipe_enable)) begin + $display("Critical Warning: parameter 'tx_pipe_enable' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", tx_pipe_enable, rbc_all_tx_pipe_enable, fnl_tx_pipe_enable); + end + //$display("rx_pipe_enable = orig: '%s', any:'%s', all:'%s', final: '%s'", rx_pipe_enable, rbc_any_rx_pipe_enable, rbc_all_rx_pipe_enable, fnl_rx_pipe_enable); + if (!is_in_legal_set(rx_pipe_enable, rbc_all_rx_pipe_enable)) begin + $display("Critical Warning: parameter 'rx_pipe_enable' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rx_pipe_enable, rbc_all_rx_pipe_enable, fnl_rx_pipe_enable); + end + //$display("pipe_byte_de_serializer_en = orig: '%s', any:'%s', all:'%s', final: '%s'", pipe_byte_de_serializer_en, rbc_any_pipe_byte_de_serializer_en, rbc_all_pipe_byte_de_serializer_en, fnl_pipe_byte_de_serializer_en); + if (!is_in_legal_set(pipe_byte_de_serializer_en, rbc_all_pipe_byte_de_serializer_en)) begin + $display("Critical Warning: parameter 'pipe_byte_de_serializer_en' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pipe_byte_de_serializer_en, rbc_all_pipe_byte_de_serializer_en, fnl_pipe_byte_de_serializer_en); + end + //$display("txswing = orig: '%s', any:'%s', all:'%s', final: '%s'", txswing, rbc_any_txswing, rbc_all_txswing, fnl_txswing); + if (!is_in_legal_set(txswing, rbc_all_txswing)) begin + $display("Critical Warning: parameter 'txswing' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", txswing, rbc_all_txswing, fnl_txswing); + end + //$display("rxdetect_bypass = orig: '%s', any:'%s', all:'%s', final: '%s'", rxdetect_bypass, rbc_any_rxdetect_bypass, rbc_all_rxdetect_bypass, fnl_rxdetect_bypass); + if (!is_in_legal_set(rxdetect_bypass, rbc_all_rxdetect_bypass)) begin + $display("Critical Warning: parameter 'rxdetect_bypass' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", rxdetect_bypass, rbc_all_rxdetect_bypass, fnl_rxdetect_bypass); + end + //$display("error_replace_pad = orig: '%s', any:'%s', all:'%s', final: '%s'", error_replace_pad, rbc_any_error_replace_pad, rbc_all_error_replace_pad, fnl_error_replace_pad); + if (!is_in_legal_set(error_replace_pad, rbc_all_error_replace_pad)) begin + $display("Critical Warning: parameter 'error_replace_pad' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", error_replace_pad, rbc_all_error_replace_pad, fnl_error_replace_pad); + end + //$display("ind_error_reporting = orig: '%s', any:'%s', all:'%s', final: '%s'", ind_error_reporting, rbc_any_ind_error_reporting, rbc_all_ind_error_reporting, fnl_ind_error_reporting); + if (!is_in_legal_set(ind_error_reporting, rbc_all_ind_error_reporting)) begin + $display("Critical Warning: parameter 'ind_error_reporting' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", ind_error_reporting, rbc_all_ind_error_reporting, fnl_ind_error_reporting); + end + //$display("phystatus_rst_toggle = orig: '%s', any:'%s', all:'%s', final: '%s'", phystatus_rst_toggle, rbc_any_phystatus_rst_toggle, rbc_all_phystatus_rst_toggle, fnl_phystatus_rst_toggle); + if (!is_in_legal_set(phystatus_rst_toggle, rbc_all_phystatus_rst_toggle)) begin + $display("Critical Warning: parameter 'phystatus_rst_toggle' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", phystatus_rst_toggle, rbc_all_phystatus_rst_toggle, fnl_phystatus_rst_toggle); + end + end + + arriav_hssi_pipe_gen1_2 #( + .prot_mode(fnl_prot_mode), + .avmm_group_channel_index(avmm_group_channel_index), + .ctrl_plane_bonding_consumption(fnl_ctrl_plane_bonding_consumption), + .elec_idle_delay_val(elec_idle_delay_val), + .elecidle_delay(elecidle_delay), + .phy_status_delay(phy_status_delay), + .phystatus_delay_val(phystatus_delay_val), + .rpre_emph_a_val(rpre_emph_a_val), + .rpre_emph_b_val(rpre_emph_b_val), + .rpre_emph_c_val(rpre_emph_c_val), + .rpre_emph_d_val(rpre_emph_d_val), + .rpre_emph_e_val(rpre_emph_e_val), + .rpre_emph_settings(rpre_emph_settings), + .rvod_sel_a_val(rvod_sel_a_val), + .rvod_sel_b_val(rvod_sel_b_val), + .rvod_sel_c_val(rvod_sel_c_val), + .rvod_sel_d_val(rvod_sel_d_val), + .rvod_sel_e_val(rvod_sel_e_val), + .rvod_sel_settings(rvod_sel_settings), + .sup_mode(fnl_sup_mode), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address), + .hip_mode(fnl_hip_mode), + .tx_pipe_enable(fnl_tx_pipe_enable), + .rx_pipe_enable(fnl_rx_pipe_enable), + .pipe_byte_de_serializer_en(fnl_pipe_byte_de_serializer_en), + .txswing(fnl_txswing), + .rxdetect_bypass(fnl_rxdetect_bypass), + .error_replace_pad(fnl_error_replace_pad), + .ind_error_reporting(fnl_ind_error_reporting), + .phystatus_rst_toggle(fnl_phystatus_rst_toggle) + ) wys ( + // ports + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .blockselect(blockselect), + .currentcoeff(currentcoeff), + .pcieswitch(pcieswitch), + .phystatus(phystatus), + .piperxclk(piperxclk), + .pipetxclk(pipetxclk), + .polinvrx(polinvrx), + .polinvrxint(polinvrxint), + .powerdown(powerdown), + .powerstatetransitiondone(powerstatetransitiondone), + .powerstatetransitiondoneena(powerstatetransitiondoneena), + .refclkb(refclkb), + .refclkbreset(refclkbreset), + .revloopback(revloopback), + .revloopbk(revloopbk), + .revloopbkpcsgen3(revloopbkpcsgen3), + .rxd(rxd), + .rxdch(rxdch), + .rxdetectvalid(rxdetectvalid), + .rxelecidle(rxelecidle), + .rxelectricalidle(rxelectricalidle), + .rxelectricalidleout(rxelectricalidleout), + .rxfound(rxfound), + .rxpipereset(rxpipereset), + .rxpolarity(rxpolarity), + .rxstatus(rxstatus), + .rxvalid(rxvalid), + .sigdetni(sigdetni), + .speedchange(speedchange), + .speedchangechnldown(speedchangechnldown), + .speedchangechnlup(speedchangechnlup), + .speedchangeout(speedchangeout), + .txd(txd), + .txdch(txdch), + .txdeemph(txdeemph), + .txdetectrx(txdetectrx), + .txdetectrxloopback(txdetectrxloopback), + .txelecidlecomp(txelecidlecomp), + .txelecidlein(txelecidlein), + .txelecidleout(txelecidleout), + .txmargin(txmargin), + .txpipereset(txpipereset), + .txswingport(txswingport) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_rx_pcs_pma_interface_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_rx_pcs_pma_interface_rbc.sv new file mode 100644 index 0000000..0b30f00 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_rx_pcs_pma_interface_rbc.sv @@ -0,0 +1,142 @@ +// (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_rx_pcs_pma_interface +// + +`timescale 1 ns / 1 ps + +module av_hssi_rx_pcs_pma_interface_rbc #( + // unconstrained parameters + parameter prot_mode = "", // cpri_8g, other_protocols + + // extra unconstrained parameters found in atom map + parameter avmm_group_channel_index = 0, // 0..2 + parameter selectpcs = "eight_g_pcs", // default, eight_g_pcs + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0, // 0..2047 + + // constrained parameters + parameter clkslip_sel = "" // pld, slip_eight_g_pcs +) ( + // ports + output wire asynchdatain, + 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 blockselect, + input wire clockinfrompma, + output wire clockoutto8gpcs, + input wire [79:0] datainfrompma, + output wire [19:0] dataoutto8gpcs, + input wire pcs8grxclkiqout, + input wire pcs8grxclkslip, + output wire pcs8gsigdetni, + input wire pldrxclkslip, + input wire pldrxpmarstb, + input wire [4:0] pmareservedin, + output wire [4:0] pmareservedout, + output wire pmarxclkout, + output wire pmarxclkslip, + input wire pmarxpllphaselockin, + output wire pmarxpllphaselockout, + output wire pmarxpmarstb, + input wire pmasigdet, + output wire reset +); + import altera_xcvr_functions::*; + + // prot_mode external parameter (no RBC) + localparam rbc_all_prot_mode = "(cpri_8g,other_protocols)"; + localparam rbc_any_prot_mode = "other_protocols"; + localparam fnl_prot_mode = (prot_mode == "" || prot_mode == "") ? rbc_any_prot_mode : prot_mode; + + // selectpcs external parameter (no RBC) + localparam rbc_all_selectpcs = "(default,eight_g_pcs)"; + localparam rbc_any_selectpcs = "eight_g_pcs"; + localparam fnl_selectpcs = (selectpcs == "" || selectpcs == "") ? rbc_any_selectpcs : selectpcs; + + // 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; + + // clkslip_sel, RBC-validated + localparam rbc_all_clkslip_sel = (fnl_prot_mode == "cpri_8g") ? ("(slip_eight_g_pcs,pld)") : "pld"; + localparam rbc_any_clkslip_sel = (fnl_prot_mode == "cpri_8g") ? ("pld") : "pld"; + localparam fnl_clkslip_sel = (clkslip_sel == "" || clkslip_sel == "") ? rbc_any_clkslip_sel : clkslip_sel; + + // Validate input parameters against known values or RBC values + initial begin + //$display("prot_mode = orig: '%s', any:'%s', all:'%s', final: '%s'", prot_mode, rbc_any_prot_mode, rbc_all_prot_mode, fnl_prot_mode); + if (!is_in_legal_set(prot_mode, rbc_all_prot_mode)) begin + $display("Critical Warning: parameter 'prot_mode' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", prot_mode, rbc_all_prot_mode, fnl_prot_mode); + end + //$display("selectpcs = orig: '%s', any:'%s', all:'%s', final: '%s'", selectpcs, rbc_any_selectpcs, rbc_all_selectpcs, fnl_selectpcs); + if (!is_in_legal_set(selectpcs, rbc_all_selectpcs)) begin + $display("Critical Warning: parameter 'selectpcs' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", selectpcs, rbc_all_selectpcs, fnl_selectpcs); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + //$display("clkslip_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", clkslip_sel, rbc_any_clkslip_sel, rbc_all_clkslip_sel, fnl_clkslip_sel); + if (!is_in_legal_set(clkslip_sel, rbc_all_clkslip_sel)) begin + $display("Critical Warning: parameter 'clkslip_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", clkslip_sel, rbc_all_clkslip_sel, fnl_clkslip_sel); + end + end + + arriav_hssi_rx_pcs_pma_interface #( + .prot_mode(fnl_prot_mode), + .avmm_group_channel_index(avmm_group_channel_index), + .selectpcs(fnl_selectpcs), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address), + .clkslip_sel(fnl_clkslip_sel) + ) wys ( + // ports + .asynchdatain(asynchdatain), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .blockselect(blockselect), + .clockinfrompma(clockinfrompma), + .clockoutto8gpcs(clockoutto8gpcs), + .datainfrompma(datainfrompma), + .dataoutto8gpcs(dataoutto8gpcs), + .pcs8grxclkiqout(pcs8grxclkiqout), + .pcs8grxclkslip(pcs8grxclkslip), + .pcs8gsigdetni(pcs8gsigdetni), + .pldrxclkslip(pldrxclkslip), + .pldrxpmarstb(pldrxpmarstb), + .pmareservedin(pmareservedin), + .pmareservedout(pmareservedout), + .pmarxclkout(pmarxclkout), + .pmarxclkslip(pmarxclkslip), + .pmarxpllphaselockin(pmarxpllphaselockin), + .pmarxpllphaselockout(pmarxpllphaselockout), + .pmarxpmarstb(pmarxpmarstb), + .pmasigdet(pmasigdet), + .reset(reset) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_rx_pld_pcs_interface_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_rx_pld_pcs_interface_rbc.sv new file mode 100644 index 0000000..1e0620c --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_rx_pld_pcs_interface_rbc.sv @@ -0,0 +1,254 @@ +// (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_rx_pld_pcs_interface +// + +`timescale 1 ns / 1 ps + +module av_hssi_rx_pld_pcs_interface_rbc #( + // unconstrained parameters + + // extra unconstrained parameters found in atom map + parameter avmm_group_channel_index = 0, // 0..2 + parameter is_8g_0ppm = "false", // false, true + parameter pcs_side_block_sel = "eight_g_pcs", // default, eight_g_pcs + parameter pld_side_data_source = "pld", // hip, pld + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0 // 0..2047 + + // constrained parameters +) ( + // ports + output wire asynchdatain, + 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 blockselect, + input wire clockinfrom8gpcs, + input wire [63:0] datainfrom8gpcs, + output wire [63:0] dataouttopld, + input wire emsipenablediocsrrdydly, + output wire [128:0] emsiprxout, + input wire [12:0] emsiprxspecialin, + output wire [15:0] emsiprxspecialout, + input wire [3:0] pcs8ga1a2k1k2flag, + output wire pcs8ga1a2size, + input wire pcs8galignstatus, + input wire pcs8gbistdone, + input wire pcs8gbisterr, + output wire pcs8gbitlocreven, + output wire pcs8gbitslip, + input wire pcs8gbyteordflag, + output wire pcs8gbytereven, + output wire pcs8gbytordpld, + output wire pcs8gcmpfifourst, + input wire pcs8gemptyrmf, + input wire pcs8gemptyrx, + output wire pcs8gencdt, + input wire pcs8gfullrmf, + input wire pcs8gfullrx, + output wire pcs8gphfifourstrx, + output wire pcs8gpldrxclk, + output wire pcs8gpolinvrx, + output wire pcs8grdenablermf, + output wire pcs8grdenablerx, + input wire pcs8grlvlt, + input wire [3:0] pcs8grxdatavalid, + output wire pcs8grxurstpcs, + input wire pcs8gsignaldetectout, + output wire pcs8gsyncsmenoutput, + input wire [4:0] pcs8gwaboundary, + output wire pcs8gwrdisablerx, + output wire pcs8gwrenablermf, + output wire [3:0] pld8ga1a2k1k2flag, + input wire pld8ga1a2size, + output wire pld8galignstatus, + output wire pld8gbistdone, + output wire pld8gbisterr, + input wire pld8gbitlocreven, + input wire pld8gbitslip, + output wire pld8gbyteordflag, + input wire pld8gbytereven, + input wire pld8gbytordpld, + input wire pld8gcmpfifourstn, + output wire pld8gemptyrmf, + output wire pld8gemptyrx, + input wire pld8gencdt, + output wire pld8gfullrmf, + output wire pld8gfullrx, + input wire pld8gphfifourstrxn, + input wire pld8gpldrxclk, + input wire pld8gpolinvrx, + input wire pld8grdenablermf, + input wire pld8grdenablerx, + output wire pld8grlvlt, + output wire pld8grxclkout, + output wire [3:0] pld8grxdatavalid, + input wire pld8grxurstpcsn, + output wire pld8gsignaldetectout, + input wire pld8gsyncsmeninput, + output wire [4:0] pld8gwaboundary, + input wire pld8gwrdisablerx, + input wire pld8gwrenablermf, + input wire pldrxclkslipin, + output wire pldrxclkslipout, + input wire pldrxpmarstbin, + output wire pldrxpmarstbout, + input wire pmarxplllock, + output wire reset, + input wire rstsel, + input wire usrrstsel +); + import altera_xcvr_functions::*; + + // is_8g_0ppm external parameter (no RBC) + localparam rbc_all_is_8g_0ppm = "(false,true)"; + localparam rbc_any_is_8g_0ppm = "false"; + localparam fnl_is_8g_0ppm = (is_8g_0ppm == "" || is_8g_0ppm == "") ? rbc_any_is_8g_0ppm : is_8g_0ppm; + + // pcs_side_block_sel external parameter (no RBC) + localparam rbc_all_pcs_side_block_sel = "(default,eight_g_pcs)"; + localparam rbc_any_pcs_side_block_sel = "eight_g_pcs"; + localparam fnl_pcs_side_block_sel = (pcs_side_block_sel == "" || pcs_side_block_sel == "") ? rbc_any_pcs_side_block_sel : pcs_side_block_sel; + + // pld_side_data_source external parameter (no RBC) + localparam rbc_all_pld_side_data_source = "(hip,pld)"; + localparam rbc_any_pld_side_data_source = "pld"; + localparam fnl_pld_side_data_source = (pld_side_data_source == "" || pld_side_data_source == "") ? rbc_any_pld_side_data_source : pld_side_data_source; + + // 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; + + // Validate input parameters against known values or RBC values + initial begin + //$display("is_8g_0ppm = orig: '%s', any:'%s', all:'%s', final: '%s'", is_8g_0ppm, rbc_any_is_8g_0ppm, rbc_all_is_8g_0ppm, fnl_is_8g_0ppm); + if (!is_in_legal_set(is_8g_0ppm, rbc_all_is_8g_0ppm)) begin + $display("Critical Warning: parameter 'is_8g_0ppm' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", is_8g_0ppm, rbc_all_is_8g_0ppm, fnl_is_8g_0ppm); + end + //$display("pcs_side_block_sel = orig: '%s', any:'%s', all:'%s', final: '%s'", pcs_side_block_sel, rbc_any_pcs_side_block_sel, rbc_all_pcs_side_block_sel, fnl_pcs_side_block_sel); + if (!is_in_legal_set(pcs_side_block_sel, rbc_all_pcs_side_block_sel)) begin + $display("Critical Warning: parameter 'pcs_side_block_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pcs_side_block_sel, rbc_all_pcs_side_block_sel, fnl_pcs_side_block_sel); + end + //$display("pld_side_data_source = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_data_source, rbc_any_pld_side_data_source, rbc_all_pld_side_data_source, fnl_pld_side_data_source); + if (!is_in_legal_set(pld_side_data_source, rbc_all_pld_side_data_source)) begin + $display("Critical Warning: parameter 'pld_side_data_source' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_data_source, rbc_all_pld_side_data_source, fnl_pld_side_data_source); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + end + + arriav_hssi_rx_pld_pcs_interface #( + .avmm_group_channel_index(avmm_group_channel_index), + .is_8g_0ppm(fnl_is_8g_0ppm), + .pcs_side_block_sel(fnl_pcs_side_block_sel), + .pld_side_data_source(fnl_pld_side_data_source), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address) + ) wys ( + // ports + .asynchdatain(asynchdatain), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .blockselect(blockselect), + .clockinfrom8gpcs(clockinfrom8gpcs), + .datainfrom8gpcs(datainfrom8gpcs), + .dataouttopld(dataouttopld), + .emsipenablediocsrrdydly(emsipenablediocsrrdydly), + .emsiprxout(emsiprxout), + .emsiprxspecialin(emsiprxspecialin), + .emsiprxspecialout(emsiprxspecialout), + .pcs8ga1a2k1k2flag(pcs8ga1a2k1k2flag), + .pcs8ga1a2size(pcs8ga1a2size), + .pcs8galignstatus(pcs8galignstatus), + .pcs8gbistdone(pcs8gbistdone), + .pcs8gbisterr(pcs8gbisterr), + .pcs8gbitlocreven(pcs8gbitlocreven), + .pcs8gbitslip(pcs8gbitslip), + .pcs8gbyteordflag(pcs8gbyteordflag), + .pcs8gbytereven(pcs8gbytereven), + .pcs8gbytordpld(pcs8gbytordpld), + .pcs8gcmpfifourst(pcs8gcmpfifourst), + .pcs8gemptyrmf(pcs8gemptyrmf), + .pcs8gemptyrx(pcs8gemptyrx), + .pcs8gencdt(pcs8gencdt), + .pcs8gfullrmf(pcs8gfullrmf), + .pcs8gfullrx(pcs8gfullrx), + .pcs8gphfifourstrx(pcs8gphfifourstrx), + .pcs8gpldrxclk(pcs8gpldrxclk), + .pcs8gpolinvrx(pcs8gpolinvrx), + .pcs8grdenablermf(pcs8grdenablermf), + .pcs8grdenablerx(pcs8grdenablerx), + .pcs8grlvlt(pcs8grlvlt), + .pcs8grxdatavalid(pcs8grxdatavalid), + .pcs8grxurstpcs(pcs8grxurstpcs), + .pcs8gsignaldetectout(pcs8gsignaldetectout), + .pcs8gsyncsmenoutput(pcs8gsyncsmenoutput), + .pcs8gwaboundary(pcs8gwaboundary), + .pcs8gwrdisablerx(pcs8gwrdisablerx), + .pcs8gwrenablermf(pcs8gwrenablermf), + .pld8ga1a2k1k2flag(pld8ga1a2k1k2flag), + .pld8ga1a2size(pld8ga1a2size), + .pld8galignstatus(pld8galignstatus), + .pld8gbistdone(pld8gbistdone), + .pld8gbisterr(pld8gbisterr), + .pld8gbitlocreven(pld8gbitlocreven), + .pld8gbitslip(pld8gbitslip), + .pld8gbyteordflag(pld8gbyteordflag), + .pld8gbytereven(pld8gbytereven), + .pld8gbytordpld(pld8gbytordpld), + .pld8gcmpfifourstn(pld8gcmpfifourstn), + .pld8gemptyrmf(pld8gemptyrmf), + .pld8gemptyrx(pld8gemptyrx), + .pld8gencdt(pld8gencdt), + .pld8gfullrmf(pld8gfullrmf), + .pld8gfullrx(pld8gfullrx), + .pld8gphfifourstrxn(pld8gphfifourstrxn), + .pld8gpldrxclk(pld8gpldrxclk), + .pld8gpolinvrx(pld8gpolinvrx), + .pld8grdenablermf(pld8grdenablermf), + .pld8grdenablerx(pld8grdenablerx), + .pld8grlvlt(pld8grlvlt), + .pld8grxclkout(pld8grxclkout), + .pld8grxdatavalid(pld8grxdatavalid), + .pld8grxurstpcsn(pld8grxurstpcsn), + .pld8gsignaldetectout(pld8gsignaldetectout), + .pld8gsyncsmeninput(pld8gsyncsmeninput), + .pld8gwaboundary(pld8gwaboundary), + .pld8gwrdisablerx(pld8gwrdisablerx), + .pld8gwrenablermf(pld8gwrenablermf), + .pldrxclkslipin(pldrxclkslipin), + .pldrxclkslipout(pldrxclkslipout), + .pldrxpmarstbin(pldrxpmarstbin), + .pldrxpmarstbout(pldrxpmarstbout), + .pmarxplllock(pmarxplllock), + .reset(reset), + .rstsel(rstsel), + .usrrstsel(usrrstsel) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_tx_pcs_pma_interface_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_tx_pcs_pma_interface_rbc.sv new file mode 100644 index 0000000..7906edc --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_tx_pcs_pma_interface_rbc.sv @@ -0,0 +1,102 @@ +// (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_tx_pcs_pma_interface +// + +`timescale 1 ns / 1 ps + +module av_hssi_tx_pcs_pma_interface_rbc #( + // unconstrained parameters + + // extra unconstrained parameters found in atom map + parameter avmm_group_channel_index = 0, // 0..2 + parameter selectpcs = "eight_g_pcs", // default, eight_g_pcs + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0 // 0..2047 + + // constrained parameters +) ( + // ports + output wire asynchdatain, + 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 blockselect, + input wire clockinfrompma, + output wire clockoutto8gpcs, + input wire [19:0] datainfrom8gpcs, + output wire [79:0] dataouttopma, + input wire pcs8gtxclkiqout, + input wire pmarxfreqtxcmuplllockin, + output wire pmarxfreqtxcmuplllockout, + output wire pmatxclkout, + output wire reset +); + import altera_xcvr_functions::*; + + // selectpcs external parameter (no RBC) + localparam rbc_all_selectpcs = "(default,eight_g_pcs)"; + localparam rbc_any_selectpcs = "eight_g_pcs"; + localparam fnl_selectpcs = (selectpcs == "" || selectpcs == "") ? rbc_any_selectpcs : selectpcs; + + // 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; + + // Validate input parameters against known values or RBC values + initial begin + //$display("selectpcs = orig: '%s', any:'%s', all:'%s', final: '%s'", selectpcs, rbc_any_selectpcs, rbc_all_selectpcs, fnl_selectpcs); + if (!is_in_legal_set(selectpcs, rbc_all_selectpcs)) begin + $display("Critical Warning: parameter 'selectpcs' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", selectpcs, rbc_all_selectpcs, fnl_selectpcs); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + end + + arriav_hssi_tx_pcs_pma_interface #( + .avmm_group_channel_index(avmm_group_channel_index), + .selectpcs(fnl_selectpcs), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address) + ) wys ( + // ports + .asynchdatain(asynchdatain), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .blockselect(blockselect), + .clockinfrompma(clockinfrompma), + .clockoutto8gpcs(clockoutto8gpcs), + .datainfrom8gpcs(datainfrom8gpcs), + .dataouttopma(dataouttopma), + .pcs8gtxclkiqout(pcs8gtxclkiqout), + .pmarxfreqtxcmuplllockin(pmarxfreqtxcmuplllockin), + .pmarxfreqtxcmuplllockout(pmarxfreqtxcmuplllockout), + .pmatxclkout(pmatxclkout), + .reset(reset) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_tx_pld_pcs_interface_rbc.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_tx_pld_pcs_interface_rbc.sv new file mode 100644 index 0000000..16578d1 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_hssi_tx_pld_pcs_interface_rbc.sv @@ -0,0 +1,165 @@ +// (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_tx_pld_pcs_interface +// + +`timescale 1 ns / 1 ps + +module av_hssi_tx_pld_pcs_interface_rbc #( + // unconstrained parameters + + // extra unconstrained parameters found in atom map + parameter avmm_group_channel_index = 0, // 0..2 + parameter is_8g_0ppm = "false", // false, true + parameter pld_side_data_source = "pld", // hip, pld + parameter use_default_base_address = "true", // false, true + parameter user_base_address = 0 // 0..2047 + + // constrained parameters +) ( + // ports + output wire asynchdatain, + 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 blockselect, + input wire clockinfrom8gpcs, + input wire [43:0] datainfrompld, + output wire [43:0] dataoutto8gpcs, + input wire emsipenablediocsrrdydly, + output wire [2:0] emsippcstxclkout, + input wire [103:0] emsiptxin, + input wire [12:0] emsiptxspecialin, + output wire [15:0] emsiptxspecialout, + input wire pcs8gemptytx, + input wire pcs8gfulltx, + output wire pcs8gphfifoursttx, + output wire pcs8gpldtxclk, + output wire pcs8gpolinvtx, + output wire pcs8grddisabletx, + output wire pcs8grevloopbk, + output wire [4:0] pcs8gtxboundarysel, + output wire [3:0] pcs8gtxdatavalid, + output wire pcs8gtxurstpcs, + output wire pcs8gwrenabletx, + output wire pld8gemptytx, + output wire pld8gfulltx, + input wire pld8gphfifoursttxn, + input wire pld8gpldtxclk, + input wire pld8gpolinvtx, + input wire pld8grddisabletx, + input wire pld8grevloopbk, + input wire [4:0] pld8gtxboundarysel, + output wire pld8gtxclkout, + input wire [3:0] pld8gtxdatavalid, + input wire pld8gtxurstpcsn, + input wire pld8gwrenabletx, + input wire pmatxcmuplllock, + output wire reset, + input wire rstsel, + input wire usrrstsel +); + import altera_xcvr_functions::*; + + // is_8g_0ppm external parameter (no RBC) + localparam rbc_all_is_8g_0ppm = "(false,true)"; + localparam rbc_any_is_8g_0ppm = "false"; + localparam fnl_is_8g_0ppm = (is_8g_0ppm == "" || is_8g_0ppm == "") ? rbc_any_is_8g_0ppm : is_8g_0ppm; + + // pld_side_data_source external parameter (no RBC) + localparam rbc_all_pld_side_data_source = "(hip,pld)"; + localparam rbc_any_pld_side_data_source = "pld"; + localparam fnl_pld_side_data_source = (pld_side_data_source == "" || pld_side_data_source == "") ? rbc_any_pld_side_data_source : pld_side_data_source; + + // 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; + + // Validate input parameters against known values or RBC values + initial begin + //$display("is_8g_0ppm = orig: '%s', any:'%s', all:'%s', final: '%s'", is_8g_0ppm, rbc_any_is_8g_0ppm, rbc_all_is_8g_0ppm, fnl_is_8g_0ppm); + if (!is_in_legal_set(is_8g_0ppm, rbc_all_is_8g_0ppm)) begin + $display("Critical Warning: parameter 'is_8g_0ppm' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", is_8g_0ppm, rbc_all_is_8g_0ppm, fnl_is_8g_0ppm); + end + //$display("pld_side_data_source = orig: '%s', any:'%s', all:'%s', final: '%s'", pld_side_data_source, rbc_any_pld_side_data_source, rbc_all_pld_side_data_source, fnl_pld_side_data_source); + if (!is_in_legal_set(pld_side_data_source, rbc_all_pld_side_data_source)) begin + $display("Critical Warning: parameter 'pld_side_data_source' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", pld_side_data_source, rbc_all_pld_side_data_source, fnl_pld_side_data_source); + end + //$display("use_default_base_address = orig: '%s', any:'%s', all:'%s', final: '%s'", use_default_base_address, rbc_any_use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + if (!is_in_legal_set(use_default_base_address, rbc_all_use_default_base_address)) begin + $display("Critical Warning: parameter 'use_default_base_address' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", use_default_base_address, rbc_all_use_default_base_address, fnl_use_default_base_address); + end + end + + arriav_hssi_tx_pld_pcs_interface #( + .avmm_group_channel_index(avmm_group_channel_index), + .is_8g_0ppm(fnl_is_8g_0ppm), + .pld_side_data_source(fnl_pld_side_data_source), + .use_default_base_address(fnl_use_default_base_address), + .user_base_address(user_base_address) + ) wys ( + // ports + .asynchdatain(asynchdatain), + .avmmaddress(avmmaddress), + .avmmbyteen(avmmbyteen), + .avmmclk(avmmclk), + .avmmread(avmmread), + .avmmreaddata(avmmreaddata), + .avmmrstn(avmmrstn), + .avmmwrite(avmmwrite), + .avmmwritedata(avmmwritedata), + .blockselect(blockselect), + .clockinfrom8gpcs(clockinfrom8gpcs), + .datainfrompld(datainfrompld), + .dataoutto8gpcs(dataoutto8gpcs), + .emsipenablediocsrrdydly(emsipenablediocsrrdydly), + .emsippcstxclkout(emsippcstxclkout), + .emsiptxin(emsiptxin), + .emsiptxspecialin(emsiptxspecialin), + .emsiptxspecialout(emsiptxspecialout), + .pcs8gemptytx(pcs8gemptytx), + .pcs8gfulltx(pcs8gfulltx), + .pcs8gphfifoursttx(pcs8gphfifoursttx), + .pcs8gpldtxclk(pcs8gpldtxclk), + .pcs8gpolinvtx(pcs8gpolinvtx), + .pcs8grddisabletx(pcs8grddisabletx), + .pcs8grevloopbk(pcs8grevloopbk), + .pcs8gtxboundarysel(pcs8gtxboundarysel), + .pcs8gtxdatavalid(pcs8gtxdatavalid), + .pcs8gtxurstpcs(pcs8gtxurstpcs), + .pcs8gwrenabletx(pcs8gwrenabletx), + .pld8gemptytx(pld8gemptytx), + .pld8gfulltx(pld8gfulltx), + .pld8gphfifoursttxn(pld8gphfifoursttxn), + .pld8gpldtxclk(pld8gpldtxclk), + .pld8gpolinvtx(pld8gpolinvtx), + .pld8grddisabletx(pld8grddisabletx), + .pld8grevloopbk(pld8grevloopbk), + .pld8gtxboundarysel(pld8gtxboundarysel), + .pld8gtxclkout(pld8gtxclkout), + .pld8gtxdatavalid(pld8gtxdatavalid), + .pld8gtxurstpcsn(pld8gtxurstpcsn), + .pld8gwrenabletx(pld8gwrenabletx), + .pmatxcmuplllock(pmatxcmuplllock), + .reset(reset), + .rstsel(rstsel), + .usrrstsel(usrrstsel) + ); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_pcs.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_pcs.sv new file mode 100644 index 0000000..3bda4e2 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_pcs.sv @@ -0,0 +1,1089 @@ +// (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. + + +// +// ALTERA CORPORATION +// +// av_pcs.sv +// automatically generated at 23:1:59, Fri Aug 26, 2011 +// +// + + +`timescale 1ps/1ps + + +module av_pcs + #( + //PARAM_LIST_START + parameter bonded_lanes = 1, + parameter bonding_master_ch = 0, + parameter enable_8g_rx = "true", + parameter enable_8g_tx = "true", + parameter enable_dyn_reconfig = "true", + parameter enable_gen12_pipe = "true", + parameter channel_number = 0, + + // Adding new parameter for PMA Direct + parameter enable_pma_direct_tx = "false", // (true,false) Enable, disable the PMA Direct path + parameter enable_pma_direct_rx = "false", // (true,false) Enable, disable the PMA Direct path + + // parameters for arriav_hssi_8g_rx_pcs + parameter pcs8g_rx_agg_block_sel = "", // same_smrt_pack|other_smrt_pack + parameter pcs8g_rx_auto_error_replacement = "", // dis_err_replace|en_err_replace + parameter pcs8g_rx_auto_speed_nego = "", // dis_asn|en_asn_g2_freq_scal + parameter pcs8g_rx_bist_ver = "", // dis_bist|incremental|cjpat|crpat + parameter pcs8g_rx_bist_ver_clr_flag = "", // dis_bist_clr_flag|en_bist_clr_flag + parameter pcs8g_rx_bit_reversal = "", // dis_bit_reversal|en_bit_reversal + parameter pcs8g_rx_bo_pad = 10'b0, + parameter pcs8g_rx_bo_pattern = 20'b0, + parameter pcs8g_rx_bypass_pipeline_reg = "", // dis_bypass_pipeline|en_bypass_pipeline + parameter pcs8g_rx_byte_deserializer = "", // dis_bds|en_bds_by_2|en_bds_by_2_det + parameter pcs8g_rx_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 pcs8g_rx_cdr_ctrl = "", // dis_cdr_ctrl|en_cdr_ctrl|en_cdr_ctrl_w_cid + parameter pcs8g_rx_cdr_ctrl_rxvalid_mask = "", // dis_rxvalid_mask|en_rxvalid_mask + parameter pcs8g_rx_cid_pattern = "", // cid_pattern_0|cid_pattern_1 + parameter pcs8g_rx_cid_pattern_len = 8'b0, + parameter pcs8g_rx_clkcmp_pattern_n = 20'b0, + parameter pcs8g_rx_clkcmp_pattern_p = 20'b0, + parameter pcs8g_rx_clock_gate_bds_dec_asn = "", // dis_bds_dec_asn_clk_gating|en_bds_dec_asn_clk_gating + parameter pcs8g_rx_clock_gate_bist = "", // dis_bist_clk_gating|en_bist_clk_gating + parameter pcs8g_rx_clock_gate_byteorder = "", // dis_byteorder_clk_gating|en_byteorder_clk_gating + parameter pcs8g_rx_clock_gate_cdr_eidle = "", // dis_cdr_eidle_clk_gating|en_cdr_eidle_clk_gating + parameter pcs8g_rx_clock_gate_dskw_rd = "", // dis_dskw_rdclk_gating|en_dskw_rdclk_gating + parameter pcs8g_rx_clock_gate_dw_dskw_wr = "", // dis_dw_dskw_wrclk_gating|en_dw_dskw_wrclk_gating + parameter pcs8g_rx_clock_gate_dw_pc_wrclk = "", // dis_dw_pc_wrclk_gating|en_dw_pc_wrclk_gating + parameter pcs8g_rx_clock_gate_dw_rm_rd = "", // dis_dw_rm_rdclk_gating|en_dw_rm_rdclk_gating + parameter pcs8g_rx_clock_gate_dw_rm_wr = "", // dis_dw_rm_wrclk_gating|en_dw_rm_wrclk_gating + parameter pcs8g_rx_clock_gate_dw_wa = "", // dis_dw_wa_clk_gating|en_dw_wa_clk_gating + parameter pcs8g_rx_clock_gate_pc_rdclk = "", // dis_pc_rdclk_gating|en_pc_rdclk_gating + parameter pcs8g_rx_clock_gate_prbs = "", // dis_prbs_clk_gating|en_prbs_clk_gating + parameter pcs8g_rx_clock_gate_sw_dskw_wr = "", // dis_sw_dskw_wrclk_gating|en_sw_dskw_wrclk_gating + parameter pcs8g_rx_clock_gate_sw_pc_wrclk = "", // dis_sw_pc_wrclk_gating|en_sw_pc_wrclk_gating + parameter pcs8g_rx_clock_gate_sw_rm_rd = "", // dis_sw_rm_rdclk_gating|en_sw_rm_rdclk_gating + parameter pcs8g_rx_clock_gate_sw_rm_wr = "", // dis_sw_rm_wrclk_gating|en_sw_rm_wrclk_gating + parameter pcs8g_rx_clock_gate_sw_wa = "", // dis_sw_wa_clk_gating|en_sw_wa_clk_gating + parameter pcs8g_rx_comp_fifo_rst_pld_ctrl = "", // dis_comp_fifo_rst_pld_ctrl|en_comp_fifo_rst_pld_ctrl + // BONDING_PARAM: parameter pcs8g_rx_ctrl_plane_bonding_compensation = "", // dis_compensation|en_compensation + // BONDING_PARAM: parameter pcs8g_rx_ctrl_plane_bonding_consumption = "", // individual|bundled_master|bundled_slave_below|bundled_slave_above + // BONDING_PARAM: parameter pcs8g_rx_ctrl_plane_bonding_distribution = "", // master_chnl_distr|not_master_chnl_distr + parameter pcs8g_rx_deskew = "", // dis_deskew|en_srio_v2p1|en_xaui + parameter pcs8g_rx_deskew_pattern = 10'b1101101000, + parameter pcs8g_rx_deskew_prog_pattern_only = "", // dis_deskew_prog_pat_only|en_deskew_prog_pat_only + parameter pcs8g_rx_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 pcs8g_rx_eidle_entry_eios = "", // dis_eidle_eios|en_eidle_eios + parameter pcs8g_rx_eidle_entry_iei = "", // dis_eidle_iei|en_eidle_iei + parameter pcs8g_rx_eidle_entry_sd = "", // dis_eidle_sd|en_eidle_sd + parameter pcs8g_rx_eightb_tenb_decoder = "", // dis_8b10b|en_8b10b_ibm|en_8b10b_sgx + parameter pcs8g_rx_eightbtenb_decoder_output_sel = "", // data_8b10b_decoder|data_xaui_sm + parameter pcs8g_rx_err_flags_sel = "", // err_flags_wa|err_flags_8b10b + parameter pcs8g_rx_fixed_pat_det = "", // dis_fixed_patdet|en_fixed_patdet + parameter pcs8g_rx_fixed_pat_num = 4'b1111, + parameter pcs8g_rx_force_signal_detect = "", // en_force_signal_detect|dis_force_signal_detect + parameter pcs8g_rx_hip_mode = "", // dis_hip|en_hip + parameter pcs8g_rx_ibm_invalid_code = "", // dis_ibm_invalid_code|en_ibm_invalid_code + parameter pcs8g_rx_invalid_code_flag_only = "", // dis_invalid_code_only|en_invalid_code_only + parameter pcs8g_rx_mask_cnt = 10'h3ff, + parameter pcs8g_rx_pad_or_edb_error_replace = "", // replace_edb|replace_pad|replace_edb_dynamic + parameter pcs8g_rx_pc_fifo_rst_pld_ctrl = "", // dis_pc_fifo_rst_pld_ctrl|en_pc_fifo_rst_pld_ctrl + parameter pcs8g_rx_pcs_bypass = "", // dis_pcs_bypass|en_pcs_bypass + parameter pcs8g_rx_phase_compensation_fifo = "", // low_latency|normal_latency|register_fifo|pld_ctrl_low_latency|pld_ctrl_normal_latency + parameter pcs8g_rx_pipe_if_enable = "", // dis_pipe_rx|en_pipe_rx + parameter pcs8g_rx_pma_done_count = 18'b0, + parameter pcs8g_rx_pma_dw = "", // eight_bit|ten_bit|sixteen_bit|twenty_bit + parameter pcs8g_rx_polarity_inversion = "", // dis_pol_inv|en_pol_inv + parameter pcs8g_rx_polinv_8b10b_dec = "", // dis_polinv_8b10b_dec|en_polinv_8b10b_dec + parameter pcs8g_rx_prbs_ver = "", // dis_prbs|prbs_7_sw|prbs_7_dw|prbs_8|prbs_10|prbs_23_sw|prbs_23_dw|prbs_15|prbs_31|prbs_hf_sw|prbs_hf_dw|prbs_lf_sw|prbs_lf_dw|prbs_mf_sw|prbs_mf_dw + parameter pcs8g_rx_prbs_ver_clr_flag = "", // dis_prbs_clr_flag|en_prbs_clr_flag + parameter pcs8g_rx_prot_mode = "", // pipe_g1|pipe_g2|cpri|cpri_rx_tx|gige|xaui|srio_2p1|test|basic|disabled_prot_mode + parameter pcs8g_rx_rate_match = "", // dis_rm|xaui_rm|gige_rm|pipe_rm|pipe_rm_0ppm|sw_basic_rm|srio_v2p1_rm|srio_v2p1_rm_0ppm|dw_basic_rm + parameter pcs8g_rx_re_bo_on_wa = "", // dis_re_bo_on_wa|en_re_bo_on_wa + parameter pcs8g_rx_runlength_check = "", // dis_runlength|en_runlength_sw|en_runlength_dw + parameter pcs8g_rx_runlength_val = 6'b0, + parameter pcs8g_rx_rx_clk1 = "", // rcvd_clk_clk1|tx_pma_clock_clk1|rcvd_clk_agg_clk1|rcvd_clk_agg_top_or_bottom_clk1 + parameter pcs8g_rx_rx_clk2 = "", // rcvd_clk_clk2|tx_pma_clock_clk2|refclk_dig2_clk2 + parameter pcs8g_rx_rx_clk_free_running = "", // dis_rx_clk_free_run|en_rx_clk_free_run + parameter pcs8g_rx_rx_pcs_urst = "", // dis_rx_pcs_urst|en_rx_pcs_urst + parameter pcs8g_rx_rx_rcvd_clk = "", // rcvd_clk_rcvd_clk|tx_pma_clock_rcvd_clk + parameter pcs8g_rx_rx_rd_clk = "", // pld_rx_clk|rx_clk + parameter pcs8g_rx_rx_refclk = "", // dis_refclk_sel|en_refclk_sel + parameter pcs8g_rx_rx_wr_clk = "", // rx_clk2_div_1_2_4|txfifo_rd_clk + parameter pcs8g_rx_sup_mode = "", // user_mode|engineering_mode + parameter pcs8g_rx_symbol_swap = "", // dis_symbol_swap|en_symbol_swap + parameter pcs8g_rx_test_bus_sel = "", // prbs_bist_testbus|tx_testbus|tx_ctrl_plane_testbus|wa_testbus|deskew_testbus|rm_testbus|rx_ctrl_testbus|pcie_ctrl_testbus|rx_ctrl_plane_testbus|agg_testbus + parameter pcs8g_rx_test_mode = "", // dont_care_test|prbs|bist + parameter pcs8g_rx_tx_rx_parallel_loopback = "", // dis_plpbk|en_plpbk + parameter pcs8g_rx_use_default_base_address = "true", // false|true + parameter pcs8g_rx_user_base_address = 0, // 0..2047 + parameter pcs8g_rx_wa_boundary_lock_ctrl = "", // bit_slip|sync_sm|deterministic_latency|auto_align_pld_ctrl + parameter pcs8g_rx_wa_clk_slip_spacing = "", // min_clk_slip_spacing|user_programmable_clk_slip_spacing + parameter pcs8g_rx_wa_clk_slip_spacing_data = 10'b10000, + parameter pcs8g_rx_wa_det_latency_sync_status_beh = "", // assert_sync_status_imm|assert_sync_status_non_imm|dont_care_assert_sync + parameter pcs8g_rx_wa_disp_err_flag = "", // dis_disp_err_flag|en_disp_err_flag + parameter pcs8g_rx_wa_kchar = "", // dis_kchar|en_kchar + parameter pcs8g_rx_wa_pd = "", // dont_care_wa_pd_0|dont_care_wa_pd_1|wa_pd_7|wa_pd_10|wa_pd_20|wa_pd_40|wa_pd_8_sw|wa_pd_8_dw|wa_pd_16_sw|wa_pd_16_dw|wa_pd_32|wa_pd_fixed_7_k28p5|wa_pd_fixed_10_k28p5|wa_pd_fixed_16_a1a2_sw|wa_pd_fixed_16_a1a2_dw|wa_pd_fixed_32_a1a1a2a2|prbs15_fixed_wa_pd_16_sw|prbs15_fixed_wa_pd_16_dw|prbs15_fixed_wa_pd_20_dw|prbs31_fixed_wa_pd_16_sw|prbs31_fixed_wa_pd_16_dw|prbs31_fixed_wa_pd_10_sw|prbs31_fixed_wa_pd_40_dw|prbs8_fixed_wa|prbs10_fixed_wa|prbs7_fixed_wa_pd_16_sw|prbs7_fixed_wa_pd_16_dw|prbs7_fixed_wa_pd_20_dw|prbs23_fixed_wa_pd_16_sw|prbs23_fixed_wa_pd_32_dw|prbs23_fixed_wa_pd_40_dw + parameter pcs8g_rx_wa_pd_data = 40'b0, + parameter pcs8g_rx_wa_pd_polarity = "", // dis_pd_both_pol|en_pd_both_pol|dont_care_both_pol + parameter pcs8g_rx_wa_pld_controlled = "", // dis_pld_ctrl|pld_ctrl_sw|rising_edge_sensitive_dw|level_sensitive_dw + parameter pcs8g_rx_wa_renumber_data = 6'b0, + parameter pcs8g_rx_wa_rgnumber_data = 8'b0, + parameter pcs8g_rx_wa_rknumber_data = 8'b0, + parameter pcs8g_rx_wa_rosnumber_data = 2'b0, + parameter pcs8g_rx_wa_rvnumber_data = 13'b0, + parameter pcs8g_rx_wa_sync_sm_ctrl = "", // gige_sync_sm|pipe_sync_sm|xaui_sync_sm|srio1p3_sync_sm|srio2p1_sync_sm|sw_basic_sync_sm|dw_basic_sync_sm|fibre_channel_sync_sm + parameter pcs8g_rx_wait_cnt = 8'b0, + + // parameters for arriav_hssi_8g_tx_pcs + parameter pcs8g_tx_agg_block_sel = "", // same_smrt_pack|other_smrt_pack + parameter pcs8g_tx_auto_speed_nego_gen2 = "", // dis_asn_g2|en_asn_g2_freq_scal + parameter pcs8g_tx_bist_gen = "", // dis_bist|incremental|cjpat|crpat + parameter pcs8g_tx_bit_reversal = "", // dis_bit_reversal|en_bit_reversal + parameter pcs8g_tx_bypass_pipeline_reg = "", // dis_bypass_pipeline|en_bypass_pipeline + parameter pcs8g_tx_byte_serializer = "", // dis_bs|en_bs_by_2 + parameter pcs8g_tx_cid_pattern = "", // cid_pattern_0|cid_pattern_1 + parameter pcs8g_tx_cid_pattern_len = 8'b0, + parameter pcs8g_tx_clock_gate_bist = "", // dis_bist_clk_gating|en_bist_clk_gating + parameter pcs8g_tx_clock_gate_bs_enc = "", // dis_bs_enc_clk_gating|en_bs_enc_clk_gating + parameter pcs8g_tx_clock_gate_dw_fifowr = "", // dis_dw_fifowr_clk_gating|en_dw_fifowr_clk_gating + parameter pcs8g_tx_clock_gate_fiford = "", // dis_fiford_clk_gating|en_fiford_clk_gating + parameter pcs8g_tx_clock_gate_prbs = "", // dis_prbs_clk_gating|en_prbs_clk_gating + parameter pcs8g_tx_clock_gate_sw_fifowr = "", // dis_sw_fifowr_clk_gating|en_sw_fifowr_clk_gating + // BONDING_PARAM: parameter pcs8g_tx_ctrl_plane_bonding_compensation = "", // dis_compensation|en_compensation + // BONDING_PARAM: parameter pcs8g_tx_ctrl_plane_bonding_consumption = "", // individual|bundled_master|bundled_slave_below|bundled_slave_above + // BONDING_PARAM: parameter pcs8g_tx_ctrl_plane_bonding_distribution = "", // master_chnl_distr|not_master_chnl_distr + parameter pcs8g_tx_data_selection_8b10b_encoder_input = "", // normal_data_path|xaui_sm|gige_idle_conversion + parameter pcs8g_tx_dynamic_clk_switch = "", // dis_dyn_clk_switch|en_dyn_clk_switch + parameter pcs8g_tx_eightb_tenb_disp_ctrl = "", // dis_disp_ctrl|en_disp_ctrl|en_ib_disp_ctrl + parameter pcs8g_tx_eightb_tenb_encoder = "", // dis_8b10b|en_8b10b_ibm|en_8b10b_sgx + parameter pcs8g_tx_force_echar = "", // dis_force_echar|en_force_echar + parameter pcs8g_tx_force_kchar = "", // dis_force_kchar|en_force_kchar + parameter pcs8g_tx_hip_mode = "", // dis_hip|en_hip + parameter pcs8g_tx_pcfifo_urst = "", // dis_pcfifourst|en_pcfifourst + parameter pcs8g_tx_pcs_bypass = "", // dis_pcs_bypass|en_pcs_bypass + parameter pcs8g_tx_phase_compensation_fifo = "", // low_latency|normal_latency|register_fifo|pld_ctrl_low_latency|pld_ctrl_normal_latency + parameter pcs8g_tx_phfifo_write_clk_sel = "", // pld_tx_clk|tx_clk + parameter pcs8g_tx_pma_dw = "", // eight_bit|ten_bit|sixteen_bit|twenty_bit + parameter pcs8g_tx_polarity_inversion = "", // dis_polinv|enable_polinv + parameter pcs8g_tx_prbs_gen = "", // dis_prbs|prbs_7_sw|prbs_7_dw|prbs_8|prbs_10|prbs_23_sw|prbs_23_dw|prbs_15|prbs_31|prbs_hf_sw|prbs_hf_dw|prbs_lf_sw|prbs_lf_dw|prbs_mf_sw|prbs_mf_dw + parameter pcs8g_tx_prot_mode = "", // pipe_g1|pipe_g2|cpri|cpri_rx_tx|gige|xaui|srio_2p1|test|basic|disabled_prot_mode + parameter pcs8g_tx_refclk_b_clk_sel = "", // tx_pma_clock|refclk_dig + parameter pcs8g_tx_revloop_back_rm = "", // dis_rev_loopback_rx_rm|en_rev_loopback_rx_rm + parameter pcs8g_tx_sup_mode = "", // user_mode|engineering_mode + parameter pcs8g_tx_symbol_swap = "", // dis_symbol_swap|en_symbol_swap + parameter pcs8g_tx_test_mode = "", // dont_care_test|prbs|bist + parameter pcs8g_tx_tx_bitslip = "", // dis_tx_bitslip|en_tx_bitslip + parameter pcs8g_tx_tx_compliance_controlled_disparity = "", // dis_txcompliance|en_txcompliance_pipe2p0 + parameter pcs8g_tx_txclk_freerun = "", // dis_freerun_tx|en_freerun_tx + parameter pcs8g_tx_txpcs_urst = "", // dis_txpcs_urst|en_txpcs_urst + parameter pcs8g_tx_use_default_base_address = "true", // false|true + parameter pcs8g_tx_user_base_address = 0, // 0..2047 + + // parameters for arriav_hssi_common_pcs_pma_interface + parameter com_pcs_pma_if_auto_speed_ena = "", // dis_auto_speed_ena|en_auto_speed_ena + parameter com_pcs_pma_if_force_freqdet = "", // force_freqdet_dis|force1_freqdet_en|force0_freqdet_en + parameter com_pcs_pma_if_func_mode = "", // disable|hrdrstctrl_cmu|eightg_only_pld|eightg_only_hip|pma_direct + parameter com_pcs_pma_if_pipe_if_g3pcs = "", // pipe_if_8gpcs + parameter com_pcs_pma_if_pma_if_dft_en = "dft_dis", // dft_dis + parameter com_pcs_pma_if_pma_if_dft_val = "dft_0", // dft_0 + parameter com_pcs_pma_if_ppm_cnt_rst = "", // ppm_cnt_rst_dis|ppm_cnt_rst_en + parameter com_pcs_pma_if_ppm_deassert_early = "", // deassert_early_dis|deassert_early_en + parameter com_pcs_pma_if_ppm_gen1_2_cnt = "", // cnt_32k|cnt_64k + parameter com_pcs_pma_if_ppm_post_eidle_delay = "", // cnt_200_cycles|cnt_400_cycles + parameter com_pcs_pma_if_ppmsel = "", // ppmsel_default|ppmsel_1000|ppmsel_500|ppmsel_300|ppmsel_250|ppmsel_200|ppmsel_125|ppmsel_100|ppmsel_62p5|ppm_other + parameter com_pcs_pma_if_prot_mode = "", // disabled_prot_mode|pipe_g1|pipe_g2|other_protocols + parameter com_pcs_pma_if_selectpcs = "", // eight_g_pcs + parameter com_pcs_pma_if_sup_mode = "", // user_mode|engineering_mode + parameter com_pcs_pma_if_use_default_base_address = "true", // false|true + parameter com_pcs_pma_if_user_base_address = 0, // 0..2047 + + // parameters for arriav_hssi_common_pld_pcs_interface + parameter com_pld_pcs_if_hip_enable = "hip_disable", // hip_disable|hip_enable + parameter com_pld_pcs_if_hrdrstctrl_en_cfg = "hrst_dis_cfg", // hrst_dis_cfg|hrst_en_cfg + parameter com_pld_pcs_if_hrdrstctrl_en_cfgusr = "hrst_dis_cfgusr", // hrst_dis_cfgusr|hrst_en_cfgusr + parameter com_pld_pcs_if_pld_side_data_source = "pld", // hip|pld + parameter com_pld_pcs_if_pld_side_reserved_source0 = "pld_res0", // pld_res0|hip_res0 + parameter com_pld_pcs_if_pld_side_reserved_source1 = "pld_res1", // pld_res1|hip_res1 + parameter com_pld_pcs_if_pld_side_reserved_source10 = "pld_res10", // pld_res10|hip_res10 + parameter com_pld_pcs_if_pld_side_reserved_source11 = "pld_res11", // pld_res11|hip_res11 + parameter com_pld_pcs_if_pld_side_reserved_source2 = "pld_res2", // pld_res2|hip_res2 + parameter com_pld_pcs_if_pld_side_reserved_source3 = "pld_res3", // pld_res3|hip_res3 + parameter com_pld_pcs_if_pld_side_reserved_source4 = "pld_res4", // pld_res4|hip_res4 + parameter com_pld_pcs_if_pld_side_reserved_source5 = "pld_res5", // pld_res5|hip_res5 + parameter com_pld_pcs_if_pld_side_reserved_source6 = "pld_res6", // pld_res6|hip_res6 + parameter com_pld_pcs_if_pld_side_reserved_source7 = "pld_res7", // pld_res7|hip_res7 + parameter com_pld_pcs_if_pld_side_reserved_source8 = "pld_res8", // pld_res8|hip_res8 + parameter com_pld_pcs_if_pld_side_reserved_source9 = "pld_res9", // pld_res9|hip_res9 + parameter com_pld_pcs_if_testbus_sel = "eight_g_pcs", // eight_g_pcs|pma_if + parameter com_pld_pcs_if_use_default_base_address = "true", // false|true + parameter com_pld_pcs_if_user_base_address = 0, // 0..2047 + parameter com_pld_pcs_if_usrmode_sel4rst = "usermode", // usermode|last_frz + + // parameters for arriav_hssi_pipe_gen1_2 + // BONDING_PARAM: parameter pipe12_ctrl_plane_bonding_consumption = "individual", // individual|bundled_master|bundled_slave_below|bundled_slave_above + parameter pipe12_elec_idle_delay_val = 3'b0, + parameter pipe12_elecidle_delay = "elec_idle_delay", // elec_idle_delay + parameter pipe12_error_replace_pad = "", // replace_edb|replace_pad + parameter pipe12_hip_mode = "", // dis_hip|en_hip + parameter pipe12_ind_error_reporting = "", // dis_ind_error_reporting|en_ind_error_reporting + parameter pipe12_phy_status_delay = "phystatus_delay", // phystatus_delay + parameter pipe12_phystatus_delay_val = 3'b0, + parameter pipe12_phystatus_rst_toggle = "", // dis_phystatus_rst_toggle|en_phystatus_rst_toggle + parameter pipe12_pipe_byte_de_serializer_en = "", // dis_bds|en_bds_by_2|dont_care_bds + parameter pipe12_prot_mode = "", // pipe_g1|pipe_g2|srio_2p1|basic|disabled_prot_mode + parameter pipe12_rpre_emph_a_val = 6'b0, + parameter pipe12_rpre_emph_b_val = 6'b0, + parameter pipe12_rpre_emph_c_val = 6'b0, + parameter pipe12_rpre_emph_d_val = 6'b0, + parameter pipe12_rpre_emph_e_val = 6'b0, + parameter pipe12_rpre_emph_settings = 6'b0, + parameter pipe12_rvod_sel_a_val = 6'b0, + parameter pipe12_rvod_sel_b_val = 6'b0, + parameter pipe12_rvod_sel_c_val = 6'b0, + parameter pipe12_rvod_sel_d_val = 6'b0, + parameter pipe12_rvod_sel_e_val = 6'b0, + parameter pipe12_rvod_sel_settings = 6'b0, + parameter pipe12_rx_pipe_enable = "", // dis_pipe_rx|en_pipe_rx + parameter pipe12_rxdetect_bypass = "", // dis_rxdetect_bypass|en_rxdetect_bypass + parameter pipe12_sup_mode = "user_mode", // user_mode|engineering_mode + parameter pipe12_tx_pipe_enable = "", // dis_pipe_tx|en_pipe_tx + parameter pipe12_txswing = "", // dis_txswing|en_txswing + parameter pipe12_use_default_base_address = "true", // false|true + parameter pipe12_user_base_address = 0, // 0..2047 + + // parameters for arriav_hssi_rx_pcs_pma_interface + parameter rx_pcs_pma_if_clkslip_sel = "", // pld|slip_eight_g_pcs + parameter rx_pcs_pma_if_prot_mode = "", // other_protocols|cpri_8g + parameter rx_pcs_pma_if_selectpcs = "eight_g_pcs", // eight_g_pcs|default + parameter rx_pcs_pma_if_use_default_base_address = "true", // false|true + parameter rx_pcs_pma_if_user_base_address = 0, // 0..2047 + + // parameters for arriav_hssi_rx_pld_pcs_interface + parameter rx_pld_pcs_if_is_8g_0ppm = "false", // false|true + parameter rx_pld_pcs_if_pcs_side_block_sel = "eight_g_pcs", // eight_g_pcs|default + parameter rx_pld_pcs_if_pld_side_data_source = "pld", // hip|pld + parameter rx_pld_pcs_if_use_default_base_address = "true", // false|true + parameter rx_pld_pcs_if_user_base_address = 0, // 0..2047 + + // parameters for arriav_hssi_tx_pcs_pma_interface + parameter tx_pcs_pma_if_selectpcs = "eight_g_pcs", // eight_g_pcs|default + parameter tx_pcs_pma_if_use_default_base_address = "true", // false|true + parameter tx_pcs_pma_if_user_base_address = 0, // 0..2047 + + // parameters for arriav_hssi_tx_pld_pcs_interface + parameter tx_pld_pcs_if_is_8g_0ppm = "false", // false|true + parameter tx_pld_pcs_if_pld_side_data_source = "pld", // hip|pld + parameter tx_pld_pcs_if_use_default_base_address = "true", // false|true + parameter tx_pld_pcs_if_user_base_address = 0 // 0..2047 + //PARAM_LIST_END + ) + ( + //PORT_LIST_START + input wire [bonded_lanes - 1:0] in_agg_align_status, + input wire [bonded_lanes - 1:0] in_agg_align_status_sync_0, + input wire [bonded_lanes - 1:0] in_agg_align_status_sync_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_align_status_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_rd_d_all, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_rd_d_all_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_wr_all, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_wr_all_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_del_cond_met_0, + input wire [bonded_lanes - 1:0] in_agg_del_cond_met_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_qd, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_qd_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_rd_ptrs, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_rd_ptrs_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_fifo_ovr_0, + input wire [bonded_lanes - 1:0] in_agg_fifo_ovr_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_fifo_rd_in_comp_0, + input wire [bonded_lanes - 1:0] in_agg_fifo_rd_in_comp_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_fifo_rst_rd_qd, + input wire [bonded_lanes - 1:0] in_agg_fifo_rst_rd_qd_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_insert_incomplete_0, + input wire [bonded_lanes - 1:0] in_agg_insert_incomplete_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_latency_comp_0, + input wire [bonded_lanes - 1:0] in_agg_latency_comp_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_rcvd_clk_agg, + input wire [bonded_lanes - 1:0] in_agg_rcvd_clk_agg_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_rx_control_rs, + input wire [bonded_lanes - 1:0] in_agg_rx_control_rs_top_or_bot, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_rx_data_rs, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_rx_data_rs_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_test_so_to_pld_in, + input wire [bonded_lanes * 16 - 1 : 0] in_agg_testbus, + input wire [bonded_lanes - 1:0] in_agg_tx_ctl_ts, + input wire [bonded_lanes - 1:0] in_agg_tx_ctl_ts_top_or_bot, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_tx_data_ts, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_tx_data_ts_top_or_bot, + input wire [bonded_lanes * 11 - 1 : 0] in_avmmaddress, + input wire [bonded_lanes * 2 - 1 : 0] in_avmmbyteen, + input wire [bonded_lanes - 1:0] in_avmmclk, + input wire [bonded_lanes - 1:0] in_avmmread, + input wire [bonded_lanes - 1:0] in_avmmrstn, + input wire [bonded_lanes - 1:0] in_avmmwrite, + input wire [bonded_lanes * 16 - 1 : 0] in_avmmwritedata, + input wire [bonded_lanes * 38 - 1 : 0] in_emsip_com_in, + input wire [bonded_lanes * 13 - 1 : 0] in_emsip_rx_special_in, + input wire [bonded_lanes * 104 - 1 : 0] in_emsip_tx_in, + input wire [bonded_lanes * 13 - 1 : 0] in_emsip_tx_special_in, + input wire [bonded_lanes - 1:0] in_pld_8g_a1a2_size, + input wire [bonded_lanes - 1:0] in_pld_8g_bitloc_rev_en, + input wire [bonded_lanes - 1:0] in_pld_8g_bitslip, + input wire [bonded_lanes - 1:0] in_pld_8g_byte_rev_en, + input wire [bonded_lanes - 1:0] in_pld_8g_bytordpld, + input wire [bonded_lanes - 1:0] in_pld_8g_cmpfifourst_n, + input wire [bonded_lanes - 1:0] in_pld_8g_encdt, + input wire [bonded_lanes - 1:0] in_pld_8g_phfifourst_rx_n, + input wire [bonded_lanes - 1:0] in_pld_8g_phfifourst_tx_n, + input wire [bonded_lanes - 1:0] in_pld_8g_pld_rx_clk, + input wire [bonded_lanes - 1:0] in_pld_8g_pld_tx_clk, + input wire [bonded_lanes - 1:0] in_pld_8g_polinv_rx, + input wire [bonded_lanes - 1:0] in_pld_8g_polinv_tx, + input wire [bonded_lanes * 2 - 1 : 0] in_pld_8g_powerdown, + input wire [bonded_lanes - 1:0] in_pld_8g_prbs_cid_en, + input wire [bonded_lanes - 1:0] in_pld_8g_rddisable_tx, + input wire [bonded_lanes - 1:0] in_pld_8g_rdenable_rmf, + input wire [bonded_lanes - 1:0] in_pld_8g_rdenable_rx, + input wire [bonded_lanes - 1:0] in_pld_8g_refclk_dig, + input wire [bonded_lanes - 1:0] in_pld_8g_refclk_dig2, + input wire [bonded_lanes - 1:0] in_pld_8g_rev_loopbk, + input wire [bonded_lanes - 1:0] in_pld_8g_rxpolarity, + input wire [bonded_lanes - 1:0] in_pld_8g_rxurstpcs_n, + input wire [bonded_lanes * 5 - 1 : 0] in_pld_8g_tx_boundary_sel, + input wire [bonded_lanes * 4 - 1 : 0] in_pld_8g_tx_data_valid, + input wire [bonded_lanes - 1:0] in_pld_8g_txdeemph, + input wire [bonded_lanes - 1:0] in_pld_8g_txdetectrxloopback, + input wire [bonded_lanes - 1:0] in_pld_8g_txelecidle, + input wire [bonded_lanes * 3 - 1 : 0] in_pld_8g_txmargin, + input wire [bonded_lanes - 1:0] in_pld_8g_txswing, + input wire [bonded_lanes - 1:0] in_pld_8g_txurstpcs_n, + input wire [bonded_lanes - 1:0] in_pld_8g_wrdisable_rx, + input wire [bonded_lanes - 1:0] in_pld_8g_wrenable_rmf, + input wire [bonded_lanes - 1:0] in_pld_8g_wrenable_tx, + input wire [bonded_lanes - 1:0] in_pld_agg_refclk_dig, + input wire [bonded_lanes * 3 - 1 : 0] in_pld_eidleinfersel, + input wire [bonded_lanes - 1:0] in_pld_ltr, + input wire [bonded_lanes - 1:0] in_pld_partial_reconfig_in, + input wire [bonded_lanes - 1:0] in_pld_pcs_pma_if_refclk_dig, + input wire [bonded_lanes - 1:0] in_pld_rate, + input wire [bonded_lanes * 12 - 1 : 0] in_pld_reserved_in, + input wire [bonded_lanes - 1:0] in_pld_rx_clk_slip_in, + input wire [bonded_lanes - 1:0] in_pld_rxpma_rstb_in, + input wire [bonded_lanes - 1:0] in_pld_scan_mode_n, + input wire [bonded_lanes - 1:0] in_pld_scan_shift_n, + input wire [bonded_lanes - 1:0] in_pld_sync_sm_en, + input wire [bonded_lanes * 44 - 1 : 0] in_pld_tx_data, + input wire [bonded_lanes - 1:0] in_pma_clklow_in, + input wire [bonded_lanes - 1:0] in_pma_fref_in, + input wire [bonded_lanes - 1:0] in_pma_hclk, + input wire [bonded_lanes - 1:0] in_pma_pcie_sw_done, + input wire [bonded_lanes * 5 - 1 : 0] in_pma_reserved_in, + input wire [bonded_lanes * 20 - 1 : 0] in_pma_rx_data, + input wire [bonded_lanes - 1:0] in_pma_rx_detect_valid, + input wire [bonded_lanes - 1:0] in_pma_rx_found, + input wire [bonded_lanes - 1:0] in_pma_rx_freq_tx_cmu_pll_lock_in, + input wire [bonded_lanes - 1:0] in_pma_rx_pll_phase_lock_in, + input wire [bonded_lanes - 1:0] in_pma_rx_pma_clk, + input wire [bonded_lanes - 1:0] in_pma_sigdet, + input wire [bonded_lanes - 1:0] in_pma_tx_pma_clk, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_align_det_sync, + output wire [bonded_lanes - 1:0] out_agg_align_status_sync, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_cg_comp_rd_d_out, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_cg_comp_wr_out, + output wire [bonded_lanes - 1:0] out_agg_dec_ctl, + output wire [bonded_lanes * 8 - 1 : 0] out_agg_dec_data, + output wire [bonded_lanes - 1:0] out_agg_dec_data_valid, + output wire [bonded_lanes - 1:0] out_agg_del_cond_met_out, + output wire [bonded_lanes - 1:0] out_agg_fifo_ovr_out, + output wire [bonded_lanes - 1:0] out_agg_fifo_rd_out_comp, + output wire [bonded_lanes - 1:0] out_agg_insert_incomplete_out, + output wire [bonded_lanes - 1:0] out_agg_latency_comp_out, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_rd_align, + output wire [bonded_lanes - 1:0] out_agg_rd_enable_sync, + output wire [bonded_lanes - 1:0] out_agg_refclk_dig, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_running_disp, + output wire [bonded_lanes - 1:0] out_agg_rxpcs_rst, + output wire [bonded_lanes - 1:0] out_agg_scan_mode_n, + output wire [bonded_lanes - 1:0] out_agg_scan_shift_n, + output wire [bonded_lanes - 1:0] out_agg_sync_status, + output wire [bonded_lanes - 1:0] out_agg_tx_ctl_tc, + output wire [bonded_lanes * 8 - 1 : 0] out_agg_tx_data_tc, + output wire [bonded_lanes - 1:0] out_agg_txpcs_rst, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_com_pcs_pma_if, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_com_pld_pcs_if, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_pcs8g_rx, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_pcs8g_tx, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_pipe12, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_rx_pcs_pma_if, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_rx_pld_pcs_if, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_tx_pcs_pma_if, + output wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_tx_pld_pcs_if, + output wire [bonded_lanes - 1:0] out_blockselect_com_pcs_pma_if, + output wire [bonded_lanes - 1:0] out_blockselect_com_pld_pcs_if, + output wire [bonded_lanes - 1:0] out_blockselect_pcs8g_rx, + output wire [bonded_lanes - 1:0] out_blockselect_pcs8g_tx, + output wire [bonded_lanes - 1:0] out_blockselect_pipe12, + output wire [bonded_lanes - 1:0] out_blockselect_rx_pcs_pma_if, + output wire [bonded_lanes - 1:0] out_blockselect_rx_pld_pcs_if, + output wire [bonded_lanes - 1:0] out_blockselect_tx_pcs_pma_if, + output wire [bonded_lanes - 1:0] out_blockselect_tx_pld_pcs_if, + output wire [bonded_lanes * 3 - 1 : 0] out_emsip_com_clk_out, + output wire [bonded_lanes * 27 - 1 : 0] out_emsip_com_out, + output wire [bonded_lanes * 129 - 1 : 0] out_emsip_rx_out, + output wire [bonded_lanes * 16 - 1 : 0] out_emsip_rx_special_out, + output wire [bonded_lanes * 3 - 1 : 0] out_emsip_tx_clk_out, + output wire [bonded_lanes * 16 - 1 : 0] out_emsip_tx_special_out, + output wire [bonded_lanes * 4 - 1 : 0] out_pld_8g_a1a2_k1k2_flag, + output wire [bonded_lanes - 1:0] out_pld_8g_align_status, + output wire [bonded_lanes - 1:0] out_pld_8g_bistdone, + output wire [bonded_lanes - 1:0] out_pld_8g_bisterr, + output wire [bonded_lanes - 1:0] out_pld_8g_byteord_flag, + output wire [bonded_lanes - 1:0] out_pld_8g_empty_rmf, + output wire [bonded_lanes - 1:0] out_pld_8g_empty_rx, + output wire [bonded_lanes - 1:0] out_pld_8g_empty_tx, + output wire [bonded_lanes - 1:0] out_pld_8g_full_rmf, + output wire [bonded_lanes - 1:0] out_pld_8g_full_rx, + output wire [bonded_lanes - 1:0] out_pld_8g_full_tx, + output wire [bonded_lanes - 1:0] out_pld_8g_phystatus, + output wire [bonded_lanes - 1:0] out_pld_8g_rlv_lt, + output wire [bonded_lanes - 1:0] out_pld_8g_rx_clk_out, + output wire [bonded_lanes * 4 - 1 : 0] out_pld_8g_rx_data_valid, + output wire [bonded_lanes - 1:0] out_pld_8g_rxelecidle, + output wire [bonded_lanes * 3 - 1 : 0] out_pld_8g_rxstatus, + output wire [bonded_lanes - 1:0] out_pld_8g_rxvalid, + output wire [bonded_lanes - 1:0] out_pld_8g_signal_detect_out, + output wire [bonded_lanes - 1:0] out_pld_8g_tx_clk_out, + output wire [bonded_lanes * 5 - 1 : 0] out_pld_8g_wa_boundary, + output wire [bonded_lanes - 1:0] out_pld_clklow, + output wire [bonded_lanes - 1:0] out_pld_fref, + output wire [bonded_lanes * 11 - 1 : 0] out_pld_reserved_out, + output wire [bonded_lanes * 64 - 1 : 0] out_pld_rx_data, + output wire [bonded_lanes * 20 - 1 : 0] out_pld_test_data, + output wire [bonded_lanes - 1:0] out_pld_test_si_to_agg_out, + output wire [bonded_lanes * 12 - 1 : 0] out_pma_current_coeff, + output wire [bonded_lanes - 1:0] out_pma_early_eios, + output wire [bonded_lanes - 1:0] out_pma_ltr, + output wire [bonded_lanes - 1:0] out_pma_nfrzdrv, + output wire [bonded_lanes - 1:0] out_pma_partial_reconfig, + output wire [bonded_lanes - 1:0] out_pma_pcie_switch, + output wire [bonded_lanes - 1:0] out_pma_ppm_lock, + output wire [bonded_lanes * 5 - 1 : 0] out_pma_reserved_out, + output wire [bonded_lanes - 1:0] out_pma_rx_clk_out, + output wire [bonded_lanes - 1:0] out_pma_rxclkslip, + output wire [bonded_lanes - 1:0] out_pma_rxpma_rstb, + output wire [bonded_lanes - 1:0] out_pma_tx_clk_out, + output wire [bonded_lanes * 20 - 1 : 0] out_pma_tx_data, + output wire [bonded_lanes - 1:0] out_pma_tx_elec_idle, + output wire [bonded_lanes - 1:0] out_pma_txdetectrx + //PORT_LIST_END + ); + //wire declarations for bonded connections + + // module arriav_hssi_8g_rx_pcs + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_wrenableoutchnlup; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_rdenableoutchnlup; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_rx_rxdivsyncoutchnlup; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_resetppmcntrsoutchnlup; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_configseloutchnlup; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_speedchangeoutchnlup; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_rx_rxweoutchnlup; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_resetpcptrsoutchnlup; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_speedchangeoutchnldown; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_rx_rxweoutchnldown; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_wrenableoutchnldown; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_rx_rxdivsyncoutchnldown; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_resetppmcntrsoutchnldown; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_resetpcptrsoutchnldown; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_rdenableoutchnldown; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_rx_configseloutchnldown; + + // module arriav_hssi_8g_tx_pcs + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_tx_wrenableoutchnlup; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_tx_rdenableoutchnlup; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_tx_txdivsyncoutchnlup; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_tx_fifoselectoutchnlup; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_tx_fifoselectoutchnldown; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_tx_wrenableoutchnldown; + wire [(bonded_lanes + 2) * 2 - 1 : 0] w_pcs8g_tx_txdivsyncoutchnldown; + wire [(bonded_lanes + 2)- 1:0] w_pcs8g_tx_rdenableoutchnldown; + + + // instantiation of av_pcs_ch + genvar i; + generate + for (i=0; i < bonded_lanes; i = i + 1) + begin:ch + av_pcs_ch #( + // parameters + .enable_8g_rx (enable_8g_rx), + .enable_8g_tx (enable_8g_tx), + .enable_dyn_reconfig (enable_dyn_reconfig), + .enable_gen12_pipe (enable_gen12_pipe), + .channel_number (i), + .enable_pma_direct_tx (enable_pma_direct_tx), + .enable_pma_direct_rx (enable_pma_direct_rx), + + // parameters for arriav_hssi_8g_rx_pcs + .pcs8g_rx_agg_block_sel(pcs8g_rx_agg_block_sel), + .pcs8g_rx_auto_error_replacement(pcs8g_rx_auto_error_replacement), + .pcs8g_rx_auto_speed_nego(pcs8g_rx_auto_speed_nego), + .pcs8g_rx_bist_ver(pcs8g_rx_bist_ver), + .pcs8g_rx_bist_ver_clr_flag(pcs8g_rx_bist_ver_clr_flag), + .pcs8g_rx_bit_reversal(pcs8g_rx_bit_reversal), + .pcs8g_rx_bo_pad(pcs8g_rx_bo_pad), + .pcs8g_rx_bo_pattern(pcs8g_rx_bo_pattern), + .pcs8g_rx_bypass_pipeline_reg(pcs8g_rx_bypass_pipeline_reg), + .pcs8g_rx_byte_deserializer(pcs8g_rx_byte_deserializer), + .pcs8g_rx_byte_order(pcs8g_rx_byte_order), + .pcs8g_rx_cdr_ctrl(pcs8g_rx_cdr_ctrl), + .pcs8g_rx_cdr_ctrl_rxvalid_mask(pcs8g_rx_cdr_ctrl_rxvalid_mask), + .pcs8g_rx_cid_pattern(pcs8g_rx_cid_pattern), + .pcs8g_rx_cid_pattern_len(pcs8g_rx_cid_pattern_len), + .pcs8g_rx_clkcmp_pattern_n(pcs8g_rx_clkcmp_pattern_n), + .pcs8g_rx_clkcmp_pattern_p(pcs8g_rx_clkcmp_pattern_p), + .pcs8g_rx_clock_gate_bds_dec_asn(pcs8g_rx_clock_gate_bds_dec_asn), + .pcs8g_rx_clock_gate_bist(pcs8g_rx_clock_gate_bist), + .pcs8g_rx_clock_gate_byteorder(pcs8g_rx_clock_gate_byteorder), + .pcs8g_rx_clock_gate_cdr_eidle(pcs8g_rx_clock_gate_cdr_eidle), + .pcs8g_rx_clock_gate_dskw_rd(pcs8g_rx_clock_gate_dskw_rd), + .pcs8g_rx_clock_gate_dw_dskw_wr(pcs8g_rx_clock_gate_dw_dskw_wr), + .pcs8g_rx_clock_gate_dw_pc_wrclk(pcs8g_rx_clock_gate_dw_pc_wrclk), + .pcs8g_rx_clock_gate_dw_rm_rd(pcs8g_rx_clock_gate_dw_rm_rd), + .pcs8g_rx_clock_gate_dw_rm_wr(pcs8g_rx_clock_gate_dw_rm_wr), + .pcs8g_rx_clock_gate_dw_wa(pcs8g_rx_clock_gate_dw_wa), + .pcs8g_rx_clock_gate_pc_rdclk(pcs8g_rx_clock_gate_pc_rdclk), + .pcs8g_rx_clock_gate_prbs(pcs8g_rx_clock_gate_prbs), + .pcs8g_rx_clock_gate_sw_dskw_wr(pcs8g_rx_clock_gate_sw_dskw_wr), + .pcs8g_rx_clock_gate_sw_pc_wrclk(pcs8g_rx_clock_gate_sw_pc_wrclk), + .pcs8g_rx_clock_gate_sw_rm_rd(pcs8g_rx_clock_gate_sw_rm_rd), + .pcs8g_rx_clock_gate_sw_rm_wr(pcs8g_rx_clock_gate_sw_rm_wr), + .pcs8g_rx_clock_gate_sw_wa(pcs8g_rx_clock_gate_sw_wa), + .pcs8g_rx_comp_fifo_rst_pld_ctrl(pcs8g_rx_comp_fifo_rst_pld_ctrl), + .pcs8g_rx_ctrl_plane_bonding_compensation( +((pcs8g_rx_prot_mode!="pipe_g1")&& (pcs8g_rx_prot_mode!="pipe_g2")&& (pcs8g_rx_prot_mode!="pipe_g3")&& (pcs8g_rx_prot_mode!="xaui"))? "dis_compensation" : +(pcs8g_rx_byte_deserializer=="en_bds_by_4") ? "en_compensation" : + "dis_compensation" +), + .pcs8g_rx_ctrl_plane_bonding_consumption( +((pcs8g_rx_prot_mode!="pipe_g1")&& (pcs8g_rx_prot_mode!="pipe_g2")&& (pcs8g_rx_prot_mode!="pipe_g3")&& (pcs8g_rx_prot_mode!="xaui"))? "individual" : +(bonded_lanes==1)? "individual": +(i==bonding_master_ch)? "bundled_master": +(i < bonding_master_ch)? "bundled_slave_below": +"bundled_slave_above" +), + .pcs8g_rx_ctrl_plane_bonding_distribution( +((pcs8g_rx_prot_mode!="pipe_g1")&& (pcs8g_rx_prot_mode!="pipe_g2")&& (pcs8g_rx_prot_mode!="pipe_g3")&& (pcs8g_rx_prot_mode!="xaui"))? "not_master_chnl_distr" : +(bonded_lanes==1)? "not_master_chnl_distr": + (i==bonding_master_ch)? "master_chnl_distr": +"not_master_chnl_distr" +), + .pcs8g_rx_deskew(pcs8g_rx_deskew), + .pcs8g_rx_deskew_pattern(pcs8g_rx_deskew_pattern), + .pcs8g_rx_deskew_prog_pattern_only(pcs8g_rx_deskew_prog_pattern_only), + .pcs8g_rx_dw_one_or_two_symbol_bo(pcs8g_rx_dw_one_or_two_symbol_bo), + .pcs8g_rx_eidle_entry_eios(pcs8g_rx_eidle_entry_eios), + .pcs8g_rx_eidle_entry_iei(pcs8g_rx_eidle_entry_iei), + .pcs8g_rx_eidle_entry_sd(pcs8g_rx_eidle_entry_sd), + .pcs8g_rx_eightb_tenb_decoder(pcs8g_rx_eightb_tenb_decoder), + .pcs8g_rx_eightbtenb_decoder_output_sel(pcs8g_rx_eightbtenb_decoder_output_sel), + .pcs8g_rx_err_flags_sel(pcs8g_rx_err_flags_sel), + .pcs8g_rx_fixed_pat_det(pcs8g_rx_fixed_pat_det), + .pcs8g_rx_fixed_pat_num(pcs8g_rx_fixed_pat_num), + .pcs8g_rx_force_signal_detect(pcs8g_rx_force_signal_detect), + .pcs8g_rx_hip_mode(pcs8g_rx_hip_mode), + .pcs8g_rx_ibm_invalid_code(pcs8g_rx_ibm_invalid_code), + .pcs8g_rx_invalid_code_flag_only(pcs8g_rx_invalid_code_flag_only), + .pcs8g_rx_mask_cnt(pcs8g_rx_mask_cnt), + .pcs8g_rx_pad_or_edb_error_replace(pcs8g_rx_pad_or_edb_error_replace), + .pcs8g_rx_pc_fifo_rst_pld_ctrl(pcs8g_rx_pc_fifo_rst_pld_ctrl), + .pcs8g_rx_pcs_bypass(pcs8g_rx_pcs_bypass), + .pcs8g_rx_phase_compensation_fifo(pcs8g_rx_phase_compensation_fifo), + .pcs8g_rx_pipe_if_enable(pcs8g_rx_pipe_if_enable), + .pcs8g_rx_pma_done_count(pcs8g_rx_pma_done_count), + .pcs8g_rx_pma_dw(pcs8g_rx_pma_dw), + .pcs8g_rx_polarity_inversion(pcs8g_rx_polarity_inversion), + .pcs8g_rx_polinv_8b10b_dec(pcs8g_rx_polinv_8b10b_dec), + .pcs8g_rx_prbs_ver(pcs8g_rx_prbs_ver), + .pcs8g_rx_prbs_ver_clr_flag(pcs8g_rx_prbs_ver_clr_flag), + .pcs8g_rx_prot_mode(pcs8g_rx_prot_mode), + .pcs8g_rx_rate_match(pcs8g_rx_rate_match), + .pcs8g_rx_re_bo_on_wa(pcs8g_rx_re_bo_on_wa), + .pcs8g_rx_runlength_check(pcs8g_rx_runlength_check), + .pcs8g_rx_runlength_val(pcs8g_rx_runlength_val), + .pcs8g_rx_rx_clk1(pcs8g_rx_rx_clk1), + .pcs8g_rx_rx_clk2(pcs8g_rx_rx_clk2), + .pcs8g_rx_rx_clk_free_running(pcs8g_rx_rx_clk_free_running), + .pcs8g_rx_rx_pcs_urst(pcs8g_rx_rx_pcs_urst), + .pcs8g_rx_rx_rcvd_clk(pcs8g_rx_rx_rcvd_clk), + .pcs8g_rx_rx_rd_clk(pcs8g_rx_rx_rd_clk), + .pcs8g_rx_rx_refclk(pcs8g_rx_rx_refclk), + .pcs8g_rx_rx_wr_clk(pcs8g_rx_rx_wr_clk), + .pcs8g_rx_sup_mode(pcs8g_rx_sup_mode), + .pcs8g_rx_symbol_swap(pcs8g_rx_symbol_swap), + .pcs8g_rx_test_bus_sel(pcs8g_rx_test_bus_sel), + .pcs8g_rx_test_mode(pcs8g_rx_test_mode), + .pcs8g_rx_tx_rx_parallel_loopback(pcs8g_rx_tx_rx_parallel_loopback), + .pcs8g_rx_use_default_base_address(pcs8g_rx_use_default_base_address), + .pcs8g_rx_user_base_address(pcs8g_rx_user_base_address), + .pcs8g_rx_wa_boundary_lock_ctrl(pcs8g_rx_wa_boundary_lock_ctrl), + .pcs8g_rx_wa_clk_slip_spacing(pcs8g_rx_wa_clk_slip_spacing), + .pcs8g_rx_wa_clk_slip_spacing_data(pcs8g_rx_wa_clk_slip_spacing_data), + .pcs8g_rx_wa_det_latency_sync_status_beh(pcs8g_rx_wa_det_latency_sync_status_beh), + .pcs8g_rx_wa_disp_err_flag(pcs8g_rx_wa_disp_err_flag), + .pcs8g_rx_wa_kchar(pcs8g_rx_wa_kchar), + .pcs8g_rx_wa_pd(pcs8g_rx_wa_pd), + .pcs8g_rx_wa_pd_data(pcs8g_rx_wa_pd_data), + .pcs8g_rx_wa_pd_polarity(pcs8g_rx_wa_pd_polarity), + .pcs8g_rx_wa_pld_controlled(pcs8g_rx_wa_pld_controlled), + .pcs8g_rx_wa_renumber_data(pcs8g_rx_wa_renumber_data), + .pcs8g_rx_wa_rgnumber_data(pcs8g_rx_wa_rgnumber_data), + .pcs8g_rx_wa_rknumber_data(pcs8g_rx_wa_rknumber_data), + .pcs8g_rx_wa_rosnumber_data(pcs8g_rx_wa_rosnumber_data), + .pcs8g_rx_wa_rvnumber_data(pcs8g_rx_wa_rvnumber_data), + .pcs8g_rx_wa_sync_sm_ctrl(pcs8g_rx_wa_sync_sm_ctrl), + .pcs8g_rx_wait_cnt(pcs8g_rx_wait_cnt), + + // parameters for arriav_hssi_8g_tx_pcs + .pcs8g_tx_agg_block_sel(pcs8g_tx_agg_block_sel), + .pcs8g_tx_auto_speed_nego_gen2(pcs8g_tx_auto_speed_nego_gen2), + .pcs8g_tx_bist_gen(pcs8g_tx_bist_gen), + .pcs8g_tx_bit_reversal(pcs8g_tx_bit_reversal), + .pcs8g_tx_bypass_pipeline_reg(pcs8g_tx_bypass_pipeline_reg), + .pcs8g_tx_byte_serializer(pcs8g_tx_byte_serializer), + .pcs8g_tx_cid_pattern(pcs8g_tx_cid_pattern), + .pcs8g_tx_cid_pattern_len(pcs8g_tx_cid_pattern_len), + .pcs8g_tx_clock_gate_bist(pcs8g_tx_clock_gate_bist), + .pcs8g_tx_clock_gate_bs_enc(pcs8g_tx_clock_gate_bs_enc), + .pcs8g_tx_clock_gate_dw_fifowr(pcs8g_tx_clock_gate_dw_fifowr), + .pcs8g_tx_clock_gate_fiford(pcs8g_tx_clock_gate_fiford), + .pcs8g_tx_clock_gate_prbs(pcs8g_tx_clock_gate_prbs), + .pcs8g_tx_clock_gate_sw_fifowr(pcs8g_tx_clock_gate_sw_fifowr), + .pcs8g_tx_ctrl_plane_bonding_compensation( +(pcs8g_rx_byte_deserializer=="en_bds_by_4") ? "en_compensation" : "dis_compensation" +), + .pcs8g_tx_ctrl_plane_bonding_consumption( +(bonded_lanes==1)? "individual": +(i==bonding_master_ch)? "bundled_master": +(i") ? rbc_any_prot_mode : pma_prot_mode; +localparam pipe_mode = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2") ? 1 : 0; + +localparam rbc_all_auto_negotiation = (fnl_prot_mode == "pipe_g1" || fnl_prot_mode == "pipe_g2") ? "(true,false)" : "false"; +localparam rbc_any_auto_negotiation = "false"; +localparam fnl_auto_negotiation = (auto_negotiation == "" || auto_negotiation == "") ? rbc_any_auto_negotiation : auto_negotiation; + +// Internal parameters +localparam INT_DATA_RATE = str2hz(pma_data_rate); // TODO - may fail due to 32-bit param +localparam INT_CDR_OUT_CLOCK_FREQ = INT_DATA_RATE / 2; +localparam INT_CDR_OUT_CLOCK_FREQ_STR= hz2str(INT_CDR_OUT_CLOCK_FREQ); +localparam pma_width = (pma_prot_mode == "pma direct") ? 80 : 20; + +localparam FIR_COEFF_CTRL_SEL = (pipe_mode == 1)? "dynamic_ctl" : "ram_ctl"; +// Parameter legality checking +initial begin + if (!is_in_legal_set(pma_prot_mode, rbc_all_prot_mode)) begin + $display("Critical Warning: pma_prot_mode value, '%s', not in legal set: '%s'", pma_prot_mode, rbc_all_prot_mode); + end + + if (!is_in_legal_set(auto_negotiation, rbc_all_auto_negotiation)) begin + $display("Critical Warning: auto_negotiation value, '%s', not in legal set: '%s'", auto_negotiation, rbc_all_auto_negotiation); + end + +end + + +// Internal signals +wire [bonded_lanes - 1: 0] loopback_data; +wire [bonded_lanes -1: 0] int_pciesw; // PCIe generation select +wire [bonded_lanes-1: 0] int_pcieswdone; // Inidicates PMA has accepted value on pciesw input. + +wire [bonded_lanes - 1: 0] reverse_loopback_data_p; +wire [bonded_lanes - 1: 0] reverse_loopback_data_n; +wire [bonded_lanes - 1: 0] seriallpbken_n; + +assign int_pciesw = (fnl_auto_negotiation == "true") ? pciesw : {bonded_lanes{1'b0}}; +assign tx_pcieswdone = (fnl_auto_negotiation == "true" || tx_enable == 0) ? int_pcieswdone : {bonded_lanes{1'b0}}; + +assign out_pcs_signal_ok = rx_is_lockedtodata; +assign out_pcs_rx_pll_phase_lock_out = rx_is_lockedtodata; +// We only drive seriallpbken in duplex mode. +assign seriallpbken_n = ((rx_enable == 1) && (tx_enable == 1)) ? ~seriallpbken : {bonded_lanes{1'b1}}; + + +//********************************************************************* +//************************ Receiver PMA ******************************* +generate if(rx_enable == 1) begin +av_rx_pma #( + .bonded_lanes (bonded_lanes ), + .bonding_master_ch_num (pma_bonding_master ), + .bonding_master_only (bonding_master_only ), + .mode (pma_mode ), + //.serial_loopback ("lpbkp_dis" ), + .sdclk_enable ("true" ), // TODO Hard-code for now + .channel_number (channel_number ), + .deser_enable_bit_slip (deser_enable_bit_slip ), + .auto_negotiation (fnl_auto_negotiation ), + .cdr_refclk_sel (cdr_refclk_sel ), + .cdr_reconfig (cdr_reconfig ), + .cdr_reference_clock_frequency(cdr_reference_clock_frequency), + .cdr_refclk_cnt (cdr_refclk_cnt ), + .cdr_output_clock_frequency (INT_CDR_OUT_CLOCK_FREQ_STR ), + .rxpll_pd_bw_ctrl ("300" ), // TODO Hard-code for now + .sd_on (sd_on ), + .pdb_sd (pdb_sd ), + .pma_width (pma_width ), + .pma_direct ((pma_prot_mode == "pma direct")? "true" : "false"), + .cvp_en_iocsr (cvp_en_iocsr ) //Only PCIe CvP designs override this +) av_rx_pma( + .rstn (rx_rstn ), + .crurstn (rx_crurstn ), + + .calclk ({bonded_lanes{calclk}} ), + .datain (rx_datain ), + .seriallpbkin (loopback_data ), + .seriallpbken (seriallpbken_n ), + .bslip (rx_bslip ), + //.adaptcapture (rx_adaptcapture ), + //.adcestandby (rx_adcestandby ), + .hardoccalen (rx_hardoccalen ), + //.eyemonitor (rx_eyemonitor ), + //.adaptdone (rx_adaptdone ), + //.hardoccaldone (rx_hardoccaldone ), + + .cdr_ref_clk (rx_cdr_ref_clk ), + + .pciesw (int_pciesw ), + + .ltr (rx_ltr ), + .ltd (rx_ltd ), + .freqlock (rx_freqlock ), + + .earlyeios (rx_earlyeios ), + + .clkdivrx (rx_clkdivrx ), + .dout (rx_dataout ), + .sd (rx_sd ), + + .clklow (rx_clklow ), + .fref (rx_fref ), + + .rx_is_lockedtodata (rx_is_lockedtodata ), + .rx_is_lockedtoref (rx_is_lockedtoref ), + + .avmmrstn (pma_avmmrstn ), + .avmmclk (pma_avmmclk ), + .avmmwrite (pma_avmmwrite ), + .avmmread (pma_avmmread ), + .avmmbyteen (pma_avmmbyteen ), + .avmmaddress (pma_avmmaddress ), + .avmmwritedata (pma_avmmwritedata ), + .avmmreaddata_ser (pma_avmmreaddata_rx_ser), // SER readdata + .avmmreaddata_buf (pma_avmmreaddata_rx_buf), // BUF readdata + .avmmreaddata_cdr (pma_avmmreaddata_rx_cdr), // CDR readdata + .avmmreaddata_mux (pma_avmmreaddata_rx_mux), // CDR MUX readdata + .blockselect_ser (pma_blockselect_rx_ser ), // SER blockselect + .blockselect_buf (pma_blockselect_rx_buf ), // BUF blockselect + .blockselect_cdr (pma_blockselect_rx_cdr ), // CDR blockselect + .blockselect_mux (pma_blockselect_rx_mux ), // CDR MUX blockselect + + .rdlpbkp (reverse_loopback_data_p) + //.rdlpbkn (reverse_loopback_data_n) + +); + +end else begin + // Default unused outputs + assign rx_clkdivrx = {bonded_lanes{1'b0}}; + assign rx_dataout = {(bonded_lanes*pma_width){1'b0}}; + assign rx_sd = {bonded_lanes{1'b0}}; + assign rx_clklow = {bonded_lanes{1'b0}}; + assign rx_fref = {bonded_lanes{1'b0}}; + assign rx_is_lockedtodata = {bonded_lanes{1'b0}}; + assign rx_is_lockedtoref = {bonded_lanes{1'b0}}; + //assign rx_adaptdone = {bonded_lanes{1'b0}}; + //assign rx_hardoccaldone = {bonded_lanes{1'b0}}; + + assign pma_avmmreaddata_rx_ser = {bonded_lanes*16{1'b0}}; + assign pma_avmmreaddata_rx_buf = {bonded_lanes*16{1'b0}}; + assign pma_avmmreaddata_rx_cdr = {bonded_lanes*16{1'b0}}; + assign pma_avmmreaddata_rx_mux = {bonded_lanes*16{1'b0}}; + assign pma_blockselect_rx_ser = {bonded_lanes{1'b0}}; + assign pma_blockselect_rx_buf = {bonded_lanes{1'b0}}; + assign pma_blockselect_rx_cdr = {bonded_lanes{1'b0}}; + assign pma_blockselect_rx_mux = {bonded_lanes{1'b0}}; + assign reverse_loopback_data_p = {bonded_lanes{1'b0}}; +end +endgenerate +//********************** End Receiver PMA ***************************** +//********************************************************************* + + +//********************************************************************* +//********************** Transmitter PMA ****************************** +generate if(tx_enable == 1) begin +av_tx_pma #( + .bonded_lanes (bonded_lanes ), + .bonding_master_ch_num (pma_bonding_master ), + .bonding_master_only (bonding_master_only ), + .base_data_rate (base_data_rate ), + .data_rate (pma_data_rate ), // TODO + .mode (pma_mode ), + .plls (plls ), + .pll_sel (pll_sel ), + .channel_number (channel_number ), + .ser_loopback ("false" ), + .auto_negotiation (fnl_auto_negotiation ), + .ht_delay_sel ("false" ), + .rx_det_pdb ("false" ), + .tx_clk_div (tx_clk_div ), + .pcie_rst (pcie_rst ), + .fref_vco_bypass (fref_vco_bypass ), + .pma_width (pma_width ), + .pma_bonding_mode (pma_bonding_mode ), + .fir_coeff_ctrl_sel (FIR_COEFF_CTRL_SEL ), + .pma_direct ((pma_prot_mode == "pma direct")? "true" : "false"), + .external_master_cgb (external_master_cgb ) +) av_tx_pma( + //input port for aux + .calclk ({bonded_lanes{calclk}} ), + //input port for buf + .datain (tx_datain ), + .txelecidl (tx_txelecidl ), + .rxdetclk (tx_rxdetclk ), + .txdetrx (tx_txdetrx ), + + //output port for buf + .dataout (tx_dataout ), + .rxdetectvalid (tx_rxdetectvalid ), + .rxfound (tx_rxfound ), + + //input ports for ser + .rstn (tx_rstn ), + .seriallpbken (seriallpbken_n ), + + //output ports for ser + .clkdivtx (tx_clkdivtx ), + .seriallpbkout (loopback_data ), + + //input ports for cgb + .clk (tx_ser_clk ), + .pcsrstn (tx_pcsrstn ), + .fref (tx_fref ), + .rstn_cgb_master (tx_rstn_cgb_master ), + .pciesw (int_pciesw[bonding_master_ch]), + .cpulsein (tx_cpulsein ), + .hclkin (tx_hclkin ), + .lfclkin (tx_lfclkin ), + .pclkin (tx_pclkin ), + + //output ports for cgb + .pcieswdone (int_pcieswdone ), + + .avmmrstn (pma_avmmrstn ), + .avmmclk (pma_avmmclk ), + .avmmwrite (pma_avmmwrite ), + .avmmread (pma_avmmread ), + .avmmbyteen (pma_avmmbyteen ), + .avmmaddress (pma_avmmaddress ), + .avmmwritedata (pma_avmmwritedata ), + .avmmreaddata_cgb (pma_avmmreaddata_tx_cgb), // CGB readdata + .avmmreaddata_ser (pma_avmmreaddata_tx_ser), // SER readdata + .avmmreaddata_buf (pma_avmmreaddata_tx_buf), // BUF readdata + .blockselect_cgb (pma_blockselect_tx_cgb ), // CGB blockselect + .blockselect_ser (pma_blockselect_tx_ser ), // SER blockselect + .blockselect_buf (pma_blockselect_tx_buf ), // BUF blockselect + .atb_comp_out (pll_aux_atb_comp_out ), // pll aux voltage comparator output + + .vrlpbkp (reverse_loopback_data_p), + .vrlpbkn ({bonded_lanes{1'b0}}) +); + +end else begin + // Default the outputs + assign tx_dataout = {bonded_lanes{1'b0}}; + assign tx_rxdetectvalid = {bonded_lanes{1'b0}}; + assign tx_rxfound = {bonded_lanes{1'b0}}; + assign tx_clkdivtx = {bonded_lanes{1'b0}}; + assign int_pcieswdone = {bonded_lanes{1'b0}}; + assign pma_avmmreaddata_tx_cgb = {bonded_lanes*16{1'b0}}; + assign pma_avmmreaddata_tx_ser = {bonded_lanes*16{1'b0}}; + assign pma_avmmreaddata_tx_buf = {bonded_lanes*16{1'b0}}; + assign pma_blockselect_tx_cgb = {bonded_lanes{1'b0}}; + assign pma_blockselect_tx_ser = {bonded_lanes{1'b0}}; + assign pma_blockselect_tx_buf = {bonded_lanes{1'b0}}; + assign pll_aux_atb_comp_out = {bonded_lanes{1'b0}}; + assign loopback_data = {bonded_lanes{1'b0}}; +end +endgenerate +//******************** End Transmitter PMA **************************** +//********************************************************************* + +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_reconfig_bundle_to_basic.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_reconfig_bundle_to_basic.sv new file mode 100644 index 0000000..5411c4b --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_reconfig_bundle_to_basic.sv @@ -0,0 +1,95 @@ +// (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. + + +// +// Transceiver native reconfig adapter for Stratix V & derivatives. +// Translates from native reconfig wire bundles to separate Av reconfig and testbus signals +// +// This direction for bundle to separate buses inside the sv_xcvr_protocol_native block +// +// $Header$ +// + +`timescale 1 ns / 1 ns + +module av_reconfig_bundle_to_basic #( + parameter native_ifs = 1 // number of native reconfig interfaces +) ( + // bundled reconfig buses + output wire [native_ifs*altera_xcvr_functions::W_S5_RECONFIG_BUNDLE_TO_XCVR -1:0] reconfig_to_xcvr, // all inputs from reconfig block to native xcvr reconfig ports + input wire [native_ifs*altera_xcvr_functions::W_S5_RECONFIG_BUNDLE_FROM_XCVR-1:0] reconfig_from_xcvr,// all input s from native xcvr reconfig ports to reconfig block + + // native reconfig sources + output wire [native_ifs*16 -1:0] native_reconfig_readdata, // Avalon DPRIO readdata + output wire [native_ifs*3*8-1:0] pif_testbus, // testbus from native reconfig, for all physical interfaces + output wire pif_atbout, // Voltage comparator output for DCD (1 for each lane) + + // native reconfig sinks + input wire [native_ifs*1 -1:0] native_reconfig_clk, + input wire [native_ifs*1 -1:0] native_reconfig_reset, + input wire [native_ifs*16 -1:0] native_reconfig_writedata, // Avalon DPRIO writedata + input wire [native_ifs*12 -1:0] native_reconfig_address, // Avalon DPRIO address + input wire [native_ifs*1 -1:0] native_reconfig_write, // Avalon DPRIO write + input wire [native_ifs*1 -1:0] native_reconfig_read, // Avalon DPRIO read + input wire [native_ifs*12 -1:0] pif_testbus_sel, // 4 bits per physical channel + input wire [native_ifs*1 -1:0] pif_interface_sel, + input wire [native_ifs*1 -1:0] pif_ser_shift_load, + input wire oc_cal_busy, + input wire tx_cal_busy, + input wire rx_cal_busy +); + + localparam w_bundle_to_xcvr = altera_xcvr_functions::W_S5_RECONFIG_BUNDLE_TO_XCVR; + localparam w_bundle_from_xcvr= altera_xcvr_functions::W_S5_RECONFIG_BUNDLE_FROM_XCVR; + + wire [native_ifs*1 -1:0] oc_cal_busy_bus; + wire [native_ifs*1 -1:0] tx_cal_busy_bus; + wire [native_ifs*1 -1:0] rx_cal_busy_bus; + tri0 [native_ifs*1 -1:0] pif_atbout_bus; + + assign oc_cal_busy_bus = {native_ifs{oc_cal_busy}}; + assign tx_cal_busy_bus = {native_ifs{tx_cal_busy}}; + assign rx_cal_busy_bus = {native_ifs{rx_cal_busy}}; + + assign pif_atbout = |pif_atbout_bus; + + genvar pi; + generate + for (pi=0; pi 11) ? 11 : cdr_refclk_cnt; + localparam [MAX_CHARS*8-1:0] refclk_sel_param = cdr_refclk_sel == 10 ? "ref_iqclk10" : + cdr_refclk_sel == 9 ? "ref_iqclk9" : + cdr_refclk_sel == 8 ? "ref_iqclk8" : + cdr_refclk_sel == 7 ? "ref_iqclk7" : + cdr_refclk_sel == 6 ? "ref_iqclk6" : + cdr_refclk_sel == 5 ? "ref_iqclk5" : + cdr_refclk_sel == 4 ? "ref_iqclk4" : + cdr_refclk_sel == 3 ? "ref_iqclk3" : + cdr_refclk_sel == 2 ? "ref_iqclk2" : + cdr_refclk_sel == 1 ? "ref_iqclk1" : + "ref_iqclk0" ; + + + // Set "enabled_for_reconfig" from pll_reconfig parameter + localparam enabled_for_reconfig = (cdr_reconfig == 0) ? "false" : "true"; + + // Use fast simulation models when reconfig is not enabled + localparam sim_use_fast_model = (enabled_for_reconfig == "false") ? "true" : "false"; + + generate + for(i = 0; i < bonded_lanes; i = i + 1) + begin: rx_pmas + localparam is_master_only = (((int_bonding_master_only_set >> i) & 1'b1) == 1) ? 1 : 0; + + if (is_master_only == 0) + begin: rx_pma + wire wire_dataout_to_cdr; + wire wire_refclk_to_cdr; + wire wire_cdr_to_deser_clk; + wire wire_cdr_to_deser_clk_270; + wire wire_pciel; + wire wire_pciem; + wire wire_dodd; + wire wire_deven; + wire wire_clkdivrxrx; + wire nonuserfrompmaux; + + wire [10:0] int_refclks; // internal refclks + + assign int_refclks = { {(11-cdr_refclk_cnt_fnl){1'b0}} , cdr_ref_clk[i*cdr_refclk_cnt_fnl+:cdr_refclk_cnt_fnl]}; + + arriav_hssi_pma_aux #( + .continuous_calibration ("true") + ) rx_pma_aux ( + .calpdb (1'b1 ), + .calclk (calclk [i] ), + .atb0out ( ), + .atb1out ( ), + .zrxtx50 (/*unused*/ ), + .nonusertoio (nonuserfrompmaux ) + + `ifndef ALTERA_RESERVED_QIS + , + // Unused inputs + .testcntl (1'b0 ), + .refiqclk (6'b0 ) + `endif // ifndef ALTERA_RESERVED_QIS + ); + + arriav_hssi_pma_rx_buf #( + .channel_number (channel_number ), + //.serial_loopback (serial_loopback ) + .sd_on (sd_on ), + .pdb_sd (pdb_sd ) + ) rx_pma_buf ( + .datain (datain [i] ), + .rstn (rstn [i] ), + .lpbkp (seriallpbkin [i] ), + .slpbk (seriallpbken [i] ), + .dataout (wire_dataout_to_cdr ), + .sd (sd [i] ), + .ck0sigdet (wire_clkdivrxrx ), // the signal detect clock is supplied by the deserializer + .nonuserfrompmaux (nonuserfrompmaux ), + // + //.adaptcapture (adaptcapture [i] ), + //.adcestandby (adcestandby [i] ), + .hardoccalen (hardoccalen [i] ), + // + //.adaptdone (adaptdone [i] ), + //.hardoccaldone (hardoccaldone [i] ), + //.eyemonitor (eyemonitor [i* 5+: 5] ), + + .avmmrstn (avmmrstn [i] ), + .avmmclk (avmmclk [i] ), + .avmmwrite (avmmwrite [i] ), + .avmmread (avmmread [i] ), + .avmmbyteen (avmmbyteen [i* 2+: 2] ), + .avmmaddress (avmmaddress [i*11+:11] ), + .avmmwritedata (avmmwritedata [i*16+:16] ), + .avmmreaddata (avmmreaddata_buf[i*16+:16] ), + .blockselect (blockselect_buf [i] ), + + //.voplp (/*unused*/), + //.vonlp (/*unused*/), + .rdlpbkp (rdlpbkp [i]) + //.lpbkn (/*unused*/), + //.rxrefclk (/*unused*/), + //.rdlpbkn (rdlpbkn [i]) + ); + + arriav_channel_pll #( + .reference_clock_frequency(cdr_reference_clock_frequency_fnl), + .pcie_freq_control ((cdr_reference_clock_frequency_fnl=="125 MHz") ? "pcie_125mhz":"pcie_100mhz"), + .output_clock_frequency (cdr_output_clock_frequency ), + .powerdown ("false" ), + .rxpll_pd_bw_ctrl (rxpll_pd_bw_ctrl ), + .enabled_for_reconfig (enabled_for_reconfig ), + .sim_use_fast_model (sim_use_fast_model ), + .cvp_en_iocsr (cvp_en_iocsr ) //Only PCIe CvP designs override this + + ) rx_cdr ( + .crurstb (crurstn [i] ), //check the correct reset signal + .ltr (ltr [i] ), // receive_pma -> m_locktorefout + .rxp (wire_dataout_to_cdr ), + .refclk (wire_refclk_to_cdr ), + .ltd (~ltd [i] ), // active low + .rstn (rstn [i] ), //check the correct reset signal + .sd (sd [i] ), // check + .clk90bdes (wire_cdr_to_deser_clk ), + .clk270bdes (wire_cdr_to_deser_clk_270 ), + .clkcdr (/*unused*/ ), + .clklow (clklow [i] ), + .fref (fref [i] ), + .dodd (wire_dodd ), + .deven (wire_deven ), + .pfdmodelock (rx_is_lockedtoref [i] ), + .rxplllock (rx_is_lockedtodata [i] ), + .ppmlock (freqlock [i] ), + .earlyeios (earlyeios [i] ), + + .pciesw ({1'b0,pciesw [i]}), + .pciel (wire_pciel ), + //.pciem (wire_pciem ), + + .avmmrstn (avmmrstn [i] ), + .avmmclk (avmmclk [i] ), + .avmmwrite (avmmwrite [i] ), + .avmmread (avmmread [i] ), + .avmmbyteen (avmmbyteen [i* 2+: 2] ), + .avmmaddress (avmmaddress [i*11+:11] ), + .avmmwritedata(avmmwritedata [i*16+:16] ), + .avmmreaddata (avmmreaddata_cdr [i*16+:16] ), + .blockselect (blockselect_cdr [i] ), + + //.clk270eye (/*unused*/), + //.clk270beyerm (/*unused*/), + //.clk90eye (/*unused*/), + //.clk90beyerm (/*unused*/), + .clkindeser (/*unused*/), + //.deeye (/*unused*/), + //.deeyerm (/*unused*/), + //.doeye (/*unused*/), + //.doeyerm (/*unused*/), + .extclk (/*unused*/), + //.extfbctrla (/*unused*/), + //.extfbctrlb (/*unused*/), + //.gpblck2refb (/*unused*/), + .lpbkpreen (/*unused*/), + .occalen (/*unused*/), + .ck0pd (/*unused*/), + .ck180pd (/*unused*/), + .ck270pd (/*unused*/), + .ck90pd (/*unused*/), + //.clk270bcdr (/*unused*/), + //.clk90bcdr (/*unused*/), + //.decdr (/*unused*/), + //.docdr (/*unused*/), + .pdof (/*unused*/), + .rxlpbdp (/*unused*/), + .rxlpbp (/*unused*/), + .txpllhclk (/*unused*/), + .txrlpbk (/*unused*/), + .vctrloverrange (/*unused*/) + ); + + arriav_hssi_pma_rx_deser #( + .mode (mode ), + .channel_number (channel_number ), + .auto_negotiation (auto_negotiation ), + .sdclk_enable (sdclk_enable ), + .enable_bit_slip (deser_enable_bit_slip), + .pma_direct (pma_direct) + ) rx_pma_deser ( + .bslip (bslip [i] ), + .clk90b (wire_cdr_to_deser_clk ), + .clk270b (wire_cdr_to_deser_clk_270 ), + .deven (wire_deven ), + .dodd (wire_dodd ), + //.pfdmodelock (rx_is_lockedtoref [i] ), + .pciesw (pciesw [i] ), + .rstn (rstn [i] ), + .clkdivrx (clkdivrx [i] ), + .clkdivrxrx (wire_clkdivrxrx ), // clock for signal detect + .dout (dout [i*pma_width+:pma_width] ), + .pciel (wire_pciel ), + //.pciem (wire_pciem ), + + .avmmrstn (avmmrstn [i] ), + .avmmclk (avmmclk [i] ), + .avmmwrite (avmmwrite [i] ), + .avmmread (avmmread [i] ), + .avmmbyteen (avmmbyteen [i*2+:2] ), + .avmmaddress (avmmaddress [i*11+:11] ), + .avmmwritedata (avmmwritedata [i*16+:16] ), + .avmmreaddata (avmmreaddata_ser [i*16+:16] ), + .blockselect (blockselect_ser [i] ) + + //.fref (/*unused*/), + //.clklow (/*unused*/), + //.clk33pcs (/*unused*/) + ); + + // REFCLK_SELECT_MUX + arriav_hssi_pma_cdr_refclk_select_mux #( + .refclk_select (refclk_sel_param ), + .channel_number (channel_number ), + .reference_clock_frequency (cdr_reference_clock_frequency_fnl) + ) cdr_refclk_mux0 ( + // Inputs + .refiqclk0 (int_refclks[ 0]), + .refiqclk1 (int_refclks[ 1]), + .refiqclk2 (int_refclks[ 2]), + .refiqclk3 (int_refclks[ 3]), + .refiqclk4 (int_refclks[ 4]), + .refiqclk5 (int_refclks[ 5]), + .refiqclk6 (int_refclks[ 6]), + .refiqclk7 (int_refclks[ 7]), + .refiqclk8 (int_refclks[ 8]), + .refiqclk9 (int_refclks[ 9]), + .refiqclk10 (int_refclks[10]), + + // Outputs + .clkout (wire_refclk_to_cdr ), + + .avmmclk (avmmclk [i] ), + .avmmrstn (avmmrstn [i] ), + .avmmwrite (avmmwrite [i] ), + .avmmread (avmmread [i] ), + .avmmbyteen (avmmbyteen [i* 2+: 2] ), + .avmmaddress (avmmaddress [i*11+:11] ), + .avmmwritedata (avmmwritedata [i*16+:16] ), + .avmmreaddata (avmmreaddata_mux [i*16+:16] ), + .blockselect (blockselect_mux [i] ) + + `ifndef ALTERA_RESERVED_QIS + , + // Unused inputs + .calclk (1'b0), + .ffplloutbot (1'b0), + .ffpllouttop (1'b0), + .pldclk (1'b0), + .rxiqclk0 (1'b0), + .rxiqclk1 (1'b0), + .rxiqclk10 (1'b0), + .rxiqclk2 (1'b0), + .rxiqclk3 (1'b0), + .rxiqclk4 (1'b0), + .rxiqclk5 (1'b0), + .rxiqclk6 (1'b0), + .rxiqclk7 (1'b0), + .rxiqclk8 (1'b0), + .rxiqclk9 (1'b0) + `endif // ifndef ALTERA_RESERVED_QIS + ); + + end else begin:no_rx_pma + + //Tie-off the output ports from the master-only channel index. There is + //no Rx PMA in the master-only channel. + //assign adaptdone [i] = 1'b0; + //assign hardoccaldone [i] = 1'b0; + assign sd [i] = 1'b0; + assign clkdivrx [i] = 1'b0; + assign dout [i*pma_width+:pma_width] = pma_width*1'b0; + assign sd [i] = 1'b0; + assign clklow [i] = 1'b0; + assign fref [i] = 1'b0; + assign rx_is_lockedtodata [i] = 1'b0; + assign rx_is_lockedtoref [i] = 1'b0; + assign avmmreaddata_ser [i*16+:16] = 16'b0; + assign avmmreaddata_buf [i*16+:16] = 16'b0; + assign avmmreaddata_cdr [i*16+:16] = 16'b0; + assign avmmreaddata_mux [i*16+:16] = 16'b0; + assign blockselect_ser [i] = 1'b0; + assign blockselect_buf [i] = 1'b0; + assign blockselect_cdr [i] = 1'b0; + assign blockselect_mux [i] = 1'b0; + end + end + endgenerate + +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_tx_pma.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_tx_pma.sv new file mode 100644 index 0000000..9b43ebd --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_tx_pma.sv @@ -0,0 +1,264 @@ +// (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. + + +// This block instantiates a single channel or a number of bonded +// channels. The channel numbers are assigned sequentially starting from +// the channel_number specifical as a parameter +// +// Key parameters: +// +// bonded_lanes = specifies the number of lanes to produce. If bonded_lanes == 1, +// only a single chann is produced of type "SINGLE_CHANNEL". +// If bonded_lanes > 1, then look at the value of the bonding_master_lane +// and bonding_master_only parameters +// +// +// bonding_master_ch_number = uint, must be in the range [channel_number : channel_number + bonded_lanes - 1] +// Indicates that channel number that must be the master channel. +// All other lanes, with the exception of the master will be of SLAVE_CHANNEL type +// There are two scenarious possible: +// (1) If the bonding_master_only parameter is set to "true"; A master lane +// of type "MASTER_ONLY" will be instantiated. +// +// (2) If the bonding_master_only parameter is set to "false"; A master lane +// of type "MASTER_SINGLE_CHANNEL" will be instantiated. +// +// bonding_master_only = "true","false", Indicates the lane indicated by bonding_master_ch_number +// should by of type "MASTER_ONLY" ("true"), or of type "MASTER_SINGLE_CHANNEL" ("false"). +// +// channel_number = uint, starting channel number. This module will instantiate channels and will label them +// consequitively from (channel_number) to (channnel_number + bonded_lanes - 1) +// + + +`timescale 1ps/1ps +module av_tx_pma #( + parameter bonded_lanes = 1, + parameter bonding_master_ch_num = "0", + parameter bonding_master_only = "-1", + + parameter base_data_rate = "0 ps", + parameter data_rate = "0 ps", + + parameter mode = 8, + parameter channel_number = 0, + parameter ser_loopback = "false", + parameter auto_negotiation = "false", + parameter plls = 1, + parameter pll_sel = 0, + parameter pclksel = "local_pclk", + parameter ht_delay_sel = "false", + parameter rx_det_pdb = "false", + parameter tx_clk_div = 1, // (1,2,4,8) + parameter pcie_rst = "normal_reset", + parameter fref_vco_bypass = "NORMAL_OPERATION", + parameter pma_width = 20, + parameter pma_bonding_mode = "x1", // valid value "x1", "xN" + parameter pma_direct = "false", + parameter external_master_cgb = 0, + parameter fir_coeff_ctrl_sel = "ram_ctl" +) ( + //input port for aux + input [bonded_lanes - 1 : 0] calclk, + //input port for buf + input [(bonded_lanes * pma_width) -1: 0] datain, + input [bonded_lanes - 1 : 0] txelecidl, + input rxdetclk, + input [bonded_lanes - 1 : 0] txdetrx, + + //output port for buf + output [bonded_lanes - 1 : 0] dataout, + output [bonded_lanes - 1 : 0] rxdetectvalid, + output [bonded_lanes - 1 : 0] rxfound, + + //input ports for ser + input rstn, + input [bonded_lanes - 1 : 0] seriallpbken, + + //output ports for ser + output [bonded_lanes - 1 : 0] clkdivtx, + output [bonded_lanes - 1 : 0] seriallpbkout, + + //input ports for cgb + input [bonded_lanes*plls-1:0] clk, // High-speed serial clocks from PLLs + input pciesw, // to the master channel + input pcsrstn, + input fref, + input [bonded_lanes*plls-1:0] rstn_cgb_master, + input [bonded_lanes - 1 : 0] cpulsein, + input [bonded_lanes - 1 : 0] hclkin, + input [bonded_lanes - 1 : 0] lfclkin, + input [bonded_lanes*3-1 : 0] pclkin, + + //output ports for cgb + output [bonded_lanes-1 : 0] pcieswdone, // from the master channel + + input [bonded_lanes-1:0 ] avmmrstn, // one for each lane + input [bonded_lanes-1:0 ] avmmclk, // one for each lane + input [bonded_lanes-1:0 ] avmmwrite, // one for each lane + input [bonded_lanes-1:0 ] avmmread, // one for each lane + input [(bonded_lanes*2)-1:0 ] avmmbyteen, // two for each lane + input [(bonded_lanes*11)-1:0 ] avmmaddress, // 11 for each lane + input [(bonded_lanes*16)-1:0 ] avmmwritedata, // 16 for each lane + output [(bonded_lanes*16)-1:0 ] avmmreaddata_cgb, // CGB readdata + output [(bonded_lanes*16)-1:0 ] avmmreaddata_ser, // SER readdata + output [(bonded_lanes*16)-1:0 ] avmmreaddata_buf, // BUF readdata + output [bonded_lanes-1:0 ] blockselect_cgb, // CGB blockselect + output [bonded_lanes-1:0 ] blockselect_ser, // SER blockselect + output [bonded_lanes-1:0 ] blockselect_buf, // BUF blockselect + output [bonded_lanes-1:0 ] atb_comp_out, // Voltage comparator output for DCD + + input [bonded_lanes-1:0 ] vrlpbkp, + input [bonded_lanes-1:0 ] vrlpbkn +); + + import altera_xcvr_functions::*; + + wire [bonded_lanes-1:0] w_hfclkp; + wire [bonded_lanes-1:0] w_lfclkp; + wire [bonded_lanes-1:0] w_cpulse; + wire [2:0] w_pclk [bonded_lanes-1:0]; + wire [bonded_lanes*80-1:0] dadtain_padded; + + localparam integer bonding_master_0 = str2int(get_value_at_index(0,bonding_master_ch_num)); + + genvar i; + generate + for(i = 0; i < bonded_lanes; i = i + 1) begin:tx_pma_insts + + assign dadtain_padded[(i+1)*80 - 1 : i*80] = (pma_width == 20) ? {60'b0 , datain[(i+1)*20 - 1 : i*20]} : datain[(i+1)*pma_width - 1 : i*pma_width]; + + localparam [MAX_CHARS*8-1:0] str_i = int2str(i); + localparam is_single_chan = (bonded_lanes == 1 && pma_bonding_mode == "x1") ? 1 : 0; + localparam is_master_only = ( (is_single_chan == 0) && + (is_in_legal_set(str_i,bonding_master_ch_num) == 1) && + (is_in_legal_set(str_i,bonding_master_only) == 1)) + ? 1 : 0; + localparam is_master_chan = ( (is_single_chan == 0) && + (is_master_only == 0) && + (is_in_legal_set(str_i,bonding_master_ch_num) == 1)) + ? 1 : 0; + localparam is_slave_chan = ( (is_single_chan == 0) && + ((is_in_legal_set(str_i,bonding_master_ch_num) == 0) && + (is_in_legal_set(str_i,-1) == 0))) + ? 1 : 0; + + //localparam is_fb_comp = ( (is_single_chan == 0) && + // (pma_bonding_type == "fb_compensation") && + // (is_in_legal_set(str_i,-1) == 0)) + // ? 1 : 0; + + localparam is_fb_comp = 0; + + // Determine PMA type + localparam [MAX_CHARS*8-1:0] tx_pma_type = (is_single_chan == 1) ? "SINGLE_CHANNEL" : + (is_fb_comp == 1) ? "FB_COMP_CHANNEL" : + (is_master_only == 1) ? "MASTER_ONLY" : + (is_master_chan == 1) ? "MASTER_SINGLE_CHANNEL" : + (is_slave_chan == 1) ? "SLAVE_CHANNEL" : + "EMPTY_CHANNEL" ; + + // Determine the bonding master for this channel + // If only one bonding master was specified, we select it. + // If a bonding master per channel was specified, we select the corresponding master + localparam [MAX_CHARS*8-1:0] master_sel_str = get_value_at_index(i,bonding_master_ch_num); + localparam integer master_sel = (master_sel_str == "NA") ? bonding_master_0 : str2int(master_sel_str); + + av_tx_pma_ch #( + .mode(mode), + .auto_negotiation(auto_negotiation), + .plls(plls), + .pll_sel(pll_sel), + .ser_loopback(ser_loopback), + .ht_delay_sel(ht_delay_sel), + .tx_pma_type(tx_pma_type), + .base_data_rate(base_data_rate), + .data_rate(data_rate), + .rx_det_pdb(rx_det_pdb), + .tx_clk_div(tx_clk_div), + .pcie_rst(pcie_rst), + .fref_vco_bypass(fref_vco_bypass), + .pma_bonding_mode(pma_bonding_mode), + .bonded_lanes(bonded_lanes), + .pma_direct(pma_direct), + .external_master_cgb(external_master_cgb), + .fir_coeff_ctrl_sel(fir_coeff_ctrl_sel) + ) av_tx_pma_ch_inst ( + //input port for aux + .calclk (calclk [i] ), + + //input port for buf + .datain (dadtain_padded [(i+1)*80 - 1 : i*80]), + .txelecidl (txelecidl [i] ), + .rxdetclk (rxdetclk ), + .txdetrx (txdetrx [i] ), + + //output port for buf + .dataout (dataout [i] ), + .rxdetectvalid (rxdetectvalid [i] ), + .rxfound (rxfound [i] ), + + //input ports for ser + .rstn (rstn ), + .seriallpbken (seriallpbken [i] ), + + //output ports for ser + .clkdivtx (clkdivtx [i] ), + .seriallpbkout (seriallpbkout [i] ), + + //input ports for cgb + .clk (clk [i*plls+:plls]), + .pciesw (pciesw ), + .pcsrstn (pcsrstn ), + .fref (fref ), + .rstn_cgb_master(rstn_cgb_master [i*plls+:plls]), + + // bonding clock inputs from master CGB + .cpulsein ((external_master_cgb == 1)? cpulsein[i] : w_cpulse [master_sel] ), + .hfclkpin ((external_master_cgb == 1)? hclkin[i] : w_hfclkp [master_sel] ), + .lfclkpin ((external_master_cgb == 1)? lfclkin[i] : w_lfclkp [master_sel] ), + .pclkin ((external_master_cgb == 1)? pclkin[i*3+:3] : w_pclk [master_sel] ), + + //output ports for cgb + .pcieswdone (pcieswdone [i] ), + + // + .cpulseout (w_cpulse [i] ), + .hfclkpout (w_hfclkp [i] ), + .lfclkpout (w_lfclkp [i] ), + .pclkout (w_pclk [i] ), + + .vrlpbkp (vrlpbkp [i] ), + .vrlpbkn (vrlpbkn [i] ), + + // Avalon-MM interface + .avmmrstn (avmmrstn [i] ), + .avmmclk (avmmclk [i] ), + .avmmwrite (avmmwrite [i] ), + .avmmread (avmmread [i] ), + .avmmbyteen (avmmbyteen [i*2+:2] ), + .avmmaddress (avmmaddress [i*11+:11] ), + .avmmwritedata (avmmwritedata[i*16+:16] ), + .avmmreaddata_cgb (avmmreaddata_cgb[i*16+:16] ), // CGB readdata + .avmmreaddata_ser (avmmreaddata_ser[i*16+:16] ), // SER readdata + .avmmreaddata_buf (avmmreaddata_buf[i*16+:16] ), // BUF readdata + .blockselect_cgb (blockselect_cgb[i] ), // CGB blockselect + .blockselect_ser (blockselect_ser[i] ), // SER blockselect + .blockselect_buf (blockselect_buf[i] ), // BUF blockselect + .atb_comp_out (atb_comp_out [i] ) + ); + end + endgenerate +endmodule + + diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_tx_pma_ch.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_tx_pma_ch.sv new file mode 100644 index 0000000..4faaf5a --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_tx_pma_ch.sv @@ -0,0 +1,682 @@ +// (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. + + + +// NOTES: parameter tx_pma_channel_type can take the following four values: +// (1) SINGLE_CHANNEL -- +// +// the av_tx_pma block will instantiate a simple pipeline of cgb -> +// ser -> tx_buf. It requires that a high frequency clock be connected to +// 'clk' input port. 'datain' and 'dataout' have to be connected as +// expected. +// +// (2) MASTER_SINGLE_CHANNEL -- +// +// the av_tx_pma block will instantiate a simple pipeline of cgb -> +// ser -> tx_buf. It requires that a high frequency clock be connected to +// 'clk' input port. In addition, the module outputs the bonding clocks via ports +// (hfclkpout, lfclkpout,cpulseout,pclk0out,pclk1out). These clocks must be +// connected to another instance of av_tx_pma_ch that serves as SLAVE_CHANNEL. +// 'datain' and 'dataout' have to be connected as expected. +// +// (3) SLAVE_CHANNEL -- +// +// the av_tx_pma block will instantiate a simple pipeline of cgb -> +// ser -> tx_buf. The cgb in this case is not used to divide the high frequency clock +// from the tx pll, but to forward the bonding clocks to the serializer. It is required that +// the bonding clock bondle is connected to the inputs (hfclkpin, lfclkpin,cpulsein, +// pclk0in,pclk1in). These clocks must come from a av_tx_pma_ch block that serves +// as MASTER_SINGLE_CHANNEL or as MASTER_ONLY. +// 'datain' and 'dataout' have to be connected as expected. +// +// (4) MASTER_ONLY +// +// the av_tx_pma_ch block will only instantiate a cgb -> ser. The cgb is used to divide the +// high frequency clock from the tx pll (input clk) and produce bonding clocks via ports +// (hfclkpout, lfclkpout,cpulseout,pclk0out,pclk1out). The serializer block in this case is +// configured in a special clk_forward_only_mode = true. This indicates that the serializer +// does not serve its usual role of converting data on a parallel bus input into a serial output, +// but serves to only forward the parallel clock from the cgb to the output clkdivtx. +// + +`timescale 1ps/1ps + +import altera_xcvr_functions::*; + +module av_tx_pma_ch #( + parameter mode = 8, + parameter channel_number = 0, + parameter auto_negotiation = "true", + parameter plls = 1, + parameter pll_sel = 0, + parameter ser_loopback = "false", + parameter ht_delay_sel = "false", + parameter tx_pma_type = "SINGLE_CHANNEL", + parameter base_data_rate = "0 ps", + parameter data_rate = "0 ps", + parameter rx_det_pdb = "false", + parameter tx_clk_div = 1, //(1,2,4,8) + parameter pcie_rst = "normal_reset", + parameter fref_vco_bypass = "normal_operation", + parameter enable_dcd = 1, // mask off PLL AUX until fitter support is ready + parameter pma_bonding_mode = "x1", // valid value "x1", "xN" + parameter bonded_lanes = 1, + parameter pma_direct = "false", + parameter external_master_cgb = 0, + parameter fir_coeff_ctrl_sel = "ram_ctl" //Valid values: dynamic_ctl|ram_ctrl + ) ( + //input port for aux + input calclk, + //input port for buf + input [79:0] datain, + input txelecidl, + input rxdetclk, + input txdetrx, + + //output port for buf + output dataout, + output rxdetectvalid, + output rxfound, + + //input ports for ser + input rstn, + input seriallpbken, + + //output ports for ser + output clkdivtx, + output seriallpbkout, + + //input ports for cgb + input [plls-1:0] clk, + input pciesw, + input pcsrstn, + input fref, + input [plls-1:0] rstn_cgb_master, + + // bonding clock inputs from master CGB + input cpulsein, + input hfclkpin, + input lfclkpin, + input [2:0] pclkin, + + //output ports for cgb + output pcieswdone, + + // bonding clock outputs (driven if this CGB is acting as a master) + output hfclkpout, + output lfclkpout, + output cpulseout, + output [2:0] pclkout, + + // input/outputs related to reconfiguration + input avmmrstn, + input avmmclk, + input avmmwrite, + input avmmread, + input [1:0 ] avmmbyteen, + input [10:0 ] avmmaddress, + input [15:0 ] avmmwritedata, + output [15:0 ] avmmreaddata_cgb, // CGB readdata + output [15:0 ] avmmreaddata_ser, // SER readdata + output [15:0 ] avmmreaddata_buf, // BUF readdata + output blockselect_cgb, // CGB blockselect + output blockselect_ser, // SER blockselect + output blockselect_buf, // BUF blockselect + output atb_comp_out, // Voltage comparator output for DCD + + input vrlpbkp, + input vrlpbkn + ); + + genvar ig; + + localparam MAX_PLLS = 7; + localparam PLL_CNT = (plls < MAX_PLLS)? plls : MAX_PLLS; + + localparam integer is_single_chan = (tx_pma_type == "SINGLE_CHANNEL" ) ? 1 : 0; + localparam integer is_master_only = (tx_pma_type == "MASTER_ONLY" ) ? 1 : 0; + localparam integer is_master_chan = (tx_pma_type == "MASTER_SINGLE_CHANNEL") ? 1 : 0; + localparam integer is_slave_chan = (tx_pma_type == "SLAVE_CHANNEL" ) ? 1 : 0; + localparam integer is_empty_chan = (tx_pma_type == "EMPTY_CHANNEL" ) ? 1 : 0; + + // to support bonding + + // Select clock source for g2 and g1 based on auto_negotiation + localparam X1_CLOCK_SOURCE_SEL_AUTONEG = (auto_negotiation == "true") ? "same_ch_txpll" + //: (pll_sel ==11) ? "hfclk_ch1_x6_up"// 9 - hfclkp_x6_up + //: (pll_sel ==10) ? "hfclk_xn_dn" // 8 - hfclkp_xn_dn + //: (pll_sel == 9) ? "hfclk_ch1_x6_dn"// 7 - hfclkp_x6_dn + //: (pll_sel == 8) ? "hfclk_xn_up" // 6 - hfclkp_xn_up + : (pll_sel == 5) ? "down_segmented" // 1 - clk_dn_seg + : (pll_sel == 4) ? "up_segmented" // 0 - clk_up_seg + //: (pll_sel == 5) ? "lcpll_bottom" // 11 - clk_lc_b + //: (pll_sel == 4) ? "lcpll_top" // 10 - clk_lc_t + : (pll_sel == 3) ? "ffpll" // 2 - clk_ffpll + : (pll_sel == 2) ? "ch1_txpll_b" // 4 - clk_cdr_1b + : (pll_sel == 1) ? "ch1_txpll_t" // 3 - clk_cdr_1t + : (pll_sel == 0) ? "same_ch_txpll" // 5 - clk_cdr_loc + : "x1_clk_unused"; + + localparam X1_DIV_M_SEL = (tx_clk_div == 2) ? 2 : + (tx_clk_div == 4) ? 4 : + (tx_clk_div == 8) ? 8 : + 1; + + + localparam [plls*2:0] bonding_mode_sel_bin = pma_bonding_str2bin(pma_bonding_mode); + localparam master_cgb_en = (bonded_lanes == 1)? bonding_mode_sel_bin[plls*2] : 0; + localparam is_pll_switching = (plls > 1)? 1 : 0; // PLL switching only supported for nonbonded mode. Bonded clocks disconnected when in nonbonded mode. + + //main PLL settings + localparam pma_bonding_sel = ((bonding_mode_sel_bin >> (2*pll_sel)) & 2'b11); + localparam pma_is_xn = (pma_bonding_sel == av_xcvr_h::AV_XR_ID_PMA_BONDING_XN) ? 1 : 0; + localparam pma_is_xn_non_bonded = (pma_is_xn == 1 && bonded_lanes == 1)? 1 : 0; + localparam pma_is_xn_bonded = (pma_is_xn == 1 && bonded_lanes != 1)? 1 : 0; + + generate if(is_empty_chan == 0) begin:tx_pma_ch + wire [MAX_PLLS-1:0] wire_clk; + wire [MAX_PLLS-1:0] int_wire_clk; + + wire [79:0] w_datain; + wire w_txelecidl; + wire w_rxdetclk; + wire w_txdetrx; + + wire cpulse_from_cgb; + wire hclk_from_cgb; + wire lfclk_from_cgb; + wire [2:0] pclk_from_cgb; + wire dataout_from_ser; + + wire wire_hfclkpin; + wire wire_lfclkpin; + wire wire_cpulsein; + wire [2:0] wire_pclkin; + + wire wire_hfclkpout; + wire wire_lfclkpout; + wire wire_cpulseout; + wire [2:0] wire_pclkout; + wire [plls-1:0] hfclkpout_from_master; + + wire wire_rstn; + wire wire_pcsrstn; + + wire w_pciesw; + + assign w_datain = (is_master_only == 0) ? datain : 80'd0; + assign w_txelecidl = (is_master_only == 0) ? txelecidl : 1'b0; + assign w_rxdetclk = (is_master_only == 0) ? rxdetclk : 1'b0; + assign w_txdetrx = (is_master_only == 0) ? txdetrx : 1'b0; + + // Determine what drives the bonding lines input to the CGB + assign wire_hfclkpin = (is_single_chan == 1) ? 1'b0 : + (pma_is_xn_bonded == 1) ? hfclkpin : // Master CGB resides with PLL for xN bonded + (pma_is_xn_non_bonded == 1) ? 1'b0 : // xn non bonded should not connect bonded clocks + (is_pll_switching == 1) ? 1'b0 : // x1/xN switching should not connect bonded clocks + (is_master_chan == 1) ? wire_hfclkpout : + (is_master_only == 1) ? wire_hfclkpout : + hfclkpin ; + + assign wire_lfclkpin = (is_single_chan == 1) ? 1'b0 : + (pma_is_xn_bonded == 1) ? lfclkpin : // Master CGB resides with PLL for xN bonded + (pma_is_xn_non_bonded == 1) ? 1'b0 : // xn non bonded should not connect bonded clocks + (is_pll_switching == 1) ? 1'b0 : // x1/xN switching should not connect bonded clocks + (is_master_chan == 1) ? wire_lfclkpout : + (is_master_only == 1) ? wire_lfclkpout : + lfclkpin ; + + assign wire_cpulsein = (is_single_chan == 1) ? 1'b0 : + (pma_is_xn_bonded == 1) ? cpulsein : // Master CGB resides with PLL for xN bonded + (pma_is_xn_non_bonded == 1) ? 1'b0 : // xn non bonded should not connect bonded clocks + (is_pll_switching == 1) ? 1'b0 : // x1/xN switching should not connect bonded clocks + (is_master_chan == 1) ? wire_cpulseout : + (is_master_only == 1) ? wire_cpulseout : + cpulsein ; + + assign wire_pclkin = (is_single_chan == 1) ? 3'b000 : + (pma_is_xn_bonded == 1) ? pclkin : // Master CGB resides with PLL for xN bonded + (pma_is_xn_non_bonded == 1) ? 3'b000 : // xn non bonded should not connect bonded clocks + (is_pll_switching == 1) ? 3'b000 : // x1/xN switching should not connect bonded clocks + (is_master_chan == 1) ? wire_pclkout : + (is_master_only == 1) ? wire_pclkout : + pclkin ; + + // determine what drives the bonding lines output from this module + assign hfclkpout = (is_single_chan == 1) ? 1'b0 : + (is_slave_chan == 1) ? 1'b0 : + wire_hfclkpout; + + assign lfclkpout = (is_single_chan == 1) ? 1'b0 : + (is_slave_chan == 1) ? 1'b0 : + wire_lfclkpout; + + assign cpulseout = (is_single_chan == 1) ? 1'b0 : + (is_slave_chan == 1) ? 1'b0 : + wire_cpulseout; + + assign pclkout = (is_single_chan == 1) ? 1'b0 : + (is_slave_chan == 1) ? 1'b0 : + wire_pclkout; + + // determine what drives the HF clock input into CGB + assign wire_clk = (is_slave_chan == 1) ? {MAX_PLLS{1'b0}} // no clock can be connected in a slave mode + : {{(MAX_PLLS-PLL_CNT){1'b0}},clk}; // otherwise, connect the input clock + + assign w_pciesw = (auto_negotiation == "false") ? 1'b0 : pciesw; + + // determine what drives the HF clock input into CGB + + // Non PCIe designs may drive "NORMAL_RESET", the default on the xcvr_native and pcs_ch.sv + // is "normal_reset". Accounting for both the conditions + assign wire_rstn = (pcie_rst == "NORMAL_RESET" || pcie_rst == "normal_reset") ? rstn + : 1'b1; + + // txpcsrstn of HIP connects directly to out_pma_reserved port of PCS + // which in turn connects to pcsrstn of CGB. We will not model this since + // simulation can not reproduce this issue. + + // Possible values for pcie_rst: + // Gen1 w/ HIP w/ HRC, Gen1 w/ HIP w/ SRC, Gen1/2 PIPE - "normal_reset" + // Gen2 w/ HIP w/ HRC - "pcie_rst" + + // Tieing pcsrstn to 1 for Gen2 HRC cases. + assign wire_pcsrstn = 1'b1; + + arriav_hssi_pma_tx_cgb #( + .mode (mode ), + .auto_negotiation (auto_negotiation), + .data_rate (data_rate ), + // fogbugz:153853 mux select attribute on CGB + .pcie_rst (pcie_rst), + .x1_clock_source_sel ((pma_is_xn_bonded == 1)? "x1_clk_unused" + :(((pma_is_xn_non_bonded == 1) || + (is_single_chan == 1) || + (is_master_chan == 1) || + (is_master_only == 1)) ? X1_CLOCK_SOURCE_SEL_AUTONEG // corresponds to .clkcdrloc input + : "x1_clk_unused")), // a special setting when the front-end mux of the CGB is not used (SLAVE CHANNEL ONLY) + .xn_clock_source_sel ((pma_is_xn_non_bonded == 1 || + (bonded_lanes == 1) && (ht_delay_sel != "true"))? "cgb_x1_m_div" + :(((is_master_chan == 1) || + (is_slave_chan == 1) || + (is_master_only == 1))? "xn_up" : // corresponds to *xnup ports + ((is_single_chan == 1) && (ht_delay_sel == "true")) ? "cgb_ht" + : "cgb_x1_m_div")), + .x1_div_m_sel (X1_DIV_M_SEL) + ) tx_cgb ( + .rstn (wire_rstn ), + .pcsrstn (wire_pcsrstn ), + .clkcdrloc (int_wire_clk[0] ), // Switch between this + .clkcdr1t (int_wire_clk[1] ), + .clkcdr1b (int_wire_clk[2] ), + .clkffpll (int_wire_clk[3] ), + .clkupseg (int_wire_clk[4] ), + .clkdnseg (int_wire_clk[5] ), + .fref (fref ), + .pciesw (w_pciesw ), + .hfclkpxnup (wire_hfclkpin ), + .lfclkpxnup (wire_lfclkpin ), + .cpulsexnup (wire_cpulsein ), + .pclkxnup (wire_pclkin ), + + // to serializer + .cpulse (cpulse_from_cgb ), + .hfclkp (hclk_from_cgb ), + .lfclkp (lfclk_from_cgb ), + .pclk (pclk_from_cgb ), + + // when used as a CGB master, these are bonding clocks + .cpulseout (wire_cpulseout ), + .hfclkpout (wire_hfclkpout ), + .lfclkpout (wire_lfclkpout ), + .pclkout (wire_pclkout ), + .pcieswdone (pcieswdone ), + + .avmmrstn (avmmrstn ), + .avmmclk (avmmclk ), + .avmmwrite (avmmwrite ), + .avmmread (avmmread ), + .avmmbyteen (avmmbyteen ), + .avmmaddress (avmmaddress ), + .avmmwritedata (avmmwritedata), + .avmmreaddata (avmmreaddata_cgb ), + .blockselect (blockselect_cgb ) + + `ifndef ALTERA_RESERVED_QIS + , + // Unused inputs + .rxclk (1'b0 ), //to pma_rx_pma_clk + //.clklct (1'b0/*TODO*/ ), + //.clklcb (1'b0/*TODO*/ ), + .hfclkn ( ), + .hfclknout ( ), + .lfclkn ( ), + .lfclknout ( ), + .rxiqclk ( ), + .clkbcdr1t (1'b0 ), + .clkbcdr1b (1'b0 ), + .clkbcdrloc (1'b0 ), + .clkbdnseg (1'b0 ), + .clkbffpll (1'b0 ), + //.clkblcb (1'b0 ), + //.clkblct (1'b0 ), + .clkbupseg (1'b0 ), + .cpulsex6up (1'b0 ), + .cpulsex6dn (1'b0 ), + .cpulsexndn (1'b0 ), + .hfclknx6up (1'b0 ), + .hfclknx6dn (1'b0 ), + .hfclknxndn (1'b0 ), + .hfclknxnup (1'b0 ), + .hfclkpx6up (1'b0 ), + .hfclkpx6dn (1'b0 ), + .hfclkpxndn (1'b0 ), + .lfclknx6up (1'b0 ), + .lfclknx6dn (1'b0 ), + .lfclknxndn (1'b0 ), + .lfclknxnup (1'b0 ), + .lfclkpx6up (1'b0 ), + .lfclkpx6dn (1'b0 ), + .lfclkpxndn (1'b0 ), + .pciesyncp (/*TODO*/ ), + //.pciefbclk (/*TODO*/ ), + .pclkx6up (1'b0 ), + .pclkx6dn (1'b0 ), + .pclkxndn (1'b0 ) + //.pllfbsw (/*TODO*/ ), + //.txpmasyncp (1'b0 ) + `endif // ifndef ALTERA_RESERVED_QIS + ); + + if(master_cgb_en == 0) begin + assign int_wire_clk = (pma_is_xn_bonded == 1)? {MAX_PLLS{1'b0}} : wire_clk; + end else begin + for(ig=0; ig> (2*ig)) & 2'b11); + localparam is_xn = (bonding_mode_sel[1:0] == av_xcvr_h::AV_XR_ID_PMA_BONDING_XN) ? 1 : 0; + + localparam [MAX_CHARS*8-1:0] base_data_rate_sel = get_value_at_index(ig,base_data_rate); + + if (is_xn) begin + assign int_wire_clk[ig] = hfclkpout_from_master[ig]; + + arriav_hssi_pma_tx_cgb #( + .auto_negotiation (auto_negotiation), + .data_rate (base_data_rate_sel), + .x1_clock_source_sel ((is_pll_switching == 0)? X1_CLOCK_SOURCE_SEL_AUTONEG : "same_ch_txpll"), + .xn_clock_source_sel ("cgb_xn_unused"), + .x1_div_m_sel (1) + ) tx_cgb_master ( + .rstn (rstn_cgb_master[ig] ), + .pcsrstn (wire_pcsrstn ), + .clkcdrloc ((is_pll_switching == 1)? wire_clk[ig] : wire_clk[0] ), // Switch between this + .clkcdr1t ((is_pll_switching == 1)? 1'b0 : wire_clk[1] ), + .clkcdr1b ((is_pll_switching == 1)? 1'b0 : wire_clk[2] ), + .clkffpll ((is_pll_switching == 1)? 1'b0 : wire_clk[3] ), + .clkupseg ((is_pll_switching == 1)? 1'b0 : wire_clk[4] ), + .clkdnseg ((is_pll_switching == 1)? 1'b0 : wire_clk[5] ), + .fref (fref ), + .pciesw (w_pciesw ), + .hfclkpxnup (1'b0 ), + .lfclkpxnup (1'b0 ), + .cpulsexnup (1'b0 ), + .pclkxnup (1'b0 ), + + // to serializer + .cpulse (), + .hfclkp (), + .lfclkp (), + .pclk (), + + // xn non-bonded only need the fast clock from Master CGB + .cpulseout (), + .hfclkpout (hfclkpout_from_master[ig]), + .lfclkpout (), + .pclkout (), + .pcieswdone (pcieswdone ), + + .avmmrstn (1'd1 ), + .avmmclk (1'd0 ), + .avmmwrite (1'd0 ), + .avmmread (1'd0 ), + .avmmbyteen (2'd0 ), + .avmmaddress (11'd0 ), + .avmmwritedata (16'd0), + .avmmreaddata ( ), + .blockselect ( ) + + `ifndef ALTERA_RESERVED_QIS + , + // Unused inputs + .rxclk (1'b0 ), //to pma_rx_pma_clk + //.clklct (1'b0/*TODO*/ ), + //.clklcb (1'b0/*TODO*/ ), + .hfclkn ( ), + .hfclknout ( ), + .lfclkn ( ), + .lfclknout ( ), + .rxiqclk ( ), + .clkbcdr1t (1'b0 ), + .clkbcdr1b (1'b0 ), + .clkbcdrloc (1'b0 ), + .clkbdnseg (1'b0 ), + .clkbffpll (1'b0 ), + //.clkblcb (1'b0 ), + //.clkblct (1'b0 ), + .clkbupseg (1'b0 ), + .cpulsex6up (1'b0 ), + .cpulsex6dn (1'b0 ), + .cpulsexndn (1'b0 ), + .hfclknx6up (1'b0 ), + .hfclknx6dn (1'b0 ), + .hfclknxndn (1'b0 ), + .hfclknxnup (1'b0 ), + .hfclkpx6up (1'b0 ), + .hfclkpx6dn (1'b0 ), + .hfclkpxndn (1'b0 ), + .lfclknx6up (1'b0 ), + .lfclknx6dn (1'b0 ), + .lfclknxndn (1'b0 ), + .lfclknxnup (1'b0 ), + .lfclkpx6up (1'b0 ), + .lfclkpx6dn (1'b0 ), + .lfclkpxndn (1'b0 ), + .pciesyncp (/*TODO*/ ), + //.pciefbclk (/*TODO*/ ), + .pclkx6up (1'b0 ), + .pclkx6dn (1'b0 ), + .pclkxndn (1'b0 ) + //.pllfbsw (/*TODO*/ ), + //.txpmasyncp (1'b0 ) + `endif // ifndef ALTERA_RESERVED_QIS + ); + end + else + assign int_wire_clk[ig] = wire_clk[ig]; + end + end + + arriav_hssi_pma_tx_ser #( + .mode (mode), + .auto_negotiation (auto_negotiation), + .ser_loopback (ser_loopback), + .clk_forward_only_mode((is_master_only == 1) ? "true" : "false"), + .pma_direct (pma_direct) + ) tx_pma_ser ( + .cpulse (cpulse_from_cgb ), + .datain (w_datain ), + .hfclk (hclk_from_cgb ), + .lfclk (lfclk_from_cgb ), + .pclk (pclk_from_cgb ), + //.pciesw (w_pciesw ), + .rstn (rstn ), + .clkdivtx (clkdivtx ), + .dataout (dataout_from_ser ), + .lbvop (seriallpbkout ), + .slpbk (seriallpbken ), + .hfclkn (1'b0 ), + .lfclkn (1'b0 ), + //.lbvon (/*TODO*/ ), + .preenout (/*TODO*/ ), + //.pciesyncp (/*TODO*/ ), + .avgvon ( ), + .avgvop ( ), + .avmmrstn (avmmrstn ), + .avmmclk (avmmclk ), + .avmmwrite (avmmwrite ), + .avmmread (avmmread ), + .avmmbyteen (avmmbyteen ), + .avmmaddress (avmmaddress ), + .avmmwritedata (avmmwritedata ), + .avmmreaddata (avmmreaddata_ser ), + .blockselect (blockselect_ser ) + ); + + + + if (is_master_only == 0) begin:tx_pma_buf + wire nonuserfrompmaux; + wire atb0outtopllaux; + wire atb1outtopllaux; + + arriav_hssi_pma_aux #( + .continuous_calibration ("true") + ) tx_pma_aux ( + .calpdb (1'b1 ), + .calclk (calclk ), + .nonusertoio (nonuserfrompmaux ), + .zrxtx50 (/*unused*/ ), + .atb0out (atb0outtopllaux), + .atb1out (atb1outtopllaux) + + `ifndef ALTERA_RESERVED_QIS + , + // Unused inputs + .testcntl (1'b0 ), + .refiqclk (6'b0 ) + `endif // ifndef ALTERA_RESERVED_QIS + ); + + arriav_hssi_pma_tx_buf #( + .rx_det_pdb(rx_det_pdb), + .fir_coeff_ctrl_sel(fir_coeff_ctrl_sel) + ) tx_pma_buf ( + .nonuserfrompmaux (nonuserfrompmaux ), + .datain (dataout_from_ser ), + .rxdetclk (w_rxdetclk ), + .txdetrx (w_txdetrx ), + .txelecidl (w_txelecidl ), + .rxdetectvalid (rxdetectvalid ), + .dataout (dataout ), + .rxfound (rxfound ), + //.txqpipulldn (1'b0 ), + //.txqpipullup (1'b0 ), + .fixedclkout (/*TODO*/ ), + .vrlpbkn (vrlpbkn ), + .vrlpbkp (vrlpbkp ), + .vrlpbkp1t (/*TODO*/ ), + .vrlpbkn1t (/*TODO*/ ), + .icoeff (/*TODO*/ ), + .avgvon ( ), + .avgvop ( ), + .compass ( ), + .detecton ( ), + .probepass ( ), + .avmmrstn (avmmrstn ), + .avmmclk (avmmclk ), + .avmmwrite (avmmwrite ), + .avmmread (avmmread ), + .avmmbyteen (avmmbyteen ), + .avmmaddress (avmmaddress ), + .avmmwritedata (avmmwritedata ), + .avmmreaddata (avmmreaddata_buf ), + .blockselect (blockselect_buf ) + ); + + if ( enable_dcd == 1 ) begin + //pll aux for DCD calibration + arriav_pll_aux # ( + .pl_aux_atb_comp_minus(1'b1), + .pl_aux_atb_comp_plus (1'b1), + .pl_aux_comp_pwr_dn (1'b0) + ) pll_aux ( + .atb0out(atb0outtopllaux), + .atb1out(atb1outtopllaux), + .atbcompout(atb_comp_out) + ); + end else begin + assign atb_comp_out = 1'b0; + end + end // end of if (is_master_only == 0) + end else begin // if dummy_chan + // Warning avoidance + assign dataout = {1'b0,calclk,datain,txelecidl,rxdetclk,txdetrx, + rstn,seriallpbken,clk,pciesw,1'b0,cpulsein, + hfclkpin,lfclkpin,pclkin,avmmrstn,avmmclk,avmmwrite, + avmmread,avmmbyteen,avmmaddress,avmmwritedata, + vrlpbkp,vrlpbkn}; + + assign rxdetectvalid = 1'b0; + assign rxfound = 1'b0; + assign clkdivtx = 1'b0; + assign seriallpbkout = 1'b0; + assign pcieswdone = 2'b00; + assign hfclkpout = 1'b0; + assign lfclkpout = 1'b0; + assign cpulseout = 1'b0; + assign pclkout = 3'b000; + + assign avmmreaddata_cgb = 16'd0; + assign avmmreaddata_ser = 16'd0; + assign avmmreaddata_buf = 16'd0; + assign blockselect_cgb = 1'b0; + assign blockselect_ser = 1'b0; + assign blockselect_buf = 1'b0; + end + + endgenerate + +initial begin + if( (tx_clk_div != 1) && (tx_clk_div != 2) && (tx_clk_div != 4) && (tx_clk_div != 8) ) begin + $display("Critical Warning: parameter 'tx_clk_div' of instance '%m' has illegal value '%0d' assigned to it. Valid parameter values are: '1,2,4,8'. Using value '%0d'", tx_clk_div, X1_DIV_M_SEL); + end +end + + +// Function takes in a string of comma seperated values containing PMA bonding mode. +// returns a binary where every two bits represents the PMA bonding mode. +// MSB indicate whether any of the PLLs using xN non bonded mode. + +function [plls*2:0] pma_bonding_str2bin( + input [MAX_CHARS*MAX_STRS*8-1:0] pma_bonding_set +); + int index; + reg [MAX_CHARS*8-1:0] pma_bonding_str; + reg [1:0] pma_bonding_bin; + reg master_cgb_en; //check whether all PLLs are using x1 + + pma_bonding_str2bin = {plls{2'b00}}; + for(index = 0; index < plls; index = index + 1) begin + pma_bonding_str = altera_xcvr_functions::get_value_at_index(index,pma_bonding_set); + pma_bonding_bin = (pma_bonding_str == "x1") ? av_xcvr_h::AV_XR_ID_PMA_BONDING_X1[1:0]: + (pma_bonding_str == "xN") ? av_xcvr_h::AV_XR_ID_PMA_BONDING_XN [1:0]: + av_xcvr_h::AV_XR_ID_PMA_BONDING_NONE[1:0]; + pma_bonding_str2bin[plls*2-1:0] = pma_bonding_str2bin[plls*2-1:0] | (( {plls{2'b00}} | pma_bonding_bin ) << (index*2)); + pma_bonding_str2bin[plls*2] = pma_bonding_str2bin[plls*2] | pma_bonding_str2bin[index*2]; + end +endfunction + +endmodule + diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_avmm.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_avmm.sv new file mode 100644 index 0000000..6e937c4 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_avmm.sv @@ -0,0 +1,398 @@ +// (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 1ps/1ps + +import altera_xcvr_functions::*; + +module av_xcvr_avmm + #( + //PARAM_LIST_START + parameter bonded_lanes = 1, // Number of lanes + parameter bonding_master_ch = 0, // Indicates which channel is master + parameter bonding_master_only = "-1", // Indicates which channels are MASTER_ONLY. List of strings. + parameter pma_reserved_ch = "-1", // Indicates which channels are reserved + + // PMA enables + parameter rx_enable = 0, // Indicates whether this interface contains an rx channel. + parameter tx_enable = 0, // Indicates whether this interface contains a tx channel + // PCS enables + parameter enable_8g_tx = "false",// Is 8g TX PCS enabled? + parameter enable_8g_rx = "false",// Is 8g RX PCS enabled? + // Services requests + parameter request_dcd = 0, // Request Duty Cycle Distortion correction at startup + parameter request_vrc = 0, // Request Voltage Regulator Calibration at startup + parameter request_offset = 1 // Request RX Offset Cancellation at startup - defaults to enabled, only PCIE w/HIP should unset this + //PARAM_LIST_END + ) ( + //PORT_LIST_START + // Reconfiguration signal bundles + input wire [bonded_lanes*W_S5_RECONFIG_BUNDLE_TO_XCVR -1:0] reconfig_to_xcvr, + output wire [bonded_lanes*W_S5_RECONFIG_BUNDLE_FROM_XCVR-1:0] reconfig_from_xcvr, + // Control inputs from PLD + input wire [bonded_lanes-1 :0] seriallpbken, // 1 = enable serial loopback + // PCS clocks + input wire [bonded_lanes-1 :0] in_pld_8g_pld_rx_clk, // 8g PCS RX clock + // PCS resets + input wire [bonded_lanes-1 :0] in_pld_8g_txurstpcs_n, // 8g PCS TX reset + input wire [bonded_lanes-1 :0] in_pld_8g_rxurstpcs_n, // 8g PCS RX reset + output wire [bonded_lanes-1 :0] out_pld_8g_txurstpcs_n, // 8g PCS TX reset + output wire [bonded_lanes-1 :0] out_pld_8g_rxurstpcs_n, // 8g PCS RX reset + + // PMA resets + input wire [bonded_lanes-1 :0] rx_crurstn, // CDR analog reset (active low) + input wire [bonded_lanes-1 :0] in_pld_rxpma_rstb_in, + output wire [bonded_lanes-1 :0] out_rx_crurstn, // CDR analog reset (active low) + output wire [bonded_lanes-1 :0] out_pld_rxpma_rstb_in, + + // PCS data + input wire [bonded_lanes*64-1 :0] out_pld_rx_data, // PCS data output + + // Calibration clocks + output wire calclk, // Calibration clock driven from reconfig clock to aux block + + //calibration status + output wire [bonded_lanes-1 :0] tx_cal_busy, + output wire [bonded_lanes-1 :0] rx_cal_busy, + // Reconfig controls + output wire [bonded_lanes-1 :0] pma_hardoccalen, + output wire [bonded_lanes-1 :0] pma_seriallpbken, + // Reconfig status + input wire [bonded_lanes-1 :0] pcs_8g_prbs_done, + input wire [bonded_lanes-1 :0] pcs_8g_prbs_err, + + // Channel AVMM interface signals + output wire [bonded_lanes-1 :0] chnl_avmm_clk, + output wire [bonded_lanes-1 :0] chnl_avmm_rstn, + output wire [bonded_lanes*16-1 :0] chnl_avmm_writedata, + output wire [bonded_lanes*11-1 :0] chnl_avmm_address, + output wire [bonded_lanes-1 :0] chnl_avmm_write, + output wire [bonded_lanes-1 :0] chnl_avmm_read, + output wire [bonded_lanes*2-1 :0] chnl_avmm_byteen, + // PMA AVMM signals + input wire [bonded_lanes*16-1 :0] pma_avmmreaddata_tx_cgb, // TX AVMM CGB readdata (16 for each lane) + input wire [bonded_lanes*16-1 :0] pma_avmmreaddata_tx_ser, // TX AVMM SER readdata (16 for each lane) + input wire [bonded_lanes*16-1 :0] pma_avmmreaddata_tx_buf, // TX AVMM BUF readdata (16 for each lane) + input wire [bonded_lanes*16-1 :0] pma_avmmreaddata_rx_ser, // RX AVMM SER readdata (16 for each lane) + input wire [bonded_lanes*16-1 :0] pma_avmmreaddata_rx_buf, // RX AVMM BUF readdata (16 for each lane) + input wire [bonded_lanes*16-1 :0] pma_avmmreaddata_rx_cdr, // RX AVMM CDR readdata (16 for each lane) + input wire [bonded_lanes*16-1 :0] pma_avmmreaddata_rx_mux, // RX AVMM CDR MUX readdata (16 for each lane) + input wire [bonded_lanes-1 :0] pma_blockselect_tx_cgb, // TX AVMM CGB blockselect (1 for each lane) + input wire [bonded_lanes-1 :0] pma_blockselect_tx_ser, // TX AVMM SER blockselect (1 for each lane) + input wire [bonded_lanes-1 :0] pma_blockselect_tx_buf, // TX AVMM BUF blockselect (1 for each lane) + input wire [bonded_lanes-1 :0] pma_blockselect_rx_ser, // RX AVMM SER blockselect (1 for each lane) + input wire [bonded_lanes-1 :0] pma_blockselect_rx_buf, // RX AVMM BUF blockselect (1 for each lane) + input wire [bonded_lanes-1 :0] pma_blockselect_rx_cdr, // RX AVMM CDR blockselect (1 for each lane) + input wire [bonded_lanes-1 :0] pma_blockselect_rx_mux, // RX AVMM CDR MUX blockselect (1 for each lane) + input wire [bonded_lanes-1 :0] pll_aux_atb_comp_out, // Voltage comparator output for DCD (1 for each lane) + // PCS AVMM signals + input wire [bonded_lanes*16-1 :0] avmmreaddata_com_pcs_pma_if, + input wire [bonded_lanes*16-1 :0] avmmreaddata_com_pld_pcs_if, + input wire [bonded_lanes*16-1 :0] avmmreaddata_pcs8g_rx, + input wire [bonded_lanes*16-1 :0] avmmreaddata_pcs8g_tx, + input wire [bonded_lanes*16-1 :0] avmmreaddata_pipe12, + input wire [bonded_lanes*16-1 :0] avmmreaddata_rx_pcs_pma_if, + input wire [bonded_lanes*16-1 :0] avmmreaddata_rx_pld_pcs_if, + input wire [bonded_lanes*16-1 :0] avmmreaddata_tx_pcs_pma_if, + input wire [bonded_lanes*16-1 :0] avmmreaddata_tx_pld_pcs_if, + input wire [bonded_lanes-1 :0] blockselect_com_pcs_pma_if, + input wire [bonded_lanes-1 :0] blockselect_com_pld_pcs_if, + input wire [bonded_lanes-1 :0] blockselect_pcs8g_rx, + input wire [bonded_lanes-1 :0] blockselect_pcs8g_tx, + input wire [bonded_lanes-1 :0] blockselect_pipe12, + input wire [bonded_lanes-1 :0] blockselect_rx_pcs_pma_if, + input wire [bonded_lanes-1 :0] blockselect_rx_pld_pcs_if, + input wire [bonded_lanes-1 :0] blockselect_tx_pcs_pma_if, + input wire [bonded_lanes-1 :0] blockselect_tx_pld_pcs_if + //PORT_LIST_END + ); +`ifndef ALTERA_RESERVED_QIS_ES + `define ALTERA_RESERVED_XCVR_AV_CMU_PLL_RESET_CONNECT +`endif + +localparam w_bundle_to_xcvr = W_S5_RECONFIG_BUNDLE_TO_XCVR; +localparam w_bundle_from_xcvr= W_S5_RECONFIG_BUNDLE_FROM_XCVR; + + +wire [bonded_lanes-1:0] pld_avmm_clk; +wire [bonded_lanes-1:0] pld_avmm_reset; +wire [bonded_lanes-1:0] w_interface_sel; +wire [bonded_lanes-1:0] w_ser_shift_load; +wire [bonded_lanes-1:0] w_seriallpbken; +wire [bonded_lanes-1:0] tx_digital_reset; +wire [bonded_lanes-1:0] rx_digital_reset; +wire [bonded_lanes-1:0] tx_rst_ovr; +wire [bonded_lanes-1:0] tx_digital_rst_n_val; +wire [bonded_lanes-1:0] rx_rst_ovr; +wire [bonded_lanes-1:0] rx_digital_rst_n_val; +wire [bonded_lanes-1:0] rx_analog_rst_n_val; +wire [bonded_lanes-1:0] l_in_pld_rxpma_rstb_in; +wire [bonded_lanes-1:0] l_rx_crurstn; + +wire avmm_clk; // Selected AVMM clock +wire avmm_reset; // Selected AVMM reset +// Use first channel clock for all channels' calclk +assign calclk = pld_avmm_clk[0]; +assign avmm_clk = pld_avmm_clk[0]; +assign avmm_reset= pld_avmm_reset[0]; + +// Allow PRBS clear to be driven either from reconfig or from core. +// Allow serial loopback to be driven either from reconfig or from core. +assign pma_seriallpbken = seriallpbken | w_seriallpbken; +assign rx_digital_reset = (enable_8g_rx == "true") ? ~in_pld_8g_rxurstpcs_n: + 1'b0; // Issue +assign tx_digital_reset = (enable_8g_rx == "true") ? ~in_pld_8g_rxurstpcs_n: + 1'b0; // Issue + +// Disconnect reset inputs for ES silicon +`ifdef ALTERA_RESERVED_XCVR_AV_CMU_PLL_RESET_CONNECT + assign l_in_pld_rxpma_rstb_in = in_pld_rxpma_rstb_in; + assign l_rx_crurstn = rx_crurstn; +`else + assign l_in_pld_rxpma_rstb_in = {bonded_lanes{1'b1}}; + assign l_rx_crurstn = {bonded_lanes{1'b1}}; +`endif +// Reset overrides for calibration IP use +assign out_pld_8g_txurstpcs_n = tx_rst_ovr ? tx_digital_rst_n_val : in_pld_8g_txurstpcs_n; // 8g PCS TX reset +assign out_pld_8g_rxurstpcs_n = rx_rst_ovr ? rx_digital_rst_n_val : in_pld_8g_rxurstpcs_n; // 8g PCS RX reset +assign out_rx_crurstn = rx_rst_ovr ? rx_analog_rst_n_val : l_rx_crurstn; // CDR analog reset (active low) + + +initial begin + // Validate parameters + // PMA disabled and PCS enabled + if(rx_enable == 0 && enable_8g_rx == "true") + $display("Error: [av_xcvr_avmm] Enabling of 8g RX PCS without PMA not supported!"); + if(tx_enable == 0 && enable_8g_tx == "true") + $display("Error: [av_xcvr_avmm] Enabling of 8g RX PCS without PMA not supported!"); + +end + + localparam [MAX_XCVR_CHANNELS-1:0] int_bonding_master_only_set = altera_xcvr_functions::map_numerical_is_in_legal_set(bonded_lanes,bonding_master_only); + localparam [MAX_XCVR_CHANNELS-1:0] int_reserved_ch_set = altera_xcvr_functions::map_numerical_is_in_legal_set(bonded_lanes,pma_reserved_ch); + +generate begin + genvar ig; + genvar jg; + for(ig=0;ig AVMM signals + // Avalon MM native reconfiguration interfaces + wire [15:0] pld_avmm_writedata; // Avalon DPRIO writedata + wire [11:0] pld_avmm_address; // Avalon DPRIO address + wire pld_avmm_write; // Avalon DPRIO write + wire pld_avmm_read; // Avalon DPRIO read + wire [15:0] pld_avmm_readdata; // Avalon readdata to core + wire csr_avmm_n_sel; // Select Soft CSR or DPRIO + reg csr_avmm_n_sel_r; // Select Soft CSR or DPRIO (read) + // Soft CSR Avalon signals + wire csr_write; // Avalon write to Soft CSR + wire csr_read; // Avalon read to Soft CSR + wire [15:0] csr_readdata; // Avalon readdata from Soft CSR + // DPRIO Avalon signals + wire avmm_write; // Avalon write to DPRIO + wire avmm_read; // Avalon read to DPRIO + wire [15:0] avmm_readdata; // Avalon readdata from DPRIO + // Testbus + wire [23:0] w_pmatestbus; + wire [11:0] w_pmatestbussel; + + localparam is_master_only = (((int_bonding_master_only_set >> ig) & 1'b1) == 1) ? 1 : 0; + localparam is_reserved = (((int_reserved_ch_set >> ig) & 1'b1) == 1) ? 1 : 0; + + assign out_pld_rxpma_rstb_in[ig] = ( is_master_only == 1 || is_reserved == 1) ? l_in_pld_rxpma_rstb_in[ig] :rx_rst_ovr[ig] ? rx_analog_rst_n_val[ig] : in_pld_rxpma_rstb_in[ig]; + + // Extract and compose bundled signals + av_reconfig_bundle_to_xcvr #( + .native_ifs (1) // number of native reconfig interfaces + ) av_reconfig_bundle_to_xcvr_inst( + // bundled reconfig buses + .reconfig_to_xcvr (reconfig_to_xcvr [ig*w_bundle_to_xcvr +:w_bundle_to_xcvr ] ), // all inputs from reconfig block to native xcvr reconfig ports + .reconfig_from_xcvr (reconfig_from_xcvr[ig*w_bundle_from_xcvr+:w_bundle_from_xcvr] ), // all outputs from native xcvr reconfig ports to reconfig block + // native reconfig sources + .native_reconfig_readdata (pld_avmm_readdata ), // Avalon DPRIO readdata + .pif_testbus (w_pmatestbus ), + + // Voltage comparator output for DCD + .pif_atbcompout (pll_aux_atb_comp_out [ig]), + + // Calibration status + .tx_cal_busy (tx_cal_busy [ig]), + .rx_cal_busy (rx_cal_busy [ig]), + + // native reconfig sinks + .native_reconfig_clk (pld_avmm_clk [ig]), + .native_reconfig_reset (pld_avmm_reset [ig]), + .native_reconfig_writedata(pld_avmm_writedata ), + .native_reconfig_address (pld_avmm_address ), + .native_reconfig_write (pld_avmm_write ), + .native_reconfig_read (pld_avmm_read ), + .pif_testbus_sel (w_pmatestbussel ), // 4 bits per physical channel + .pif_interface_sel (w_interface_sel [ig]), + .pif_ser_shift_load (w_ser_shift_load [ig]) + ); + + // Only instantiate avmm block if this is not a bonding master only channel + // If the lane is master only lane or empty channel, do not stamp out the AVMM + if((is_master_only != 1) && (is_reserved != 1)) begin + // DPRIO signals + wire [90-1:0] chnl_avmm_blockselect; + wire [15:0] chnl_avmm_readdata [0:(90-1)]; + wire [90*16-1:0] chnl_avmm_readdatabus; + + for(jg = 0; jg < 90; jg = jg + 1) begin:avmm_assigns + assign chnl_avmm_readdatabus[jg*16+:16] = chnl_avmm_readdata[jg]; + assign {chnl_avmm_readdata[jg],chnl_avmm_blockselect[jg]} = + // TX PMA connections + (jg == 0) ? {pma_avmmreaddata_tx_ser [ig*16+:16],pma_blockselect_tx_ser [ig]} : + (jg == 1) ? {pma_avmmreaddata_tx_cgb [ig*16+:16],pma_blockselect_tx_cgb [ig]} : + (jg == 2) ? {pma_avmmreaddata_tx_buf [ig*16+:16],pma_blockselect_tx_buf [ig]} : + // RX PMA connections + (jg == 3) ? {pma_avmmreaddata_rx_ser [ig*16+:16],pma_blockselect_rx_ser [ig]} : + (jg == 4) ? {pma_avmmreaddata_rx_buf [ig*16+:16],pma_blockselect_rx_buf [ig]} : + (jg == 5) ? {pma_avmmreaddata_rx_cdr [ig*16+:16],pma_blockselect_rx_cdr [ig]} : + (jg == 6) ? {pma_avmmreaddata_rx_mux [ig*16+:16],pma_blockselect_rx_mux [ig]} : + // PCS connections + (jg == 10) ? {avmmreaddata_pcs8g_rx [ig*16+:16],blockselect_pcs8g_rx [ig]} : + (jg == 11) ? {avmmreaddata_pipe12 [ig*16+:16],blockselect_pipe12 [ig]} : + (jg == 12) ? {avmmreaddata_pcs8g_tx [ig*16+:16],blockselect_pcs8g_tx [ig]} : + (jg == 18) ? {avmmreaddata_com_pld_pcs_if [ig*16+:16],blockselect_com_pld_pcs_if[ig]} : + (jg == 19) ? {avmmreaddata_tx_pld_pcs_if [ig*16+:16],blockselect_tx_pld_pcs_if [ig]} : + (jg == 20) ? {avmmreaddata_rx_pld_pcs_if [ig*16+:16],blockselect_rx_pld_pcs_if [ig]} : + (jg == 21) ? {avmmreaddata_com_pcs_pma_if [ig*16+:16],blockselect_com_pcs_pma_if[ig]} : + (jg == 22) ? {avmmreaddata_tx_pcs_pma_if [ig*16+:16],blockselect_tx_pcs_pma_if [ig]} : + (jg == 23) ? {avmmreaddata_rx_pcs_pma_if [ig*16+:16],blockselect_rx_pcs_pma_if [ig]} : + {16'd0,1'b0}; + end + + // Mux between hard and soft reconfig registers + assign csr_avmm_n_sel = pld_avmm_address[11]; + assign pld_avmm_readdata = csr_avmm_n_sel_r ? csr_readdata : avmm_readdata; + assign avmm_write = pld_avmm_write & ~csr_avmm_n_sel; + assign avmm_read = pld_avmm_read & ~csr_avmm_n_sel; + assign csr_write = pld_avmm_write & csr_avmm_n_sel; + assign csr_read = pld_avmm_read & csr_avmm_n_sel; + + always @(posedge avmm_clk or posedge avmm_reset) + if(avmm_reset) csr_avmm_n_sel_r <= 1'b0; + else csr_avmm_n_sel_r <= csr_avmm_n_sel; + + // AVMM atom + arriav_hssi_avmm_interface av_hssi_avmm_interface_inst + ( + .avmmrstn (1'b1 ), + .avmmclk (avmm_clk ), // Use first channel clock for all channels + .avmmwrite (avmm_write ), + .avmmread (avmm_read ), + .avmmbyteen (2'b11 ), + .avmmaddress (pld_avmm_address [10:0] ), + .avmmwritedata (pld_avmm_writedata ), + .avmmreaddata (avmm_readdata ), + + + .blockselect (chnl_avmm_blockselect ), + .readdatachnl (chnl_avmm_readdatabus ), + .clkchnl (chnl_avmm_clk [ig] ), + .rstnchnl (chnl_avmm_rstn [ig] ), + .writedatachnl (chnl_avmm_writedata [ig*16+:16] ), + .regaddrchnl (chnl_avmm_address [ig*11+:11] ), + .writechnl (chnl_avmm_write [ig] ), + .readchnl (chnl_avmm_read [ig] ), + .byteenchnl (chnl_avmm_byteen [ig*2+:2] ), + + // The following ports belong to pm_tst_mux blocks in the PMA + .pmatestbus (w_pmatestbus ), + .pmatestbussel (w_pmatestbussel ), + + // + .scanmoden (1'b1 ), // Not used + .scanshiftn (1'b1 ), // Not used + .sershiftload (w_ser_shift_load[0] ), // Use first channel signal + .interfacesel (w_interface_sel [0] ), // Use first channel signal + + .refclkdig (/*unused*/ ), + .avmmreservedin (/*unused*/ ), + + .avmmreservedout (/*unused*/ ), + .dpriorstntop (/*unused*/ ), + .dprioclktop (/*unused*/ ), + .mdiodistopchnl (/*unused*/ ), + .dpriorstnmid (/*unused*/ ), + .dprioclkmid (/*unused*/ ), + .mdiodismidchnl (/*unused*/ ), + .dpriorstnbot (/*unused*/ ), + .dprioclkbot (/*unused*/ ), + .mdiodisbotchnl (/*unused*/ ), + .dpriotestsitopchnl (/*unused*/ ), + .dpriotestsimidchnl (/*unused*/ ), + .dpriotestsibotchnl (/*unused*/ ) + ); + + // Soft reconfig CSR + av_xcvr_avmm_csr #( + .pll_type (0 ), // 0-None,1-CMU,2-LC/ATX,3-fPLL + .rx_enable (rx_enable ), // Indicates whether this interface contains an rx channel. + .tx_enable (tx_enable ), // Indicates whether this interface contains a tx channel + // Service request parameters + .request_dcd (request_dcd ), // Request Duty Cycle Distortion correction at startup + .request_vrc (request_vrc ), // Request Voltage Regulator Calibration at startup + .request_offset (request_offset ) // Request RX Offset Cancellation at startup + ) sv_xcvr_avmm_csr_inst ( + // Avalon interface + .av_clk (avmm_clk ), + .av_reset (avmm_reset ), + .av_writedata (pld_avmm_writedata ), + .av_address (pld_avmm_address[3:0] ), + .av_write (csr_write ), + .av_read (csr_read ), + .av_readdata (csr_readdata ), + // Offset Cancellation + .hardoccaldone (1'b0 ), + .hardoccalen (pma_hardoccalen [ig]), + // PRBS + .pcs_8g_prbs_done (pcs_8g_prbs_done [ig]), + .pcs_8g_prbs_err (pcs_8g_prbs_err [ig]), + // SLPBK + .seriallpbken (w_seriallpbken [ig]), + // Channel STATUS + .stat_pll_locked (1'b0 ), + .stat_tx_digital_reset(tx_digital_reset [ig]), + .stat_rx_digital_reset(rx_digital_reset [ig]), + // Reset overrides + .tx_rst_ovr (tx_rst_ovr [ig]), + .tx_digital_rst_n_val (tx_digital_rst_n_val[ig]), + .rx_rst_ovr (rx_rst_ovr [ig]), + .rx_digital_rst_n_val (rx_digital_rst_n_val[ig]), + .rx_analog_rst_n_val (rx_analog_rst_n_val [ig]) + ); + + end else begin + assign chnl_avmm_clk [ig] = 1'b0; + assign chnl_avmm_rstn [ig] = 1'b1; + assign chnl_avmm_writedata [ig*16+:16] = 16'd0; + assign chnl_avmm_address [ig*11+:11] = 11'd0; + assign chnl_avmm_write [ig] = 1'b0; + assign chnl_avmm_read [ig] = 1'b0; + assign chnl_avmm_byteen [ig* 2+: 2] = 1'b0; + assign w_seriallpbken [ig] = 1'b0; + + assign tx_rst_ovr [ig] = 1'b0; + assign tx_digital_rst_n_val[ig] = 1'b0; + assign rx_rst_ovr [ig] = 1'b0; + assign rx_digital_rst_n_val[ig] = 1'b0; + assign rx_analog_rst_n_val [ig] = 1'b0; + end + end +end +endgenerate + +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_avmm_csr.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_avmm_csr.sv new file mode 100644 index 0000000..8ed24e6 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_avmm_csr.sv @@ -0,0 +1,337 @@ +// (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 1ps/1ps + +module av_xcvr_avmm_csr + #( + parameter pll_type = 0, // 0-None,1-CMU,2-LC/ATX,3-fPLL + parameter rx_enable = 0, // Indicates whether this interface contains an rx channel. + parameter tx_enable = 0, // Indicates whether this interface contains a tx channel + // Service request parameters + parameter request_dcd = 0, // Request Duty Cycle Distortion correction at startup + parameter request_vrc = 0, // Request Voltage Regulator Calibration at startup + parameter request_offset = 1 // Request RX Offset Cancellation at startup - defaults to enabled, only PCIE w/HIP should disable this request + ) ( + // Avalon interface + input wire av_clk, + input wire av_reset, + input wire [15:0] av_writedata, + input wire [ 3:0] av_address, + input wire av_write, + input wire av_read, + output reg [15:0] av_readdata, + // Offset Cancellation + input wire hardoccaldone, + output wire hardoccalen, + // PRBS + input wire pcs_8g_prbs_done, + input wire pcs_8g_prbs_err, + // DCD + input wire dcd_ack, + input wire [7:0] dcd_sum_a, + input wire [7:0] dcd_sum_b, + // SLPBK + output wire seriallpbken, + // Channel STATUS + input wire stat_pll_locked, + input wire stat_tx_digital_reset, + input wire stat_rx_digital_reset, + // Reset overrides + output wire tx_rst_ovr, + output wire tx_digital_rst_n_val, + output wire rx_rst_ovr, + output wire rx_digital_rst_n_val, + output wire rx_analog_rst_n_val +); + +import av_xcvr_h::*; + +localparam [15:0] RD_UNUSED = 16'h0000; + +wire [3:0] loc_address; + +//******************* +// Readback registers +wire [15:0] rd_dummy; +wire [15:0] rd_oc; +wire [15:0] rd_prbs; +wire [15:0] rd_slpbk; +wire [15:0] rd_status; +wire [15:0] rd_id; +wire [15:0] rd_request; +wire [15:0] rd_rstctl; + +//********************* +// Avalon readback data +assign loc_address = av_address[3:0]; +always @(posedge av_clk) + if(~av_read) av_readdata <= RD_UNUSED; + else case(loc_address) + AV_XR_ADDR_DUMMY: av_readdata <= rd_dummy; + AV_XR_ADDR_OC: av_readdata <= rd_oc; + AV_XR_ADDR_PRBS: av_readdata <= rd_prbs; + AV_XR_ADDR_SLPBK: av_readdata <= rd_slpbk; + AV_XR_ADDR_STATUS: av_readdata <= rd_status; + AV_XR_ADDR_ID: av_readdata <= rd_id; + AV_XR_ADDR_REQUEST: av_readdata <= rd_request; + AV_XR_ADDR_RSTCTL: av_readdata <= rd_rstctl; + default: av_readdata <= RD_UNUSED; + endcase + +//*************** +// DUMMY register +reg r_dummy = 1'b0; + +// Readback data +assign rd_dummy = {15'd0,r_dummy}; +always @(posedge av_clk or posedge av_reset) + if(av_reset) r_dummy <= 1'b0; + else if(av_write & (loc_address == AV_XR_ADDR_DUMMY)) + r_dummy <= av_writedata[AV_XR_DUMMY_DUMMY_OFST]; + +//************ +// OC register +generate if (rx_enable == 1) begin:gen_oc_reg + reg r_hardoccalen = 1'b0; + + // Control outputs + assign hardoccalen = r_hardoccalen; + // Readback data + assign rd_oc[AV_XR_OC_CALEN_OFST ] = r_hardoccalen; + assign rd_oc[AV_XR_OC_CALDONE_OFST] = hardoccaldone; // TODO - meta + assign rd_oc[AV_XR_OC_UNUSED_OFST + +:AV_XR_OC_UNUSED_LEN] = {AV_XR_OC_UNUSED_LEN{1'b0}}; + // Avalon registers + always @(posedge av_clk or posedge av_reset) + if(av_reset) begin + r_hardoccalen <= 1'b0; + end else if(av_write & (loc_address == AV_XR_ADDR_OC)) begin + r_hardoccalen <= av_writedata[AV_XR_OC_CALEN_OFST]; + end +end else begin + // Register unused + assign hardoccalen = 1'b0; + assign rd_oc = RD_UNUSED; +end +endgenerate + + +//************** +// PRBS register +generate if (rx_enable == 1) begin:gen_prbs_reg + reg r_prbs_err_clr = 1'b0; + + // Readback data + assign rd_prbs[AV_XR_PRBS_CLR_OFST ] = r_prbs_err_clr; + assign rd_prbs[AV_XR_PRBS_8G_ERR_OFST ] = pcs_8g_prbs_err; // TODO - meta + assign rd_prbs[AV_XR_PRBS_8G_DONE_OFST ] = pcs_8g_prbs_done; // TODO - meta + assign rd_prbs[AV_XR_PRBS_UNUSED_OFST + +:AV_XR_PRBS_UNUSED_LEN ] = {AV_XR_PRBS_UNUSED_LEN{1'b0}}; + // Avalon registers + always @(posedge av_clk or posedge av_reset) + if(av_reset) begin + r_prbs_err_clr <= 1'b0; + end else if(av_write & (loc_address == AV_XR_ADDR_PRBS)) begin + r_prbs_err_clr <= av_writedata[AV_XR_PRBS_CLR_OFST]; + end +end else begin + // Register unused + assign rd_prbs = RD_UNUSED; +end +endgenerate + + +//*************** +// SLPBK register +generate if (tx_enable == 1) begin:gen_slpbk_reg + reg r_seriallpbken = 1'b0; + + // Control outputs + assign seriallpbken = r_seriallpbken; + // Readback data + assign rd_slpbk[AV_XR_SLPBK_SLPBKEN_OFST] = r_seriallpbken; + assign rd_slpbk[AV_XR_SLPBK_UNUSED_OFST + +:AV_XR_SLPBK_UNUSED_LEN] = {AV_XR_SLPBK_UNUSED_LEN{1'b0}}; + // Avalon registers + always @(posedge av_clk or posedge av_reset) + if(av_reset) begin + r_seriallpbken <= 1'b0; + end else if(av_write & (loc_address == AV_XR_ADDR_SLPBK)) begin + r_seriallpbken <= av_writedata[AV_XR_SLPBK_SLPBKEN_OFST]; + end +end else begin + // Register unused + assign seriallpbken = 1'b0; + assign rd_slpbk = RD_UNUSED; +end +endgenerate + + +//**************** +// STATUS register +// Readback data +// TX status +generate if (tx_enable == 1) begin:gen_status_reg_tx + wire stat_tx_digital_reset_r; + // Resynchronize input signals + alt_xcvr_resync #( + .WIDTH(1) + ) alt_xcvr_resync_inst ( + .clk (av_clk), + .reset (av_reset), + .d (stat_tx_digital_reset), + .q (stat_tx_digital_reset_r) + ); + assign rd_status[AV_XR_STATUS_TX_DIGITAL_RESET_OFST] = stat_tx_digital_reset_r; +end else begin + assign rd_status[AV_XR_STATUS_TX_DIGITAL_RESET_OFST] = 1'b0; +end +endgenerate +// RX status +generate if (rx_enable == 1) begin:gen_status_reg_rx + wire stat_rx_digital_reset_r; + // Resynchronize input signals + alt_xcvr_resync #( + .WIDTH(1) + ) alt_xcvr_resync_inst ( + .clk (av_clk), + .reset (av_reset), + .d (stat_rx_digital_reset), + .q (stat_rx_digital_reset_r) + ); + assign rd_status[AV_XR_STATUS_RX_DIGITAL_RESET_OFST] = stat_rx_digital_reset_r; +end else begin + assign rd_status[AV_XR_STATUS_RX_DIGITAL_RESET_OFST] = 1'b0; +end +endgenerate +// PLL status +generate if (pll_type != AV_XR_ID_PLL_TYPE_NONE) begin:gen_status_reg_pll + wire stat_pll_locked_r; + reg r_pll_locked_flag; + // Resynchronize input signals + alt_xcvr_resync #( + .WIDTH(1) + ) alt_xcvr_resync_inst ( + .clk (av_clk), + .reset (av_reset), + .d (stat_pll_locked), + .q (stat_pll_locked_r) + ); + + // pll_locked flag logic + // Set by AVMM interface, cleared by pll_locked deassertion + always @(posedge av_clk or posedge av_reset) begin + if(av_reset) + r_pll_locked_flag <= 1'b0; + else if(av_write & (loc_address == AV_XR_ADDR_STATUS)) + r_pll_locked_flag <= av_writedata[AV_XR_STATUS_PLL_LOCKED_FLAG_OFST]; + else if(!stat_pll_locked_r) + r_pll_locked_flag <= 1'b0; + end + + assign rd_status[AV_XR_STATUS_PLL_LOCKED_OFST ] = stat_pll_locked_r; + assign rd_status[AV_XR_STATUS_PLL_LOCKED_FLAG_OFST ] = r_pll_locked_flag; +end else begin + assign rd_status[AV_XR_STATUS_PLL_LOCKED_OFST ] = 1'b0; + assign rd_status[AV_XR_STATUS_PLL_LOCKED_FLAG_OFST ] = 1'b0; +end +endgenerate + +assign rd_status[AV_XR_STATUS_UNUSED_OFST+:AV_XR_STATUS_UNUSED_LEN] = {AV_XR_STATUS_UNUSED_LEN{1'b0}}; + + +//************ +// ID register +// Readback data +assign rd_id[AV_XR_ID_TX_CHANNEL_OFST ] = (tx_enable == 1) ? 1'b1 : 1'b0; +assign rd_id[AV_XR_ID_RX_CHANNEL_OFST ] = (rx_enable == 1) ? 1'b1 : 1'b0; +assign rd_id[AV_XR_ID_PLL_TYPE_OFST+:AV_XR_ID_PLL_TYPE_LEN] + = pll_type[1:0]; +assign rd_id[AV_XR_ID_UNUSED_OFST+:AV_XR_ID_UNUSED_LEN] + = {AV_XR_ID_UNUSED_LEN{1'b0}}; + + +//************************** +// REQUEST services register +assign rd_request[AV_XR_REQUEST_DCD_OFST ] = (request_dcd == 0) ? 1'b0 : 1'b1; +assign rd_request[AV_XR_REQUEST_VRC_OFST ] = (request_vrc == 0) ? 1'b0 : 1'b1; +assign rd_request[AV_XR_REQUEST_OFFSET_OFST ] = (request_offset == 0) ? 1'b0 : 1'b1; +assign rd_request[AV_XR_REQUEST_UNUSED_OFST+:AV_XR_REQUEST_UNUSED_LEN] + = {AV_XR_REQUEST_UNUSED_LEN{1'b0}}; +//************************ +// RSTCTL register +// User reset controls + +// Avalon registers for Tx digital reset +generate if (tx_enable == 1) begin:gen_rstctl_reg_tx + reg r_tx_rst_ovr = 1'b0; + reg r_tx_digital_rst_n_val = 1'b0; + + always @(posedge av_clk or posedge av_reset) begin + if(av_reset) begin + r_tx_rst_ovr <= 1'b0; + r_tx_digital_rst_n_val <= 1'b0; + end else if(av_write & (loc_address == AV_XR_ADDR_RSTCTL)) begin + r_tx_rst_ovr <= av_writedata[AV_XR_RSTCTL_TX_RST_OVR_OFST]; + r_tx_digital_rst_n_val <= av_writedata[AV_XR_RSTCTL_TX_DIGITAL_RST_N_VAL_OFST]; + end + end + + assign tx_rst_ovr = r_tx_rst_ovr; + assign tx_digital_rst_n_val = r_tx_digital_rst_n_val; +end +else begin + assign tx_rst_ovr = 1'b0; + assign tx_digital_rst_n_val = 1'b0; +end +endgenerate + +// Avalon registers for Rx digital and analog resets +generate if (rx_enable == 1) begin:gen_rstctl_reg_rx + reg r_rx_rst_ovr = 1'b0; + reg r_rx_digital_rst_n_val = 1'b0; + reg r_rx_analog_rst_n_val = 1'b0; + + always @(posedge av_clk or posedge av_reset) begin + if(av_reset) begin + r_rx_rst_ovr <= 1'b0; + r_rx_digital_rst_n_val <= 1'b0; + r_rx_analog_rst_n_val <= 1'b0; + end else if(av_write & (loc_address == AV_XR_ADDR_RSTCTL)) begin + r_rx_rst_ovr <= av_writedata[AV_XR_RSTCTL_RX_RST_OVR_OFST]; + r_rx_digital_rst_n_val <= av_writedata[AV_XR_RSTCTL_RX_DIGITAL_RST_N_VAL_OFST]; + r_rx_analog_rst_n_val <= av_writedata[AV_XR_RSTCTL_RX_ANALOG_RST_N_VAL_OFST]; + end + end + + assign rx_rst_ovr = r_rx_rst_ovr; + assign rx_digital_rst_n_val = r_rx_digital_rst_n_val; + assign rx_analog_rst_n_val = r_rx_analog_rst_n_val; +end +else begin + assign rx_rst_ovr = 1'b0; + assign rx_digital_rst_n_val = 1'b0; + assign rx_analog_rst_n_val = 1'b0; +end +endgenerate + +assign rd_rstctl[AV_XR_RSTCTL_TX_RST_OVR_OFST ] = tx_rst_ovr; +assign rd_rstctl[AV_XR_RSTCTL_TX_DIGITAL_RST_N_VAL_OFST] = tx_digital_rst_n_val; +assign rd_rstctl[AV_XR_RSTCTL_RX_RST_OVR_OFST ] = rx_rst_ovr; +assign rd_rstctl[AV_XR_RSTCTL_RX_DIGITAL_RST_N_VAL_OFST] = rx_digital_rst_n_val; +assign rd_rstctl[AV_XR_RSTCTL_RX_ANALOG_RST_N_VAL_OFST ] = rx_analog_rst_n_val; +assign rd_rstctl[AV_XR_RSTCTL_UNUSED_OFST+:AV_XR_RSTCTL_UNUSED_LEN] + = {AV_XR_RSTCTL_UNUSED_LEN{1'b0}}; + +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_custom_native.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_custom_native.sv new file mode 100644 index 0000000..71f4c63 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_custom_native.sv @@ -0,0 +1,866 @@ +// (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 + +import altera_xcvr_functions::*; + +module av_xcvr_custom_native #( + parameter device_family = "Arria V", // (Arria V) + parameter protocol_hint = "basic", // (basic, gige, cpri) + parameter operation_mode = "Duplex", // (TX, RX, Duplex) + parameter lanes = 1, // (1+) + parameter bonded_group_size = 1, // (1,lanes) + parameter pma_bonding_mode = "x1", // (x1, xN) + parameter pcs_pma_width = 8, //legal value: 8,10,16,20 + parameter ser_base_factor = 8, // (8,10) + parameter ser_words = 1, // (1,2,4) + parameter data_rate = "1250 Mbps", + parameter base_data_rate = "0 Mbps", // (PLL Rate) - must be (data_rate * 1,2,4,or8) + + //tx bitslip + parameter tx_bitslip_enable = "false", + + //optional coreclks + parameter tx_use_coreclk = "false", + parameter rx_use_coreclk = "false", + parameter en_synce_support = 0, //expose CDR ref-clk in this mode + + //Phase compensation FIFO + parameter std_tx_pcfifo_mode = "low_latency", + parameter std_rx_pcfifo_mode = "low_latency", + + //8B10B + parameter use_8b10b = "false", // ("false", "true") + parameter use_8b10b_manual_control = "false", // ("false", "true") + + //Word Aligner + parameter word_aligner_mode = "bitslip", // (bitslip, sync state machine, manual, deterministic_latency) + parameter word_aligner_state_machine_datacnt = 0, // (0 - 256) + parameter word_aligner_state_machine_errcnt = 0, // (0 - 256) + parameter word_aligner_state_machine_patterncnt = 0, // (0 - 256) + parameter word_aligner_pattern_length = 7, + parameter word_align_pattern = "0000000000", + parameter run_length_violation_checking = 0, // (0, 1+) + + //RM FIFO + parameter use_rate_match_fifo = 0, // (0,1) + parameter rate_match_pattern1 = "00000000000000000000", + parameter rate_match_pattern2 = "00000000000000000000", + + //Byte Ordering Block + parameter byte_order_mode = "None", // (None, Sync state machine, PLD control) + parameter byte_order_pattern = "0", + parameter byte_order_pad_pattern = "0", + + //Hidden parameter to enable 0ppm legality bypass + parameter coreclk_0ppm_enable = "false", + + //PLL + parameter pll_refclk_cnt = 1, // Number of reference clocks + parameter pll_refclk_freq = "125 MHz", // Frequency of each reference clock + parameter pll_refclk_select = "0", // Selects the initial reference clock for each PLL + parameter cdr_refclk_select = 0, // Selects the initial reference clock for all RX CDR PLLs + parameter plls = 1, // (1+) + parameter pll_feedback_path = "no_compensation", //no_compensation, tx_clkout + parameter pll_type = "AUTO", // PLL type for each PLL + parameter pll_select = 0, // Selects the initial PLL + parameter pll_reconfig = 0, // (0,1) 0-Disable PLL reconfig, 1-Enable PLL reconfig + parameter pll_external_enable = 0, // (0,1) 0-Disable external TX PLL, 1-Enable external + + parameter starting_channel_number = 0, // (0+) + + //Channel Interface Reconfiguration + parameter channel_interface = 0, //legal value: (0,1) 1-Enable channel reconfiguration + + //low latency mode - PMA+ + parameter low_latency_mode = "false" + ) ( + //input from reset controller + input wire tx_analogreset, // for tx pma + input wire [((bonded_group_size != 1) ? 1 : lanes)*plls-1:0] pll_powerdown, + input wire [lanes-1:0] tx_digitalreset, + input wire [lanes-1:0] rx_analogreset, // for rx pma + input wire [lanes-1:0] rx_digitalreset, // for rx pcs + // Calibration busy signals + output wire [lanes-1:0] tx_cal_busy, + output wire [lanes-1:0] rx_cal_busy, + + //clk signal + input wire [pll_refclk_cnt-1:0] pll_ref_clk, + input wire cdr_ref_clk, // used only in SyncE mode + input tri0 [lanes - 1 : 0] tx_coreclkin, + input tri0 [lanes - 1 : 0] rx_coreclkin, + input wire [(plls*lanes)- 1 : 0] ext_pll_clk, // clkout from external PLL + + + //data ports + input wire [(channel_interface? 44: ser_base_factor*ser_words)*lanes-1:0] tx_parallel_data, + output wire [(channel_interface? 64: ser_base_factor*ser_words)*lanes-1:0] rx_parallel_data, + input wire [ser_words*lanes-1:0] tx_datak, + output wire [ser_words*lanes-1:0] rx_datak, + input tri0 [ser_words*lanes-1:0] tx_forcedisp, + input wire [ser_words*lanes-1:0] tx_dispval, + input wire [lanes-1:0] rx_enabyteord, + + input wire [lanes-1:0] rx_serial_data, + output wire [lanes-1:0] tx_serial_data, + + //clock outputs + output wire [(lanes/bonded_group_size)-1:0] tx_clkout, + output wire [lanes-1:0] rx_clkout, + output wire [lanes-1:0] rx_recovered_clk, + + //control ports + input tri0 [lanes-1:0] tx_forceelecidle, + input tri0 [lanes-1:0] tx_invpolarity, + input tri0 [lanes*5-1:0] tx_bitslipboundaryselect, + + input tri0 [lanes-1:0] rx_invpolarity, + input tri0 [lanes-1:0] rx_seriallpbken, + input tri0 [lanes-1:0] rx_set_locktodata, + input tri0 [lanes-1:0] rx_set_locktoref, + input tri0 [lanes-1:0] rx_enapatternalign, + input tri0 [lanes-1:0] rx_bitslip, + input tri0 [lanes-1:0] rx_bitreversalenable, + input tri0 [lanes-1:0] rx_bytereversalenable, + input tri0 [lanes-1:0] rx_a1a2size, + + output wire [lanes-1:0] rx_rlv, + output wire [ser_words*lanes-1:0] rx_patterndetect, + output wire [ser_words*lanes-1:0] rx_syncstatus, + output wire [lanes*5-1:0] rx_bitslipboundaryselectout, + output wire [ser_words*lanes-1:0] rx_errdetect, + output wire [ser_words*lanes-1:0] rx_disperr, + output wire [ser_words*lanes-1:0] rx_runningdisp, + output wire [lanes-1:0] rx_rmfifofull, + output wire [lanes-1:0] rx_rmfifoempty, + output wire [ser_words*lanes-1:0] rx_rmfifodatainserted, + output wire [ser_words*lanes-1:0] rx_rmfifodatadeleted, + output wire [ser_words*lanes-1:0] rx_a1a2sizeout, + + output wire [lanes-1:0] rx_is_lockedtoref, + output wire [lanes-1:0] rx_signaldetect, + output wire [lanes-1:0] rx_is_lockedtodata, + output wire [plls-1 :0] pll_locked, + + output wire [lanes-1:0] rx_phase_comp_fifo_error, + output wire [lanes-1:0] tx_phase_comp_fifo_error, + + // per-lane outputs + output wire [lanes-1:0] rx_byteordflag, + +// input wire [get_custom_reconfig_to_width ("Arria V",operation_mode,lanes,plls,bonded_group_size,"","")-1:0] reconfig_to_xcvr, +// output wire [get_custom_reconfig_from_width("Arria V",operation_mode,lanes,plls,bonded_group_size,"","")-1:0] reconfig_from_xcvr, + + input wire [get_custom_reconfig_to_width ("Arria V",operation_mode,lanes,((pll_external_enable == 1)? 0: plls),bonded_group_size,"","")-1:0] reconfig_to_xcvr, + output wire [get_custom_reconfig_from_width("Arria V",operation_mode,lanes,((pll_external_enable == 1)? 0: plls),bonded_group_size,"","")-1:0] reconfig_from_xcvr + +); + +import altera_xcvr_functions::*; + +// Reconfig parameters +localparam w_bundle_to_xcvr = W_S5_RECONFIG_BUNDLE_TO_XCVR; +localparam w_bundle_from_xcvr = W_S5_RECONFIG_BUNDLE_FROM_XCVR; +//localparam reconfig_interfaces = altera_xcvr_functions::get_custom_reconfig_interfaces("Arria V",operation_mode,lanes,plls,bonded_group_size); +localparam reconfig_interfaces = altera_xcvr_functions::get_custom_reconfig_interfaces("Arria V",operation_mode,lanes,(pll_external_enable ? 0 : plls),bonded_group_size); + +// RBC checks +localparam rbc_all_protocol_hint = "(basic,gige,cpri)"; +localparam fnl_protocol_hint = (protocol_hint == "basic") ? "basic" : + (protocol_hint == "gige") ? "gige" : + (protocol_hint == "cpri") ? ((word_aligner_mode=="manual")? "cpri_rx_tx":"cpri") ://cpri_rx_tx is the legacy StratixIV CPRI + protocol_hint; + +localparam prot_mode = fnl_protocol_hint; + + +localparam dummy_wa_pd_data = m_str_to_bin(word_align_pattern); +localparam [7:0] dummy_wa_sm_datacnt = word_aligner_state_machine_datacnt [7:0]; +localparam [6:0] dummy_wa_sm_errcnt = word_aligner_state_machine_errcnt [6:0]; +localparam [7:0] dummy_wa_sm_patterncnt = word_aligner_state_machine_patterncnt [7:0]; + +localparam tmp_bo_pat = m_str_to_bin(byte_order_pattern); +localparam bo_pat = tmp_bo_pat[19:0]; + +localparam tmp_bo_pad_pat = m_str_to_bin(byte_order_pad_pattern); +localparam bo_pad_pat = tmp_bo_pad_pat[9:0]; + +localparam tmp_rm_pat2 = m_str_to_bin(rate_match_pattern2); +localparam rm_pat2 = tmp_rm_pat2[19:0]; + +localparam tmp_rm_pat1 = m_str_to_bin(rate_match_pattern1); +localparam rm_pat1 = tmp_rm_pat1[19:0]; + +//localparam time data_rate_int = str2hz(data_rate); // data rate in Hz. Must use time unit since its a 64-bit unsigned int +`define data_rate_int (str2hz(data_rate)/1000000) // data rate in Hz. Must use time unit since its a 64-bit unsigned int +//`define half_data_rate string'(hz2str(`data_rate_int/2)) + +// Default base data rate to data rate if not specified +localparam [MAX_STRS*MAX_CHARS*8-1:0] INT_BASE_DATA_RATE = (get_value_at_index(0, base_data_rate) == "0 Mbps") ? data_rate : base_data_rate; +localparam INT_TX_CLK_DIV = str2hz(get_value_at_index(pll_select, INT_BASE_DATA_RATE)) / str2hz(data_rate); + +localparam deser_factor = ser_base_factor * ser_words; + +localparam pcs_double_width = (deser_factor == 32 || deser_factor == 40)? "true" + : (deser_factor == 8 || deser_factor == 10)? "false" + : ((pcs_pma_width == 8 || pcs_pma_width == 10) && deser_factor == 16)? "true" + : (pcs_pma_width == 10 && deser_factor == 20)? "true" + : "false"; + +localparam pcs_param_pma_dw = (pcs_pma_width == 8) ? "eight_bit" + : (pcs_pma_width == 10) ? "ten_bit" + : (pcs_pma_width == 16) ? "sixteen_bit" + : (pcs_pma_width == 20) ? "twenty_bit" + : "invalid"; + +localparam run_length_resolution = (pcs_pma_width == 8)? 4 + : (pcs_pma_width == 10)? 5 + : (pcs_pma_width == 16)? 8 + : (pcs_pma_width == 20)? 10 + : -1; + +localparam run_length_max = (pcs_pma_width == 8 || pcs_pma_width == 10)? run_length_resolution * 32 + : run_length_resolution * 64; + +localparam INT_RUN_LENGTH = run_length_violation_checking / run_length_resolution; + +localparam [5:0] dummy_run_length = (INT_RUN_LENGTH == run_length_max)? 6'b000000 : INT_RUN_LENGTH [5:0]; + +localparam pma_data_rate = data_rate; + +localparam SKIP_WORD= ((deser_factor == 16 || deser_factor == 20) && pcs_double_width == "true") ? 2 : 1; //for 3G PCS DW mode, skip a word + +localparam tx_data_bundle_size = 11; // TX PLD to PCS interface groups data and control in 11-bit bundles +localparam rx_data_bundle_size = 16; // RX PCS to PLD interface groups data and status in 16-bit bundles + +localparam INT_IN_PLD_SYNC_SM_EN = 1'b1; +localparam INT_WA_PATTERN_LENGTH = (word_aligner_mode == "bitslip" || low_latency_mode == "true" || protocol_hint == "cpri") ? "" + : (word_aligner_pattern_length == 7) ? ((prot_mode == "gige") ? "wa_pd_fixed_7_k28p5" : "wa_pd_7") + : (word_aligner_pattern_length == 8) ? ((pcs_pma_width == 8) ? "wa_pd_8_sw" : "wa_pd_8_dw") + : (word_aligner_pattern_length == 10) ? ((prot_mode == "gige") ? "wa_pd_fixed_10_k28p5" : "wa_pd_10") + : (word_aligner_pattern_length == 16) ? ((pcs_pma_width == 8)? "wa_pd_16_sw" : "wa_pd_16_dw") + : (word_aligner_pattern_length == 20) ? "wa_pd_20" + : (word_aligner_pattern_length == 32) ? "wa_pd_32" + : "wa_pd_7"; + +localparam INT_TX_PHASE_COMP_FIFO = (prot_mode == "cpri_rx_tx" || prot_mode == "cpri" || ((prot_mode == "basic" || prot_mode == "gige") && std_tx_pcfifo_mode == "register_fifo")) ? "register_fifo" + : "low_latency"; + +localparam INT_RX_PHASE_COMP_FIFO = (prot_mode == "cpri_rx_tx" || prot_mode == "cpri" || ((prot_mode == "basic" || prot_mode == "gige") && std_rx_pcfifo_mode == "register_fifo")) ? "register_fifo" + : "low_latency"; + +//tx localparam +/// TODO: this parameter should be validated against ser_base_factor. Changed the rule for now to compute it on the fly +localparam INT_TX_PCS_USE_DOUBLE_DATA = (pcs_double_width == "true") ? "en_bs_by_2" : "dis_bs"; + +//localparam for RX +localparam INT_RX_USE_LOCALREFCLK = 0; //temporary setting, 0=false, 1=true + +localparam INT_BO_MODE = (byte_order_mode == "PLD control") ? + ((pcs_pma_width == 8 || pcs_pma_width == 16) ? "en_pld_ctrl_eight_bit_bo" + : ((use_8b10b == "true")? "en_pld_ctrl_nine_bit_bo" : "en_pld_ctrl_ten_bit_bo")) + : (byte_order_mode == "sync state machine") ? + ((pcs_pma_width == 8 || pcs_pma_width == 16) ? "en_pcs_ctrl_eight_bit_bo" + : ((use_8b10b == "true")? "en_pcs_ctrl_nine_bit_bo" : "en_pcs_ctrl_ten_bit_bo")) + : "dis_bo"; + +localparam INT_SYMBOL_SWAP = ((prot_mode == "basic")&&(pcs_pma_width == 16 || pcs_pma_width == 20))? "en_symbol_swap" : "dis_symbol_swap"; + +localparam INT_RUN_LENGTH_EN = (pcs_param_pma_dw == "eight_bit" || pcs_param_pma_dw == "ten_bit") ? "en_runlength_sw" : "en_runlength_dw"; +localparam INT_RX_CLK1_MUX_SELECT = "rcvd_clk_clk1"; +localparam INT_RX_CLK2_MUX_SELECT = (use_rate_match_fifo == 0) ? "rcvd_clk_clk2" : "tx_pma_clock_clk2"; +localparam INT_RX_RECOVERED_CLK_MUX_SELECT = "rcvd_clk_rcvd_clk"; +localparam INT_RX_RD_CLK_MUX_SELECT = (protocol_hint == "cpri" ||((prot_mode == "basic" || prot_mode == "gige") && std_rx_pcfifo_mode == "register_fifo"))? "rx_clk":"pld_rx_clk"; + +localparam INT_WA_MODE = (word_aligner_mode == "manual") ? "auto_align_pld_ctrl" + : (word_aligner_mode == "sync_state_machine")? "sync_sm" + : (word_aligner_mode == "deterministic_latency")? "deterministic_latency" + : "bit_slip"; //bypass mode need to set to bit_slip + +localparam INT_RX_PCS_USE_DOUBLE_DATA = (pcs_double_width == "true") ? "en_bds_by_2" : "dis_bds"; +localparam INT_WA_PLD_CONTROLLED = (word_aligner_mode == "sync_state_machine"||word_aligner_mode == "deterministic_latency")? "dis_pld_ctrl" + : (pcs_pma_width == 8 || pcs_pma_width == 10) ? "pld_ctrl_sw" + : "rising_edge_sensitive_dw"; + +localparam INT_WA_SYNC_SM_CTRL = (prot_mode == "gige") ? "gige_sync_sm" + : (word_aligner_mode == "sync_state_machine") ? ((pcs_pma_width == 20) ? "dw_basic_sync_sm" : "sw_basic_sync_sm") + : "gige_sync_sm"; + +localparam INT_WA_DISP_ERR_FLAG = (use_8b10b == "true") ? "en_disp_err_flag" : "dis_disp_err_flag"; + +//8B10 +localparam INT_EN_8B_10B_ENC = (use_8b10b == "false") ? "dis_8b10b" : "en_8b10b_ibm"; +localparam INT_EN_8B_10B_DEC = (use_8b10b == "false") ? "dis_8b10b" : "en_8b10b_ibm"; +localparam INT_8B_10B_DISP_CTRL = (use_8b10b_manual_control == "false") ? "dis_disp_ctrl" : "en_disp_ctrl"; + + +localparam INT_SYMBOL_BO = (byte_order_mode == "PLD control" || byte_order_mode == "sync state machine") ? + (pcs_double_width == "true") ? + (pcs_pma_width == 16) ? "two_symbol_bo_eight_bit" + : (pcs_pma_width == 20 && use_8b10b == "true") ? "two_symbol_bo_nine_bit" + : (pcs_pma_width == 20 && use_8b10b == "false")? "two_symbol_bo_ten_bit" + : "donot_care_one_two_bo" + : "donot_care_one_two_bo" + : "donot_care_one_two_bo"; + +//TX BITSLIP +localparam INT_EN_TX_BITSLIP = (prot_mode == "gige") ? "dis_tx_bitslip" + : (tx_bitslip_enable == "true") ? "en_tx_bitslip" + : "dis_tx_bitslip"; + +//RM FIFO +localparam INT_RM_FIFO_MODE = (use_rate_match_fifo == 1) ? + (prot_mode == "gige") ? "gige_rm" + : (pcs_pma_width == 20 || pcs_pma_width == 16) ? "dw_basic_rm" + : "sw_basic_rm" + : "dis_rm"; + +localparam INT_RX_ENABLE = (operation_mode == "Rx" || operation_mode == "RX" + || operation_mode == "Duplex" || operation_mode == "DUPLEX") ? 1 : 0; +localparam INT_TX_ENABLE = (operation_mode == "Tx" || operation_mode == "TX" + || operation_mode == "Duplex" || operation_mode == "DUPLEX") ? 1 : 0; + +localparam INT_RX_POL_INV = "en_pol_inv"; +localparam INT_TX_POL_INV = "enable_polinv"; + +localparam INT_RX_BIT_REV = (prot_mode == "basic") ? "en_bit_reversal" : "dis_bit_reversal"; + +localparam INT_WA_DET_LATENCY_SYNC_STATUS = (prot_mode == "cpri")? "":""; //valid setting:assert_sync_status_imm,assert_sync_status_non_imm[default] for CPRI +localparam INT_WA_CLK_SLIP_SPACING = (prot_mode == "cpri")? "":""; //valid setting:min_clk_slip_spacing[default],user_programmable_clk_slip_spacing +localparam INT_RX_PCS_PMA_IF_PROT_MODE = (prot_mode == "cpri")? "cpri_8g": "other_protocols"; +localparam INT_CLKSLIP_SEL = (prot_mode == "cpri")? "slip_eight_g_pcs": "pld"; //legal value: pld|slip_eight_g_pcs +localparam INT_DESER_ENABLE_BIT_SLIP = (word_aligner_mode == "deterministic_latency")? "true": "false"; //legal value: true|false + +//PLD-PCS wires +// used data bundle width is [tx_data_bundle_size * ser_words * lanes - 1: 0], but declare 10G max size (64b/lane) +tri0 [44 * lanes - 1: 0] tx_datain_from_pld; +//conduit +wire [lanes - 1 : 0] tx_coreclk_in; + +//wires for RX +// used data bundle width is [rx_data_bundle_size * ser_words * lanes - 1: 0], but declare max size +tri0 [rx_data_bundle_size * 4 * lanes - 1: 0] rx_dataout_to_pld; +wire [lanes - 1 : 0] rx_coreclk_in; +wire [lanes - 1 : 0] dataout_from_pma; +wire [lanes - 1 : 0] int_pcfifoempty; +wire [lanes - 1 : 0] int_pcfifofull; + +//wires for TX +wire [lanes - 1 : 0] int_phfifounderflow; +wire [lanes - 1 : 0] int_phfifooverflow; +wire [lanes - 1 : 0] tx_clkout_to_pld; +wire [(plls*lanes)-1:0] pll_out_clk; + +//wire for PLL +wire [plls - 1 : 0] pll_locked_wire [lanes-1:0]; +wire [lanes - 1 : 0] pll_locked_xpos [plls-1:0]; + +//wire for master CGB +wire cpulse_master; +wire hclk_master; +wire lfclk_master; +wire [2 : 0] pclk_master; + +wire [lanes*plls-1:0] cgb_master_rstn; + +// Declare local merged versions of reconfig buses +wire [get_custom_reconfig_to_width ("Arria V",operation_mode,lanes,(pll_external_enable ? 0 : plls),bonded_group_size,"","")-1:0] rcfg_to_xcvr; +wire [get_custom_reconfig_from_width("Arria V",operation_mode,lanes,(pll_external_enable ? 0 : plls),bonded_group_size,"","")-1:0] rcfg_from_xcvr; + +// SYNCE +wire [bonded_group_size*pll_refclk_cnt-1:0] cdr_clock ; +// Parameter validation +initial begin + if(!is_in_legal_set(protocol_hint, rbc_all_protocol_hint)) begin + $display("Critical Warning: Parameter 'protocol_hint' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'. Using value '%s'", protocol_hint, rbc_all_protocol_hint, fnl_protocol_hint); + end + + if((bonded_group_size != lanes) && (bonded_group_size != 1)) begin + $display("Error: Parameter 'bonded_group_size' of instance '%m' has illegal value '%d' assigned to it. Valid parameter values are: '1' and '%d'.", bonded_group_size, lanes); + end +end +// End parameter validation + +genvar ig; // Iterator for generated loops +genvar jg; +genvar num_word; + +generate begin:gen + + // 1 bit of tx_clkout per lane when non-bonded, 1 bit of tx_clkout per instance when bonded + assign tx_clkout = tx_clkout_to_pld[(lanes/bonded_group_size) - 1 : 0]; + + // Connect reset for xN non-bonded mode Master CGB + assign cgb_master_rstn = (bonded_group_size == 1)? pll_powerdown : {(plls*lanes){1'b0}}; + + // One pll_locked output per logical PLL + for (ig=0; ig[plls][lanes] + for(jg=0; jg_xcvr ports to PLL only when using internal PLL + assign pll_rcfg_to_xcvr = rcfg_to_xcvr[(lanes+(plls*ig))*w_bundle_to_xcvr+:plls*w_bundle_to_xcvr]; + assign rcfg_from_xcvr[(lanes+(plls*ig))*w_bundle_from_xcvr+:plls*w_bundle_from_xcvr] = pll_rcfg_from_xcvr; + end + + av_xcvr_plls #( + .plls (plls ), + .pll_type (pll_type ), + .pll_reconfig (pll_reconfig ), + .pll_sel (pll_select ), + .refclks (pll_refclk_cnt ), + .reference_clock_frequency(pll_refclk_freq ), + .reference_clock_select (pll_refclk_select ), + .output_clock_datarate (INT_BASE_DATA_RATE ), + .feedback_clk (INT_FEEDBACK_CLK ), + .tx_clk_div (INT_TX_CLK_DIV ), + .data_rate (data_rate ), + .mode (pcs_pma_width ), + .pll_external_enable (pll_external_enable), + .enable_master_cgb ((num_bonded != 1)? 1 : 0) + ) tx_plls ( + // When using external PLLs, refclk port is repurposed to provide the external PLL clock input + .refclk (pll_external_enable ? ext_pll_clk[ig*plls+:plls] : pll_ref_clk ), + .rst (pll_powerdown[ig*plls+:plls] ), + .fbclk ({plls{tx_fbclk}} ), + .outclk (pll_out_clk [ig*plls+:plls] ), + .locked (pll_locked_wire[ig] ), + .fboutclk (pll_fb_clk ), + + //ports for master CGB + .cpulse_master (cpulse_master ), + .hclk_master (hclk_master ), + .lfclk_master (lfclk_master ), + .pclk_master (pclk_master ), + + // avalon MM native reconfiguration interfaces + .reconfig_to_xcvr (pll_rcfg_to_xcvr ), + .reconfig_from_xcvr (pll_rcfg_from_xcvr ) + + ); + end // block: gen_tx_plls + else + begin: gen_no_tx // TX disabled + assign pll_out_clk[ig*plls+:plls] = {plls{1'b0}}; + assign pll_locked_wire[ig] = {plls{1'b0}}; + end + end // block: gen_tx_plls + else begin:gen_pll_fanout + assign pll_out_clk[ig*plls+:plls] = pll_out_clk[0+:plls]; // Fanout pll_out_clk for xN bonding + assign pll_locked_wire[ig] = pll_locked_wire[0]; // Fanout pll_locked for xN bonded mode + end + + +// use cdr_ref_clk for syncE mode and pll_ref_clk otherwise + if (en_synce_support) begin : SYNCE + assign cdr_clock = {num_bonded{cdr_ref_clk}}; + end else begin : NO_SYNCE + assign cdr_clock = {num_bonded{pll_ref_clk}}; + end + if((ig % bonded_group_size) == 0) begin:gen_bonded_group + // Create native transceiver interface + av_xcvr_native #( + .device_family (device_family ), + .rx_enable (INT_RX_ENABLE ), + .tx_enable (INT_TX_ENABLE ), + .bonded_lanes (num_bonded ), + .pma_prot_mode (prot_mode ), + .pma_mode (pcs_pma_width ), // (8,10,16,20,32,40,64,80) Serialization factor + .base_data_rate (base_data_rate ), + .pma_data_rate (pma_data_rate ), // Serial data rate in bits-per-second + .cdr_reconfig (pll_reconfig ), + .cdr_reference_clock_frequency (pll_refclk_freq ), + .cdr_refclk_cnt (pll_refclk_cnt ), + .cdr_refclk_sel (cdr_refclk_select ), + .tx_clk_div (INT_TX_CLK_DIV ), + .pma_bonding_mode (pma_bonding_mode ), + .external_master_cgb ((num_bonded != 1)? 1:0), + .plls (plls ), + .pll_sel (pll_select ), + .deser_enable_bit_slip (INT_DESER_ENABLE_BIT_SLIP ), + + // PCS + .enable_8g_rx (INT_RX_ENABLE ? "true" : "false"), + .enable_8g_tx (INT_TX_ENABLE ? "true" : "false"), + .enable_dyn_reconfig ("false"), + .enable_gen12_pipe ("false"), + + // parameters for arriav_hssi_8g_rx_pcs + .pcs8g_rx_auto_error_replacement("" ), + .pcs8g_rx_bit_reversal (INT_RX_BIT_REV ), + .pcs8g_rx_bo_pad (bo_pad_pat ), + .pcs8g_rx_bo_pattern (bo_pat ), + .pcs8g_rx_byte_deserializer (INT_RX_PCS_USE_DOUBLE_DATA ), + .pcs8g_rx_byte_order (INT_BO_MODE ), + .pcs8g_rx_clkcmp_pattern_n (rm_pat2 ), + .pcs8g_rx_clkcmp_pattern_p (rm_pat1 ), + .pcs8g_rx_deskew_prog_pattern_only("dis_deskew_prog_pat_only"), // TODO - had to add + .pcs8g_rx_dw_one_or_two_symbol_bo (INT_SYMBOL_BO ), + .pcs8g_rx_eightb_tenb_decoder (INT_EN_8B_10B_DEC ), + .pcs8g_rx_err_flags_sel ("" ), + .pcs8g_rx_mask_cnt (10'h320 ), + .pcs8g_rx_pcs_bypass ((low_latency_mode == "true")? "en_pcs_bypass" : "dis_pcs_bypass"), + .pcs8g_rx_phase_compensation_fifo(INT_RX_PHASE_COMP_FIFO ), + .pcs8g_rx_pma_dw (pcs_param_pma_dw ), + .pcs8g_rx_polarity_inversion (INT_RX_POL_INV ), +// .pcs8g_rx_polinv_8b10b_dec ("en_polinv_8b10b_dec" ), + .pcs8g_rx_prot_mode (prot_mode ), + .pcs8g_rx_rate_match (INT_RM_FIFO_MODE ), +// .pcs8g_rx_re_bo_on_wa (I), + .pcs8g_rx_runlength_check (INT_RUN_LENGTH_EN ), + .pcs8g_rx_runlength_val (dummy_run_length ), + .pcs8g_rx_rx_clk1 (INT_RX_CLK1_MUX_SELECT ), + .pcs8g_rx_rx_clk2 (INT_RX_CLK2_MUX_SELECT ), + .pcs8g_rx_rx_rcvd_clk (INT_RX_RECOVERED_CLK_MUX_SELECT ), + .pcs8g_rx_rx_rd_clk (INT_RX_RD_CLK_MUX_SELECT ), + .pcs8g_rx_sup_mode ("user_mode" ), + .pcs8g_rx_symbol_swap (INT_SYMBOL_SWAP ), + .pcs8g_rx_wa_boundary_lock_ctrl (INT_WA_MODE ), + .pcs8g_rx_wa_disp_err_flag (INT_WA_DISP_ERR_FLAG ), + .pcs8g_rx_wa_pd (INT_WA_PATTERN_LENGTH ), + .pcs8g_rx_wa_pd_data (dummy_wa_pd_data ), + .pcs8g_rx_wa_pld_controlled (INT_WA_PLD_CONTROLLED ), + .pcs8g_rx_wa_renumber_data (dummy_wa_sm_errcnt), + .pcs8g_rx_wa_rgnumber_data (dummy_wa_sm_datacnt), + .pcs8g_rx_wa_rknumber_data (dummy_wa_sm_patterncnt), + .pcs8g_rx_wa_sync_sm_ctrl (INT_WA_SYNC_SM_CTRL ), + .pcs8g_rx_wa_det_latency_sync_status_beh ( INT_WA_DET_LATENCY_SYNC_STATUS ), + .pcs8g_rx_wa_clk_slip_spacing ( INT_WA_CLK_SLIP_SPACING ), + + .rx_pld_pcs_if_is_8g_0ppm (coreclk_0ppm_enable ), + + // parameters for arriav_hssi_8g_tx_pcs + .pcs8g_tx_bit_reversal ("dis_bit_reversal" ), + .pcs8g_tx_byte_serializer (INT_TX_PCS_USE_DOUBLE_DATA ), + .pcs8g_tx_eightb_tenb_disp_ctrl (INT_8B_10B_DISP_CTRL ), + .pcs8g_tx_eightb_tenb_encoder (INT_EN_8B_10B_ENC ), + .pcs8g_tx_pcs_bypass ((low_latency_mode == "true")? "en_pcs_bypass" : "dis_pcs_bypass"), + .pcs8g_tx_phase_compensation_fifo(INT_TX_PHASE_COMP_FIFO ), + .pcs8g_tx_pma_dw (pcs_param_pma_dw ), + .pcs8g_tx_polarity_inversion (INT_TX_POL_INV ), + .pcs8g_tx_prot_mode (prot_mode ), + .pcs8g_tx_sup_mode ("user_mode" ), + .pcs8g_tx_symbol_swap ("dis_symbol_swap" ), + .pcs8g_tx_tx_bitslip (INT_EN_TX_BITSLIP ), +// .pcs8g_tx_tx_compliance_controlled_disparity(), + + .tx_pld_pcs_if_is_8g_0ppm (coreclk_0ppm_enable ), + + .rx_pcs_pma_if_prot_mode (INT_RX_PCS_PMA_IF_PROT_MODE ), + .rx_pcs_pma_if_selectpcs ("eight_g_pcs" ), + .rx_pcs_pma_if_clkslip_sel (INT_CLKSLIP_SEL ), + + +// .com_pld_pcs_if_hrdrstctrl_en_cfgusr ("hrst_en_cfgusr" ), // hrst_dis_cfgusr|hrst_en_cfgusr + // parameters for arriav_hssi_common_pcs_pma_interface + .com_pcs_pma_if_func_mode ("eightg_only_pld" ), + .com_pcs_pma_if_prot_mode ("other_protocols" ), + .com_pcs_pma_if_sup_mode ("user_mode" ), + .com_pcs_pma_if_selectpcs ("eight_g_pcs" ), + .com_pcs_pma_if_force_freqdet ("force_freqdet_dis" ), + .com_pcs_pma_if_ppmsel ("ppmsel_1000" ), + .com_pcs_pma_if_auto_speed_ena ("dis_auto_speed_ena" ) + ) av_xcvr_native_inst( + // PMA ports + // TX/RX ports + .seriallpbken (rx_seriallpbken [ig +: num_bonded] ), // 1 = enable serial loopback + // RX ports + .rx_crurstn (~rx_analogreset [ig +: num_bonded] ), // TODO - investigate resets + .rx_datain (rx_serial_data [ig +: num_bonded] ), // RX serial data input + .rx_cdr_ref_clk (cdr_clock ), // Reference clock for CDR + .rx_ltd (rx_set_locktodata [ig +: num_bonded] ), // Force lock-to-data stream (TODO - active low) + .rx_is_lockedtoref(rx_is_lockedtoref [ig +: num_bonded] ), // Indicates lock to reference clock + .rx_is_lockedtodata(rx_is_lockedtodata[ig +: num_bonded] ), + .rx_clkdivrx (rx_recovered_clk [ig +: num_bonded] ), + + // TX ports + .tx_rxdetclk (/*TODO*/ ), // Clock for detection of downstream receiver (125MHz ?) + .tx_dataout (tx_serial_data [ig +: num_bonded] ), // TX serial data output + .tx_rstn (~tx_analogreset ), // TODO - Examine resets + .tx_rstn_cgb_master (~cgb_master_rstn [ig*plls+:(num_bonded*plls)]), + .tx_ser_clk (pll_out_clk [ig*plls+:(num_bonded*plls)]), // High-speed serial clocks from PLL + .tx_cal_busy (tx_cal_busy [ig +: num_bonded] ), + .rx_cal_busy (rx_cal_busy [ig +: num_bonded] ), + .tx_cpulsein ({num_bonded{cpulse_master}} ), + .tx_hclkin ({num_bonded{hclk_master }} ), + .tx_lfclkin ({num_bonded{lfclk_master }} ), + .tx_pclkin ({num_bonded{pclk_master }} ), + + //PCS ports + .in_agg_align_status (/*unused*/ ), + .in_agg_align_status_sync_0 (/*unused*/ ), + .in_agg_align_status_sync_0_top_or_bot(/*unused*/ ), + .in_agg_align_status_top_or_bot (/*unused*/ ), + .in_agg_cg_comp_rd_d_all (/*unused*/ ), + .in_agg_cg_comp_rd_d_all_top_or_bot (/*unused*/ ), + .in_agg_cg_comp_wr_all (/*unused*/ ), + .in_agg_cg_comp_wr_all_top_or_bot (/*unused*/ ), + .in_agg_del_cond_met_0 (/*unused*/ ), + .in_agg_del_cond_met_0_top_or_bot (/*unused*/ ), + .in_agg_en_dskw_qd (/*unused*/ ), + .in_agg_en_dskw_qd_top_or_bot (/*unused*/ ), + .in_agg_en_dskw_rd_ptrs (/*unused*/ ), + .in_agg_en_dskw_rd_ptrs_top_or_bot (/*unused*/ ), + .in_agg_fifo_ovr_0 (/*unused*/ ), + .in_agg_fifo_ovr_0_top_or_bot (/*unused*/ ), + .in_agg_fifo_rd_in_comp_0 (/*unused*/ ), + .in_agg_fifo_rd_in_comp_0_top_or_bot (/*unused*/ ), + .in_agg_fifo_rst_rd_qd (/*unused*/ ), + .in_agg_fifo_rst_rd_qd_top_or_bot (/*unused*/ ), + .in_agg_insert_incomplete_0 (/*unused*/ ), + .in_agg_insert_incomplete_0_top_or_bot(/*unused*/ ), + .in_agg_latency_comp_0 (/*unused*/ ), + .in_agg_latency_comp_0_top_or_bot (/*unused*/ ), + .in_agg_rcvd_clk_agg (/*unused*/ ), + .in_agg_rcvd_clk_agg_top_or_bot (/*unused*/ ), + .in_agg_rx_control_rs (/*unused*/ ), + .in_agg_rx_control_rs_top_or_bot (/*unused*/ ), + .in_agg_rx_data_rs (/*unused*/ ), + .in_agg_rx_data_rs_top_or_bot (/*unused*/ ), + .in_agg_test_so_to_pld_in (/*unused*/ ), + .in_agg_testbus (/*unused*/ ), + .in_agg_tx_ctl_ts (/*unused*/ ), + .in_agg_tx_ctl_ts_top_or_bot (/*unused*/ ), + .in_agg_tx_data_ts (/*unused*/ ), + .in_agg_tx_data_ts_top_or_bot (/*unused*/ ), + + .in_emsip_com_in (/*unused*/ ), + .in_emsip_rx_special_in (/*unused*/ ), + .in_emsip_tx_in (/*unused*/ ), + .in_emsip_tx_special_in (/*unused*/ ), + + .in_pld_8g_a1a2_size (rx_a1a2size [ig +: num_bonded] ), + .in_pld_8g_bitloc_rev_en (rx_bitreversalenable [ig +: num_bonded] ), + .in_pld_8g_bitslip (rx_bitslip [ig +: num_bonded] ), + .in_pld_8g_byte_rev_en (rx_bytereversalenable[ig +: num_bonded] ), + .in_pld_8g_bytordpld (rx_enabyteord [ig +: num_bonded] ), + .in_pld_8g_cmpfifourst_n (/*unused*/ ), // TODO + .in_pld_8g_encdt (rx_enapatternalign [ig +: num_bonded] ), + .in_pld_8g_phfifourst_rx_n (/*unused*/ ), // TODO + .in_pld_8g_phfifourst_tx_n (/*unused*/ ), // TODO + .in_pld_8g_pld_rx_clk (rx_coreclk_in [ig +: num_bonded] ), + .in_pld_8g_pld_tx_clk (tx_coreclk_in [ig +: num_bonded] ), + .in_pld_8g_polinv_rx (rx_invpolarity [ig +: num_bonded] ), + .in_pld_8g_polinv_tx (tx_invpolarity [ig +: num_bonded] ), + .in_pld_8g_powerdown (/*unused*/ ), + .in_pld_8g_prbs_cid_en (/*unused*/ ), + .in_pld_8g_rddisable_tx ({num_bonded{1'b0}} ), + .in_pld_8g_rdenable_rmf ({num_bonded{1'b0}} ), + .in_pld_8g_rdenable_rx (/*unused*/ ), + .in_pld_8g_refclk_dig (/*unused*/ ), + .in_pld_8g_refclk_dig2 (/*unused*/ ), + .in_pld_8g_rev_loopbk ({num_bonded{1'b0}} ), + .in_pld_8g_rxpolarity (/*unused*/ ), + .in_pld_8g_rxurstpcs_n (~rx_digitalreset [ig +: num_bonded] ), + //.in_pld_8g_tx_blk_start ({num_bonded{4'b0000}} ), + .in_pld_8g_tx_boundary_sel (tx_bitslipboundaryselect [(ig*5) +: (num_bonded*5)] ), + .in_pld_8g_tx_data_valid ({num_bonded{4'b0000}} ), + //.in_pld_8g_tx_sync_hdr ({num_bonded{2'b00}} ), + .in_pld_8g_txdeemph (/*unused*/ ), + .in_pld_8g_txdetectrxloopback (/*unused*/ ), + .in_pld_8g_txelecidle (tx_forceelecidle [ig +: num_bonded] ), + .in_pld_8g_txmargin (/*unused*/ ), + .in_pld_8g_txswing (/*unused*/ ), + .in_pld_8g_txurstpcs_n (~tx_digitalreset [ig +: num_bonded] ), + .in_pld_8g_wrdisable_rx ({num_bonded{1'b0}} ), + .in_pld_8g_wrenable_rmf ({num_bonded{1'b0}} ), + .in_pld_8g_wrenable_tx ({num_bonded{1'b0}} ), + + .in_pld_agg_refclk_dig (/*unused*/ ), + + .in_pld_eidleinfersel (/*unused*/ ), + + .in_pld_ltr (rx_set_locktoref [ig +: num_bonded] ), + .in_pld_partial_reconfig_in ({num_bonded{1'b1}} ), /// NOTE: active high + .in_pld_pcs_pma_if_refclk_dig (/*unused*/ ), + .in_pld_rate (/*unused*/ ), + .in_pld_reserved_in (/*unused*/ ), + .in_pld_rx_clk_slip_in ({num_bonded{1'b0}} ), + .in_pld_rxpma_rstb_in (~rx_analogreset [ig +: num_bonded] ), + .in_pld_scan_mode_n ({num_bonded{1'b1}} ), /// NOTE: active high + .in_pld_scan_shift_n ({num_bonded{1'b1}} ), + .in_pld_sync_sm_en ({num_bonded{INT_IN_PLD_SYNC_SM_EN}} ), + .in_pld_tx_data (tx_datain_from_pld[44*ig +: num_bonded*44]), + + .in_pma_hclk (/*unused*/ ), + .in_pma_reserved_in (/*unused*/ ), + .in_pma_rx_freq_tx_cmu_pll_lock_in ({num_bonded{1'b0}} ), + + .out_agg_align_det_sync (/*unused*/ ), + .out_agg_align_status_sync (/*unused*/ ), + .out_agg_cg_comp_rd_d_out (/*unused*/ ), + .out_agg_cg_comp_wr_out (/*unused*/ ), + .out_agg_dec_ctl (/*unused*/ ), + .out_agg_dec_data (/*unused*/ ), + .out_agg_dec_data_valid (/*unused*/ ), + .out_agg_del_cond_met_out (/*unused*/ ), + .out_agg_fifo_ovr_out (/*unused*/ ), + .out_agg_fifo_rd_out_comp (/*unused*/ ), + .out_agg_insert_incomplete_out (/*unused*/ ), + .out_agg_latency_comp_out (/*unused*/ ), + .out_agg_rd_align (/*unused*/ ), + .out_agg_rd_enable_sync (/*unused*/ ), + .out_agg_refclk_dig (/*unused*/ ), + .out_agg_running_disp (/*unused*/ ), + .out_agg_rxpcs_rst (/*unused*/ ), + .out_agg_scan_mode_n (/*unused*/ ), + .out_agg_scan_shift_n (/*unused*/ ), + .out_agg_sync_status (/*unused*/ ), + .out_agg_tx_ctl_tc (/*unused*/ ), + .out_agg_tx_data_tc (/*unused*/ ), + .out_agg_txpcs_rst (/*unused*/ ), + + .out_emsip_com_clk_out (/*unused*/ ), + .out_emsip_com_out (/*unused*/ ), + .out_emsip_rx_out (/*unused*/ ), + .out_emsip_rx_special_out (/*unused*/ ), + .out_emsip_tx_special_out (/*unused*/ ), + + .out_pld_8g_a1a2_k1k2_flag (/*unused*/ ), + .out_pld_8g_align_status (/*unused*/ ), + .out_pld_8g_bistdone (/*unused*/ ), + .out_pld_8g_bisterr (/*unused*/ ), + .out_pld_8g_byteord_flag (rx_byteordflag [ig +: num_bonded] ), + .out_pld_8g_empty_rmf (rx_rmfifoempty [ig +: num_bonded] ), + .out_pld_8g_empty_rx (int_pcfifoempty [ig +: num_bonded] ), + .out_pld_8g_empty_tx (int_phfifounderflow [ig +: num_bonded] ), + .out_pld_8g_full_rmf (rx_rmfifofull [ig +: num_bonded] ), + .out_pld_8g_full_rx (int_pcfifofull [ig +: num_bonded] ), + .out_pld_8g_full_tx (int_phfifooverflow [ig +: num_bonded] ), + .out_pld_8g_phystatus (/*unused*/ ), + .out_pld_8g_rlv_lt (rx_rlv [ig +: num_bonded] ), + .out_pld_8g_rx_clk_out (rx_clkout [ig +: num_bonded] ), + .out_pld_8g_rx_data_valid (/*unused*/ ), + .out_pld_8g_rxelecidle (/*unused*/ ), + .out_pld_8g_rxstatus (/*unused*/ ), + .out_pld_8g_rxvalid (/*unused*/ ), + .out_pld_8g_signal_detect_out (rx_signaldetect [ig +: num_bonded] ), + .out_pld_8g_tx_clk_out (tx_clkout_to_pld [ig +: num_bonded] ), + .out_pld_8g_wa_boundary (rx_bitslipboundaryselectout[5*ig +: 5*num_bonded] ), + + .out_pld_clklow (/*unused*/ ), + .out_pld_fref (/*unused*/ ), + .out_pld_rx_data (rx_dataout_to_pld [4*rx_data_bundle_size*ig +: num_bonded*4*rx_data_bundle_size]), + + .out_pma_current_coeff (/*unused*/ ), + .out_pma_nfrzdrv (/*unused*/ ), + .out_pma_partial_reconfig (/*unused*/ ), + .out_pma_reserved_out (/*unused*/ ), + .out_pma_rx_clk_out (/*unused*/ ), + .out_pma_tx_clk_out (/*unused*/ ), + + // avalon MM native reconfiguration interfaces + .reconfig_to_xcvr (rcfg_to_xcvr [ig*w_bundle_to_xcvr+:num_bonded*w_bundle_to_xcvr] ), + .reconfig_from_xcvr (rcfg_from_xcvr [ig*w_bundle_from_xcvr+:num_bonded*w_bundle_from_xcvr]) + ); + end // block: gen_bonded_group + + + + //***************************************************************** + //*********************** TX assignments ************************** + assign tx_coreclk_in [ig] = (tx_use_coreclk == "true") ? tx_coreclkin[ig] : (bonded_group_size == 1)? tx_clkout_to_pld[ig] : tx_clkout_to_pld[ig/bonded_group_size]; + assign tx_phase_comp_fifo_error[ig] = int_phfifooverflow[ig] | int_phfifounderflow[ig]; + //********************* End TX assignments ************************ + //***************************************************************** + + //***************************************************************** + //*********************** RX assignments ************************** + assign rx_coreclk_in[ig] = (rx_use_coreclk == "true") ? rx_coreclkin[ig] + : (use_rate_match_fifo == 1) ? ((bonded_group_size == 1)? tx_clkout_to_pld[ig] : tx_clkout_to_pld[ig/bonded_group_size]) : rx_clkout[ig]; + assign rx_phase_comp_fifo_error[ig] = int_pcfifoempty[ig] | int_pcfifofull[ig]; + //********************* End TX assignments ************************ + //***************************************************************** + + //***************************************************************** + //*********************** PLL assignments ************************** + end // block: av_xcvr_native_insts +end // block: gen +endgenerate + +// Merge critical reconfig signals +sv_reconfig_bundle_merger #( + .reconfig_interfaces(reconfig_interfaces) +) av_reconfig_bundle_merger_inst ( + // Reconfig buses to/from reconfig controller + .rcfg_reconfig_to_xcvr (reconfig_to_xcvr ), + .rcfg_reconfig_from_xcvr(reconfig_from_xcvr ), + + // Reconfig buses to/from native xcvr + .xcvr_reconfig_to_xcvr (rcfg_to_xcvr ), + .xcvr_reconfig_from_xcvr(rcfg_from_xcvr ) +); + + +av_xcvr_data_adapter #( + .lanes (lanes ), //Number of lanes chosen by user. legal value: 1+ + .channel_interface (channel_interface), //legal value: (0,1) 1-Enable channel reconfiguration + .ser_base_factor (ser_base_factor ), // (8,10) + .ser_words (ser_words ), // (1,2,4) + .skip_word (SKIP_WORD ) // (1,2) +) av_xcvr_data_adapter_inst( + .tx_parallel_data (tx_parallel_data ), + .tx_datak (tx_datak ), + .tx_forcedisp (tx_forcedisp ), + .tx_dispval (tx_dispval ), + + .tx_datain_from_pld (tx_datain_from_pld ), + .rx_dataout_to_pld (rx_dataout_to_pld ), + + .rx_parallel_data (rx_parallel_data ), + .rx_datak (rx_datak ), + .rx_errdetect (rx_errdetect ), + .rx_syncstatus (rx_syncstatus ), + .rx_disperr (rx_disperr ), + .rx_patterndetect (rx_patterndetect ), + .rx_rmfifodatainserted(rx_rmfifodatainserted), + .rx_rmfifodatadeleted (rx_rmfifodatadeleted ), + .rx_runningdisp (rx_runningdisp ), + .rx_a1a2sizeout (rx_a1a2sizeout ) +); + +`undef data_rate_int +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_data_adapter.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_data_adapter.sv new file mode 100644 index 0000000..38d3420 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_data_adapter.sv @@ -0,0 +1,132 @@ +// (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 1ps/1ps + + +//************************************************************************************************************************ +// +// Wiring adapter for native data from PLD-PCS interface, to a form suitable for encoded or unencoded data +// +// +//************************************************************************************************************************ + +module av_xcvr_data_adapter #( + parameter lanes = 1, //Number of lanes chosen by user. legal value: 1+ + parameter channel_interface = 0, //legal value: (0,1) 1-Enable channel reconfiguration + parameter ser_base_factor = 8, // (8,10) + parameter ser_words = 1, // (1,2,4) + parameter skip_word = 1 // (1,2) +) ( + + input wire [(channel_interface? 44: ser_base_factor*ser_words)*lanes-1:0] tx_parallel_data, + input wire [ser_words*lanes -1:0] tx_datak, + input tri0 [ser_words*lanes -1:0] tx_forcedisp, + input wire [ser_words*lanes -1:0] tx_dispval, + + output tri0 [44*lanes -1:0] tx_datain_from_pld, + input tri0 [64*lanes -1:0] rx_dataout_to_pld, + + output wire [(channel_interface? 64: ser_base_factor*ser_words)*lanes-1:0] rx_parallel_data, + output wire [ser_words*lanes -1:0] rx_datak, + output wire [ser_words*lanes -1:0] rx_errdetect, + output wire [ser_words*lanes -1:0] rx_syncstatus, + output wire [ser_words*lanes -1:0] rx_disperr, + output wire [ser_words*lanes -1:0] rx_patterndetect, + output wire [ser_words*lanes -1:0] rx_rmfifodatainserted, + output wire [ser_words*lanes -1:0] rx_rmfifodatadeleted, + output wire [ser_words*lanes -1:0] rx_runningdisp, + output wire [ser_words*lanes -1:0] rx_a1a2sizeout +); + + localparam tx_data_bundle_size = 11; // TX PLD to PCS interface groups data and control in 11-bit bundles + localparam rx_data_bundle_size = 16; // RX PCS to PLD interface groups data and status in 16-bit bundles + + generate begin + genvar num_ch; + genvar num_word; + for (num_ch=0; num_ch < lanes; num_ch = num_ch + 1) begin:channel + + if (channel_interface == 0) begin + for (num_word=0; num_word < ser_words; num_word=num_word+1) begin:word + //*************************************************************** + //*********************** TX assignments ************************ + //With 8B/10B enabled, Tx datain from PLD to PCS has 8-bit data + 3 controls in 11-bit bundles + //For 1 lane, [7:0] = data + // [8] = k char + // [9] = force disparity + // [10] = disparity value (Tx Elec Idle for PIPE Gen1 & 2) + + assign tx_datain_from_pld[44*num_ch+num_word*tx_data_bundle_size*skip_word +: ser_base_factor] = tx_parallel_data[ser_base_factor*ser_words*num_ch+num_word*ser_base_factor +: ser_base_factor]; + + if (ser_base_factor == 8) begin + assign tx_datain_from_pld[44*num_ch+num_word*tx_data_bundle_size*skip_word + 8] = tx_datak [ser_words*num_ch+num_word]; + assign tx_datain_from_pld[44*num_ch+num_word*tx_data_bundle_size*skip_word + 9] = tx_forcedisp [ser_words*num_ch+num_word]; + assign tx_datain_from_pld[44*num_ch+num_word*tx_data_bundle_size*skip_word + 10] = tx_dispval [ser_words*num_ch+num_word]; + end + + //*************************************************************** + //*********************** RX assignments ************************ + //With 8B/10B enabled, Rx dataout from PCS to PLD has 8-bit data + 8 controls in 16-bit bundles + //For 1 lane, [7:0] = data + // [8] = k char + // [9] = code violation + // [10] = word aligner status + // [11] = disparity error + // [12] = pattern detect + // [14:13] = rate match FIFO status + // [15] = running disparity + + assign rx_parallel_data[ser_base_factor*ser_words*num_ch+num_word*ser_base_factor +: ser_base_factor] + = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word +: ser_base_factor]; + assign rx_datak [ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 8]; + assign rx_errdetect [ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 9]; + assign rx_syncstatus [ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 10]; + assign rx_disperr [ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 11]; + assign rx_patterndetect[ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 12]; + // rate-match FIFO status is encoded as 2 bits at offsets 13,14 within a bundle + // 00: Normal data, 01: Deletion, 10: Insertion (or Underflow with 9'h1FE or 9'h1F7), 11: Overflow + assign rx_rmfifodatainserted[ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 14] + & ~rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 13]; + assign rx_rmfifodatadeleted [ser_words*num_ch+num_word] = ~rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 14] + & rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 13]; + + assign rx_runningdisp [ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 15]; + assign rx_a1a2sizeout [ser_words*num_ch+num_word] = rx_dataout_to_pld[64*num_ch+num_word*rx_data_bundle_size*skip_word + 8]; + end //for word + end + else begin + assign tx_datain_from_pld[44*num_ch +: 44] = tx_parallel_data[44*num_ch +: 44]; + assign rx_parallel_data[64*num_ch +: 64] = rx_dataout_to_pld[64*num_ch +: 64]; + + // Drive unused outputs + assign rx_datak = {(ser_words*lanes){1'b0}}; + assign rx_errdetect = {(ser_words*lanes){1'b0}}; + assign rx_syncstatus = {(ser_words*lanes){1'b0}}; + assign rx_disperr = {(ser_words*lanes){1'b0}}; + assign rx_patterndetect = {(ser_words*lanes){1'b0}}; + assign rx_rmfifodatainserted = {(ser_words*lanes){1'b0}}; + assign rx_rmfifodatadeleted = {(ser_words*lanes){1'b0}}; + assign rx_runningdisp = {(ser_words*lanes){1'b0}}; + assign rx_a1a2sizeout = {(ser_words*lanes){1'b0}}; + end + end //for channel + end + endgenerate +endmodule + + + + + + diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_h.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_h.sv new file mode 100644 index 0000000..1891b86 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_h.sv @@ -0,0 +1,316 @@ +// (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. + + +// +// SV-generation transceiver definitions and functions +// +// $Header$ +// +// PACKAGE DECLARATION +package av_xcvr_h; + + // SV Reconfiguration address definitions + + // PMA, PCS Base address + localparam RECONFIG_PMA_CH0_BASE = 11'h000; + localparam RECONFIG_PCSPMAIF_CH0_BASE = 11'h064; + localparam RECONFIG_PCS8G_CH0_BASE = 11'h096; + localparam RECONFIG_PCSPLDIF_CH0_BASE = 11'h0FA; + + localparam RECONFIG_PMA_CH1_BASE = 11'h190; + localparam RECONFIG_PCSPMAIF_CH1_BASE = RECONFIG_PMA_CH1_BASE + RECONFIG_PCSPMAIF_CH0_BASE; + localparam RECONFIG_PCS8G_CH1_BASE = RECONFIG_PMA_CH1_BASE + RECONFIG_PCS8G_CH0_BASE; + localparam RECONFIG_PCSPLDIF_CH1_BASE = RECONFIG_PMA_CH1_BASE + RECONFIG_PCSPLDIF_CH0_BASE; + + localparam RECONFIG_PMA_CH2_BASE = 11'h320; + localparam RECONFIG_PCSPMAIF_CH2_BASE = RECONFIG_PMA_CH2_BASE + RECONFIG_PCSPMAIF_CH0_BASE; + localparam RECONFIG_PCS8G_CH2_BASE = RECONFIG_PMA_CH2_BASE + RECONFIG_PCS8G_CH0_BASE; + localparam RECONFIG_PCSPLDIF_CH2_BASE = RECONFIG_PMA_CH2_BASE + RECONFIG_PCSPLDIF_CH0_BASE; + + + // PMA RECONFIG Address + + localparam RECONFIG_PMA_CH0_VOD = RECONFIG_PMA_CH0_BASE + 11'h004; + localparam RECONFIG_PMA_CH0_PRETAP = RECONFIG_PMA_CH0_BASE + 11'h003; + localparam RECONFIG_PMA_CH0_POSTTAP1 = RECONFIG_PMA_CH0_BASE + 11'h003; + localparam RECONFIG_PMA_CH0_POSTTAP2 = RECONFIG_PMA_CH0_BASE + 11'h003; + localparam RECONFIG_PMA_CH0_RX_EQA = RECONFIG_PMA_CH0_BASE + 11'h012; + localparam RECONFIG_PMA_CH0_RX_EQB = RECONFIG_PMA_CH0_BASE + 11'h018; + localparam RECONFIG_PMA_CH0_RX_EQC = RECONFIG_PMA_CH0_BASE + 11'h018; + localparam RECONFIG_PMA_CH0_RX_EQD = RECONFIG_PMA_CH0_BASE + 11'h018; + localparam RECONFIG_PMA_CH0_RX_EQV = RECONFIG_PMA_CH0_BASE + 11'h013; + localparam RECONFIG_PMA_CH0_RX_EQDCGAIN = RECONFIG_PMA_CH0_BASE + 11'h013; + + localparam RECONFIG_PMA_CH0_RCRU_RLBK = RECONFIG_PMA_CH0_BASE + 11'h010; + localparam RECONFIG_PMA_CH0_RREVLB_SW = RECONFIG_PMA_CH0_BASE + 11'h012; + localparam RECONFIG_PMA_CH0_RRX_DLPBK = RECONFIG_PMA_CH0_BASE + 11'h013; + + localparam RECONFIG_PMA_CH0_RXBYPASSEQZ123 = RECONFIG_PMA_CH0_BASE + 11'h012; //chestan: cannot find this in S5, need to check with Gary + localparam RECONFIG_PMA_CH0_RXSELHALFBW = RECONFIG_PMA_CH0_BASE + 11'h012; + + //DCD + localparam RECONFIG_PMA_CH0_DCD_RSER_CLK_MON = RECONFIG_PMA_CH0_BASE + 12'h001; // Forced data (test pattern) + localparam RECONFIG_PMA_CH0_DCD_RTX_LST = RECONFIG_PMA_CH0_BASE + 12'h002; // ATB + localparam RECONFIG_PMA_CH0_DCD_DC_TUNE = RECONFIG_PMA_CH0_BASE + 12'h006; // DCD calibration + + // register bits offsets + localparam RSER_CLK_MON_OFST = 8; // Forced data (test pattern) + localparam RTX_LST_3_OFST = 15; // ATB to LPF mode - MSB + localparam RTX_LST_2_OFST = 14; + localparam RTX_LST_1_OFST = 13; + localparam RTX_LST_0_OFST = 12; // ATB to LPF mode - LSB + localparam RSER_DC_TUNE_2_OFST = 12; // DCD calibration -msb + localparam RSER_DC_TUNE_1_OFST = 11; + localparam RSER_DC_TUNE_0_OFST = 10; // DCD calibration -lsb + localparam REYE_ISEL_2 = 2; // ISEL msb + localparam REYE_ISEL_1 = 1; + localparam REYE_ISEL_0 = 0; // ISEL lsb + localparam REYE_PDB = 11; // power enable + + //MIF RMW offsets and masks + localparam RECONFIG_PMA_CGB_REG_OFST = 12'h000; // contains rcgb_clk_sel, rcgb_x_en bits + localparam RECONFIG_PMA_CLKNET_CLKMON_REG_OFST = 12'h001; // contains XN Line select (rcgb_clknet_in_en), DCD protected bits (rser_clk_mon) + localparam RECONFIG_PMA_LST_REG_OFST = 12'h002; // contains DCD protected bits (rtx_lst) + localparam RECONFIG_PMA_BBPD_REG_OFST = 12'h00f; // contains BBPD control (rcru_pdof_*i) + localparam RECONFIG_PMA_TB_REG_OFST = 12'h010; // contains Testbus control control (rcru_pdof_test) + localparam RECONFIG_PMA_PCIEMD_RREF_REG_OFST = 12'h012; // contains (pcie_mode_sel, rrefclk_sel) bit + localparam RECONFIG_PMA_RXDATAO_REG_OFST = 12'h022; // contains rx_data_out_sel //rdynamic_sw, rint_early_eios, rint_ltr, rrxp_reserved[29], rint_tx_elec_idle, rint_txdetectrx, rint_pcie_switch, rint_cvp_mode, rint_ffclk_pdb + localparam RECONFIG_PMA_REFIQ_REG_OFST = 12'h024; // contains pma_iq_clk_sel bits + localparam RECONFIG_PCS8G_POWER_TRL_REG_OFST = RECONFIG_PCS8G_CH0_BASE + 12'h044; // contains r_pow_power_iso_ctrl bits + + localparam RECONFIG_PMA_CGB_REG_MASK = 16'h1e3f; + localparam RECONFIG_PMA_CLKNET_CLKMON_REG_MASK = 16'h0300; + localparam RECONFIG_PMA_LST_REG_MASK = 16'hf000; + localparam RECONFIG_PMA_BBPD_REG_MASK = 16'hffff; + localparam RECONFIG_PMA_TB_REG_MASK = 16'h0007; + localparam RECONFIG_PMA_PCIEMD_RREF_REG_MASK = 16'h0820; + localparam RECONFIG_PMA_RXDATAO_REG_MASK = 16'h01ff; // contains rx_data_out_sel + localparam RECONFIG_PMA_REFIQ_REG_MASK = 16'h07f8; // contains pma_iq_clk_sel bits + localparam RECONFIG_PMA_DCD_DC_TUNE_REG_MASK = 16'h1c00; // contains rser_dc_tune + localparam RECONFIG_PCS8G_POWER_TRL_REG_MASK = 16'h0004; // contains r_pow_power_iso_ctrl bits + + + +//**************************************************************************** +//************************ Local channel registers *************************** + + // Register address offset to gain access to the soft reconfig registers. + // This value must be added to the register addresses listed below. + localparam AV_XR_LOCAL_OFFSET = 12'h800; + + //**************************** + // Relative register addresses + localparam AV_XR_ADDR_DUMMY = 4'd0; // Dummy register for read/write testing + localparam AV_XR_ADDR_ADCE = 4'd1; // internal register for ADCE capture and standby + localparam AV_XR_ADDR_OC = 4'd2; // internal register for hard OC cal enable + localparam AV_XR_ADDR_PRBS = 4'd3; // internal register for PRBS control and status + localparam AV_XR_ADDR_DCD = 4'd4; // internal register for DCD control and status + localparam AV_XR_ADDR_DCD_RES = 4'd5; // internal register for DCD results + localparam AV_XR_ADDR_SLPBK = 4'd6; // internal register for serial loopback control + localparam AV_XR_ADDR_STATUS = 4'd7; // internal register for channel status + localparam AV_XR_ADDR_ID = 4'd8; // internal register for channel ID + localparam AV_XR_ADDR_REQUEST = 4'd9; // internal register for channel services request + localparam AV_XR_ADDR_RSTCTL = 4'd10; // internal register for channel reset control and override + + //**************************** + // Absolute register addresses + localparam AV_XR_ABS_ADDR_DUMMY = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_DUMMY; + localparam AV_XR_ABS_ADDR_ADCE = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_ADCE; + localparam AV_XR_ABS_ADDR_OC = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_OC; + localparam AV_XR_ABS_ADDR_PRBS = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_PRBS; + localparam AV_XR_ABS_ADDR_DCD = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_DCD; + localparam AV_XR_ABS_ADDR_DCD_RES = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_DCD_RES; + localparam AV_XR_ABS_ADDR_SLPBK = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_SLPBK; + localparam AV_XR_ABS_ADDR_STATUS = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_STATUS; + localparam AV_XR_ABS_ADDR_ID = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_ID; + localparam AV_XR_ABS_ADDR_REQUEST = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_REQUEST; + localparam AV_XR_ABS_ADDR_RSTCTL = AV_XR_LOCAL_OFFSET + AV_XR_ADDR_RSTCTL; + + //***************************** + // Bit masks for DUMMY register + localparam AV_XR_DUMMY_DUMMY_OFST = 0; + localparam AV_XR_DUMMY_DUMMY_LEN = 1; + localparam AV_XR_DUMMY_DUMMY_MASK = 16'h0001; + + //**************************** + // Bit masks for ADCE register + localparam AV_XR_ADCE_CAPTURE_OFST = 0; + localparam AV_XR_ADCE_STANDBY_OFST = 1; + localparam AV_XR_ADCE_DONE_OFST = 2; + localparam AV_XR_ADCE_UNUSED_OFST = 3; + + localparam AV_XR_ADCE_CAPTURE_LEN = 1; + localparam AV_XR_ADCE_STANDBY_LEN = 1; + localparam AV_XR_ADCE_DONE_LEN = 1; + localparam AV_XR_ADCE_UNUSED_LEN = 13; + + localparam AV_XR_ADCE_CAPTURE_MASK = 16'h0001; // bitfield position of ADCE capture, within ADCE reg + localparam AV_XR_ADCE_STANDBY_MASK = 16'h0002; // bitfield position of ADCE standby, within ADCE reg + localparam AV_XR_ADCE_DONE_MASK = 16'h0004; // bitfield position of ADCE adapt done, within ADCE reg + + //************************************ + // Bit masks for HARDOC_CALEN register + localparam AV_XR_OC_CALEN_OFST = 0; + localparam AV_XR_OC_CALDONE_OFST = 1; + localparam AV_XR_OC_UNUSED_OFST = 2; + + localparam AV_XR_OC_CALEN_LEN = 1; + localparam AV_XR_OC_CALDONE_LEN = 1; + localparam AV_XR_OC_UNUSED_LEN = 14; + + localparam AV_XR_OC_CALEN_MASK = 16'h0001; + localparam AV_XR_OC_CALDONE_MASK = 16'h0002; + + //**************************** + // Bit masks for PRBS register + localparam AV_XR_PRBS_CLR_OFST = 0; + localparam AV_XR_PRBS_8G_ERR_OFST = 1; + localparam AV_XR_PRBS_8G_DONE_OFST = 2; + localparam AV_XR_PRBS_UNUSED_OFST = 3; + + localparam AV_XR_PRBS_CLR_LEN = 1; + localparam AV_XR_PRBS_8G_ERR_LEN = 1; + localparam AV_XR_PRBS_8G_DONE_LEN = 1; + localparam AV_XR_PRBS_10G_ERR_LEN = 1; + localparam AV_XR_PRBS_10G_DONE_LEN = 1; + localparam AV_XR_PRBS_UNUSED_LEN = 13; + + localparam AV_XR_PRBS_CLR_MASK = 16'h0001; + localparam AV_XR_PRBS_8G_ERR_MASK = 16'h0002; + localparam AV_XR_PRBS_8G_DONE_MASK = 16'h0004; + localparam AV_XR_PRBS_10G_ERR_MASK = 16'h0008; + localparam AV_XR_PRBS_10G_DONE_MASK = 16'h0010; + + //*************************** + // Bit masks for DCD register + localparam AV_XR_DCD_REQ_OFST = 0; + localparam AV_XR_DCD_ACK_OFST = 1; + localparam AV_XR_DCD_UNUSED_OFST = 2; + + localparam AV_XR_DCD_REQ_LEN = 1; + localparam AV_XR_DCD_ACK_LEN = 1; + localparam AV_XR_DCD_UNUSED_LEN = 14; + + localparam AV_XR_DCD_REQ_MASK = 16'h0001; + localparam AV_XR_DCD_ACK_MASK = 16'h0002; + + //******************************* + // Bit masks for DCD_RES register + localparam AV_XR_DCD_RES_A_OFST = 0; + localparam AV_XR_DCD_RES_B_OFST = 8; + + localparam AV_XR_DCD_RES_A_LEN = 8; + localparam AV_XR_DCD_RES_B_LEN = 8; + + localparam AV_XR_DCD_RES_A_MASK = 16'h00ff; + localparam AV_XR_DCD_RES_B_MASK = 16'hff00; + + //***************************** + // Bit masks for SLPBK register + localparam AV_XR_SLPBK_SLPBKEN_OFST = 0; + localparam AV_XR_SLPBK_UNUSED_OFST = 1; + + localparam AV_XR_SLPBK_SLPBKEN_LEN = 1; + localparam AV_XR_SLPBK_UNUSED_LEN = 15; + + localparam AV_XR_SLPBK_SLPBKEN_MASK = 16'h0001; + + //****************************** + // Bit masks for STATUS register + localparam AV_XR_STATUS_TX_DIGITAL_RESET_OFST = 0; // Valid only for channel interfaces + localparam AV_XR_STATUS_RX_DIGITAL_RESET_OFST = 1; // Valid only for channel interfaces + localparam AV_XR_STATUS_PLL_LOCKED_OFST = 2; // Valid only for PLL interfaces + localparam AV_XR_STATUS_PLL_LOCKED_FLAG_OFST = 3; // Valid only for PLL interfaces + localparam AV_XR_STATUS_UNUSED_OFST = 4; // Valid only for PLL interfaces + + localparam AV_XR_STATUS_TX_DIGITAL_RESET_LEN = 1; + localparam AV_XR_STATUS_RX_DIGITAL_RESET_LEN = 1; + localparam AV_XR_STATUS_PLL_LOCKED_LEN = 1; + localparam AV_XR_STATUS_PLL_LOCKED_FLAG_LEN = 1; + localparam AV_XR_STATUS_UNUSED_LEN = 12; + + localparam AV_XR_STATUS_TX_DIGITAL_RESET_MASK = 16'h0001; + localparam AV_XR_STATUS_RX_DIGITAL_RESET_MASK = 16'h0002; + localparam AV_XR_STATUS_PLL_LOCKED_MASK = 16'h0004; + localparam AV_XR_STATUS_PLL_LOCKED_FLAG_MASK = 16'h0008; + + //************************** + // Bit masks for ID register + localparam AV_XR_ID_TX_CHANNEL_OFST = 0; + localparam AV_XR_ID_RX_CHANNEL_OFST = 1; + localparam AV_XR_ID_PLL_TYPE_OFST = 2; + localparam AV_XR_ID_UNUSED_OFST = 4; + + localparam AV_XR_ID_TX_CHANNEL_LEN = 1; + localparam AV_XR_ID_RX_CHANNEL_LEN = 1; + localparam AV_XR_ID_PLL_TYPE_LEN = 2; + localparam AV_XR_ID_UNUSED_LEN = 12; + + localparam AV_XR_ID_TX_CHANNEL_MASK = 16'h0001; + localparam AV_XR_ID_RX_CHANNEL_MASK = 16'h0002; + localparam AV_XR_ID_PLL_TYPE_MASK = 16'h000C; + + // Parameters for PLL Type field + localparam AV_XR_ID_PLL_TYPE_NONE = 0; + localparam AV_XR_ID_PLL_TYPE_CMU = 1; + localparam AV_XR_ID_PLL_TYPE_LC = 2; + localparam AV_XR_ID_PLL_TYPE_FPLL = 3; + + // Parameters for PMA bonding mode field + localparam AV_XR_ID_PMA_BONDING_X1 = 0; + localparam AV_XR_ID_PMA_BONDING_XN = 1; + localparam AV_XR_ID_PMA_BONDING_NONE = 2; + + //******************************* + // Bit masks for REQUEST register + localparam AV_XR_REQUEST_DCD_OFST = 0; + localparam AV_XR_REQUEST_VRC_OFST = 1; + localparam AV_XR_REQUEST_OFFSET_OFST = 2; + localparam AV_XR_REQUEST_UNUSED_OFST = 3; + + localparam AV_XR_REQUEST_DCD_LEN = 1; + localparam AV_XR_REQUEST_VRC_LEN = 1; + localparam AV_XR_REQUEST_UNUSED_LEN = 13; + + localparam AV_XR_REQUEST_DCD_MASK = 16'h0001; + localparam AV_XR_REQUEST_VRC_MASK = 16'h0002; + localparam AV_XR_REQUEST_OFFSET_MASK = 16'h0004; + +//******************************** + // Bit masks for RSTCTL register + localparam AV_XR_RSTCTL_TX_RST_OVR_OFST = 0; + localparam AV_XR_RSTCTL_TX_DIGITAL_RST_N_VAL_OFST = 1; + localparam AV_XR_RSTCTL_RX_RST_OVR_OFST = 2; + localparam AV_XR_RSTCTL_RX_DIGITAL_RST_N_VAL_OFST = 3; + localparam AV_XR_RSTCTL_RX_ANALOG_RST_N_VAL_OFST = 4; + localparam AV_XR_RSTCTL_UNUSED_OFST = 5; + + localparam AV_XR_RSTCTL_TX_RST_OVR_LEN = 1; + localparam AV_XR_RSTCTL_TX_DIGITAL_RST_N_VAL_LEN = 1; + localparam AV_XR_RSTCTL_RX_RST_OVR_LEN = 1; + localparam AV_XR_RSTCTL_RX_DIGITAL_RST_N_VAL_LEN = 1; + localparam AV_XR_RSTCTL_RX_ANALOG_RST_N_VAL_LEN = 1; + localparam AV_XR_RSTCTL_UNUSED_LEN = 11; + + localparam AV_XR_RSTCTL_TX_RST_OVR_MASK = 16'h0001; + localparam AV_XR_RSTCTL_TX_DIGITAL_RST_N_MASK = 16'h0002; + localparam AV_XR_RSTCTL_RX_RST_OVR_MASK = 16'h0004; + localparam AV_XR_RSTCTL_RX_DIGITAL_RST_N_MASK = 16'h0008; + localparam AV_XR_RSTCTL_RX_ANALOG_RST_N_MASK = 16'h0010; + +//********************** End local channel registers ************************* +//**************************************************************************** + + +endpackage + diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_low_latency_phy_nr.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_low_latency_phy_nr.sv new file mode 100644 index 0000000..9e703e2 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_low_latency_phy_nr.sv @@ -0,0 +1,510 @@ +// (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: xaui verilog for Arria V +// +// Authors: hhleong 08-May-2012 +// +// Copyright (c) Altera Corporation 1997 - 2012 +// All rights reserved. +// +//----------------------------------------------------------------------------- + + +`timescale 1 ns / 1 ps + +import altera_xcvr_functions::*; + +module av_xcvr_low_latency_phy_nr #( + parameter device_family = "Arria V", + parameter protocol_hint = "basic", // (basic, gige, cpri) + parameter operation_mode = "Duplex", //legal value: TX, RX, Duplex + parameter lanes = 4, //legal value: 1+ + parameter bonded_group_size = 4, //legal value: integer from 1 .. lanes + parameter pma_bonding_mode = "xN", // (x1, xN) + parameter pcs_pma_width = 10, //legal value: 8,10,16,20 + parameter ser_base_factor = 10, //legal value: 8,10 + parameter ser_words = 2, // legal values: 1,2,4 + parameter data_rate = "3125 Mbps", + parameter base_data_rate = "3125 Mbps", // (PLL Rate) - must be (data_rate * 1,2,4,or8) + + // tx bitslip + parameter tx_bitslip_enable = "false", + + //optional coreclks + parameter tx_use_coreclk = "false", + parameter rx_use_coreclk = "false", + parameter en_synce_support = 0, //expose CDR ref-clk in this mode + + //8B10B + parameter use_8b10b = "false", //legal value: "false", "true" + parameter use_8b10b_manual_control= "false", //legal value: "false", "true" + + //Word Aligner + parameter word_aligner_mode = "bitslip", //legal value: bitslip, sync state machine, manual + parameter word_aligner_state_machine_datacnt = 1, //legal value: 0 - 256 + parameter word_aligner_state_machine_errcnt = 1, //legal value: 0 - 256 + parameter word_aligner_state_machine_patterncnt = 10, //legal value: 0 - 256 + parameter word_aligner_pattern_length = 10, + parameter word_align_pattern = "0101111100", + parameter run_length_violation_checking = 40, //legal value: 0, 1+ + + //RM FIFO + parameter use_rate_match_fifo = 0, //legal value: 0, 1 + parameter rate_match_pattern1 = "11010000111010000011", + parameter rate_match_pattern2 = "00101111000101111100", + + //Byte Ordering Block + parameter byte_order_mode = "none", //legal value: None, sync_state_machine, PLD control + parameter byte_order_pattern = "000000000", + parameter byte_order_pad_pattern = "111111011", + + //Hidden parameter to enable 0ppm legality bypass + parameter coreclk_0ppm_enable = "false", + + //PLL + parameter pll_refclk_cnt = 1, // Number of reference clocks + parameter pll_refclk_freq = "156.25 MHz", // Frequency of each reference clock + parameter pll_refclk_select = "0", // Selects the initial reference clock for each TX PLL + parameter cdr_refclk_select = 0, // Selects the initial reference clock for all RX CDR PLLs + parameter plls = 1, // (1+) + parameter pll_feedback_path = "no_compensation", //no_compensation, tx_clkout + parameter pll_type = "CMU", // PLL type for each PLL + parameter pll_select = 0, // Selects the initial PLL + parameter pll_reconfig = 0, // (0,1) 0-Disable PLL reconfig, 1-Enable PLL reconfig + parameter pll_external_enable = 0, // (0,1) 0-Disable external TX PLL, 1-Enable external TX PLL + + //system clock rate + parameter mgmt_clk_in_mhz = 100, + parameter embedded_reset = 1, // (0,1) 1-Enable embedded reset controller + parameter channel_interface = 0, //legal value: (0,1) 1-Enable channel reconfiguration + parameter starting_channel_number = 0 //legal value: 0+ +) ( + // user data (avalon-MM slave interface) //for all the channel rst, powerdown, rx serilize loopback enable + input wire mgmt_clk_reset, + input wire mgmt_clk, + input wire [7:0] mgmt_address, + input wire mgmt_read, + output wire [31:0] mgmt_readdata, + input wire mgmt_write, + input wire [31:0] mgmt_writedata, + output wire mgmt_waitrequest, + + // Reset inputs + //input wire [plls -1:0] pll_powerdown, + //input wire [lanes-1:0] tx_analogreset, + //input wire [lanes-1:0] tx_digitalreset, + //input wire [lanes-1:0] rx_analogreset, + //input wire [lanes-1:0] rx_digitalreset, + + // Calibration busy signals + output wire [lanes-1:0] tx_cal_busy, + output wire [lanes-1:0] rx_cal_busy, + + //clk signal + input wire [pll_refclk_cnt-1:0] pll_ref_clk, + input wire cdr_ref_clk, // used only in SyncE mode + input wire [lanes-1:0] tx_coreclk, + input wire [lanes-1:0] rx_coreclk, + + //data ports - Avalon ST interface + input wire [(channel_interface? 44: ser_base_factor*ser_words)*lanes-1:0] tx_parallel_data, + output wire [(channel_interface? 64: ser_base_factor*ser_words)*lanes-1:0] rx_parallel_data, + //input wire [ser_words*lanes-1:0] tx_datak, + //output wire [ser_words*lanes-1:0] rx_datak, + //input wire [ser_words*lanes-1:0] tx_forcedisp, + //input wire [ser_words*lanes-1:0] tx_dispval, + //output wire [ser_words*lanes-1:0] rx_runningdisp, + //input wire [lanes-1:0] rx_enabyteord, + input wire [lanes-1:0] rx_bitslip, + + //optional ports + input wire [lanes*5-1:0] tx_bitslip, + //input wire [lanes-1:0] tx_forceelecidle, + output wire [ser_words*lanes-1:0] rx_syncstatus, + //output wire [ser_words*lanes-1:0] rx_patterndetect, + //output wire [lanes-1:0] rx_signaldetect, + //output wire [ser_words*lanes-1:0] rx_errdetect, + //output wire [ser_words*lanes-1:0] rx_disperr, + //output wire [ser_words*lanes-1:0] rx_a1a2sizeout, + //output wire [lanes*5-1:0] rx_bitslipboundaryselectout, + //output wire [ser_words*lanes-1:0] rx_rmfifodatainserted, + //output wire [ser_words*lanes-1:0] rx_rmfifodatadeleted, + //output wire [lanes-1:0] rx_rlv, + //output wire [lanes-1:0] rx_byteordflag, + + //conduit + input wire [lanes-1:0] rx_serial_data, + output wire [lanes-1:0] tx_serial_data, + + output wire [plls-1 :0] pll_locked, + output wire [lanes-1:0] rx_is_lockedtodata, + output wire [lanes-1:0] rx_is_lockedtoref, + + output wire rx_ready, + output wire tx_ready, + + input wire [(plls*lanes)- 1 : 0] ext_pll_clk, // clkout from external PLL + + //clock outputs + output wire [(lanes/bonded_group_size)-1:0] tx_clkout, + output wire [lanes-1:0] rx_clkout, + //output wire [lanes-1:0] rx_recovered_clk, + + // reconfiguration ports and status + //input wire [altera_xcvr_functions::get_custom_reconfig_to_width ("Arria V",operation_mode,lanes,plls,bonded_group_size,"","")-1:0] reconfig_to_xcvr, + //output wire [altera_xcvr_functions::get_custom_reconfig_from_width("Arria V",operation_mode,lanes,plls,bonded_group_size,"","")-1:0] reconfig_from_xcvr, + + input wire [get_custom_reconfig_to_width ("Arria V",operation_mode,lanes,((pll_external_enable == 1)? 0: plls),bonded_group_size,"","")-1:0] reconfig_to_xcvr, + output wire [get_custom_reconfig_from_width("Arria V",operation_mode,lanes,((pll_external_enable == 1)? 0: plls),bonded_group_size,"","")-1:0] reconfig_from_xcvr, + + input wire [plls-1:0] pll_locked_i, + + // Following outputs tx_digital_rst and rx_digital_rst to support SOFT XAUI + output wire [lanes-1:0] tx_digital_rst, // output digital reset for soft PCS, this reset can be controlled in AVMM in cahnnel controller + output wire [lanes-1:0] rx_digital_rst // output digital reset for soft PCS, this reset can be controlled in AVMM in cahnnel controller + +); + + localparam TX_ENABLE = (operation_mode != "Rx" && operation_mode != "RX"); + localparam RX_ENABLE = (operation_mode != "Tx" && operation_mode != "TX"); + + //wire [lanes-1:0] rx_rmfifofull_wire; + //wire [lanes-1:0] rx_rmfifoempty_wire; + //wire [lanes-1:0] rx_phase_comp_fifo_error_wire; + //wire [lanes-1:0] tx_phase_comp_fifo_error_wire; + + + wire [plls-1 :0] phy_pll_locked; + + ////////////////////////////////// + // Control & status register map (CSR) outputs + ////////////////////////////////// + wire csr_reset_tx_digital; //to reset controller + wire csr_reset_rx_digital; //to reset controller + wire csr_reset_all; //to reset controller + wire csr_pll_powerdown; //to xcvr instance + wire [lanes-1:0] csr_tx_digitalreset; //to xcvr instance + wire [lanes-1:0] csr_rx_analogreset; //to xcvr instance + wire [lanes-1:0] csr_rx_digitalreset; //to xcvr instance + wire [lanes-1:0] csr_phy_loopback_serial; //to xcvr instance + wire [lanes-1:0] csr_tx_invpolarity; //to xcvr instance + wire [lanes-1:0] csr_rx_invpolarity; //to xcvr instance + wire [lanes-1:0] csr_rx_set_locktoref; //to xcvr instance + wire [lanes-1:0] csr_rx_set_locktodata; //to xcvr instance + wire [lanes-1:0] csr_rx_enapatternalign; //to xcvr instance + wire [lanes-1:0] csr_rx_bitreversalenable; //to xcvr instance + wire [lanes-1:0] csr_rx_bytereversalenable; //to xcvr instance + wire [lanes-1:0] csr_rx_a1a2size; //to xcvr instance + //wire [lanes*5-1:0] csr_tx_bitslipboundaryselect; //to xcvr instance + + // readdata output from both CSR blocks + wire [31:0] mgmt_readdata_common; + //wire [31:0] mgmt_readdata_pcs; + + + ////////////////////////////////// + //reset controller outputs + ////////////////////////////////// + wire reset_controller_pll_powerdown; + wire [lanes-1:0] reset_controller_tx_digitalreset; + wire [lanes-1:0] reset_controller_rx_analogreset; + wire [lanes-1:0] reset_controller_rx_digitalreset; + wire [lanes-1:0] reset_controller_tx_ready; + wire [lanes-1:0] reset_controller_rx_ready; + + // Final reset signals + wire [plls-1:0] pll_powerdown_fnl; + wire [lanes-1:0] tx_analogreset_fnl; + wire [lanes-1:0] tx_digitalreset_fnl; + wire [lanes-1:0] rx_analogreset_fnl; + wire [lanes-1:0] rx_digitalreset_fnl; + + assign pll_powerdown_fnl = {plls {csr_pll_powerdown}} ; + assign tx_analogreset_fnl = {lanes{csr_pll_powerdown}} ; + assign tx_digitalreset_fnl = csr_tx_digitalreset | {lanes{1'b0}} ; + assign rx_analogreset_fnl = csr_rx_analogreset | {lanes{1'b0}} ; + assign rx_digitalreset_fnl = csr_rx_digitalreset | {lanes{1'b0}} ; + + av_xcvr_custom_native #( + .device_family (device_family ), + .protocol_hint (protocol_hint ), + .lanes (lanes ), + .plls (plls ), + .pll_type (pll_type ), + .pll_select (pll_select ), + .pll_reconfig (pll_reconfig ), + .pma_bonding_mode (pma_bonding_mode ), + .pcs_pma_width (pcs_pma_width ), + .ser_base_factor (10 ), + .ser_words (ser_words ), + .data_rate (data_rate ), + .base_data_rate (base_data_rate ), + .en_synce_support (en_synce_support), //expose CDR ref-clk in this mode + .pll_refclk_cnt (pll_refclk_cnt ), + .pll_refclk_freq (pll_refclk_freq ), + .pll_refclk_select (pll_refclk_select ), + .cdr_refclk_select (cdr_refclk_select ), + .pll_external_enable (pll_external_enable ), + .operation_mode (operation_mode ), + .starting_channel_number (starting_channel_number ), + .bonded_group_size (bonded_group_size ), + .channel_interface (channel_interface ), + .use_8b10b ("false" ), + .use_8b10b_manual_control (use_8b10b_manual_control ), + .tx_use_coreclk (tx_use_coreclk ), + .rx_use_coreclk (rx_use_coreclk ), + .tx_bitslip_enable (tx_bitslip_enable ), + .word_aligner_mode (word_aligner_mode ), + .word_aligner_state_machine_datacnt (word_aligner_state_machine_datacnt ), + .word_aligner_state_machine_errcnt (word_aligner_state_machine_errcnt ), + .word_aligner_state_machine_patterncnt(word_aligner_state_machine_patterncnt), + .run_length_violation_checking (run_length_violation_checking ), + .word_align_pattern (word_align_pattern ), + .word_aligner_pattern_length (word_aligner_pattern_length ), + .use_rate_match_fifo (0 ), + .rate_match_pattern1 (rate_match_pattern1 ), + .rate_match_pattern2 (rate_match_pattern2 ), + .byte_order_mode ("None" ), + .byte_order_pattern (byte_order_pattern ), + .byte_order_pad_pattern (byte_order_pad_pattern ), + .coreclk_0ppm_enable (coreclk_0ppm_enable ), + .pll_feedback_path (pll_feedback_path ) + ) transceiver_core ( + .tx_analogreset (tx_analogreset_fnl ), + .pll_powerdown (pll_powerdown_fnl ), + .tx_digitalreset (tx_digitalreset_fnl ), + .rx_analogreset (rx_analogreset_fnl ), + .rx_digitalreset (rx_digitalreset_fnl ), + .tx_cal_busy (tx_cal_busy ), + .rx_cal_busy (rx_cal_busy ), + .pll_ref_clk (pll_ref_clk ), + .cdr_ref_clk (cdr_ref_clk), // used only in SyncE mode + .tx_coreclkin (tx_coreclk ), + .rx_coreclkin (rx_coreclk ), + .tx_parallel_data (tx_parallel_data ), + .rx_parallel_data (rx_parallel_data ), + .tx_datak (/*unused*/ ), + .rx_datak (/*unused*/ ), + .tx_forcedisp (/*unused*/ ), + .tx_dispval (/*unused*/ ), + .rx_runningdisp (/*unused*/ ), + .rx_serial_data (rx_serial_data ), + .tx_serial_data (tx_serial_data ), + .tx_clkout (tx_clkout ), + .rx_clkout (rx_clkout ), + .rx_recovered_clk (/*unused*/ ), + .rx_enabyteord (/*unused*/ ), + .rx_bitslip (rx_bitslip ), + //MM ports + .tx_forceelecidle (/*unused*/ ), + .tx_invpolarity (/*unused*/ ), + .tx_bitslipboundaryselect (tx_bitslip ), + .rx_invpolarity (/*unused*/ ), + .rx_seriallpbken (csr_phy_loopback_serial ), + .rx_set_locktodata (csr_rx_set_locktodata ), + .rx_set_locktoref (csr_rx_set_locktoref ), + .rx_enapatternalign (/*unused*/ ), + .rx_bitreversalenable (/*unused*/ ), + .rx_bytereversalenable (/*unused*/ ), + .rx_a1a2size (/*unused*/ ), + .rx_rlv (/*unused*/ ), + .rx_patterndetect (/*unused*/ ), + .rx_syncstatus (rx_syncstatus ), + .rx_signaldetect (/*unused*/ ), + .rx_bitslipboundaryselectout(/*unused*/ ), + .rx_errdetect (/*unused*/ ), + .rx_disperr (/*unused*/ ), + .rx_rmfifofull (/*unused*/ ), + .rx_rmfifoempty (/*unused*/ ), + .rx_rmfifodatainserted (/*unused*/ ), + .rx_rmfifodatadeleted (/*unused*/ ), + .rx_a1a2sizeout (/*unused*/ ), + .rx_byteordflag (/*unused*/ ), + .rx_is_lockedtoref (rx_is_lockedtoref ), + .rx_is_lockedtodata (rx_is_lockedtodata ), + .pll_locked (phy_pll_locked ), + .rx_phase_comp_fifo_error (/*unused*/ ), + .tx_phase_comp_fifo_error (/*unused*/ ), + .ext_pll_clk (ext_pll_clk ), + .reconfig_to_xcvr (reconfig_to_xcvr ), + .reconfig_from_xcvr (reconfig_from_xcvr ) + ); + + + assign pll_locked = pll_external_enable? pll_locked_i : phy_pll_locked; + + // assign rx_analog_rst = csr_rx_analogreset; + // following for XAUI, SOFT XAUI needs this + assign tx_digital_rst = csr_tx_digitalreset; + assign rx_digital_rst = csr_rx_digitalreset; + + // Instantiate memory map logic for given number of lanes & PLL's + // Includes all except PCS + alt_xcvr_csr_common #( + .lanes (lanes), + .plls (plls ), + .rpc (1 ) + ) csr ( + .clk (mgmt_clk ), + .reset (mgmt_clk_reset ), + .address (mgmt_address ), + .read (mgmt_read ), + .write (mgmt_write ), + .writedata (mgmt_writedata ), + .pll_locked (pll_locked ), + .rx_is_lockedtoref (rx_is_lockedtoref ), + .rx_is_lockedtodata (rx_is_lockedtodata ), + .rx_signaldetect ({lanes{1'b0}} ), + .reset_controller_tx_ready (tx_ready ), + .reset_controller_rx_ready (rx_ready ), + .reset_controller_pll_powerdown (reset_controller_pll_powerdown ), + .reset_controller_tx_digitalreset (reset_controller_tx_digitalreset ), + .reset_controller_rx_analogreset (reset_controller_rx_analogreset ), + .reset_controller_rx_digitalreset (reset_controller_rx_digitalreset ), + .readdata (mgmt_readdata_common ), + .csr_reset_tx_digital (csr_reset_tx_digital ), + .csr_reset_rx_digital (csr_reset_rx_digital ), + .csr_reset_all (csr_reset_all ), + .csr_pll_powerdown (csr_pll_powerdown ), + .csr_tx_digitalreset (csr_tx_digitalreset ), + .csr_rx_analogreset (csr_rx_analogreset ), + .csr_rx_digitalreset (csr_rx_digitalreset ), + .csr_phy_loopback_serial (csr_phy_loopback_serial ), + .csr_rx_set_locktoref (csr_rx_set_locktoref ), + .csr_rx_set_locktodata (csr_rx_set_locktodata ) + ); + + // generate waitrequest for 'top' channel + altera_wait_generate top_wait ( + .rst (mgmt_clk_reset ), + .clk (mgmt_clk ), + .launch_signal (mgmt_read ), + .wait_req (mgmt_waitrequest ) + ); + + // Instantiate PCS memory map logic for given number of lanes + // Note: This block is being replaced by the hxaui_csr + /* + alt_xcvr_csr_pcs8g #( + .lanes (lanes ), + .words (ser_words) + ) csr_pcs ( + .clk (mgmt_clk ), + .reset (mgmt_clk_reset ), + .address (mgmt_address ), + .read (mgmt_read ), + .write (mgmt_write ), + .writedata (mgmt_writedata ), + .readdata (mgmt_readdata_pcs ), + .rx_clk (rx_clkout[0] ), + .tx_clk (tx_clkout[0] ), + .rx_patterndetect (rx_patterndetect ), + .rx_syncstatus (rx_syncstatus ), + .rlv (rx_rlv ), + .rx_phase_comp_fifo_error (rx_phase_comp_fifo_error_wire), + .tx_phase_comp_fifo_error (tx_phase_comp_fifo_error_wire), + .rx_errdetect (rx_errdetect ), + .rx_disperr (rx_disperr ), + .rx_bitslipboundaryselectout (rx_bitslipboundaryselectout ), + .rx_a1a2sizeout (rx_a1a2sizeout ), + .csr_tx_invpolarity (csr_tx_invpolarity ), + .csr_rx_invpolarity (csr_rx_invpolarity ), + .csr_rx_bitreversalenable (csr_rx_bitreversalenable ), + .csr_rx_bitslip ( ), + .csr_rx_enapatternalign (csr_rx_enapatternalign ), + .csr_rx_bytereversalenable (csr_rx_bytereversalenable ), + .csr_rx_a1a2size (csr_rx_a1a2size ), + .csr_tx_bitslipboundaryselect (csr_tx_bitslipboundaryselect ) + ); + */ + + // combine readdata output from both CSR blocks + // each decodes non-overlapping addresses, and outputs "11..111" for undecoded addresses, + // so an AND is sufficient + assign mgmt_readdata = mgmt_readdata_common; + + // Reset Controller + generate if (embedded_reset) begin : gen_embedded_reset + localparam RX_PER_CHANNEL = (bonded_group_size == 1); + wire [lanes-1:0] rx_manual_mode; + + // Put reset controller into manual mode when we are not in auto lock mode + assign rx_manual_mode = (csr_rx_set_locktoref | csr_rx_set_locktodata); + // We have a single tx_ready, rx_ready output per IP instance + assign tx_ready = &reset_controller_tx_ready; + assign rx_ready = &reset_controller_rx_ready; + + altera_xcvr_reset_control + #( + .CHANNELS (lanes ), // Number of CHANNELS + .SYNCHRONIZE_RESET (0 ), // (0,1) Synchronize the reset input + .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 + // Reset timings + .SYS_CLK_IN_MHZ (mgmt_clk_in_mhz), // Clock frequency in MHz. Required for reset timers + .REDUCED_SIM_TIME (1 ), // (0,1) 1=Reduced reset timings for simulation + // PLL options + .TX_PLL_ENABLE (TX_ENABLE ), // (0,1) Enable TX PLL reset + .PLLS (1 ), // Number of TX PLLs + .T_PLL_POWERDOWN (1000 ), // pll_powerdown period in ns + // TX options + .TX_ENABLE (TX_ENABLE ), // (0,1) Enable TX resets + .TX_PER_CHANNEL (0 ), // (0,1) 1=separate TX reset per channel + .T_TX_DIGITALRESET (20 ), // tx_digitalreset period (after pll_powerdown) + .T_PLL_LOCK_HYST (0 ), // Amount of hysteresis to add to pll_locked status signal + // RX options + .RX_ENABLE (RX_ENABLE ), // (0,1) Enable RX resets + .RX_PER_CHANNEL (RX_PER_CHANNEL ), // (0,1) 1=separate RX reset per channel + .T_RX_ANALOGRESET (40 ), // rx_analogreset period + .T_RX_DIGITALRESET (4000 ) // rx_digitalreset period (after rx_is_lockedtodata) + ) reset_controller ( + // User inputs and outputs + .clock (mgmt_clk ), // System clock + .reset (mgmt_clk_reset ), // Asynchronous reset + // Reset signals + .pll_powerdown (reset_controller_pll_powerdown ), // reset TX PLL + .tx_analogreset (/*unused*/ ), // reset TX PMA + .tx_digitalreset (reset_controller_tx_digitalreset ), // reset TX PCS + .rx_analogreset (reset_controller_rx_analogreset ), // reset RX PMA + .rx_digitalreset (reset_controller_rx_digitalreset ), // reset RX PCS + // Status output + .tx_ready (reset_controller_tx_ready ), // TX is not in reset + .rx_ready (reset_controller_rx_ready ), // RX is not in reset + // Digital reset override inputs (must by synchronous with clock) + .tx_digitalreset_or({lanes{csr_reset_tx_digital}} ), // reset request for tx_digitalreset + .rx_digitalreset_or({lanes{csr_reset_rx_digital}} ), // reset request for rx_digitalreset + // TX control inputs + .pll_locked (pll_locked[pll_select] ), // TX PLL is locked status + .pll_select (1'b0 ), // Select TX PLL locked signal + .tx_cal_busy (tx_cal_busy ), // TX channel calibration status + .tx_manual ({lanes{1'b1}} ), // 1=Manual TX reset mode + // RX control inputs + .rx_is_lockedtodata (rx_is_lockedtodata ), // RX CDR PLL is locked to data status + .rx_cal_busy (rx_cal_busy ), // RX channel calibration status + .rx_manual (rx_manual_mode ) // 1=Manual RX reset mode + ); + end else begin:gen_no_embedded_reset + assign reset_controller_pll_powerdown = 1'b0; + assign reset_controller_tx_digitalreset = {lanes{1'b0}}; + assign reset_controller_rx_analogreset = {lanes{1'b0}}; + assign reset_controller_rx_digitalreset = {lanes{1'b0}}; + assign tx_ready = 1'b0; + assign rx_ready = 1'b0; + end + endgenerate + +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_native.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_native.sv new file mode 100644 index 0000000..281653e --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_native.sv @@ -0,0 +1,1235 @@ +// (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 1ps/1ps +import altera_xcvr_functions::*; + +module av_xcvr_native #( + parameter device_family = "Arria V", + // av_pma parameters + parameter rx_enable = 1, // (1,0) Enable or disable reciever PMA + parameter tx_enable = 1, // (1,0) Enable or disable transmitter PMA + parameter bonding_master_ch = 0, // Indicates which channel is master + parameter pma_bonding_master = "0", // (List i.e. "0,3,..."), Indicates which channels is master + parameter bonding_master_only = "-1", // Indicates bonding_master_channel is MASTER_ONLY + parameter channel_number = 0, // + parameter plls = 1, // (1+) Number of high-speed serial clocks from TX plls (tx_ser_clk) + parameter pll_sel = 0, // (0 - plls-1) // Which PLL clock to use + parameter pma_prot_mode = "basic", // (basic,cpri,cpri_rx_tx,disabled_prot_mode,gige, pipe_g1,pipe_g2,srio_2p1,test,xaui) + parameter pma_mode = 8, // (8,10,16,20,32,40,64,80) Serialization factor + parameter base_data_rate = "1250000000 bps", // Base data rate for CGB + parameter pma_data_rate = "1250000000 bps", // Serial data rate in bits-per-second + parameter cdr_reconfig = 0, // 1-Enable CDR reconfiguration, 0-Disable CDR reconfiguration + parameter cdr_reference_clock_frequency = "100 Mhz", + parameter cdr_refclk_cnt = 1, // # of CDR reference clocks + parameter cdr_refclk_sel = 0, // Initial CDR reference clock selection + parameter deser_enable_bit_slip = "false", + parameter auto_negotiation = "", // ("true","false") PCIe Auto-Negotiation (Gen1,2,3) + parameter tx_clk_div = 1, // (1,2,4,8) + parameter pcie_rst = "normal_reset", + parameter fref_vco_bypass = "NORMAL_OPERATION", + parameter sd_on = 16, + parameter pdb_sd = "true", + parameter pma_bonding_mode = "x1", // valid value "x1", "xN" + parameter external_master_cgb = 0, + + // av_pcs parameters + parameter enable_8g_rx = "true", + parameter enable_8g_tx = "true", + parameter enable_dyn_reconfig = "true", + parameter enable_gen12_pipe = "true", + + // Adding new parameter for PMA Direct + parameter enable_pma_direct_rx = "false", // (true,false) Enable, disable the PMA Direct path + parameter enable_pma_direct_tx = "false", // (true,false) Enable, disable the PMA Direct path + // parameters for arriav_hssi_8g_rx_pcs + parameter pcs8g_rx_agg_block_sel = "", // same_smrt_pack|other_smrt_pack + parameter pcs8g_rx_auto_error_replacement = "", // dis_err_replace|en_err_replace + parameter pcs8g_rx_auto_speed_nego = "", // dis_asn|en_asn_g2_freq_scal + parameter pcs8g_rx_bist_ver = "", // dis_bist|incremental|cjpat|crpat + parameter pcs8g_rx_bist_ver_clr_flag = "", // dis_bist_clr_flag|en_bist_clr_flag + parameter pcs8g_rx_bit_reversal = "", // dis_bit_reversal|en_bit_reversal + parameter pcs8g_rx_bo_pad = 10'b0, + parameter pcs8g_rx_bo_pattern = 20'b0, + parameter pcs8g_rx_bypass_pipeline_reg = "", // dis_bypass_pipeline|en_bypass_pipeline + parameter pcs8g_rx_byte_deserializer = "", // dis_bds|en_bds_by_2|en_bds_by_2_det + parameter pcs8g_rx_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 pcs8g_rx_cdr_ctrl = "", // dis_cdr_ctrl|en_cdr_ctrl|en_cdr_ctrl_w_cid + parameter pcs8g_rx_cdr_ctrl_rxvalid_mask = "", // dis_rxvalid_mask|en_rxvalid_mask + parameter pcs8g_rx_cid_pattern = "", // cid_pattern_0|cid_pattern_1 + parameter pcs8g_rx_cid_pattern_len = 8'b0, + parameter pcs8g_rx_clkcmp_pattern_n = 20'b0, + parameter pcs8g_rx_clkcmp_pattern_p = 20'b0, + parameter pcs8g_rx_clock_gate_bds_dec_asn = "", // dis_bds_dec_asn_clk_gating|en_bds_dec_asn_clk_gating + parameter pcs8g_rx_clock_gate_bist = "", // dis_bist_clk_gating|en_bist_clk_gating + parameter pcs8g_rx_clock_gate_byteorder = "", // dis_byteorder_clk_gating|en_byteorder_clk_gating + parameter pcs8g_rx_clock_gate_cdr_eidle = "", // dis_cdr_eidle_clk_gating|en_cdr_eidle_clk_gating + parameter pcs8g_rx_clock_gate_dskw_rd = "", // dis_dskw_rdclk_gating|en_dskw_rdclk_gating + parameter pcs8g_rx_clock_gate_dw_dskw_wr = "", // dis_dw_dskw_wrclk_gating|en_dw_dskw_wrclk_gating + parameter pcs8g_rx_clock_gate_dw_pc_wrclk = "", // dis_dw_pc_wrclk_gating|en_dw_pc_wrclk_gating + parameter pcs8g_rx_clock_gate_dw_rm_rd = "", // dis_dw_rm_rdclk_gating|en_dw_rm_rdclk_gating + parameter pcs8g_rx_clock_gate_dw_rm_wr = "", // dis_dw_rm_wrclk_gating|en_dw_rm_wrclk_gating + parameter pcs8g_rx_clock_gate_dw_wa = "", // dis_dw_wa_clk_gating|en_dw_wa_clk_gating + parameter pcs8g_rx_clock_gate_pc_rdclk = "", // dis_pc_rdclk_gating|en_pc_rdclk_gating + parameter pcs8g_rx_clock_gate_prbs = "", // dis_prbs_clk_gating|en_prbs_clk_gating + parameter pcs8g_rx_clock_gate_sw_dskw_wr = "", // dis_sw_dskw_wrclk_gating|en_sw_dskw_wrclk_gating + parameter pcs8g_rx_clock_gate_sw_pc_wrclk = "", // dis_sw_pc_wrclk_gating|en_sw_pc_wrclk_gating + parameter pcs8g_rx_clock_gate_sw_rm_rd = "", // dis_sw_rm_rdclk_gating|en_sw_rm_rdclk_gating + parameter pcs8g_rx_clock_gate_sw_rm_wr = "", // dis_sw_rm_wrclk_gating|en_sw_rm_wrclk_gating + parameter pcs8g_rx_clock_gate_sw_wa = "", // dis_sw_wa_clk_gating|en_sw_wa_clk_gating + parameter pcs8g_rx_comp_fifo_rst_pld_ctrl = "", // dis_comp_fifo_rst_pld_ctrl|en_comp_fifo_rst_pld_ctrl + parameter pcs8g_rx_deskew = "", // dis_deskew|en_srio_v2p1|en_xaui + parameter pcs8g_rx_deskew_pattern = 10'b1101101000, + parameter pcs8g_rx_deskew_prog_pattern_only = "", // dis_deskew_prog_pat_only|en_deskew_prog_pat_only + parameter pcs8g_rx_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 pcs8g_rx_eidle_entry_eios = "", // dis_eidle_eios|en_eidle_eios + parameter pcs8g_rx_eidle_entry_iei = "", // dis_eidle_iei|en_eidle_iei + parameter pcs8g_rx_eidle_entry_sd = "", // dis_eidle_sd|en_eidle_sd + parameter pcs8g_rx_eightb_tenb_decoder = "", // dis_8b10b|en_8b10b_ibm|en_8b10b_sgx + parameter pcs8g_rx_eightbtenb_decoder_output_sel = "",// data_8b10b_decoder|data_xaui_sm + parameter pcs8g_rx_err_flags_sel = "", // err_flags_wa|err_flags_8b10b + parameter pcs8g_rx_fixed_pat_det = "", // dis_fixed_patdet|en_fixed_patdet + parameter pcs8g_rx_fixed_pat_num = 4'b1111, + parameter pcs8g_rx_force_signal_detect = "", // en_force_signal_detect|dis_force_signal_detect + parameter pcs8g_rx_hip_mode = "", // dis_hip|en_hip + parameter pcs8g_rx_ibm_invalid_code = "", // dis_ibm_invalid_code|en_ibm_invalid_code + parameter pcs8g_rx_invalid_code_flag_only = "", // dis_invalid_code_only|en_invalid_code_only + parameter pcs8g_rx_mask_cnt = 10'h3ff, + parameter pcs8g_rx_pad_or_edb_error_replace = "", // replace_edb|replace_pad|replace_edb_dynamic + parameter pcs8g_rx_pc_fifo_rst_pld_ctrl = "", // dis_pc_fifo_rst_pld_ctrl|en_pc_fifo_rst_pld_ctrl + parameter pcs8g_rx_pcs_bypass = "", // dis_pcs_bypass|en_pcs_bypass + parameter pcs8g_rx_phase_compensation_fifo = "", // low_latency|normal_latency|register_fifo|pld_ctrl_low_latency|pld_ctrl_normal_latency + parameter pcs8g_rx_pipe_if_enable = "", // dis_pipe_rx|en_pipe_rx + parameter pcs8g_rx_pma_done_count = 18'b0, + parameter pcs8g_rx_pma_dw = "", // eight_bit|ten_bit|sixteen_bit|twenty_bit + parameter pcs8g_rx_polarity_inversion = "", // dis_pol_inv|en_pol_inv + parameter pcs8g_rx_polinv_8b10b_dec = "", // dis_polinv_8b10b_dec|en_polinv_8b10b_dec + parameter pcs8g_rx_prbs_ver = "", // dis_prbs|prbs_7_sw|prbs_7_dw|prbs_8|prbs_10|prbs_23_sw|prbs_23_dw|prbs_15|prbs_31|prbs_hf_sw|prbs_hf_dw|prbs_lf_sw|prbs_lf_dw|prbs_mf_sw|prbs_mf_dw + parameter pcs8g_rx_prbs_ver_clr_flag = "", // dis_prbs_clr_flag|en_prbs_clr_flag + parameter pcs8g_rx_prot_mode = "", // pipe_g1|pipe_g2|cpri|cpri_rx_tx|gige|xaui|srio_2p1|test|basic|disabled_prot_mode + parameter pcs8g_rx_rate_match = "", // dis_rm|xaui_rm|gige_rm|pipe_rm|pipe_rm_0ppm|sw_basic_rm|srio_v2p1_rm|srio_v2p1_rm_0ppm|dw_basic_rm + parameter pcs8g_rx_re_bo_on_wa = "", // dis_re_bo_on_wa|en_re_bo_on_wa + parameter pcs8g_rx_runlength_check = "", // dis_runlength|en_runlength_sw|en_runlength_dw + parameter pcs8g_rx_runlength_val = 6'b0, + parameter pcs8g_rx_rx_clk1 = "", // rcvd_clk_clk1|tx_pma_clock_clk1|rcvd_clk_agg_clk1|rcvd_clk_agg_top_or_bottom_clk1 + parameter pcs8g_rx_rx_clk2 = "", // rcvd_clk_clk2|tx_pma_clock_clk2|refclk_dig2_clk2 + parameter pcs8g_rx_rx_clk_free_running = "", // dis_rx_clk_free_run|en_rx_clk_free_run + parameter pcs8g_rx_rx_pcs_urst = "", // dis_rx_pcs_urst|en_rx_pcs_urst + parameter pcs8g_rx_rx_rcvd_clk = "", // rcvd_clk_rcvd_clk|tx_pma_clock_rcvd_clk + parameter pcs8g_rx_rx_rd_clk = "", // pld_rx_clk|rx_clk + parameter pcs8g_rx_rx_refclk = "", // dis_refclk_sel|en_refclk_sel + parameter pcs8g_rx_rx_wr_clk = "", // rx_clk2_div_1_2_4|txfifo_rd_clk + parameter pcs8g_rx_sup_mode = "", // user_mode|engineering_mode + parameter pcs8g_rx_symbol_swap = "", // dis_symbol_swap|en_symbol_swap + parameter pcs8g_rx_test_bus_sel = "", // prbs_bist_testbus|tx_testbus|tx_ctrl_plane_testbus|wa_testbus|deskew_testbus|rm_testbus|rx_ctrl_testbus|pcie_ctrl_testbus|rx_ctrl_plane_testbus|agg_testbus + parameter pcs8g_rx_test_mode = "", // dont_care_test|prbs|bist + parameter pcs8g_rx_tx_rx_parallel_loopback = "", // dis_plpbk|en_plpbk + parameter pcs8g_rx_use_default_base_address = "true", // false|true + parameter pcs8g_rx_user_base_address = 0, // 0..2047 + parameter pcs8g_rx_wa_boundary_lock_ctrl = "", // bit_slip|sync_sm|deterministic_latency|auto_align_pld_ctrl + parameter pcs8g_rx_wa_clk_slip_spacing = "", // min_clk_slip_spacing|user_programmable_clk_slip_spacing + parameter pcs8g_rx_wa_clk_slip_spacing_data = 10'b10000, + parameter pcs8g_rx_wa_det_latency_sync_status_beh = "",// assert_sync_status_imm|assert_sync_status_non_imm|dont_care_assert_sync + parameter pcs8g_rx_wa_disp_err_flag = "", // dis_disp_err_flag|en_disp_err_flag + parameter pcs8g_rx_wa_kchar = "", // dis_kchar|en_kchar + parameter pcs8g_rx_wa_pd = "", // dont_care_wa_pd_0|dont_care_wa_pd_1|wa_pd_7|wa_pd_10|wa_pd_20|wa_pd_40|wa_pd_8_sw|wa_pd_8_dw|wa_pd_16_sw|wa_pd_16_dw|wa_pd_32|wa_pd_fixed_7_k28p5|wa_pd_fixed_10_k28p5|wa_pd_fixed_16_a1a2_sw|wa_pd_fixed_16_a1a2_dw|wa_pd_fixed_32_a1a1a2a2|prbs15_fixed_wa_pd_16_sw|prbs15_fixed_wa_pd_16_dw|prbs15_fixed_wa_pd_20_dw|prbs31_fixed_wa_pd_16_sw|prbs31_fixed_wa_pd_16_dw|prbs31_fixed_wa_pd_10_sw|prbs31_fixed_wa_pd_40_dw|prbs8_fixed_wa|prbs10_fixed_wa|prbs7_fixed_wa_pd_16_sw|prbs7_fixed_wa_pd_16_dw|prbs7_fixed_wa_pd_20_dw|prbs23_fixed_wa_pd_16_sw|prbs23_fixed_wa_pd_32_dw|prbs23_fixed_wa_pd_40_dw + parameter pcs8g_rx_wa_pd_data = 40'b0, + parameter pcs8g_rx_wa_pd_polarity = "", // dis_pd_both_pol|en_pd_both_pol|dont_care_both_pol + parameter pcs8g_rx_wa_pld_controlled = "", // dis_pld_ctrl|pld_ctrl_sw|rising_edge_sensitive_dw|level_sensitive_dw + parameter pcs8g_rx_wa_renumber_data = 6'b0, + parameter pcs8g_rx_wa_rgnumber_data = 8'b0, + parameter pcs8g_rx_wa_rknumber_data = 8'b0, + parameter pcs8g_rx_wa_rosnumber_data = 2'b0, + parameter pcs8g_rx_wa_rvnumber_data = 13'b0, + parameter pcs8g_rx_wa_sync_sm_ctrl = "", // gige_sync_sm|pipe_sync_sm|xaui_sync_sm|srio1p3_sync_sm|srio2p1_sync_sm|sw_basic_sync_sm|dw_basic_sync_sm|fibre_channel_sync_sm + parameter pcs8g_rx_wait_cnt = 8'b0, + // parameters for arriav_hssi_8g_tx_pcs + parameter pcs8g_tx_agg_block_sel = "", // same_smrt_pack|other_smrt_pack + parameter pcs8g_tx_auto_speed_nego_gen2 = "", // dis_asn_g2|en_asn_g2_freq_scal + parameter pcs8g_tx_bist_gen = "", // dis_bist|incremental|cjpat|crpat + parameter pcs8g_tx_bit_reversal = "", // dis_bit_reversal|en_bit_reversal + parameter pcs8g_tx_bypass_pipeline_reg = "", // dis_bypass_pipeline|en_bypass_pipeline + parameter pcs8g_tx_byte_serializer = "", // dis_bs|en_bs_by_2 + parameter pcs8g_tx_cid_pattern = "", // cid_pattern_0|cid_pattern_1 + parameter pcs8g_tx_cid_pattern_len = 8'b0, + parameter pcs8g_tx_clock_gate_bist = "", // dis_bist_clk_gating|en_bist_clk_gating + parameter pcs8g_tx_clock_gate_bs_enc = "", // dis_bs_enc_clk_gating|en_bs_enc_clk_gating + parameter pcs8g_tx_clock_gate_dw_fifowr = "", // dis_dw_fifowr_clk_gating|en_dw_fifowr_clk_gating + parameter pcs8g_tx_clock_gate_fiford = "", // dis_fiford_clk_gating|en_fiford_clk_gating + parameter pcs8g_tx_clock_gate_prbs = "", // dis_prbs_clk_gating|en_prbs_clk_gating + parameter pcs8g_tx_clock_gate_sw_fifowr = "", // dis_sw_fifowr_clk_gating|en_sw_fifowr_clk_gating + parameter pcs8g_tx_data_selection_8b10b_encoder_input = "",// normal_data_path|xaui_sm|gige_idle_conversion + parameter pcs8g_tx_dynamic_clk_switch = "", // dis_dyn_clk_switch|en_dyn_clk_switch + parameter pcs8g_tx_eightb_tenb_disp_ctrl = "", // dis_disp_ctrl|en_disp_ctrl|en_ib_disp_ctrl + parameter pcs8g_tx_eightb_tenb_encoder = "", // dis_8b10b|en_8b10b_ibm|en_8b10b_sgx + parameter pcs8g_tx_force_echar = "", // dis_force_echar|en_force_echar + parameter pcs8g_tx_force_kchar = "", // dis_force_kchar|en_force_kchar + parameter pcs8g_tx_hip_mode = "", // dis_hip|en_hip + parameter pcs8g_tx_pcfifo_urst = "", // dis_pcfifourst|en_pcfifourst + parameter pcs8g_tx_pcs_bypass = "", // dis_pcs_bypass|en_pcs_bypass + parameter pcs8g_tx_phase_compensation_fifo = "", // low_latency|normal_latency|register_fifo|pld_ctrl_low_latency|pld_ctrl_normal_latency + parameter pcs8g_tx_phfifo_write_clk_sel = "", // pld_tx_clk|tx_clk + parameter pcs8g_tx_pma_dw = "", // eight_bit|ten_bit|sixteen_bit|twenty_bit + parameter pcs8g_tx_polarity_inversion = "", // dis_polinv|enable_polinv + parameter pcs8g_tx_prbs_gen = "", // dis_prbs|prbs_7_sw|prbs_7_dw|prbs_8|prbs_10|prbs_23_sw|prbs_23_dw|prbs_15|prbs_31|prbs_hf_sw|prbs_hf_dw|prbs_lf_sw|prbs_lf_dw|prbs_mf_sw|prbs_mf_dw + parameter pcs8g_tx_prot_mode = "", // pipe_g1|pipe_g2|cpri|cpri_rx_tx|gige|xaui|srio_2p1|test|basic|disabled_prot_mode + parameter pcs8g_tx_refclk_b_clk_sel = "", // tx_pma_clock|refclk_dig + parameter pcs8g_tx_revloop_back_rm = "", // dis_rev_loopback_rx_rm|en_rev_loopback_rx_rm + parameter pcs8g_tx_sup_mode = "", // user_mode|engineering_mode + parameter pcs8g_tx_symbol_swap = "", // dis_symbol_swap|en_symbol_swap + parameter pcs8g_tx_test_mode = "", // dont_care_test|prbs|bist + parameter pcs8g_tx_tx_bitslip = "", // dis_tx_bitslip|en_tx_bitslip + parameter pcs8g_tx_tx_compliance_controlled_disparity = "",// dis_txcompliance|en_txcompliance_pipe2p0 + parameter pcs8g_tx_txclk_freerun = "", // dis_freerun_tx|en_freerun_tx + parameter pcs8g_tx_txpcs_urst = "", // dis_txpcs_urst|en_txpcs_urst + parameter pcs8g_tx_use_default_base_address = "true", // false|true + parameter pcs8g_tx_user_base_address = 0, // 0..2047 + // parameters for arriav_hssi_common_pcs_pma_interface + parameter com_pcs_pma_if_auto_speed_ena = "", // dis_auto_speed_ena|en_auto_speed_ena + parameter com_pcs_pma_if_force_freqdet = "", // force_freqdet_dis|force1_freqdet_en|force0_freqdet_en + parameter com_pcs_pma_if_func_mode = "", // disable|hrdrstctrl_cmu|eightg_only_pld|eightg_only_hip|pma_direct + parameter com_pcs_pma_if_pipe_if_g3pcs = "", // pipe_if_8gpcs + parameter com_pcs_pma_if_pma_if_dft_en = "dft_dis", // dft_dis + parameter com_pcs_pma_if_pma_if_dft_val = "dft_0", // dft_0 + parameter com_pcs_pma_if_ppm_cnt_rst = "", // ppm_cnt_rst_dis|ppm_cnt_rst_en + parameter com_pcs_pma_if_ppm_deassert_early = "", // deassert_early_dis|deassert_early_en + parameter com_pcs_pma_if_ppm_gen1_2_cnt = "", // cnt_32k|cnt_64k + parameter com_pcs_pma_if_ppm_post_eidle_delay = "",// cnt_200_cycles|cnt_400_cycles + parameter com_pcs_pma_if_ppmsel = "", // ppmsel_default|ppmsel_1000|ppmsel_500|ppmsel_300|ppmsel_250|ppmsel_200|ppmsel_125|ppmsel_100|ppmsel_62p5|ppm_other + parameter com_pcs_pma_if_prot_mode = "", // disabled_prot_mode|pipe_g1|pipe_g2|other_protocols + parameter com_pcs_pma_if_selectpcs = "", // eight_g_pcs + parameter com_pcs_pma_if_sup_mode = "", // user_mode|engineering_mode + parameter com_pcs_pma_if_use_default_base_address = "true", // false|true + parameter com_pcs_pma_if_user_base_address = 0, // 0..2047 + // parameters for arriav_hssi_common_pld_pcs_interface + parameter com_pld_pcs_if_hip_enable = "hip_disable", // hip_disable|hip_enable + parameter com_pld_pcs_if_hrdrstctrl_en_cfg = "hrst_dis_cfg", // hrst_dis_cfg|hrst_en_cfg + parameter com_pld_pcs_if_hrdrstctrl_en_cfgusr = "hrst_dis_cfgusr",// hrst_dis_cfgusr|hrst_en_cfgusr + parameter com_pld_pcs_if_pld_side_data_source = "pld", // hip|pld + parameter com_pld_pcs_if_pld_side_reserved_source0 = "pld_res0",// pld_res0|hip_res0 + parameter com_pld_pcs_if_pld_side_reserved_source1 = "pld_res1",// pld_res1|hip_res1 + parameter com_pld_pcs_if_pld_side_reserved_source10 = "pld_res10",// pld_res10|hip_res10 + parameter com_pld_pcs_if_pld_side_reserved_source11 = "pld_res11",// pld_res11|hip_res11 + parameter com_pld_pcs_if_pld_side_reserved_source2 = "pld_res2",// pld_res2|hip_res2 + parameter com_pld_pcs_if_pld_side_reserved_source3 = "pld_res3",// pld_res3|hip_res3 + parameter com_pld_pcs_if_pld_side_reserved_source4 = "pld_res4",// pld_res4|hip_res4 + parameter com_pld_pcs_if_pld_side_reserved_source5 = "pld_res5",// pld_res5|hip_res5 + parameter com_pld_pcs_if_pld_side_reserved_source6 = "pld_res6",// pld_res6|hip_res6 + parameter com_pld_pcs_if_pld_side_reserved_source7 = "pld_res7",// pld_res7|hip_res7 + parameter com_pld_pcs_if_pld_side_reserved_source8 = "pld_res8",// pld_res8|hip_res8 + parameter com_pld_pcs_if_pld_side_reserved_source9 = "pld_res9",// pld_res9|hip_res9 + parameter com_pld_pcs_if_testbus_sel = "eight_g_pcs", // eight_g_pcs|pma_if + parameter com_pld_pcs_if_use_default_base_address = "true", // false|true + parameter com_pld_pcs_if_user_base_address = 0, // 0..2047 + parameter com_pld_pcs_if_usrmode_sel4rst = "usermode", // usermode|last_frz + // parameters for arriav_hssi_pipe_gen1_2 + parameter pipe12_elec_idle_delay_val = 3'b0, + parameter pipe12_elecidle_delay = "elec_idle_delay", // elec_idle_delay + parameter pipe12_error_replace_pad = "", // replace_edb|replace_pad + parameter pipe12_hip_mode = "", // dis_hip|en_hip + parameter pipe12_ind_error_reporting = "", // dis_ind_error_reporting|en_ind_error_reporting + parameter pipe12_phy_status_delay = "phystatus_delay", // phystatus_delay + parameter pipe12_phystatus_delay_val = 3'b0, + parameter pipe12_phystatus_rst_toggle = "", // dis_phystatus_rst_toggle|en_phystatus_rst_toggle + parameter pipe12_pipe_byte_de_serializer_en = "", // dis_bds|en_bds_by_2|dont_care_bds + parameter pipe12_prot_mode = "", // pipe_g1|pipe_g2|srio_2p1|basic|disabled_prot_mode + parameter pipe12_rpre_emph_a_val = 6'b0, + parameter pipe12_rpre_emph_b_val = 6'b0, + parameter pipe12_rpre_emph_c_val = 6'b0, + parameter pipe12_rpre_emph_d_val = 6'b0, + parameter pipe12_rpre_emph_e_val = 6'b0, + parameter pipe12_rpre_emph_settings = 6'b0, + parameter pipe12_rvod_sel_a_val = 6'b0, + parameter pipe12_rvod_sel_b_val = 6'b0, + parameter pipe12_rvod_sel_c_val = 6'b0, + parameter pipe12_rvod_sel_d_val = 6'b0, + parameter pipe12_rvod_sel_e_val = 6'b0, + parameter pipe12_rvod_sel_settings = 6'b0, + parameter pipe12_rx_pipe_enable = "", // dis_pipe_rx|en_pipe_rx + parameter pipe12_rxdetect_bypass = "", // dis_rxdetect_bypass|en_rxdetect_bypass + parameter pipe12_sup_mode = "user_mode", // user_mode|engineering_mode + parameter pipe12_tx_pipe_enable = "", // dis_pipe_tx|en_pipe_tx + parameter pipe12_txswing = "", // dis_txswing|en_txswing + parameter pipe12_use_default_base_address = "true", // false|true + parameter pipe12_user_base_address = 0, // 0..2047 + // parameters for arriav_hssi_rx_pcs_pma_interface + parameter rx_pcs_pma_if_clkslip_sel = "", // pld|slip_eight_g_pcs + parameter rx_pcs_pma_if_prot_mode = "", // other_protocols|cpri_8g + parameter rx_pcs_pma_if_selectpcs = "eight_g_pcs", // eight_g_pcs|default + parameter rx_pcs_pma_if_use_default_base_address = "true", // false|true + parameter rx_pcs_pma_if_user_base_address = 0, // 0..2047 + // parameters for arriav_hssi_rx_pld_pcs_interface + parameter rx_pld_pcs_if_is_8g_0ppm = "false", // false|true + parameter rx_pld_pcs_if_pcs_side_block_sel = "eight_g_pcs", // eight_g_pcs|default + parameter rx_pld_pcs_if_pld_side_data_source = "pld", // hip|pld + parameter rx_pld_pcs_if_use_default_base_address = "true", // false|true + parameter rx_pld_pcs_if_user_base_address = 0, // 0..2047 + // parameters for arriav_hssi_tx_pcs_pma_interface + parameter tx_pcs_pma_if_selectpcs = "eight_g_pcs", // eight_g_pcs|default + parameter tx_pcs_pma_if_use_default_base_address = "true", // false|true + parameter tx_pcs_pma_if_user_base_address = 0, // 0..2047 + // parameters for arriav_hssi_tx_pld_pcs_interface + parameter tx_pld_pcs_if_is_8g_0ppm = "false", // false|true + parameter tx_pld_pcs_if_pld_side_data_source = "pld", // hip|pld + parameter tx_pld_pcs_if_use_default_base_address = "true", // false|true + parameter tx_pld_pcs_if_user_base_address = 0, // 0..2047 + + // av_xcvr_avmm parameters + parameter bonded_lanes = 1, // Number of lanes + parameter pma_reserved_ch = "-1", // Indicates which channels are reserved + // PMA enables + // PCS enables + // Services requests + parameter request_dcd = 1, // Request Duty Cycle Distortion correction at startup + parameter request_vrc = 0, // Request Voltage Regulator Calibration at startup + parameter request_offset = 1, // Request RX Offset Cancellation at startup - defaults to enabled, only PCIE w/HIP should unset this + // CvP IOCSR control - cvp_update + parameter cvp_en_iocsr = "false" // valid values = "true", "false" + )( + + // av_pma ports + // TX/RX ports + // RX ports + input wire [bonded_lanes - 1 : 0] rx_datain, // RX serial data input + input wire [bonded_lanes*cdr_refclk_cnt-1:0] rx_cdr_ref_clk, // Reference clock for CDR + input wire [bonded_lanes - 1 : 0] rx_ltd, // Force lock-to-data stream + output wire [bonded_lanes - 1 : 0] rx_clkdivrx, // RX parallel clock output + output wire [bonded_lanes*80-1: 0] rx_dataout, // RX parallel data output + output wire [bonded_lanes - 1 : 0] rx_is_lockedtodata, // Indicates lock to incoming data rate + output wire [bonded_lanes - 1 : 0] rx_is_lockedtoref, // Indicates lock to reference clock + output wire [bonded_lanes - 1 : 0] out_pcs_signal_ok, + // TX ports + //input port for buf + input wire tx_rxdetclk, // Clock for detection of downstream receiver (125MHz ?) + //output port for buf + output wire [bonded_lanes - 1 : 0] tx_dataout, // TX serial data output + //input ports for ser + input wire tx_rstn, // TODO - Examine resets + //output ports for ser + output wire [bonded_lanes - 1 : 0] tx_clkdivtx, // TX parallel clock output + //input ports for cgb + input wire [bonded_lanes*plls-1:0] tx_ser_clk, // High-speed serial clock(s) from PLL + input wire tx_pcsrstn, + input wire tx_fref, + input wire [bonded_lanes*plls-1:0] tx_rstn_cgb_master, + input wire [bonded_lanes - 1 : 0] tx_cpulsein, + input wire [bonded_lanes - 1 : 0] tx_hclkin, + input wire [bonded_lanes - 1 : 0] tx_lfclkin, + input wire [bonded_lanes*3-1 : 0] tx_pclkin, + //output ports for cgb + // AVMM ports + + // av_pcs ports + input wire [bonded_lanes - 1:0] in_agg_align_status, + input wire [bonded_lanes - 1:0] in_agg_align_status_sync_0, + input wire [bonded_lanes - 1:0] in_agg_align_status_sync_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_align_status_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_rd_d_all, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_rd_d_all_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_wr_all, + input wire [bonded_lanes - 1:0] in_agg_cg_comp_wr_all_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_del_cond_met_0, + input wire [bonded_lanes - 1:0] in_agg_del_cond_met_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_qd, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_qd_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_rd_ptrs, + input wire [bonded_lanes - 1:0] in_agg_en_dskw_rd_ptrs_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_fifo_ovr_0, + input wire [bonded_lanes - 1:0] in_agg_fifo_ovr_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_fifo_rd_in_comp_0, + input wire [bonded_lanes - 1:0] in_agg_fifo_rd_in_comp_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_fifo_rst_rd_qd, + input wire [bonded_lanes - 1:0] in_agg_fifo_rst_rd_qd_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_insert_incomplete_0, + input wire [bonded_lanes - 1:0] in_agg_insert_incomplete_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_latency_comp_0, + input wire [bonded_lanes - 1:0] in_agg_latency_comp_0_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_rcvd_clk_agg, + input wire [bonded_lanes - 1:0] in_agg_rcvd_clk_agg_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_rx_control_rs, + input wire [bonded_lanes - 1:0] in_agg_rx_control_rs_top_or_bot, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_rx_data_rs, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_rx_data_rs_top_or_bot, + input wire [bonded_lanes - 1:0] in_agg_test_so_to_pld_in, + input wire [bonded_lanes * 16 - 1 : 0] in_agg_testbus, + input wire [bonded_lanes - 1:0] in_agg_tx_ctl_ts, + input wire [bonded_lanes - 1:0] in_agg_tx_ctl_ts_top_or_bot, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_tx_data_ts, + input wire [bonded_lanes * 8 - 1 : 0] in_agg_tx_data_ts_top_or_bot, + input wire [bonded_lanes * 38 - 1 : 0] in_emsip_com_in, + input wire [bonded_lanes * 13 - 1 : 0] in_emsip_rx_special_in, + input wire [bonded_lanes * 104 - 1 : 0] in_emsip_tx_in, + input wire [bonded_lanes * 13 - 1 : 0] in_emsip_tx_special_in, + input wire [bonded_lanes - 1:0] in_pld_8g_a1a2_size, + input wire [bonded_lanes - 1:0] in_pld_8g_bitloc_rev_en, + input wire [bonded_lanes - 1:0] in_pld_8g_bitslip, + input wire [bonded_lanes - 1:0] in_pld_8g_byte_rev_en, + input wire [bonded_lanes - 1:0] in_pld_8g_bytordpld, + input wire [bonded_lanes - 1:0] in_pld_8g_cmpfifourst_n, + input wire [bonded_lanes - 1:0] in_pld_8g_encdt, + input wire [bonded_lanes - 1:0] in_pld_8g_phfifourst_rx_n, + input wire [bonded_lanes - 1:0] in_pld_8g_phfifourst_tx_n, + input wire [bonded_lanes - 1:0] in_pld_8g_pld_tx_clk, + input wire [bonded_lanes - 1:0] in_pld_8g_polinv_rx, + input wire [bonded_lanes - 1:0] in_pld_8g_polinv_tx, + input wire [bonded_lanes * 2 - 1 : 0] in_pld_8g_powerdown, + input wire [bonded_lanes - 1:0] in_pld_8g_prbs_cid_en, + input wire [bonded_lanes - 1:0] in_pld_8g_rddisable_tx, + input wire [bonded_lanes - 1:0] in_pld_8g_rdenable_rmf, + input wire [bonded_lanes - 1:0] in_pld_8g_rdenable_rx, + input wire [bonded_lanes - 1:0] in_pld_8g_refclk_dig, + input wire [bonded_lanes - 1:0] in_pld_8g_refclk_dig2, + input wire [bonded_lanes - 1:0] in_pld_8g_rev_loopbk, + input wire [bonded_lanes - 1:0] in_pld_8g_rxpolarity, + input wire [bonded_lanes * 5 - 1 : 0] in_pld_8g_tx_boundary_sel, + input wire [bonded_lanes * 4 - 1 : 0] in_pld_8g_tx_data_valid, + input wire [bonded_lanes - 1:0] in_pld_8g_txdeemph, + input wire [bonded_lanes - 1:0] in_pld_8g_txdetectrxloopback, + input wire [bonded_lanes - 1:0] in_pld_8g_txelecidle, + input wire [bonded_lanes * 3 - 1 : 0] in_pld_8g_txmargin, + input wire [bonded_lanes - 1:0] in_pld_8g_txswing, + input wire [bonded_lanes - 1:0] in_pld_8g_wrdisable_rx, + input wire [bonded_lanes - 1:0] in_pld_8g_wrenable_rmf, + input wire [bonded_lanes - 1:0] in_pld_8g_wrenable_tx, + input wire [bonded_lanes - 1:0] in_pld_agg_refclk_dig, + input wire [bonded_lanes * 3 - 1 : 0] in_pld_eidleinfersel, + input wire [bonded_lanes - 1:0] in_pld_ltr, + input wire [bonded_lanes - 1:0] in_pld_partial_reconfig_in, + input wire [bonded_lanes - 1:0] in_pld_pcs_pma_if_refclk_dig, + input wire [bonded_lanes - 1:0] in_pld_rate, + input wire [bonded_lanes * 12 - 1 : 0] in_pld_reserved_in, + input wire [bonded_lanes - 1:0] in_pld_rx_clk_slip_in, + input wire [bonded_lanes - 1:0] in_pld_scan_mode_n, + input wire [bonded_lanes - 1:0] in_pld_scan_shift_n, + input wire [bonded_lanes - 1:0] in_pld_sync_sm_en, + input wire [bonded_lanes * 44 - 1 : 0] in_pld_tx_data, + input wire [bonded_lanes * 80 - 1 : 0] in_pld_tx_pma_data, + input wire [bonded_lanes - 1:0] in_pma_hclk, + input wire [bonded_lanes * 5 - 1 : 0] in_pma_reserved_in, + input wire [bonded_lanes - 1:0] in_pma_rx_freq_tx_cmu_pll_lock_in, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_align_det_sync, + output wire [bonded_lanes - 1:0] out_agg_align_status_sync, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_cg_comp_rd_d_out, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_cg_comp_wr_out, + output wire [bonded_lanes - 1:0] out_agg_dec_ctl, + output wire [bonded_lanes * 8 - 1 : 0] out_agg_dec_data, + output wire [bonded_lanes - 1:0] out_agg_dec_data_valid, + output wire [bonded_lanes - 1:0] out_agg_del_cond_met_out, + output wire [bonded_lanes - 1:0] out_agg_fifo_ovr_out, + output wire [bonded_lanes - 1:0] out_agg_fifo_rd_out_comp, + output wire [bonded_lanes - 1:0] out_agg_insert_incomplete_out, + output wire [bonded_lanes - 1:0] out_agg_latency_comp_out, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_rd_align, + output wire [bonded_lanes - 1:0] out_agg_rd_enable_sync, + output wire [bonded_lanes - 1:0] out_agg_refclk_dig, + output wire [bonded_lanes * 2 - 1 : 0] out_agg_running_disp, + output wire [bonded_lanes - 1:0] out_agg_rxpcs_rst, + output wire [bonded_lanes - 1:0] out_agg_scan_mode_n, + output wire [bonded_lanes - 1:0] out_agg_scan_shift_n, + output wire [bonded_lanes - 1:0] out_agg_sync_status, + output wire [bonded_lanes - 1:0] out_agg_tx_ctl_tc, + output wire [bonded_lanes * 8 - 1 : 0] out_agg_tx_data_tc, + output wire [bonded_lanes - 1:0] out_agg_txpcs_rst, + output wire [bonded_lanes * 3 - 1 : 0] out_emsip_com_clk_out, + output wire [bonded_lanes * 27 - 1 : 0] out_emsip_com_out, + output wire [bonded_lanes * 129 - 1 : 0] out_emsip_rx_out, + output wire [bonded_lanes * 16 - 1 : 0] out_emsip_rx_special_out, + output wire [bonded_lanes * 3 - 1 : 0] out_emsip_tx_clk_out, + output wire [bonded_lanes * 16 - 1 : 0] out_emsip_tx_special_out, + output wire [bonded_lanes * 4 - 1 : 0] out_pld_8g_a1a2_k1k2_flag, + output wire [bonded_lanes - 1:0] out_pld_8g_align_status, + output wire [bonded_lanes - 1:0] out_pld_8g_bistdone, + output wire [bonded_lanes - 1:0] out_pld_8g_bisterr, + output wire [bonded_lanes - 1:0] out_pld_8g_byteord_flag, + output wire [bonded_lanes - 1:0] out_pld_8g_empty_rmf, + output wire [bonded_lanes - 1:0] out_pld_8g_empty_rx, + output wire [bonded_lanes - 1:0] out_pld_8g_empty_tx, + output wire [bonded_lanes - 1:0] out_pld_8g_full_rmf, + output wire [bonded_lanes - 1:0] out_pld_8g_full_rx, + output wire [bonded_lanes - 1:0] out_pld_8g_full_tx, + output wire [bonded_lanes - 1:0] out_pld_8g_phystatus, + output wire [bonded_lanes - 1:0] out_pld_8g_rlv_lt, + output wire [bonded_lanes - 1:0] out_pld_8g_rx_clk_out, + output wire [bonded_lanes * 4 - 1 : 0] out_pld_8g_rx_data_valid, + output wire [bonded_lanes - 1:0] out_pld_8g_rxelecidle, + output wire [bonded_lanes * 3 - 1 : 0] out_pld_8g_rxstatus, + output wire [bonded_lanes - 1:0] out_pld_8g_rxvalid, + output wire [bonded_lanes - 1:0] out_pld_8g_signal_detect_out, + output wire [bonded_lanes - 1:0] out_pld_8g_tx_clk_out, + output wire [bonded_lanes * 5 - 1 : 0] out_pld_8g_wa_boundary, + output wire [bonded_lanes - 1:0] out_pld_clklow, + output wire [bonded_lanes - 1:0] out_pld_fref, + output wire [bonded_lanes * 11 - 1 : 0] out_pld_reserved_out, + output wire [bonded_lanes * 64 - 1 : 0] out_pld_rx_data, + output wire [bonded_lanes * 20 - 1 : 0] out_pld_test_data, + output wire [bonded_lanes - 1:0] out_pld_test_si_to_agg_out, + output wire [bonded_lanes * 12 - 1 : 0] out_pma_current_coeff, + output wire [bonded_lanes - 1:0] out_pma_nfrzdrv, + output wire [bonded_lanes - 1:0] out_pma_partial_reconfig, + output wire [bonded_lanes - 1:0] out_pma_ppm_lock, + output wire [bonded_lanes * 5 - 1 : 0] out_pma_reserved_out, + output wire [bonded_lanes - 1:0] out_pma_rx_clk_out, + output wire [bonded_lanes - 1:0] out_pma_tx_clk_out, + + // av_xcvr_avmm ports + // Reconfiguration signal bundles + input wire [bonded_lanes*W_S5_RECONFIG_BUNDLE_TO_XCVR -1:0] reconfig_to_xcvr, + output wire [bonded_lanes*W_S5_RECONFIG_BUNDLE_FROM_XCVR-1:0] reconfig_from_xcvr, + // Control inputs from PLD + input wire [bonded_lanes-1 :0] seriallpbken, // 1 = enable serial loopback + // PCS clocks + input wire [bonded_lanes-1 :0] in_pld_8g_pld_rx_clk, // 8g PCS RX clock + // PCS resets + input wire [bonded_lanes-1 :0] in_pld_8g_txurstpcs_n, // 8g PCS TX reset + input wire [bonded_lanes-1 :0] in_pld_8g_rxurstpcs_n, // 8g PCS RX reset + // PMA resets + input wire [bonded_lanes-1 :0] rx_crurstn, // CDR analog reset (active low) + input wire [bonded_lanes-1 :0] in_pld_rxpma_rstb_in, + // PCS data + // Calibration clocks + //calibration status + output wire [bonded_lanes-1 :0] tx_cal_busy, + output wire [bonded_lanes-1 :0] rx_cal_busy, + output wire [bonded_lanes-1 :0] rx_sd +); + + + wire [bonded_lanes - 1 : 0] rx_clklow; + wire [bonded_lanes - 1 : 0] rx_fref; + wire [bonded_lanes - 1 : 0] out_pcs_rx_pll_phase_lock_out; + wire [bonded_lanes - 1 : 0] tx_rxdetectvalid; + wire [bonded_lanes - 1 : 0] tx_rxfound; + wire [bonded_lanes -1 : 0] tx_pcieswdone; + wire [(bonded_lanes*16)-1:0 ] pma_avmmreaddata_tx_cgb; + wire [(bonded_lanes*16)-1:0 ] pma_avmmreaddata_tx_ser; + wire [(bonded_lanes*16)-1:0 ] pma_avmmreaddata_tx_buf; + wire [(bonded_lanes*16)-1:0 ] pma_avmmreaddata_rx_ser; + wire [(bonded_lanes*16)-1:0 ] pma_avmmreaddata_rx_buf; + wire [(bonded_lanes*16)-1:0 ] pma_avmmreaddata_rx_cdr; + wire [(bonded_lanes*16)-1:0 ] pma_avmmreaddata_rx_mux; + wire [bonded_lanes-1:0 ] pma_blockselect_tx_cgb; + wire [bonded_lanes-1:0 ] pma_blockselect_tx_ser; + wire [bonded_lanes-1:0 ] pma_blockselect_tx_buf; + wire [bonded_lanes-1:0 ] pma_blockselect_rx_ser; + wire [bonded_lanes-1:0 ] pma_blockselect_rx_buf; + wire [bonded_lanes-1:0 ] pma_blockselect_rx_cdr; + wire [bonded_lanes-1:0 ] pma_blockselect_rx_mux; + wire [bonded_lanes-1:0 ] pll_aux_atb_comp_out; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_com_pcs_pma_if; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_com_pld_pcs_if; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_pcs8g_rx; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_pcs8g_tx; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_pipe12; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_rx_pcs_pma_if; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_rx_pld_pcs_if; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_tx_pcs_pma_if; + wire [bonded_lanes * 16 - 1 : 0] out_avmmreaddata_tx_pld_pcs_if; + wire [bonded_lanes - 1:0] out_blockselect_com_pcs_pma_if; + wire [bonded_lanes - 1:0] out_blockselect_com_pld_pcs_if; + wire [bonded_lanes - 1:0] out_blockselect_pcs8g_rx; + wire [bonded_lanes - 1:0] out_blockselect_pcs8g_tx; + wire [bonded_lanes - 1:0] out_blockselect_pipe12; + wire [bonded_lanes - 1:0] out_blockselect_rx_pcs_pma_if; + wire [bonded_lanes - 1:0] out_blockselect_rx_pld_pcs_if; + wire [bonded_lanes - 1:0] out_blockselect_tx_pcs_pma_if; + wire [bonded_lanes - 1:0] out_blockselect_tx_pld_pcs_if; + wire [bonded_lanes - 1:0] out_pma_early_eios; + wire [bonded_lanes - 1:0] out_pma_ltr; + wire [bonded_lanes - 1:0] out_pma_pcie_switch; + wire [bonded_lanes - 1:0] out_pma_rxclkslip; + wire [bonded_lanes - 1:0] out_pma_rxpma_rstb; + wire [bonded_lanes * 20 - 1 : 0] out_pma_tx_data; + wire [bonded_lanes - 1:0] out_pma_tx_elec_idle; + wire [bonded_lanes - 1:0] out_pma_txdetectrx; + wire [bonded_lanes-1 :0] out_pld_8g_txurstpcs_n; + wire [bonded_lanes-1 :0] out_pld_8g_rxurstpcs_n; + wire [bonded_lanes-1 :0] out_rx_crurstn; + wire [bonded_lanes-1 :0] out_pld_rxpma_rstb_in; + wire calclk; + wire [bonded_lanes-1 :0] pma_hardoccalen; + wire [bonded_lanes-1 :0] pma_seriallpbken; + wire [bonded_lanes-1 :0] chnl_avmm_clk; + wire [bonded_lanes-1 :0] chnl_avmm_rstn; + wire [bonded_lanes*16-1 :0] chnl_avmm_writedata; + wire [bonded_lanes*11-1 :0] chnl_avmm_address; + wire [bonded_lanes-1 :0] chnl_avmm_write; + wire [bonded_lanes-1 :0] chnl_avmm_read; + wire [bonded_lanes*2-1 :0] chnl_avmm_byteen; + wire [((pma_prot_mode == "pma direct") ? (bonded_lanes*80) : (bonded_lanes*20))-1: 0] rx_dataout_int; + wire [bonded_lanes*20-1: 0] in_pma_rx_data; + wire [bonded_lanes-1 :0] hardoccalen_av_only; +generate + if ( (device_family == "Arria V") || (device_family == "Cyclone V")) + assign hardoccalen_av_only = pma_hardoccalen ; + else + assign hardoccalen_av_only = {bonded_lanes{1'b0}}; + endgenerate + + // Following for PMA Direct, if PMA direct mode then 80 bit data directly from PMA + // otherwise 64 bit data from PCS + generate + genvar num_ch; + + if (pma_prot_mode == "pma direct") + begin + assign rx_dataout = rx_dataout_int; + + for (num_ch=0; num_ch < bonded_lanes; num_ch = num_ch + 1) + begin:in_pma_rx_data_inst + assign in_pma_rx_data[num_ch*20 +: 20] = rx_dataout_int[80*num_ch +: 20]; + end + end + else + begin + assign rx_dataout = 80'b0; + assign in_pma_rx_data = rx_dataout_int; + end + + endgenerate + + av_pma #( + .rx_enable (rx_enable ), // (1,0) Enable or disable reciever PMA + .tx_enable (tx_enable ), // (1,0) Enable or disable transmitter PMA + .bonded_lanes (bonded_lanes ), // Number of bonded lanes + .bonding_master_ch (bonding_master_ch ), // Indicates which channel is master + .pma_bonding_master (pma_bonding_master ), // (List i.e. "0,3,..."), Indicates which channels is master + .bonding_master_only (bonding_master_only ), // Indicates bonding_master_channel is MASTER_ONLY + .channel_number (channel_number ), // + .plls (plls ), // (1+) Number of high-speed serial clocks from TX plls (tx_ser_clk) + .pll_sel (pll_sel ), // (0 - plls-1) // Which PLL clock to use + .pma_prot_mode (pma_prot_mode ), // (basic,cpri,cpri_rx_tx,disabled_prot_mode,gige, pipe_g1,pipe_g2,srio_2p1,test,xaui) + .pma_mode (pma_mode ), // (8,10,16,20,32,40,64,80) Serialization factor + .base_data_rate (base_data_rate ), // Base data rate for CGB + .pma_data_rate (pma_data_rate ), // Serial data rate in bits-per-second + .cdr_reconfig (cdr_reconfig ), // 1-Enable CDR reconfiguration, 0-Disable CDR reconfiguration + .cdr_reference_clock_frequency (cdr_reference_clock_frequency ), + .cdr_refclk_cnt (cdr_refclk_cnt ), + .cdr_refclk_sel (cdr_refclk_sel ), // Initial CDR reference clock selection + .deser_enable_bit_slip (deser_enable_bit_slip ), + .auto_negotiation (auto_negotiation ), // ("true","false") PCIe Auto-Negotiation (Gen1,2,3) + .tx_clk_div (tx_clk_div ), // (1,2,4,8) + .pcie_rst (pcie_rst ), + .fref_vco_bypass (fref_vco_bypass ), + .sd_on (sd_on ), + .pdb_sd (pdb_sd ), + .pma_bonding_mode (pma_bonding_mode ), // valid value "x1", "xN" + .external_master_cgb (external_master_cgb ), + .cvp_en_iocsr (cvp_en_iocsr ) + ) inst_av_pma ( + // TX/RX ports + .calclk (calclk ), // Calibration clock (to aux block) + .seriallpbken (pma_seriallpbken ), // 1 = enable serial loopback + .pciesw (out_pma_pcie_switch ), // PCIe generation select + // RX ports + .rx_rstn (out_pma_rxpma_rstb ), // Active low digital reset for (deserializer, CDR, RX buf) + .rx_crurstn (out_rx_crurstn ), // CDR analog reset (active low) + .rx_datain (rx_datain ), // RX serial data input + .rx_bslip (out_pma_rxclkslip ), // PMA bitslip. Slips one clock cycle (2 UI of data) + .rx_cdr_ref_clk (rx_cdr_ref_clk ), // Reference clock for CDR + .rx_ltr (out_pma_ltr ), // Force lock-to_reference clock + .rx_ltd (rx_ltd ), // Force lock-to-data stream + .rx_freqlock (out_pma_ppm_lock ), // frequency lock detector input (external PPM detector) + .rx_earlyeios (out_pma_early_eios ), // Early electricle idle ordered sequence + .rx_hardoccalen (hardoccalen_av_only ), // Enable Offset cancellation + .rx_clkdivrx (rx_clkdivrx ), // RX parallel clock output + .rx_dataout (rx_dataout_int ), // RX parallel data output + .rx_sd (rx_sd ), // RX signal detect + .rx_clklow (rx_clklow ), // RX low frequency recovered clock + .rx_fref (rx_fref ), // RX PFD reference clock (rx_cdr_refclk after divider) + .rx_is_lockedtodata (rx_is_lockedtodata ), // Indicates lock to incoming data rate + .rx_is_lockedtoref (rx_is_lockedtoref ), // Indicates lock to reference clock + .out_pcs_signal_ok (out_pcs_signal_ok ), + .out_pcs_rx_pll_phase_lock_out (out_pcs_rx_pll_phase_lock_out ), + // TX ports + //input port for buf + .tx_datain ((pma_prot_mode == "pma direct") ? in_pld_tx_pma_data : out_pma_tx_data ), // TX parallel data input + .tx_txelecidl (out_pma_tx_elec_idle ), // TX force electricle idle + .tx_rxdetclk (tx_rxdetclk ), // Clock for detection of downstream receiver (125MHz ?) + .tx_txdetrx (out_pma_txdetectrx ), // 1 = enable downstream receiver detection + //output port for buf + .tx_dataout (tx_dataout ), // TX serial data output + .tx_rxdetectvalid (tx_rxdetectvalid ), // Indicates corresponding tx_rxfound signal contains valid data + .tx_rxfound (tx_rxfound ), // Indicates downnstream receiver is detected (qualify with tx_rxdetectvalid) + //input ports for ser + .tx_rstn (tx_rstn ), // TODO - Examine resets + //output ports for ser + .tx_clkdivtx (tx_clkdivtx ), // TX parallel clock output + //input ports for cgb + .tx_ser_clk (tx_ser_clk ), // High-speed serial clock(s) from PLL + .tx_pcsrstn (tx_pcsrstn ), + .tx_fref (tx_fref ), + .tx_rstn_cgb_master (tx_rstn_cgb_master ), + .tx_cpulsein (tx_cpulsein ), + .tx_hclkin (tx_hclkin ), + .tx_lfclkin (tx_lfclkin ), + .tx_pclkin (tx_pclkin ), + //output ports for cgb + .tx_pcieswdone (tx_pcieswdone ), // Inidicates PMA has accepted value on pciesw input. + // AVMM ports + .pma_avmmrstn (chnl_avmm_rstn ), // one for each lane + .pma_avmmclk (chnl_avmm_clk ), // one for each lane + .pma_avmmwrite (chnl_avmm_write ), // one for each lane + .pma_avmmread (chnl_avmm_read ), // one for each lane + .pma_avmmbyteen (chnl_avmm_byteen ), // two for each lane + .pma_avmmaddress (chnl_avmm_address ), // 11 for each lane + .pma_avmmwritedata (chnl_avmm_writedata ), // 16 for each lane + .pma_avmmreaddata_tx_cgb (pma_avmmreaddata_tx_cgb ), // TX AVMM CGB readdata (16 for each lane) + .pma_avmmreaddata_tx_ser (pma_avmmreaddata_tx_ser ), // TX AVMM SER readdata (16 for each lane) + .pma_avmmreaddata_tx_buf (pma_avmmreaddata_tx_buf ), // TX AVMM BUF readdata (16 for each lane) + .pma_avmmreaddata_rx_ser (pma_avmmreaddata_rx_ser ), // RX AVMM SER readdata (16 for each lane) + .pma_avmmreaddata_rx_buf (pma_avmmreaddata_rx_buf ), // RX AVMM BUF readdata (16 for each lane) + .pma_avmmreaddata_rx_cdr (pma_avmmreaddata_rx_cdr ), // RX AVMM CDR readdata (16 for each lane) + .pma_avmmreaddata_rx_mux (pma_avmmreaddata_rx_mux ), // RX AVMM CDR MUX readdata (16 for each lane) + .pma_blockselect_tx_cgb (pma_blockselect_tx_cgb ), // TX AVMM CGB blockselect (1 for each lane) + .pma_blockselect_tx_ser (pma_blockselect_tx_ser ), // TX AVMM SER blockselect (1 for each lane) + .pma_blockselect_tx_buf (pma_blockselect_tx_buf ), // TX AVMM BUF blockselect (1 for each lane) + .pma_blockselect_rx_ser (pma_blockselect_rx_ser ), // RX AVMM SER blockselect (1 for each lane) + .pma_blockselect_rx_buf (pma_blockselect_rx_buf ), // RX AVMM BUF blockselect (1 for each lane) + .pma_blockselect_rx_cdr (pma_blockselect_rx_cdr ), // RX AVMM SER blockselect (1 for each lane) + .pma_blockselect_rx_mux (pma_blockselect_rx_mux ), // RX AVMM BUF blockselect (1 for each lane) + .pll_aux_atb_comp_out (pll_aux_atb_comp_out ) // Voltage comparator output for DCD (1 for each lane) +); + + + av_pcs #( + .bonded_lanes (bonded_lanes ), + .bonding_master_ch (bonding_master_ch ), + .enable_8g_rx (enable_8g_rx ), + .enable_8g_tx (enable_8g_tx ), + .enable_pma_direct_tx (enable_pma_direct_tx ), + .enable_pma_direct_rx (enable_pma_direct_rx ), + .enable_dyn_reconfig (enable_dyn_reconfig ), + .enable_gen12_pipe (enable_gen12_pipe ), + .channel_number (channel_number ), + // parameters for arriav_hssi_8g_rx_pcs + .pcs8g_rx_agg_block_sel (pcs8g_rx_agg_block_sel ), // same_smrt_pack|other_smrt_pack + .pcs8g_rx_auto_error_replacement(pcs8g_rx_auto_error_replacement), // dis_err_replace|en_err_replace + .pcs8g_rx_auto_speed_nego (pcs8g_rx_auto_speed_nego ), // dis_asn|en_asn_g2_freq_scal + .pcs8g_rx_bist_ver (pcs8g_rx_bist_ver ), // dis_bist|incremental|cjpat|crpat + .pcs8g_rx_bist_ver_clr_flag (pcs8g_rx_bist_ver_clr_flag ), // dis_bist_clr_flag|en_bist_clr_flag + .pcs8g_rx_bit_reversal (pcs8g_rx_bit_reversal ), // dis_bit_reversal|en_bit_reversal + .pcs8g_rx_bo_pad (pcs8g_rx_bo_pad ), + .pcs8g_rx_bo_pattern (pcs8g_rx_bo_pattern ), + .pcs8g_rx_bypass_pipeline_reg (pcs8g_rx_bypass_pipeline_reg ), // dis_bypass_pipeline|en_bypass_pipeline + .pcs8g_rx_byte_deserializer (pcs8g_rx_byte_deserializer ), // dis_bds|en_bds_by_2|en_bds_by_2_det + .pcs8g_rx_byte_order (pcs8g_rx_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 + .pcs8g_rx_cdr_ctrl (pcs8g_rx_cdr_ctrl ), // dis_cdr_ctrl|en_cdr_ctrl|en_cdr_ctrl_w_cid + .pcs8g_rx_cdr_ctrl_rxvalid_mask(pcs8g_rx_cdr_ctrl_rxvalid_mask), // dis_rxvalid_mask|en_rxvalid_mask + .pcs8g_rx_cid_pattern (pcs8g_rx_cid_pattern ), // cid_pattern_0|cid_pattern_1 + .pcs8g_rx_cid_pattern_len (pcs8g_rx_cid_pattern_len ), + .pcs8g_rx_clkcmp_pattern_n (pcs8g_rx_clkcmp_pattern_n ), + .pcs8g_rx_clkcmp_pattern_p (pcs8g_rx_clkcmp_pattern_p ), + .pcs8g_rx_clock_gate_bds_dec_asn(pcs8g_rx_clock_gate_bds_dec_asn), // dis_bds_dec_asn_clk_gating|en_bds_dec_asn_clk_gating + .pcs8g_rx_clock_gate_bist (pcs8g_rx_clock_gate_bist ), // dis_bist_clk_gating|en_bist_clk_gating + .pcs8g_rx_clock_gate_byteorder (pcs8g_rx_clock_gate_byteorder ), // dis_byteorder_clk_gating|en_byteorder_clk_gating + .pcs8g_rx_clock_gate_cdr_eidle (pcs8g_rx_clock_gate_cdr_eidle ), // dis_cdr_eidle_clk_gating|en_cdr_eidle_clk_gating + .pcs8g_rx_clock_gate_dskw_rd (pcs8g_rx_clock_gate_dskw_rd ), // dis_dskw_rdclk_gating|en_dskw_rdclk_gating + .pcs8g_rx_clock_gate_dw_dskw_wr(pcs8g_rx_clock_gate_dw_dskw_wr), // dis_dw_dskw_wrclk_gating|en_dw_dskw_wrclk_gating + .pcs8g_rx_clock_gate_dw_pc_wrclk(pcs8g_rx_clock_gate_dw_pc_wrclk), // dis_dw_pc_wrclk_gating|en_dw_pc_wrclk_gating + .pcs8g_rx_clock_gate_dw_rm_rd (pcs8g_rx_clock_gate_dw_rm_rd ), // dis_dw_rm_rdclk_gating|en_dw_rm_rdclk_gating + .pcs8g_rx_clock_gate_dw_rm_wr (pcs8g_rx_clock_gate_dw_rm_wr ), // dis_dw_rm_wrclk_gating|en_dw_rm_wrclk_gating + .pcs8g_rx_clock_gate_dw_wa (pcs8g_rx_clock_gate_dw_wa ), // dis_dw_wa_clk_gating|en_dw_wa_clk_gating + .pcs8g_rx_clock_gate_pc_rdclk (pcs8g_rx_clock_gate_pc_rdclk ), // dis_pc_rdclk_gating|en_pc_rdclk_gating + .pcs8g_rx_clock_gate_prbs (pcs8g_rx_clock_gate_prbs ), // dis_prbs_clk_gating|en_prbs_clk_gating + .pcs8g_rx_clock_gate_sw_dskw_wr(pcs8g_rx_clock_gate_sw_dskw_wr), // dis_sw_dskw_wrclk_gating|en_sw_dskw_wrclk_gating + .pcs8g_rx_clock_gate_sw_pc_wrclk(pcs8g_rx_clock_gate_sw_pc_wrclk), // dis_sw_pc_wrclk_gating|en_sw_pc_wrclk_gating + .pcs8g_rx_clock_gate_sw_rm_rd (pcs8g_rx_clock_gate_sw_rm_rd ), // dis_sw_rm_rdclk_gating|en_sw_rm_rdclk_gating + .pcs8g_rx_clock_gate_sw_rm_wr (pcs8g_rx_clock_gate_sw_rm_wr ), // dis_sw_rm_wrclk_gating|en_sw_rm_wrclk_gating + .pcs8g_rx_clock_gate_sw_wa (pcs8g_rx_clock_gate_sw_wa ), // dis_sw_wa_clk_gating|en_sw_wa_clk_gating + .pcs8g_rx_comp_fifo_rst_pld_ctrl(pcs8g_rx_comp_fifo_rst_pld_ctrl), // dis_comp_fifo_rst_pld_ctrl|en_comp_fifo_rst_pld_ctrl + .pcs8g_rx_deskew (pcs8g_rx_deskew ), // dis_deskew|en_srio_v2p1|en_xaui + .pcs8g_rx_deskew_pattern (pcs8g_rx_deskew_pattern ), + .pcs8g_rx_deskew_prog_pattern_only(pcs8g_rx_deskew_prog_pattern_only), // dis_deskew_prog_pat_only|en_deskew_prog_pat_only + .pcs8g_rx_dw_one_or_two_symbol_bo(pcs8g_rx_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 + .pcs8g_rx_eidle_entry_eios (pcs8g_rx_eidle_entry_eios ), // dis_eidle_eios|en_eidle_eios + .pcs8g_rx_eidle_entry_iei (pcs8g_rx_eidle_entry_iei ), // dis_eidle_iei|en_eidle_iei + .pcs8g_rx_eidle_entry_sd (pcs8g_rx_eidle_entry_sd ), // dis_eidle_sd|en_eidle_sd + .pcs8g_rx_eightb_tenb_decoder (pcs8g_rx_eightb_tenb_decoder ), // dis_8b10b|en_8b10b_ibm|en_8b10b_sgx + .pcs8g_rx_eightbtenb_decoder_output_sel(pcs8g_rx_eightbtenb_decoder_output_sel), // data_8b10b_decoder|data_xaui_sm + .pcs8g_rx_err_flags_sel (pcs8g_rx_err_flags_sel ), // err_flags_wa|err_flags_8b10b + .pcs8g_rx_fixed_pat_det (pcs8g_rx_fixed_pat_det ), // dis_fixed_patdet|en_fixed_patdet + .pcs8g_rx_fixed_pat_num (pcs8g_rx_fixed_pat_num ), + .pcs8g_rx_force_signal_detect (pcs8g_rx_force_signal_detect ), // en_force_signal_detect|dis_force_signal_detect + .pcs8g_rx_hip_mode (pcs8g_rx_hip_mode ), // dis_hip|en_hip + .pcs8g_rx_ibm_invalid_code (pcs8g_rx_ibm_invalid_code ), // dis_ibm_invalid_code|en_ibm_invalid_code + .pcs8g_rx_invalid_code_flag_only(pcs8g_rx_invalid_code_flag_only), // dis_invalid_code_only|en_invalid_code_only + .pcs8g_rx_mask_cnt (pcs8g_rx_mask_cnt ), + .pcs8g_rx_pad_or_edb_error_replace(pcs8g_rx_pad_or_edb_error_replace), // replace_edb|replace_pad|replace_edb_dynamic + .pcs8g_rx_pc_fifo_rst_pld_ctrl (pcs8g_rx_pc_fifo_rst_pld_ctrl ), // dis_pc_fifo_rst_pld_ctrl|en_pc_fifo_rst_pld_ctrl + .pcs8g_rx_pcs_bypass (pcs8g_rx_pcs_bypass ), // dis_pcs_bypass|en_pcs_bypass + .pcs8g_rx_phase_compensation_fifo(pcs8g_rx_phase_compensation_fifo), // low_latency|normal_latency|register_fifo|pld_ctrl_low_latency|pld_ctrl_normal_latency + .pcs8g_rx_pipe_if_enable (pcs8g_rx_pipe_if_enable ), // dis_pipe_rx|en_pipe_rx + .pcs8g_rx_pma_done_count (pcs8g_rx_pma_done_count ), + .pcs8g_rx_pma_dw (pcs8g_rx_pma_dw ), // eight_bit|ten_bit|sixteen_bit|twenty_bit + .pcs8g_rx_polarity_inversion (pcs8g_rx_polarity_inversion ), // dis_pol_inv|en_pol_inv + .pcs8g_rx_polinv_8b10b_dec (pcs8g_rx_polinv_8b10b_dec ), // dis_polinv_8b10b_dec|en_polinv_8b10b_dec + .pcs8g_rx_prbs_ver (pcs8g_rx_prbs_ver ), // dis_prbs|prbs_7_sw|prbs_7_dw|prbs_8|prbs_10|prbs_23_sw|prbs_23_dw|prbs_15|prbs_31|prbs_hf_sw|prbs_hf_dw|prbs_lf_sw|prbs_lf_dw|prbs_mf_sw|prbs_mf_dw + .pcs8g_rx_prbs_ver_clr_flag (pcs8g_rx_prbs_ver_clr_flag ), // dis_prbs_clr_flag|en_prbs_clr_flag + .pcs8g_rx_prot_mode (pcs8g_rx_prot_mode ), // pipe_g1|pipe_g2|cpri|cpri_rx_tx|gige|xaui|srio_2p1|test|basic|disabled_prot_mode + .pcs8g_rx_rate_match (pcs8g_rx_rate_match ), // dis_rm|xaui_rm|gige_rm|pipe_rm|pipe_rm_0ppm|sw_basic_rm|srio_v2p1_rm|srio_v2p1_rm_0ppm|dw_basic_rm + .pcs8g_rx_re_bo_on_wa (pcs8g_rx_re_bo_on_wa ), // dis_re_bo_on_wa|en_re_bo_on_wa + .pcs8g_rx_runlength_check (pcs8g_rx_runlength_check ), // dis_runlength|en_runlength_sw|en_runlength_dw + .pcs8g_rx_runlength_val (pcs8g_rx_runlength_val ), + .pcs8g_rx_rx_clk1 (pcs8g_rx_rx_clk1 ), // rcvd_clk_clk1|tx_pma_clock_clk1|rcvd_clk_agg_clk1|rcvd_clk_agg_top_or_bottom_clk1 + .pcs8g_rx_rx_clk2 (pcs8g_rx_rx_clk2 ), // rcvd_clk_clk2|tx_pma_clock_clk2|refclk_dig2_clk2 + .pcs8g_rx_rx_clk_free_running (pcs8g_rx_rx_clk_free_running ), // dis_rx_clk_free_run|en_rx_clk_free_run + .pcs8g_rx_rx_pcs_urst (pcs8g_rx_rx_pcs_urst ), // dis_rx_pcs_urst|en_rx_pcs_urst + .pcs8g_rx_rx_rcvd_clk (pcs8g_rx_rx_rcvd_clk ), // rcvd_clk_rcvd_clk|tx_pma_clock_rcvd_clk + .pcs8g_rx_rx_rd_clk (pcs8g_rx_rx_rd_clk ), // pld_rx_clk|rx_clk + .pcs8g_rx_rx_refclk (pcs8g_rx_rx_refclk ), // dis_refclk_sel|en_refclk_sel + .pcs8g_rx_rx_wr_clk (pcs8g_rx_rx_wr_clk ), // rx_clk2_div_1_2_4|txfifo_rd_clk + .pcs8g_rx_sup_mode (pcs8g_rx_sup_mode ), // user_mode|engineering_mode + .pcs8g_rx_symbol_swap (pcs8g_rx_symbol_swap ), // dis_symbol_swap|en_symbol_swap + .pcs8g_rx_test_bus_sel (pcs8g_rx_test_bus_sel ), // prbs_bist_testbus|tx_testbus|tx_ctrl_plane_testbus|wa_testbus|deskew_testbus|rm_testbus|rx_ctrl_testbus|pcie_ctrl_testbus|rx_ctrl_plane_testbus|agg_testbus + .pcs8g_rx_test_mode (pcs8g_rx_test_mode ), // dont_care_test|prbs|bist + .pcs8g_rx_tx_rx_parallel_loopback(pcs8g_rx_tx_rx_parallel_loopback), // dis_plpbk|en_plpbk + .pcs8g_rx_use_default_base_address(pcs8g_rx_use_default_base_address), // false|true + .pcs8g_rx_user_base_address (pcs8g_rx_user_base_address ), // 0..2047 + .pcs8g_rx_wa_boundary_lock_ctrl(pcs8g_rx_wa_boundary_lock_ctrl), // bit_slip|sync_sm|deterministic_latency|auto_align_pld_ctrl + .pcs8g_rx_wa_clk_slip_spacing (pcs8g_rx_wa_clk_slip_spacing ), // min_clk_slip_spacing|user_programmable_clk_slip_spacing + .pcs8g_rx_wa_clk_slip_spacing_data(pcs8g_rx_wa_clk_slip_spacing_data), + .pcs8g_rx_wa_det_latency_sync_status_beh(pcs8g_rx_wa_det_latency_sync_status_beh), // assert_sync_status_imm|assert_sync_status_non_imm|dont_care_assert_sync + .pcs8g_rx_wa_disp_err_flag (pcs8g_rx_wa_disp_err_flag ), // dis_disp_err_flag|en_disp_err_flag + .pcs8g_rx_wa_kchar (pcs8g_rx_wa_kchar ), // dis_kchar|en_kchar + .pcs8g_rx_wa_pd (pcs8g_rx_wa_pd ), // dont_care_wa_pd_0|dont_care_wa_pd_1|wa_pd_7|wa_pd_10|wa_pd_20|wa_pd_40|wa_pd_8_sw|wa_pd_8_dw|wa_pd_16_sw|wa_pd_16_dw|wa_pd_32|wa_pd_fixed_7_k28p5|wa_pd_fixed_10_k28p5|wa_pd_fixed_16_a1a2_sw|wa_pd_fixed_16_a1a2_dw|wa_pd_fixed_32_a1a1a2a2|prbs15_fixed_wa_pd_16_sw|prbs15_fixed_wa_pd_16_dw|prbs15_fixed_wa_pd_20_dw|prbs31_fixed_wa_pd_16_sw|prbs31_fixed_wa_pd_16_dw|prbs31_fixed_wa_pd_10_sw|prbs31_fixed_wa_pd_40_dw|prbs8_fixed_wa|prbs10_fixed_wa|prbs7_fixed_wa_pd_16_sw|prbs7_fixed_wa_pd_16_dw|prbs7_fixed_wa_pd_20_dw|prbs23_fixed_wa_pd_16_sw|prbs23_fixed_wa_pd_32_dw|prbs23_fixed_wa_pd_40_dw + .pcs8g_rx_wa_pd_data (pcs8g_rx_wa_pd_data ), + .pcs8g_rx_wa_pd_polarity (pcs8g_rx_wa_pd_polarity ), // dis_pd_both_pol|en_pd_both_pol|dont_care_both_pol + .pcs8g_rx_wa_pld_controlled (pcs8g_rx_wa_pld_controlled ), // dis_pld_ctrl|pld_ctrl_sw|rising_edge_sensitive_dw|level_sensitive_dw + .pcs8g_rx_wa_renumber_data (pcs8g_rx_wa_renumber_data ), + .pcs8g_rx_wa_rgnumber_data (pcs8g_rx_wa_rgnumber_data ), + .pcs8g_rx_wa_rknumber_data (pcs8g_rx_wa_rknumber_data ), + .pcs8g_rx_wa_rosnumber_data (pcs8g_rx_wa_rosnumber_data ), + .pcs8g_rx_wa_rvnumber_data (pcs8g_rx_wa_rvnumber_data ), + .pcs8g_rx_wa_sync_sm_ctrl (pcs8g_rx_wa_sync_sm_ctrl ), // gige_sync_sm|pipe_sync_sm|xaui_sync_sm|srio1p3_sync_sm|srio2p1_sync_sm|sw_basic_sync_sm|dw_basic_sync_sm|fibre_channel_sync_sm + .pcs8g_rx_wait_cnt (pcs8g_rx_wait_cnt ), + // parameters for arriav_hssi_8g_tx_pcs + .pcs8g_tx_agg_block_sel (pcs8g_tx_agg_block_sel ), // same_smrt_pack|other_smrt_pack + .pcs8g_tx_auto_speed_nego_gen2 (pcs8g_tx_auto_speed_nego_gen2 ), // dis_asn_g2|en_asn_g2_freq_scal + .pcs8g_tx_bist_gen (pcs8g_tx_bist_gen ), // dis_bist|incremental|cjpat|crpat + .pcs8g_tx_bit_reversal (pcs8g_tx_bit_reversal ), // dis_bit_reversal|en_bit_reversal + .pcs8g_tx_bypass_pipeline_reg (pcs8g_tx_bypass_pipeline_reg ), // dis_bypass_pipeline|en_bypass_pipeline + .pcs8g_tx_byte_serializer (pcs8g_tx_byte_serializer ), // dis_bs|en_bs_by_2 + .pcs8g_tx_cid_pattern (pcs8g_tx_cid_pattern ), // cid_pattern_0|cid_pattern_1 + .pcs8g_tx_cid_pattern_len (pcs8g_tx_cid_pattern_len ), + .pcs8g_tx_clock_gate_bist (pcs8g_tx_clock_gate_bist ), // dis_bist_clk_gating|en_bist_clk_gating + .pcs8g_tx_clock_gate_bs_enc (pcs8g_tx_clock_gate_bs_enc ), // dis_bs_enc_clk_gating|en_bs_enc_clk_gating + .pcs8g_tx_clock_gate_dw_fifowr (pcs8g_tx_clock_gate_dw_fifowr ), // dis_dw_fifowr_clk_gating|en_dw_fifowr_clk_gating + .pcs8g_tx_clock_gate_fiford (pcs8g_tx_clock_gate_fiford ), // dis_fiford_clk_gating|en_fiford_clk_gating + .pcs8g_tx_clock_gate_prbs (pcs8g_tx_clock_gate_prbs ), // dis_prbs_clk_gating|en_prbs_clk_gating + .pcs8g_tx_clock_gate_sw_fifowr (pcs8g_tx_clock_gate_sw_fifowr ), // dis_sw_fifowr_clk_gating|en_sw_fifowr_clk_gating + .pcs8g_tx_data_selection_8b10b_encoder_input(pcs8g_tx_data_selection_8b10b_encoder_input), // normal_data_path|xaui_sm|gige_idle_conversion + .pcs8g_tx_dynamic_clk_switch (pcs8g_tx_dynamic_clk_switch ), // dis_dyn_clk_switch|en_dyn_clk_switch + .pcs8g_tx_eightb_tenb_disp_ctrl(pcs8g_tx_eightb_tenb_disp_ctrl), // dis_disp_ctrl|en_disp_ctrl|en_ib_disp_ctrl + .pcs8g_tx_eightb_tenb_encoder (pcs8g_tx_eightb_tenb_encoder ), // dis_8b10b|en_8b10b_ibm|en_8b10b_sgx + .pcs8g_tx_force_echar (pcs8g_tx_force_echar ), // dis_force_echar|en_force_echar + .pcs8g_tx_force_kchar (pcs8g_tx_force_kchar ), // dis_force_kchar|en_force_kchar + .pcs8g_tx_hip_mode (pcs8g_tx_hip_mode ), // dis_hip|en_hip + .pcs8g_tx_pcfifo_urst (pcs8g_tx_pcfifo_urst ), // dis_pcfifourst|en_pcfifourst + .pcs8g_tx_pcs_bypass (pcs8g_tx_pcs_bypass ), // dis_pcs_bypass|en_pcs_bypass + .pcs8g_tx_phase_compensation_fifo(pcs8g_tx_phase_compensation_fifo), // low_latency|normal_latency|register_fifo|pld_ctrl_low_latency|pld_ctrl_normal_latency + .pcs8g_tx_phfifo_write_clk_sel (pcs8g_tx_phfifo_write_clk_sel ), // pld_tx_clk|tx_clk + .pcs8g_tx_pma_dw (pcs8g_tx_pma_dw ), // eight_bit|ten_bit|sixteen_bit|twenty_bit + .pcs8g_tx_polarity_inversion (pcs8g_tx_polarity_inversion ), // dis_polinv|enable_polinv + .pcs8g_tx_prbs_gen (pcs8g_tx_prbs_gen ), // dis_prbs|prbs_7_sw|prbs_7_dw|prbs_8|prbs_10|prbs_23_sw|prbs_23_dw|prbs_15|prbs_31|prbs_hf_sw|prbs_hf_dw|prbs_lf_sw|prbs_lf_dw|prbs_mf_sw|prbs_mf_dw + .pcs8g_tx_prot_mode (pcs8g_tx_prot_mode ), // pipe_g1|pipe_g2|cpri|cpri_rx_tx|gige|xaui|srio_2p1|test|basic|disabled_prot_mode + .pcs8g_tx_refclk_b_clk_sel (pcs8g_tx_refclk_b_clk_sel ), // tx_pma_clock|refclk_dig + .pcs8g_tx_revloop_back_rm (pcs8g_tx_revloop_back_rm ), // dis_rev_loopback_rx_rm|en_rev_loopback_rx_rm + .pcs8g_tx_sup_mode (pcs8g_tx_sup_mode ), // user_mode|engineering_mode + .pcs8g_tx_symbol_swap (pcs8g_tx_symbol_swap ), // dis_symbol_swap|en_symbol_swap + .pcs8g_tx_test_mode (pcs8g_tx_test_mode ), // dont_care_test|prbs|bist + .pcs8g_tx_tx_bitslip (pcs8g_tx_tx_bitslip ), // dis_tx_bitslip|en_tx_bitslip + .pcs8g_tx_tx_compliance_controlled_disparity(pcs8g_tx_tx_compliance_controlled_disparity), // dis_txcompliance|en_txcompliance_pipe2p0 + .pcs8g_tx_txclk_freerun (pcs8g_tx_txclk_freerun ), // dis_freerun_tx|en_freerun_tx + .pcs8g_tx_txpcs_urst (pcs8g_tx_txpcs_urst ), // dis_txpcs_urst|en_txpcs_urst + .pcs8g_tx_use_default_base_address(pcs8g_tx_use_default_base_address), // false|true + .pcs8g_tx_user_base_address (pcs8g_tx_user_base_address ), // 0..2047 + // parameters for arriav_hssi_common_pcs_pma_interface + .com_pcs_pma_if_auto_speed_ena (com_pcs_pma_if_auto_speed_ena ), // dis_auto_speed_ena|en_auto_speed_ena + .com_pcs_pma_if_force_freqdet (com_pcs_pma_if_force_freqdet ), // force_freqdet_dis|force1_freqdet_en|force0_freqdet_en + .com_pcs_pma_if_func_mode (com_pcs_pma_if_func_mode ), // disable|hrdrstctrl_cmu|eightg_only_pld|eightg_only_hip|pma_direct + .com_pcs_pma_if_pipe_if_g3pcs (com_pcs_pma_if_pipe_if_g3pcs ), // pipe_if_8gpcs + .com_pcs_pma_if_pma_if_dft_en (com_pcs_pma_if_pma_if_dft_en ), // dft_dis + .com_pcs_pma_if_pma_if_dft_val (com_pcs_pma_if_pma_if_dft_val ), // dft_0 + .com_pcs_pma_if_ppm_cnt_rst (com_pcs_pma_if_ppm_cnt_rst ), // ppm_cnt_rst_dis|ppm_cnt_rst_en + .com_pcs_pma_if_ppm_deassert_early(com_pcs_pma_if_ppm_deassert_early), // deassert_early_dis|deassert_early_en + .com_pcs_pma_if_ppm_gen1_2_cnt (com_pcs_pma_if_ppm_gen1_2_cnt ), // cnt_32k|cnt_64k + .com_pcs_pma_if_ppm_post_eidle_delay(com_pcs_pma_if_ppm_post_eidle_delay), // cnt_200_cycles|cnt_400_cycles + .com_pcs_pma_if_ppmsel (com_pcs_pma_if_ppmsel ), // ppmsel_default|ppmsel_1000|ppmsel_500|ppmsel_300|ppmsel_250|ppmsel_200|ppmsel_125|ppmsel_100|ppmsel_62p5|ppm_other + .com_pcs_pma_if_prot_mode (com_pcs_pma_if_prot_mode ), // disabled_prot_mode|pipe_g1|pipe_g2|other_protocols + .com_pcs_pma_if_selectpcs (com_pcs_pma_if_selectpcs ), // eight_g_pcs + .com_pcs_pma_if_sup_mode (com_pcs_pma_if_sup_mode ), // user_mode|engineering_mode + .com_pcs_pma_if_use_default_base_address(com_pcs_pma_if_use_default_base_address), // false|true + .com_pcs_pma_if_user_base_address(com_pcs_pma_if_user_base_address), // 0..2047 + // parameters for arriav_hssi_common_pld_pcs_interface + .com_pld_pcs_if_hip_enable (com_pld_pcs_if_hip_enable ), // hip_disable|hip_enable + .com_pld_pcs_if_hrdrstctrl_en_cfg(com_pld_pcs_if_hrdrstctrl_en_cfg), // hrst_dis_cfg|hrst_en_cfg + .com_pld_pcs_if_hrdrstctrl_en_cfgusr(com_pld_pcs_if_hrdrstctrl_en_cfgusr), // hrst_dis_cfgusr|hrst_en_cfgusr + .com_pld_pcs_if_pld_side_data_source(com_pld_pcs_if_pld_side_data_source), // hip|pld + .com_pld_pcs_if_pld_side_reserved_source0(com_pld_pcs_if_pld_side_reserved_source0), // pld_res0|hip_res0 + .com_pld_pcs_if_pld_side_reserved_source1(com_pld_pcs_if_pld_side_reserved_source1), // pld_res1|hip_res1 + .com_pld_pcs_if_pld_side_reserved_source10(com_pld_pcs_if_pld_side_reserved_source10), // pld_res10|hip_res10 + .com_pld_pcs_if_pld_side_reserved_source11(com_pld_pcs_if_pld_side_reserved_source11), // pld_res11|hip_res11 + .com_pld_pcs_if_pld_side_reserved_source2(com_pld_pcs_if_pld_side_reserved_source2), // pld_res2|hip_res2 + .com_pld_pcs_if_pld_side_reserved_source3(com_pld_pcs_if_pld_side_reserved_source3), // pld_res3|hip_res3 + .com_pld_pcs_if_pld_side_reserved_source4(com_pld_pcs_if_pld_side_reserved_source4), // pld_res4|hip_res4 + .com_pld_pcs_if_pld_side_reserved_source5(com_pld_pcs_if_pld_side_reserved_source5), // pld_res5|hip_res5 + .com_pld_pcs_if_pld_side_reserved_source6(com_pld_pcs_if_pld_side_reserved_source6), // pld_res6|hip_res6 + .com_pld_pcs_if_pld_side_reserved_source7(com_pld_pcs_if_pld_side_reserved_source7), // pld_res7|hip_res7 + .com_pld_pcs_if_pld_side_reserved_source8(com_pld_pcs_if_pld_side_reserved_source8), // pld_res8|hip_res8 + .com_pld_pcs_if_pld_side_reserved_source9(com_pld_pcs_if_pld_side_reserved_source9), // pld_res9|hip_res9 + .com_pld_pcs_if_testbus_sel (com_pld_pcs_if_testbus_sel ), // eight_g_pcs|pma_if + .com_pld_pcs_if_use_default_base_address(com_pld_pcs_if_use_default_base_address), // false|true + .com_pld_pcs_if_user_base_address(com_pld_pcs_if_user_base_address), // 0..2047 + .com_pld_pcs_if_usrmode_sel4rst(com_pld_pcs_if_usrmode_sel4rst), // usermode|last_frz + // parameters for arriav_hssi_pipe_gen1_2 + .pipe12_elec_idle_delay_val (pipe12_elec_idle_delay_val ), + .pipe12_elecidle_delay (pipe12_elecidle_delay ), // elec_idle_delay + .pipe12_error_replace_pad (pipe12_error_replace_pad ), // replace_edb|replace_pad + .pipe12_hip_mode (pipe12_hip_mode ), // dis_hip|en_hip + .pipe12_ind_error_reporting (pipe12_ind_error_reporting ), // dis_ind_error_reporting|en_ind_error_reporting + .pipe12_phy_status_delay (pipe12_phy_status_delay ), // phystatus_delay + .pipe12_phystatus_delay_val (pipe12_phystatus_delay_val ), + .pipe12_phystatus_rst_toggle (pipe12_phystatus_rst_toggle ), // dis_phystatus_rst_toggle|en_phystatus_rst_toggle + .pipe12_pipe_byte_de_serializer_en(pipe12_pipe_byte_de_serializer_en), // dis_bds|en_bds_by_2|dont_care_bds + .pipe12_prot_mode (pipe12_prot_mode ), // pipe_g1|pipe_g2|srio_2p1|basic|disabled_prot_mode + .pipe12_rpre_emph_a_val (pipe12_rpre_emph_a_val ), + .pipe12_rpre_emph_b_val (pipe12_rpre_emph_b_val ), + .pipe12_rpre_emph_c_val (pipe12_rpre_emph_c_val ), + .pipe12_rpre_emph_d_val (pipe12_rpre_emph_d_val ), + .pipe12_rpre_emph_e_val (pipe12_rpre_emph_e_val ), + .pipe12_rpre_emph_settings (pipe12_rpre_emph_settings ), + .pipe12_rvod_sel_a_val (pipe12_rvod_sel_a_val ), + .pipe12_rvod_sel_b_val (pipe12_rvod_sel_b_val ), + .pipe12_rvod_sel_c_val (pipe12_rvod_sel_c_val ), + .pipe12_rvod_sel_d_val (pipe12_rvod_sel_d_val ), + .pipe12_rvod_sel_e_val (pipe12_rvod_sel_e_val ), + .pipe12_rvod_sel_settings (pipe12_rvod_sel_settings ), + .pipe12_rx_pipe_enable (pipe12_rx_pipe_enable ), // dis_pipe_rx|en_pipe_rx + .pipe12_rxdetect_bypass (pipe12_rxdetect_bypass ), // dis_rxdetect_bypass|en_rxdetect_bypass + .pipe12_sup_mode (pipe12_sup_mode ), // user_mode|engineering_mode + .pipe12_tx_pipe_enable (pipe12_tx_pipe_enable ), // dis_pipe_tx|en_pipe_tx + .pipe12_txswing (pipe12_txswing ), // dis_txswing|en_txswing + .pipe12_use_default_base_address(pipe12_use_default_base_address), // false|true + .pipe12_user_base_address (pipe12_user_base_address ), // 0..2047 + // parameters for arriav_hssi_rx_pcs_pma_interface + .rx_pcs_pma_if_clkslip_sel (rx_pcs_pma_if_clkslip_sel ), // pld|slip_eight_g_pcs + .rx_pcs_pma_if_prot_mode (rx_pcs_pma_if_prot_mode ), // other_protocols|cpri_8g + .rx_pcs_pma_if_selectpcs (rx_pcs_pma_if_selectpcs ), // eight_g_pcs|default + .rx_pcs_pma_if_use_default_base_address(rx_pcs_pma_if_use_default_base_address), // false|true + .rx_pcs_pma_if_user_base_address(rx_pcs_pma_if_user_base_address), // 0..2047 + // parameters for arriav_hssi_rx_pld_pcs_interface + .rx_pld_pcs_if_is_8g_0ppm (rx_pld_pcs_if_is_8g_0ppm ), // false|true + .rx_pld_pcs_if_pcs_side_block_sel(rx_pld_pcs_if_pcs_side_block_sel), // eight_g_pcs|default + .rx_pld_pcs_if_pld_side_data_source(rx_pld_pcs_if_pld_side_data_source), // hip|pld + .rx_pld_pcs_if_use_default_base_address(rx_pld_pcs_if_use_default_base_address), // false|true + .rx_pld_pcs_if_user_base_address(rx_pld_pcs_if_user_base_address), // 0..2047 + // parameters for arriav_hssi_tx_pcs_pma_interface + .tx_pcs_pma_if_selectpcs (tx_pcs_pma_if_selectpcs ), // eight_g_pcs|default + .tx_pcs_pma_if_use_default_base_address(tx_pcs_pma_if_use_default_base_address), // false|true + .tx_pcs_pma_if_user_base_address(tx_pcs_pma_if_user_base_address), // 0..2047 + // parameters for arriav_hssi_tx_pld_pcs_interface + .tx_pld_pcs_if_is_8g_0ppm (tx_pld_pcs_if_is_8g_0ppm ), // false|true + .tx_pld_pcs_if_pld_side_data_source(tx_pld_pcs_if_pld_side_data_source), // hip|pld + .tx_pld_pcs_if_use_default_base_address(tx_pld_pcs_if_use_default_base_address), // false|true + .tx_pld_pcs_if_user_base_address(tx_pld_pcs_if_user_base_address) // 0..2047 + ) inst_av_pcs ( + .in_agg_align_status (in_agg_align_status ), + .in_agg_align_status_sync_0 (in_agg_align_status_sync_0 ), + .in_agg_align_status_sync_0_top_or_bot(in_agg_align_status_sync_0_top_or_bot), + .in_agg_align_status_top_or_bot(in_agg_align_status_top_or_bot), + .in_agg_cg_comp_rd_d_all (in_agg_cg_comp_rd_d_all ), + .in_agg_cg_comp_rd_d_all_top_or_bot(in_agg_cg_comp_rd_d_all_top_or_bot), + .in_agg_cg_comp_wr_all (in_agg_cg_comp_wr_all ), + .in_agg_cg_comp_wr_all_top_or_bot(in_agg_cg_comp_wr_all_top_or_bot), + .in_agg_del_cond_met_0 (in_agg_del_cond_met_0 ), + .in_agg_del_cond_met_0_top_or_bot(in_agg_del_cond_met_0_top_or_bot), + .in_agg_en_dskw_qd (in_agg_en_dskw_qd ), + .in_agg_en_dskw_qd_top_or_bot (in_agg_en_dskw_qd_top_or_bot ), + .in_agg_en_dskw_rd_ptrs (in_agg_en_dskw_rd_ptrs ), + .in_agg_en_dskw_rd_ptrs_top_or_bot(in_agg_en_dskw_rd_ptrs_top_or_bot), + .in_agg_fifo_ovr_0 (in_agg_fifo_ovr_0 ), + .in_agg_fifo_ovr_0_top_or_bot (in_agg_fifo_ovr_0_top_or_bot ), + .in_agg_fifo_rd_in_comp_0 (in_agg_fifo_rd_in_comp_0 ), + .in_agg_fifo_rd_in_comp_0_top_or_bot(in_agg_fifo_rd_in_comp_0_top_or_bot), + .in_agg_fifo_rst_rd_qd (in_agg_fifo_rst_rd_qd ), + .in_agg_fifo_rst_rd_qd_top_or_bot(in_agg_fifo_rst_rd_qd_top_or_bot), + .in_agg_insert_incomplete_0 (in_agg_insert_incomplete_0 ), + .in_agg_insert_incomplete_0_top_or_bot(in_agg_insert_incomplete_0_top_or_bot), + .in_agg_latency_comp_0 (in_agg_latency_comp_0 ), + .in_agg_latency_comp_0_top_or_bot(in_agg_latency_comp_0_top_or_bot), + .in_agg_rcvd_clk_agg (in_agg_rcvd_clk_agg ), + .in_agg_rcvd_clk_agg_top_or_bot(in_agg_rcvd_clk_agg_top_or_bot), + .in_agg_rx_control_rs (in_agg_rx_control_rs ), + .in_agg_rx_control_rs_top_or_bot(in_agg_rx_control_rs_top_or_bot), + .in_agg_rx_data_rs (in_agg_rx_data_rs ), + .in_agg_rx_data_rs_top_or_bot (in_agg_rx_data_rs_top_or_bot ), + .in_agg_test_so_to_pld_in (in_agg_test_so_to_pld_in ), + .in_agg_testbus (in_agg_testbus ), + .in_agg_tx_ctl_ts (in_agg_tx_ctl_ts ), + .in_agg_tx_ctl_ts_top_or_bot (in_agg_tx_ctl_ts_top_or_bot ), + .in_agg_tx_data_ts (in_agg_tx_data_ts ), + .in_agg_tx_data_ts_top_or_bot (in_agg_tx_data_ts_top_or_bot ), + .in_avmmaddress (chnl_avmm_address ), + .in_avmmbyteen (chnl_avmm_byteen ), + .in_avmmclk (chnl_avmm_clk ), + .in_avmmread (chnl_avmm_read ), + .in_avmmrstn (chnl_avmm_rstn ), + .in_avmmwrite (chnl_avmm_write ), + .in_avmmwritedata (chnl_avmm_writedata ), + .in_emsip_com_in (in_emsip_com_in ), + .in_emsip_rx_special_in (in_emsip_rx_special_in ), + .in_emsip_tx_in (in_emsip_tx_in ), + .in_emsip_tx_special_in (in_emsip_tx_special_in ), + .in_pld_8g_a1a2_size (in_pld_8g_a1a2_size ), + .in_pld_8g_bitloc_rev_en (in_pld_8g_bitloc_rev_en ), + .in_pld_8g_bitslip (in_pld_8g_bitslip ), + .in_pld_8g_byte_rev_en (in_pld_8g_byte_rev_en ), + .in_pld_8g_bytordpld (in_pld_8g_bytordpld ), + .in_pld_8g_cmpfifourst_n (in_pld_8g_cmpfifourst_n ), + .in_pld_8g_encdt (in_pld_8g_encdt ), + .in_pld_8g_phfifourst_rx_n (in_pld_8g_phfifourst_rx_n ), + .in_pld_8g_phfifourst_tx_n (in_pld_8g_phfifourst_tx_n ), + .in_pld_8g_pld_rx_clk (in_pld_8g_pld_rx_clk ), + .in_pld_8g_pld_tx_clk (in_pld_8g_pld_tx_clk ), + .in_pld_8g_polinv_rx (in_pld_8g_polinv_rx ), + .in_pld_8g_polinv_tx (in_pld_8g_polinv_tx ), + .in_pld_8g_powerdown (in_pld_8g_powerdown ), + .in_pld_8g_prbs_cid_en (in_pld_8g_prbs_cid_en ), + .in_pld_8g_rddisable_tx (in_pld_8g_rddisable_tx ), + .in_pld_8g_rdenable_rmf (in_pld_8g_rdenable_rmf ), + .in_pld_8g_rdenable_rx (in_pld_8g_rdenable_rx ), + .in_pld_8g_refclk_dig (in_pld_8g_refclk_dig ), + .in_pld_8g_refclk_dig2 (in_pld_8g_refclk_dig2 ), + .in_pld_8g_rev_loopbk (in_pld_8g_rev_loopbk ), + .in_pld_8g_rxpolarity (in_pld_8g_rxpolarity ), + .in_pld_8g_rxurstpcs_n (out_pld_8g_rxurstpcs_n ), + .in_pld_8g_tx_boundary_sel (in_pld_8g_tx_boundary_sel ), + .in_pld_8g_tx_data_valid (in_pld_8g_tx_data_valid ), + .in_pld_8g_txdeemph (in_pld_8g_txdeemph ), + .in_pld_8g_txdetectrxloopback (in_pld_8g_txdetectrxloopback ), + .in_pld_8g_txelecidle (in_pld_8g_txelecidle ), + .in_pld_8g_txmargin (in_pld_8g_txmargin ), + .in_pld_8g_txswing (in_pld_8g_txswing ), + .in_pld_8g_txurstpcs_n (out_pld_8g_txurstpcs_n ), + .in_pld_8g_wrdisable_rx (in_pld_8g_wrdisable_rx ), + .in_pld_8g_wrenable_rmf (in_pld_8g_wrenable_rmf ), + .in_pld_8g_wrenable_tx (in_pld_8g_wrenable_tx ), + .in_pld_agg_refclk_dig (in_pld_agg_refclk_dig ), + .in_pld_eidleinfersel (in_pld_eidleinfersel ), + .in_pld_ltr (in_pld_ltr ), + .in_pld_partial_reconfig_in (in_pld_partial_reconfig_in ), + .in_pld_pcs_pma_if_refclk_dig (in_pld_pcs_pma_if_refclk_dig ), + .in_pld_rate (in_pld_rate ), + .in_pld_reserved_in (in_pld_reserved_in ), + .in_pld_rx_clk_slip_in (in_pld_rx_clk_slip_in ), + .in_pld_rxpma_rstb_in (out_pld_rxpma_rstb_in ), + .in_pld_scan_mode_n (in_pld_scan_mode_n ), + .in_pld_scan_shift_n (in_pld_scan_shift_n ), + .in_pld_sync_sm_en (in_pld_sync_sm_en ), + .in_pld_tx_data (in_pld_tx_data ), + .in_pma_clklow_in (rx_clklow ), + .in_pma_fref_in (rx_fref ), + .in_pma_hclk (in_pma_hclk ), + .in_pma_pcie_sw_done (tx_pcieswdone ), + .in_pma_reserved_in (in_pma_reserved_in ), + .in_pma_rx_data (in_pma_rx_data ), + .in_pma_rx_detect_valid (tx_rxdetectvalid ), + .in_pma_rx_found (tx_rxfound ), + .in_pma_rx_freq_tx_cmu_pll_lock_in(in_pma_rx_freq_tx_cmu_pll_lock_in), + .in_pma_rx_pll_phase_lock_in (out_pcs_rx_pll_phase_lock_out ), + .in_pma_rx_pma_clk (rx_clkdivrx ), + .in_pma_sigdet (rx_sd ), + .in_pma_tx_pma_clk (tx_clkdivtx ), + .out_agg_align_det_sync (out_agg_align_det_sync ), + .out_agg_align_status_sync (out_agg_align_status_sync ), + .out_agg_cg_comp_rd_d_out (out_agg_cg_comp_rd_d_out ), + .out_agg_cg_comp_wr_out (out_agg_cg_comp_wr_out ), + .out_agg_dec_ctl (out_agg_dec_ctl ), + .out_agg_dec_data (out_agg_dec_data ), + .out_agg_dec_data_valid (out_agg_dec_data_valid ), + .out_agg_del_cond_met_out (out_agg_del_cond_met_out ), + .out_agg_fifo_ovr_out (out_agg_fifo_ovr_out ), + .out_agg_fifo_rd_out_comp (out_agg_fifo_rd_out_comp ), + .out_agg_insert_incomplete_out (out_agg_insert_incomplete_out ), + .out_agg_latency_comp_out (out_agg_latency_comp_out ), + .out_agg_rd_align (out_agg_rd_align ), + .out_agg_rd_enable_sync (out_agg_rd_enable_sync ), + .out_agg_refclk_dig (out_agg_refclk_dig ), + .out_agg_running_disp (out_agg_running_disp ), + .out_agg_rxpcs_rst (out_agg_rxpcs_rst ), + .out_agg_scan_mode_n (out_agg_scan_mode_n ), + .out_agg_scan_shift_n (out_agg_scan_shift_n ), + .out_agg_sync_status (out_agg_sync_status ), + .out_agg_tx_ctl_tc (out_agg_tx_ctl_tc ), + .out_agg_tx_data_tc (out_agg_tx_data_tc ), + .out_agg_txpcs_rst (out_agg_txpcs_rst ), + .out_avmmreaddata_com_pcs_pma_if(out_avmmreaddata_com_pcs_pma_if), + .out_avmmreaddata_com_pld_pcs_if(out_avmmreaddata_com_pld_pcs_if), + .out_avmmreaddata_pcs8g_rx (out_avmmreaddata_pcs8g_rx ), + .out_avmmreaddata_pcs8g_tx (out_avmmreaddata_pcs8g_tx ), + .out_avmmreaddata_pipe12 (out_avmmreaddata_pipe12 ), + .out_avmmreaddata_rx_pcs_pma_if(out_avmmreaddata_rx_pcs_pma_if), + .out_avmmreaddata_rx_pld_pcs_if(out_avmmreaddata_rx_pld_pcs_if), + .out_avmmreaddata_tx_pcs_pma_if(out_avmmreaddata_tx_pcs_pma_if), + .out_avmmreaddata_tx_pld_pcs_if(out_avmmreaddata_tx_pld_pcs_if), + .out_blockselect_com_pcs_pma_if(out_blockselect_com_pcs_pma_if), + .out_blockselect_com_pld_pcs_if(out_blockselect_com_pld_pcs_if), + .out_blockselect_pcs8g_rx (out_blockselect_pcs8g_rx ), + .out_blockselect_pcs8g_tx (out_blockselect_pcs8g_tx ), + .out_blockselect_pipe12 (out_blockselect_pipe12 ), + .out_blockselect_rx_pcs_pma_if (out_blockselect_rx_pcs_pma_if ), + .out_blockselect_rx_pld_pcs_if (out_blockselect_rx_pld_pcs_if ), + .out_blockselect_tx_pcs_pma_if (out_blockselect_tx_pcs_pma_if ), + .out_blockselect_tx_pld_pcs_if (out_blockselect_tx_pld_pcs_if ), + .out_emsip_com_clk_out (out_emsip_com_clk_out ), + .out_emsip_com_out (out_emsip_com_out ), + .out_emsip_rx_out (out_emsip_rx_out ), + .out_emsip_rx_special_out (out_emsip_rx_special_out ), + .out_emsip_tx_clk_out (out_emsip_tx_clk_out ), + .out_emsip_tx_special_out (out_emsip_tx_special_out ), + .out_pld_8g_a1a2_k1k2_flag (out_pld_8g_a1a2_k1k2_flag ), + .out_pld_8g_align_status (out_pld_8g_align_status ), + .out_pld_8g_bistdone (out_pld_8g_bistdone ), + .out_pld_8g_bisterr (out_pld_8g_bisterr ), + .out_pld_8g_byteord_flag (out_pld_8g_byteord_flag ), + .out_pld_8g_empty_rmf (out_pld_8g_empty_rmf ), + .out_pld_8g_empty_rx (out_pld_8g_empty_rx ), + .out_pld_8g_empty_tx (out_pld_8g_empty_tx ), + .out_pld_8g_full_rmf (out_pld_8g_full_rmf ), + .out_pld_8g_full_rx (out_pld_8g_full_rx ), + .out_pld_8g_full_tx (out_pld_8g_full_tx ), + .out_pld_8g_phystatus (out_pld_8g_phystatus ), + .out_pld_8g_rlv_lt (out_pld_8g_rlv_lt ), + .out_pld_8g_rx_clk_out (out_pld_8g_rx_clk_out ), + .out_pld_8g_rx_data_valid (out_pld_8g_rx_data_valid ), + .out_pld_8g_rxelecidle (out_pld_8g_rxelecidle ), + .out_pld_8g_rxstatus (out_pld_8g_rxstatus ), + .out_pld_8g_rxvalid (out_pld_8g_rxvalid ), + .out_pld_8g_signal_detect_out (out_pld_8g_signal_detect_out ), + .out_pld_8g_tx_clk_out (out_pld_8g_tx_clk_out ), + .out_pld_8g_wa_boundary (out_pld_8g_wa_boundary ), + .out_pld_clklow (out_pld_clklow ), + .out_pld_fref (out_pld_fref ), + .out_pld_reserved_out (out_pld_reserved_out ), + .out_pld_rx_data (out_pld_rx_data ), + .out_pld_test_data (out_pld_test_data ), + .out_pld_test_si_to_agg_out (out_pld_test_si_to_agg_out ), + .out_pma_current_coeff (out_pma_current_coeff ), + .out_pma_early_eios (out_pma_early_eios ), + .out_pma_ltr (out_pma_ltr ), + .out_pma_nfrzdrv (out_pma_nfrzdrv ), + .out_pma_partial_reconfig (out_pma_partial_reconfig ), + .out_pma_pcie_switch (out_pma_pcie_switch ), + .out_pma_ppm_lock (out_pma_ppm_lock ), + .out_pma_reserved_out (out_pma_reserved_out ), + .out_pma_rx_clk_out (out_pma_rx_clk_out ), + .out_pma_rxclkslip (out_pma_rxclkslip ), + .out_pma_rxpma_rstb (out_pma_rxpma_rstb ), + .out_pma_tx_clk_out (out_pma_tx_clk_out ), + .out_pma_tx_data (out_pma_tx_data ), + .out_pma_tx_elec_idle (out_pma_tx_elec_idle ), + .out_pma_txdetectrx (out_pma_txdetectrx ) +); + + + av_xcvr_avmm #( + .bonded_lanes (bonded_lanes ), // Number of lanes + .bonding_master_ch (bonding_master_ch ), // Indicates which channel is master + .bonding_master_only (bonding_master_only ), // Indicates which channels are MASTER_ONLY. List of strings. + .pma_reserved_ch (pma_reserved_ch ), // Indicates which channels are reserved + // PMA enables + .rx_enable (rx_enable ), // Indicates whether this interface contains an rx channel. + .tx_enable (tx_enable ), // Indicates whether this interface contains a tx channel + // PCS enables + .enable_8g_tx (enable_8g_tx ), // Is 8g TX PCS enabled? + .enable_8g_rx (enable_8g_rx ), // Is 8g RX PCS enabled? + // Services requests + .request_dcd (request_dcd ), // Request Duty Cycle Distortion correction at startup + .request_vrc (request_vrc ), // Request Voltage Regulator Calibration at startup + .request_offset (request_offset ) // Request RX Offset Cancellation at startup - defaults to enabled, only PCIE w/HIP should unset this + ) inst_av_xcvr_avmm ( + // Reconfiguration signal bundles + .reconfig_to_xcvr (reconfig_to_xcvr ), + .reconfig_from_xcvr (reconfig_from_xcvr ), + // Control inputs from PLD + .seriallpbken (seriallpbken ), // 1 = enable serial loopback + // PCS clocks + .in_pld_8g_pld_rx_clk (in_pld_8g_pld_rx_clk ), // 8g PCS RX clock + // PCS resets + .in_pld_8g_txurstpcs_n (in_pld_8g_txurstpcs_n ), // 8g PCS TX reset + .in_pld_8g_rxurstpcs_n (in_pld_8g_rxurstpcs_n ), // 8g PCS RX reset + .out_pld_8g_txurstpcs_n (out_pld_8g_txurstpcs_n ), // 8g PCS TX reset + .out_pld_8g_rxurstpcs_n (out_pld_8g_rxurstpcs_n ), // 8g PCS RX reset + // PMA resets + .rx_crurstn (rx_crurstn ), // CDR analog reset (active low) + .in_pld_rxpma_rstb_in (in_pld_rxpma_rstb_in ), + .out_rx_crurstn (out_rx_crurstn ), // CDR analog reset (active low) + .out_pld_rxpma_rstb_in (out_pld_rxpma_rstb_in ), + // PCS data + .out_pld_rx_data (out_pld_rx_data ), // PCS data output + // Calibration clocks + .calclk (calclk ), // Calibration clock driven from reconfig clock to aux block + //calibration status + .tx_cal_busy (tx_cal_busy ), + .rx_cal_busy (rx_cal_busy ), + // Reconfig controls + .pma_hardoccalen (pma_hardoccalen ), + .pma_seriallpbken (pma_seriallpbken ), + // Reconfig status + .pcs_8g_prbs_done ( {bonded_lanes{1'b0}} ), + .pcs_8g_prbs_err ( {bonded_lanes{1'b0}} ), + // Channel AVMM interface signals + .chnl_avmm_clk (chnl_avmm_clk ), + .chnl_avmm_rstn (chnl_avmm_rstn ), + .chnl_avmm_writedata (chnl_avmm_writedata ), + .chnl_avmm_address (chnl_avmm_address ), + .chnl_avmm_write (chnl_avmm_write ), + .chnl_avmm_read (chnl_avmm_read ), + .chnl_avmm_byteen (chnl_avmm_byteen ), + // PMA AVMM signals + .pma_avmmreaddata_tx_cgb (pma_avmmreaddata_tx_cgb ), // TX AVMM CGB readdata (16 for each lane) + .pma_avmmreaddata_tx_ser (pma_avmmreaddata_tx_ser ), // TX AVMM SER readdata (16 for each lane) + .pma_avmmreaddata_tx_buf (pma_avmmreaddata_tx_buf ), // TX AVMM BUF readdata (16 for each lane) + .pma_avmmreaddata_rx_ser (pma_avmmreaddata_rx_ser ), // RX AVMM SER readdata (16 for each lane) + .pma_avmmreaddata_rx_buf (pma_avmmreaddata_rx_buf ), // RX AVMM BUF readdata (16 for each lane) + .pma_avmmreaddata_rx_cdr (pma_avmmreaddata_rx_cdr ), // RX AVMM CDR readdata (16 for each lane) + .pma_avmmreaddata_rx_mux (pma_avmmreaddata_rx_mux ), // RX AVMM CDR MUX readdata (16 for each lane) + .pma_blockselect_tx_cgb (pma_blockselect_tx_cgb ), // TX AVMM CGB blockselect (1 for each lane) + .pma_blockselect_tx_ser (pma_blockselect_tx_ser ), // TX AVMM SER blockselect (1 for each lane) + .pma_blockselect_tx_buf (pma_blockselect_tx_buf ), // TX AVMM BUF blockselect (1 for each lane) + .pma_blockselect_rx_ser (pma_blockselect_rx_ser ), // RX AVMM SER blockselect (1 for each lane) + .pma_blockselect_rx_buf (pma_blockselect_rx_buf ), // RX AVMM BUF blockselect (1 for each lane) + .pma_blockselect_rx_cdr (pma_blockselect_rx_cdr ), // RX AVMM CDR blockselect (1 for each lane) + .pma_blockselect_rx_mux (pma_blockselect_rx_mux ), // RX AVMM CDR MUX blockselect (1 for each lane) + .pll_aux_atb_comp_out (pll_aux_atb_comp_out ), // Voltage comparator output for DCD (1 for each lane) + // PCS AVMM signals + .avmmreaddata_com_pcs_pma_if (out_avmmreaddata_com_pcs_pma_if), + .avmmreaddata_com_pld_pcs_if (out_avmmreaddata_com_pld_pcs_if), + .avmmreaddata_pcs8g_rx (out_avmmreaddata_pcs8g_rx ), + .avmmreaddata_pcs8g_tx (out_avmmreaddata_pcs8g_tx ), + .avmmreaddata_pipe12 (out_avmmreaddata_pipe12 ), + .avmmreaddata_rx_pcs_pma_if (out_avmmreaddata_rx_pcs_pma_if), + .avmmreaddata_rx_pld_pcs_if (out_avmmreaddata_rx_pld_pcs_if), + .avmmreaddata_tx_pcs_pma_if (out_avmmreaddata_tx_pcs_pma_if), + .avmmreaddata_tx_pld_pcs_if (out_avmmreaddata_tx_pld_pcs_if), + .blockselect_com_pcs_pma_if (out_blockselect_com_pcs_pma_if), + .blockselect_com_pld_pcs_if (out_blockselect_com_pld_pcs_if), + .blockselect_pcs8g_rx (out_blockselect_pcs8g_rx ), + .blockselect_pcs8g_tx (out_blockselect_pcs8g_tx ), + .blockselect_pipe12 (out_blockselect_pipe12 ), + .blockselect_rx_pcs_pma_if (out_blockselect_rx_pcs_pma_if ), + .blockselect_rx_pld_pcs_if (out_blockselect_rx_pld_pcs_if ), + .blockselect_tx_pcs_pma_if (out_blockselect_tx_pcs_pma_if ), + .blockselect_tx_pld_pcs_if (out_blockselect_tx_pld_pcs_if ) +); +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_plls.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_plls.sv new file mode 100644 index 0000000..ca84ca0 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/av_xcvr_plls.sv @@ -0,0 +1,726 @@ +// (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. + + +// +// Creates one or more TX plls +// +// Clock switching must use the exported reconfiguration ports +// +// $Header$ +// + +`timescale 1 ns / 1 ns + +import altera_xcvr_functions::*; + +module av_xcvr_plls #( + parameter plls = 1, // number of PLLs + parameter pll_type = "AUTO", // "AUTO","CMU","fPLL" (List i.e. "CMU,CMU,...") + parameter pll_reconfig = 0, // 0-PLL reconfig not enabled. 1-PLL reconfig enabled + parameter pll_sel = 0, // (0 - plls-1) // Which PLL clock to use + parameter refclks = 1, // number of refclks per PLL + parameter reference_clock_frequency = "0 ps", // refclk frequencies (List i.e. "100 MHz,150 MHz,156.25 MHz,...") + parameter reference_clock_select = "0", // refclk_sel per pll (List i.e. "0,3,1,2,...") + parameter output_clock_datarate = "0 Mbps", // outclk data rate (frequency*2)(List i.e. "5000 Mbps,2.5 Gbps,...") Not used if left at "0 Mbps" + parameter output_clock_frequency = "0 ps", // outclk frequency (List i.e. "5000 MHz, 1000 MHz,..."), Only used if output_clock_datarate unused. + parameter feedback_clk = "internal",// feedback clock select per pll (List i.e. "internal,external,external,...")\ + parameter tx_clk_div = 1, //(1,2,4,8) + parameter data_rate = "0ps", + parameter mode = 8, + + // Unused parameters + parameter sim_additional_refclk_cycles_to_lock = 0, // + parameter duty_cycle = 50, // duty cycle (List i.e. "50,40,55,...") + parameter phase_shift = "0 ps", // phase shift (List i.e. "0 ps, 180 ps, ...") + // Config options + parameter enable_hclk = 0, // 1 = Enable hclk PLL output (PCIe) + parameter enable_avmm = 1, // 1 = Include AVMM blocks + parameter use_generic_pll = 0, // 1 = Use generic PLL atoms, 0 = Use LC/CDR/FPLL atoms + parameter enable_mux = 1, // 1 = Enable refclk mux, 0 = Disable + parameter pll_external_enable = 0, + parameter enable_master_cgb = 0 +) ( + input wire [((pll_external_enable) ? plls : refclks)-1:0] refclk, // Overloaded. if(pll_external==1) inputs clocks from external PLLs + // if(pll_external==0) reference clock inputs to internal PLLs + input wire [plls -1:0] rst, + input wire [plls -1:0] fbclk, + + //input for master CGB + output wire [plls -1:0] outclk, + output wire [plls -1:0] locked, + output wire [plls -1:0] fboutclk, + output wire [plls -1:0] hclk, + + //output from master CGB + output wire cpulse_master, + output wire hclk_master, + output wire lfclk_master, + output wire [2 : 0] pclk_master, + + // + input wire [plls*W_A5_RECONFIG_BUNDLE_TO_XCVR -1 :0] reconfig_to_xcvr, + output wire [plls*W_A5_RECONFIG_BUNDLE_FROM_XCVR-1 :0] reconfig_from_xcvr +); + +// Macro definition to connect or disconnect ATX PLL reset input +`ifndef ALTERA_RESERVED_QIS_ES + `define ALTERA_RESERVED_XCVR_AV_CMU_PLL_RESET_CONNECT +`endif + + +localparam MAX_PLLS = 7; +localparam PLL_CNT = (plls < MAX_PLLS) ? plls : MAX_PLLS; +localparam w_bundle_to_xcvr = W_A5_RECONFIG_BUNDLE_TO_XCVR; +localparam w_bundle_from_xcvr= W_A5_RECONFIG_BUNDLE_FROM_XCVR; + +localparam [plls*2-1:0] pll_type_sel_bin = pll_type_str2bin(pll_type); + +// Set "enabled_for_reconfig" from pll_reconfig parameter +localparam enabled_for_reconfig = (pll_reconfig == 0) ? "false" : "true"; +// Use fast simulation models when reconfig is not enabled +localparam sim_use_fast_model = (enabled_for_reconfig == "false") ? "true" : "false"; + +// for Master CGB +// Select clock source for g2 and g1 based on auto_negotiation +localparam X1_CLOCK_SOURCE_SEL = (pll_sel == 5) ? "down_segmented" // 1 - clk_dn_seg + : (pll_sel == 4) ? "up_segmented" // 0 - clk_up_seg + : (pll_sel == 3) ? "ffpll" // 2 - clk_ffpll + : (pll_sel == 2) ? "ch1_txpll_b" // 4 - clk_cdr_1b + : (pll_sel == 1) ? "ch1_txpll_t" // 3 - clk_cdr_1t + : (pll_sel == 0) ? "same_ch_txpll" // 5 - clk_cdr_loc + : "x1_clk_unused"; + +localparam X1_DIV_M_SEL = (tx_clk_div == 2) ? 2 : + (tx_clk_div == 4) ? 4 : + (tx_clk_div == 8) ? 8 : + 1; + +genvar ig; // Iterator for generated loops +genvar jg; + +generate + if (enable_master_cgb == 1) begin:master_cgb + wire [MAX_PLLS-1:0] wire_clk; + + // determine what drives the HF clock input into CGB + assign wire_clk = {{(MAX_PLLS-PLL_CNT){1'b0}}, outclk}; + + arriav_hssi_pma_tx_cgb #( + .mode (mode), + .auto_negotiation ("false"), + .data_rate (data_rate), + .x1_clock_source_sel(X1_CLOCK_SOURCE_SEL), // corresponds to .clkcdrloc input + .xn_clock_source_sel("xn_up"), + .x1_div_m_sel (X1_DIV_M_SEL) + ) tx_cgb ( + .rstn (~rst ), + .pcsrstn (1'b1 ), + .clkcdrloc (wire_clk[0] ), // Switch between this + .clkcdr1t (wire_clk[1] ), + .clkcdr1b (wire_clk[2] ), + .clkffpll (wire_clk[3] ), + .clkupseg (wire_clk[4] ), + .clkdnseg (wire_clk[5] ), + .fref (1'b0 ), + .pciesw (1'b0 ), + .hfclkpxnup (hclk_master ), + .lfclkpxnup (lfclk_master ), + .cpulsexnup (cpulse_master ), + .pclkxnup (pclk_master ), + + // to serializer + .cpulse ( ), + .hfclkp ( ), + .lfclkp ( ), + .pclk ( ), + + // when used as a CGB master, these are bonding clocks + .cpulseout (cpulse_master ), + .hfclkpout (hclk_master ), + .lfclkpout (lfclk_master ), + .pclkout (pclk_master ), + .pcieswdone ( ), + + .avmmrstn (1'd1 ), + .avmmclk (1'd0 ), + .avmmwrite (1'd0 ), + .avmmread (1'd0 ), + .avmmbyteen (2'd0 ), + .avmmaddress (11'd0 ), + .avmmwritedata (16'd0), + .avmmreaddata ( ), + .blockselect ( ) + + + + `ifndef ALTERA_RESERVED_QIS + , + //.clklct (1'b0/*TODO*/ ), + //.clklcb (1'b0/*TODO*/ ), + .rxclk (1'b0 ), //to pma_rx_pma_clk + .hfclkn ( ), + .hfclknout ( ), + .lfclkn ( ), + .lfclknout ( ), + .rxiqclk ( ), + .clkbcdr1t (1'b0 ), + .clkbcdr1b (1'b0 ), + .clkbcdrloc (1'b0 ), + .clkbdnseg (1'b0 ), + .clkbffpll (1'b0 ), + //.clkblcb (1'b0 ), + //.clkblct (1'b0 ), + .clkbupseg (1'b0 ), + .cpulsex6up (1'b0 ), + .cpulsex6dn (1'b0 ), + .cpulsexndn (1'b0 ), + .hfclknx6up (1'b0 ), + .hfclknx6dn (1'b0 ), + .hfclknxndn (1'b0 ), + .hfclknxnup (1'b0 ), + .hfclkpx6up (1'b0 ), + .hfclkpx6dn (1'b0 ), + .hfclkpxndn (1'b0 ), + .lfclknx6up (1'b0 ), + .lfclknx6dn (1'b0 ), + .lfclknxndn (1'b0 ), + .lfclknxnup (1'b0 ), + .lfclkpx6up (1'b0 ), + .lfclkpx6dn (1'b0 ), + .lfclkpxndn (1'b0 ), + .pciesyncp (/*TODO*/ ), + //.pciefbclk (/*TODO*/ ), + .pclkx6up (3'b0 ), + .pclkx6dn (3'b0 ), + .pclkxndn (3'b0 ) + //.pllfbsw (/*TODO*/ ), + //.txpmasyncp (1'b0 ) + `endif // ifndef ALTERA_RESERVED_QIS + ); + end + else begin + assign pclk_master = 3'b0; + assign lfclk_master = 1'b0; + assign hclk_master = 1'b0; + assign cpulse_master = 1'b0; + end +endgenerate + +generate + for(ig=0; ig> (2*ig)) & 2'b11); + localparam [MAX_CHARS*8-1:0] pll_type_sdc = (pll_type_sel == av_xcvr_h::AV_XR_ID_PLL_TYPE_CMU ) ? "-name PLL_TYPE CMU" : + ""; + localparam use_cmu_pll = ((use_generic_pll == 0) && (pll_external_enable == 0) && (pll_type_sel == av_xcvr_h::AV_XR_ID_PLL_TYPE_CMU)) ? 1 : 0; + localparam use_avmm = ((enable_avmm == 1) && (pll_external_enable == 0)) ? 1 : 0; + + // PLL type parameter for CSR + localparam csr_pll_type = pll_type_sel; + + localparam [MAX_CHARS*8-1:0] feedback_clk_val = get_value_at_index(ig,feedback_clk); + localparam [MAX_CHARS*8-1:0] feedback_clk_sel = (feedback_clk_val == "NA") ? get_value_at_index(0,feedback_clk) : feedback_clk_val; + + // Local AVMM signals (AVMM atom <-> PLL atoms) + wire local_avmm_rstn; + wire local_avmm_clk; + wire [15:0] local_avmm_writedata; + wire [10:0] local_avmm_address; + wire [ 1:0] local_avmm_byteen; + wire local_avmm_write; + wire local_avmm_read; + wire mux_avmm_blockselect; + wire [15:0] mux_avmm_readdata; + wire cdr_avmm_blockselect; + wire [15:0] cdr_avmm_readdata; + + // Select feedback clock + wire fbclk_in; + assign fbclk_in = (feedback_clk_sel == "external") ? fbclk[ig] : fboutclk[ig]; +// initial begin +// if(!is_in_legal_set(pll_type_sel, "(CMU,AUTO)") begin +// $display("Error: parameter 'pll_type_sel' of instance '%m' has illegal value '%s' assigned to it. Valid parameter values are: '%s'.", pll_type_sel, "(CMU,AUTO)"); +// end +// end // initial + + if(use_avmm == 1) begin:avmm + // avalon MM native reconfiguration interfaces + wire pld_avmm_reset; // one for each lane + wire pld_avmm_clk; // one for each lane + wire [15:0] pld_avmm_writedata; // Avalon DPRIO writedata + wire [11:0] pld_avmm_address; // Avalon DPRIO address + wire pld_avmm_write; // Avalon DPRIO write + wire pld_avmm_read; // Avalon DPRIO read + wire [15:0] pld_avmm_readdata; // Avalon DPRIO readdata + + // CSR/DPRIO selection signals + wire csr_avmm_n_sel; // Select Soft CSR or DPRIO + reg csr_avmm_n_sel_r; // Select Soft CSR or DPRIO (read) + // Soft CSR Avalon signals + wire csr_write; // Avalon write to Soft CSR + wire csr_read; // Avalon read to Soft CSR + wire [15:0] csr_readdata; // Avalon readdata from Soft CSR + // DPRIO Avalon signals + wire avmm_write; // Avalon write to DPRIO + wire avmm_read; // Avalon read to DPRIO + wire [15:0] avmm_readdata; // Avalon readdata from DPRIO + + wire [11:0] pmatestbussel; + wire [23:0] pmatestbus; + + wire interface_sel; + wire ser_shift_load; + + wire [90-1:0] chnl_avmm_blockselect; + wire [15:0] chnl_avmm_readdata [0:(90-1)]; + wire [90*16-1:0] chnl_avmm_readdatabus; + + for(jg = 0; jg < 90; jg = jg + 1) begin:avmm_assigns + assign chnl_avmm_readdatabus[jg*16+:16] = chnl_avmm_readdata[jg]; + assign {chnl_avmm_readdata[jg],chnl_avmm_blockselect[jg]} = + // TX PMA connections + (jg == 5) ? {cdr_avmm_readdata,cdr_avmm_blockselect} : + (jg == 6) ? {mux_avmm_readdata,mux_avmm_blockselect} : + {16'd0,1'b0}; + end + + // Mux between hard and soft reconfig registers + assign csr_avmm_n_sel = pld_avmm_address[11]; + assign pld_avmm_readdata = csr_avmm_n_sel_r ? csr_readdata : avmm_readdata; + assign avmm_write = pld_avmm_write & ~csr_avmm_n_sel; + assign avmm_read = pld_avmm_read & ~csr_avmm_n_sel; + assign csr_write = pld_avmm_write & csr_avmm_n_sel; + assign csr_read = pld_avmm_read & csr_avmm_n_sel; + + always @(posedge pld_avmm_clk or posedge pld_avmm_reset) + if(pld_avmm_reset) csr_avmm_n_sel_r <= 1'b0; + else csr_avmm_n_sel_r <= csr_avmm_n_sel; + + // Extract and compose bundled signals + av_reconfig_bundle_to_xcvr #( + .native_ifs (1 ) // number of native reconfig interfaces + ) av_reconfig_bundle_to_xcvr_inst( + // bundled reconfig buses + .reconfig_to_xcvr (reconfig_to_xcvr [ig*w_bundle_to_xcvr +:w_bundle_to_xcvr ] ), + .reconfig_from_xcvr (reconfig_from_xcvr[ig*w_bundle_from_xcvr+:w_bundle_from_xcvr ] ), + // native reconfig sources + .native_reconfig_clk (pld_avmm_clk ), + .native_reconfig_reset (pld_avmm_reset ), + .native_reconfig_writedata(pld_avmm_writedata ), + .native_reconfig_address (pld_avmm_address ), + .native_reconfig_write (pld_avmm_write ), + .native_reconfig_read (pld_avmm_read ), + // native reconfig sinks + .native_reconfig_readdata (pld_avmm_readdata ), // Avalon DPRIO readdata + + // calibration connections + .tx_cal_busy (/*unused*/ ), + .rx_cal_busy (/*unused*/ ), + + .pif_testbus (pmatestbus ), + .pif_testbus_sel (pmatestbussel ), + .pif_atbcompout (1'b0 ), + + .pif_interface_sel (interface_sel ), + .pif_ser_shift_load (ser_shift_load ) + ); + + // Instantiate AVMM_INTERFACE + arriav_hssi_avmm_interface av_hssi_avmm_interface_inst ( + .avmmrstn (1'b1 ), + .avmmclk (pld_avmm_clk ), + .avmmwrite (avmm_write ), + .avmmread (avmm_read ), + .avmmbyteen (2'b11 ), + .avmmaddress (pld_avmm_address[10:0] ), + .avmmwritedata (pld_avmm_writedata ), + .avmmreaddata (avmm_readdata ), + + .blockselect (chnl_avmm_blockselect ), + .readdatachnl (chnl_avmm_readdatabus ), + .clkchnl (local_avmm_clk ), + .rstnchnl (local_avmm_rstn ), + .writedatachnl (local_avmm_writedata ), + .regaddrchnl (local_avmm_address ), + .writechnl (local_avmm_write ), + .readchnl (local_avmm_read ), + .byteenchnl (local_avmm_byteen ), + + // The following ports belong to pm_tst_mux blocks in the PMA + .pmatestbus (pmatestbus ), + .pmatestbussel (pmatestbussel ), + + // + .scanmoden (1'b1 ), + .scanshiftn (1'b1 ), + .sershiftload (ser_shift_load ), + .interfacesel (interface_sel ), + + .refclkdig (/*unused*/ ), + .avmmreservedin (/*unused*/ ), + + .avmmreservedout (/*unused*/ ), + .dpriorstntop (/*unused*/ ), + .dprioclktop (/*unused*/ ), + .mdiodistopchnl (/*unused*/ ), + .dpriorstnmid (/*unused*/ ), + .dprioclkmid (/*unused*/ ), + .mdiodismidchnl (/*unused*/ ), + .dpriorstnbot (/*unused*/ ), + .dprioclkbot (/*unused*/ ), + .mdiodisbotchnl (/*unused*/ ), + .dpriotestsitopchnl (/*unused*/ ), + .dpriotestsimidchnl (/*unused*/ ), + .dpriotestsibotchnl (/*unused*/ ) + + ); + + // Soft reconfig CSR + av_xcvr_avmm_csr #( + .pll_type (csr_pll_type), // 0-None,1-CMU,2-LC/ATX,3-fPLL + .rx_enable (0 ), // Indicates whether this interface contains an rx channel. + .tx_enable (0 ), // Indicates whether this interface contains a tx channel + // Service request parameters + .request_dcd (0), // Request Duty Cycle Distortion correction at startup + .request_vrc (0) // Request Voltage Regulator Calibration at startup + ) av_xcvr_avmm_csr_inst ( + // Avalon interface + .av_clk (pld_avmm_clk ), + .av_reset (pld_avmm_reset ), + .av_writedata (pld_avmm_writedata ), + .av_address (pld_avmm_address[3:0]), + .av_write (csr_write ), + .av_read (csr_read ), + .av_readdata (csr_readdata ), + + // Reset overrides (used only in channel) + .tx_rst_ovr (/*unused*/ ), + .tx_digital_rst_n_val (/*unused*/ ), + .rx_rst_ovr (/*unused*/ ), + .rx_digital_rst_n_val (/*unused*/ ), + .rx_analog_rst_n_val (/*unused*/ ), + + // Offset Cancellation + .hardoccaldone (/*unused*/ ), + .hardoccalen (/*unused*/ ), + // PRBS + .pcs_8g_prbs_done (/*unused*/), + .pcs_8g_prbs_err (/*unused*/), + // DCD + .dcd_ack (/*unused*/ ), + .dcd_sum_a (/*unused*/ ), + .dcd_sum_b (/*unused*/ ), + // SLPBK + .seriallpbken (/*unused*/ ), + // Channel STATUS + .stat_pll_locked (locked [ig]), + .stat_tx_digital_reset(/*unused*/ ), + .stat_rx_digital_reset(/*unused*/ ) + ); + end else begin:no_avmm + assign reconfig_from_xcvr= {(plls*w_bundle_from_xcvr){1'b0}}; + assign local_avmm_rstn = 1'b1; + assign local_avmm_clk = 1'b0; + assign local_avmm_writedata = 16'd0; + assign local_avmm_address = 11'd0; + assign local_avmm_byteen = 2'b00; + assign local_avmm_write = 1'b0; + assign local_avmm_read = 1'b0; + end + + // PLL + if(pll_external_enable == 1) begin:external_pll + // Pass refclk (PLL output clock from external PLL when "external_pll" == 1) to output (or CGB) + assign outclk [ig] = refclk[ig]; + assign locked [ig] = 1'b0; + assign fboutclk[ig] = 1'b0; + assign hclk [ig] = 1'b0; + end else if(use_generic_pll == 1) begin:generic_pll + // No hclk with generic_pll + assign hclk[ig] = 1'b0; + + // Create generic TX pll. Set type using attribute + (* altera_attribute = pll_type_sdc *) + generic_pll #( + .reference_clock_frequency(refclk_freq_fnl), + .output_clock_frequency (outclk_freq_fnl) + ) tx_pll ( + .fbclk (fbclk_in ), + .fboutclk (fboutclk [ig] ), + .refclk (refclk [refclk_sel_fnl] ), + .rst (rst [ig] ), + .outclk (outclk [ig] ), + .locked (locked [ig] ) + + `ifndef ALTERA_RESERVED_QIS + , + // Inputs from Generic PLL Adapter + .writerefclkdata (/*unused*/ ), + .writeoutclkdata (/*unused*/ ), + .writephaseshiftdata(/*unused*/ ), + .writedutycycledata (/*unused*/ ), + // Outputs to Generic PLL Adapter + .readrefclkdata (/*unused*/ ), + .readoutclkdata (/*unused*/ ), + .readphaseshiftdata (/*unused*/ ), + .readdutycycledata (/*unused*/ ) + `endif // ifndef ALTERA_RESERVED_QIS + ); + + // Terminate unused avmm signals + assign cdr_avmm_readdata = 16'd0; + assign mux_avmm_readdata = 16'd0; + assign cdr_avmm_blockselect = 1'b0; + assign mux_avmm_blockselect = &{1'b0,local_avmm_rstn,local_avmm_clk,local_avmm_writedata,local_avmm_address, + local_avmm_write,local_avmm_read,local_avmm_byteen,cdr_avmm_readdata, + cdr_avmm_blockselect, 1'b0, 1'b0, + mux_avmm_readdata,mux_avmm_blockselect}; // Warning avoidance + end else begin:pll + // Connect feedback clock only in "external" feedback mode + assign fboutclk[ig] = 1'b0; + + // CMU PLL + if(use_cmu_pll) begin:cmu_pll + // Determine feedback clock selection + localparam [MAX_CHARS*8-1:0] feedback_clk_fnl = (feedback_clk_sel == "external") ? "extclk" : "vcoclk"; + localparam [MAX_CHARS*8-1:0] refclk_sel_param = refclk_sel_fnl == 10 ? "ref_iqclk10" : + refclk_sel_fnl == 9 ? "ref_iqclk9" : + refclk_sel_fnl == 8 ? "ref_iqclk8" : + refclk_sel_fnl == 7 ? "ref_iqclk7" : + refclk_sel_fnl == 6 ? "ref_iqclk6" : + refclk_sel_fnl == 5 ? "ref_iqclk5" : + refclk_sel_fnl == 4 ? "ref_iqclk4" : + refclk_sel_fnl == 3 ? "ref_iqclk3" : + refclk_sel_fnl == 2 ? "ref_iqclk2" : + refclk_sel_fnl == 1 ? "ref_iqclk1" : + "ref_iqclk0" ; + + localparam [MAX_CHARS*8-1:0] HCLK_ENABLE = (enable_hclk == 1) ? "true" : "false"; + + wire mux_refclk_out; + wire cmurstn; + + if(enable_mux == 1) begin:pll_mux + wire [10:0] int_refclks; // internal refclks + + assign int_refclks = { {(11-refclks){1'b0}} , refclk}; + + arriav_hssi_pma_cdr_refclk_select_mux + #( + .refclk_select(refclk_sel_param), + .reference_clock_frequency(refclk_freq_fnl) + //parameter lpm_type = "stratixv_hssi_pma_cdr_refclk_select_mux"; + //parameter mux_type = "cdr_refclk_select_mux"; // cdr_refclk_select_mux|lc_refclk_select_mux + //parameter channel_number = 0 ; + //parameter avmm_group_channel_index = 0; + //parameter use_default_base_address = "true"; + //parameter user_base_address = 0; + + ) pll_refclk_select_mux ( + // AVMM inteface + .avmmclk (local_avmm_clk ), + .avmmrstn (local_avmm_rstn ), + .avmmwrite (local_avmm_write ), + .avmmread (local_avmm_read ), + .avmmbyteen (local_avmm_byteen ), + .avmmaddress (local_avmm_address ), + .avmmwritedata(local_avmm_writedata ), + .avmmreaddata (mux_avmm_readdata ), + .blockselect (mux_avmm_blockselect ), + + // Refclk inputs + .refiqclk0 (int_refclks[0] ), + .refiqclk1 (int_refclks[1] ), + .refiqclk10 (int_refclks[10]), + .refiqclk2 (int_refclks[2] ), + .refiqclk3 (int_refclks[3] ), + .refiqclk4 (int_refclks[4] ), + .refiqclk5 (int_refclks[5] ), + .refiqclk6 (int_refclks[6] ), + .refiqclk7 (int_refclks[7] ), + .refiqclk8 (int_refclks[8] ), + .refiqclk9 (int_refclks[9] ), + + // Selected refclk output + .clkout (mux_refclk_out ) + + `ifndef ALTERA_RESERVED_QIS + , + // Unused + .calclk (1'b0), + .ffplloutbot (1'b0), + .ffpllouttop (1'b0), + .pldclk (1'b0), + .rxiqclk0 (1'b0), + .rxiqclk1 (1'b0), + .rxiqclk10 (1'b0), + .rxiqclk2 (1'b0), + .rxiqclk3 (1'b0), + .rxiqclk4 (1'b0), + .rxiqclk5 (1'b0), + .rxiqclk6 (1'b0), + .rxiqclk7 (1'b0), + .rxiqclk8 (1'b0), + .rxiqclk9 (1'b0) + `endif // ifndef ALTERA_RESERVED_QIS + ); + end else begin:no_mux + assign mux_refclk_out = refclk [refclk_sel_fnl]; + end + + // Disconnect reset for ES silicon unless macro is defined + `ifdef ALTERA_RESERVED_XCVR_AV_CMU_PLL_RESET_CONNECT + assign cmurstn = ~rst[ig]; + `else + assign cmurstn = 1'b1; + `endif + // Create CMU pll atom + arriav_channel_pll + #( + // Parameter declarations and default value assignments + .reference_clock_frequency(refclk_freq_fnl), + .output_clock_frequency (outclk_freq_fnl), + .fb_sel(feedback_clk_fnl), + .cgb_clk_enable("true"), + .txpll_hclk_driver_enable(HCLK_ENABLE), + .enabled_for_reconfig(enabled_for_reconfig), + .sim_use_fast_model(sim_use_fast_model) + //parameter avmm_group_channel_index = 0, + //parameter use_default_base_address = "true", + //parameter user_base_address = 0, + //parameter bbpd_salatch_offset_ctrl_clk0 = "offset_0mv", + //parameter bbpd_salatch_offset_ctrl_clk180 = "offset_0mv", + //parameter bbpd_salatch_offset_ctrl_clk270 = "offset_0mv", + //parameter bbpd_salatch_offset_ctrl_clk90 = "offset_0mv", + //parameter bbpd_salatch_sel = "normal", + //parameter bypass_cp_rgla = "false", + //parameter cdr_atb_select = "atb_disable", + //parameter charge_pump_current_test = "enable_ch_pump_normal", + //parameter clklow_fref_to_ppm_div_sel = 1, + //parameter clock_monitor = "lpbk_data", + //parameter diag_rev_lpbk = "false", + //parameter eye_monitor_bbpd_data_ctrl = "cdr_data", + //parameter fast_lock_mode = "false", + //parameter gpon_lock2ref_ctrl = "lck2ref", + //parameter hs_levshift_power_supply_setting = 1, + //parameter ignore_phslock = "false", + //parameter l_counter_pd_clock_disable = "false", + //parameter m_counter = 4, + //parameter pcie_freq_control = "pcie_100mhz", + //parameter pd_charge_pump_current_ctrl = 5, + //parameter pd_l_counter = 1, + //parameter pfd_charge_pump_current_ctrl = 20, + //parameter pfd_l_counter = 1, + //parameter powerdown = "false", + //parameter ref_clk_div = 1, + //parameter regulator_volt_inc = "0", + //parameter replica_bias_ctrl = "true", + //parameter reverse_serial_lpbk = "false", + //parameter ripple_cap_ctrl = "none", + //parameter rxpll_pd_bw_ctrl = 300, + //parameter rxpll_pfd_bw_ctrl = 3200, + //parameter vco_overange_ref = "off", + //parameter vco_range_ctrl_en = "false" + ) tx_pll ( + // AVMM interface + .avmmaddress (local_avmm_address ), + .avmmbyteen (local_avmm_byteen ), + .avmmclk (local_avmm_clk ), + .avmmread (local_avmm_read ), + .avmmrstn (local_avmm_rstn ), + .avmmwrite (local_avmm_write ), + .avmmwritedata (local_avmm_writedata ), + .avmmreaddata (cdr_avmm_readdata ), + .blockselect (cdr_avmm_blockselect ), + + // Inputs + .refclk (mux_refclk_out ), + .extclk (fbclk_in ), + .ltd (1'b1 ), // PMA interface block has a invert on LTD so need to drive 1 on LTD to see actual 0. + .ltr (1'b1 ), + .rstn (cmurstn ), + .pciel (1'b0 ), + .pciesw (2'b00 ), //set to 0 for the tx pll + + // Outputs + .clkcdr (outclk[ig] ), + .pfdmodelock (locked[ig] ), + .txpllhclk (hclk[ig] ) + + // Unused inputs + `ifndef ALTERA_RESERVED_QIS + , + .crurstb (/*unused*/), + .clkindeser (/*unused*/), + .earlyeios (/*unused*/), + .lpbkpreen (/*unused*/), + .occalen (/*unused*/), + .ppmlock (/*unused*/), + .rxp (/*unused*/), + .sd (/*unused*/), + + // Unused outputs + .ck0pd (/*unused*/), + .ck180pd (/*unused*/), + .ck270pd (/*unused*/), + .ck90pd (/*unused*/), + .clk270bdes (/*unused*/), + .clk90bdes (/*unused*/), + .clklow (/*unused*/), + .deven (/*unused*/), + .dodd (/*unused*/), + .fref (/*unused*/), + .pdof (/*unused*/), + .rxlpbdp (/*unused*/), + .rxlpbp (/*unused*/), + .rxplllock (/*unused*/), + .txrlpbk (/*unused*/), + .vctrloverrange (/*unused*/) + `endif // ifndef ALTERA_RESERVED_QIS + ); + end // CMU PLL + end // Not Generic PLL + end +endgenerate + +// Function takes in a string of comma seperated values containing PLL types. +// returns a binary where every two bits represents the PLL type. Allows +// Up to 10 PLLs +function [plls*2-1:0] pll_type_str2bin( + input [MAX_CHARS*MAX_STRS*8-1:0] pll_type_set +); + int index; + reg [MAX_CHARS*8-1:0] pll_type_str; + reg [1:0] pll_type_bin; + + pll_type_str2bin = {plls{2'b00}}; + for(index = 0; index < plls; index = index + 1) begin + pll_type_str = altera_xcvr_functions::get_value_at_index(index,pll_type_set); + pll_type_bin = (pll_type_str == "fPLL") ? av_xcvr_h::AV_XR_ID_PLL_TYPE_FPLL[1:0]: + (pll_type_str == "CMU") ? av_xcvr_h::AV_XR_ID_PLL_TYPE_CMU [1:0]: + (pll_type_str == "AUTO") ? av_xcvr_h::AV_XR_ID_PLL_TYPE_CMU [1:0]: + av_xcvr_h::AV_XR_ID_PLL_TYPE_NONE[1:0]; + pll_type_str2bin = pll_type_str2bin | (( {plls{2'b00}} | pll_type_bin ) << (index*2)); + end +endfunction + +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/cv_xcvr_xaui.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/cv_xcvr_xaui.sv new file mode 100644 index 0000000..7937080 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/cv_xcvr_xaui.sv @@ -0,0 +1,450 @@ +// (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: xaui verilog for Arria V +// +// Authors: hhleong 08-May-2012 +// +// Copyright (c) Altera Corporation 1997 - 2012 +// All rights reserved. +// +//----------------------------------------------------------------------------- +module cv_xcvr_xaui #( + // initially found in sv_xcvr_custom_phy + parameter device_family = "Cyclone V", + parameter protocol_hint = "basic", // (basic, gige) + parameter operation_mode = "Duplex", //legal value: TX,RX,Duplex + parameter interface_type = "Soft XAUI", + parameter soft_pcs_legacy_new_n = 0, + parameter xaui_pll_type = "CMU", + parameter use_control_and_status_ports = 0, + parameter lanes = 4, //legal value: 1+ + parameter bonded_group_size = 4, //legal value: integer from 1 .. lanes + parameter bonded_mode = "xN", // (xN, fb_compensation) + parameter pma_bonding_mode = "xN", // ("x1", "xN") + parameter pcs_pma_width = 10, //legal value: 8, 10, 16, 20 + parameter ser_base_factor = 10, //legal value: 8,10 + parameter ser_words = 2, //legal value 1,2,4 + parameter data_rate = "3125 Mbps", //remove this later + parameter base_data_rate = "3125 Mbps", // (PLL data rate) + parameter reconfig_interfaces = 1, + + // tx bitslip + parameter tx_bitslip_enable = "false", + + //optional coreclks + parameter tx_use_coreclk = "false", + parameter rx_use_coreclk = "true", + parameter en_synce_support = 0, //expose CDR ref-clk in this mode + + // 8B10B + parameter use_8b10b = "false", //legal value: "false", "true" + parameter use_8b10b_manual_control = "false", + + //Word Aligner + parameter word_aligner_mode = "sync_state_machine", //legal value: bitslip, sync_state_machine, manual + parameter word_aligner_state_machine_datacnt = 1, //legal value: 0-256 + parameter word_aligner_state_machine_errcnt = 1, //legal value: 0-256 + parameter word_aligner_state_machine_patterncnt = 10, //legal value: 0-256 + parameter word_aligner_pattern_length = 10, + parameter word_align_pattern = "0101111100", + parameter run_length_violation_checking = 40, //legal value: 0,1+ + + //RM FIFO + parameter use_rate_match_fifo = 0, //legal value: 0,1 + parameter rate_match_pattern1 = "11010000111010000011", + parameter rate_match_pattern2 = "00101111000101111100", + + //Byte Ordering Block + parameter byte_order_mode = "none", //legal value: None, sync_state_machine, PLD control + parameter byte_order_pattern = "000000000", + parameter byte_order_pad_pattern = "111111011", + + //Hidden parameter to enable 0ppm legality bypass + parameter coreclk_0ppm_enable = "false", + + //PLL + parameter pll_refclk_cnt = 1, // Number of reference clocks + parameter pll_refclk_freq = "156.25 MHz", // Frequency of each reference clock + parameter pll_refclk_select = "0", // Selects the initial reference clock for each TX PLL + parameter cdr_refclk_select = 0, // Selects the initial reference clock for all RX CDR PLLs + parameter plls = 1, // (1+) + parameter pll_type = "CMU", // PLL type for each PLL + parameter pll_select = 0, // Selects the initial PLL + parameter pll_reconfig = 0, // (0,1) 0-Disable PLL reconfig, 1-Enable PLL reconfig + parameter pll_external_enable = 0, // (0,1) 0-Disable external TX PLL, 1-Enable external TX PLL + + // initially found in siv_xcvr_custom_phy + // Analog Parameters + parameter gxb_analog_power = "AUTO", //legal value: AUTO,2.5V,3.0V,3.3V,3.9V + parameter pll_lock_speed = "AUTO", + parameter tx_analog_power = "AUTO", //legal value: AUTO,1.4V,1.5V + parameter tx_slew_rate = "OFF", + parameter tx_termination = "OCT_100_OHMS", //legal value: OCT_85_OHMS,OCT_100_OHMS,OCT_120_OHMS,OCT_150_OHMS + parameter tx_use_external_termination = "false", //legal value: true, false + parameter tx_preemp_pretap = 0, + parameter tx_preemp_pretap_inv = "FALSE", + parameter tx_preemp_tap_1 = 0, + parameter tx_preemp_tap_2 = 0, + parameter tx_preemp_tap_2_inv = "FALSE", + parameter tx_vod_selection = 2, + parameter tx_common_mode = "0.65V", //legal value: 0.65V + parameter rx_pll_lock_speed = "AUTO", + parameter rx_common_mode = "0.82V", //legal value: "0.65V" + parameter rx_termination = "OCT_100_OHMS", //legal value: OCT_85_OHMS,OCT_100_OHMS,OCT_120_OHMS,OCT_150_OHMS + parameter rx_use_external_termination = "false", //legal value: true, false + parameter rx_eq_dc_gain = 1, + parameter rx_eq_ctrl = 16, + + //Param siv_xcvr_custom_phy.mgmt_clk_in_mhz has default '50', but module-level default is '150' + parameter mgmt_clk_in_mhz = 250, //needed for reset controller timed delays + parameter embedded_reset = 1, // (0,1) 1-Enable embedded reset controller + parameter channel_interface = 0, //legal value: (0,1) 1-Enable channel reconfiguration + parameter starting_channel_number = 0, //legal value: 0+em + parameter rx_ppmselect = 32, + parameter rx_signal_detect_threshold = 2, + parameter rx_use_cruclk = "FALSE" + +) ( + input wire pll_ref_clk, // refclk.clk + input wire cdr_ref_clk, // used only in SyncE mode + input wire xgmii_tx_clk, // xgmii_tx_clk.clk + output wire xgmii_rx_clk, // xgmii_rx_clk.clk + input wire phy_mgmt_clk, // mgmt_clk.clk + input wire phy_mgmt_clk_reset, // mgmt_clk_rst.reset_n + input wire [7:0] phy_mgmt_address, // phy_mgmt.address + output wire phy_mgmt_waitrequest, // .waitrequest + input wire phy_mgmt_read, // .read + output wire [31:0] phy_mgmt_readdata, // .readdata + input wire phy_mgmt_write, // .write + input wire [31:0] phy_mgmt_writedata, // .writedata + input wire [71:0] xgmii_tx_dc, // xgmii_tx_dc.data + output wire [71:0] xgmii_rx_dc, // xgmii_rx_dc.data + output wire [3:0] xaui_tx_serial_data, // xaui_tx_serial.export + input wire [3:0] xaui_rx_serial_data, // xaui_rx_serial.export + output wire rx_ready, // rx_pma_ready.data + output wire tx_ready, // tx_pma_ready.data + output wire [3:0] rx_recovered_clk, // rx recovered clock from cdr +// optional control and status ports + input wire rx_digitalreset, + input wire tx_digitalreset, + output wire rx_channelaligned, + output wire [7:0] rx_disperr, + output wire [7:0] rx_errdetect, + output wire [7:0] rx_syncstatus, + output wire [229:0] reconfig_from_xcvr, + input wire [349:0] reconfig_to_xcvr + +); + +import altera_xcvr_functions::*; + + wire alt_pma_controller_0_cal_blk_pdn_data; + wire alt_pma_controller_0_pll_pdn0_data; + wire pll_locked_data; + wire [7:0] rx_disperr_data; + wire [7:0] rx_errdetect_data; + wire [3:0] alt_pma_ch_controller_0_rx_analog_rst_data; + wire [3:0] alt_pma_ch_controller_0_tx_digital_rst_data; + wire [3:0] alt_pma_ch_controller_0_rx_digital_rst_data; + wire hxaui_csr_r_rx_digitalreset_data; + wire hxaui_csr_r_tx_digitalreset_data; + wire hxaui_csr_simulation_flag_data; + wire alt_pma_controller_0_pll_pdn; + wire alt_pma_0_tx_out_clk_clk; + wire alt_pma_0_tx_out_clk; + wire [3:0] alt_pma_0_rx_recovered_clk_clk; + wire [79:0] sxaui_0_tx_parallel_data_data; + wire [79:0] alt_pma_0_rx_parallel_data_data; + wire [3:0] alt_pma_0_rx_is_lockedtodata_data; + wire rx_pma_ready; + wire sxaui_rst_done; + + wire [5:0] sc_pma_ch_controller_address; + wire sc_pma_ch_controller_read; + wire [31:0] sc_pma_ch_controller_readdata; + wire sc_pma_ch_controller_waitrequest; + wire sc_pma_ch_controller_write; + + + wire [1:0] sc_pma_controller_address; + wire sc_pma_controller_read; + wire [31:0] sc_pma_controller_readdata; + wire sc_pma_controller_waitrequest; + wire sc_pma_controller_write; + + wire [4:0] sc_csr_address; + wire sc_csr_read; + wire [31:0] sc_csr_readdata; + wire sc_csr_write; + +// assign output wires for status ports - whether or not they are used will be decided by the top level + assign rx_disperr = rx_disperr_data; + assign rx_errdetect = rx_errdetect_data; + assign rx_recovered_clk = alt_pma_0_rx_recovered_clk_clk; + assign alt_pma_0_tx_out_clk_clk = alt_pma_0_tx_out_clk; + + /////////////////////////////////////////////////////////////////////// + // Decoder for multiple slaves of pma_ch_control,pma_control,hxaui i/f + /////////////////////////////////////////////////////////////////////// + alt_xcvr_mgmt2dec_xaui mgmtdec_xaui ( + .mgmt_clk_reset (phy_mgmt_clk_reset), + .mgmt_clk (phy_mgmt_clk), + .mgmt_address (phy_mgmt_address), + .mgmt_read (phy_mgmt_read), + .mgmt_write (phy_mgmt_write), + .mgmt_readdata (phy_mgmt_readdata), + .mgmt_waitrequest (phy_mgmt_waitrequest), + + // internal interface to 'top' pma ch controller block + .sc_pma_ch_controller_readdata (sc_pma_ch_controller_readdata), + .sc_pma_ch_controller_waitrequest (sc_pma_ch_controller_waitrequest), + .sc_pma_ch_controller_address (sc_pma_ch_controller_address), //6 bit wide + .sc_pma_ch_controller_read (sc_pma_ch_controller_read), + .sc_pma_ch_controller_write (sc_pma_ch_controller_write), + + // internal interface to 'top' pma controller block + .sc_pma_controller_readdata (sc_pma_controller_readdata), + .sc_pma_controller_waitrequest (sc_pma_controller_waitrequest), + .sc_pma_controller_address (sc_pma_controller_address), //2 bit wide + .sc_pma_controller_read (sc_pma_controller_read), + .sc_pma_controller_write (sc_pma_controller_write), + + // internal interface to 'top' hxaui csr block + .sc_csr_readdata (sc_csr_readdata), + .sc_csr_waitrequest (1'b0), // PCS CSR is always ready + .sc_csr_address (sc_csr_address), //5 bit wide + .sc_csr_read (sc_csr_read), + .sc_csr_write (sc_csr_write) + ); + + /////////////////////////////////////////////////////////////////////// + // ALT_PMA + /////////////////////////////////////////////////////////////////////// + generate + if (interface_type == "Soft XAUI") begin + (* ALTERA_ATTRIBUTE = {"-name SDC_STATEMENT \"set_false_path -from [get_registers {*av_xcvr_xaui*hxaui_csr*hxaui_csr_reset0q[1]}] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*pll_inreset*]\" ;-name SDC_STATEMENT \"set_false_path -from [get_registers {*av_xcvr_xaui*hxaui_csr*hxaui_csr_reset0q[1]}] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*tx_reset*]\" ;-name SDC_STATEMENT \"set_false_path -from [get_registers {*sxaui_0*alt_soft_xaui_pcs*xaui_rx*disp_err_delay[*]}] -to [get_registers *xaui_phy*hxaui_csr*rx*_c[*]]\" ;-name SDC_STATEMENT \"set_false_path -from [get_registers {*sxaui_0*alt_soft_xaui_pcs*xaui_rx*pcs_rx_syncstatus[*]}] -to [get_registers *xaui_phy*hxaui_csr*rx*_c[*]]\" ;-name SDC_STATEMENT \"set_false_path -from [get_registers {*sxaui_0*alt_soft_xaui_pcs*xaui_rx*channel_align_synchclk[*]}] -to [get_registers *xaui_phy*hxaui_csr*rx*_c[*]]\" ;-name SDC_STATEMENT \"set_false_path -from [get_registers {*av_xcvr_xaui*hxaui_csr*hxaui_csr_reset0q[1]}] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*rx_reset*]\" ;-name SDC_STATEMENT \"set_false_path -from [get_registers {*av_xcvr_xaui*hxaui_csr*hxaui_csr_simulation_flag0q}] -to [get_registers *sxaui_0*alt_soft_xaui_pcs*pcs_reset*simulation_flag_f]\""} *) + av_xcvr_low_latency_phy_nr #( + .device_family(device_family), + .protocol_hint(protocol_hint), + .lanes(lanes), + .pma_bonding_mode(pma_bonding_mode), + .pcs_pma_width(pcs_pma_width), + .ser_base_factor(ser_base_factor), + .ser_words(ser_words), + .mgmt_clk_in_mhz(mgmt_clk_in_mhz), + .data_rate(data_rate), + .base_data_rate(base_data_rate), + .en_synce_support(en_synce_support), //expose CDR ref-clk in this mode + .plls(plls), + .pll_type(pll_type), + .pll_select(pll_select), + .pll_reconfig(pll_reconfig), + .pll_refclk_cnt(pll_refclk_cnt), + .pll_refclk_freq(pll_refclk_freq), + .pll_refclk_select(pll_refclk_select), + .cdr_refclk_select(cdr_refclk_select), + .operation_mode(operation_mode), + .starting_channel_number(starting_channel_number), + .bonded_group_size(bonded_group_size), + .embedded_reset(embedded_reset), + .channel_interface(channel_interface), + .use_8b10b(use_8b10b), + .use_8b10b_manual_control(use_8b10b_manual_control), + .tx_use_coreclk(tx_use_coreclk), + .rx_use_coreclk(rx_use_coreclk), + .tx_bitslip_enable(tx_bitslip_enable), + .word_aligner_mode(word_aligner_mode), + .word_aligner_state_machine_datacnt(word_aligner_state_machine_datacnt), + .word_aligner_state_machine_errcnt(word_aligner_state_machine_errcnt), + .word_aligner_state_machine_patterncnt(word_aligner_state_machine_patterncnt), + .run_length_violation_checking(run_length_violation_checking), + .word_align_pattern(word_align_pattern), + .word_aligner_pattern_length(word_aligner_pattern_length), + .use_rate_match_fifo(use_rate_match_fifo), + .rate_match_pattern1(rate_match_pattern1), + .rate_match_pattern2(rate_match_pattern2), + .byte_order_mode(byte_order_mode), + .byte_order_pattern(byte_order_pattern), + .byte_order_pad_pattern(byte_order_pad_pattern), + .coreclk_0ppm_enable(coreclk_0ppm_enable) + ) alt_pma_0 ( + .mgmt_clk (phy_mgmt_clk), + .mgmt_clk_reset (phy_mgmt_clk_reset), + .mgmt_address (8'h40 | sc_pma_ch_controller_address), + .mgmt_read (sc_pma_ch_controller_read), + .mgmt_readdata (sc_pma_ch_controller_readdata), + .mgmt_write (sc_pma_ch_controller_write), + .mgmt_writedata (phy_mgmt_writedata), + .mgmt_waitrequest (sc_pma_ch_controller_waitrequest), + .rx_ready (rx_ready), + .tx_ready (tx_ready), + .pll_locked (pll_locked_data), + .rx_coreclk ({4{alt_pma_0_rx_recovered_clk_clk[2]}}), + .pll_ref_clk (pll_ref_clk), + .cdr_ref_clk (cdr_ref_clk), // used only in SyncE mode + .tx_coreclk (4'b0), + //.rx_coreclk (), //edit here + .tx_parallel_data (sxaui_0_tx_parallel_data_data), + .tx_serial_data (xaui_tx_serial_data), + .tx_clkout (alt_pma_0_tx_out_clk), + .tx_bitslip (28'b0), + .rx_serial_data (xaui_rx_serial_data), + .rx_parallel_data (alt_pma_0_rx_parallel_data_data), + .rx_clkout (alt_pma_0_rx_recovered_clk_clk), + .rx_bitslip (4'b0), + .rx_syncstatus (rx_syncstatus), + .rx_is_lockedtodata (alt_pma_0_rx_is_lockedtodata_data), + .rx_is_lockedtoref (), + .reconfig_to_xcvr (reconfig_to_xcvr), + .reconfig_from_xcvr (reconfig_from_xcvr), + .tx_digital_rst (alt_pma_ch_controller_0_tx_digital_rst_data), + .rx_digital_rst (alt_pma_ch_controller_0_rx_digital_rst_data) + ); + + + end else begin + assign rx_pma_ready = 1'b0; + assign tx_ready = 1'b0; + assign sxaui_rst_done = 1'b0; // no hard xaui support + end + endgenerate + + /////////////////////////////////////////////////////////////////////// + // PMA Controller + /////////////////////////////////////////////////////////////////////// + alt_pma_controller_tgx #( + .number_of_plls (1), + .sync_depth (2), + .tx_pll_reset_hold_time (20) + ) alt_pma_controller_0 ( + .clk (phy_mgmt_clk), + .rst (phy_mgmt_clk_reset), + .pma_mgmt_address (sc_pma_controller_address), + .pma_mgmt_read (sc_pma_controller_read), + .pma_mgmt_readdata (sc_pma_controller_readdata), + .pma_mgmt_write (sc_pma_controller_write), + .pma_mgmt_writedata (phy_mgmt_writedata), + .pma_mgmt_waitrequest (sc_pma_controller_waitrequest), + .cal_blk_clk (phy_mgmt_clk), + .cal_blk_pdn (alt_pma_controller_0_cal_blk_pdn_data), + .tx_pll_ready (), + .gx_pdn (), + .pll_pdn (alt_pma_controller_0_pll_pdn0_data), + .pll_locked (pll_locked_data) + ); + + /////////////////////////////////////////////////////////////////////// + // HXAUI CSR + /////////////////////////////////////////////////////////////////////// + hxaui_csr hxaui_csr ( + .clk (phy_mgmt_clk), + .reset (phy_mgmt_clk_reset), + .address (sc_csr_address), + .byteenable (4'b1111), // .byteenable (Tie byteenable to all 1s) + .read (sc_csr_read), + .readdata (sc_csr_readdata), + .write (sc_csr_write), + .writedata (phy_mgmt_writedata), + .rx_patterndetect (8'b0), // not supported by soft PCS + .rx_syncstatus (rx_syncstatus), + .rx_runningdisp (8'b0), // not supported by soft PCS + .rx_errdetect (rx_errdetect_data), + .rx_disperr (rx_disperr_data), + .rx_phase_comp_fifo_error (4'b0), // not supported by soft PCS + .rx_rlv (4'b0), // not supported by soft PCS + .rx_rmfifodatadeleted (8'b0), // not supported by soft PCS + .rx_rmfifodatainserted (8'b0), // not supported by soft PCS + .rx_rmfifoempty (4'b0), // not supported by soft PCS + .rx_rmfifofull (4'b0), // not supported by soft PCS + .tx_phase_comp_fifo_error (4'b0), // not supported by soft PCS + .r_rx_invpolarity (), // not supported by soft PCS + .r_tx_invpolarity (), // not supported by soft PCS + .r_rx_digitalreset (hxaui_csr_r_rx_digitalreset_data), + .r_tx_digitalreset (hxaui_csr_r_tx_digitalreset_data), + .simulation_flag (hxaui_csr_simulation_flag_data) // only for soft_xaui + ); + + + /////////////////////////////////////////////////////////////////////// + // SXAUI - Interface to soft PCS + /////////////////////////////////////////////////////////////////////// + + generate + if (interface_type == "Soft XAUI" && soft_pcs_legacy_new_n) begin + sxaui #( + .starting_channel_number (0), + .xaui_pll_type (xaui_pll_type), + .use_control_and_status_ports (use_control_and_status_ports), + .soft_pcs_legacy_new_n (soft_pcs_legacy_new_n) + ) sxaui_0 ( + .xgmii_tx_clk (xgmii_tx_clk), // xgmii_tx_clk.clk + .xgmii_tx_dc (xgmii_tx_dc), // xgmii_tx_dc.data + .xgmii_rx_clk (xgmii_rx_clk), // xgmii_rx_clk.clk + .xgmii_rx_dc (xgmii_rx_dc), // xgmii_rx_dc.data + .refclk (pll_ref_clk), // refclk.clk + .mgmt_clk (phy_mgmt_clk), // mgmt_clk.clk + .tx_out_clk (alt_pma_0_tx_out_clk_clk), // tx_out_clk.clk + .rx_recovered_clk (alt_pma_0_rx_recovered_clk_clk[2]), // rx_recovered_clk.clk + .tx_parallel_data (sxaui_0_tx_parallel_data_data), // tx_parallel_data.data + .rx_parallel_data (alt_pma_0_rx_parallel_data_data), // rx_parallel_data.data + .rx_is_lockedtodata (alt_pma_0_rx_is_lockedtodata_data), // rx_is_lockedtodata.data + .rx_digitalreset (alt_pma_ch_controller_0_rx_digital_rst_data[0] ), // rx_digitalreset.from alt_pma + .tx_digitalreset (alt_pma_ch_controller_0_tx_digital_rst_data[0] ), // tx_digitalreset.from alt_pma + .pll_locked (pll_locked_data), // pll_locked.data + .rx_syncstatus (rx_syncstatus), // rx_syncstatus.data + .rx_channelaligned (rx_channelaligned), // rx_channelaligned.data + .rx_disperr (rx_disperr_data), // rx_disperr.data + .rx_errdetect (rx_errdetect_data), // rx_errdetect.data + .r_rx_digitalreset (hxaui_csr_r_rx_digitalreset_data), // r_rx_digitalreset.data + .r_tx_digitalreset (hxaui_csr_r_tx_digitalreset_data), // r_tx_digitalreset.data + .pma_stat_rst_done (sxaui_rst_done), // soft reset done + .simulation_flag (hxaui_csr_simulation_flag_data) // simulation_flag.data + ); + end + else if (interface_type == "Soft XAUI" && !soft_pcs_legacy_new_n ) begin + sxaui #( + .starting_channel_number (0), + .xaui_pll_type (xaui_pll_type), + .use_control_and_status_ports (use_control_and_status_ports), + .soft_pcs_legacy_new_n (soft_pcs_legacy_new_n) + ) sxaui_0 ( + .xgmii_tx_clk (xgmii_tx_clk), // xgmii_tx_clk.clk + .xgmii_tx_dc (xgmii_tx_dc), // xgmii_tx_dc.data + .xgmii_rx_clk (xgmii_rx_clk), // xgmii_rx_clk.clk + .xgmii_rx_dc (xgmii_rx_dc), // xgmii_rx_dc.data + .refclk (pll_ref_clk), // refclk.clk + .mgmt_clk (phy_mgmt_clk), // mgmt_clk.clk + .tx_out_clk (alt_pma_0_tx_out_clk_clk), // tx_out_clk.clk + .rx_recovered_clk (alt_pma_0_rx_recovered_clk_clk[2]), // rx_recovered_clk.clk + .tx_parallel_data (sxaui_0_tx_parallel_data_data), // tx_parallel_data.data + .rx_parallel_data (alt_pma_0_rx_parallel_data_data), // rx_parallel_data.data + .rx_is_lockedtodata (alt_pma_0_rx_is_lockedtodata_data), // rx_is_lockedtodata.data + .rx_digitalreset (alt_pma_ch_controller_0_rx_digital_rst_data[0] ), // rx_digitalreset.from alt_pma + .tx_digitalreset (alt_pma_ch_controller_0_tx_digital_rst_data[0] ), // tx_digitalreset.from alt_pma + .pll_locked (pll_locked_data), // pll_locked.data + .hard_pcs_rx_syncstatus (rx_syncstatus), // rx_syncstatus.data + .rx_channelaligned (rx_channelaligned), // rx_channelaligned.data + .rx_disperr (rx_disperr_data), // rx_disperr.data + .rx_errdetect (rx_errdetect_data), // rx_errdetect.data + .r_rx_digitalreset (hxaui_csr_r_rx_digitalreset_data), // r_rx_digitalreset.data + .r_tx_digitalreset (hxaui_csr_r_tx_digitalreset_data), // r_tx_digitalreset.data + .pma_stat_rst_done (sxaui_rst_done), // soft reset done + .simulation_flag (hxaui_csr_simulation_flag_data) // simulation_flag.data + ); + end + endgenerate + +endmodule diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/hxaui_csr.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/hxaui_csr.sv new file mode 100644 index 0000000..cf5c85d --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/hxaui_csr.sv @@ -0,0 +1,461 @@ +// (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. + + +// (C) 2001-2010 Altera Corporation. All rights reserved. +// Your use of Altera Corporation's design tools, logic functions and other +// software and tools, and its AMPP partner logic functions, and any output +// files 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 Altera Program License Subscription +// Agreement, Altera MegaCore Function License Agreement, or other applicable +// license agreement, including, without limitation, that your use is for the +// sole purpose of programming logic devices manufactured by Altera and sold by +// Altera or its authorized distributors. Please refer to the applicable +// agreement for further details. + + +/////////////////////////////////////////////////////////////////////////////// +// +// +// Description: Hard xaui control and status registers +// +// Authors: ishimony 12-Jun-2009 +// +// Copyright (c) Altera Corporation 1997 - 2009 +// All rights reserved. +// +/////////////////////////////////////////////////////////////////////////////// + +// +// TBD: unless synthesis is smart enough all synchronization flops will have +// to be manually instantiated (altera_std_synchronizer) +// + +`timescale 1 ps / 1 ps + +module hxaui_csr( + clk, reset, address, byteenable, read, readdata, write, writedata, + rx_patterndetect, rx_syncstatus, rx_runningdisp, rx_errdetect, + rx_disperr, rx_phase_comp_fifo_error, rx_rlv, rx_rmfifodatadeleted, + rx_rmfifodatainserted, rx_rmfifoempty, rx_rmfifofull, + tx_phase_comp_fifo_error, r_rx_invpolarity, r_tx_invpolarity, + r_rx_digitalreset, r_tx_digitalreset, simulation_flag +); // module hxaui_csr +import hxaui_csr_h::*; + +// ports ------------------------------------------------------------------- + +// Avalon MM slave +input clk; +input reset; + +input [4:0] address; +input [3:0] byteenable; + +input read; +output [31:0] readdata; + +input write; +input [31:0] writedata; + +// hard xaui control/status +input [7:0] rx_patterndetect; +input [7:0] rx_syncstatus; +input [7:0] rx_runningdisp; // nc + +input [7:0] rx_errdetect; +input [7:0] rx_disperr; + +input [3:0] rx_phase_comp_fifo_error; +input [3:0] rx_rlv; + +input [7:0] rx_rmfifodatadeleted; +input [7:0] rx_rmfifodatainserted; +input [3:0] rx_rmfifoempty; +input [3:0] rx_rmfifofull; + +input [3:0] tx_phase_comp_fifo_error; + +output [3:0] r_rx_invpolarity; +output [3:0] r_tx_invpolarity; +output r_rx_digitalreset; +output r_tx_digitalreset; + +output simulation_flag; // '1' shortens reset and loss_timer length + +// ports ------------------------------------------------------------------- +wire clk; +wire reset; +wire [4:0] address; +wire [6:0] addr; +wire [3:0] byteenable; +wire read; +reg [31:0] readdata; +wire write; +wire [31:0] writedata; +wire [3:0] rx_phase_comp_fifo_error; +wire [3:0] rx_rlv; +wire [3:0] rx_rmfifoempty; +wire [3:0] rx_rmfifofull; +wire [3:0] tx_phase_comp_fifo_error; +wire [7:0] rx_disperr; +wire [7:0] rx_errdetect; +wire [7:0] rx_patterndetect; +wire [7:0] rx_rmfifodatadeleted; +wire [7:0] rx_rmfifodatainserted; +wire [7:0] rx_runningdisp; +wire [7:0] rx_syncstatus; +wire [3:0] r_rx_invpolarity; +wire [3:0] r_tx_invpolarity; +wire r_rx_digitalreset; +wire r_tx_digitalreset; +wire simulation_flag; + +// locals ------------------------------------------------------------------ +reg [1:0] hxaui_csr_reset, hxaui_csr_reset0q; +reg [3:0] hxaui_csr_rx_cntrl, hxaui_csr_rx_cntrl0q; +reg [3:0] hxaui_csr_tx_cntrl, hxaui_csr_tx_cntrl0q; +wire [31:0] hxaui_csr_rx_status_0; +wire [31:0] hxaui_csr_rx_status_1; +wire [31:0] hxaui_csr_rx_status_2; +wire [31:0] hxaui_csr_rx_status_3; +wire [31:0] hxaui_csr_rx_status_4; +wire [31:0] hxaui_csr_tx_status_0; +reg hxaui_csr_simulation_flag, hxaui_csr_simulation_flag0q; + + +reg [7:0] rx_patterndetect_c; // rx_patterndetect synced to clk +reg [7:0] rx_syncstatus_c; // rx_syncstatus synced to clk +reg [7:0] rx_patterndetect_sr; // rx_patterndetect sr ff +reg [7:0] rx_syncstatus_sr; // rx_syncstatus sr ff +wire read_rx_status_0; + +reg [7:0] rx_errdetect_c; // rx_errdetect synced to clk +reg [7:0] rx_disperr_c; // rx_disperr synced to clk +reg [7:0] rx_errdetect_sr; // rx_errdetect sr ff +reg [7:0] rx_disperr_sr; // rx_disperr sr ff +wire read_rx_status_1; + +reg [3:0] rx_phase_comp_fifo_error_c; // rx_phase_comp_fifo_error synced +reg [3:0] rx_rlv_c; // rx_rlv synced to clk +reg [3:0] rx_phase_comp_fifo_error_sr; // rx_phase_comp_fifo_error sr ff +reg [3:0] rx_rlv_sr; // rx_rlv sr ff +wire read_rx_status_2; + +reg [7:0] rx_rmfifodatainserted_c; // rx_rmfifodatainserted synced to clk +reg [7:0] rx_rmfifodatadeleted_c; // rx_rmfifodatadeleted synced to clk +reg [7:0] rx_rmfifodatainserted_sr;// rx_rmfifodatainserted sr ff +reg [7:0] rx_rmfifodatadeleted_sr; // rx_rmfifodatadeleted sr ff +wire read_rx_status_3; + +reg [3:0] rx_rmfifofull_c; // rx_rmfifo_full synced +reg [3:0] rx_rmfifoempty_c; // rx_rmfifoempty synced to clk +reg [3:0] rx_rmfifofull_sr; // rx_rmfifo_full sr ff +reg [3:0] rx_rmfifoempty_sr; // rx_rmfifoempty sr ff +wire read_rx_status_4; + +wire read_rx_status_5; + +reg [3:0] tx_phase_comp_fifo_error_c; // tx_phase_comp_fifo_error synced +reg [3:0] tx_phase_comp_fifo_error_sr; // tx_phase_comp_fifo_error sr ff +wire read_tx_status_0; + +// body -------------------------------------------------------------------- + +//--- readdata output latch --- +// For easier address debug shift back 2 bits +assign addr = {address[4:0], 2'b00}; + +always @(*) begin + case (addr) + HXAUI_CSR_RESET_ADDR: + readdata <= hxaui_csr_reset0q; + HXAUI_CSR_RX_CNTRL_ADDR: + readdata <= hxaui_csr_rx_cntrl0q; + HXAUI_CSR_TX_CNTRL_ADDR: + readdata <= hxaui_csr_tx_cntrl0q; + HXAUI_CSR_RX_STATUS_0_ADDR: + readdata <= hxaui_csr_rx_status_0; + HXAUI_CSR_RX_STATUS_1_ADDR: + readdata <= hxaui_csr_rx_status_1; + HXAUI_CSR_RX_STATUS_2_ADDR: + readdata <= hxaui_csr_rx_status_2; + HXAUI_CSR_RX_STATUS_3_ADDR: + readdata <= hxaui_csr_rx_status_3; + HXAUI_CSR_RX_STATUS_4_ADDR: + readdata <= hxaui_csr_rx_status_4; + HXAUI_CSR_TX_STATUS_0_ADDR: + readdata <= hxaui_csr_tx_status_0; + HXAUI_CSR_SIMULATION_FLAG_ADDR: + readdata <= hxaui_csr_simulation_flag0q; + default: + readdata <= 32'h0; + endcase // case (addr) +end + +always @ (posedge clk or posedge reset) begin + if (reset) begin + hxaui_csr_reset0q <= 2'b0; + hxaui_csr_rx_cntrl0q <= 4'b0; + hxaui_csr_tx_cntrl0q <= 4'b0; + hxaui_csr_simulation_flag0q <= 1'b0; + end else begin + hxaui_csr_reset0q <= hxaui_csr_reset; + hxaui_csr_rx_cntrl0q <= hxaui_csr_rx_cntrl; + hxaui_csr_tx_cntrl0q <= hxaui_csr_tx_cntrl; + hxaui_csr_simulation_flag0q <= hxaui_csr_simulation_flag; + end +end + + +always @ (*) begin + hxaui_csr_reset = hxaui_csr_reset0q; + hxaui_csr_rx_cntrl = hxaui_csr_rx_cntrl0q; + hxaui_csr_tx_cntrl = hxaui_csr_tx_cntrl0q; + hxaui_csr_simulation_flag = hxaui_csr_simulation_flag0q; + if (write) begin + case (addr) + HXAUI_CSR_RESET_ADDR: + hxaui_csr_reset = writedata[1:0]; + HXAUI_CSR_RX_CNTRL_ADDR: + hxaui_csr_rx_cntrl = writedata[3:0]; + HXAUI_CSR_TX_CNTRL_ADDR: + hxaui_csr_tx_cntrl = writedata[3:0]; + HXAUI_CSR_SIMULATION_FLAG_ADDR: + hxaui_csr_simulation_flag = writedata[0]; + default:; + endcase // case (addr) + end +end + +assign {r_rx_digitalreset, r_tx_digitalreset} = hxaui_csr_reset0q[1:0]; +assign r_rx_invpolarity[3:0] = hxaui_csr_rx_cntrl0q[3:0]; +assign r_tx_invpolarity[3:0] = hxaui_csr_tx_cntrl0q[3:0]; +assign simulation_flag = hxaui_csr_simulation_flag0q; + +//--- rx_status_0 register: sticky - set by status, clear by read --- +// The events latched are asynchronous to the Avalon clk, hence the user should +// not assume that all the bits are set at the same time. + +// synchronize status signal to 'clk' +//always @ (posedge clk) begin +// rx_patterndetect_c <= rx_patterndetect; +// rx_syncstatus_c <= rx_syncstatus; +//end + +// Replace above single re-sync flop with standard alt_xcvr_resync module + alt_xcvr_resync #( + .SYNC_CHAIN_LENGTH(2), // Number of flip-flops for retiming + .WIDTH (8), + .INIT_VALUE (0) + ) resync_rx_syncstatus ( + .clk (clk ), + .reset (reset ), + .d (rx_syncstatus), + .q (rx_syncstatus_c) + ); + + alt_xcvr_resync #( + .SYNC_CHAIN_LENGTH(2), // Number of flip-flops for retiming + .WIDTH (8), + .INIT_VALUE (0) + ) resync_rx_patterndetect ( + .clk (clk ), + .reset (reset ), + .d (rx_patterndetect), + .q (rx_patterndetect_c) + ); + + +assign read_rx_status_0 = read && (addr == HXAUI_CSR_RX_STATUS_0_ADDR); + +// sticky bits implementation - +// set: status signal +// reset: read from register +// Set has precedence over reset +// +// s r q nq +// ------------ +// 0 0 x q +// 0 1 x 0 +// 1 x x 1 +// +// nq <= s + qr' +// + +always @(posedge clk or posedge reset) begin + if (reset) begin + rx_patterndetect_sr <= 8'h0; + rx_syncstatus_sr <= 8'h0; + end else begin + rx_patterndetect_sr <= rx_patterndetect_c | + (rx_patterndetect_sr & {8{read_rx_status_0}}); + rx_syncstatus_sr <= rx_syncstatus_c | + (rx_syncstatus_sr & {8{read_rx_status_0}}); + end +end + +assign hxaui_csr_rx_status_0 = {rx_patterndetect_sr, rx_syncstatus_sr}; + +//--- rx_status_1 register: sticky - set by status, clear by read --- +// The events latched are asynchronous to the Avalon clk, hence the user should +// not assume that all the bits are set at the same time. + +// synchronize status signal to 'clk' +//always @ (posedge clk) begin +// rx_errdetect_c <= rx_errdetect; +// rx_disperr_c <= rx_disperr; +//end +// Replace above single re-sync flop with standard alt_xcvr_resync module + alt_xcvr_resync #( + .SYNC_CHAIN_LENGTH(2), // Number of flip-flops for retiming + .WIDTH (8), + .INIT_VALUE (0) + ) resync_rx_disperr ( + .clk (clk ), + .reset (reset ), + .d (rx_disperr), + .q (rx_disperr_c) + ); + + alt_xcvr_resync #( + .SYNC_CHAIN_LENGTH(2), // Number of flip-flops for retiming + .WIDTH (8), + .INIT_VALUE (0) + ) resync_rx_errdetect ( + .clk (clk ), + .reset (reset ), + .d (rx_errdetect), + .q (rx_errdetect_c) + ); + +assign read_rx_status_1 = read && (addr == HXAUI_CSR_RX_STATUS_1_ADDR); + +always @(posedge clk or posedge reset) begin + if (reset) begin + rx_errdetect_sr <= 8'h0; + rx_disperr_sr <= 8'h0; + end else begin + rx_errdetect_sr <= rx_errdetect_c | + (rx_errdetect_sr & {8{read_rx_status_1}}); + rx_disperr_sr <= rx_disperr_c | + (rx_disperr_sr & {8{read_rx_status_1}}); + end +end + +assign hxaui_csr_rx_status_1 = {rx_errdetect_sr, rx_disperr_sr}; + +//--- rx_status_2 register: sticky - set by status, clear by read --- +// The events latched are asynchronous to the Avalon clk, hence the user should +// not assume that all the bits are set at the same time. + +// synchronize status signal to 'clk' +always @ (posedge clk) begin + rx_phase_comp_fifo_error_c <= rx_phase_comp_fifo_error; + rx_rlv_c <= rx_rlv; +end + +assign read_rx_status_2 = read && (addr == HXAUI_CSR_RX_STATUS_2_ADDR); + +always @(posedge clk or posedge reset) begin + if (reset) begin + rx_phase_comp_fifo_error_sr <= 4'h0; + rx_rlv_sr <= 4'h0; + end else begin + rx_phase_comp_fifo_error_sr <= rx_phase_comp_fifo_error_c | + (rx_phase_comp_fifo_error_sr & {4{read_rx_status_2}}); + rx_rlv_sr <= rx_rlv_c | + (rx_rlv_sr & {4{read_rx_status_2}}); + end +end + +assign hxaui_csr_rx_status_2 = {rx_phase_comp_fifo_error_sr, rx_rlv_sr}; + +//--- rx_status_3 register: sticky - set by status, clear by read --- +// The events latched are asynchronous to the Avalon clk, hence the user should +// not assume that all the bits are set at the same time. + +// synchronize status signal to 'clk' +always @ (posedge clk) begin + rx_rmfifodatainserted_c <= rx_rmfifodatainserted; + rx_rmfifodatadeleted_c <= rx_rmfifodatadeleted; +end + +assign read_rx_status_3 = read && (addr == HXAUI_CSR_RX_STATUS_3_ADDR); + +always @(posedge clk or posedge reset) begin + if (reset) begin + rx_rmfifodatainserted_sr <= 8'h0; + rx_rmfifodatadeleted_sr <= 8'h0; + end else begin + rx_rmfifodatainserted_sr <= rx_rmfifodatainserted_c | + (rx_rmfifodatainserted_sr & {8{read_rx_status_3}}); + rx_rmfifodatadeleted_sr <= rx_rmfifodatadeleted_c | + (rx_rmfifodatadeleted_sr & {8{read_rx_status_3}}); + end +end + +assign hxaui_csr_rx_status_3 = {rx_rmfifodatainserted_sr, + rx_rmfifodatadeleted_sr}; + +//--- rx_status_4 register: sticky - set by status, clear by read --- +// The events latched are asynchronous to the Avalon clk, hence the user should +// not assume that all the bits are set at the same time. + +// synchronize status signal to 'clk' +always @ (posedge clk) begin + rx_rmfifoempty_c <= rx_rmfifoempty; + rx_rmfifofull_c <= rx_rmfifofull; +end + +assign read_rx_status_4 = read && (addr == HXAUI_CSR_RX_STATUS_4_ADDR); + +always @(posedge clk or posedge reset) begin + if (reset) begin + rx_rmfifoempty_sr <= 4'h0; + rx_rmfifofull_sr <= 4'h0; + end else begin + rx_rmfifoempty_sr <= rx_rmfifoempty_c | + (rx_rmfifoempty_sr & {4{read_rx_status_4}}); + rx_rmfifofull_sr <= rx_rmfifofull_c | + (rx_rmfifofull_sr & {4{read_rx_status_4}}); + end +end + +assign hxaui_csr_rx_status_4 = {rx_rmfifoempty_sr, rx_rmfifofull_sr}; + +//--- tx_status_0 register: sticky - set by status, clear by read --- +// The events latched are asynchronous to the Avalon clk, hence the user should +// not assume that all the bits are set at the same time. + +// synchronize status signal to 'clk' +always @ (posedge clk) begin + tx_phase_comp_fifo_error_c <= tx_phase_comp_fifo_error; +end + +assign read_tx_status_0 = read && (addr == HXAUI_CSR_TX_STATUS_0_ADDR); + +always @(posedge clk or posedge reset) begin + if (reset) begin + tx_phase_comp_fifo_error_sr <= 4'h0; + end else begin + tx_phase_comp_fifo_error_sr <= tx_phase_comp_fifo_error_c | + (tx_phase_comp_fifo_error_sr & {4{read_tx_status_0}}); + end +end + +assign hxaui_csr_tx_status_0 = tx_phase_comp_fifo_error_sr; + + +endmodule // hxaui_csr + diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/hxaui_csr_h.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/hxaui_csr_h.sv new file mode 100644 index 0000000..c6ae322 --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/hxaui_csr_h.sv @@ -0,0 +1,155 @@ +// (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. + + +// (C) 2001-2011 Altera Corporation. All rights reserved. +// Your use of Altera Corporation's design tools, logic functions and other +// software and tools, and its AMPP partner logic functions, and any output +// files 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 Altera Program License Subscription +// Agreement, Altera MegaCore Function License Agreement, or other applicable +// license agreement, including, without limitation, that your use is for the +// sole purpose of programming logic devices manufactured by Altera and sold by +// Altera or its authorized distributors. Please refer to the applicable +// agreement for further details. + + +/////////////////////////////////////////////////////////////////////////////// +// +// +// Description: Hard xaui control and status registers header file +// +// Authors: ishimony 12-Jun-2009 +// +// Copyright (c) Altera Corporation 1997 - 2009 +// All rights reserved. +// +/////////////////////////////////////////////////////////////////////////////// +`timescale 1 ps / 1 ps + +package hxaui_csr_h; + + +// address map +localparam [11:0]ALT_PMA_CONTROLLER_ADDR =12'h080; +localparam [11:0]ALT_PMA_CH_CONTROLLER_ADDR =12'h180; +//localparam ALT_PMA_ADDR 12'h080 +localparam [11:0]ALT_RECONFIG_ANALOG_ADDR =12'h400; +localparam [11:0]ALT_RECONFIG_OC_ADDR =12'h408; +localparam [11:0]HXAUI_CSR_ADDR =12'h200; + + +// registers address ------------------------------------------------------- +// preserve 7'h00 for indirection register (future implementation) +localparam [6:0]HXAUI_CSR_RESET_ADDR =7'h04; +localparam [6:0]HXAUI_CSR_RX_CNTRL_ADDR =7'h08; +localparam [6:0]HXAUI_CSR_TX_CNTRL_ADDR =7'h0C; +localparam [6:0]HXAUI_CSR_RX_STATUS_0_ADDR =7'h10; +localparam [6:0]HXAUI_CSR_RX_STATUS_1_ADDR =7'h14; +localparam [6:0]HXAUI_CSR_RX_STATUS_2_ADDR =7'h18; +localparam [6:0]HXAUI_CSR_RX_STATUS_3_ADDR =7'h1C; +localparam [6:0]HXAUI_CSR_RX_STATUS_4_ADDR =7'h20; +localparam [6:0]HXAUI_CSR_TX_STATUS_0_ADDR =7'h24; +localparam [6:0]HXAUI_CSR_SIMULATION_FLAG_ADDR =7'h28; + +// register bitmap --------------------------------------------------------- +localparam [32:0]HXAUI_CSR_RESET_RX_DIGITAL =32'h0000_0001; +localparam [32:0]HXAUI_CSR_RESET_TX_DIGITAL =32'h0000_0002; + +localparam [32:0]HXAUI_CSR_RX_CNTRL_INVPOLARITY_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_RX_CNTRL_INVPOLARITY_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_RX_CNTRL_INVPOLARITY_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_RX_CNTRL_INVPOLARITY_3 =32'h0000_0008; + +localparam [32:0]HXAUI_CSR_TX_CNTRL_INVPOLARITY_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_TX_CNTRL_INVPOLARITY_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_TX_CNTRL_INVPOLARITY_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_TX_CNTRL_INVPOLARITY_3 =32'h0000_0008; + +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_3 =32'h0000_0008; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_4 =32'h0000_0010; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_5 =32'h0000_0020; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_6 =32'h0000_0040; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_PATTERNDETECT_7 =32'h0000_0080; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_0 =32'h0000_0100; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_1 =32'h0000_0200; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_2 =32'h0000_0400; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_3 =32'h0000_0800; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_4 =32'h0000_1000; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_5 =32'h0000_2000; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_6 =32'h0000_4000; +localparam [32:0]HXAUI_CSR_RX_STATUS_0_SYNCSTATUS_7 =32'h0000_8000; + +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_3 =32'h0000_0008; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_4 =32'h0000_0010; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_5 =32'h0000_0020; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_6 =32'h0000_0040; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_ERRDETECT_7 =32'h0000_0080; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_0 =32'h0000_0100; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_1 =32'h0000_0200; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_2 =32'h0000_0400; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_3 =32'h0000_0800; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_4 =32'h0000_1000; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_5 =32'h0000_2000; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_6 =32'h0000_4000; +localparam [32:0]HXAUI_CSR_RX_STATUS_1_DISPERR_7 =32'h0000_8000; + +localparam [32:0]HXAUI_CSR_RX_STATUS_2_RLV_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_RX_STATUS_2_RLV_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_RX_STATUS_2_RLV_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_RX_STATUS_2_RLV_3 =32'h0000_0008; +localparam [32:0]HXAUI_CSR_RX_STATUS_2_PHASE_COMP_FIFO_ERROR_0 =32'h0000_0010; +localparam [32:0]HXAUI_CSR_RX_STATUS_2_PHASE_COMP_FIFO_ERROR_1 =32'h0000_0020; +localparam [32:0]HXAUI_CSR_RX_STATUS_2_PHASE_COMP_FIFO_ERROR_2 =32'h0000_0040; +localparam [32:0]HXAUI_CSR_RX_STATUS_2_PHASE_COMP_FIFO_ERROR_3 =32'h0000_0080; + +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_3 =32'h0000_0008; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_4 =32'h0000_0010; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_5 =32'h0000_0020; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_6 =32'h0000_0040; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATADELETED_7 =32'h0000_0080; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_0 =32'h0000_0100; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_1 =32'h0000_0200; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_2 =32'h0000_0400; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_3 =32'h0000_0800; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_4 =32'h0000_1000; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_5 =32'h0000_2000; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_6 =32'h0000_4000; +localparam [32:0]HXAUI_CSR_RX_STATUS_3_RMFIFODATAINSERTED_7 =32'h0000_8000; + +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOFULL_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOFULL_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOFULL_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOFULL_3 =32'h0000_0008; +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOEMPTY_0 =32'h0000_0010; +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOEMPTY_1 =32'h0000_0020; +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOEMPTY_2 =32'h0000_0040; +localparam [32:0]HXAUI_CSR_RX_STATUS_4_RMFIFOEMPTY_3 =32'h0000_0080; + +localparam [32:0]HXAUI_CSR_TX_STATUS_0_PHASE_COMP_FIFO_ERROR_0 =32'h0000_0001; +localparam [32:0]HXAUI_CSR_TX_STATUS_0_PHASE_COMP_FIFO_ERROR_1 =32'h0000_0002; +localparam [32:0]HXAUI_CSR_TX_STATUS_0_PHASE_COMP_FIFO_ERROR_2 =32'h0000_0004; +localparam [32:0]HXAUI_CSR_TX_STATUS_0_PHASE_COMP_FIFO_ERROR_3 =32'h0000_0008; + +localparam [32:0]HXAUI_CSR_SIMULATION_FLAG =32'h0000_0001; + +endpackage diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/l_modules.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/l_modules.v new file mode 100644 index 0000000..0c073c3 Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/l_modules.v differ diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4_unit_lc_siv.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4_unit_lc_siv.v new file mode 100644 index 0000000..5042d56 Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4_unit_lc_siv.v differ diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4_unit_siv.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4_unit_siv.v new file mode 100644 index 0000000..cc09223 Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4_unit_siv.v differ diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4unit.v b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4unit.v new file mode 100644 index 0000000..c5c84da Binary files /dev/null and b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/serdes_4unit.v differ diff --git a/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/sv_reconfig_bundle_merger.sv b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/sv_reconfig_bundle_merger.sv new file mode 100644 index 0000000..733bc3c --- /dev/null +++ b/generic_ip/third_party_ip/xaui_phy_itf/src/xaui_phy_itf/sv_reconfig_bundle_merger.sv @@ -0,0 +1,58 @@ +// (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 1ps/1ps + +import altera_xcvr_functions::*; + +module sv_reconfig_bundle_merger + #( + parameter reconfig_interfaces = 1 // number of reconfig interfaces + ) ( + // Reconfig buses to/from reconfig controller + input wire [reconfig_interfaces*W_S5_RECONFIG_BUNDLE_TO_XCVR -1:0] rcfg_reconfig_to_xcvr, // inputs from reconfig block to native xcvr + output wire [reconfig_interfaces*W_S5_RECONFIG_BUNDLE_FROM_XCVR -1:0] rcfg_reconfig_from_xcvr, // outputs to reconfig block from native xcvr + + // Reconfig buses to/from native xcvr + output wire [reconfig_interfaces*W_S5_RECONFIG_BUNDLE_TO_XCVR -1:0] xcvr_reconfig_to_xcvr, // outputs to native xcvr from reconfig block + input wire [reconfig_interfaces*W_S5_RECONFIG_BUNDLE_FROM_XCVR -1:0] xcvr_reconfig_from_xcvr // inputs from native xcvr to reconfig block + ); + +// Reconfig bundle width +localparam W_BUNDLE_TO_XCVR = W_S5_RECONFIG_BUNDLE_TO_XCVR; +localparam W_TOTAL_BUNDLE_TO_XCVR = W_BUNDLE_TO_XCVR * reconfig_interfaces; + +// Indices for signals that require sharing +localparam IDX_CLK = 0; +localparam IDX_RST = 1; +localparam IDX_INTERFACESEL = 44; +localparam IDX_SERSHIFTLOAD = 45; + +// Pass reconfig_from_xcvr signals through without alteration +assign rcfg_reconfig_from_xcvr = xcvr_reconfig_from_xcvr; + +// We need to connect the shared signals from the first reconfig bundle to the remaining bundles. +// All other signals pass through without change +genvar pi; +generate + for (pi=0; pi +-- Company : On my own +-- Target : Generic (simulation), Generic (synthesis) +-- Dependency : none +------------------------------------------------------------------------------- +-- Description: PRN generator based on a 32-bit LFSR with maximum length, +-- modified for removing the absorbing state. +------------------------------------------------------------------------------- +-- Last update: 2015-08-17 +------------------------------------------------------------------------------- +-- Revisions : +-- Date Version Author Description +-- 2010-09-13 1.0 ggm Created +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +-- The LFSR period is about 7.16 sec at 100MHz. +-- For different LFSR lengths please consult: +-- Xilinx XAPP052, 7th July 1996, "Efficient Shift Registers, LFSR Counters, +-- and Long Pseudo-Random Sequence Generators", by Peter Alfke. +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; + +entity PRN_gen_0 is + generic( + seed : std_logic_vector(31 downto 0) := X"FFFFFFFF"); + port( + rstN : in std_logic; + clk : in std_logic; + PRN_rst : in std_logic; + PRN_upd : in std_logic; + PRN_reg : out std_logic_vector(31 downto 0); + PRN_out : out std_logic); +end PRN_gen_0; + +architecture RTL of PRN_gen_0 is + + signal LFSR_reg : std_logic_vector(31 downto 0); + +begin + + pLFSR : process(rstN, clk) + begin + if(rstN = '0') then + LFSR_reg <= seed; + elsif(clk = '1' and clk'event) then + if(PRN_rst = '1') then + LFSR_reg <= seed; + elsif(PRN_upd = '1' and LFSR_reg = X"00000000") then + LFSR_reg <= X"FFFFFFFF"; + elsif(PRN_upd = '1') then + LFSR_reg <= LFSR_reg(30 downto 0) & (LFSR_reg(30) xor LFSR_reg(27)); + end if; + end if; + end process pLFSR; + + PRN_reg <= LFSR_reg; + PRN_out <= LFSR_reg(31); + +end RTL; + + + diff --git a/generic_ip/xgbe_oe/0/src/crc32_gen_0.vhd b/generic_ip/xgbe_oe/0/src/crc32_gen_0.vhd new file mode 100644 index 0000000..9929250 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/crc32_gen_0.vhd @@ -0,0 +1,122 @@ +------------------------------------------------------------------------------- +-- Title : crc32_gen_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : crc32_gen_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-02-07 +-- Last update: 2020-07-02 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: compute the CRC-32 checksum for an Ethernet packet, by +-- accepting a byte of payload at every clock cycles. This implementation is +-- suitable for link rates up to 1 Gbps. +-- The implementation is based on the description in Xilinx Application Note +-- xapp209. +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity crc32_gen_0 is + port( + clk : in std_logic; + init : in std_logic; + byte_en : in std_logic; + byte_in : in std_logic_vector( 7 downto 0); + crc32 : out std_logic_vector(31 downto 0)); +end crc32_gen_0; + +architecture RTL of crc32_gen_0 is + + signal byte : std_logic_vector( 7 downto 0); + signal crc32_i : std_logic_vector(31 downto 0); + +begin -- RTL + + -- reverse the input byte + BYTE_REV: for i in 0 to 7 generate + byte(i) <= byte_in(7-i); + end generate BYTE_REV; + + -- Ethernet CRC polynomial: 0x04C11DB7 + pCRC : process(clk) + begin + if(clk = '1' and clk'event) then + if(init = '1') then + crc32_i <= (others => '1'); + elsif(byte_en = '1') then + crc32_i( 0) <= byte(6) xor byte(0) xor crc32_i(24) xor crc32_i(30); + crc32_i( 1) <= byte(7) xor byte(6) xor byte(1) xor byte(0) xor crc32_i(24) xor crc32_i(25) xor + crc32_i(30) xor crc32_i(31); + crc32_i( 2) <= byte(7) xor byte(6) xor byte(2) xor byte(1) xor byte(0) xor crc32_i(24) xor + crc32_i(25) xor crc32_i(26) xor crc32_i(30) xor crc32_i(31); + crc32_i( 3) <= byte(7) xor byte(3) xor byte(2) xor byte(1) xor crc32_i(25) xor crc32_i(26) xor + crc32_i(27) xor crc32_i(31); + crc32_i( 4) <= byte(6) xor byte(4) xor byte(3) xor byte(2) xor byte(0) xor crc32_i(24) xor + crc32_i(26) xor crc32_i(27) xor crc32_i(28) xor crc32_i(30); + crc32_i( 5) <= byte(7) xor byte(6) xor byte(5) xor byte(4) xor byte(3) xor byte(1) xor + byte(0) xor crc32_i(24) xor crc32_i(25) xor crc32_i(27) xor crc32_i(28) xor crc32_i(29) xor + crc32_i(30) xor crc32_i(31); + crc32_i( 6) <= byte(7) xor byte(6) xor byte(5) xor byte(4) xor byte(2) xor byte(1) xor + crc32_i(25) xor crc32_i(26) xor crc32_i(28) xor crc32_i(29) xor crc32_i(30) xor crc32_i(31); + crc32_i( 7) <= byte(7) xor byte(5) xor byte(3) xor byte(2) xor byte(0) xor crc32_i(24) xor + crc32_i(26) xor crc32_i(27) xor crc32_i(29) xor crc32_i(31); + crc32_i( 8) <= byte(4) xor byte(3) xor byte(1) xor byte(0) xor crc32_i(0) xor crc32_i(24) xor + crc32_i(25) xor crc32_i(27) xor crc32_i(28); + crc32_i( 9) <= byte(5) xor byte(4) xor byte(2) xor byte(1) xor crc32_i(1) xor crc32_i(25) xor + crc32_i(26) xor crc32_i(28) xor crc32_i(29); + crc32_i(10) <= byte(5) xor byte(3) xor byte(2) xor byte(0) xor crc32_i(2) xor crc32_i(24) xor + crc32_i(26) xor crc32_i(27) xor crc32_i(29); + crc32_i(11) <= byte(4) xor byte(3) xor byte(1) xor byte(0) xor crc32_i(3) xor crc32_i(24) xor + crc32_i(25) xor crc32_i(27) xor crc32_i(28); + crc32_i(12) <= byte(6) xor byte(5) xor byte(4) xor byte(2) xor byte(1) xor byte(0) xor + crc32_i(4) xor crc32_i(24) xor crc32_i(25) xor crc32_i(26) xor crc32_i(28) xor crc32_i(29) xor + crc32_i(30); + crc32_i(13) <= byte(7) xor byte(6) xor byte(5) xor byte(3) xor byte(2) xor byte(1) xor + crc32_i(5) xor crc32_i(25) xor crc32_i(26) xor crc32_i(27) xor crc32_i(29) xor crc32_i(30) xor + crc32_i(31); + crc32_i(14) <= byte(7) xor byte(6) xor byte(4) xor byte(3) xor byte(2) xor crc32_i(6) xor + crc32_i(26) xor crc32_i(27) xor crc32_i(28) xor crc32_i(30) xor crc32_i(31); + crc32_i(15) <= byte(7) xor byte(5) xor byte(4) xor byte(3) xor crc32_i(7) xor crc32_i(27) xor + crc32_i(28) xor crc32_i(29) xor crc32_i(31); + crc32_i(16) <= byte(5) xor byte(4) xor byte(0) xor crc32_i(8) xor crc32_i(24) xor crc32_i(28) xor + crc32_i(29); + crc32_i(17) <= byte(6) xor byte(5) xor byte(1) xor crc32_i(9) xor crc32_i(25) xor crc32_i(29) xor + crc32_i(30); + crc32_i(18) <= byte(7) xor byte(6) xor byte(2) xor crc32_i(10) xor crc32_i(26) xor crc32_i(30) xor + crc32_i(31); + crc32_i(19) <= byte(7) xor byte(3) xor crc32_i(11) xor crc32_i(27) xor crc32_i(31); + crc32_i(20) <= byte(4) xor crc32_i(12) xor crc32_i(28); + crc32_i(21) <= byte(5) xor crc32_i(13) xor crc32_i(29); + crc32_i(22) <= byte(0) xor crc32_i(14) xor crc32_i(24); + crc32_i(23) <= byte(6) xor byte(1) xor byte(0) xor crc32_i(15) xor crc32_i(24) xor crc32_i(25) xor + crc32_i(30); + crc32_i(24) <= byte(7) xor byte(2) xor byte(1) xor crc32_i(16) xor crc32_i(25) xor crc32_i(26) xor + crc32_i(31); + crc32_i(25) <= byte(3) xor byte(2) xor crc32_i(17) xor crc32_i(26) xor crc32_i(27); + crc32_i(26) <= byte(6) xor byte(4) xor byte(3) xor byte(0) xor crc32_i(18) xor crc32_i(24) xor + crc32_i(27) xor crc32_i(28) xor crc32_i(30); + crc32_i(27) <= byte(7) xor byte(5) xor byte(4) xor byte(1) xor crc32_i(19) xor crc32_i(25) xor + crc32_i(28) xor crc32_i(29) xor crc32_i(31); + crc32_i(28) <= byte(6) xor byte(5) xor byte(2) xor crc32_i(20) xor crc32_i(26) xor crc32_i(29) xor + crc32_i(30); + crc32_i(29) <= byte(7) xor byte(6) xor byte(3) xor crc32_i(21) xor crc32_i(27) xor crc32_i(30) xor + crc32_i(31); + crc32_i(30) <= byte(7) xor byte(4) xor crc32_i(22) xor crc32_i(28) xor crc32_i(31); + crc32_i(31) <= byte(5) xor crc32_i(23) xor crc32_i(29); + end if; + end if; + end process pCRC; + + -- Reverse and complement the output + OUT_REV: for i in 0 to 31 generate + crc32(i) <= not crc32_i(31-i); + end generate OUT_REV; + +end RTL; + diff --git a/generic_ip/xgbe_oe/0/src/gmii_rx_bridge_0.vhd b/generic_ip/xgbe_oe/0/src/gmii_rx_bridge_0.vhd new file mode 100644 index 0000000..39ea28b --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/gmii_rx_bridge_0.vhd @@ -0,0 +1,167 @@ +------------------------------------------------------------------------------- +-- Title : gmii_rx_bridge_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : gmii_rx_bridge_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-06-15 +-- Last update: 2020-08-10 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- convert data from the rx_packet_split to a gmii format, for the HPS-EMAC. +-- An asynchronous FIFO is used to buffer data read from the rx_packet_split, +-- at 10Gbps, and then transfered at slower rate (1Gbps) to the HPS-EMAC. The +-- FIFO is also used to perform the clock crossing to 125 MHz, for the GMII +-- interface. The logic restores the Ethernet preamble and SFD bytes, which +-- have been removed by the 10G MAC. +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity gmii_rx_bridge_0 is + port ( + clk : in std_logic; -- @156.25MHz + gmii_clk : in std_logic; -- @125MHz + -- + init : in std_logic; + fifo_afull_flag : out std_logic; + clr_fifo_afull_flag : in std_logic; + -- rx_packet_split interface + packet_dest : in std_logic; -- '1' => filter is matched + 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_eof : in std_logic; + rx_rts : in std_logic; + rx_cts : out std_logic; + -- GMII interface + gmii_rx_clk : in std_logic; -- @125MHz + gmii_rx_rxdv : out std_logic; + gmii_rx_rxer : out std_logic; + gmii_rx_rxd : out std_logic_vector(7 downto 0)); +end entity gmii_rx_bridge_0; + +architecture rtl of gmii_rx_bridge_0 is + + signal fifo_we, fifo_re, fifo_re_d : std_logic; + signal fifo_empty, fifo_afull : std_logic; + signal rx_cts_i, init_i, init_ii : std_logic; + signal egress_packet, egress_start : std_logic; + signal egress_completed : std_logic; + signal ready_for_word : std_logic; + -- + signal init_v : std_logic_vector( 2 downto 0); + signal fifo_usew, data_valid : std_logic_vector( 7 downto 0); + signal byte_sel : std_logic_vector( 7 downto 0); + signal data : std_logic_vector(63 downto 0); + signal fifo_d, fifo_q : std_logic_vector(79 downto 0); + + +begin + + ----------------------------------------------------------------------------- + -- Input Packet Buffer + ----------------------------------------------------------------------------- + + iDATA_BUFFER : entity work.afifo_256x80_0 + port map ( + aclr => init, + wrclk => clk, + wrreq => fifo_we, + data => fifo_d, + rdclk => gmii_clk, + rdreq => fifo_re, + rdempty => fifo_empty, + wrfull => open, + q => fifo_q, + wrusedw => fifo_usew); + + fifo_d <= 6x"0" & rx_eof & rx_sof & rx_data_valid & rx_data; + + pINGRESS_REGs : process(clk) + begin + if(clk = '1' and clk'event) then + if(fifo_afull = '1') then + rx_cts_i <= '0'; + else + rx_cts_i <= '1'; + end if; + if(init = '1' or clr_fifo_afull_flag = '1') then + fifo_afull_flag <= '0'; + elsif(fifo_afull = '1') then + fifo_afull_flag <= '1'; + end if; + end if; + end process pINGRESS_REGs; + + fifo_afull <= '1' when fifo_usew(fifo_usew'left downto 2) = "111111" else '0'; + + rx_cts <= rx_cts_i; + + fifo_we <= '1' when rx_cts_i = '1' and rx_rts = '1' and packet_dest = '0' else '0'; + + ----------------------------------------------------------------------------- + -- Egress Logic & GMII interface + ----------------------------------------------------------------------------- + + -- Stretch init pulse before resynchronizing it to gmii_clk + pStretchInit: process(clk) + begin + if(clk = '1' and clk'event) then + if(init = '1') then + init_v <= b"111"; + else + init_v <= '0' & init_v(2 downto 1); + end if; + end if; + end process pStretchInit; + + pGMII: process(gmii_clk) + begin + if(gmii_clk = '1' and gmii_clk'event) then + fifo_re_d <= fifo_re; + -- Synchronize the init to gmii_clk + init_i <= init_v(0); + init_ii <= init_i; + if(init_ii = '1' or egress_completed = '1') then + egress_packet <= '0'; + elsif(egress_start = '1') then + egress_packet <= '1'; + end if; + if(egress_start = '1') then + data <= X"5D55555555555555"; -- 7 octets preamble + SFD + data_valid <= (others => '1'); + elsif(fifo_re_d = '1') then + data <= fifo_q(63 downto 0); + data_valid <= fifo_q(71 downto 64); + else + data <= X"00" & data(63 downto 8); + data_valid <= '0' & data_valid(7 downto 1); + end if; + if(egress_start = '1' or fifo_re_d = '1') then + byte_sel <= X"FF"; + else + byte_sel <= '0' & byte_sel(7 downto 1); + end if; + end if; + end process pGMII; + + fifo_re <= '1' when egress_packet = '1' and ready_for_word = '1' and fifo_empty = '0' and fifo_re_d = '0' else '0'; + + egress_start <= '1' when fifo_empty = '0' and egress_packet = '0' and unsigned(byte_sel) = 0 else '0'; + + ready_for_word <= '1' when byte_sel(7 downto 2) = b"000000" else '0'; + + egress_completed <= fifo_re_d and fifo_q(73); + + gmii_rx_rxd <= data(7 downto 0); + gmii_rx_rxdv <= data_valid(0); + gmii_rx_rxer <= '0'; + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/gmii_tx_bridge_0.vhd b/generic_ip/xgbe_oe/0/src/gmii_tx_bridge_0.vhd new file mode 100644 index 0000000..528d9a3 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/gmii_tx_bridge_0.vhd @@ -0,0 +1,332 @@ +------------------------------------------------------------------------------- +-- Title : gmii_tx_bridge_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : gmii_tx_bridge_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-07-02 +-- Last update: 2020-08-06 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- This block takes tx packets generated by the HPS-EMAC in GMII format (8-bits +-- at 125 MHz), and converts to a 64-bits at 156.25 MHz rate, with preamble, +-- SFD and CRC checksum stripped from the packet, so that the packet can be +-- transmitted by the 10G MAC. an internal state machine identifies the packet +-- boundaries by looking for a CRC-32 zero checksum. +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity gmii_tx_bridge_0 is + generic( + MTU_SIZE : natural := 1500; + PREAMBLE_LEN : natural := 7); + port ( + clk : in std_logic; -- @156.25MHz + -- + init : in std_logic; + buffer_ovfl_flag : out std_logic; + clr_buffer_ovfl_flag : in std_logic; + buffer_level : out std_logic_vector(10 downto 0); + discarded_packets : out std_logic_vector(15 downto 0); + -- GMII TX interface + gmii_tx_clk : in std_logic; -- @125MHz + gmii_txen : in std_logic; + gmii_txer : in std_logic; + gmii_txd : in std_logic_vector(7 downto 0); + -- tx_packet_combine interface + tx_data : out std_logic_vector(63 downto 0); + tx_data_valid : out std_logic_vector(7 downto 0); + tx_sof : out std_logic; + tx_eof : out std_logic; + tx_rts : out std_logic; + tx_cts : in std_logic); +end entity gmii_tx_bridge_0; + +architecture rtl of gmii_tx_bridge_0 is + + constant MTU_SIZE_plus : natural := MTU_SIZE; -- MTU_SIZE + preamble + + type fsm_state_t is (S_IDLE, S_CHECK_PREAMBLE, S_CHECK_SFD, S_DETECTED_SOF, + S_CHECK_PAYLOAD, S_DETECTED_EOF); + + signal fsm_state_curr, fsm_state_next : fsm_state_t; + + signal fifo_we, fifo_re, fifo_empty, fifo_full : std_logic; + signal buffer_ovfl_pulse, buffer_ovfl_ii : std_logic; + signal buffer_ovfl_i, buffer_ovfl, sof, eof : std_logic; + signal init_crc, upd_crc, upd_crc_en : std_logic; + signal fifo_read, next_bit : std_logic; + signal word_egress, abort_packet, matched_crc : std_logic; + signal detected_sof, detected_eof, is_sfd : std_logic; + signal inc_discarded_cnt, is_preamble : std_logic; + signal preamble_ok, frame_is_too_long : std_logic; + signal rst_frame_len_cnt, inc_frame_len_cnt : std_logic; + + signal buffer_ovfl_v : std_logic_vector( 2 downto 0); + signal delayed_upd : std_logic_vector( 3 downto 0); + signal byte, byte_valid : std_logic_vector( 7 downto 0); + signal fifo_d, fifo_q : std_logic_vector( 9 downto 0); + signal frame_len_cnt : std_logic_vector(13 downto 0); + signal excess_frame_len : std_logic_vector(14 downto 0); + signal discarded_packets_cnt : std_logic_vector(15 downto 0); + signal last3bytes : std_logic_vector(23 downto 0); + signal crc32, crc32_d : std_logic_vector(31 downto 0); + signal crc32_dd, crc32_ddd : std_logic_vector(31 downto 0); + signal rx_crc : std_logic_vector(31 downto 0); + signal word : std_logic_vector(95 downto 0); + +begin + + ----------------------------------------------------------------------------- + -- Input Packet Buffer + ----------------------------------------------------------------------------- + + iDATA_BUFFER: entity work.afifo_2048x10_0 + port map ( + aclr => init, + data => fifo_d, + rdclk => clk, + rdreq => fifo_re, + wrclk => gmii_tx_clk, + wrreq => fifo_we, + q => fifo_q, + rdempty => fifo_empty, + rdusedw => buffer_level, + wrfull => fifo_full); + + + fifo_d <= gmii_txer & gmii_txen & gmii_txd; + -- bytes with gmii_txer are still written into the FIFO and declared as + -- valid, under the assumption that they are still used by the HPS-EMAC to + -- compute the CRC. Doing differently may cause the full packet to be dropped + -- because the CRC is not detected. + fifo_we <= (gmii_txen or gmii_txer) and not fifo_full; + + -- Overflow flag management + buffer_ovfl_pulse <= '1' when (gmii_txer = '1' or gmii_txen = '1') and fifo_full = '1' else '0'; + + byte <= fifo_q(7 downto 0); + + -- Stretch the pulse for a few clock cycles, synchronize the signal to 156.25 + -- MHz clock + pOVFL_PULSE_STRETCH: process(gmii_tx_clk) + begin + if(gmii_tx_clk = '1' and gmii_tx_clk'event) then + if(buffer_ovfl_pulse = '1') then + buffer_ovfl_v <= (others => '1'); + else + buffer_ovfl_v <= '0' & buffer_ovfl_v(buffer_ovfl_v'left downto 1); + end if; + end if; + end process pOVFL_PULSE_STRETCH; + + pBUFFER_OVFL: process(clk) + begin + if(clk = '1' and clk'event) then + -- synchronize first the pulse to this clock domain + buffer_ovfl_ii <= buffer_ovfl_v(0); + buffer_ovfl_i <= buffer_ovfl_ii; + buffer_ovfl <= buffer_ovfl_i; + if(init = '1' or clr_buffer_ovfl_flag = '1') then + buffer_ovfl_flag <= '0'; + elsif(buffer_ovfl = '1') then + buffer_ovfl_flag <= '1'; + end if; + end if; + end process pBUFFER_OVFL; + + ----------------------------------------------------------------------------- + -- Packet detection and egress + ----------------------------------------------------------------------------- + + -- CRC-32 computation + iCRC: entity work.crc32_gen_0 + port map ( + clk => clk, + init => init_crc, + byte_en => upd_crc, + byte_in => byte, + crc32 => crc32); + + -- packet detection register + pPACKET_DET_REGS : process(clk) + begin + if(clk = '1' and clk'event) then + if(upd_crc = '1') then + -- Received CRC-32 + last3bytes <= byte & last3bytes(23 downto 8); + -- Previous CRC-32 values + crc32_d <= crc32; + crc32_dd <= crc32_d; + crc32_ddd <= crc32_dd; + end if; + if(init = '1') then + discarded_packets_cnt <= (others => '0'); + elsif(inc_discarded_cnt = '1') then + discarded_packets_cnt <= std_logic_vector(unsigned(discarded_packets_cnt)+1); + end if; + if(detected_sof = '1') then + sof <= '1'; + elsif(init = '1' or word_egress = '1') then + sof <= '0'; + end if; + if(detected_eof = '1') then + eof <= '1'; + elsif(init = '1' or word_egress = '1' or abort_packet = '1') then + eof <= '0'; + end if; + if(rst_frame_len_cnt = '1') then + frame_len_cnt <= (others => '0'); + elsif(inc_frame_len_cnt = '1') then + frame_len_cnt <= std_logic_vector(unsigned(frame_len_cnt)+1); + end if; + -- the delayed updated is used to delay the egress phase of 4 bytes. + -- This helps to discard the last 4 bytes of the frame, which contains + -- the CRC signature. This is also the reason why 'word' (see below) is + -- bigger than 64-bit + if(init_crc = '1') then + delayed_upd <= (others => '0'); + elsif(upd_crc = '1') then + delayed_upd <= delayed_upd(delayed_upd'left-1 downto 0) & '1'; + end if; + if(init = '1' or (word_egress = '1' and upd_crc = '0')) then + byte_valid <= (others => '0'); + elsif(word_egress = '1' and upd_crc = '1') then + byte_valid <= (7 => '1', others => '0'); + elsif(upd_crc = '1' or eof = '1') then + byte_valid <= next_bit & byte_valid(7 downto 1); + end if; + if(upd_crc = '1' or eof = '1') then + --word <= word(word'left-8 downto 0) & byte; + word <= byte & word(word'left downto 8); + end if; + upd_crc <= fifo_re and upd_crc_en; + end if; + end process pPACKET_DET_REGS; + + next_bit <= delayed_upd(delayed_upd'left) when eof = '0' else '0'; + + discarded_packets <= discarded_packets_cnt; + + -- packet detection combinational logic + fifo_re <= fifo_read and not fifo_empty; + + inc_frame_len_cnt <= fifo_re; + + --word_egress <= '1' when byte_valid(0) = '1' or eof = '1' else '0'; + word_egress <= byte_valid(0); + + is_preamble <= '1' when byte = X"55" else '0'; + --preamble_ok <= '1' when (unsigned(frame_len_cnt(2 downto 0)) = PREAMBLE_LEN-1) or (unsigned(frame_len_cnt(2 downto 0)) = PREAMBLE_LEN) else '0'; + + preamble_ok <= '1' when (unsigned(frame_len_cnt(2 downto 0)) = PREAMBLE_LEN-1) else '0'; + + rx_crc <= byte & last3bytes; + matched_crc <= '1' when crc32_ddd = rx_crc else '0'; + + is_sfd <= '1' when byte = X"5D" else '0'; + + excess_frame_len <= std_logic_vector(MTU_SIZE_plus - signed('0' & frame_len_cnt)); + + frame_is_too_long <= excess_frame_len(excess_frame_len'left); + + tx_data <= word(63 downto 0); + tx_data_valid <= byte_valid when word_egress = '1' else X"00"; + tx_sof <= sof and word_egress; -- to be fixed later + tx_eof <= eof and word_egress; -- to be fixed later + tx_rts <= word_egress; + + pFSM_SR : process(clk) + begin + if(clk = '1' and clk'event) then + if(init = '1') then + fsm_state_curr <= S_IDLE; + else + fsm_state_curr <= fsm_state_next; + end if; + end if; + end process pFSM_SR; + + pFSM_CL : process(all) + begin + -- default assignments + fifo_read <= '0'; + inc_discarded_cnt <= '0'; + init_crc <= '0'; + upd_crc_en <= '0'; + detected_sof <= '0'; + detected_eof <= '0'; + abort_packet <= '0'; + rst_frame_len_cnt <= '0'; + -- + fsm_state_next <= fsm_state_curr; + + case fsm_state_curr is + when S_IDLE => + init_crc <= '1'; + rst_frame_len_cnt <= '1'; + if(fifo_empty = '0') then + fifo_read <= '1'; + fsm_state_next <= S_CHECK_PREAMBLE; + end if; + + when S_CHECK_PREAMBLE => + fifo_read <= '1'; + if(is_preamble = '0') then + fifo_read <= '0'; + inc_discarded_cnt <= '1'; + fsm_state_next <= S_IDLE; + elsif(preamble_ok = '1' and fifo_empty = '0') then + fsm_state_next <= S_CHECK_SFD; + end if; + + when S_CHECK_SFD => + fifo_read <= '1'; + init_crc <= '1'; + if(is_sfd = '0') then + fifo_read <= '0'; + inc_discarded_cnt <= '1'; + fsm_state_next <= S_IDLE; + else + upd_crc_en <= '1'; + fsm_state_next <= S_DETECTED_SOF; + end if; + + when S_DETECTED_SOF => + upd_crc_en <= '1'; + if(fifo_empty = '0') then + fifo_read <= '1'; + detected_sof <= '1'; + fsm_state_next <= S_CHECK_PAYLOAD; + end if; + + when S_CHECK_PAYLOAD => + fifo_read <= '1'; + upd_crc_en <= '1'; + if(frame_is_too_long = '1') then + fifo_read <= '0'; + abort_packet <= '1'; + inc_discarded_cnt <= '1'; + fsm_state_next <= S_IDLE; + elsif(matched_crc = '1') then + fifo_read <= '0'; + detected_eof <= '1'; + fsm_state_next <= S_DETECTED_EOF; + end if; + + when S_DETECTED_EOF => + fsm_state_next <= S_IDLE; + + when others => null; + end case; + + end process pFSM_CL; + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/intel/afifo_2048x10_0.vhd b/generic_ip/xgbe_oe/0/src/intel/afifo_2048x10_0.vhd new file mode 100644 index 0000000..5819351 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/intel/afifo_2048x10_0.vhd @@ -0,0 +1,214 @@ +-- megafunction wizard: %FIFO% +-- GENERATION: STANDARD +-- VERSION: WM1.0 +-- MODULE: dcfifo + +-- ============================================================ +-- File Name: afifo_2048x10_0.vhd +-- Megafunction Name(s): +-- dcfifo +-- +-- 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.all; + +ENTITY afifo_2048x10_0 IS + PORT + ( + aclr : IN STD_LOGIC := '0'; + data : IN STD_LOGIC_VECTOR (9 DOWNTO 0); + rdclk : IN STD_LOGIC ; + rdreq : IN STD_LOGIC ; + wrclk : IN STD_LOGIC ; + wrreq : IN STD_LOGIC ; + q : OUT STD_LOGIC_VECTOR (9 DOWNTO 0); + rdempty : OUT STD_LOGIC ; + rdusedw : OUT STD_LOGIC_VECTOR (10 DOWNTO 0); + wrfull : OUT STD_LOGIC + ); +END afifo_2048x10_0; + + +ARCHITECTURE SYN OF afifo_2048x10_0 IS + + SIGNAL sub_wire0 : STD_LOGIC_VECTOR (9 DOWNTO 0); + SIGNAL sub_wire1 : STD_LOGIC ; + SIGNAL sub_wire2 : STD_LOGIC_VECTOR (10 DOWNTO 0); + SIGNAL sub_wire3 : STD_LOGIC ; + + + + COMPONENT dcfifo + GENERIC ( + intended_device_family : STRING; + lpm_hint : STRING; + lpm_numwords : NATURAL; + lpm_showahead : STRING; + lpm_type : STRING; + lpm_width : NATURAL; + lpm_widthu : NATURAL; + overflow_checking : STRING; + rdsync_delaypipe : NATURAL; + read_aclr_synch : STRING; + underflow_checking : STRING; + use_eab : STRING; + write_aclr_synch : STRING; + wrsync_delaypipe : NATURAL + ); + PORT ( + aclr : IN STD_LOGIC ; + data : IN STD_LOGIC_VECTOR (9 DOWNTO 0); + rdclk : IN STD_LOGIC ; + rdreq : IN STD_LOGIC ; + wrclk : IN STD_LOGIC ; + wrreq : IN STD_LOGIC ; + q : OUT STD_LOGIC_VECTOR (9 DOWNTO 0); + rdempty : OUT STD_LOGIC ; + rdusedw : OUT STD_LOGIC_VECTOR (10 DOWNTO 0); + wrfull : OUT STD_LOGIC + ); + END COMPONENT; + +BEGIN + q <= sub_wire0(9 DOWNTO 0); + rdempty <= sub_wire1; + rdusedw <= sub_wire2(10 DOWNTO 0); + wrfull <= sub_wire3; + + dcfifo_component : dcfifo + GENERIC MAP ( + intended_device_family => "Cyclone V", + lpm_hint => "RAM_BLOCK_TYPE=M10K", + lpm_numwords => 2048, + lpm_showahead => "OFF", + lpm_type => "dcfifo", + lpm_width => 10, + lpm_widthu => 11, + overflow_checking => "ON", + rdsync_delaypipe => 4, + read_aclr_synch => "OFF", + underflow_checking => "ON", + use_eab => "ON", + write_aclr_synch => "OFF", + wrsync_delaypipe => 4 + ) + PORT MAP ( + aclr => aclr, + data => data, + rdclk => rdclk, + rdreq => rdreq, + wrclk => wrclk, + wrreq => wrreq, + q => sub_wire0, + rdempty => sub_wire1, + rdusedw => sub_wire2, + wrfull => sub_wire3 + ); + + + +END SYN; + +-- ============================================================ +-- CNX file retrieval info +-- ============================================================ +-- Retrieval info: PRIVATE: AlmostEmpty NUMERIC "0" +-- Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC "-1" +-- Retrieval info: PRIVATE: AlmostFull NUMERIC "0" +-- Retrieval info: PRIVATE: AlmostFullThr NUMERIC "-1" +-- Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC "0" +-- Retrieval info: PRIVATE: Clock NUMERIC "4" +-- Retrieval info: PRIVATE: Depth NUMERIC "2048" +-- Retrieval info: PRIVATE: Empty NUMERIC "1" +-- Retrieval info: PRIVATE: Full NUMERIC "1" +-- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone V" +-- Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC "0" +-- Retrieval info: PRIVATE: LegacyRREQ NUMERIC "1" +-- Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC "0" +-- Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC "0" +-- Retrieval info: PRIVATE: Optimize NUMERIC "0" +-- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "2" +-- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0" +-- Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC "0" +-- Retrieval info: PRIVATE: UsedW NUMERIC "1" +-- Retrieval info: PRIVATE: Width NUMERIC "10" +-- Retrieval info: PRIVATE: dc_aclr NUMERIC "1" +-- Retrieval info: PRIVATE: diff_widths NUMERIC "0" +-- Retrieval info: PRIVATE: msb_usedw NUMERIC "0" +-- Retrieval info: PRIVATE: output_width NUMERIC "10" +-- Retrieval info: PRIVATE: rsEmpty NUMERIC "1" +-- Retrieval info: PRIVATE: rsFull NUMERIC "0" +-- Retrieval info: PRIVATE: rsUsedW NUMERIC "1" +-- Retrieval info: PRIVATE: sc_aclr NUMERIC "0" +-- Retrieval info: PRIVATE: sc_sclr NUMERIC "0" +-- Retrieval info: PRIVATE: wsEmpty NUMERIC "0" +-- Retrieval info: PRIVATE: wsFull NUMERIC "1" +-- Retrieval info: PRIVATE: wsUsedW NUMERIC "0" +-- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all +-- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V" +-- Retrieval info: CONSTANT: LPM_HINT STRING "RAM_BLOCK_TYPE=M10K" +-- Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC "2048" +-- Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING "OFF" +-- Retrieval info: CONSTANT: LPM_TYPE STRING "dcfifo" +-- Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "10" +-- Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC "11" +-- Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING "ON" +-- Retrieval info: CONSTANT: RDSYNC_DELAYPIPE NUMERIC "4" +-- Retrieval info: CONSTANT: READ_ACLR_SYNCH STRING "OFF" +-- Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING "ON" +-- Retrieval info: CONSTANT: USE_EAB STRING "ON" +-- Retrieval info: CONSTANT: WRITE_ACLR_SYNCH STRING "OFF" +-- Retrieval info: CONSTANT: WRSYNC_DELAYPIPE NUMERIC "4" +-- Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND "aclr" +-- Retrieval info: USED_PORT: data 0 0 10 0 INPUT NODEFVAL "data[9..0]" +-- Retrieval info: USED_PORT: q 0 0 10 0 OUTPUT NODEFVAL "q[9..0]" +-- Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL "rdclk" +-- Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL "rdempty" +-- Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL "rdreq" +-- Retrieval info: USED_PORT: rdusedw 0 0 11 0 OUTPUT NODEFVAL "rdusedw[10..0]" +-- Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL "wrclk" +-- Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL "wrfull" +-- Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL "wrreq" +-- Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0 +-- Retrieval info: CONNECT: @data 0 0 10 0 data 0 0 10 0 +-- Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0 +-- Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0 +-- Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0 +-- Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0 +-- Retrieval info: CONNECT: q 0 0 10 0 @q 0 0 10 0 +-- Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0 +-- Retrieval info: CONNECT: rdusedw 0 0 11 0 @rdusedw 0 0 11 0 +-- Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0 +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_2048x10_0.vhd TRUE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_2048x10_0.inc FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_2048x10_0.cmp FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_2048x10_0.bsf FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_2048x10_0_inst.vhd FALSE +-- Retrieval info: LIB_FILE: altera_mf diff --git a/generic_ip/xgbe_oe/0/src/intel/afifo_256x80_0.vhd b/generic_ip/xgbe_oe/0/src/intel/afifo_256x80_0.vhd new file mode 100644 index 0000000..f11f6eb --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/intel/afifo_256x80_0.vhd @@ -0,0 +1,211 @@ +-- megafunction wizard: %FIFO% +-- GENERATION: STANDARD +-- VERSION: WM1.0 +-- MODULE: dcfifo + +-- ============================================================ +-- File Name: afifo_256x80_0.vhd +-- Megafunction Name(s): +-- dcfifo +-- +-- 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.all; + +ENTITY afifo_256x80_0 IS + PORT + ( + aclr : IN STD_LOGIC := '0'; + data : IN STD_LOGIC_VECTOR (79 DOWNTO 0); + rdclk : IN STD_LOGIC ; + rdreq : IN STD_LOGIC ; + wrclk : IN STD_LOGIC ; + wrreq : IN STD_LOGIC ; + q : OUT STD_LOGIC_VECTOR (79 DOWNTO 0); + rdempty : OUT STD_LOGIC ; + wrfull : OUT STD_LOGIC ; + wrusedw : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) + ); +END afifo_256x80_0; + + +ARCHITECTURE SYN OF afifo_256x80_0 IS + + SIGNAL sub_wire0 : STD_LOGIC_VECTOR (79 DOWNTO 0); + SIGNAL sub_wire1 : STD_LOGIC ; + SIGNAL sub_wire2 : STD_LOGIC ; + SIGNAL sub_wire3 : STD_LOGIC_VECTOR (7 DOWNTO 0); + + + + COMPONENT dcfifo + GENERIC ( + intended_device_family : STRING; + lpm_numwords : NATURAL; + lpm_showahead : STRING; + lpm_type : STRING; + lpm_width : NATURAL; + lpm_widthu : NATURAL; + overflow_checking : STRING; + rdsync_delaypipe : NATURAL; + read_aclr_synch : STRING; + underflow_checking : STRING; + use_eab : STRING; + write_aclr_synch : STRING; + wrsync_delaypipe : NATURAL + ); + PORT ( + aclr : IN STD_LOGIC ; + data : IN STD_LOGIC_VECTOR (79 DOWNTO 0); + rdclk : IN STD_LOGIC ; + rdreq : IN STD_LOGIC ; + wrclk : IN STD_LOGIC ; + wrreq : IN STD_LOGIC ; + q : OUT STD_LOGIC_VECTOR (79 DOWNTO 0); + rdempty : OUT STD_LOGIC ; + wrfull : OUT STD_LOGIC ; + wrusedw : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) + ); + END COMPONENT; + +BEGIN + q <= sub_wire0(79 DOWNTO 0); + rdempty <= sub_wire1; + wrfull <= sub_wire2; + wrusedw <= sub_wire3(7 DOWNTO 0); + + dcfifo_component : dcfifo + GENERIC MAP ( + intended_device_family => "Cyclone V", + lpm_numwords => 256, + lpm_showahead => "OFF", + lpm_type => "dcfifo", + lpm_width => 80, + lpm_widthu => 8, + overflow_checking => "ON", + rdsync_delaypipe => 4, + read_aclr_synch => "OFF", + underflow_checking => "ON", + use_eab => "ON", + write_aclr_synch => "OFF", + wrsync_delaypipe => 4 + ) + PORT MAP ( + aclr => aclr, + data => data, + rdclk => rdclk, + rdreq => rdreq, + wrclk => wrclk, + wrreq => wrreq, + q => sub_wire0, + rdempty => sub_wire1, + wrfull => sub_wire2, + wrusedw => sub_wire3 + ); + + + +END SYN; + +-- ============================================================ +-- CNX file retrieval info +-- ============================================================ +-- Retrieval info: PRIVATE: AlmostEmpty NUMERIC "0" +-- Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC "-1" +-- Retrieval info: PRIVATE: AlmostFull NUMERIC "0" +-- Retrieval info: PRIVATE: AlmostFullThr NUMERIC "-1" +-- Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC "0" +-- Retrieval info: PRIVATE: Clock NUMERIC "4" +-- Retrieval info: PRIVATE: Depth NUMERIC "256" +-- Retrieval info: PRIVATE: Empty NUMERIC "1" +-- Retrieval info: PRIVATE: Full NUMERIC "1" +-- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone V" +-- Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC "0" +-- Retrieval info: PRIVATE: LegacyRREQ NUMERIC "1" +-- Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC "0" +-- Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC "0" +-- Retrieval info: PRIVATE: Optimize NUMERIC "0" +-- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0" +-- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0" +-- Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC "0" +-- Retrieval info: PRIVATE: UsedW NUMERIC "1" +-- Retrieval info: PRIVATE: Width NUMERIC "80" +-- Retrieval info: PRIVATE: dc_aclr NUMERIC "1" +-- Retrieval info: PRIVATE: diff_widths NUMERIC "0" +-- Retrieval info: PRIVATE: msb_usedw NUMERIC "0" +-- Retrieval info: PRIVATE: output_width NUMERIC "80" +-- Retrieval info: PRIVATE: rsEmpty NUMERIC "1" +-- Retrieval info: PRIVATE: rsFull NUMERIC "0" +-- Retrieval info: PRIVATE: rsUsedW NUMERIC "0" +-- Retrieval info: PRIVATE: sc_aclr NUMERIC "0" +-- Retrieval info: PRIVATE: sc_sclr NUMERIC "0" +-- Retrieval info: PRIVATE: wsEmpty NUMERIC "0" +-- Retrieval info: PRIVATE: wsFull NUMERIC "1" +-- Retrieval info: PRIVATE: wsUsedW NUMERIC "1" +-- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all +-- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V" +-- Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC "256" +-- Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING "OFF" +-- Retrieval info: CONSTANT: LPM_TYPE STRING "dcfifo" +-- Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "80" +-- Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC "8" +-- Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING "ON" +-- Retrieval info: CONSTANT: RDSYNC_DELAYPIPE NUMERIC "4" +-- Retrieval info: CONSTANT: READ_ACLR_SYNCH STRING "OFF" +-- Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING "ON" +-- Retrieval info: CONSTANT: USE_EAB STRING "ON" +-- Retrieval info: CONSTANT: WRITE_ACLR_SYNCH STRING "OFF" +-- Retrieval info: CONSTANT: WRSYNC_DELAYPIPE NUMERIC "4" +-- Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT GND "aclr" +-- Retrieval info: USED_PORT: data 0 0 80 0 INPUT NODEFVAL "data[79..0]" +-- Retrieval info: USED_PORT: q 0 0 80 0 OUTPUT NODEFVAL "q[79..0]" +-- Retrieval info: USED_PORT: rdclk 0 0 0 0 INPUT NODEFVAL "rdclk" +-- Retrieval info: USED_PORT: rdempty 0 0 0 0 OUTPUT NODEFVAL "rdempty" +-- Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL "rdreq" +-- Retrieval info: USED_PORT: wrclk 0 0 0 0 INPUT NODEFVAL "wrclk" +-- Retrieval info: USED_PORT: wrfull 0 0 0 0 OUTPUT NODEFVAL "wrfull" +-- Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL "wrreq" +-- Retrieval info: USED_PORT: wrusedw 0 0 8 0 OUTPUT NODEFVAL "wrusedw[7..0]" +-- Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0 +-- Retrieval info: CONNECT: @data 0 0 80 0 data 0 0 80 0 +-- Retrieval info: CONNECT: @rdclk 0 0 0 0 rdclk 0 0 0 0 +-- Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0 +-- Retrieval info: CONNECT: @wrclk 0 0 0 0 wrclk 0 0 0 0 +-- Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0 +-- Retrieval info: CONNECT: q 0 0 80 0 @q 0 0 80 0 +-- Retrieval info: CONNECT: rdempty 0 0 0 0 @rdempty 0 0 0 0 +-- Retrieval info: CONNECT: wrfull 0 0 0 0 @wrfull 0 0 0 0 +-- Retrieval info: CONNECT: wrusedw 0 0 8 0 @wrusedw 0 0 8 0 +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_256x80_0.vhd TRUE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_256x80_0.inc FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_256x80_0.cmp FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_256x80_0.bsf FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL afifo_256x80_0_inst.vhd FALSE +-- Retrieval info: LIB_FILE: altera_mf diff --git a/generic_ip/xgbe_oe/0/src/intel/asym_ram_0.vhd b/generic_ip/xgbe_oe/0/src/intel/asym_ram_0.vhd new file mode 100644 index 0000000..0dbc47b --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/intel/asym_ram_0.vhd @@ -0,0 +1,204 @@ +-- megafunction wizard: %RAM: 2-PORT% +-- GENERATION: STANDARD +-- VERSION: WM1.0 +-- MODULE: altsyncram + +-- ============================================================ +-- File Name: asym_ram_0.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 asym_ram_0 IS + GENERIC ( + WDATAWIDTH : natural range 1 to 1024 := 32; + LOG2WADDRWIDTH : natural range 1 to 1024 := 5; + RDATAWIDTH : natural range 1 to 1024 := 64; + LOG2RADDRWIDTH : natural range 1 to 1024 := 4 + ); + PORT + ( + clock : IN STD_LOGIC := '1'; + data : IN STD_LOGIC_VECTOR (WDATAWIDTH-1 DOWNTO 0); + rdaddress : IN STD_LOGIC_VECTOR (LOG2RADDRWIDTH-1 DOWNTO 0); + wraddress : IN STD_LOGIC_VECTOR (LOG2WADDRWIDTH-1 DOWNTO 0); + wren : IN STD_LOGIC := '0'; + q : OUT STD_LOGIC_VECTOR (RDATAWIDTH-1 DOWNTO 0) + ); +END asym_ram_0; + + +ARCHITECTURE SYN OF asym_ram_0 IS + + SIGNAL sub_wire0 : STD_LOGIC_VECTOR (RDATAWIDTH-1 DOWNTO 0); + +BEGIN + q <= sub_wire0(RDATAWIDTH-1 DOWNTO 0); + + altsyncram_component : altsyncram + GENERIC MAP ( + address_aclr_b => "NONE", + address_reg_b => "CLOCK0", + clock_enable_input_a => "BYPASS", + clock_enable_input_b => "BYPASS", + clock_enable_output_b => "BYPASS", + intended_device_family => "Cyclone V", + lpm_type => "altsyncram", + numwords_a => 2**LOG2WADDRWIDTH, + numwords_b => 2**LOG2RADDRWIDTH, + operation_mode => "DUAL_PORT", + outdata_aclr_b => "NONE", + outdata_reg_b => "UNREGISTERED", + power_up_uninitialized => "FALSE", + ram_block_type => "M10K", + read_during_write_mode_mixed_ports => "DONT_CARE", + widthad_a => LOG2WADDRWIDTH, + widthad_b => LOG2RADDRWIDTH, + width_a => WDATAWIDTH, + width_b => RDATAWIDTH, + width_byteena_a => 1 + ) + PORT MAP ( + address_a => wraddress, + address_b => rdaddress, + clock0 => clock, + data_a => data, + wren_a => wren, + q_b => sub_wire0 + ); + + + +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 "0" +-- Retrieval info: PRIVATE: INIT_FILE_LAYOUT STRING "PORT_B" +-- 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 "1024" +-- Retrieval info: PRIVATE: MEM_IN_BITS NUMERIC "0" +-- Retrieval info: PRIVATE: MIFfilename STRING "" +-- Retrieval info: PRIVATE: OPERATION_MODE NUMERIC "2" +-- Retrieval info: PRIVATE: OUTDATA_ACLR_B NUMERIC "0" +-- Retrieval info: PRIVATE: OUTDATA_REG_B NUMERIC "0" +-- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "2" +-- 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 "1" +-- Retrieval info: PRIVATE: REGrdaddress NUMERIC "1" +-- Retrieval info: PRIVATE: REGrren NUMERIC "1" +-- 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 "1" +-- Retrieval info: PRIVATE: WIDTH_READ_A NUMERIC "32" +-- Retrieval info: PRIVATE: WIDTH_READ_B NUMERIC "64" +-- Retrieval info: PRIVATE: WIDTH_WRITE_A NUMERIC "32" +-- Retrieval info: PRIVATE: WIDTH_WRITE_B NUMERIC "64" +-- Retrieval info: PRIVATE: WRADDR_ACLR_B NUMERIC "0" +-- Retrieval info: PRIVATE: WRADDR_REG_B NUMERIC "0" +-- 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_ACLR_B STRING "NONE" +-- 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_B STRING "BYPASS" +-- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V" +-- Retrieval info: CONSTANT: LPM_TYPE STRING "altsyncram" +-- Retrieval info: CONSTANT: NUMWORDS_A NUMERIC "32" +-- Retrieval info: CONSTANT: NUMWORDS_B NUMERIC "16" +-- Retrieval info: CONSTANT: OPERATION_MODE STRING "DUAL_PORT" +-- Retrieval info: CONSTANT: OUTDATA_ACLR_B STRING "NONE" +-- Retrieval info: CONSTANT: OUTDATA_REG_B STRING "UNREGISTERED" +-- Retrieval info: CONSTANT: POWER_UP_UNINITIALIZED STRING "FALSE" +-- Retrieval info: CONSTANT: RAM_BLOCK_TYPE STRING "M10K" +-- Retrieval info: CONSTANT: READ_DURING_WRITE_MODE_MIXED_PORTS STRING "DONT_CARE" +-- Retrieval info: CONSTANT: WIDTHAD_A NUMERIC "5" +-- Retrieval info: CONSTANT: WIDTHAD_B NUMERIC "4" +-- Retrieval info: CONSTANT: WIDTH_A NUMERIC "32" +-- Retrieval info: CONSTANT: WIDTH_B NUMERIC "64" +-- Retrieval info: CONSTANT: WIDTH_BYTEENA_A NUMERIC "1" +-- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT VCC "clock" +-- Retrieval info: USED_PORT: data 0 0 32 0 INPUT NODEFVAL "data[31..0]" +-- Retrieval info: USED_PORT: q 0 0 64 0 OUTPUT NODEFVAL "q[63..0]" +-- Retrieval info: USED_PORT: rdaddress 0 0 4 0 INPUT NODEFVAL "rdaddress[3..0]" +-- Retrieval info: USED_PORT: wraddress 0 0 5 0 INPUT NODEFVAL "wraddress[4..0]" +-- Retrieval info: USED_PORT: wren 0 0 0 0 INPUT GND "wren" +-- Retrieval info: CONNECT: @address_a 0 0 5 0 wraddress 0 0 5 0 +-- Retrieval info: CONNECT: @address_b 0 0 4 0 rdaddress 0 0 4 0 +-- Retrieval info: CONNECT: @clock0 0 0 0 0 clock 0 0 0 0 +-- Retrieval info: CONNECT: @data_a 0 0 32 0 data 0 0 32 0 +-- Retrieval info: CONNECT: @wren_a 0 0 0 0 wren 0 0 0 0 +-- Retrieval info: CONNECT: q 0 0 64 0 @q_b 0 0 64 0 +-- Retrieval info: GEN_FILE: TYPE_NORMAL asym_ram_0.vhd TRUE +-- Retrieval info: GEN_FILE: TYPE_NORMAL asym_ram_0.inc FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL asym_ram_0.cmp FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL asym_ram_0.bsf FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL asym_ram_0_inst.vhd FALSE +-- Retrieval info: LIB_FILE: altera_mf diff --git a/generic_ip/xgbe_oe/0/src/intel/gmii_pll/gmii_pll_0002_0.v b/generic_ip/xgbe_oe/0/src/intel/gmii_pll/gmii_pll_0002_0.v new file mode 100644 index 0000000..a2f9491 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/intel/gmii_pll/gmii_pll_0002_0.v @@ -0,0 +1,87 @@ +`timescale 1ns/10ps +module gmii_pll_0002_0( + + // interface 'refclk' + input wire refclk, + + // interface 'reset' + input wire rst, + + // interface 'outclk0' + output wire outclk_0, + + // interface 'locked' + output wire locked +); + + altera_pll #( + .fractional_vco_multiplier("false"), + .reference_clock_frequency("25.0 MHz"), + .operation_mode("direct"), + .number_of_clocks(1), + .output_clock_frequency0("125.000000 MHz"), + .phase_shift0("0 ps"), + .duty_cycle0(50), + .output_clock_frequency1("0 MHz"), + .phase_shift1("0 ps"), + .duty_cycle1(50), + .output_clock_frequency2("0 MHz"), + .phase_shift2("0 ps"), + .duty_cycle2(50), + .output_clock_frequency3("0 MHz"), + .phase_shift3("0 ps"), + .duty_cycle3(50), + .output_clock_frequency4("0 MHz"), + .phase_shift4("0 ps"), + .duty_cycle4(50), + .output_clock_frequency5("0 MHz"), + .phase_shift5("0 ps"), + .duty_cycle5(50), + .output_clock_frequency6("0 MHz"), + .phase_shift6("0 ps"), + .duty_cycle6(50), + .output_clock_frequency7("0 MHz"), + .phase_shift7("0 ps"), + .duty_cycle7(50), + .output_clock_frequency8("0 MHz"), + .phase_shift8("0 ps"), + .duty_cycle8(50), + .output_clock_frequency9("0 MHz"), + .phase_shift9("0 ps"), + .duty_cycle9(50), + .output_clock_frequency10("0 MHz"), + .phase_shift10("0 ps"), + .duty_cycle10(50), + .output_clock_frequency11("0 MHz"), + .phase_shift11("0 ps"), + .duty_cycle11(50), + .output_clock_frequency12("0 MHz"), + .phase_shift12("0 ps"), + .duty_cycle12(50), + .output_clock_frequency13("0 MHz"), + .phase_shift13("0 ps"), + .duty_cycle13(50), + .output_clock_frequency14("0 MHz"), + .phase_shift14("0 ps"), + .duty_cycle14(50), + .output_clock_frequency15("0 MHz"), + .phase_shift15("0 ps"), + .duty_cycle15(50), + .output_clock_frequency16("0 MHz"), + .phase_shift16("0 ps"), + .duty_cycle16(50), + .output_clock_frequency17("0 MHz"), + .phase_shift17("0 ps"), + .duty_cycle17(50), + .pll_type("General"), + .pll_subtype("General") + ) altera_pll_i ( + .rst (rst), + .outclk ({outclk_0}), + .locked (locked), + .fboutclk ( ), + .fbclk (1'b0), + .refclk (refclk) + ); +endmodule + diff --git a/generic_ip/xgbe_oe/0/src/intel/gmii_pll_0.vhd b/generic_ip/xgbe_oe/0/src/intel/gmii_pll_0.vhd new file mode 100644 index 0000000..490b6d9 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/intel/gmii_pll_0.vhd @@ -0,0 +1,271 @@ +-- megafunction wizard: %PLL Intel FPGA IP v18.1% +-- GENERATION: XML +-- gmii_pll_0.vhd + +-- Generated using ACDS version 18.1 625 + +library IEEE; +use IEEE.std_logic_1164.all; +use IEEE.numeric_std.all; + +entity gmii_pll_0 is + port ( + refclk : in std_logic := '0'; -- refclk.clk + rst : in std_logic := '0'; -- reset.reset + outclk_0 : out std_logic; -- outclk0.clk + locked : out std_logic -- locked.export + ); +end entity gmii_pll_0; + +architecture rtl of gmii_pll_0 is + component gmii_pll_0_0002 is + port ( + refclk : in std_logic := 'X'; -- clk + rst : in std_logic := 'X'; -- reset + outclk_0 : out std_logic; -- clk + locked : out std_logic -- export + ); + end component gmii_pll_0_0002; + +begin + + gmii_pll_0_inst : component gmii_pll_0_0002 + port map ( + refclk => refclk, -- refclk.clk + rst => rst, -- reset.reset + outclk_0 => outclk_0, -- outclk0.clk + locked => locked -- locked.export + ); + +end architecture rtl; -- of gmii_pll_0 +-- 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: +-- 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: +-- 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: +-- 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: +-- 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: +-- Retrieval info: +-- Retrieval info: +-- Retrieval info: +-- Retrieval info: +-- Retrieval info: +-- Retrieval info: +-- Retrieval info: +-- Retrieval info: +-- Retrieval info: +-- IPFS_FILES : gmii_pll_0.vho +-- RELATED_FILES: gmii_pll_0.vhd, gmii_pll_0_0002.v diff --git a/generic_ip/xgbe_oe/0/src/intel/sfifo_0.vhd b/generic_ip/xgbe_oe/0/src/intel/sfifo_0.vhd new file mode 100644 index 0000000..52c5bd8 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/intel/sfifo_0.vhd @@ -0,0 +1,201 @@ +-- megafunction wizard: %FIFO% +-- GENERATION: STANDARD +-- VERSION: WM1.0 +-- MODULE: scfifo + +-- ============================================================ +-- File Name: sfifo_0.vhd +-- Megafunction Name(s): +-- scfifo +-- +-- 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.all; + +ENTITY sfifo_0 IS + GENERIC ( + WIDTH : natural range 1 to 1024 := 80; + LOG2DEPTH : natural range 1 to 32 := 8 + ); + PORT + ( + clock : IN STD_LOGIC ; + data : IN STD_LOGIC_VECTOR (WIDTH-1 DOWNTO 0); + rdreq : IN STD_LOGIC ; + sclr : IN STD_LOGIC ; + wrreq : IN STD_LOGIC ; + empty : OUT STD_LOGIC ; + full : OUT STD_LOGIC ; + q : OUT STD_LOGIC_VECTOR (WIDTH-1 DOWNTO 0); + usedw : OUT STD_LOGIC_VECTOR (LOG2DEPTH-1 DOWNTO 0) + ); +END sfifo_0; + + +ARCHITECTURE SYN OF sfifo_0 IS + + SIGNAL sub_wire0 : STD_LOGIC ; + SIGNAL sub_wire1 : STD_LOGIC ; + SIGNAL sub_wire2 : STD_LOGIC_VECTOR (WIDTH-1 DOWNTO 0); + SIGNAL sub_wire3 : STD_LOGIC_VECTOR (LOG2DEPTH-1 DOWNTO 0); + + + + COMPONENT scfifo + GENERIC ( + add_ram_output_register : STRING; + intended_device_family : STRING; + lpm_numwords : NATURAL; + lpm_showahead : STRING; + lpm_type : STRING; + lpm_width : NATURAL; + lpm_widthu : NATURAL; + overflow_checking : STRING; + underflow_checking : STRING; + use_eab : STRING + ); + PORT ( + clock : IN STD_LOGIC ; + data : IN STD_LOGIC_VECTOR (WIDTH-1 DOWNTO 0); + rdreq : IN STD_LOGIC ; + sclr : IN STD_LOGIC ; + wrreq : IN STD_LOGIC ; + empty : OUT STD_LOGIC ; + full : OUT STD_LOGIC ; + q : OUT STD_LOGIC_VECTOR (WIDTH-1 DOWNTO 0); + usedw : OUT STD_LOGIC_VECTOR (LOG2DEPTH-1 DOWNTO 0) + ); + END COMPONENT; + +BEGIN + empty <= sub_wire0; + full <= sub_wire1; + q <= sub_wire2(WIDTH-1 DOWNTO 0); + usedw <= sub_wire3(LOG2DEPTH-1 DOWNTO 0); + + scfifo_component : scfifo + GENERIC MAP ( + add_ram_output_register => "OFF", + intended_device_family => "Cyclone V", + lpm_numwords => 2**LOG2DEPTH, + lpm_showahead => "OFF", + lpm_type => "scfifo", + lpm_width => WIDTH, + lpm_widthu => LOG2DEPTH, + overflow_checking => "ON", + underflow_checking => "ON", + use_eab => "ON" + ) + PORT MAP ( + clock => clock, + data => data, + rdreq => rdreq, + sclr => sclr, + wrreq => wrreq, + empty => sub_wire0, + full => sub_wire1, + q => sub_wire2, + usedw => sub_wire3 + ); + + + +END SYN; + +-- ============================================================ +-- CNX file retrieval info +-- ============================================================ +-- Retrieval info: PRIVATE: AlmostEmpty NUMERIC "0" +-- Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC "-1" +-- Retrieval info: PRIVATE: AlmostFull NUMERIC "0" +-- Retrieval info: PRIVATE: AlmostFullThr NUMERIC "-1" +-- Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC "0" +-- Retrieval info: PRIVATE: Clock NUMERIC "0" +-- Retrieval info: PRIVATE: Depth NUMERIC "256" +-- Retrieval info: PRIVATE: Empty NUMERIC "1" +-- Retrieval info: PRIVATE: Full NUMERIC "1" +-- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone V" +-- Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC "0" +-- Retrieval info: PRIVATE: LegacyRREQ NUMERIC "1" +-- Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC "0" +-- Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC "0" +-- Retrieval info: PRIVATE: Optimize NUMERIC "0" +-- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0" +-- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0" +-- Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC "0" +-- Retrieval info: PRIVATE: UsedW NUMERIC "1" +-- Retrieval info: PRIVATE: Width NUMERIC "80" +-- Retrieval info: PRIVATE: dc_aclr NUMERIC "0" +-- Retrieval info: PRIVATE: diff_widths NUMERIC "0" +-- Retrieval info: PRIVATE: msb_usedw NUMERIC "0" +-- Retrieval info: PRIVATE: output_width NUMERIC "80" +-- Retrieval info: PRIVATE: rsEmpty NUMERIC "1" +-- Retrieval info: PRIVATE: rsFull NUMERIC "0" +-- Retrieval info: PRIVATE: rsUsedW NUMERIC "0" +-- Retrieval info: PRIVATE: sc_aclr NUMERIC "0" +-- Retrieval info: PRIVATE: sc_sclr NUMERIC "1" +-- Retrieval info: PRIVATE: wsEmpty NUMERIC "0" +-- Retrieval info: PRIVATE: wsFull NUMERIC "1" +-- Retrieval info: PRIVATE: wsUsedW NUMERIC "0" +-- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all +-- Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING "OFF" +-- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V" +-- Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC "256" +-- Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING "OFF" +-- Retrieval info: CONSTANT: LPM_TYPE STRING "scfifo" +-- Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "80" +-- Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC "8" +-- Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING "ON" +-- Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING "ON" +-- Retrieval info: CONSTANT: USE_EAB STRING "ON" +-- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT NODEFVAL "clock" +-- Retrieval info: USED_PORT: data 0 0 80 0 INPUT NODEFVAL "data[79..0]" +-- Retrieval info: USED_PORT: empty 0 0 0 0 OUTPUT NODEFVAL "empty" +-- Retrieval info: USED_PORT: full 0 0 0 0 OUTPUT NODEFVAL "full" +-- Retrieval info: USED_PORT: q 0 0 80 0 OUTPUT NODEFVAL "q[79..0]" +-- Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL "rdreq" +-- Retrieval info: USED_PORT: sclr 0 0 0 0 INPUT NODEFVAL "sclr" +-- Retrieval info: USED_PORT: usedw 0 0 8 0 OUTPUT NODEFVAL "usedw[7..0]" +-- Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL "wrreq" +-- Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0 +-- Retrieval info: CONNECT: @data 0 0 80 0 data 0 0 80 0 +-- Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0 +-- Retrieval info: CONNECT: @sclr 0 0 0 0 sclr 0 0 0 0 +-- Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0 +-- Retrieval info: CONNECT: empty 0 0 0 0 @empty 0 0 0 0 +-- Retrieval info: CONNECT: full 0 0 0 0 @full 0 0 0 0 +-- Retrieval info: CONNECT: q 0 0 80 0 @q 0 0 80 0 +-- Retrieval info: CONNECT: usedw 0 0 8 0 @usedw 0 0 8 0 +-- Retrieval info: GEN_FILE: TYPE_NORMAL sfifo_0.vhd TRUE +-- Retrieval info: GEN_FILE: TYPE_NORMAL sfifo_0.inc FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL sfifo_0.cmp FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL sfifo_0.bsf FALSE +-- Retrieval info: GEN_FILE: TYPE_NORMAL sfifo_256x80_inst.vhd FALSE +-- Retrieval info: LIB_FILE: altera_mf diff --git a/generic_ip/xgbe_oe/0/src/rx_packet_filter_0.vhd b/generic_ip/xgbe_oe/0/src/rx_packet_filter_0.vhd new file mode 100644 index 0000000..e8e96a1 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/rx_packet_filter_0.vhd @@ -0,0 +1,134 @@ +------------------------------------------------------------------------------- +-- Title : rx_packet_filter_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : rx_packet_filter_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2017-05-25 +-- Last update: 2020-08-07 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- This block checks whether the received packet matches the configured filter. +-- The filter lenght is programmable in steps of 8 bytes (64 bits), up to 64 +-- bytes. The filter always starts from the start_of-packet byte word, and it +-- fininshes either with the filter lenght or with the end_of_packet word. +-- Note: the filter/mask configuration cannot read-back because that would +-- double the number of M10Ks block (or MLABs) required +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity rx_packet_filter_0 is + port ( + clk : in std_logic; + -- + init : in std_logic; + -- + cfg_addr : in std_logic_vector( 5 downto 0); + cfg_write : in std_logic; + cfg_data : in std_logic_vector(31 downto 0); + filt_len : in std_logic_vector( 3 downto 0); + -- rx data + start_of_packet : in std_logic; + end_of_packet : in std_logic; + rx_data_valid : in std_logic; + rx_data : in std_logic_vector(63 downto 0); + -- status signals + completed : out std_logic; + filter_match : out std_logic); +end entity rx_packet_filter_0; + +architecture rtl of rx_packet_filter_0 is + + ----------------------------------------------------------------------------- + -- Signals and Types + ----------------------------------------------------------------------------- + + signal cfg_filt_wr, cfg_mask_wr : std_logic; + signal check_completed, last_address : std_logic; + signal checksum_ok, completed_flag : std_logic; + signal rx_data_valid_d : std_logic; + signal filt_addr : std_logic_vector( 3 downto 0); + signal rx_data_i, rx_data_masked : std_logic_vector(63 downto 0); + signal filt_out, mask_out : std_logic_vector(63 downto 0); + +begin + + ----------------------------------------------------------------------------- + -- Filter/Mask memory + ----------------------------------------------------------------------------- + + -- Each of this memories employs 2 M10Ks block!! + + iFILTER_RAM: entity work.asym_ram_0 + port map ( + clock => clk, + wraddress => cfg_addr(4 downto 0), + wren => cfg_filt_wr, + data => cfg_data, + rdaddress => filt_addr, + q => filt_out); + + iMASK_RAM: entity work.asym_ram_0 + port map ( + clock => clk, + wraddress => cfg_addr(4 downto 0), + wren => cfg_mask_wr, + data => cfg_data, + rdaddress => filt_addr, + q => mask_out); + + cfg_filt_wr <= '1' when cfg_write = '1' and cfg_addr(5) = '0' else '0'; + cfg_mask_wr <= '1' when cfg_write = '1' and cfg_addr(5) = '1' else '0'; + + ----------------------------------------------------------------------------- + -- Filter Logic + ----------------------------------------------------------------------------- + + pFILTER : process(clk) + begin + if(clk = '1' and clk'event) then + rx_data_valid_d <= rx_data_valid; + check_completed <= (end_of_packet or last_address) and not completed_flag; + if(init = '1' or end_of_packet = '1') then + filt_addr <= (others => '0'); + elsif(rx_data_valid = '1' and (completed_flag = '0')) then + filt_addr <= std_logic_vector(unsigned(filt_addr)+1); + end if; + if(init = '1' or end_of_packet = '1') then + completed_flag <= '0'; + elsif(check_completed = '1') then + completed_flag <= '1'; + end if; + if(check_completed = '1') then + completed <= '1'; + else + completed <= '0'; + end if; + if(init = '1' or start_of_packet = '1') then + filter_match <= '0'; + elsif(check_completed = '1') then + filter_match <= checksum_ok; + end if; + if(init = '1' or start_of_packet = '1') then + checksum_ok <= '1'; + elsif((rx_data_valid_d = '1' and (rx_data_masked) /= filt_out)) then + checksum_ok <= '0'; + end if; + if(rx_data_valid = '1') then + rx_data_i <= rx_data; + end if; + end if; + end process pFILTER; + + rx_data_masked <= rx_data_i and mask_out; + + last_address <= '1' when unsigned(filt_addr) = unsigned(filt_len) or unsigned(filt_addr) = 31 else '0'; + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/rx_packet_split_0.vhd b/generic_ip/xgbe_oe/0/src/rx_packet_split_0.vhd new file mode 100644 index 0000000..cfab2ab --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/rx_packet_split_0.vhd @@ -0,0 +1,193 @@ +------------------------------------------------------------------------------- +-- Title : rx_packet_split_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : rx_packet_split_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-05-01 +-- Last update: 2020-08-12 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- The rx_packet_split_0 is composed of 2 elements: +-- 1. A packet filter, checking whether the packet is directed destination 0 +-- (packet filter not matched), or to destination 1 (packet filter matched). +-- 2. A data buffer, to store the output data from the MAC, +-- at least until the packet filter has determined the destination of a packet. +-- In case one of the destinations is not available to process data +-- immediately, the size of the buffer needs to be increased consequently, +-- and a queue for tracking the destinations of multiple packets is also +-- necessary, like in the original netfork-rx. +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity rx_packet_split_0 is + port ( + clk : in std_logic; + reset_n : in std_logic := '1'; + -- + init : in std_logic; + -- packet filter configuration + cfg_addr : in std_logic_vector(5 downto 0); + cfg_data : in std_logic_vector(31 downto 0); + cfg_write : in std_logic; + filt_len : in std_logic_vector(3 downto 0); + -- Source data interface (MAC) + rx_data_in : in std_logic_vector(63 downto 0); + rx_data_valid_in : in std_logic_vector(7 downto 0); -- data byte valid + rx_sop_in : in std_logic; -- start-of-packet + rx_eop_in : in std_logic; -- end-of-packet + rx_frame_valid_in : in std_logic; + rx_cts_in : out std_logic; -- clear-to-send + -- Destination data interface + packet_dest : out std_logic; -- '1' => filter is matched + rx_data_out : out std_logic_vector(63 downto 0); + rx_data_valid_out : out std_logic_vector(7 downto 0); + rx_sof_out : out std_logic; + rx_eof_out : out std_logic; + rx_frame_valid_out : out std_logic; + rx_rts_out : out std_logic; + rx_cts_out : in std_logic); +end entity rx_packet_split_0; + +architecture rtl of rx_packet_split_0 is + + signal filter_completed, filter_match : std_logic; + signal data_valid, data_re, rx_cts : std_logic; + signal packet_queue_empty : std_logic; + signal rx_buffer_empty : std_logic; + signal egress_start : std_logic; + signal egress_packet : std_logic := '0'; + signal egress_completed, valid_out : std_logic; + -- + signal packet_d, packet_q : std_logic_vector( 0 downto 0); + signal rx_buffer_usew : std_logic_vector( 7 downto 0); + signal data, q : std_logic_vector(79 downto 0); + + +begin + + ----------------------------------------------------------------------------- + -- Packet filter + ----------------------------------------------------------------------------- + + iPACKET_FILTER: entity work.rx_packet_filter_0 + port map ( + clk => clk, + init => init, + cfg_addr => cfg_addr, + cfg_write => cfg_write, + cfg_data => cfg_data, + filt_len => filt_len, + start_of_packet => rx_sop_in, + end_of_packet => rx_eop_in, + rx_data_valid => rx_data_valid_in(0), + rx_data => rx_data_in, + completed => filter_completed, + filter_match => filter_match); + + ----------------------------------------------------------------------------- + -- Data Buffer + ----------------------------------------------------------------------------- + + iDATA_BUFFER: entity work.sfifo_0 + generic map ( + WIDTH => 80, + LOG2DEPTH => 8 + ) + port map ( + clock => clk, + sclr => init, + wrreq => data_valid, + data => data, + rdreq => data_re, + empty => rx_buffer_empty, + full => open, + q => q, + usedw => rx_buffer_usew); + + data <= 5x"0" & rx_frame_valid_in & rx_eop_in & rx_sop_in & rx_data_valid_in & rx_data_in; + + pGEN_RX_CTS : process(clk) + begin + if(clk = '1' and clk'event) then + if(rx_buffer_usew(7 downto 2) /= "111111") then + rx_cts <= '1'; + else + rx_cts <= '0'; + end if; + end if; + end process pGEN_RX_CTS; + + rx_cts_in <= rx_cts; + + data_valid <= '1' when unsigned(rx_data_valid_in) /= 0 and rx_cts = '1' else '0'; + + ----------------------------------------------------------------------------- + -- Packet Queue + ----------------------------------------------------------------------------- + + -- Since the data buffer can store several packets, a separate queue is needed to + -- store the result of the filter check + iPACKET_QUEUE: entity work.sfifo_0 + generic map ( + WIDTH => 1, + LOG2DEPTH => 5 + ) + port map ( + clock => clk, + sclr => init, + wrreq => filter_completed, + data => packet_d, + rdreq => egress_start, + empty => packet_queue_empty, + full => open, + q => packet_q, + usedw => open); + + packet_d(0) <= filter_match; + + ----------------------------------------------------------------------------- + -- Egress Logic + ----------------------------------------------------------------------------- + + pEgressRegs: process(clk) + begin + if(clk = '1' and clk'event) then + if(init = '1' or egress_completed = '1') then + egress_packet <= '0'; + elsif(egress_start = '1') then + egress_packet <= '1'; + end if; + valid_out <= data_re; + -- Add a register between the FIFO output and the TCP-Server + rx_data_out <= q(63 downto 0); + + if valid_out then + rx_data_valid_out <= q(71 downto 64); + else + rx_data_valid_out <= (others => '0'); + end if; + + rx_rts_out <= valid_out; + rx_sof_out <= valid_out and q(72); + rx_eof_out <= valid_out and q(73); + rx_frame_valid_out <= valid_out and q(74); + end if; + end process pEgressRegs; + + data_re <= '1' when egress_packet = '1' and rx_cts_out = '1' and rx_buffer_empty = '0' else '0'; + + egress_start <= '1' when packet_queue_empty = '0' and egress_packet = '0' else '0'; + + egress_completed <= valid_out and q(73); + + packet_dest <= packet_q(0); + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/tcp_tpc_0.vhd b/generic_ip/xgbe_oe/0/src/tcp_tpc_0.vhd new file mode 100644 index 0000000..cd3ffe0 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/tcp_tpc_0.vhd @@ -0,0 +1,107 @@ +------------------------------------------------------------------------------- +-- Title : tcp_tpc_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : tcp_tpc_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-07-14 +-- Last update: 2020-08-12 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- TCP Server test pattern checker (TPC). It matches the the pattern generated by the +-- TCP Server Test Pattern Generator (TPG) +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity tcp_tpc_0 is + generic( + SEED : std_logic_vector(63 downto 0) := X"5AA5BAD0BAD1A55A"); + port ( + clk : in std_logic; -- @156.25MHz + -- control interface + init : in std_logic; + check_start : in std_logic; + check_stop : in std_logic; + word_errors : out std_logic_vector(15 downto 0); + -- TCP Server Rx interface + rx_data : in std_logic_vector(63 downto 0); + rx_data_valid : in std_logic_vector( 7 downto 0); + rx_rts : in std_logic; + rx_cts : out std_logic; + rx_cts_ack : in std_logic); +end entity tcp_tpc_0; + +architecture rtl of tcp_tpc_0 is + + signal upd, data_valid, running : std_logic; + signal detected_error : std_logic; + + signal prn_word : std_logic_vector(63 downto 0); + +begin + + ----------------------------------------------------------------------------- + -- LFSRs + ----------------------------------------------------------------------------- + + iLSB: entity work.PRN_gen_0 + generic map ( + seed => SEED(31 downto 0)) + port map ( + rstN => '1', + clk => clk, + PRN_rst => init, + PRN_upd => upd, + PRN_reg => prn_word(31 downto 0), + PRN_out => open); + + iMSB: entity work.PRN_gen_0 + generic map ( + seed => SEED(63 downto 32)) + port map ( + rstN => '1', + clk => clk, + PRN_rst => init, + PRN_upd => upd, + PRN_reg => prn_word(63 downto 32), + PRN_out => open); + + ----------------------------------------------------------------------------- + -- Burst generation logic + ----------------------------------------------------------------------------- + + -- Data are generated in bursts of 64-bit words, with burst_size specifying + -- the number of words composing a burst, and burst_gap the number of clock + -- cycles between contiguous bursts + + pTPC_REGS: process(clk) + begin + if(clk = '1' and clk'event) then + if(init = '1' or check_stop = '1') then + running <= '0'; + elsif(check_start = '1') then + running <= '1'; + end if; + if(init = '1') then + word_errors <= (0 => '1', others => '0'); + elsif(detected_error = '1') then + word_errors <= std_logic_vector(unsigned(word_errors)+1); + end if; + end if; + end process pTPC_REGS; + + data_valid <= rx_rts and running; + upd <= data_valid; + + rx_cts <= running; + + detected_error <= '1' when data_valid = '1' and rx_data /= prn_word else '0'; + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/tcp_tpg_0.vhd b/generic_ip/xgbe_oe/0/src/tcp_tpg_0.vhd new file mode 100644 index 0000000..673e73b --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/tcp_tpg_0.vhd @@ -0,0 +1,170 @@ +------------------------------------------------------------------------------- +-- Title : tcp_tpg_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : tcp_tpg_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-07-14 +-- Last update: 2020-07-14 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- TCP Server test pattern generator, LFSR based +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity tcp_tpg_0 is + generic( + SEED : std_logic_vector(63 downto 0) := X"5AA5BAD0BAD1A55A"); + port ( + clk : in std_logic; -- @156.25MHz + -- control interface + init : in std_logic; + gen_start : in std_logic; + gen_stop : in std_logic; + burst_size : in std_logic_vector(10 downto 0); + burst_gap : in std_logic_vector(15 downto 0); + -- TCP Server Tx interface + tx_data : out std_logic_vector(63 downto 0); + tx_data_valid : out std_logic_vector(7 downto 0); + tx_data_flush : out std_logic; + tx_cts : in std_logic); +end entity tcp_tpg_0; + +architecture rtl of tcp_tpg_0 is + + type fsm_state_t is (S_IDLE, S_GEN_BURST, S_FLUSH, S_PAUSE); + + signal fsm_state_curr, fsm_state_next : fsm_state_t; + + signal upd, rst_cnt, inc_cnt, stop : std_logic; + signal end_burst, end_pause : std_logic; + signal data_valid, data_flush : std_logic; + + signal cnt : std_logic_vector(15 downto 0); + signal prn_word : std_logic_vector(63 downto 0); + +begin + + ----------------------------------------------------------------------------- + -- LFSRs + ----------------------------------------------------------------------------- + + iLSB: entity work.PRN_gen_0 + generic map ( + seed => SEED(31 downto 0)) + port map ( + rstN => '1', + clk => clk, + PRN_rst => init, + PRN_upd => upd, + PRN_reg => prn_word(31 downto 0), + PRN_out => open); + + iMSB: entity work.PRN_gen_0 + generic map ( + seed => SEED(63 downto 32)) + port map ( + rstN => '1', + clk => clk, + PRN_rst => init, + PRN_upd => upd, + PRN_reg => prn_word(63 downto 32), + PRN_out => open); + + ----------------------------------------------------------------------------- + -- Burst generation logic + ----------------------------------------------------------------------------- + + -- Data are generated in bursts of 64-bit words, with burst_size specifying + -- the number of words composing a burst, and burst_gap the number of clock + -- cycles between contiguous bursts + + pBURST_REGS: process(clk) + begin + if(clk = '1' and clk'event) then + if(rst_cnt = '1') then + cnt <= (0 => '1', others => '0'); + elsif(inc_cnt = '1') then + cnt <= std_logic_vector(unsigned(cnt)+1); + end if; + if(init = '1' or gen_start = '1') then + stop <= '0'; + elsif(gen_stop = '1') then + stop <= '1'; + end if; + end if; + end process pBURST_REGS; + + upd <= data_valid; + + pFSM_SR: process(clk) + begin + if(clk = '1' and clk'event) then + if(init = '1') then + fsm_state_curr <= S_IDLE; + else + fsm_state_curr <= fsm_state_next; + end if; + end if; + end process pFSM_SR; + + end_burst <= '1' when unsigned(cnt) = unsigned(burst_size) else '0'; + end_pause <= '1' when unsigned(cnt) = unsigned(burst_gap) else '0'; + + pFSM_CL: process(all) + begin + -- default assignments + rst_cnt <= '0'; + inc_cnt <= '0'; + data_valid <= '0'; + data_flush <= '0'; + fsm_state_next <= fsm_state_curr; + + case fsm_state_curr is + when S_IDLE => + rst_cnt <= '1'; + if(gen_start = '1') then + fsm_state_next <= S_GEN_BURST; + end if; + + when S_GEN_BURST => + if(tx_cts = '1') then + inc_cnt <= '1'; + data_valid <= '1'; + end if; + if(end_burst = '1') then + rst_cnt <= '1'; + fsm_state_next <= S_FLUSH; + end if; + + when S_FLUSH => + data_flush <= '1'; + fsm_state_next <= S_PAUSE; + + when S_PAUSE => + inc_cnt <= '1'; + if(stop = '1') then + fsm_state_next <= S_IDLE; + elsif(end_pause = '1') then + rst_cnt <= '1'; + fsm_state_next <= S_GEN_BURST; + end if; + + when others => null; + end case; + + end process pFSM_CL; + + -- egress interface + tx_data <= prn_word; + tx_data_valid <= (others => '1') when data_valid = '1' else (others => '0'); + tx_data_flush <= data_flush; + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/tx_packet_combine_0.vhd b/generic_ip/xgbe_oe/0/src/tx_packet_combine_0.vhd new file mode 100644 index 0000000..a32a8fa --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/tx_packet_combine_0.vhd @@ -0,0 +1,183 @@ +------------------------------------------------------------------------------- +-- Title : tx_packet_combine_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : tx_packet_combine_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-05-01 +-- Last update: 2020-08-11 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Combine Tx packets coming either by the TCP-Server or the HPS-EMAC, to be +-- transmitted by the 10G PHY +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity tx_packet_combine_0 is + port ( + clk : in std_logic; + reset_n : in std_logic := '1'; + -- + init : in std_logic; + -- TCP Server Source interface + toe_tx_data : in std_logic_vector(63 downto 0); + toe_tx_data_valid : in std_logic_vector( 7 downto 0); -- data byte valid + toe_tx_sop : in std_logic; -- start-of-packet + toe_tx_eop : in std_logic; -- end-of-packet + toe_tx_cts : out std_logic; -- clear-to-send + toe_tx_rts : in std_logic; -- ready-to-send + -- HPS-EMAC Source interface + emac_tx_data : in std_logic_vector(63 downto 0); + emac_tx_data_valid : in std_logic_vector( 7 downto 0); -- data byte valid + emac_tx_sop : in std_logic; -- start-of-packet + emac_tx_eop : in std_logic; -- end-of-packet + emac_tx_cts : out std_logic; -- clear-to-send + emac_tx_rts : in std_logic; -- ready-to-send + -- MAC Destination interface + 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); +end entity tx_packet_combine_0; + +architecture rtl of tx_packet_combine_0 is + + signal fifo_we, fifo_re, fifo_re_d : std_logic; + signal emac_tx_cts_i, fifo_empty : std_logic; + signal egress_completed : std_logic; + signal egress_packet : std_logic; + signal egress_start : std_logic; + signal source_is_emac : std_logic; + signal packet_available : std_logic; + signal toe_tx_rts_d : std_logic; + -- + signal packet_cnt : std_logic_vector( 4 downto 0); + signal fifo_usew : std_logic_vector( 7 downto 0); + signal fifo_d, fifo_q : std_logic_vector(79 downto 0); + + +begin + + ----------------------------------------------------------------------------- + -- Data Buffer + ----------------------------------------------------------------------------- + + -- This FIFO has the purpose of accumulating data from the HPS-EMAC until at + -- least one full packet is available, allowing the pass data to the 10G-MAC + -- at 10G instead of 1G, which is the HPS-EMAC output speed. The FIFO + -- has a size slightly bigger than 1 MTU. It should be noticed that the + -- GMII-Tx-Bridge block provides also further buffering for data coming from + -- the HPS-EMAC. + + iDATA_BUFFER: entity work.sfifo_0 + generic map ( + WIDTH => 80, + LOG2DEPTH => 8 + ) + port map ( + clock => clk, + sclr => init, + wrreq => fifo_we, + data => fifo_d, + rdreq => fifo_re, + empty => fifo_empty, + full => open, + q => fifo_q, + usedw => fifo_usew); + + fifo_d <= 6x"0" & emac_tx_eop & emac_tx_sop & emac_tx_data_valid & emac_tx_data; + + pGEN_RX_CTS : process(clk) + begin + if(clk = '1' and clk'event) then + if(fifo_usew(7 downto 2) /= "111111" or packet_cnt(4 downto 3) /= "11") then + emac_tx_cts_i <= '1'; + else + emac_tx_cts_i <= '0'; + end if; + end if; + end process pGEN_RX_CTS; + + emac_tx_cts <= emac_tx_cts_i; + + fifo_we <= '1' when emac_tx_cts_i = '1' and emac_tx_rts = '1' else '0'; + + ----------------------------------------------------------------------------- + -- Combine & Egress Logic + ----------------------------------------------------------------------------- + + pCombineRegs: process(clk, reset_n) + begin + if reset_n = '0' then + + source_is_emac <= '0'; + egress_packet <= '0'; + packet_cnt <= (others => '0'); + toe_tx_rts_d <= '0'; + mac_tx_data_valid <= (others => '0'); + + elsif(clk = '1' and clk'event) then + + toe_tx_rts_d <= toe_tx_rts; + + if(init = '1') then + packet_cnt <= (others => '0'); + elsif(fifo_we = '1' and emac_tx_eop = '1') then + packet_cnt <= std_logic_vector(unsigned(packet_cnt)+1); + elsif(egress_completed = '1') then + packet_cnt <= std_logic_vector(unsigned(packet_cnt)-1); + end if; + + if(init = '1' or egress_completed = '1') then + egress_packet <= '0'; + elsif(egress_start = '1') then + egress_packet <= '1'; + end if; + + if(egress_start = '1') then + if(init = '1' or (fifo_usew(fifo_usew'left) = '0' and toe_tx_rts = '1')) then + source_is_emac <= '0'; + else + source_is_emac <= '1'; + end if; + end if; + + if(source_is_emac = '0') then + mac_tx_data <= toe_tx_data; + else + mac_tx_data <= fifo_q(63 downto 0); + end if; + + fifo_re_d <= fifo_re; + + if(egress_packet = '1' and mac_tx_cts = '1' and toe_tx_rts_d = '1') then + mac_tx_data_valid <= toe_tx_data_valid; + mac_tx_eof <= toe_tx_eop; + elsif(mac_tx_cts = '1' and fifo_re_d = '1') then + mac_tx_data_valid <= fifo_q(71 downto 64); + mac_tx_eof <= fifo_q(73); + else + mac_tx_data_valid <= (others => '0'); + mac_tx_eof <= '0'; + end if; + end if; + end process pCombineRegs; + + packet_available <= '1' when unsigned(packet_cnt) /= 0 else '0'; + + fifo_re <= '1' when egress_completed = '0' and egress_packet = '1' and mac_tx_cts = '1' and source_is_emac = '1' and fifo_empty = '0' else '0'; + + egress_start <= '1' when egress_packet = '0' and (toe_tx_rts = '1' or packet_available = '1') else '0'; + + egress_completed <= '1' when fifo_q(73) = '1' and fifo_re_d = '1' else '0'; + + toe_tx_cts <= mac_tx_cts and not source_is_emac; + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd b/generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd new file mode 100644 index 0000000..7064e0f --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd @@ -0,0 +1,1153 @@ +------------------------------------------------------------------------------- +-- Title : xgbe_oe_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : xgbe_oe_0.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-02-07 +-- Last update: 2020-08-12 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: GIS 10 Gigabit Ethernet Offload Engine +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library work; +use work.xgbe_oe_0_pkg.all; +use work.com5502pkg.all; + +entity xgbe_oe_0 is + generic( + EXT_PHY_MDIO_ADDR : std_logic_vector(4 downto 0) := "00000"; + SIM_MODE : std_logic := '0'; + XAUI_WIDTH : integer range 4 to 72 := 4; + TPG_ENABLED : boolean := false + ); + port( + clk_avs : in std_logic; -- avalon slave clock + reset_n : in std_logic := '1'; + clk_156_out : out std_logic; -- 156.25 MHz derived from the transceiver + + -- Ethernet 10G-PHY interface + -- 10G-PHY - XAUI interface + xaui_ref_clk : in std_logic; -- 156.25 MHz (from oscillator) + xaui_rx : in std_logic_vector(XAUI_WIDTH-1 downto 0); + xaui_tx : out std_logic_vector(XAUI_WIDTH-1 downto 0); + + -- 10G-PHY - Clocks & configuration + phy_rclk0 : in std_logic := '0'; -- PHY Recovered clock, at 25MHz + phy_reset_n : out std_logic; -- PHY harware reset (min is 10 ms) + phy_int_n : in std_logic := '1'; + phy_mdc : out std_logic; + phy_mdio_out : out std_logic; + phy_mdio_in : in std_logic; + phy_mdio_oe : out std_logic; + + -- 10G-PHY - PTP (1588) + tod_pclk : in std_logic := '0'; + tod_clk_out : in std_logic := '0'; + tod_trig_out : in std_logic := '0'; + + -- HPS-EMAC interface + -- EMAC-GMII interface + hps_emac_phy_txd : in std_logic_vector(7 downto 0); + hps_emac_phy_txen : in std_logic; + hps_emac_phy_txer : in std_logic; + hps_emac_phy_rxdv : out std_logic; + hps_emac_phy_rxer : out std_logic; + hps_emac_phy_rxd : out std_logic_vector(7 downto 0); + hps_emac_rx_clk : out std_logic; + hps_emac_rx_reset_n : in std_logic; + hps_emac_tx_clk : out std_logic; + hps_emac_tx_reset_n : in std_logic; + + -- EMAC-MDIO interface + hps_emac_md_clk : in std_logic; + hps_emac_gmii_mdo : in std_logic; + hps_emac_gmii_mdo_oe : in std_logic; + hps_emac_gmii_mdi : out std_logic; + + -- EMAC-PTP interface + hps_emac_ptp_pps : in std_logic := '0'; + hps_emac_ptp_aux_ts_trig : out std_logic; + hps_emac_gtx_clk : in std_logic; + hps_emac_ptp_ref_clock : out std_logic; + + -- Avalon MM Slave Interface + avs_address : in std_logic_vector(4 downto 0); + avs_write : in std_logic; + avs_writedata : in std_logic_vector(31 downto 0); + avs_read : in std_logic; + avs_readdata : out std_logic_vector(31 downto 0)); +end entity xgbe_oe_0; + +architecture rtl of xgbe_oe_0 is + + -- constants + constant MTU_SIZE : natural := 1500; + constant PREAMBLE_LEN : natural := 7; -- HPS-EMAC Preamble length + + constant MAC_ADDR_DEF : std_logic_vector(47 downto 0) :=X"DEF0DEF1DEF2"; + + -- TCP Server parameters + constant NTCPSTREAMS : natural := 1; + constant TX_IDLE_TIMEOUT : integer := 50; + constant TCP_KEEPALIVE_PERIOD : integer := 60; + + -- The PHY HW reset duration is 10 ms + constant PHY_HW_RESET_LEN : integer := 1562500; + + constant TPG_SEED : std_logic_vector(63 downto 0) := X"5AA5BAD0BAD1A55A"; + + + constant IPv4_MULTICAST_ADDR : std_logic_vector(31 downto 0) := X"00000000"; + constant IPv4_SUBNET_MASK : std_logic_vector(31 downto 0) := X"FFFFFF00"; + + signal reset_n_i : std_logic; + signal gmii_rx_clk : std_logic := '0'; + signal clk_156 : std_logic := '0'; + signal phy_rclk0_locked, init : std_logic; + signal xaui_rx_ready_i, xaui_rx_ready : std_logic; + signal xaui_tx_ready_i, xaui_tx_ready : std_logic; + signal mac_sync_reset : std_logic := '0'; + signal mac_async_reset : std_logic; + signal mac_power_down, phy_config_change : std_logic; + signal mac_tx_eof, mac_tx_cts : std_logic; + signal mac_rx_eof, mac_rx_sof : std_logic; + signal mac_rx_cts, mac_rx_frame_valid : std_logic; + signal mac_power_down_d : std_logic; + signal gmii_rx_rxdv : std_logic; + signal gmii_rx_rxer : std_logic; + signal toe_tx_sof, toe_tx_eof : std_logic; + signal toe_tx_cts, toe_tx_rts : std_logic; + signal toe_rx_sof, toe_rx_eof : std_logic; + signal toe_rx_frame_valid, rx_frame_valid : std_logic; + signal toe_sync_reset, tcp_conn_reset : std_logic; + signal tcp_keepalive_en : std_logic; + signal filt_cfg_write, mac_sync_reset_i : std_logic; + signal rx_sof, rx_eof, rx_cts, rx_rts : std_logic; + signal rx_packet_dest, fifo_afull_flag : std_logic; + signal clr_fifo_afull_flag, gmii_rx_cts : std_logic; + signal emac_tx_sof, emac_tx_eof : std_logic; + signal emac_tx_cts, emac_tx_rts : std_logic; + signal gmii_tx_clk, gmii_txen : std_logic; + signal gmii_txer : std_logic; + signal tcp_tx_cts : std_logic; + signal tcp_rx_cts : std_logic := '1'; + signal tcp_rx_rts : std_logic; + signal tcp_rx_cts_ack : std_logic; + signal tcp_tx_data_flush : std_logic; + signal tcp_connected_flag : std_logic; + signal phy_reset_start, phy_reset_done : std_logic; + signal gen_phy_reset, phy_rst_cnt_tc : std_logic := '0'; + signal mac_loopback_en : std_logic; + signal tpg_start, tpg_stop : std_logic; + signal tpc_start, tpc_stop : std_logic; + signal tx_brg_buffer_ovfl_flag : std_logic; + signal tx_brg_clr_buffer_ovfl_flag : std_logic; + -- + signal tcp_tx_data_flush_v : std_logic_vector( 0 downto 0); + signal toe_conn_reset_v : std_logic_vector( 0 downto 0); + signal tcp_keepalive_en_v : std_logic_vector( 0 downto 0); + signal tcp_rx_cts_v : std_logic_vector( 0 downto 0); + signal tcp_tx_cts_v : std_logic_vector( 0 downto 0); + signal tcp_rx_cts_ack_v : std_logic_vector( 0 downto 0); + signal tcp_rx_rts_v : std_logic_vector( 0 downto 0); + signal tcp_connected_flag_v : std_logic_vector( 0 downto 0); + signal mac_test_mode : std_logic_vector( 1 downto 0); + signal mac_test_mode_d : std_logic_vector( 1 downto 0); + signal filt_cfg_len : std_logic_vector( 3 downto 0); + signal filt_cfg_addr : std_logic_vector( 5 downto 0); + signal rst_cnt : std_logic_vector( 5 downto 0); + signal mac_tx_config : std_logic_vector( 7 downto 0); + signal mac_rx_config : std_logic_vector( 7 downto 0); + signal rx_ipg : std_logic_vector( 7 downto 0); + signal phy_status : std_logic_vector( 7 downto 0); + signal phy_status2 : std_logic_vector( 7 downto 0); + signal xgmii_txc : std_logic_vector( 7 downto 0); + signal xgmii_rxc : std_logic_vector( 7 downto 0); + signal xgmii_rxc_xaui : std_logic_vector( 7 downto 0); + signal mac_tx_data_valid : std_logic_vector( 7 downto 0); + signal mac_rx_data_valid : std_logic_vector( 7 downto 0); + signal rx_data_valid : std_logic_vector( 7 downto 0); + signal toe_tx_data_valid : std_logic_vector( 7 downto 0); + signal toe_rx_data_valid : std_logic_vector( 7 downto 0); + signal tcp_rx_data_valid : std_logic_vector( 7 downto 0); + signal tcp_tx_data_valid : std_logic_vector( 7 downto 0); + signal tcp_rx_data_valid_v : SLV8xNTCPSTREAMStype; + signal emac_tx_data_valid : std_logic_vector( 7 downto 0); + signal gmii_rx_rxd : std_logic_vector( 7 downto 0); + signal gmii_txd : std_logic_vector( 7 downto 0); + signal tx_brg_buffer_level : std_logic_vector(10 downto 0); + signal tpg_burst_size : std_logic_vector(10 downto 0); + signal tpg_burst_gap : std_logic_vector(15 downto 0); + signal tpc_errors : std_logic_vector(15 downto 0); + signal phy_id : std_logic_vector(15 downto 0); + signal n_tx_frames : std_logic_vector(15 downto 0); + signal n_rx_frames : std_logic_vector(15 downto 0); + signal n_rx_bad_crcs : std_logic_vector(15 downto 0); + signal n_rx_length_errors : std_logic_vector(15 downto 0); + signal n_rx_frames_too_short : std_logic_vector(15 downto 0); + signal n_rx_frames_too_long : std_logic_vector(15 downto 0); + signal n_rx_wrong_addr : std_logic_vector(15 downto 0); + signal tx_brg_disc_packets : std_logic_vector(15 downto 0); + signal tcp_local_port : std_logic_vector(15 downto 0); + signal tcp_local_ports : SLV16xNTCPSTREAMStype; + signal phy_rst_cnt : std_logic_vector(20 downto 0); + signal ip_addr : std_logic_vector(31 downto 0); + signal ip_gateway_addr : std_logic_vector(31 downto 0); + signal filt_cfg_data : std_logic_vector(31 downto 0); + signal mac_addr : std_logic_vector(47 downto 0); + signal xgmii_txd : std_logic_vector(63 downto 0); + signal xgmii_rxd : std_logic_vector(63 downto 0); + signal xgmii_rxd_xaui : std_logic_vector(63 downto 0); + signal mac_tx_data : std_logic_vector(63 downto 0); + signal mac_rx_data : std_logic_vector(63 downto 0); + signal rx_data : std_logic_vector(63 downto 0); + signal toe_tx_data : std_logic_vector(63 downto 0); + signal toe_rx_data : std_logic_vector(63 downto 0); + signal tcp_rx_data : std_logic_vector(63 downto 0); + signal tcp_tx_data : std_logic_vector(63 downto 0); + signal tcp_rx_data_v : SLV64xNTCPSTREAMStype; + signal emac_tx_data : std_logic_vector(63 downto 0); + signal xgmii_tx_dc : std_logic_vector(71 downto 0); + signal xgmii_rx_dc : std_logic_vector(71 downto 0); + --signal fifo_tx_d : std_logic_vector(71 downto 0); + --signal fifo_tx_q : std_logic_vector(71 downto 0); + --signal fifo_rx_d : std_logic_vector(71 downto 0); + --signal fifo_rx_q : std_logic_vector(71 downto 0); + + -- CSR synchronization signals + signal reset_n_avs : std_logic := '1'; + signal init_i : std_logic; + signal phy_reset_start_i : std_logic; + signal phy_reset_done_i : std_logic; + signal tcp_conn_reset_i : std_logic; + signal filt_cfg_write_i : std_logic; + signal filt_cfg_write_d : std_logic; + signal filt_cfg_done : std_logic; + signal set_filt_cfg_wr_done_i : std_logic; + signal filt_cfg_wr_done_i : std_logic; + signal tpg_start_i, tpg_stop_i : std_logic; + signal tpc_start_i, tpc_stop_i : std_logic; + signal tpc_poll_error_req : std_logic; + signal tpc_poll_error_req_i : std_logic; + signal tpc_poll_error_req_d : std_logic; + signal tpc_errors_is_valid : std_logic; + signal tpc_errors_is_valid_i : std_logic; + signal set_tpc_errors_is_valid_i : std_logic; + signal mac_status_read_req : std_logic; + signal mac_status_read_req_i : std_logic; + signal mac_status_rdy_i : std_logic; + signal set_mac_status_rdy_i : std_logic; + signal tx_brg_disc_stat_rd_req_i : std_logic; + signal tx_brg_disc_stat_rd_req : std_logic; + signal tx_brg_clr_buffer_ovfl_flag_i : std_logic; + signal tx_brg_buffer_ovfl_flag_i : std_logic; + signal tx_brg_disc_stat_rdy_i : std_logic; + signal set_tx_brg_disc_stat_rdy_i : std_logic; + -- + signal init_v : std_logic_vector(2 downto 0); + signal phy_reset_start_v : std_logic_vector(2 downto 0); + signal filt_cfg_write_v : std_logic_vector(2 downto 0); + signal tpg_start_v, tpg_stop_v : std_logic_vector(2 downto 0); + signal tpc_start_v, tpc_stop_v : std_logic_vector(2 downto 0); + signal mac_status_read_req_v : std_logic_vector(2 downto 0); + signal tx_brg_disc_stat_rd_req_v : std_logic_vector(2 downto 0); + signal tx_brg_clr_buffer_ovfl_flag_v : std_logic_vector(2 downto 0); + signal filt_cfg_done_v : std_logic_vector(3 downto 0); + signal tpc_errors_is_valid_v : std_logic_vector(3 downto 0); + signal mac_status_rdy_v : std_logic_vector(3 downto 0); + signal mac_status_addr_i : std_logic_vector(3 downto 0); + signal tx_brg_disc_stat_rdy_v : std_logic_vector(3 downto 0); + signal mac_status_val : std_logic_vector(15 downto 0); + signal mac_status_val_i : std_logic_vector(15 downto 0); + signal tpc_errors_i : std_logic_vector(15 downto 0); + signal tx_brg_disc_packets_i : std_logic_vector(15 downto 0); + + +begin + + ----------------------------------------------------------------------------- + -- Clocks and reset + ----------------------------------------------------------------------------- + + iSyncReset : entity work.sync_reset + port map ( + async_rstN => reset_n, + clk => clk_156, + sync_rstN => reset_n_i); + + -- This PLL generates a 125MHz clock from the 25MHz PHY recovered clock. The + -- clock frequency remains 25MHz even when the link speed changes. + + gGMII_PLL: if SIM_MODE = '0' generate + + iGMII_PLL: entity work.gmii_pll_0 + port map ( + refclk => phy_rclk0, + rst => gen_phy_reset, + outclk_0 => gmii_rx_clk, + locked => phy_rclk0_locked); + + else generate + -- SIM_MODE = '1' + + --pragma translate_off + + -- emulate a 125 MHz clock + gmii_rx_clk <= not gmii_rx_clk after 4 ns; + + phy_rclk0_locked <= not gen_phy_reset after 100 ns; + + --pragma translate_on + + end generate gGMII_PLL; + + ----------------------------------------------------------------------------- + -- MAC + ----------------------------------------------------------------------------- + + iMAC : entity work.com5501 + generic map ( + EXT_PHY_MDIO_ADDR => EXT_PHY_MDIO_ADDR, + RX_MTU => MTU_SIZE, + RX_BUFFER => '0', + RX_BUFFER_ADDR_NBITS => 10, + TX_MTU => MTU_SIZE, + TX_BUFFER => '0', + TX_BUFFER_ADDR_NBITS => 10, + MAC_CONTROL_PAUSE_ENABLE => '1', + SIMULATION => SIM_MODE) + port map ( + -- clocks and resets + clk => clk_156, + sync_reset => mac_sync_reset, + clk156g => clk_156, -- this clock is generated by the XAUI SerDes + -- MAC C&S + mac_tx_config => mac_tx_config, + mac_rx_config => mac_rx_config, + mac_addr => mac_addr, + -- PHY Configuration + phy_reset => '0', + test_mode => mac_test_mode, + power_down => mac_power_down, + phy_config_change => phy_config_change, + -- MAC status + n_tx_frames => n_tx_frames, + n_rx_frames => n_rx_frames, + n_rx_bad_crcs => n_rx_bad_crcs, + n_rx_frames_too_short => n_rx_frames_too_short, + n_rx_frames_too_long => n_rx_frames_too_long, + n_rx_wrong_addr => n_rx_wrong_addr, + n_rx_length_errors => n_rx_length_errors, + rx_ipg => rx_ipg, + -- PHY status + phy_status => phy_status, + phy_status2 => phy_status2, + phy_id => phy_id, + -- MAC Rx/Tx data ports + mac_tx_data => mac_tx_data, + mac_tx_data_valid => mac_tx_data_valid, + mac_tx_eof => mac_tx_eof, + mac_tx_cts => mac_tx_cts, + mac_rx_data => mac_rx_data, + mac_rx_data_valid => mac_rx_data_valid, + mac_rx_sof => mac_rx_sof, + mac_rx_eof => mac_rx_eof, + mac_rx_frame_valid => mac_rx_frame_valid, + mac_rx_cts => mac_rx_cts, + -- XGMII interface + xgmii_txd => xgmii_txd, + xgmii_txc => xgmii_txc, + xgmii_rxd => xgmii_rxd, + xgmii_rxc => xgmii_rxc, + -- PHY monitoring and control + reset_n => open, + /* + mdc => phy_mdc, + mdio_out => phy_mdio_out, + mdio_in => phy_mdio_in, + mdio_dir => phy_mdio_oe, + */ + -- Use the HPS-EMAC to configure the 10G-PHY + mdc => open, + mdio_out => open, + mdio_in => '0', + mdio_dir => open, + -- debug + debug1 => open, + debug2 => open, + debug3 => open, + tp => open); + + -- MAC-Tx-Configuration: Auto-Padding On, Add CRC On, raise error on frames + -- bigger than MTU size + mac_tx_config <= X"03"; + + -- MAC-Rx-Configuration: Promiscuous mode off, Accept Broadcast packets, Accept + -- Multi-Cast packets, raise error on frames bigger than MTU size + -- Note: in com5501.vhd (Software Revision 0), there is a comment + -- specifying: "..use 0x0F when interfacing with COM-5502 IP/UDP/TCP stack." + -- This is probably incorrect cause mac_rx_config(3) is unused + mac_rx_config <= X"16"; + + -- Generate a synchronous reset to the MAC + mac_async_reset <= '1' when reset_n_i = '0' or init = '1' or xaui_tx_ready = '0' or xaui_rx_ready = '0' else '0'; + + iSYNC_MAC_RST : entity work.sync_wire + port map('1', clk_156, mac_async_reset, mac_sync_reset_i); + + -- The MAC synchronous reset pulse must be at least 400 ns; + pGEN_MAC_RST: process(clk_156) + begin + if(clk_156 = '1' and clk_156'event) then + if(mac_sync_reset_i = '1') then + mac_sync_reset <= '1'; + rst_cnt <= (others => '1'); + elsif(unsigned(rst_cnt) /= 0) then + rst_cnt <= std_logic_vector(unsigned(rst_cnt) - 1); + else + mac_sync_reset <= '0'; + end if; + end if; + end process pGEN_MAC_RST; + + -- Generate the phy_config_change input to the MAC + pMAC_CONFIG_CHG: process(clk_156) + begin + if(clk_156 = '1' and clk_156'event) then + mac_power_down_d <= mac_power_down; + mac_test_mode_d <= mac_test_mode; + if((mac_power_down xor mac_power_down_d) = '1' or (mac_test_mode /= mac_test_mode_d)) then + phy_config_change <= '1'; + else + phy_config_change <= '0'; + end if; + end if; + end process pMAC_CONFIG_CHG; + + + ----------------------------------------------------------------------------- + -- MAC Diagnostic registers + ----------------------------------------------------------------------------- + + -- MAC diagnostic registers are multiplexed to reduce the logic resources, + -- especially in relation to the clock-crossing to the Avalon CSR clock + -- domain + pMAC_STATUS_MUX : process(all) + begin + case mac_status_addr_i(2 downto 0) is + when b"000" => + mac_status_val <= n_tx_frames; + when b"001" => + mac_status_val <= n_rx_frames; + when b"010" => + mac_status_val <= n_rx_bad_crcs; + when b"011" => + mac_status_val <= n_rx_length_errors; + when b"100" => + mac_status_val <= n_rx_frames_too_short; + when b"101" => + mac_status_val <= n_rx_frames_too_long; + when b"110" => + mac_status_val <= n_rx_wrong_addr; + when b"111" => + mac_status_val <= X"00" & rx_ipg; + when others => null; + end case; + end process pMAC_STATUS_MUX; + + + ----------------------------------------------------------------------------- + -- MAC Loopback Switch + ----------------------------------------------------------------------------- + + -- the switch is used for testing the data-path: MAC XGMII Tx interface is + -- looped back to the MAC XGMII Rx interface, excluding the XAUI transceivers + pMAC_LOOPBACK: process(clk_156) + begin + if(clk_156 = '1' and clk_156'event) then + if(mac_loopback_en = '0') then + xgmii_rxd <= xgmii_rxd_xaui; + xgmii_rxc <= xgmii_rxc_xaui; + else + xgmii_rxd <= xgmii_txd; + xgmii_rxc <= xgmii_txc; + end if; + end if; + end process pMAC_LOOPBACK; + + ----------------------------------------------------------------------------- + -- PHY interface: XGMII to XAUI interface + ----------------------------------------------------------------------------- + + -- Notes: + -- XAUI PHY Register interface: disabled to reduces resources utilization + + gPHY_SERIAL_ITF: if SIM_MODE = '0' generate + + iPHY_SERIAL_ITF: entity work.xaui_phy_itf + port map ( + pll_ref_clk => xaui_ref_clk, + xgmii_tx_clk => clk_156, + xgmii_rx_clk => clk_156, + xgmii_rx_dc => xgmii_rx_dc, + xgmii_tx_dc => xgmii_tx_dc, + xaui_rx_serial_data => xaui_rx, + xaui_tx_serial_data => xaui_tx, + rx_ready => xaui_rx_ready_i, + tx_ready => xaui_tx_ready_i); + + clk_156_out <= clk_156; + + -- XAUI-PHY needs xgmii data and control bits interleaved + gxmii_remap: for j in 0 to 7 generate + + xgmii_tx_dc( 7+j+8*j downto j+8*j) <= xgmii_txd(7+8*j downto 8*j); + xgmii_tx_dc(8*j+8+j) <= xgmii_txc(j); + -- + xgmii_rxd_xaui(7+8*j downto 8*j) <= xgmii_rx_dc( 7+j+8*j downto j+8*j); + xgmii_rxd_xaui(j) <= xgmii_rx_dc(8*j+8+j); + + end generate gxmii_remap; + + -- For safety, synchronize the ready status signals from the PHY to the Avalon bus clock, + -- cause it is not clear from Intel documentation to which clock domain they + -- belong + iSYNC_TX_RDY : entity work.sync_wire + port map(reset_n_i, clk_156, xaui_tx_ready_i, xaui_tx_ready); + + iSYNC_RX_RDY : entity work.sync_wire + port map(reset_n_i, clk_156, xaui_rx_ready_i, xaui_rx_ready); + + else generate + -- SIM_MODE = '1' + + --pragma translate_off + + clk_156 <= xaui_ref_clk; + + clk_156_out <= clk_156; + + xaui_tx_ready <= reset_n_i; + + xaui_rx_ready <= reset_n_i; + + -- xaui_tx <= (others => '0'); + xaui_tx (63 downto 0) <= xgmii_txd; + xaui_tx (71 downto 64) <= xgmii_txc; + + xgmii_rxd_xaui <= xaui_rx(63 downto 0); + xgmii_rxc_xaui <= xaui_rx(71 downto 64); + + --pragma translate_on + + end generate gPHY_SERIAL_ITF; + + ----------------------------------------------------------------------------- + -- Rx-Data Split: buffers rx-data from the MAC, identifies the destination of + -- the packet + ----------------------------------------------------------------------------- + + iPKT_SPLIT : entity work.rx_packet_split_0 + port map ( + clk => clk_156, + reset_n => reset_n, + init => init, + cfg_addr => filt_cfg_addr, + cfg_data => filt_cfg_data, + cfg_write => filt_cfg_write, + filt_len => filt_cfg_len, + rx_data_in => mac_rx_data, + rx_data_valid_in => mac_rx_data_valid, + rx_sop_in => mac_rx_sof, + rx_eop_in => mac_rx_eof, + rx_frame_valid_in => mac_rx_frame_valid, + rx_cts_in => mac_rx_cts, + packet_dest => rx_packet_dest, + rx_data_out => rx_data, + rx_data_valid_out => rx_data_valid, + rx_sof_out => rx_sof, + rx_eof_out => rx_eof, + rx_frame_valid_out => rx_frame_valid, + rx_rts_out => rx_rts, + rx_cts_out => rx_cts); + + -- The TCP Server is always available to accept new packets + rx_cts <= gmii_rx_cts when rx_packet_dest = '0' else '1'; + + + ----------------------------------------------------------------------------- + -- GMII Rx Bridge + ----------------------------------------------------------------------------- + + iGMII_RX_BRG: entity work.gmii_rx_bridge_0 + port map ( + clk => clk_156, + gmii_clk => gmii_rx_clk, + init => init, + fifo_afull_flag => fifo_afull_flag, + clr_fifo_afull_flag => clr_fifo_afull_flag, + packet_dest => rx_packet_dest, + rx_data => rx_data, + rx_data_valid => rx_data_valid, + rx_sof => rx_sof, + rx_eof => rx_eof, + rx_rts => rx_rts, + rx_cts => gmii_rx_cts, + gmii_rx_clk => gmii_rx_clk, + gmii_rx_rxdv => gmii_rx_rxdv, + gmii_rx_rxer => gmii_rx_rxer, + gmii_rx_rxd => gmii_rx_rxd); + + -- this signal actually need to be properly connected to the CSR interface at + -- some point + clr_fifo_afull_flag <= '0'; + + ----------------------------------------------------------------------------- + -- Tx-Data combine: combine together frames to be transmitted by the MAC + ----------------------------------------------------------------------------- + + iTX_COMBINE: entity work.tx_packet_combine_0 + port map ( + clk => clk_156, + reset_n => reset_n, + init => init, + toe_tx_data => toe_tx_data, + toe_tx_data_valid => toe_tx_data_valid, + toe_tx_sop => toe_tx_sof, + toe_tx_eop => toe_tx_eof, + toe_tx_cts => toe_tx_cts, + toe_tx_rts => toe_tx_rts, + emac_tx_data => emac_tx_data, + emac_tx_data_valid => emac_tx_data_valid, + emac_tx_sop => emac_tx_sof, + emac_tx_eop => emac_tx_eof, + emac_tx_cts => emac_tx_cts, + emac_tx_rts => emac_tx_rts, + mac_tx_data => mac_tx_data, + mac_tx_data_valid => mac_tx_data_valid, + mac_tx_eof => mac_tx_eof, + mac_tx_cts => mac_tx_cts); + + ----------------------------------------------------------------------------- + -- GMII Tx Bridge + ----------------------------------------------------------------------------- + + iGMII_TX_BRG: entity work.gmii_tx_bridge_0 + generic map ( + MTU_SIZE => MTU_SIZE, + PREAMBLE_LEN => PREAMBLE_LEN) + port map ( + clk => clk_156, + init => init, + buffer_ovfl_flag => tx_brg_buffer_ovfl_flag, + clr_buffer_ovfl_flag => tx_brg_clr_buffer_ovfl_flag, + buffer_level => tx_brg_buffer_level, + discarded_packets => tx_brg_disc_packets, + gmii_tx_clk => gmii_tx_clk, + gmii_txen => gmii_txen, + gmii_txer => gmii_txer, + gmii_txd => gmii_txd, + tx_data => emac_tx_data, + tx_data_valid => emac_tx_data_valid, + tx_sof => emac_tx_sof, + tx_eof => emac_tx_eof, + tx_rts => emac_tx_rts, + tx_cts => emac_tx_cts); + + -- same 125 MHz clock derived from the 10G PHY recovered clock + gmii_tx_clk <= gmii_rx_clk; + + ----------------------------------------------------------------------------- + -- HPS-EMAC interface + ----------------------------------------------------------------------------- + + -- PHY Serial configuration port + phy_mdio_out <= hps_emac_gmii_mdo; + phy_mdio_oe <= hps_emac_gmii_mdo_oe; + phy_mdc <= hps_emac_md_clk; + hps_emac_gmii_mdi <= phy_mdio_in; + + -- GMII Rx interface + hps_emac_rx_clk <= gmii_rx_clk; + hps_emac_phy_rxd <= gmii_rx_rxd; + hps_emac_phy_rxdv <= gmii_rx_rxdv; + hps_emac_phy_rxer <= gmii_rx_rxer; + + -- GMII Tx interface + hps_emac_tx_clk <= gmii_tx_clk; + gmii_txen <= hps_emac_phy_txen; + gmii_txer <= hps_emac_phy_txer; + gmii_txd <= hps_emac_phy_txd; + + ----------------------------------------------------------------------------- + -- TCP Server - ComBlock com5502 IP + ----------------------------------------------------------------------------- + + iTCP_SERVER: entity work.com5502 + generic map ( + NTCPSTREAMS => NTCPSTREAMS, + NUDPTX => 0, + NUDPRX => 0, + MTU => MTU_SIZE, + IPv6_ENABLED => '0', + DHCP_SERVER_EN => '0', + DHCP_CLIENT_EN => '0', + IGMP_EN => '0', + TX_IDLE_TIMEOUT => TX_IDLE_TIMEOUT, + TCP_KEEPALIVE_PERIOD => TCP_KEEPALIVE_PERIOD, + CLK_FREQUENCY => 156, + SIMULATION => SIM_MODE) + port map ( + clk => clk_156, + sync_reset => toe_sync_reset, + -- configuration + mac_addr => mac_addr, + dynamic_ipv4 => '0', + requested_ipv4_addr => ip_addr, + ipv4_multicast_addr => IPv4_MULTICAST_ADDR, + ipv4_subnet_mask => IPv4_SUBNET_MASK, + ipv4_gateway_addr => ip_gateway_addr, + ipv6_addr => (others => '0'), + ipv6_subnet_prefix_length => (others => '0'), + ipv6_gateway_addr => (others => '0'), + connection_reset => toe_conn_reset_v, + tcp_keepalive_en => tcp_keepalive_en_v, + dhcp_server_en2 => '0', + dhcp_server_ip_min_lsb => (others => '0'), + dhcp_server_nips => (others => '0'), + dhcp_server_lease_time => (others => '0'), + dhcp_router => (others => '0'), + dhcp_server_dns => (others => '0'), + -- MAC interface + mac_tx_data => toe_tx_data, + mac_tx_data_valid => toe_tx_data_valid, + mac_tx_sof => toe_tx_sof, + mac_tx_eof => toe_tx_eof, + mac_tx_cts => toe_tx_cts, + mac_tx_rts => toe_tx_rts, + mac_rx_data => toe_rx_data, + mac_rx_data_valid => toe_rx_data_valid, + mac_rx_sof => toe_rx_sof, + mac_rx_eof => toe_rx_eof, + mac_rx_frame_valid => toe_rx_frame_valid, + -- UDP interface + udp_rx_data => open, + udp_rx_data_valid => open, + udp_rx_sof => open, + udp_rx_eof => open, + udp_rx_frame_valid => open, + udp_rx_dest_port_no_in => (others => '0'), + check_udp_rx_dest_port_no => '0', + udp_rx_dest_port_no_out => open, + udp_tx_data => (others => '0'), + udp_tx_data_valid => (others => '0'), + udp_tx_sof => '0', + udp_tx_eof => '0', + udp_tx_cts => open, + udp_tx_ack => open, + udp_tx_nak => open, + udp_tx_dest_ip_addr => (others => '0'), + udp_tx_dest_ipv4_6n => '0', + udp_tx_dest_port_no => (others => '0'), + udp_tx_source_port_no => (others => '0'), + -- TCP interface + tcp_local_ports => tcp_local_ports, + tcp_rx_data => tcp_rx_data_v, + tcp_rx_data_valid => tcp_rx_data_valid_v, + tcp_rx_rts => tcp_rx_rts_v, + tcp_rx_cts => tcp_rx_cts_v, + tcp_rx_cts_ack => tcp_rx_cts_ack_v, + tcp_tx_data => (others => tcp_tx_data), + tcp_tx_data_valid => (others => tcp_tx_data_valid), + tcp_tx_data_flush => tcp_tx_data_flush_v, + tcp_tx_cts => tcp_tx_cts_v, + tcp_connected_flag => tcp_connected_flag_v, + CS1 => open, + CS1_CLK => open, + CS2 => open, + CS2_CLK => open, + DEBUG1 => open, + DEBUG2 => open, + DEBUG3 => open, + TP => open); + + -- use the MAC reset also for the TCP Server + toe_sync_reset <= mac_sync_reset; + + toe_rx_data <= rx_data; + toe_rx_data_valid <= rx_data_valid; + toe_rx_sof <= rx_sof and rx_packet_dest; + toe_rx_eof <= rx_eof and rx_packet_dest; + toe_rx_frame_valid <= rx_frame_valid and rx_packet_dest; + + + + tcp_local_ports(0) <= tcp_local_port; + + toe_conn_reset_v(0) <= tcp_conn_reset; + tcp_keepalive_en_v(0) <= tcp_keepalive_en; + + tcp_connected_flag <= tcp_connected_flag_v(0); + + tcp_rx_data <= tcp_rx_data_v(0); + tcp_rx_data_valid <= tcp_rx_data_valid_v(0); + tcp_rx_rts <= tcp_rx_rts_v(0); + tcp_rx_cts_v(0) <= tcp_rx_cts; + tcp_rx_cts_ack <= tcp_rx_cts_ack_v(0); + -- + tcp_tx_cts <= tcp_tx_cts_v(0); + -- + tcp_tx_data_flush_v(0) <= tcp_tx_data_flush; + + ----------------------------------------------------------------------------- + -- Test Pattern Generation and Checking + ----------------------------------------------------------------------------- + + gTPG : if TPG_ENABLED generate + iTPG: entity work.tcp_tpg_0 + generic map ( + SEED => TPG_SEED) + port map ( + clk => clk_156, + init => init, + gen_start => tpg_start, + gen_stop => tpg_stop, + burst_size => tpg_burst_size, + burst_gap => tpg_burst_gap, + tx_data => tcp_tx_data, + tx_data_valid => tcp_tx_data_valid, + tx_data_flush => tcp_tx_data_flush, + tx_cts => tcp_tx_cts); + + iTPC: entity work.tcp_tpc_0 + generic map ( + SEED => TPG_SEED) + port map ( + clk => clk_156, + init => init, + check_start => tpc_start, + check_stop => tpc_stop, + word_errors => tpc_errors, + rx_data => tcp_rx_data, + rx_data_valid => tcp_rx_data_valid, + rx_rts => tcp_rx_rts, + rx_cts => tcp_rx_cts, + rx_cts_ack => tcp_rx_cts_ack); + else generate + + tcp_tx_data_flush <= '0'; + tcp_tx_data_valid <= (others => '0'); + + end generate; + + ----------------------------------------------------------------------------- + -- Miscellanea + ----------------------------------------------------------------------------- + + -- Generate a 10 ms hardware reset to the Marvell PHY + pPHY_RST_GEN: process(clk_156) + begin + if(clk_156 = '1' and clk_156'event) then + if(phy_reset_start = '1') then + gen_phy_reset <= '1'; + elsif(phy_rst_cnt_tc = '1') then + gen_phy_reset <= '0'; + end if; + if(init = '1' or phy_reset_start = '1') then + phy_reset_done <= '0'; + elsif(phy_rst_cnt_tc = '1') then + phy_reset_done <= '1'; + end if; + if(gen_phy_reset = '0') then + phy_rst_cnt <= (others => '0'); + else + phy_rst_cnt <= std_logic_vector(unsigned(phy_rst_cnt)+1); + end if; + end if; + end process pPHY_RST_GEN; + + phy_reset_n <= not gen_phy_reset; + + phy_rst_cnt_tc <= '1' when unsigned(phy_rst_cnt) = PHY_HW_RESET_LEN-1 else '0'; + + --PTP + hps_emac_ptp_aux_ts_trig <= '0'; + hps_emac_ptp_ref_clock <= tod_pclk; + + ----------------------------------------------------------------------------- + -- C&S registers (Avalon-MM I/F) + ----------------------------------------------------------------------------- + + iCSR_AUTO: entity work.xgbe_oe_0_csr_regs + generic map ( + ADDR_DECODE_WIDTH => 5) + port map ( + clk => clk_avs, + rst_n => reset_n_avs, + xgbe_oe_ctrl_init => init_i, + xgbe_oe_ctrl_PHY_reset_start => phy_reset_start_i, + xgbe_oe_ctrl_mac_loopback_en => mac_loopback_en, + xgbe_oe_ctrl_mac_power_down => mac_power_down, + xgbe_oe_ctrl_mac_test_mode => mac_test_mode, + xgbe_oe_ctrl_tcp_connection_reset => tcp_conn_reset_i, + xgbe_oe_ctrl_tcp_keepalive_en => tcp_keepalive_en, + xgbe_oe_status_PHY_reset_done => phy_reset_done_i, + xgbe_oe_status_PHY_rclk_locked => phy_rclk0_locked, + xgbe_oe_status_xaui_tx_ready => xaui_tx_ready, + xgbe_oe_status_xaui_rx_ready => xaui_rx_ready, + xgbe_oe_status_tcp_connected_flag => tcp_connected_flag, + mac_address_0 => mac_addr(31 downto 0), + mac_address_1 => mac_addr(47 downto 32), + ipv4_addr => ip_addr, + ipv4_gateway_addr => ip_gateway_addr, + tcp_local_port => tcp_local_port, + pkt_split_cfg_wr_ctrl_wr_addr => filt_cfg_addr, + pkt_split_cfg_wr_ctrl_wr_en => filt_cfg_write_i, + pkt_split_cfg_wr_done => filt_cfg_wr_done_i, + pkt_split_cfg_wr_data => filt_cfg_data, + pkt_split_cfg_wr_ctrl_filt_len => filt_cfg_len, + mac_status_rd_ctrl_read_req => mac_status_read_req_i, + mac_status_rd_ctrl_reg_ptr => mac_status_addr_i, + mac_status_rd_value_reg_rdy => mac_status_rdy_i, + mac_status_rd_value_reg_value => mac_status_val_i, + gmii_tx_brg_ctrl_clr_buf_ovfl_flag => tx_brg_clr_buffer_ovfl_flag_i, + gmii_tx_brg_ctrl_disc_stat_rd_req => tx_brg_disc_stat_rd_req_i, + gmii_tx_brg_stat_buf_ovfl_flag => tx_brg_buffer_ovfl_flag_i, + gmii_tx_brg_stat_disc_stat_rdy => tx_brg_disc_stat_rdy_i, + gmii_tx_brg_stat_disc_packets => tx_brg_disc_packets_i, + tpg_ctrl_tpg_start => tpg_start_i, + tpg_ctrl_tpg_stop => tpg_stop_i, + tpg_ctrl_tpg_burst_size => tpg_burst_size, + tpg_ctrl_tpg_burst_gap => tpg_burst_gap, + tpc_ctrl_tpc_start => tpc_start_i, + tpc_ctrl_tpc_stop => tpc_stop_i, + tpc_ctrl_tpc_poll_error_req => tpc_poll_error_req_i, + tpc_status_tpc_errors_is_valid => tpc_errors_is_valid_i, + tpc_status_tpc_errors => tpc_errors_i, + avs_address => avs_address, + avs_write => avs_write, + avs_writedata => avs_writedata, + avs_read => avs_read, + avs_readdata => avs_readdata); + + ----------------------------------------------------------------------------- + -- Control & Status Synchronization logic + ----------------------------------------------------------------------------- + + -- The avalon interface works at a different clock then the internal logic. + -- The vast majority of control signals are static, in the sense that they + -- are set before the logic start processing, and not changed after that, + -- therefore synchronization is not necessary for those. + -- Regarding diagnostic registers, the value is latched before being read. + -- All the others are manually synchronized + + iSyncResetAvs : entity work.sync_reset + port map ( + async_rstN => reset_n, + clk => clk_avs, + sync_rstN => reset_n_avs); + + -- Stretch pulses to make sure they last enough clock cycles to perform clock + -- crossing + pSTRETCH_PULSES: process(clk_avs) + begin + if(clk_avs = '1' and clk_avs'event) then + if(init_i = '1') then + init_v <= (others => '1'); + else + init_v <= '0' & init_v(init_v'left downto 1); + end if; + if(phy_reset_start_i = '1') then + phy_reset_start_v <= (others => '1'); + else + phy_reset_start_v <= '0' & phy_reset_start_v(phy_reset_start_v'left downto 1); + end if; + if(filt_cfg_write_i = '1') then + filt_cfg_write_v <= (others => '1'); + else + filt_cfg_write_v <= '0' & filt_cfg_write_v(filt_cfg_write_v'left downto 1); + end if; + if(tpg_start_i = '1') then + tpg_start_v <= (others => '1'); + else + tpg_start_v <= '0' & tpg_start_v(tpg_start_v'left downto 1); + end if; + if(tpg_stop_i = '1') then + tpg_stop_v <= (others => '1'); + else + tpg_stop_v <= '0' & tpg_stop_v(tpg_stop_v'left downto 1); + end if; + if(tpc_start_i = '1') then + tpc_start_v <= (others => '1'); + else + tpc_start_v <= '0' & tpc_start_v(tpc_start_v'left downto 1); + end if; + if(tpc_stop_i = '1') then + tpc_stop_v <= (others => '1'); + else + tpc_stop_v <= '0' & tpc_stop_v(tpc_stop_v'left downto 1); + end if; + if(init_i = '1' or tpc_poll_error_req_i = '1') then + tpc_errors_is_valid_i <= '0'; + elsif(set_tpc_errors_is_valid_i = '1') then + tpc_errors_is_valid_i <= '1'; + end if; + if(init_i = '1' or filt_cfg_write_i = '1') then + filt_cfg_wr_done_i <= '0'; + elsif(set_filt_cfg_wr_done_i = '1') then + filt_cfg_wr_done_i <= '1'; + end if; + if(mac_status_read_req_i = '1') then + mac_status_read_req_v <= (others => '1'); + else + mac_status_read_req_v <= '0' & mac_status_read_req_v(mac_status_read_req_v'left downto 1); + end if; + if(init_i = '1' or mac_status_read_req_i = '1') then + mac_status_rdy_i <= '0'; + elsif(set_mac_status_rdy_i = '1') then + mac_status_rdy_i <= '1'; + end if; + if(tx_brg_clr_buffer_ovfl_flag_i = '1') then + tx_brg_clr_buffer_ovfl_flag_v <= (others => '1'); + else + tx_brg_clr_buffer_ovfl_flag_v <= '0' & tx_brg_clr_buffer_ovfl_flag_v(tx_brg_clr_buffer_ovfl_flag_v'left downto 1); + end if; + if(tx_brg_disc_stat_rd_req_i = '1') then + tx_brg_disc_stat_rd_req_v <= (others => '1'); + else + tx_brg_disc_stat_rd_req_v <= '0' & tx_brg_disc_stat_rd_req_v(tx_brg_disc_stat_rd_req_v'left downto 1); + end if; + if(init_i = '1' or tx_brg_disc_stat_rd_req_i = '1') then + tx_brg_disc_stat_rdy_i <= '0'; + elsif(set_tx_brg_disc_stat_rdy_i = '1') then + tx_brg_disc_stat_rdy_i <= '1'; + end if; + end if; + end process pSTRETCH_PULSES; + + -- Latch registers in the 156.25 MHz domain, whenever necessary to allow the + -- signal to be stable before clock crossing + pSYNC_REGs_156 : process(clk_156) + begin + if(clk_156 = '1' and clk_156'event) then + tpc_poll_error_req_d <= tpc_poll_error_req; + if(tpc_poll_error_req_d = '1') then + tpc_errors_is_valid_v <= (others => '1'); + else + tpc_errors_is_valid_v <= '0' & tpc_errors_is_valid_v(tpc_errors_is_valid_v'left downto 1); + end if; + filt_cfg_write_d <= filt_cfg_write; + if(filt_cfg_write_d = '1') then + filt_cfg_done_v <= (others => '1'); + else + filt_cfg_done_v <= '0' & filt_cfg_done_v(filt_cfg_done_v'left downto 1); + end if; + if(mac_status_read_req = '1') then + mac_status_rdy_v <= (others => '1'); + else + mac_status_rdy_v <= '0' & mac_status_rdy_v(mac_status_rdy_v'left downto 1); + end if; + if(tx_brg_disc_stat_rd_req = '1') then + tx_brg_disc_stat_rdy_v <= (others => '1'); + else + tx_brg_disc_stat_rdy_v <= '0' & tx_brg_disc_stat_rdy_v(tx_brg_disc_stat_rdy_v'left downto 1); + end if; + end if; + end process pSYNC_REGs_156; + + iSYNC_INIT: entity work.sync_wire + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => init_v(0), sync_out => init); + + iSYNC_PHY_RST_START: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => phy_reset_start_v(0), sync_out => phy_reset_start); + + iSYNC_PHY_RST_DONE: entity work.sync_wire + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_avs, clk => clk_avs, async_in => phy_reset_done, sync_out => phy_reset_done_i); + + iSYNC_TCP_CONN_RST: entity work.sync_wire + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => tcp_conn_reset_i, sync_out => tcp_conn_reset); + + iSYNC_FILT_CFG_WR_EN: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => filt_cfg_write_v(0), sync_out => filt_cfg_write); + + iSYNC_FILT_CFG_WR_DONE: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_avs, clk => clk_avs, async_in => filt_cfg_done_v(0), sync_out => set_filt_cfg_wr_done_i); + + iSYNC_TPG_START: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => tpg_start_v(0), sync_out => tpg_start); + + iSYNC_TPG_STOP: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => tpg_stop_v(0), sync_out => tpg_stop); + + iSYNC_TPC_START: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => tpc_start_v(0), sync_out => tpc_start); + + iSYNC_TPC_STOP: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => tpc_stop_v(0), sync_out => tpc_stop); + + iSYNC_TPC_ERROR_POLL: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => tpc_poll_error_req_i, sync_out => tpc_poll_error_req); + + iSYNC_TPC_ERROR_VALID: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_avs, clk => clk_avs, async_in => tpc_errors_is_valid_v(0), sync_out => set_tpc_errors_is_valid_i); + + iSYNC_MAC_STAT_REQ: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => mac_status_read_req_v(0), sync_out => mac_status_read_req); + + iSYNC_MAC_STAT_RDY: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_avs, clk => clk_avs, async_in => mac_status_rdy_v(0), sync_out => set_mac_status_rdy_i); + + iSYNC_CLR_OVFL: entity work.sync_wire + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_avs, clk => clk_156, async_in => tx_brg_clr_buffer_ovfl_flag_v(0), sync_out => tx_brg_clr_buffer_ovfl_flag); + + iSYNC_DISCP_REQ: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_i, clk => clk_156, async_in => tx_brg_disc_stat_rd_req_v(0), sync_out => tx_brg_disc_stat_rd_req); + + iSYNC_BRG_STAT_RDY: entity work.sync_wire_redge + generic map (rst_val => '0', sync_stages => 3) + port map (rstN => reset_n_avs, clk => clk_avs, async_in => tx_brg_disc_stat_rdy_v(0), sync_out => set_tx_brg_disc_stat_rdy_i); + + + -- Latching the status ensures the register value is stable before being clock crossing + pSTATUS_LATCH : process(clk_156) + begin + if(clk_156 = '1' and clk_156'event) then + if(tpc_poll_error_req = '1') then + tpc_errors_i <= tpc_errors; + end if; + if(mac_status_read_req = '1') then + mac_status_val_i <= mac_status_val; + end if; + if(tx_brg_disc_stat_rd_req = '1') then + tx_brg_disc_packets_i <= tx_brg_disc_packets; + end if; + end if; + end process pSTATUS_LATCH; + + +end architecture rtl; diff --git a/generic_ip/xgbe_oe/0/src/xgbe_oe_0_pkg.vhd b/generic_ip/xgbe_oe/0/src/xgbe_oe_0_pkg.vhd new file mode 100644 index 0000000..eacd0e3 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/xgbe_oe_0_pkg.vhd @@ -0,0 +1,42 @@ +------------------------------------------------------------------------------- +-- Title : xgbe_oe_0_pkg +-- Project : 10G +------------------------------------------------------------------------------- +-- File : xgbe_oe_0_pkg.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2020-02-14 +-- Last update: 2020-06-15 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Package for xgbe_oe_0 +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +package xgbe_oe_0_pkg is + + constant XAUI_STATUS_REG : std_logic_vector(4 downto 0) := 5x"00"; + constant MAC_ADDR_REG_1 : std_logic_vector(4 downto 0) := 5x"01"; + constant MAC_ADDR_REG_2 : std_logic_vector(4 downto 0) := 5x"02"; + constant MAC_CTRL_REG : std_logic_vector(4 downto 0) := 5x"03"; + constant MAC_STATUS_REG_1 : std_logic_vector(4 downto 0) := 5x"04"; + constant MAC_STATUS_REG_2 : std_logic_vector(4 downto 0) := 5x"05"; + constant MAC_STATUS_REG_3 : std_logic_vector(4 downto 0) := 5x"06"; + constant MAC_STATUS_REG_4 : std_logic_vector(4 downto 0) := 5x"07"; + constant PHY_STATUS_REG : std_logic_vector(4 downto 0) := 5x"08"; + constant TX_FRAME_CTRL_REG : std_logic_vector(4 downto 0) := 5x"09"; + constant TX_FIFO_P1_REG : std_logic_vector(4 downto 0) := 5x"0A"; + constant TX_FIFO_P2_REG : std_logic_vector(4 downto 0) := 5x"0B"; + constant TX_FIFO_P3_REG : std_logic_vector(4 downto 0) := 5x"0C"; + constant RX_FRAME_CTRL_REG : std_logic_vector(4 downto 0) := 5x"0D"; + constant RX_FIFO_P1_REG : std_logic_vector(4 downto 0) := 5x"0E"; + constant RX_FIFO_P2_REG : std_logic_vector(4 downto 0) := 5x"0F"; + constant RX_FIFO_P3_REG : std_logic_vector(4 downto 0) := 5x"10"; + +end package xgbe_oe_0_pkg;