cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
nts_TcpIp_ArpCam.vhd
Go to the documentation of this file.
1 -- *******************************************************************************
2 -- * Copyright 2016 -- 2021 IBM Corporation
3 -- *
4 -- * Licensed under the Apache License, Version 2.0 (the "License");
5 -- * you may not use this file except in compliance with the License.
6 -- * You may obtain a copy of the License at
7 -- *
8 -- * http://www.apache.org/licenses/LICENSE-2.0
9 -- *
10 -- * Unless required by applicable law or agreed to in writing, software
11 -- * distributed under the License is distributed on an "AS IS" BASIS,
12 -- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -- * See the License for the specific language governing permissions and
14 -- * limitations under the License.
15 -- *******************************************************************************
16 
17 -- ************************************************
18 -- Copyright (c) 2015, Xilinx, Inc.
19 --
20 -- All rights reserved.
21 -- Redistribution and use in source and binary forms, with or without modification,
22 -- are permitted provided that the following conditions are met:
23 -- 1. Redistributions of source code must retain the above copyright notice,
24 -- this list of conditions and the following disclaimer.
25 -- 2. Redistributions in binary form must reproduce the above copyright notice,
26 -- this list of conditions and the following disclaimer in the documentation
27 -- and/or other materials provided with the distribution.
28 -- 3. Neither the name of the copyright holder nor the names of its contributors
29 -- may be used to endorse or promote products derived from this software
30 -- without specific prior written permission.
31 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 -- IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 -- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 -- INTERRUPT-- ION)
38 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
39 -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 -- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 -- ************************************************
42 
43 
44 -- ****************************************************************************
45 -- * @file : nts_TcpIp_ArpCam.vhd
46 -- * @brief : Content Addressable Memory for the address resolution server.
47 -- *
48 -- * System: : cloudFPGA
49 -- * Component : Shell, Network Transport Stack (NTS)
50 -- * Language : VHDL
51 -- *
52 -- * Description : Behavioral implementation of a CAM for the ARP server.
53 -- *
54 -- * Generics:
55 -- * gKeyLen : Sets the lenght of the CAM key.
56 -- * [ 32 : Default for the IPv4 address ]
57 -- * gValLen : Sets the length of the CAM value.
58 -- * [ 48 : Default for the MAC address ]
59 -- *
60 -- * \ingroup NTS
61 -- * \addtogroup NTS_ARP
62 -- * \{
63 -- ****************************************************************************
64 
65 LIBRARY ieee;
66 use IEEE.STD_LOGIC_1164.ALL;
67 use IEEE.STD_LOGIC_ARITH.ALL;
68 use IEEE.STD_LOGIC_UNSIGNED.ALL;
69 
70 -- Uncomment the following library declaration if using
71 -- arithmetic functions with Signed or Unsigned values
72 --USE ieee.numeric_std.ALL;
73 
74 library WORK;
75 use WORK.ArpCam_pkg.all;
76 
77 
78 --*************************************************************************
79 --** ENTITY
80 --*************************************************************************
81 entity ArpCam is
82  generic (
83  gKeyLength : integer := 32;
84  gValueLength : integer := 48
85  );
86  port (
87  piClk : in std_logic;
88  piRst : in std_logic;
89  poCamReady : out std_logic;
90  --
91  siLkpReq_Data : in t_RtlLkpReq;
92  siLkpReq_Valid : in std_logic;
93  siLkpReq_Ready : out std_logic;
94  --
95  soLkpRep_Data : out t_RtlLkpRep;
96  soLkpRep_Valid : out std_logic;
97  soLkpRep_Ready : in std_logic;
98  --
99  siUpdReq_Data : in t_RtlUpdReq;
100  siUpdReq_Valid : in std_logic;
101  siUpdReq_Ready : out std_logic;
102  --
103  soUpdRep_Data : out t_RtlUpdRep;
104  soUpdRep_Valid : out std_logic;
105  soUpdRep_Ready : in std_logic;
106 
107  poDebug : out std_logic_vector(179 downto 0)
108  );
109 end ArpCam;
110 
111 
112 --*************************************************************************
113 --** ARCHITECTURE
114 --*************************************************************************
115 architecture Behavioral of ArpCam is
116 
117  -----------------------------------------------------------------
118  -- COMPONENT DECLARATIONS
119  -----------------------------------------------------------------
120  component clk_gen_2
121  port (
122  CLK_IN1 : IN std_logic;
123  CLK_OUT1 : OUT std_logic;
124  RESET : IN std_logic;
125  LOCKED : OUT std_logic
126  );
127  end component;
128 
129  component BUFG
130  port (
131  I : in std_logic;
132  O : out std_logic
133  );
134  end component;
135 
136  component ARP_IPv4_MAC_CAM
137  port (
138  Rst : in std_logic;
139  Clk : in std_logic;
140  InitEnb : in std_logic;
141  InitDone : out std_logic;
142  AgingTime : in std_logic_vector(31 downto 0);
143  Size : out std_logic_vector(14 downto 0);
144  CamSize : out std_logic_vector( 3 downto 0);
145  LookupReqValid : in std_logic;
146  LookupReqKey : in std_logic_vector(gKeyLength - 1 downto 0);
147  LookupRespValid : out std_logic;
148  LookupRespHit : out std_logic;
149  LookupRespKey : out std_logic_vector(gKeyLength - 1 downto 0);
150  LookupRespValue : out std_logic_vector(gValueLength - 1 downto 0);
151  UpdateAck : out std_logic;
152  UpdateValid : in std_logic;
153  UpdateOp : in std_logic;
154  UpdateKey : in std_logic_vector(gKeyLength - 1 downto 0);
155  UpdateStatic : in std_logic;
156  UpdateValue : in std_logic_vector(gValueLength - 1 downto 0)
157  );
158  end component;
159 
160  -----------------------------------------------------------------
161  -- SIGNAL DECLARATIONS
162  -----------------------------------------------------------------
163  -- FSM Outputs
164  signal sFSM_InitEnb : std_logic := '0';
165  signal sAgingTime : std_logic_vector(31 downto 0) := (others => '1');
166 
167  signal sFSM_LkpReqValid : std_logic := '0';
168  signal sFSM_LkpReqKey : std_logic_vector(gKeyLength - 1 downto 0) := (others => '0');
169 
170  signal sFSM_UpdReqValid : std_logic := '0';
171  signal sFSM_UpdCodReq : std_logic := '0';
172  signal sFSM_UpdKeyReq : std_logic_vector(gKeyLength - 1 downto 0) := (others => '0');
173  signal sFSM_UpdValReq : std_logic_vector(gValueLength - 1 downto 0) := (others => '0');
174 
175  -- CAM Outputs
176  signal sCAM_InitDone : std_logic;
177 
178  signal sCAM_LkpRepValid : std_logic;
179  signal sCAM_LkpRepHit : std_logic;
180  signal sCAM_LkpRepKey : std_logic_vector(gKeyLength - 1 downto 0);
181  signal sCAM_LkpRepValue : std_logic_vector(gValueLength - 1 downto 0);
182  signal sCAM_UpdRepReady : std_logic;
183 
184  signal sFSM_State : std_logic_vector(7 downto 0);
185  signal sValidHappened : std_logic;
186  signal sUpdReqValid : std_logic;
187 
188  signal sDebug : std_logic_vector(179 downto 0 );
189  attribute mark_debug : string;
190  attribute mark_debug of sDebug : signal is "false"; -- Set to "true' if you need/want to trace these signals
191 
192 begin
193 
194  poCamReady <= sCAM_InitDone;
195 
196  -----------------------------------------------------------------
197  -- INST: CONTENT ADDRESSABLE MEMORY
198  -----------------------------------------------------------------
199  CAM: ARP_IPv4_MAC_CAM port map (
200  Clk => piClk,
201  Rst => piRst,
202  InitEnb => sFSM_InitEnb,
203  InitDone => sCAM_InitDone,
204  AgingTime => sAgingTime,
205  Size => open,
206  CamSize => open,
207  -- Lookup I/F
208  LookupReqValid => sFSM_LkpReqValid,
209  LookupReqKey => sFSM_LkpReqKey,
210  LookupRespValid => sCAM_LkpRepValid,
211  LookupRespHit => sCAM_LkpRepHit,
212  LookupRespKey => sCAM_LkpRepKey,
213  LookupRespValue => sCAM_LkpRepValue,
214  -- Update I/F
215  UpdateAck => sCAM_UpdRepReady,
216  UpdateValid => sUpdReqValid, --was sFSM_UpdReqValid,
217  UpdateOp => sFSM_UpdCodReq,
218  UpdateKey => sFSM_UpdKeyReq,
219  UpdateStatic => '1',
220  UpdateValue => sFSM_UpdValReq
221  );
222 
223  sAgingTime <= (others => '1');
224  sUpdReqValid <= sFSM_UpdReqValid or (sFSM_State(6) and not sCAM_UpdRepReady);
225 
226  -----------------------------------------------------------------
227  -- PROC: Cam Control
228  -----------------------------------------------------------------
229  pCamCtl : process (piClk, piRst,sCAM_InitDone)
230  begin
231  if (piRst = '1') then
232  sFSM_LkpReqValid <= '0';
233  sFSM_LkpReqKey <= (others => '0');
234  sFSM_UpdReqValid <= '0';
235  sFSM_UpdCodReq <= '0';
236  sFSM_UpdKeyReq <= (others => '0');
237  sFSM_UpdValReq <= (others => '0');
238  sFSM_State <= x"00";
239  siLkpReq_Ready <= '0';
240  siUpdReq_Ready <= '0';
241  soLkpRep_Valid <= '0';
242  soUpdRep_Valid <= '0';
243  sFSM_InitEnb <= '1';
244  elsif (piClk'event and piClk='1') then
245  sFSM_InitEnb <= not sCAM_InitDone;
246  siLkpReq_Ready <= '0';
247  siUpdReq_Ready <= '0';
248  soLkpRep_Valid <= '0';
249  soUpdRep_Valid <= '0';
250  sFSM_LkpReqValid <= '0';
251  sFSM_UpdReqValid <= '0';
252  if (sCAM_InitDone = '1' or sFSM_State > x"00") then -- [FIXME: State test can be removed]
253  case sFSM_State is
254  when x"00" =>
255  --------------------------------
256  -- IDLE-STATE --
257  --------------------------------
258  if (siLkpReq_Valid = '1') then
259  -- IDLE --> LOOKUP REQUEST -------------
260  siLkpReq_Ready <= '1';
261  sFSM_LkpReqValid <= '1';
262  sFSM_LkpReqKey <= siLkpReq_Data.ipKey;
263  soLkpRep_Data.srcBit <= siLkpReq_Data.srcBit;
264  sFSM_State <= x"10";
265  elsif (siUpdReq_Valid='1' and siUpdReq_Data.opCode=cOPCODE_INSERT) then
266  -- IDLE --> UPDATE REQUEST (INSERT) ----
267  siUpdReq_Ready <= '1';
268  sFSM_UpdReqValid <= '1';
269  sFSM_UpdCodReq <= siUpdReq_Data.opCode;
270  sFSM_UpdKeyReq <= siUpdReq_Data.ipKey;
271  sFSM_UpdValReq <= siUpdReq_Data.macVal;
272  soUpdRep_Data.srcBit <= siUpdReq_Data.srcBit;
273  sFSM_State <= x"50";
274  elsif (siUpdReq_Valid='1' and siUpdReq_Data.opCode=cOPCODE_DELETE) then
275  -- IDLE --> UPDATE REQUEST (DELETE) ----
276  siUpdReq_Ready <= '1';
277  sFSM_UpdReqValid <= '1';
278  sFSM_UpdCodReq <= siUpdReq_Data.opCode;
279  sFSM_UpdKeyReq <= siUpdReq_Data.ipKey;
280  sFSM_UpdValReq <= siUpdReq_Data.macval;
281  soUpdRep_Data.srcBit <= siUpdReq_Data.srcBit;
282  sFSM_State <= x"40";
283  else
284  -- IDLE --> IDLE ---------------------
285  sFSM_State <= x"00";
286  end if;
287 
288  when x"10" =>
289  --------------------------------
290  -- CLEAR-LOOKUP-REQUEST --
291  --------------------------------
292  sFSM_LkpReqValid <= '0';
293  sValidHappened <= '0';
294  sFSM_State <= x"11";
295 
296  when x"11" =>
297  --------------------------------
298  -- HANDLE-CAM-LKP-REPLY --
299  --------------------------------
300  if (sCAM_LkpRepValid = '1') then
301  soLkpRep_Data.hitBit <= sCAM_LkpRepHit;
302  soLkpRep_Data.macVal <= sCAM_LkpRepValue;
303  soLkpRep_Valid <= '1';
304  sFSM_State <= x"00";
305  end if;
306 
307  when x"50" =>
308  --------------------------------
309  -- UPDATE-REQUEST-INSERT --
310  --------------------------------
311  sFSM_UpdReqValid <= '1';
312  sFSM_State <= x"51";
313 
314  when x"51" =>
315  --------------------------------
316  -- HANDLE-CAM-UPD-REPLY --
317  --------------------------------
318  if (sCAM_UpdRepReady = '1') then
319  sFSM_UpdReqValid <= '0';
320  sFSM_UpdCodReq <= '0';
321  soUpdRep_Data.macVal <= sFSM_UpdValReq;
322  soUpdRep_Data.opCode <= sFSM_UpdCodReq; -- ops
323  sFSM_UpdKeyReq <= (others => '0');
324  sFSM_UpdValReq <= (others => '0');
325  sFSM_State <= x"52";
326  else -- hold everything
327  sFSM_UpdReqValid <= '0';
328  sFSM_State <= x"51";
329  end if;
330 
331  when x"52" =>
332  --------------------------------
333  -- UPDATE-REPLY-INSERT --
334  --------------------------------
335  soUpdRep_Valid <= '1';
336  sFSM_State <= x"00";
337 
338  when x"40" =>
339  --------------------------------
340  -- UPDATE-REQUEST-DELETE --
341  --------------------------------
342  sFSM_UpdReqValid <= '1';
343  sFSM_State <= x"41";
344 
345  when x"41" =>
346  --------------------------------
347  -- HANDLE-CAM-UPD-REPLY --
348  --------------------------------
349  soUpdRep_Data.macVal <= sFSM_UpdValReq;
350  soUpdRep_Data.opCode <= sFSM_UpdCodReq; -- ops
351  if (sCAM_UpdRepReady = '1') then
352  -- Reset
353  sFSM_UpdReqValid <= '0';
354  sFSM_UpdCodReq <= '0';
355  sFSM_UpdKeyReq <= (others => '0');
356  sFSM_UpdValReq <= (others => '0');
357  sFSM_State <= x"42";
358  else -- hold everything
359  sFSM_UpdReqValid <= '0';
360  sFSM_State <= x"41";
361  end if;
362 
363  when x"42" =>
364  --------------------------------
365  -- UPDATE-REPLY-DELETE --
366  --------------------------------
367  if (soUpdRep_Ready = '1') then
368  soUpdRep_Valid <= '1';
369  sFSM_State <= x"00";
370  else
371  sFSM_State <= sFSM_State;
372  end if;
373 
374  when others =>
375  --------------------------------
376  -- DEFAULT-STATE --
377  --------------------------------
378  sFSM_State <= sFSM_State + 1;
379  end case;
380  end if;
381  end if;
382  end process; -- pCamCtl
383 
384  -----------------------------------------------------------------
385  -- PROC: Debug
386  -----------------------------------------------------------------
387  pDebug: process (piClk)
388  begin
389  -- Control signals & Single bits (7..0)
390  sDebug( 0) <= piRst;
391  sDebug( 1) <= sFSM_InitEnb;
392  sDebug( 2) <= sCAM_InitDone;
393  sDebug( 3) <= sFSM_LkpReqValid;
394  sDebug( 4) <= sCAM_LkpRepValid;
395  sDebug( 5) <= sCAM_LkpRepHit;
396  sDebug( 6) <= sFSM_UpdReqValid;
397  sDebug( 7) <= '0';
398  -- FSM States
399  sDebug( 15 downto 8) <= sFSM_State;
400  -- Lookup Request I/F (47..16)
401  sDebug( 47 downto 16) <= sFSM_LkpReqKey;
402  -- Lookup Reply I/F (95..48)
403  sDebug( 95 downto 48) <= sCAM_LkpRepValue;
404  -- Update Request I/F (127..96)
405  sDebug(127 downto 96) <= sFSM_UpdKeyReq;
406  sDebug(175 downto 128) <= sFSM_UpdValReq;
407  sDebug(176) <= sFSM_UpdCodReq;
408  sDebug(177) <= sUpdReqValid;
409  sDebug(178) <= sCAM_UpdRepReady;
410  if (piClk'event and piClk='1') then
411  poDebug <= sDebug;
412  end if;
413  end process; -- pDebug
414 
415 end;
out soLkpRep_Validstd_logic
out soUpdRep_Datat_RtlUpdRep
in piClkstd_logic
in siLkpReq_Datat_RtlLkpReq
out poDebugstd_logic_vector(179 downto 0)
in siUpdReq_Datat_RtlUpdReq
gValueLengthinteger :=48
out soUpdRep_Validstd_logic
in soUpdRep_Readystd_logic
out poCamReadystd_logic
in piRststd_logic
in siLkpReq_Validstd_logic
in siUpdReq_Validstd_logic
out siUpdReq_Readystd_logic
gKeyLengthinteger :=32
in soLkpRep_Readystd_logic
out siLkpReq_Readystd_logic
out soLkpRep_Datat_RtlLkpRep