1 |
42 |
lmaarsen |
--------------------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- Ethernet Switch on Configurable Logic IP Core ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the ESoCL project ----
|
6 |
|
|
---- http://www.opencores.org/cores/esoc/ ----
|
7 |
|
|
---- ----
|
8 |
|
|
---- Description: see design description ESoCL_dd_71022001.pdf ----
|
9 |
|
|
---- ----
|
10 |
|
|
---- To Do: see roadmap description ESoCL_dd_71022001.pdf ----
|
11 |
|
|
---- and/or release bulleting ESoCL_rb_71022001.pdf ----
|
12 |
|
|
---- ----
|
13 |
|
|
---- Author(s): L.Maarsen ----
|
14 |
|
|
---- Bert Maarsen, lmaarsen@opencores.org ----
|
15 |
|
|
---- ----
|
16 |
|
|
--------------------------------------------------------------------------------
|
17 |
|
|
---- ----
|
18 |
|
|
---- Copyright (C) 2009 Authors and OPENCORES.ORG ----
|
19 |
|
|
---- ----
|
20 |
|
|
---- This source file may be used and distributed without ----
|
21 |
|
|
---- restriction provided that this copyright statement is not ----
|
22 |
|
|
---- removed from the file and that any derivative work contains ----
|
23 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
24 |
|
|
---- ----
|
25 |
|
|
---- This source file is free software; you can redistribute it ----
|
26 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
27 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
28 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
29 |
|
|
---- later version. ----
|
30 |
|
|
---- ----
|
31 |
|
|
---- This source is distributed in the hope that it will be ----
|
32 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
33 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
34 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
35 |
|
|
---- details. ----
|
36 |
|
|
---- ----
|
37 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
38 |
|
|
---- Public License along with this source; if not, download it ----
|
39 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
40 |
|
|
---- ----
|
41 |
|
|
--------------------------------------------------------------------------------
|
42 |
|
|
-- Object : Entity work.esoc_search_engine_da
|
43 |
|
|
-- Last modified : Mon Apr 14 12:50:04 2014.
|
44 |
|
|
--------------------------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
library ieee, std, work;
|
49 |
|
|
use ieee.std_logic_1164.all;
|
50 |
|
|
use std.textio.all;
|
51 |
|
|
use ieee.numeric_std.all;
|
52 |
|
|
use work.package_hash10_24b.all;
|
53 |
|
|
use work.package_esoc_configuration.all;
|
54 |
|
|
|
55 |
|
|
entity esoc_search_engine_da is
|
56 |
|
|
port(
|
57 |
|
|
clk_search : in std_logic;
|
58 |
|
|
reset : in std_logic;
|
59 |
|
|
search_eof : in std_logic;
|
60 |
|
|
search_key : in std_logic_vector(63 downto 0);
|
61 |
|
|
search_port_stalled : in std_logic_vector(esoc_port_count-1 downto 0);
|
62 |
|
|
search_result : out std_logic_vector(esoc_port_count-1 downto 0);
|
63 |
|
|
search_result_av : out std_logic;
|
64 |
|
|
search_sof : in std_logic;
|
65 |
|
|
search_table_address : out STD_LOGIC_VECTOR(12 downto 0);
|
66 |
|
|
search_table_data : out STD_LOGIC_VECTOR(79 downto 0);
|
67 |
|
|
search_table_q : in STD_LOGIC_VECTOR(79 downto 0);
|
68 |
|
|
search_table_rden : out STD_LOGIC;
|
69 |
|
|
search_table_wren : out STD_LOGIC);
|
70 |
|
|
end entity esoc_search_engine_da;
|
71 |
|
|
|
72 |
|
|
--------------------------------------------------------------------------------
|
73 |
|
|
-- Object : Architecture work.esoc_search_engine_da.esoc_search_engine_da
|
74 |
|
|
-- Last modified : Mon Apr 14 12:50:04 2014.
|
75 |
|
|
--------------------------------------------------------------------------------
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
architecture esoc_search_engine_da of esoc_search_engine_da is
|
79 |
|
|
|
80 |
|
|
type search_states is (idle, wait_hash, compare);
|
81 |
|
|
signal search_state: search_states;
|
82 |
|
|
|
83 |
|
|
signal search_table_address_i: std_logic_vector(search_table_address'high downto 0);
|
84 |
|
|
signal search_result_i: std_logic_vector(esoc_port_count-1 downto 0);
|
85 |
|
|
signal search_port_stalled_sync : std_logic_vector(2*esoc_port_count-1 downto 0);
|
86 |
|
|
|
87 |
|
|
signal search_table_coll_cnt: integer range esoc_search_engine_col_depth downto 0 ;
|
88 |
|
|
signal search_hash_delay_cnt: integer range esoc_search_engine_hash_delay downto 0;
|
89 |
|
|
|
90 |
|
|
signal search_key_i: std_logic_vector(59 downto 0);
|
91 |
|
|
|
92 |
|
|
begin
|
93 |
|
|
|
94 |
|
|
--=============================================================================================================
|
95 |
|
|
-- Process : proces search requests for destination MAC address
|
96 |
|
|
-- Description :
|
97 |
|
|
--=============================================================================================================
|
98 |
|
|
search_da: process(clk_search, reset)
|
99 |
|
|
begin
|
100 |
|
|
if reset = '1' then
|
101 |
|
|
search_table_coll_cnt <= 0;
|
102 |
|
|
search_hash_delay_cnt <= 0;
|
103 |
|
|
|
104 |
|
|
search_key_i <= (others => '0');
|
105 |
|
|
search_table_address_i <= (others => '0');
|
106 |
|
|
search_table_rden <= '0';
|
107 |
|
|
search_result_i <= (others => '0');
|
108 |
|
|
search_result_av <= '0';
|
109 |
|
|
|
110 |
|
|
search_port_stalled_sync <= (others => '0');
|
111 |
|
|
|
112 |
|
|
elsif clk_search'event and clk_search = '1' then
|
113 |
|
|
-- clear one-clock active signals
|
114 |
|
|
search_result_av <= '0';
|
115 |
|
|
search_table_rden <= '0';
|
116 |
|
|
|
117 |
|
|
-- synchronise port stalled information with this clock
|
118 |
|
|
search_port_stalled_sync(esoc_port_count-1 downto 0) <= search_port_stalled_sync(2*esoc_port_count-1 downto esoc_port_count);
|
119 |
|
|
search_port_stalled_sync(2*esoc_port_count-1 downto esoc_port_count) <= search_port_stalled;
|
120 |
|
|
|
121 |
|
|
-- process new search requests
|
122 |
|
|
case search_state is
|
123 |
|
|
when idle => -- wait for start of frame, first data is VID + DA, calculate hash pointer (additional delay may be required after synthesis, due to large XOR tree)
|
124 |
|
|
if search_sof = '1' then
|
125 |
|
|
|
126 |
|
|
-- send result (all ports) immediately if destination address is a BC or MC, if UC start search action.
|
127 |
|
|
-- the BC/MC detection is part of the search engine and not part of port because you still need to learn the SA!
|
128 |
|
|
if search_key(esoc_search_bus_mac+esoc_ethernet_uc_mc_bc) = '0'then
|
129 |
|
|
search_key_i(esoc_search_entry_vlan+11 downto esoc_search_entry_vlan) <= search_key(esoc_search_bus_vlan+11 downto esoc_search_bus_vlan);
|
130 |
|
|
search_key_i(esoc_search_entry_mac+47 downto esoc_search_entry_mac) <= search_key(esoc_search_bus_mac+47 downto esoc_search_bus_mac);
|
131 |
|
|
search_table_address_i <= CALC_HASH10_24b(search_key(esoc_search_bus_mac+23 downto esoc_search_bus_mac)) & "000";
|
132 |
|
|
search_table_rden <= '1';
|
133 |
|
|
search_table_coll_cnt <= 0;
|
134 |
|
|
|
135 |
|
|
-- use delay mechanism to give the hash function - large xor tree - time to provide stable result
|
136 |
|
|
-- depends on target speed, use target timing analysis result to optimze this delay! At least one clock
|
137 |
|
|
-- delay due to RAM latency
|
138 |
|
|
search_hash_delay_cnt <= esoc_search_engine_hash_delay-1;
|
139 |
|
|
search_state <= wait_hash;
|
140 |
|
|
|
141 |
|
|
else
|
142 |
|
|
search_result_av <= '1';
|
143 |
|
|
search_result_i <= (others => '1');
|
144 |
|
|
end if;
|
145 |
|
|
end if;
|
146 |
|
|
|
147 |
|
|
when wait_hash => -- hash result stable?
|
148 |
|
|
if search_hash_delay_cnt = 0 then
|
149 |
|
|
search_table_address_i <= std_logic_vector(to_unsigned(to_integer(unsigned(search_table_address_i))+1,search_table_address_i'length));
|
150 |
|
|
search_state <= compare;
|
151 |
|
|
else
|
152 |
|
|
search_hash_delay_cnt <= search_hash_delay_cnt-1;
|
153 |
|
|
end if;
|
154 |
|
|
|
155 |
|
|
search_table_rden <= '1';
|
156 |
|
|
|
157 |
|
|
when compare => -- there is a hit on DA and VID
|
158 |
|
|
if search_table_q(esoc_search_entry_vlan+11 downto esoc_search_entry_vlan) = search_key_i(esoc_search_entry_vlan+11 downto esoc_search_entry_vlan) and
|
159 |
|
|
search_table_q(esoc_search_entry_mac+47 downto esoc_search_entry_mac) = search_key_i(esoc_search_entry_mac+47 downto esoc_search_entry_mac) then
|
160 |
|
|
|
161 |
|
|
-- entry valid, provide destination information else return broadcast as result
|
162 |
|
|
if search_table_q(esoc_search_entry_valid) = '1' then
|
163 |
|
|
search_result_av <= '1';
|
164 |
|
|
search_result_i <= search_table_q(esoc_search_entry_destination+esoc_port_count-1 downto esoc_search_entry_destination);
|
165 |
|
|
search_state <= idle;
|
166 |
|
|
else
|
167 |
|
|
search_result_av <= '1';
|
168 |
|
|
search_result_i <= (others => '1');
|
169 |
|
|
search_state <= idle;
|
170 |
|
|
end if;
|
171 |
|
|
|
172 |
|
|
-- there is no hit on DA and VID
|
173 |
|
|
else
|
174 |
|
|
-- End of collision buffer reached, no increment address for next entry else return result
|
175 |
|
|
if search_table_coll_cnt < esoc_search_engine_col_depth then
|
176 |
|
|
search_table_coll_cnt <= search_table_coll_cnt + 1;
|
177 |
|
|
search_table_address_i <= std_logic_vector(to_unsigned(to_integer(unsigned(search_table_address_i))+1,search_table_address_i'length));
|
178 |
|
|
search_table_rden <= '1';
|
179 |
|
|
|
180 |
|
|
-- end of collission buffer, no hit, return broadcast as result
|
181 |
|
|
else
|
182 |
|
|
search_result_av <= '1';
|
183 |
|
|
search_result_i <= (others => '1');
|
184 |
|
|
search_state <= idle;
|
185 |
|
|
end if;
|
186 |
|
|
end if;
|
187 |
|
|
|
188 |
|
|
when others => search_state <= idle;
|
189 |
|
|
end case;
|
190 |
|
|
end if;
|
191 |
|
|
end process;
|
192 |
|
|
|
193 |
|
|
search_table_wren <= '0';
|
194 |
|
|
search_table_data <= (others => '0');
|
195 |
|
|
search_table_address <= search_table_address_i;
|
196 |
|
|
|
197 |
|
|
-- provide search result, but use port stall info to avoid use of data bus to stalled ports, waste of bus usage
|
198 |
|
|
search_result <= search_result_i and not(search_port_stalled_sync(esoc_port_count-1 downto 0));
|
199 |
|
|
|
200 |
|
|
end architecture esoc_search_engine_da ; -- of esoc_search_engine_da
|
201 |
|
|
|