SURF  1.0
RawEthFramerRx.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : RawEthFramerRx.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2016-05-23
5 -- Last update: 2016-05-26
6 -------------------------------------------------------------------------------
7 -- Description: Raw L2 Ethernet Framer's RX Engine
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.RawEthFramerPkg.all;
27 
28 --! @see entity
29  --! @ingroup ethernet_RawEthFramer
30 entity RawEthFramerRx is
31  generic (
32  TPD_G : time := 1 ns;
33  ETH_TYPE_G : slv(15 downto 0) := x"0010"); -- 0x1000 (big-Endian configuration)
34  port (
35  -- Local Configurations
36  localMac : in slv(47 downto 0); -- big-Endian configuration
37  remoteMac : in slv(47 downto 0); -- big-Endian configuration
38  tDest : out slv(7 downto 0);
39  req : out sl;
40  ack : in sl;
41  -- Interface to Ethernet Media Access Controller (MAC)
44  -- Interface to Application engine(s)
47  -- Clock and Reset
48  clk : in sl;
49  rst : in sl);
50 end RawEthFramerRx;
51 
52 architecture rtl of RawEthFramerRx is
53 
54  constant BC_MAC_C : slv(47 downto 0) := x"FFFFFFFFFFFF";
55 
56  type StateType is (
57  IDLE_S,
58  HDR_S,
59  TDEST_S,
60  MOVE_S);
61 
62  type RegType is record
63  bcf : sl;
64  req : sl;
65  dstMac : slv(47 downto 0);
66  srcMac : slv(47 downto 0);
67  minByteCnt : natural range 0 to 127;
68  sof : sl;
69  eof : sl;
70  eofe : sl;
73  state : StateType;
74  end record RegType;
75  constant REG_INIT_C : RegType := (
76  bcf => '0',
77  req => '0',
78  dstMac => (others => '0'),
79  srcMac => (others => '0'),
80  minByteCnt => 0,
81  sof => '1',
82  eof => '0',
83  eofe => '0',
86  state => IDLE_S);
87 
88  signal r : RegType := REG_INIT_C;
89  signal rin : RegType;
90 
91  -- attribute dont_touch : string;
92  -- attribute dont_touch of r : signal is "TRUE";
93 
94 begin
95 
96  comb : process (ack, ibAppSlave, localMac, obMacMaster, r, remoteMac, rst) is
97  variable v : RegType;
98  begin
99  -- Latch the current value
100  v := r;
101 
102  -- Reset the flags
104  if ibAppSlave.tReady = '1' then
105  v.ibAppMaster.tValid := '0';
106  v.ibAppMaster.tLast := '0';
107  v.ibAppMaster.tUser := (others => '0');
108  v.ibAppMaster.tKeep := x"00FF";
109  end if;
110 
111  -- State Machine
112  case r.state is
113  ----------------------------------------------------------------------
114  when IDLE_S =>
115  -- Check for data
116  if (obMacMaster.tValid = '1') then
117  -- Accept the data
118  v.obMacSlave.tReady := '1';
119  -- Latch the DST MAC and SRC MAC
120  v.dstMac := obMacMaster.tData(47 downto 0);
121  v.srcMac(15 downto 0) := obMacMaster.tData(63 downto 48);
122  -- Check for SOF
123  if (ssiGetUserSof(RAW_ETH_CONFIG_INIT_C, obMacMaster) = '1') then
124  -- Check the DEST MAC
125  if (localMac /= 0) and ((localMac = v.dstMac) or (v.dstMac = BC_MAC_C))then
126  -- Next state
127  v.state := HDR_S;
128  end if;
129  end if;
130  end if;
131  ----------------------------------------------------------------------
132  when HDR_S =>
133  -- Check for data
134  if (obMacMaster.tValid = '1') and (v.ibAppMaster.tValid = '0') then
135  -- Accept the data
136  v.obMacSlave.tReady := '1';
137  -- Latch the SRC MAC
138  v.srcMac(47 downto 16) := obMacMaster.tData(31 downto 0);
139  -- Latch the tDest & BC
140  v.ibAppMaster.tDest := obMacMaster.tData(63 downto 56);
141  v.bcf := obMacMaster.tData(55);
142  -- Get the min. byte cache count
143  v.minByteCnt := conv_integer(obMacMaster.tData(54 downto 48));
144  -- Check for invalid size or invalid EtherType
145  if (v.minByteCnt > 64) or (obMacMaster.tData(47 downto 32) /= ETH_TYPE_G) then
146  -- Next state
147  v.state := IDLE_S;
148  -- Check for invalid size
149  elsif (v.minByteCnt /= 0) and (v.minByteCnt <= 16) then
150  -- Next state
151  v.state := IDLE_S;
152  -- Check for invalid broadcast message
153  elsif (v.bcf = '1') and ((v.ibAppMaster.tDest /= x"FF") or (r.dstMac /= BC_MAC_C)) then
154  -- Next state
155  v.state := IDLE_S;
156  else
157  -- Set the flag
158  v.req := not(v.bcf);
159  -- Next state
160  v.state := TDEST_S;
161  end if;
162  end if;
163  ----------------------------------------------------------------------
164  when TDEST_S =>
165  if (ack = '1') or (r.bcf = '1') then
166  -- Reset the flag
167  v.sof := '1';
168  -- Update EOF flag
169  if r.minByteCnt = 0 then
170  -- Reset the flag
171  v.eof := '0';
172  else
173  -- Set the flag
174  v.eof := '1';
175  -- Remove the header offset
176  v.minByteCnt := r.minByteCnt - 16;
177  end if;
178  -- Check for valid SRC MAC or broadcast
179  if ((remoteMac /= 0) and (remoteMac = r.srcMac)) or (r.bcf = '1') then
180  -- Next state
181  v.state := MOVE_S;
182  else
183  -- Next state
184  v.state := IDLE_S;
185  end if;
186  end if;
187  ----------------------------------------------------------------------
188  when MOVE_S =>
189  -- Check if ready to move data
190  if (obMacMaster.tValid = '1') and (v.ibAppMaster.tValid = '0') then
191  -- Accept the data
192  v.obMacSlave.tReady := '1';
193  -- Move the data
194  v.ibAppMaster.tValid := '1';
195  v.ibAppMaster.tData(63 downto 0) := obMacMaster.tData(63 downto 0);
196  v.ibAppMaster.tKeep(7 downto 0) := obMacMaster.tKeep(7 downto 0);
197  -- Check for SOF
198  if r.sof = '1' then
199  -- Reset the flag
200  v.sof := '0';
201  -- Set the SOF and BCF
202  ssiSetUserSof(RAW_ETH_CONFIG_INIT_C, v.ibAppMaster, '1');
203  ssiSetUserBcf(RAW_ETH_CONFIG_INIT_C, v.ibAppMaster, r.bcf);
204  end if;
205  -- Get EOFE
206  v.eofe := ssiGetUserEofe(RAW_ETH_CONFIG_INIT_C, obMacMaster);
207  -- Check for tLast
208  if obMacMaster.tLast = '1' then
209  -- Set EOF
210  v.ibAppMaster.tLast := '1';
211  -- Set the EOFE
212  ssiSetUserEofe(RAW_ETH_CONFIG_INIT_C, v.ibAppMaster, v.eofe);
213  -- Next state
214  v.state := IDLE_S;
215  end if;
216  -- Check if TX engine had min. ETH cache
217  if r.eof = '1' then
218  -- Check for last transfer
219  if (r.minByteCnt <= 8) then
220  -- Update tKeep
221  v.ibAppMaster.tKeep := genTKeep(r.minByteCnt);
222  -- Set EOF
223  v.ibAppMaster.tLast := '1';
224  -- Set the EOFE
225  ssiSetUserEofe(RAW_ETH_CONFIG_INIT_C, v.ibAppMaster, v.eofe);
226  -- Next state
227  v.state := IDLE_S;
228  else
229  -- Decrement the counter
230  v.minByteCnt := r.minByteCnt - 8;
231  end if;
232  end if;
233  end if;
234  ----------------------------------------------------------------------
235  end case;
236 
237  -- Reset
238  if (rst = '1') then
239  v := REG_INIT_C;
240  end if;
241 
242  -- Register the variable for next clock cycle
243  rin <= v;
244 
245  -- Outputs
246  obMacSlave <= v.obMacSlave;
248  tDest <= v.ibAppMaster.tDest;
249  req <= v.req;
250 
251  end process comb;
252 
253  seq : process (clk) is
254  begin
255  if rising_edge(clk) then
256  r <= rin after TPD_G;
257  end if;
258  end process seq;
259 
260 end rtl;
AxiStreamConfigType := ssiAxiStreamConfig( 8, TKEEP_COMP_C, TUSER_FIRST_LAST_C, 8, 3) RAW_ETH_CONFIG_INIT_C
sl sof
Definition: SsiPkg.vhd:72
std_logic sl
Definition: StdRtlPkg.vhd:28
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
sl eofe
Definition: SsiPkg.vhd:74
in ibAppSlaveAxiStreamSlaveType
slv( 15 downto 0) tKeep
out ibAppMasterAxiStreamMasterType
out tDestslv( 7 downto 0)
TPD_Gtime := 1 ns
slv( 127 downto 0) tData
in remoteMacslv( 47 downto 0)
in obMacMasterAxiStreamMasterType
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
out obMacSlaveAxiStreamSlaveType
slv( 127 downto 0) tUser
ETH_TYPE_Gslv( 15 downto 0) := x"0010"
in localMacslv( 47 downto 0)
sl eof
Definition: SsiPkg.vhd:73
_library_ ieeeieee
std_logic_vector slv
Definition: StdRtlPkg.vhd:29