SURF  1.0
IpV4EngineDeMux.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : IpV4EngineDeMux.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-08-12
5 -- Last update: 2016-09-16
6 -------------------------------------------------------------------------------
7 -- Description: IPv4 AXIS DEMUX module
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 use ieee.std_logic_unsigned.all;
21 use ieee.std_logic_arith.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiStreamPkg.all;
25 use work.SsiPkg.all;
26 use work.EthMacPkg.all;
27 
28 --! @see entity
29  --! @ingroup ethernet_IpV4Engine
30 entity IpV4EngineDeMux is
31  generic (
32  TPD_G : time := 1 ns;
33  VLAN_G : boolean := false);
34  port (
35  -- Local Configurations
36  localMac : in slv(47 downto 0); -- big-Endian configuration
37  -- Slave
40  -- Masters
45  -- Clock and Reset
46  clk : in sl;
47  rst : in sl);
48 end IpV4EngineDeMux;
49 
50 architecture rtl of IpV4EngineDeMux is
51 
52  constant BROADCAST_MAC_C : slv(47 downto 0) := (others => '1');
53 
54  type StateType is (
55  IDLE_S,
56  CHECK_S,
57  MOVE_S);
58 
59  type RegType is record
60  arpSel : sl;
61  ipv4Sel : sl;
62  dly : AxiStreamMasterType;
66  state : StateType;
67  end record RegType;
68 
69  constant REG_INIT_C : RegType := (
70  arpSel => '0',
71  ipv4Sel => '0',
76  state => IDLE_S);
77 
78  signal r : RegType := REG_INIT_C;
79  signal rin : RegType;
80 
81 begin
82 
83  comb : process (ibArpSlave, ibIpv4Slave, localMac, obMacMaster, r, rst) is
84  variable v : RegType;
85  begin
86  -- Latch the current value
87  v := r;
88 
89  -- Reset strobing signals
90  v.obMacSlave.tReady := '0';
91  if ibArpSlave.tReady = '1' then
92  v.ibArpMaster.tValid := '0';
93  end if;
94  if ibIpv4Slave.tReady = '1' then
95  v.ibIpv4Master.tValid := '0';
96  end if;
97 
98  -- Check if there is data to move
99  if (obMacMaster.tValid = '1') and (v.ibArpMaster.tValid = '0') and (v.ibIpv4Master.tValid = '0') then
100  ----------------------------------------------------------------------
101  -- Checking for non-VLAN
102  ----------------------------------------------------------------------
103  if (VLAN_G = false) then
104  -- Accept for data
105  v.obMacSlave.tReady := '1';
106  -- Check for SOF and not EOF
107  if (ssiGetUserSof(EMAC_AXIS_CONFIG_C, obMacMaster) = '1') and (obMacMaster.tLast = '0') then
108  -- Reset the flags
109  v.arpSel := '0';
110  v.ipv4Sel := '0';
111  -- Check for a valid ARP EtherType
112  if (obMacMaster.tData(111 downto 96) = ARP_TYPE_C) then
113  -- Check the destination MAC address
114  if(obMacMaster.tData(47 downto 0) = BROADCAST_MAC_C) or (obMacMaster.tData(47 downto 0) = localMac) then
115  v.arpSel := '1';
117  end if;
118  -- Check for a valid IPV4 EtherType and (IPVersion + Header length)
119  elsif (obMacMaster.tData(111 downto 96) = IPV4_TYPE_C) and (obMacMaster.tData(119 downto 112) = x"45") then
120  -- Check the destination MAC address
121  if(obMacMaster.tData(47 downto 0) = BROADCAST_MAC_C) or (obMacMaster.tData(47 downto 0) = localMac) then
122  v.ipv4Sel := '1';
124  end if;
125  end if;
126  elsif r.arpSel = '1' then
128  elsif r.ipv4Sel = '1' then
130  end if;
131  if obMacMaster.tLast = '1' then
132  -- Reset the flags
133  v.arpSel := '0';
134  v.ipv4Sel := '0';
135  end if;
136  ----------------------------------------------------------------------
137  -- Checking for VLAN
138  ----------------------------------------------------------------------
139  else
140  -- State Machine
141  case r.state is
142  ----------------------------------------------------------------------
143  when IDLE_S =>
144  -- Accept for data
145  v.obMacSlave.tReady := '1';
146  -- Check for SOF and not EOF
147  if (ssiGetUserSof(EMAC_AXIS_CONFIG_C, obMacMaster) = '1') and (obMacMaster.tLast = '0') then
148  -- Check for a valid VLAN EtherType
149  if (obMacMaster.tData(111 downto 96) = VLAN_TYPE_C) then
150  -- Reset the flags
151  v.arpSel := '0';
152  v.ipv4Sel := '0';
153  -- Latch the data bus
154  v.dly := obMacMaster;
155  -- Next state
156  v.state := CHECK_S;
157  end if;
158  end if;
159  ----------------------------------------------------------------------
160  when CHECK_S =>
161  -- Check for a valid ARP EtherType
162  if (obMacMaster.tData(15 downto 0) = ARP_TYPE_C) then
163  -- Check the destination MAC address
164  if(r.dly.tData(47 downto 0) = BROADCAST_MAC_C) or (r.dly.tData(47 downto 0) = localMac) then
165  v.arpSel := '1';
166  v.ibArpMaster := r.dly;
167  end if;
168  -- Check for a valid IPV4 EtherType and (IPVersion + Header length)
169  elsif (obMacMaster.tData(15 downto 0) = IPV4_TYPE_C) and (obMacMaster.tData(23 downto 16) = x"45") then
170  -- Check the destination MAC address
171  if(r.dly.tData(47 downto 0) = BROADCAST_MAC_C) or (r.dly.tData(47 downto 0) = localMac) then
172  v.ipv4Sel := '1';
173  v.ibIpv4Master := r.dly;
174  end if;
175  end if;
176  -- Next state
177  v.state := MOVE_S;
178  ----------------------------------------------------------------------
179  when MOVE_S =>
180  -- Accept for data
181  v.obMacSlave.tReady := '1';
182  if r.arpSel = '1' then
184  elsif r.ipv4Sel = '1' then
186  end if;
187  if obMacMaster.tLast = '1' then
188  -- Next state
189  v.state := IDLE_S;
190  end if;
191  ----------------------------------------------------------------------
192  end case;
193  end if;
194  end if;
195 
196  -- Reset
197  if (rst = '1') then
198  v := REG_INIT_C;
199  end if;
200 
201  -- Register the variable for next clock cycle
202  rin <= v;
203 
204  -- Outputs
205  obMacSlave <= v.obMacSlave;
208 
209  end process comb;
210 
211  seq : process (clk) is
212  begin
213  if (rising_edge(clk)) then
214  r <= rin after TPD_G;
215  end if;
216  end process seq;
217 
218 end rtl;
VLAN_Gboolean := false
std_logic sl
Definition: StdRtlPkg.vhd:28
slv( 15 downto 0) := x"0008" IPV4_TYPE_C
Definition: EthMacPkg.vhd:35
AxiStreamMasterType :=(tValid => '0',tData =>( others => '0'),tStrb =>( others => '1'),tKeep =>( others => '1'),tLast => '0',tDest =>( others => '0'),tId =>( others => '0'),tUser =>( others => '0')) AXI_STREAM_MASTER_INIT_C
in obMacMasterAxiStreamMasterType
out ibArpMasterAxiStreamMasterType
out ibIpv4MasterAxiStreamMasterType
out obMacSlaveAxiStreamSlaveType
slv( 15 downto 0) := x"0608" ARP_TYPE_C
Definition: EthMacPkg.vhd:34
slv( 127 downto 0) tData
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
TPD_Gtime := 1 ns
_library_ ieeeieee
Definition: IpV4Engine.vhd:18
slv( 15 downto 0) := x"0081" VLAN_TYPE_C
Definition: EthMacPkg.vhd:36
in localMacslv( 47 downto 0)
in ibArpSlaveAxiStreamSlaveType
in ibIpv4SlaveAxiStreamSlaveType
AxiStreamConfigType :=(TSTRB_EN_C => false,TDATA_BYTES_C => 16,TDEST_BITS_C => 8,TID_BITS_C => 0,TKEEP_MODE_C => TKEEP_COMP_C,TUSER_BITS_C => 4,TUSER_MODE_C => TUSER_FIRST_LAST_C) EMAC_AXIS_CONFIG_C
Definition: EthMacPkg.vhd:58
std_logic_vector slv
Definition: StdRtlPkg.vhd:29