1 |
2 |
pjf |
----------------------------------------------------------------------------------
|
2 |
|
|
-- Company:
|
3 |
|
|
-- Engineer: Peter Fall
|
4 |
|
|
--
|
5 |
|
|
-- Create Date: 16:20:42 06/01/2011
|
6 |
|
|
-- Design Name:
|
7 |
|
|
-- Module Name: IPv4_TX - Behavioral
|
8 |
|
|
-- Project Name:
|
9 |
|
|
-- Target Devices:
|
10 |
|
|
-- Tool versions:
|
11 |
|
|
-- Description:
|
12 |
|
|
-- handle simple IP TX
|
13 |
|
|
-- doesnt handle segmentation
|
14 |
|
|
-- dest MAC addr resolution through ARP layer
|
15 |
|
|
-- Handle IPv4 protocol
|
16 |
|
|
-- Dependencies:
|
17 |
|
|
--
|
18 |
|
|
-- Revision:
|
19 |
|
|
-- Revision 0.01 - File Created
|
20 |
|
|
-- Revision 0.02 - fixed up setting of tx_result control defaults
|
21 |
4 |
pjf |
-- Revision 0.03 - Added data_out_first
|
22 |
2 |
pjf |
-- Additional Comments:
|
23 |
|
|
--
|
24 |
|
|
----------------------------------------------------------------------------------
|
25 |
|
|
library IEEE;
|
26 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
27 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
28 |
|
|
use work.axi.all;
|
29 |
|
|
use work.ipv4_types.all;
|
30 |
|
|
use work.arp_types.all;
|
31 |
|
|
|
32 |
|
|
entity IPv4_TX is
|
33 |
|
|
Port (
|
34 |
|
|
-- IP Layer signals
|
35 |
|
|
ip_tx_start : in std_logic;
|
36 |
|
|
ip_tx : in ipv4_tx_type; -- IP tx cxns
|
37 |
|
|
ip_tx_result : out std_logic_vector (1 downto 0); -- tx status (changes during transmission)
|
38 |
|
|
ip_tx_data_out_ready : out std_logic; -- indicates IP TX is ready to take data
|
39 |
|
|
|
40 |
|
|
-- system signals
|
41 |
|
|
clk : in STD_LOGIC; -- same clock used to clock mac data and ip data
|
42 |
|
|
reset : in STD_LOGIC;
|
43 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
44 |
|
|
our_mac_address : in std_logic_vector (47 downto 0);
|
45 |
|
|
-- ARP lookup signals
|
46 |
|
|
arp_req_req : out arp_req_req_type;
|
47 |
|
|
arp_req_rslt : in arp_req_rslt_type;
|
48 |
|
|
-- MAC layer TX signals
|
49 |
|
|
mac_tx_req : out std_logic; -- indicates that ip wants access to channel (stays up for as long as tx)
|
50 |
|
|
mac_tx_granted : in std_logic; -- indicates that access to channel has been granted
|
51 |
|
|
mac_data_out_ready : in std_logic; -- indicates system ready to consume data
|
52 |
|
|
mac_data_out_valid : out std_logic; -- indicates data out is valid
|
53 |
4 |
pjf |
mac_data_out_first : out std_logic; -- with data out valid indicates the first byte of a frame
|
54 |
2 |
pjf |
mac_data_out_last : out std_logic; -- with data out valid indicates the last byte of a frame
|
55 |
|
|
mac_data_out : out std_logic_vector (7 downto 0) -- ethernet frame (from dst mac addr through to last byte of frame)
|
56 |
|
|
);
|
57 |
|
|
end IPv4_TX;
|
58 |
|
|
|
59 |
|
|
architecture Behavioral of IPv4_TX is
|
60 |
|
|
|
61 |
|
|
type tx_state_type is (
|
62 |
|
|
IDLE,
|
63 |
|
|
WAIT_MAC, -- waiting for response from ARP for mac lookup
|
64 |
|
|
WAIT_CHN, -- waiting for tx access to MAC channel
|
65 |
|
|
SEND_ETH_HDR, -- sending the ethernet header
|
66 |
|
|
SEND_IP_HDR, -- sending the IP header
|
67 |
|
|
SEND_USER_DATA -- sending the users data
|
68 |
|
|
);
|
69 |
|
|
|
70 |
|
|
type crc_state_type is (IDLE,TOT_LEN,ID,FLAGS,TTL,CKS,SAH,SAL,DAH,DAL,FINAL,WAIT_END);
|
71 |
|
|
|
72 |
|
|
type count_mode_type is (RST, INCR, HOLD);
|
73 |
|
|
type settable_cnt_type is (RST, SET, INCR, HOLD);
|
74 |
|
|
type set_clr_type is (SET, CLR, HOLD);
|
75 |
|
|
|
76 |
|
|
-- Configuration
|
77 |
|
|
|
78 |
|
|
constant IP_TTL : std_logic_vector (7 downto 0) := x"80";
|
79 |
|
|
|
80 |
|
|
-- TX state variables
|
81 |
|
|
signal tx_state : tx_state_type;
|
82 |
|
|
signal tx_count : unsigned (11 downto 0);
|
83 |
|
|
signal tx_result_reg : std_logic_vector (1 downto 0);
|
84 |
|
|
signal tx_mac : std_logic_vector (47 downto 0);
|
85 |
|
|
signal tx_mac_chn_reqd : std_logic;
|
86 |
|
|
signal tx_hdr_cks : std_logic_vector (23 downto 0);
|
87 |
|
|
signal mac_lookup_req : std_logic;
|
88 |
|
|
signal crc_state : crc_state_type;
|
89 |
|
|
signal arp_req_ip_reg : std_logic_vector (31 downto 0);
|
90 |
|
|
signal mac_data_out_ready_reg : std_logic;
|
91 |
|
|
|
92 |
|
|
-- tx control signals
|
93 |
|
|
signal next_tx_state : tx_state_type;
|
94 |
|
|
signal set_tx_state : std_logic;
|
95 |
|
|
signal next_tx_result : std_logic_vector (1 downto 0);
|
96 |
|
|
signal set_tx_result : std_logic;
|
97 |
|
|
signal set_tx_mac : std_logic;
|
98 |
|
|
signal tx_count_val : unsigned (11 downto 0);
|
99 |
|
|
signal tx_count_mode : settable_cnt_type;
|
100 |
|
|
signal tx_data : std_logic_vector (7 downto 0);
|
101 |
|
|
signal set_last : std_logic;
|
102 |
|
|
signal set_chn_reqd : set_clr_type;
|
103 |
|
|
signal set_mac_lku_req : set_clr_type;
|
104 |
|
|
signal tx_data_valid : std_logic; -- indicates whether data is valid to tx or not
|
105 |
|
|
|
106 |
|
|
-- tx temp signals
|
107 |
|
|
signal total_length : std_logic_vector (15 downto 0); -- computed combinatorially from header size
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
FUNCTION inv_if_one(s1:std_logic_vector;en:std_logic) return std_logic_vector is
|
111 |
|
|
--this function inverts all the bits of a vector if
|
112 |
|
|
--'en' is '1'.
|
113 |
|
|
VARIABLE Z : std_logic_vector(s1'high downto s1'low);
|
114 |
|
|
BEGIN
|
115 |
|
|
FOR i IN (s1'low) to s1'high LOOP
|
116 |
|
|
Z(i) := en XOR s1(i);
|
117 |
|
|
END LOOP;
|
118 |
|
|
RETURN Z;
|
119 |
|
|
END inv_if_one; -- end function
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
-- IP datagram header format
|
123 |
|
|
--
|
124 |
|
|
-- 0 4 8 16 19 24 31
|
125 |
|
|
-- --------------------------------------------------------------------------------------------
|
126 |
|
|
-- | Version | *Header | Service Type | Total Length including header |
|
127 |
|
|
-- | (4) | Length | (ignored) | (in bytes) |
|
128 |
|
|
-- --------------------------------------------------------------------------------------------
|
129 |
|
|
-- | Identification | Flags | Fragment Offset |
|
130 |
|
|
-- | | | (in 32 bit words) |
|
131 |
|
|
-- --------------------------------------------------------------------------------------------
|
132 |
|
|
-- | Time To Live | Protocol | Header Checksum |
|
133 |
|
|
-- | (ignored) | | |
|
134 |
|
|
-- --------------------------------------------------------------------------------------------
|
135 |
|
|
-- | Source IP Address |
|
136 |
|
|
-- | |
|
137 |
|
|
-- --------------------------------------------------------------------------------------------
|
138 |
|
|
-- | Destination IP Address |
|
139 |
|
|
-- | |
|
140 |
|
|
-- --------------------------------------------------------------------------------------------
|
141 |
|
|
-- | Options (if any - ignored) | Padding |
|
142 |
|
|
-- | | (if needed) |
|
143 |
|
|
-- --------------------------------------------------------------------------------------------
|
144 |
|
|
-- | Data |
|
145 |
|
|
-- | |
|
146 |
|
|
-- --------------------------------------------------------------------------------------------
|
147 |
|
|
-- | .... |
|
148 |
|
|
-- | |
|
149 |
|
|
-- --------------------------------------------------------------------------------------------
|
150 |
|
|
--
|
151 |
|
|
-- * - in 32 bit words
|
152 |
|
|
|
153 |
|
|
begin
|
154 |
|
|
-----------------------------------------------------------------------
|
155 |
|
|
-- combinatorial process to implement FSM and determine control signals
|
156 |
|
|
-----------------------------------------------------------------------
|
157 |
|
|
|
158 |
|
|
tx_combinatorial : process(
|
159 |
|
|
-- input signals
|
160 |
|
|
ip_tx_start, ip_tx, clk, our_ip_address, our_mac_address, arp_req_rslt,
|
161 |
|
|
mac_tx_granted, mac_data_out_ready,
|
162 |
|
|
-- state variables
|
163 |
|
|
tx_state, tx_count, tx_result_reg, tx_mac, tx_mac_chn_reqd,
|
164 |
|
|
mac_lookup_req, tx_hdr_cks, arp_req_ip_reg, mac_data_out_ready_reg,
|
165 |
|
|
-- control signals
|
166 |
|
|
next_tx_state, set_tx_state, next_tx_result, set_tx_result, set_tx_mac, tx_count_mode,
|
167 |
|
|
tx_data, set_last, set_chn_reqd, set_mac_lku_req, total_length,
|
168 |
|
|
tx_data_valid, tx_count_val
|
169 |
|
|
)
|
170 |
|
|
begin
|
171 |
|
|
-- set output followers
|
172 |
|
|
ip_tx_result <= tx_result_reg;
|
173 |
|
|
mac_tx_req <= tx_mac_chn_reqd;
|
174 |
|
|
arp_req_req.lookup_req <= mac_lookup_req;
|
175 |
|
|
arp_req_req.ip <= arp_req_ip_reg;
|
176 |
|
|
|
177 |
4 |
pjf |
-- set initial values for combinatorial outputs
|
178 |
|
|
mac_data_out_first <= '0';
|
179 |
|
|
|
180 |
2 |
pjf |
case tx_state is
|
181 |
|
|
when SEND_ETH_HDR | SEND_IP_HDR =>
|
182 |
|
|
mac_data_out <= tx_data;
|
183 |
|
|
tx_data_valid <= mac_data_out_ready; -- generated internally
|
184 |
|
|
mac_data_out_last <= set_last;
|
185 |
|
|
|
186 |
|
|
when SEND_USER_DATA =>
|
187 |
|
|
mac_data_out <= ip_tx.data.data_out;
|
188 |
|
|
tx_data_valid <= ip_tx.data.data_out_valid;
|
189 |
|
|
mac_data_out_last <= ip_tx.data.data_out_last;
|
190 |
|
|
|
191 |
|
|
when others =>
|
192 |
|
|
mac_data_out <= (others => '0');
|
193 |
|
|
tx_data_valid <= '0'; -- not transmitting during this phase
|
194 |
|
|
mac_data_out_last <= '0';
|
195 |
|
|
end case;
|
196 |
|
|
|
197 |
|
|
mac_data_out_valid <= tx_data_valid and mac_data_out_ready;
|
198 |
|
|
|
199 |
|
|
-- set signal defaults
|
200 |
|
|
next_tx_state <= IDLE;
|
201 |
|
|
set_tx_state <= '0';
|
202 |
|
|
tx_count_mode <= HOLD;
|
203 |
|
|
tx_data <= x"00";
|
204 |
|
|
set_last <= '0';
|
205 |
|
|
set_tx_mac <= '0';
|
206 |
|
|
set_chn_reqd <= HOLD;
|
207 |
|
|
set_mac_lku_req <= HOLD;
|
208 |
|
|
next_tx_result <= IPTX_RESULT_NONE;
|
209 |
|
|
set_tx_result <= '0';
|
210 |
|
|
tx_count_val <= (others => '0');
|
211 |
|
|
|
212 |
|
|
-- set temp signals
|
213 |
|
|
total_length <= std_logic_vector(unsigned(ip_tx.hdr.data_length) + 20); -- total length = user data length + header length (bytes)
|
214 |
|
|
|
215 |
|
|
-- TX FSM
|
216 |
|
|
case tx_state is
|
217 |
|
|
when IDLE =>
|
218 |
|
|
ip_tx_data_out_ready <= '0'; -- in this state, we are unable to accept user data for tx
|
219 |
|
|
tx_count_mode <= RST;
|
220 |
|
|
set_chn_reqd <= CLR;
|
221 |
|
|
if ip_tx_start = '1' then
|
222 |
|
|
-- check header count for error if too high
|
223 |
|
|
if unsigned(ip_tx.hdr.data_length) > 1480 then
|
224 |
|
|
next_tx_result <= IPTX_RESULT_ERR;
|
225 |
|
|
set_tx_result <= '1';
|
226 |
|
|
else
|
227 |
|
|
-- TODO - check if we already have the mac addr for this ip, if so, bypass the WAIT_MAC state
|
228 |
|
|
|
229 |
|
|
-- req the mac address for this ip
|
230 |
|
|
set_mac_lku_req <= SET;
|
231 |
|
|
next_tx_result <= IPTX_RESULT_SENDING;
|
232 |
|
|
set_tx_result <= '1';
|
233 |
|
|
next_tx_state <= WAIT_MAC;
|
234 |
|
|
set_tx_state <= '1';
|
235 |
|
|
end if;
|
236 |
|
|
else
|
237 |
|
|
set_mac_lku_req <= CLR;
|
238 |
|
|
end if;
|
239 |
|
|
|
240 |
|
|
when WAIT_MAC =>
|
241 |
|
|
ip_tx_data_out_ready <= '0'; -- in this state, we are unable to accept user data for tx
|
242 |
|
|
if arp_req_rslt.got_mac = '1' then
|
243 |
|
|
-- save the MAC we got back from the ARP lookup
|
244 |
|
|
set_tx_mac <= '1';
|
245 |
|
|
set_chn_reqd <= SET;
|
246 |
|
|
set_mac_lku_req <= CLR;
|
247 |
|
|
-- check for optimise when already have the channel
|
248 |
|
|
if mac_tx_granted = '1' then
|
249 |
|
|
-- ready to send data
|
250 |
|
|
next_tx_state <= SEND_ETH_HDR;
|
251 |
|
|
set_tx_state <= '1';
|
252 |
|
|
else
|
253 |
|
|
next_tx_state <= WAIT_CHN;
|
254 |
|
|
set_tx_state <= '1';
|
255 |
|
|
end if;
|
256 |
|
|
elsif arp_req_rslt.got_err = '1' then
|
257 |
|
|
set_mac_lku_req <= CLR;
|
258 |
|
|
next_tx_result <= IPTX_RESULT_ERR;
|
259 |
|
|
set_tx_result <= '1';
|
260 |
|
|
next_tx_state <= IDLE;
|
261 |
|
|
set_tx_state <= '1';
|
262 |
|
|
end if;
|
263 |
|
|
|
264 |
|
|
when WAIT_CHN =>
|
265 |
|
|
ip_tx_data_out_ready <= '0'; -- in this state, we are unable to accept user data for tx
|
266 |
|
|
if mac_tx_granted = '1' then
|
267 |
|
|
-- ready to send data
|
268 |
|
|
next_tx_state <= SEND_ETH_HDR;
|
269 |
|
|
set_tx_state <= '1';
|
270 |
|
|
end if;
|
271 |
|
|
-- probably should handle a timeout here
|
272 |
|
|
|
273 |
|
|
when SEND_ETH_HDR =>
|
274 |
|
|
ip_tx_data_out_ready <= '0'; -- in this state, we are unable to accept user data for tx
|
275 |
|
|
if mac_data_out_ready = '1' then
|
276 |
|
|
if tx_count = x"00d" then
|
277 |
|
|
tx_count_mode <= RST;
|
278 |
|
|
next_tx_state <= SEND_IP_HDR;
|
279 |
|
|
set_tx_state <= '1';
|
280 |
|
|
else
|
281 |
|
|
tx_count_mode <= INCR;
|
282 |
|
|
end if;
|
283 |
|
|
case tx_count is
|
284 |
4 |
pjf |
when x"000" =>
|
285 |
|
|
mac_data_out_first <= mac_data_out_ready;
|
286 |
|
|
tx_data <= tx_mac (47 downto 40); -- trg = mac from ARP lookup
|
287 |
|
|
|
288 |
2 |
pjf |
when x"001" => tx_data <= tx_mac (39 downto 32);
|
289 |
|
|
when x"002" => tx_data <= tx_mac (31 downto 24);
|
290 |
|
|
when x"003" => tx_data <= tx_mac (23 downto 16);
|
291 |
|
|
when x"004" => tx_data <= tx_mac (15 downto 8);
|
292 |
|
|
when x"005" => tx_data <= tx_mac (7 downto 0);
|
293 |
|
|
when x"006" => tx_data <= our_mac_address (47 downto 40); -- src = our mac
|
294 |
|
|
when x"007" => tx_data <= our_mac_address (39 downto 32);
|
295 |
|
|
when x"008" => tx_data <= our_mac_address (31 downto 24);
|
296 |
|
|
when x"009" => tx_data <= our_mac_address (23 downto 16);
|
297 |
|
|
when x"00a" => tx_data <= our_mac_address (15 downto 8);
|
298 |
|
|
when x"00b" => tx_data <= our_mac_address (7 downto 0);
|
299 |
|
|
when x"00c" => tx_data <= x"08"; -- pkt type = 0800 : IP
|
300 |
|
|
when x"00d" => tx_data <= x"00";
|
301 |
|
|
when others =>
|
302 |
|
|
-- shouldnt get here - handle as error
|
303 |
|
|
next_tx_result <= IPTX_RESULT_ERR;
|
304 |
|
|
set_tx_result <= '1';
|
305 |
|
|
next_tx_state <= IDLE;
|
306 |
|
|
set_tx_state <= '1';
|
307 |
|
|
end case;
|
308 |
|
|
end if;
|
309 |
|
|
|
310 |
|
|
when SEND_IP_HDR =>
|
311 |
|
|
ip_tx_data_out_ready <= '0'; -- in this state, we are unable to accept user data for tx
|
312 |
|
|
if mac_data_out_ready = '1' then
|
313 |
|
|
if tx_count = x"013" then
|
314 |
|
|
tx_count_val <= x"001";
|
315 |
|
|
tx_count_mode <= SET;
|
316 |
|
|
next_tx_state <= SEND_USER_DATA;
|
317 |
|
|
set_tx_state <= '1';
|
318 |
|
|
else
|
319 |
|
|
tx_count_mode <= INCR;
|
320 |
|
|
end if;
|
321 |
|
|
case tx_count is
|
322 |
|
|
when x"000" => tx_data <= x"45"; -- v4, 5 words in hdr
|
323 |
|
|
when x"001" => tx_data <= x"00"; -- service type
|
324 |
|
|
when x"002" => tx_data <= total_length (15 downto 8); -- total length
|
325 |
|
|
when x"003" => tx_data <= total_length (7 downto 0);
|
326 |
|
|
when x"004" => tx_data <= x"00"; -- identification
|
327 |
|
|
when x"005" => tx_data <= x"00";
|
328 |
|
|
when x"006" => tx_data <= x"00"; -- flags and fragment offset
|
329 |
|
|
when x"007" => tx_data <= x"00";
|
330 |
|
|
when x"008" => tx_data <= IP_TTL; -- TTL
|
331 |
|
|
when x"009" => tx_data <= ip_tx.hdr.protocol; -- protocol
|
332 |
|
|
when x"00a" => tx_data <= tx_hdr_cks (15 downto 8); -- HDR checksum
|
333 |
|
|
when x"00b" => tx_data <= tx_hdr_cks (7 downto 0); -- HDR checksum
|
334 |
|
|
when x"00c" => tx_data <= our_ip_address (31 downto 24); -- src ip
|
335 |
|
|
when x"00d" => tx_data <= our_ip_address (23 downto 16);
|
336 |
|
|
when x"00e" => tx_data <= our_ip_address (15 downto 8);
|
337 |
|
|
when x"00f" => tx_data <= our_ip_address (7 downto 0);
|
338 |
|
|
when x"010" => tx_data <= ip_tx.hdr.dst_ip_addr (31 downto 24); -- dst ip
|
339 |
|
|
when x"011" => tx_data <= ip_tx.hdr.dst_ip_addr (23 downto 16);
|
340 |
|
|
when x"012" => tx_data <= ip_tx.hdr.dst_ip_addr (15 downto 8);
|
341 |
|
|
when x"013" => tx_data <= ip_tx.hdr.dst_ip_addr (7 downto 0);
|
342 |
|
|
when others =>
|
343 |
|
|
-- shouldnt get here - handle as error
|
344 |
|
|
next_tx_result <= IPTX_RESULT_ERR;
|
345 |
|
|
set_tx_result <= '1';
|
346 |
|
|
next_tx_state <= IDLE;
|
347 |
|
|
set_tx_state <= '1';
|
348 |
|
|
end case;
|
349 |
|
|
end if;
|
350 |
|
|
|
351 |
|
|
when SEND_USER_DATA =>
|
352 |
|
|
ip_tx_data_out_ready <= mac_data_out_ready and mac_data_out_ready_reg; -- in this state, we are always ready to accept user data for tx
|
353 |
|
|
if mac_data_out_ready = '1' then
|
354 |
|
|
if ip_tx.data.data_out_valid = '1' or tx_count = x"000" then
|
355 |
|
|
-- only increment if ready and valid has been subsequently established, otherwise data count moves on too fast
|
356 |
|
|
if unsigned(tx_count) = unsigned(ip_tx.hdr.data_length) then
|
357 |
|
|
set_last <= '1';
|
358 |
|
|
set_chn_reqd <= CLR;
|
359 |
|
|
tx_data <= ip_tx.data.data_out;
|
360 |
|
|
next_tx_result <= IPTX_RESULT_SENT;
|
361 |
|
|
set_tx_result <= '1';
|
362 |
|
|
next_tx_state <= IDLE;
|
363 |
|
|
set_tx_state <= '1';
|
364 |
|
|
else
|
365 |
|
|
tx_count_mode <= INCR;
|
366 |
|
|
tx_data <= ip_tx.data.data_out;
|
367 |
|
|
end if;
|
368 |
|
|
end if;
|
369 |
|
|
end if;
|
370 |
|
|
|
371 |
|
|
end case;
|
372 |
|
|
end process;
|
373 |
|
|
|
374 |
|
|
-----------------------------------------------------------------------------
|
375 |
|
|
-- sequential process to action control signals and change states and outputs
|
376 |
|
|
-----------------------------------------------------------------------------
|
377 |
|
|
|
378 |
|
|
tx_sequential : process (clk,reset,mac_data_out_ready_reg)
|
379 |
|
|
begin
|
380 |
|
|
if rising_edge(clk) then
|
381 |
|
|
mac_data_out_ready_reg <= mac_data_out_ready;
|
382 |
|
|
else
|
383 |
|
|
mac_data_out_ready_reg <= mac_data_out_ready_reg;
|
384 |
|
|
end if;
|
385 |
|
|
|
386 |
|
|
if rising_edge(clk) then
|
387 |
|
|
if reset = '1' then
|
388 |
|
|
-- reset state variables
|
389 |
|
|
tx_state <= IDLE;
|
390 |
|
|
tx_count <= x"000";
|
391 |
|
|
tx_result_reg <= IPTX_RESULT_NONE;
|
392 |
|
|
tx_mac <= (others => '0');
|
393 |
|
|
tx_mac_chn_reqd <= '0';
|
394 |
4 |
pjf |
mac_lookup_req <= '0';
|
395 |
|
|
|
396 |
2 |
pjf |
else
|
397 |
|
|
-- Next tx_state processing
|
398 |
|
|
if set_tx_state = '1' then
|
399 |
|
|
tx_state <= next_tx_state;
|
400 |
|
|
else
|
401 |
|
|
tx_state <= tx_state;
|
402 |
|
|
end if;
|
403 |
|
|
|
404 |
|
|
-- tx result processing
|
405 |
|
|
if set_tx_result = '1' then
|
406 |
|
|
tx_result_reg <= next_tx_result;
|
407 |
|
|
else
|
408 |
|
|
tx_result_reg <= tx_result_reg;
|
409 |
|
|
end if;
|
410 |
|
|
|
411 |
|
|
-- control arp lookup request
|
412 |
|
|
case set_mac_lku_req is
|
413 |
|
|
when SET =>
|
414 |
|
|
arp_req_ip_reg <= ip_tx.hdr.dst_ip_addr;
|
415 |
|
|
mac_lookup_req <= '1';
|
416 |
|
|
|
417 |
|
|
when CLR =>
|
418 |
|
|
mac_lookup_req <= '0';
|
419 |
|
|
arp_req_ip_reg <= arp_req_ip_reg;
|
420 |
|
|
|
421 |
|
|
when HOLD =>
|
422 |
|
|
mac_lookup_req <= mac_lookup_req;
|
423 |
|
|
arp_req_ip_reg <= arp_req_ip_reg;
|
424 |
|
|
end case;
|
425 |
|
|
|
426 |
|
|
-- save MAC
|
427 |
|
|
if set_tx_mac = '1' then
|
428 |
|
|
tx_mac <= arp_req_rslt.mac;
|
429 |
|
|
else
|
430 |
|
|
tx_mac <= tx_mac;
|
431 |
|
|
end if;
|
432 |
|
|
|
433 |
|
|
-- control access request to mac tx chn
|
434 |
|
|
case set_chn_reqd is
|
435 |
|
|
when SET => tx_mac_chn_reqd <= '1';
|
436 |
|
|
when CLR => tx_mac_chn_reqd <= '0';
|
437 |
|
|
when HOLD => tx_mac_chn_reqd <= tx_mac_chn_reqd;
|
438 |
|
|
end case;
|
439 |
|
|
|
440 |
|
|
-- tx_count processing
|
441 |
|
|
case tx_count_mode is
|
442 |
|
|
when RST => tx_count <= x"000";
|
443 |
|
|
when SET => tx_count <= tx_count_val;
|
444 |
|
|
when INCR => tx_count <= tx_count + 1;
|
445 |
|
|
when HOLD => tx_count <= tx_count;
|
446 |
|
|
end case;
|
447 |
|
|
|
448 |
|
|
end if;
|
449 |
|
|
end if;
|
450 |
|
|
end process;
|
451 |
|
|
|
452 |
|
|
-----------------------------------------------------------------------------
|
453 |
|
|
-- Process to calculate CRC in parallel with pkt out processing
|
454 |
|
|
-- this process must yield a valid CRC before it is required to be used in the hdr
|
455 |
|
|
-----------------------------------------------------------------------------
|
456 |
|
|
|
457 |
|
|
crc : process (clk,reset)
|
458 |
|
|
begin
|
459 |
|
|
if rising_edge(clk) then
|
460 |
|
|
case crc_state is
|
461 |
|
|
when IDLE =>
|
462 |
|
|
if ip_tx_start = '1' then
|
463 |
|
|
tx_hdr_cks <= x"004500"; -- vers & hdr len & service
|
464 |
|
|
crc_state <= TOT_LEN;
|
465 |
|
|
end if;
|
466 |
|
|
|
467 |
|
|
when TOT_LEN =>
|
468 |
|
|
tx_hdr_cks <= std_logic_vector (unsigned(tx_hdr_cks) + unsigned(total_length));
|
469 |
|
|
crc_state <= ID;
|
470 |
|
|
|
471 |
|
|
when ID =>
|
472 |
|
|
tx_hdr_cks <= tx_hdr_cks;
|
473 |
|
|
crc_state <= FLAGS;
|
474 |
|
|
|
475 |
|
|
when FLAGS =>
|
476 |
|
|
tx_hdr_cks <= tx_hdr_cks;
|
477 |
|
|
crc_state <= TTL;
|
478 |
|
|
|
479 |
|
|
when TTL =>
|
480 |
|
|
tx_hdr_cks <= std_logic_vector (unsigned(tx_hdr_cks) + unsigned(IP_TTL & ip_tx.hdr.protocol));
|
481 |
|
|
crc_state <= CKS;
|
482 |
|
|
|
483 |
|
|
when CKS =>
|
484 |
|
|
tx_hdr_cks <= tx_hdr_cks;
|
485 |
|
|
crc_state <= SAH;
|
486 |
|
|
|
487 |
|
|
when SAH =>
|
488 |
|
|
tx_hdr_cks <= std_logic_vector (unsigned(tx_hdr_cks) + unsigned(our_ip_address(31 downto 16)));
|
489 |
|
|
crc_state <= SAL;
|
490 |
|
|
|
491 |
|
|
when SAL =>
|
492 |
|
|
tx_hdr_cks <= std_logic_vector (unsigned(tx_hdr_cks) + unsigned(our_ip_address(15 downto 0)));
|
493 |
|
|
crc_state <= DAH;
|
494 |
|
|
|
495 |
|
|
when DAH =>
|
496 |
|
|
tx_hdr_cks <= std_logic_vector (unsigned(tx_hdr_cks) + unsigned(ip_tx.hdr.dst_ip_addr(31 downto 16)));
|
497 |
|
|
crc_state <= DAL;
|
498 |
|
|
|
499 |
|
|
when DAL =>
|
500 |
|
|
tx_hdr_cks <= std_logic_vector (unsigned(tx_hdr_cks) + unsigned(ip_tx.hdr.dst_ip_addr(15 downto 0)));
|
501 |
|
|
crc_state <= FINAL;
|
502 |
|
|
|
503 |
|
|
when FINAL =>
|
504 |
|
|
tx_hdr_cks <= inv_if_one(std_logic_vector (unsigned(tx_hdr_cks) + unsigned(tx_hdr_cks(23 downto 16))),'1');
|
505 |
|
|
crc_state <= WAIT_END;
|
506 |
|
|
|
507 |
|
|
when WAIT_END =>
|
508 |
|
|
tx_hdr_cks <= tx_hdr_cks;
|
509 |
|
|
if ip_tx_start = '0' then
|
510 |
|
|
crc_state <= IDLE;
|
511 |
|
|
else
|
512 |
|
|
crc_state <= WAIT_END;
|
513 |
|
|
end if;
|
514 |
|
|
|
515 |
|
|
|
516 |
|
|
end case;
|
517 |
|
|
end if;
|
518 |
|
|
end process;
|
519 |
|
|
|
520 |
|
|
|
521 |
|
|
end Behavioral;
|
522 |
|
|
|