cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
nts_TcpIp_ToeCam.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 -- *
46 -- * cloudFPGA
47 -- *
48 -- *-----------------------------------------------------------------------------
49 -- *
50 -- * Title : Content Addressable Memory for the TCP Offload Engine..
51 -- *
52 -- * File : nts_TcpIp_ToeCam.vhd
53 -- *
54 -- * Created : Jan. 2018
55 -- * Authors : Jagath Weerasinghe, Francois Abel
56 -- *
57 -- * Devices : xcku060-ffva1156-2-i
58 -- * Tools : Vivado v2016.4, v2017.4, 2019.2 (64-bit)
59 -- * Depends : None
60 -- *
61 -- * Description : Vhdl wrapper for the Verilog version of the CAM for the TCP
62 -- *
63 -- * Generics:
64 -- * gKeyLen : Sets the lenght of the CAM key.
65 -- * [ 96 : Default for {IP_SA, IP_DA, TCP_DP, TCP_SP} ]
66 -- * gValLen : Sets the length of the CAM value.
67 -- * [ 14 : Default for up to 16,384 connections ]
68 -- *
69 -- *-----------------------------------------------------------------------------
70 -- *
71 -- * Notes:
72 -- * This VHDL code is an updated version of a testbench created by ISE. This
73 -- * original testbench was automatically generated using types std_logic and
74 -- * std_logic_vector for the ports of the unit under test. Xilinx recommends
75 -- * that these types always be used for the top-level I/O of a design in order
76 -- * to guarantee that the testbench will bind correctly to the post-
77 -- * implementation simulation model.
78 -- *
79 -- ******************************************************************************
80 
81 LIBRARY IEEE;
82 use IEEE.STD_LOGIC_1164.ALL;
83 use IEEE.STD_LOGIC_ARITH.ALL;
84 use IEEE.STD_LOGIC_UNSIGNED.ALL;
85 
86 -- Uncomment the following library declaration if using
87 -- arithmetic functions with Signed or Unsigned values
88 --USE ieee.numeric_std.ALL;
89 
90 
91 --*************************************************************************
92 --** ENTITY
93 --*************************************************************************
94 entity ToeCam is
95  generic (
96  gKeyLen : integer := 96; -- [ 96 = Default for {IP_SA, IP_DA, TCP_DP, TCP_SP} ]
97  gValLen : integer := 14; -- [ 14 = Default for 16,384 connections ]
98  gSrcLen : integer := 1; -- [ 1 = Default for RXe or TAi ]
99  gHitLen : integer := 1; -- [ 1 = Default for Hit or NoHit ]
100  gOprLen : integer := 1 -- [ 1 =
101  );
102  port (
103 
104  piClk : in std_logic;
105  piRst_n : in std_logic;
106 
107  poCamReady : out std_logic;
108 
109  --------------------------------------------------------
110  -- From TOE - Lookup Request / Axis
111  --------------------------------------------------------
112  piTOE_LkpReq_tdata : in std_logic_vector((gSrcLen+gKeyLen-1) downto 0);
113  piTOE_LkpReq_tvalid : in std_logic;
114  poTOE_LkpReq_tready : out std_logic;
115 
116  --------------------------------------------------------
117  -- To TOE - Lookup Reply / Axis
118  --------------------------------------------------------
119  poTOE_LkpRep_tdata : out std_logic_vector(gHitLen+gSrcLen+gValLen-1 downto 0);
120  poTOE_LkpRep_tvalid : out std_logic;
121  piTOE_LkpRep_tready : in std_logic;
122 
123  -- -----------------------------------------------------
124  -- From TOE - Update Request / Axis
125  -- -----------------------------------------------------
126  piTOE_UpdReq_tdata : in std_logic_vector(gOprLen+gSrcLen+gValLen+gKeyLen-1 downto 0);
127  piTOE_UpdReq_tvalid : in std_logic;
128  poTOE_UpdReq_tready : out std_logic;
129 
130  --------------------------------------------------------
131  -- To TOE Interfaces
132  --------------------------------------------------------
133  poTOE_UpdRep_tdata : out std_logic_vector(gOprLen+gSrcLen+gValLen-1 downto 0);
134  poTOE_UpdRep_tvalid : out std_logic;
135  piTOE_UpdRep_tready : in std_logic;
136 
137  -- -----------------------------------------------------
138  -- LED & Debug Interfaces
139  -- -----------------------------------------------------
140  poLed0 : out std_logic;
141  poLed1 : out std_logic;
142  poDebug : out std_logic_vector(255 downto 0)
143 
144  );
145 end ToeCam;
146 
147 
148 --*************************************************************************
149 --** ARCHITECTURE
150 --*************************************************************************
151 architecture Behavioral of ToeCam is
152 
153  -----------------------------------------------------------------
154  -- COMPONENT DECLARATIONS
155  -----------------------------------------------------------------
156 
157  component ToeCamWrap -- [TODO - Rename into Cam]
158  port (
159  Rst : in std_logic;
160  Clk : in std_logic;
161 
162  InitEnb : in std_logic;
163  InitDone : out std_logic;
164 
165  AgingTime : in std_logic_vector(31 downto 0);
166  Size : out std_logic_vector(14 downto 0);
167  CamSize : out std_logic_vector( 2 downto 0);
168  -- Lookup Request/Reply ----------
169  LookupReqValid : in std_logic;
170  LookupReqKey : in std_logic_vector(gKeyLen-1 downto 0);
171  LookupRespValid : out std_logic;
172  LookupRespHit : out std_logic;
173  LookupRespKey : out std_logic_vector(gKeyLen-1 downto 0);
174  LookupRespValue : out std_logic_vector(gValLen-1 downto 0);
175  -- Update Request ----------------
176  UpdateReady : out std_logic;
177  UpdateValid : in std_logic;
178  UpdateOp : in std_logic;
179  UpdateKey : in std_logic_vector(gKeyLen-1 downto 0);
180  UpdateStatic : in std_logic;
181  UpdateValue : in std_logic_vector(gValLen-1 downto 0)
182  );
183  end component;
184 
185  -----------------------------------------------------------------
186  -- CONSTANT DECLARATIONS
187  -----------------------------------------------------------------
188  constant cOP_INSERT : std_logic := '0'; -- Insert operation
189  constant cOP_DELETE : std_logic := '1'; -- Delete operation
190 
191  -----------------------------------------------------------------
192  -- SIGNAL DECLARATIONS
193  -----------------------------------------------------------------
194 
195  -- CAM Input Signals
196  signal sInitEnable : std_logic := '0';
197  signal sAgingTime : std_logic_vector(31 downto 0) := (others => '1');
198 
199  signal sLookupReqValid : std_logic := '0';
200  signal sLookupReqKey : std_logic_vector(gKeyLen-1 downto 0) := (others => '0');
201 
202  signal sUpdateValid : std_logic := '0';
203  signal sUpdateOp : std_logic := '0';
204 
205  signal UpdateKey : std_logic_vector(95 downto 0) := (others => '0');
206  signal UpdateStatic : std_logic := '0';
207  signal UpdateValue : std_logic_vector(13 downto 0) := (others => '0');
208 
209  -- CAM Output Signals
210  signal sCAM_InitDone : std_logic;
211  signal Size : std_logic_vector(14 downto 0);
212  signal CamSize : std_logic_vector( 2 downto 0);
213  signal LookupRepValid : std_logic;
214  signal LookupRepHit : std_logic;
215  signal LookupRepKey : std_logic_vector(95 downto 0);
216  signal LookupRepValue : std_logic_vector(13 downto 0);
217  signal UpdateReady : std_logic;
218  signal valid_happened : std_logic;
219 
220  signal cnt1s : std_logic_vector(27 downto 0);
221  signal count : std_logic := '0';
222 
223  signal sRst : std_logic;
224  signal locked : std_logic;
225  signal help_updval : std_logic;
226 
227  signal ctl_fsm : std_logic_vector( 7 downto 0);
228  -- [TODO] type tFsmStates is (idle, r1, r2, r3, r4, c, p1, p2);
229  -- [TODO] signal fsmStateReg : tFsmStates;
230 
231 begin
232 
233  poCamReady <= sCAM_InitDone;
234 
235  sRst <= not piRst_n;
236 
237  -----------------------------------------------------------------
238  -- INST: CONTENT ADDRESSABLE MEMORY
239  -----------------------------------------------------------------
240  WRAP: ToeCamWrap port map (
241  Rst => sRst,
242  Clk => piClk,
243  InitEnb => sInitEnable,
244  InitDone => sCAM_InitDone,
245  AgingTime => sAgingTime,
246  Size => Size,
247  CamSize => CamSize,
248  -- Lookup Request/Reply ----------
249  LookupReqValid => sLookupReqValid,
250  LookupReqKey => sLookupReqKey,
251  LookupRespValid => LookupRepValid,
252  LookupRespHit => LookupRepHit,
253  LookupRespKey => LookupRepKey,
254  LookupRespValue => LookupRepValue,
255  -- Update Request ----------------
256  UpdateReady => UpdateReady,
257  UpdateValid => help_updval, --UpdateValid,
258  UpdateOp => sUpdateOp,
259  UpdateKey => UpdateKey,
260  UpdateStatic => UpdateStatic,
261  UpdateValue => UpdateValue
262  );
263 
264  sAgingTime <= (others => '1');
265  help_updval <= sUpdateValid or (ctl_fsm(6) and not UpdateReady);
266 
267  -----------------------------------------------------------------
268  -- PROC: CAM Control
269  -----------------------------------------------------------------
270  pCamCtl: process (piClk, sRst)
271  -----------------------------------------------------------------
272  -- ALIAS DECLARATIONS
273  -----------------------------------------------------------------
274  alias piLkpReqKey : std_logic_vector(gKeyLen-1 downto 0) is piTOE_LkpReq_tdata(gKeyLen -1 downto 0);
275  alias piLkpReqSrc : std_logic is piTOE_LkpReq_tdata(gKeyLen+gSrcLen-1); -- lookupSource bit
276 
277  alias poLkpRepVal : std_logic_vector(gValLen-1 downto 0) is poTOE_LkpRep_tdata(gValLen -1 downto 0);
278  alias poLkpRepSrc : std_logic is poTOE_LkpRep_tdata(gValLen+gSrcLen -1); -- lookupSource bit
279  alias poLkpRepHit : std_logic is poTOE_LkpRep_tdata(gValLen+gSrcLen+gHitLen-1); -- lookupHit bit
280 
281  alias piUpdReqKey : std_logic_vector(gKeyLen-1 downto 0) is piTOE_UpdReq_tdata(gKeyLen -1 downto 0); -- lookupKey
282  alias piUpdReqVal : std_logic_vector(gValLen-1 downto 0) is piTOE_UpdReq_tdata(gKeyLen+gValLen -1 downto 0); -- lookupValue
283  alias piUpdReqSrc : std_logic is piTOE_UpdReq_tdata(gKeyLen+gValLen+gSrcLen -1); -- lookupSource bit
284  alias piUpdReqOpr : std_logic is piTOE_UpdReq_tdata(gKeyLen+gValLen+gSrcLen+gOprLen-1); -- lookupOperation bit
285 
286  alias poUpdRepVal : std_logic_vector(gValLen-1 downto 0) is poTOE_UpdRep_tdata(gValLen -1 downto 0); -- lookupValue
287  alias poUpdRepSrc : std_logic is poTOE_UpdRep_tdata(gValLen+gSrcLen -1);
288  alias poUpdRepOpr : std_logic is poTOE_UpdRep_tdata(gValLen+gSrcLen+gOprLen-1);
289  begin
290 
291  if (sRst = '1') then
292  sLookupReqValid <= '0';
293  sLookupReqKey <= (others => '0');
294  sUpdateValid <= '0';
295  sUpdateOp <= '0';
296  UpdateKey <= (others => '0');
297  UpdateStatic <= '1';
298  UpdateValue <= (others => '0');
299  ctl_fsm <= x"00";
300  poTOE_LkpReq_tready <= '0';
301  poTOE_UpdReq_tready <= '0';
302  poTOE_LkpRep_tvalid <= '0';
303  poTOE_UpdRep_tvalid <= '0';
304  sInitEnable <= not sCAM_InitDone;
305 
306  elsif (piClk'event and piClk = '1') then
307  sUpdateValid <= '0';
308  sInitEnable <= not sCAM_InitDone;
309  poTOE_LkpReq_tready <= '0';
310  poTOE_UpdReq_tready <= '0';
311  poTOE_LkpRep_tvalid <= '0';
312  poTOE_UpdRep_tvalid <= '0';
313  sLookupReqValid <= '0';
314 
315  if (sCAM_InitDone = '1' or ctl_fsm > x"00") then
316 
317  case ctl_fsm is
318 
319  --================================================
320  -- IDLE STATE
321  --================================================
322  when x"00" =>
323  -- Lookup ----------------------------
324  if (piTOE_LkpReq_tvalid = '1') then
325  sLookupReqValid <= '1';
326  sLookupReqKey <= piLkpReqKey;
327  poLkpRepSrc <= piLkpReqSrc;
328  poTOE_LkpReq_tready <= '1';
329  ctl_fsm <= x"10";
330 
331  -- Update = Insert -------------------
332  elsif (piTOE_UpdReq_tvalid = '1' and piTOE_UpdReq_tdata(1) = cOP_INSERT) then
333  sUpdateValid <= '1';
334  UpdateKey <= piUpdReqKey;
335  UpdateValue <= piUpdReqVal;
336  sUpdateOp <= piUpdReqOpr;
337  poUpdRepSrc <= piUpdReqSrc;
338  poTOE_UpdReq_tready <= '1';
339  ctl_fsm <= x"50";
340 
341  -- Update = Delete -------------------
342  elsif (piTOE_UpdReq_tvalid='1' and piTOE_UpdReq_tdata(1) = cOP_DELETE) then
343  sUpdateValid <= '1';
344  UpdateKey <= piTOE_UpdReq_tdata(111 downto 16);
345  UpdateValue <= piTOE_UpdReq_tdata( 15 downto 2);
346  sUpdateOp <= piTOE_UpdReq_tdata(1);
347  poTOE_UpdRep_tdata(0) <= piTOE_UpdReq_tdata(0); -- updateSource
348  poTOE_UpdReq_tready <= '1';
349  ctl_fsm <= x"40";
350  else
351  ctl_fsm <= x"00";
352  end if;
353 
354  --================================================
355  -- END-OF-LOOKUP STATE
356  --================================================
357  when x"10" =>
358  sLookupReqValid <= '0';
359  valid_happened <= '0';
360  ctl_fsm <= x"11";
361 
362  --================================================
363  -- LOOKUP-REPLY STATE
364  --================================================
365  when x"11" =>
366  if (LookupRepValid = '1') then
367  -- Prepare the reply for TOE -------
368  poTOE_LkpRep_tdata(15) <= LookupRepHit;
369  poTOE_LkpRep_tdata(14 downto 1) <= LookupRepValue(13 downto 0);
370  end if;
371  if (piTOE_LkpRep_tready = '0') then
372  if (LookupRepValid = '1') then
373  valid_happened <= '1';
374  end if;
375  ctl_fsm <= ctl_fsm;
376  else
377  if (LookupRepValid = '1' or valid_happened = '1') then
378  -- Send reply back to TOE --------
379  poTOE_LkpRep_tvalid <= '1';
380  ctl_fsm <= x"00";
381  end if;
382  end if;
383 
384  --================================================
385  -- END-OF-INSERT STATE
386  --================================================
387  when x"50" =>
388  sUpdateValid <= '1';
389  ctl_fsm <= x"51";
390 
391  --================================================
392  -- WAIT-FOR-INSERT-REPLY STATE
393  --================================================
394  when x"51" =>
395  if (UpdateReady = '1') then
396  -- Prepare the reply for TOE -------
397  sUpdateValid <= '0'; -- clear the update request
398  sUpdateOp <= '0';
399  UpdateKey <= (others => '0');
400  UpdateValue <= (others => '0');
401  poTOE_UpdRep_tdata(15 downto 2) <= UpdateValue; -- SessId
402  poTOE_UpdRep_tdata(1) <= sUpdateOp; -- Operation
403  ctl_fsm <= x"52";
404  else
405  -- Hold-on until the CAM is ready --
406  sUpdateValid <= '0';
407  ctl_fsm <= x"51";
408  end if;
409 
410  --================================================
411  -- SEND-INSERT-REPLY STATE
412  --================================================
413  when x"52" =>
414  if (piTOE_UpdRep_tready = '0') then
415  -- Wait until TOE is ready ---------
416  ctl_fsm <= ctl_fsm;
417  else
418  -- Send reply back to TOE ----------
419  poTOE_UpdRep_tvalid <= '1';
420  ctl_fsm <= x"00";
421  end if;
422 
423  --================================================
424  -- END-OF-DELETE STATE
425  --================================================
426  when x"40" =>
427  sUpdateValid <= '1';
428  ctl_fsm <= x"41";
429 
430  --================================================
431  -- WAIT-FOR-DELETE-REPLY STATE
432  --================================================
433  when x"41" =>
434  if (UpdateReady='1') then
435  -- Prepare the reply for TOE -------
436  sUpdateValid <= '0'; -- clear the update request
437  sUpdateOp <= '0';
438  UpdateKey <= (others => '0');
439  UpdateValue <= (others => '0');
440  poTOE_UpdRep_tdata(15 downto 2) <= UpdateValue; -- SessId
441  poTOE_UpdRep_tdata(1) <= sUpdateOp; -- Operation
442  ctl_fsm <= x"42";
443  else
444  -- Hold-on until the CAM is ready --
445  sUpdateValid <= '0';
446  ctl_fsm <= x"41";
447  end if;
448 
449  --================================================
450  -- SEND-DELETE-REPLY STATE
451  --================================================
452  when x"42" =>
453  if (piTOE_UpdRep_tready = '0') then
454  -- Wait until TOE is ready ---------
455  ctl_fsm <= ctl_fsm;
456  else
457  -- Send reply back to TOE ----------
458  poTOE_UpdRep_tvalid <= '1';
459  ctl_fsm <= x"00";
460  end if;
461 
462  --================================================
463  -- DEFAULT STATE
464  --================================================
465  when others =>
466  ctl_fsm <= ctl_fsm + 1;
467 
468  end case;
469 
470  end if; -- End; if (sCAM_InitDone = '1' or ctl_fsm > x"00") then
471 
472  end if; -- End of: elsif (piClk'event and piClk = '1') then
473 
474  end process; -- End of: pCamCtl
475 
476 
477  -----------------------------------------------------------------
478  -- PROC: pHeartBeat
479  -----------------------------------------------------------------
480  pHeartBeat : process(piClk)
481  begin
482  if (piClk'event and piClk='1') then
483  if (cnt1s < x"5F5E0FF") then
484  cnt1s <= cnt1s + 1;
485  else
486  count <= not count;
487  cnt1s <= (others => '0');
488  end if;
489  end if;
490  end process;
491  -- Output Assignments --
492  poLed1 <= count;
493  poLed0 <= not count;
494 
495  -----------------------------------------------------------------
496  -- PROC: Debug
497  -----------------------------------------------------------------
498  -- pDebug: process (piClk)
499  -- begin
500  -- if (piClk'event and piClk='1') then
501  -- poDebug(0) <= sInitEnable;
502  -- poDebug(1) <= sCAM_InitDone;
503  -- poDebug(2) <= sLookupReqValid;
504  -- poDebug(99 downto 3) <= sLookupReqKey;
505  -- poDebug(100) <= LookupRepValid;
506  -- poDebug(101) <= LookupRepHit;
507  -- poDebug(198 downto 102) <= LookupRepKey;
508  -- poDebug(212 downto 199) <= LookupRepValue;
509  -- poDebug(213) <= UpdateReady;
510  -- poDebug(214) <= help_updval;
511  -- poDebug(215) <= UpdateOp;
512  -- poDebug(223 downto 216) <= UpdateKey(7 downto 0);
513  -- poDebug(224) <= UpdateStatic;
514  -- poDebug(238 downto 225) <= UpdateValue(13 downto 0);
515  -- poDebug(246 downto 239) <= ctl_fsm;
516  -- poDebug(247) <= sRst;
517  -- end if;
518  -- end process; -- End of: pDebug
519 
520 end; -- End of: architecture
in piRst_nstd_logic
in piTOE_LkpReq_tdatastd_logic_vector(( gSrcLen+ gKeyLen- 1) downto 0)
out poTOE_UpdRep_tdatastd_logic_vector( gOprLen+ gSrcLen+ gValLen- 1 downto 0)
gOprLeninteger :=1
in piTOE_UpdReq_tvalidstd_logic
gSrcLeninteger :=1
gValLeninteger :=14
in piTOE_UpdRep_treadystd_logic
out poTOE_UpdRep_tvalidstd_logic
out poDebugstd_logic_vector(255 downto 0)
out poCamReadystd_logic
in piTOE_LkpReq_tvalidstd_logic
out poTOE_UpdReq_treadystd_logic
out poTOE_LkpRep_tvalidstd_logic
out poTOE_LkpRep_tdatastd_logic_vector( gHitLen+ gSrcLen+ gValLen- 1 downto 0)
gHitLeninteger :=1
out poLed1std_logic
in piTOE_LkpRep_treadystd_logic
out poTOE_LkpReq_treadystd_logic
in piTOE_UpdReq_tdatastd_logic_vector( gOprLen+ gSrcLen+ gValLen+ gKeyLen- 1 downto 0)
out poLed0std_logic
gKeyLeninteger :=96
in piClkstd_logic