| 1 |
10 |
pjf |
----------------------------------------------------------------------------------
|
| 2 |
|
|
-- Company:
|
| 3 |
|
|
-- Engineer: Peter Fall
|
| 4 |
|
|
--
|
| 5 |
|
|
-- Create Date: 12:00:04 05/31/2011
|
| 6 |
|
|
-- Design Name:
|
| 7 |
|
|
-- Module Name: arpv2 - Structural
|
| 8 |
|
|
-- Project Name:
|
| 9 |
|
|
-- Target Devices:
|
| 10 |
|
|
-- Tool versions:
|
| 11 |
|
|
-- Description:
|
| 12 |
|
|
-- handle simple IP lookup in 1-deep cache and arp store
|
| 13 |
|
|
-- request cache fill through ARP protocol if required
|
| 14 |
|
|
-- Handle ARP protocol
|
| 15 |
|
|
-- Respond to ARP requests and replies
|
| 16 |
|
|
-- Ignore pkts that are not ARP
|
| 17 |
|
|
-- Ignore pkts that are not addressed to us
|
| 18 |
|
|
--
|
| 19 |
|
|
-- structural decomposition includes
|
| 20 |
|
|
-- arp TX block - encoding of ARP protocol
|
| 21 |
|
|
-- arp RX block - decoding of ARP protocol
|
| 22 |
|
|
-- arp REQ block - sequencing requests for resolution
|
| 23 |
|
|
-- arp STORE block - storing address resolution entries (indexed by IP addr)
|
| 24 |
|
|
-- arp sync block - sync between master RX clock and TX clock domains
|
| 25 |
|
|
--
|
| 26 |
|
|
-- Dependencies:
|
| 27 |
|
|
--
|
| 28 |
|
|
-- Revision:
|
| 29 |
|
|
-- Revision 0.01 - File Created
|
| 30 |
|
|
-- Additional Comments:
|
| 31 |
|
|
--
|
| 32 |
|
|
----------------------------------------------------------------------------------
|
| 33 |
|
|
library IEEE;
|
| 34 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 35 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
| 36 |
|
|
use work.arp_types.all;
|
| 37 |
|
|
|
| 38 |
|
|
entity arpv2 is
|
| 39 |
|
|
generic (
|
| 40 |
|
|
CLOCK_FREQ : integer := 125000000; -- freq of data_in_clk -- needed to timout cntr
|
| 41 |
|
|
ARP_TIMEOUT : integer := 60; -- ARP response timeout (s)
|
| 42 |
|
|
ARP_MAX_PKT_TMO : integer := 5; -- # wrong nwk pkts received before set error
|
| 43 |
|
|
MAX_ARP_ENTRIES : integer := 255 -- max entries in the arp store
|
| 44 |
|
|
);
|
| 45 |
|
|
Port (
|
| 46 |
|
|
-- lookup request signals
|
| 47 |
|
|
arp_req_req : in arp_req_req_type;
|
| 48 |
|
|
arp_req_rslt : out arp_req_rslt_type;
|
| 49 |
|
|
-- MAC layer RX signals
|
| 50 |
|
|
data_in_clk : in STD_LOGIC;
|
| 51 |
|
|
reset : in STD_LOGIC;
|
| 52 |
|
|
data_in : in STD_LOGIC_VECTOR (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
| 53 |
|
|
data_in_valid : in STD_LOGIC; -- indicates data_in valid on clock
|
| 54 |
|
|
data_in_last : in STD_LOGIC; -- indicates last data in frame
|
| 55 |
|
|
-- MAC layer TX signals
|
| 56 |
|
|
mac_tx_req : out std_logic; -- indicates that ip wants access to channel (stays up for as long as tx)
|
| 57 |
|
|
mac_tx_granted : in std_logic; -- indicates that access to channel has been granted
|
| 58 |
|
|
data_out_clk : in std_logic;
|
| 59 |
|
|
data_out_ready : in std_logic; -- indicates system ready to consume data
|
| 60 |
|
|
data_out_valid : out std_logic; -- indicates data out is valid
|
| 61 |
|
|
data_out_first : out std_logic; -- with data out valid indicates the first byte of a frame
|
| 62 |
|
|
data_out_last : out std_logic; -- with data out valid indicates the last byte of a frame
|
| 63 |
|
|
data_out : out std_logic_vector (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
| 64 |
|
|
-- system signals
|
| 65 |
|
|
our_mac_address : in STD_LOGIC_VECTOR (47 downto 0);
|
| 66 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
| 67 |
|
|
control : in arp_control_type;
|
| 68 |
|
|
req_count : out STD_LOGIC_VECTOR(7 downto 0) -- count of arp pkts received
|
| 69 |
|
|
);
|
| 70 |
|
|
end arpv2;
|
| 71 |
|
|
|
| 72 |
|
|
architecture structural of arpv2 is
|
| 73 |
|
|
|
| 74 |
|
|
COMPONENT arp_req
|
| 75 |
|
|
generic (
|
| 76 |
|
|
CLOCK_FREQ : integer := 125000000; -- freq of data_in_clk -- needed to timout cntr
|
| 77 |
|
|
ARP_TIMEOUT : integer := 60; -- ARP response timeout (s)
|
| 78 |
|
|
ARP_MAX_PKT_TMO : integer := 5 -- # wrong nwk pkts received before set error
|
| 79 |
|
|
);
|
| 80 |
|
|
Port (
|
| 81 |
|
|
-- lookup request signals
|
| 82 |
|
|
arp_req_req : in arp_req_req_type; -- request for a translation from IP to MAC
|
| 83 |
|
|
arp_req_rslt : out arp_req_rslt_type; -- the result
|
| 84 |
|
|
-- external arp store signals
|
| 85 |
|
|
arp_store_req : out arp_store_rdrequest_t; -- requesting a lookup or store
|
| 86 |
|
|
arp_store_result : in arp_store_result_t; -- the result
|
| 87 |
|
|
-- network request signals
|
| 88 |
|
|
arp_nwk_req : out arp_nwk_request_t; -- requesting resolution via the network
|
| 89 |
|
|
arp_nwk_result : in arp_nwk_result_t; -- the result
|
| 90 |
|
|
-- system signals
|
| 91 |
|
|
clear_cache : in std_logic; -- clear the internal cache
|
| 92 |
|
|
clk : in std_logic;
|
| 93 |
|
|
reset : in STD_LOGIC
|
| 94 |
|
|
);
|
| 95 |
|
|
END COMPONENT;
|
| 96 |
|
|
|
| 97 |
|
|
COMPONENT arp_tx
|
| 98 |
|
|
PORT(
|
| 99 |
|
|
-- control signals
|
| 100 |
|
|
send_I_have : in std_logic; -- pulse will be latched
|
| 101 |
|
|
arp_entry : in arp_entry_t; -- arp target for I_have req (will be latched)
|
| 102 |
|
|
send_who_has : in std_logic; -- pulse will be latched
|
| 103 |
|
|
ip_entry : in STD_LOGIC_VECTOR (31 downto 0); -- ip target for who_has req (will be latched)
|
| 104 |
|
|
-- MAC layer TX signals
|
| 105 |
|
|
mac_tx_req : out std_logic; -- indicates that ip wants access to channel (stays up for as long as tx)
|
| 106 |
|
|
mac_tx_granted : in std_logic; -- indicates that access to channel has been granted
|
| 107 |
|
|
data_out_ready : in std_logic; -- indicates system ready to consume data
|
| 108 |
|
|
data_out_valid : out std_logic; -- indicates data out is valid
|
| 109 |
|
|
data_out_first : out std_logic; -- with data out valid indicates the first byte of a frame
|
| 110 |
|
|
data_out_last : out std_logic; -- with data out valid indicates the last byte of a frame
|
| 111 |
|
|
data_out : out std_logic_vector (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
| 112 |
|
|
-- system signals
|
| 113 |
|
|
our_mac_address : in STD_LOGIC_VECTOR (47 downto 0);
|
| 114 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
| 115 |
|
|
tx_clk : in std_logic;
|
| 116 |
|
|
reset : in std_logic
|
| 117 |
|
|
);
|
| 118 |
|
|
END COMPONENT;
|
| 119 |
|
|
|
| 120 |
|
|
COMPONENT arp_rx
|
| 121 |
|
|
PORT(
|
| 122 |
|
|
-- MAC layer RX signals
|
| 123 |
|
|
data_in : in STD_LOGIC_VECTOR (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
| 124 |
|
|
data_in_valid : in STD_LOGIC; -- indicates data_in valid on clock
|
| 125 |
|
|
data_in_last : in STD_LOGIC; -- indicates last data in frame
|
| 126 |
|
|
-- ARP output signals
|
| 127 |
|
|
recv_who_has : out std_logic; -- pulse will be latched
|
| 128 |
|
|
arp_entry_for_who_has : out arp_entry_t; -- target for who_has msg (Iie, who to reply to)
|
| 129 |
|
|
recv_I_have : out std_logic; -- pulse will be latched
|
| 130 |
|
|
arp_entry_for_I_have : out arp_entry_t; -- arp target for I_have msg
|
| 131 |
|
|
-- control and status signals
|
| 132 |
|
|
req_count : out STD_LOGIC_VECTOR(7 downto 0); -- count of arp pkts received
|
| 133 |
|
|
-- system signals
|
| 134 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
| 135 |
|
|
rx_clk : in std_logic;
|
| 136 |
|
|
reset : in STD_LOGIC
|
| 137 |
|
|
);
|
| 138 |
|
|
END COMPONENT;
|
| 139 |
|
|
|
| 140 |
|
|
|
| 141 |
|
|
COMPONENT arp_store_br
|
| 142 |
|
|
generic (
|
| 143 |
|
|
MAX_ARP_ENTRIES : integer := 255 -- max entries in the store
|
| 144 |
|
|
);
|
| 145 |
|
|
Port (
|
| 146 |
|
|
-- read signals
|
| 147 |
|
|
read_req : in arp_store_rdrequest_t; -- requesting a lookup or store
|
| 148 |
|
|
read_result : out arp_store_result_t; -- the result
|
| 149 |
|
|
-- write signals
|
| 150 |
|
|
write_req : in arp_store_wrrequest_t; -- requesting a lookup or store
|
| 151 |
|
|
-- control and status signals
|
| 152 |
|
|
clear_store : in std_logic; -- erase all entries
|
| 153 |
|
|
entry_count : out unsigned(7 downto 0); -- how many entries currently in store
|
| 154 |
|
|
-- system signals
|
| 155 |
|
|
clk : in std_logic;
|
| 156 |
|
|
reset : in STD_LOGIC
|
| 157 |
|
|
);
|
| 158 |
|
|
END COMPONENT;
|
| 159 |
|
|
|
| 160 |
|
|
COMPONENT arp_sync
|
| 161 |
|
|
Port (
|
| 162 |
|
|
-- REQ to TX
|
| 163 |
|
|
arp_nwk_req : in arp_nwk_request_t; -- request for a translation from IP to MAC
|
| 164 |
|
|
send_who_has : out std_logic;
|
| 165 |
|
|
ip_entry : out STD_LOGIC_VECTOR (31 downto 0);
|
| 166 |
|
|
-- RX to TX
|
| 167 |
|
|
recv_who_has : in std_logic; -- this is for us, we will respond
|
| 168 |
|
|
arp_entry_for_who_has : in arp_entry_t;
|
| 169 |
|
|
send_I_have : out std_logic;
|
| 170 |
|
|
arp_entry : out arp_entry_t;
|
| 171 |
|
|
-- RX to REQ
|
| 172 |
|
|
I_have_received : in std_logic;
|
| 173 |
|
|
nwk_result_status : out arp_nwk_rslt_t;
|
| 174 |
|
|
-- System Signals
|
| 175 |
|
|
rx_clk : in std_logic;
|
| 176 |
|
|
tx_clk : in std_logic;
|
| 177 |
|
|
reset : in std_logic
|
| 178 |
|
|
);
|
| 179 |
|
|
END COMPONENT;
|
| 180 |
|
|
|
| 181 |
|
|
|
| 182 |
|
|
-- interconnect REQ -> ARP_TX
|
| 183 |
|
|
signal arp_nwk_req_int : arp_nwk_request_t; -- tx req from REQ
|
| 184 |
|
|
|
| 185 |
|
|
signal send_I_have_int : std_logic;
|
| 186 |
|
|
signal arp_entry_int : arp_entry_t;
|
| 187 |
|
|
signal send_who_has_int : std_logic;
|
| 188 |
|
|
signal ip_entry_int : STD_LOGIC_VECTOR (31 downto 0);
|
| 189 |
|
|
|
| 190 |
|
|
-- interconnect REQ <-> ARP_STORE
|
| 191 |
|
|
signal arp_store_req_int : arp_store_rdrequest_t; -- lookup request
|
| 192 |
|
|
signal arp_store_result_int: arp_store_result_t; -- lookup result
|
| 193 |
|
|
|
| 194 |
|
|
-- interconnect ARP_RX -> REQ
|
| 195 |
|
|
signal nwk_result_status_int : arp_nwk_rslt_t; -- response from a TX req
|
| 196 |
|
|
|
| 197 |
|
|
-- interconnect ARP_RX -> ARP_STORE
|
| 198 |
|
|
signal recv_I_have_int : std_logic; -- path to store new arp entry
|
| 199 |
|
|
signal arp_entry_for_I_have_int: arp_entry_t;
|
| 200 |
|
|
|
| 201 |
|
|
-- interconnect ARP_RX -> ARP_TX
|
| 202 |
|
|
signal recv_who_has_int : std_logic; -- path for reply when we can anser
|
| 203 |
|
|
signal arp_entry_for_who_has_int : arp_entry_t; -- target for who_has msg (ie, who to reply to)
|
| 204 |
|
|
|
| 205 |
|
|
|
| 206 |
|
|
begin
|
| 207 |
|
|
|
| 208 |
|
|
|
| 209 |
|
|
req : arp_req
|
| 210 |
|
|
generic map (
|
| 211 |
|
|
CLOCK_FREQ => CLOCK_FREQ,
|
| 212 |
|
|
ARP_TIMEOUT => ARP_TIMEOUT,
|
| 213 |
|
|
ARP_MAX_PKT_TMO => ARP_MAX_PKT_TMO
|
| 214 |
|
|
)
|
| 215 |
|
|
PORT MAP (
|
| 216 |
|
|
-- lookup request signals
|
| 217 |
|
|
arp_req_req => arp_req_req,
|
| 218 |
|
|
arp_req_rslt => arp_req_rslt,
|
| 219 |
|
|
-- external arp store signals
|
| 220 |
|
|
arp_store_req => arp_store_req_int,
|
| 221 |
|
|
arp_store_result => arp_store_result_int,
|
| 222 |
|
|
-- network request signals
|
| 223 |
|
|
arp_nwk_req => arp_nwk_req_int,
|
| 224 |
|
|
arp_nwk_result.status => nwk_result_status_int,
|
| 225 |
|
|
arp_nwk_result.entry => arp_entry_for_I_have_int,
|
| 226 |
|
|
-- system signals
|
| 227 |
|
|
clear_cache => control.clear_cache,
|
| 228 |
|
|
clk => data_in_clk,
|
| 229 |
|
|
reset => reset
|
| 230 |
|
|
);
|
| 231 |
|
|
|
| 232 |
|
|
sync : arp_sync PORT MAP (
|
| 233 |
|
|
-- REQ to TX
|
| 234 |
|
|
arp_nwk_req => arp_nwk_req_int,
|
| 235 |
|
|
send_who_has => send_who_has_int,
|
| 236 |
|
|
ip_entry => ip_entry_int,
|
| 237 |
|
|
-- RX to TX
|
| 238 |
|
|
recv_who_has => recv_who_has_int,
|
| 239 |
|
|
arp_entry_for_who_has => arp_entry_for_who_has_int,
|
| 240 |
|
|
send_I_have => send_I_have_int,
|
| 241 |
|
|
arp_entry => arp_entry_int,
|
| 242 |
|
|
-- RX to REQ
|
| 243 |
|
|
I_have_received => recv_I_have_int,
|
| 244 |
|
|
nwk_result_status => nwk_result_status_int,
|
| 245 |
|
|
-- system
|
| 246 |
|
|
rx_clk => data_in_clk,
|
| 247 |
|
|
tx_clk => data_out_clk,
|
| 248 |
|
|
reset => reset
|
| 249 |
|
|
);
|
| 250 |
|
|
|
| 251 |
|
|
tx : arp_tx PORT MAP (
|
| 252 |
|
|
-- control signals
|
| 253 |
|
|
send_I_have => send_I_have_int,
|
| 254 |
|
|
arp_entry => arp_entry_int,
|
| 255 |
|
|
send_who_has => send_who_has_int,
|
| 256 |
|
|
ip_entry => ip_entry_int,
|
| 257 |
|
|
-- MAC layer TX signals
|
| 258 |
|
|
mac_tx_req => mac_tx_req,
|
| 259 |
|
|
mac_tx_granted => mac_tx_granted,
|
| 260 |
|
|
data_out_ready => data_out_ready,
|
| 261 |
|
|
data_out_valid => data_out_valid,
|
| 262 |
|
|
data_out_first => data_out_first,
|
| 263 |
|
|
data_out_last => data_out_last,
|
| 264 |
|
|
data_out => data_out,
|
| 265 |
|
|
-- system signals
|
| 266 |
|
|
our_ip_address => our_ip_address,
|
| 267 |
|
|
our_mac_address => our_mac_address,
|
| 268 |
|
|
tx_clk => data_out_clk,
|
| 269 |
|
|
reset => reset
|
| 270 |
|
|
);
|
| 271 |
|
|
|
| 272 |
|
|
rx : arp_rx PORT MAP (
|
| 273 |
|
|
-- MAC layer RX signals
|
| 274 |
|
|
data_in => data_in,
|
| 275 |
|
|
data_in_valid => data_in_valid,
|
| 276 |
|
|
data_in_last => data_in_last,
|
| 277 |
|
|
-- ARP output signals
|
| 278 |
|
|
recv_who_has => recv_who_has_int,
|
| 279 |
|
|
arp_entry_for_who_has=> arp_entry_for_who_has_int,
|
| 280 |
|
|
recv_I_have => recv_I_have_int,
|
| 281 |
|
|
arp_entry_for_I_have=> arp_entry_for_I_have_int,
|
| 282 |
|
|
-- control and status signals
|
| 283 |
|
|
req_count => req_count,
|
| 284 |
|
|
-- system signals
|
| 285 |
|
|
our_ip_address => our_ip_address,
|
| 286 |
|
|
rx_clk => data_in_clk,
|
| 287 |
|
|
reset => reset
|
| 288 |
|
|
);
|
| 289 |
|
|
|
| 290 |
|
|
store : arp_store_br
|
| 291 |
|
|
generic map (
|
| 292 |
|
|
MAX_ARP_ENTRIES => MAX_ARP_ENTRIES
|
| 293 |
|
|
)
|
| 294 |
|
|
PORT MAP (
|
| 295 |
|
|
-- read signals
|
| 296 |
|
|
read_req => arp_store_req_int,
|
| 297 |
|
|
read_result => arp_store_result_int,
|
| 298 |
|
|
-- write signals
|
| 299 |
|
|
write_req.req => recv_I_have_int,
|
| 300 |
|
|
write_req.entry => arp_entry_for_I_have_int,
|
| 301 |
|
|
-- control and status signals
|
| 302 |
|
|
clear_store => control.clear_cache,
|
| 303 |
|
|
entry_count => open,
|
| 304 |
|
|
-- system signals
|
| 305 |
|
|
clk => data_in_clk,
|
| 306 |
|
|
reset => reset
|
| 307 |
|
|
);
|
| 308 |
|
|
|
| 309 |
|
|
|
| 310 |
|
|
end structural;
|
| 311 |
|
|
|