SURF  1.0
EthMacRxPause.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : EthMacRxPause.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-09-21
5 -- Last update: 2016-10-20
6 -------------------------------------------------------------------------------
7 -- Description:
8 -- Generic pause frame receiver for Ethernet MACs. Pause frames are dropped
9 -- from the incoming data stream.
10 -------------------------------------------------------------------------------
11 -- This file is part of 'SLAC Firmware Standard Library'.
12 -- It is subject to the license terms in the LICENSE.txt file found in the
13 -- top-level directory of this distribution and at:
14 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
15 -- No part of 'SLAC Firmware Standard Library', including this file,
16 -- may be copied, modified, propagated, or distributed except according to
17 -- the terms contained in the LICENSE.txt file.
18 -------------------------------------------------------------------------------
19 
20 library ieee;
21 use ieee.std_logic_1164.all;
22 use ieee.std_logic_arith.all;
23 use ieee.std_logic_unsigned.all;
24 
25 use work.AxiStreamPkg.all;
26 use work.StdRtlPkg.all;
27 use work.EthMacPkg.all;
28 
29 --! @see entity
30  --! @ingroup ethernet_EthMacCore
31 entity EthMacRxPause is
32  generic (
33  TPD_G : time := 1 ns;
34  PAUSE_EN_G : boolean := true;
35  VLAN_EN_G : boolean := false;
36  VLAN_SIZE_G : positive range 1 to 8 := 1;
37  VLAN_VID_G : Slv12Array := (0 => x"001"));
38  port (
39  -- Clock and Reset
40  ethClk : in sl;
41  ethRst : in sl;
42  -- Incoming data from MAC
44  -- Outgoing data
47  -- Pause Values
48  rxPauseReq : out sl;
49  rxPauseValue : out slv(15 downto 0));
50 end EthMacRxPause;
51 
52 architecture rtl of EthMacRxPause is
53 
54  type StateType is (
55  IDLE_S,
56  PAUSE_S,
57  DUMP_S,
58  PASS_S,
59  VLAN_S);
60 
61  type RegType is record
62  idx : natural range 0 to VLAN_SIZE_G-1;
63  pauseEn : sl;
64  pauseValue : slv(15 downto 0);
67  state : StateType;
68  end record RegType;
69 
70  constant REG_INIT_C : RegType := (
71  idx => 0,
72  pauseEn => '0',
73  pauseValue => (others => '0'),
76  state => IDLE_S);
77 
78  signal r : RegType := REG_INIT_C;
79  signal rin : RegType;
80 
81  -- attribute dont_touch : string;
82  -- attribute dont_touch of r : signal is "true";
83 
84 begin
85 
86  U_RxPauseGen : if ((PAUSE_EN_G = true) or (VLAN_EN_G = true)) generate
87 
88  comb : process (ethRst, r, sAxisMaster) is
89  variable v : RegType;
90  variable i : natural;
91  variable vidDet : boolean;
92  variable vid : slv(11 downto 0);
93  begin
94  -- Latch the current value
95  v := r;
96 
97  -- Reset flags
98  v.pauseEn := '0';
99  v.mAxisMaster.tValid := '0';
100  for i in (VLAN_SIZE_G-1) downto 0 loop
101  v.mAxisMasters(i).tValid := '0';
102  end loop;
103 
104  -- Update the variable
105  vidDet := false;
106  vid(11 downto 8) := sAxisMaster.tData(115 downto 112);
107  vid(7 downto 0) := sAxisMaster.tData(127 downto 120);
108 
109  -- State Machine
110  case r.state is
111  ----------------------------------------------------------------------
112  when IDLE_S =>
113  -- Check for data
114  if (sAxisMaster.tValid = '1') then
115  -- Check for pause frame
116  if (PAUSE_EN_G = true) and
117  (sAxisMaster.tData(47 downto 0) = x"010000c28001") and -- DST MAC (Pause MAC Address)
118  (sAxisMaster.tData(127 downto 96) = x"01000888") then -- Mac Type, Mac OpCode
119  -- Check for no EOF
120  if (sAxisMaster.tLast = '0') then
121  -- Next State
122  v.state := PAUSE_S;
123  end if;
124  else
125  if (VLAN_EN_G = false) then
126  -- Move the data
128  -- Check for no EOF
129  if (sAxisMaster.tLast = '0') then
130  -- Next State
131  v.state := PASS_S;
132  end if;
133  else
134  -- Check for VLAN
135  if (sAxisMaster.tData(111 downto 96) = VLAN_TYPE_C) then
136  for i in (VLAN_SIZE_G-1) downto 0 loop
137  if (vidDet = false) and (vid = VLAN_VID_G(i)) then
138  vidDet := true;
139  v.idx := i;
140  -- Move the data
141  v.mAxisMasters(i) := sAxisMaster;
142  -- Check for no EOF
143  if (sAxisMaster.tLast = '0') then
144  -- Next State
145  v.state := VLAN_S;
146  end if;
147  end if;
148  end loop;
149  else
150  -- Move the data
152  -- Check for no EOF
153  if (sAxisMaster.tLast = '0') then
154  -- Next State
155  v.state := PASS_S;
156  end if;
157  end if;
158  end if;
159  end if;
160  end if;
161  ----------------------------------------------------------------------
162  when PAUSE_S =>
163  ----------------------------------------------------------------------------------------------------------
164  -- Refer to https://www.safaribooksonline.com/library/view/ethernet-the-definitive/1565926609/ch04s02.html
165  ----------------------------------------------------------------------------------------------------------
166  -- Check for data
167  if (sAxisMaster.tValid = '1') then
168  -- Latch the pause data
169  v.pauseValue(7 downto 0) := sAxisMaster.tData(15 downto 8);
170  v.pauseValue(15 downto 8) := sAxisMaster.tData(7 downto 0);
171  -- Check for a EOF
172  if (sAxisMaster.tLast = '1') then
173  -- Set the pause
174  v.pauseEn := not axiStreamGetUserBit(EMAC_AXIS_CONFIG_C, sAxisMaster, EMAC_EOFE_BIT_C);
175  -- Next State
176  v.state := IDLE_S;
177  else
178  -- Next State
179  v.state := DUMP_S;
180  end if;
181  end if;
182  ----------------------------------------------------------------------
183  when DUMP_S =>
184  -- Check for a valid EOF
185  if (sAxisMaster.tValid = '1') and (sAxisMaster.tLast = '1') then
186  -- Set the pause
187  v.pauseEn := not axiStreamGetUserBit(EMAC_AXIS_CONFIG_C, sAxisMaster, EMAC_EOFE_BIT_C);
188  -- Next State
189  v.state := IDLE_S;
190  end if;
191  ----------------------------------------------------------------------
192  when PASS_S =>
193  -- Move the data
195  -- Check for a valid EOF
196  if (sAxisMaster.tValid = '1') and (sAxisMaster.tLast = '1') then
197  -- Next State
198  v.state := IDLE_S;
199  end if;
200  ----------------------------------------------------------------------
201  when VLAN_S =>
202  -- Move the data
203  v.mAxisMasters(r.idx) := sAxisMaster;
204  -- Check for a valid EOF
205  if (sAxisMaster.tValid = '1') and (sAxisMaster.tLast = '1') then
206  -- Next State
207  v.state := IDLE_S;
208  end if;
209  ----------------------------------------------------------------------
210  end case;
211 
212  -- Reset
213  if ethRst = '1' then
214  v := REG_INIT_C;
215  end if;
216 
217  -- Register the variable for next clock cycle
218  rin <= v;
219 
220  -- Outputs
223  rxPauseReq <= r.pauseEn;
224  rxPauseValue <= r.pauseValue;
225 
226  end process;
227 
228  seq : process (ethClk) is
229  begin
230  if rising_edge(ethClk) then
231  r <= rin after TPD_G;
232  end if;
233  end process seq;
234 
235  end generate;
236 
237  U_BypRxPause : if ((PAUSE_EN_G = false) and (VLAN_EN_G = false)) generate
239  mAxisMasters <= (others => AXI_STREAM_MASTER_INIT_C);
240  rxPauseReq <= '0';
241  rxPauseValue <= (others => '0');
242  end generate;
243 
244 end rtl;
out mAxisMastersAxiStreamMasterArray( VLAN_SIZE_G- 1 downto 0)
array(natural range <> ) of slv( 11 downto 0) Slv12Array
Definition: StdRtlPkg.vhd:399
TPD_Gtime := 1 ns
in sAxisMasterAxiStreamMasterType
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
out mAxisMasterAxiStreamMasterType
VLAN_EN_Gboolean := false
out rxPauseValueslv( 15 downto 0)
VLAN_VID_GSlv12Array :=( 0=> x"001")
slv( 127 downto 0) tData
VLAN_SIZE_Gpositive range 1 to 8:= 1
integer := 0 EMAC_EOFE_BIT_C
Definition: EthMacPkg.vhd:52
PAUSE_EN_Gboolean := true
array(natural range <> ) of AxiStreamMasterType AxiStreamMasterArray
slv( 15 downto 0) := x"0081" VLAN_TYPE_C
Definition: EthMacPkg.vhd:36
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