1 ------------------------------------------------------------------------------- 2 -- File : EthMacPkg.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2015-09-21 5 -- Last update: 2016-10-20 6 ------------------------------------------------------------------------------- 7 -- Description: Ethernet MAC Package File 8 ------------------------------------------------------------------------------- 9 -- This file is part of 'SLAC Firmware Standard Library'. 10 -- It is subject to the license terms in the LICENSE.txt file found in the 11 -- top-level directory of this distribution and at: 12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 13 -- No part of 'SLAC Firmware Standard Library', including this file, 14 -- may be copied, modified, propagated, or distributed except according to 15 -- the terms contained in the LICENSE.txt file. 16 ------------------------------------------------------------------------------- 19 use ieee.std_logic_1164.
all;
20 use ieee.std_logic_unsigned.
all;
21 use ieee.std_logic_arith.
all;
28 --! @ingroup ethernet_EthMacCore 30 -- Default MAC is 01:03:00:56:44:00 34 constant ARP_TYPE_C : slv(15 downto 0) := x"0608";
-- EtherType = ARP = 0x0806 35 constant IPV4_TYPE_C : slv(15 downto 0) := x"0008";
-- EtherType = IPV4 = 0x0800 36 constant VLAN_TYPE_C : slv(15 downto 0) := x"0081";
-- EtherType = VLAN = 0x8100 38 -- IPV4 Protocol Constants 39 constant UDP_C : slv(7 downto 0) := x"11";
-- Protocol = UDP = 0x11 40 constant TCP_C : slv(7 downto 0) := x"06";
-- Protocol = TCP = 0x06 41 constant ICMP_C : slv(7 downto 0) := x"01";
-- Protocol = ICMP = 0x01 44 constant DHCP_CPORT : slv(15 downto 0) := x"4400";
-- Port = 68 = 0x0044 45 constant DHCP_SPORT : slv(15 downto 0) := x"4300";
-- Port = 67 = 0x0043 57 -- Ethernet AXI Stream Configuration 67 -- Generic XMAC Configuration 89 -- Generic XMAC Status 121 step => (others => '0'), 122 sum1 => (others => (others => '0')), 123 sum3 => (others => '0'), 124 sum5 => (others => '0'));
131 -- Summation/Accumulation Signals 135 hdr :
in Slv8Array(
19 downto 0); -- IPv4 Header
138 len :
in slv(
15 downto 0);
139 ibcsum :
in slv(
15 downto 0); -- TCP/UDP checksum
to compare
143 ipCsum :
inout slv(
15 downto 0);
145 csum :
inout slv(
15 downto 0));
147 end package EthMacPkg;
153 variable vec :
slv(15 downto 0);
154 variable retVar :
Slv16Array((portSize-
1) downto 0);
156 for i
in (portSize-
1) downto 0 loop 157 -- Convert the NaturalArray into 16-bit SLV 158 vec := toSlv
(portNum
(i
),
16);
159 -- Convert to big Endian 160 retVar
(i
)(15 downto 8) := vec
(7 downto 0);
161 retVar
(i
)(7 downto 0) := vec
(15 downto 8);
168 -- Summation/Accumulation Signals 172 hdr :
in Slv8Array(
19 downto 0); -- IPv4 Header
175 len :
in slv(
15 downto 0); -- TCP/Data
length 176 ibcsum :
in slv(
15 downto 0); -- TCP/UDP checksum
to compare
180 ipCsum :
inout slv(
15 downto 0);
182 csum :
inout slv(
15 downto 0))
is 186 variable hdrCsum :
slv(15 downto 0);
187 variable lenProt :
slv(31 downto 0);
191 variable sum2B :
slv(31 downto 0);
197 -- Convert to 32-bit (little Endian) words 198 lenProt := x"0000" & len;
199 for i
in 9 downto 0 loop 200 header
(i
) := x"00000000";
201 -- Check for inbound checksum 203 -- Mask off and Save Header Checksum 204 hdrCsum
(15 downto 8) := hdr
(2*i+
0);
205 hdrCsum
(7 downto 0) := hdr
(2*i+
1);
207 header
(i
)(15 downto 8) := hdr
(2*i+
0);
208 header
(i
)(7 downto 0) := hdr
(2*i+
1);
211 for i
in 7 downto 0 loop 212 data
(i
) := x"00000000";
213 -- Check tKeep for big Endian upper byte of 16-bit word 214 if tKeep((2*i
)+
0) = '
1'
then 215 data
(i
)(15 downto 8) :=
tData((8*
((2*i
)+
0))+
7 downto (8*
((2*i
)+
0))+
0);
217 -- Check tKeep for big Endian lower byte of 16-bit word 218 if tKeep((2*i
)+
1) = '
1'
then 219 data
(i
)(7 downto 0) :=
tData((8*
((2*i
)+
1))+
7 downto (8*
((2*i
)+
1))+
0);
224 v
(0).
step(0) := last;
225 v
(1).
step(0) := last;
226 for i
in 3 downto 0 loop 227 sum0A
(i
) := header
(2*i+
0) + header
(2*i+
1);
228 sum0B
(i
) := data
(2*i+
0) + data
(2*i+
1);
232 for i
in 1 downto 0 loop 233 v
(0).
sum1(i
) := sum0A
(2*i+
0) + sum0A
(2*i+
1);
234 v
(1).
sum1(i
) := sum0B
(2*i+
0) + sum0B
(2*i+
1);
240 sum2A
(0) := r
(0).
sum1(0) + r
(0).
sum1(1);
241 sum2A
(1) := header
(8) + header
(9);
242 sum2B := r
(1).
sum1(0) + r
(1).
sum1(1);
245 v
(0).
sum3 := sum2A
(0) + sum2A
(1);
247 -- Check if we need to reset the accumulator 248 if r
(0).
step(1) = '
1'
then 249 v
(1).
sum3 :=
(others => '
0'
);
251 -- Summation/Accumulation: Level3 260 for i
in 1 downto 0 loop 261 sum3A
(i
)(31 downto 16) := x"0000";
262 sum3A
(i
)(15 downto 0) :=
sum3(i
)(31 downto 16);
263 sum3B
(i
)(31 downto 16) := x"0000";
264 sum3B
(i
)(15 downto 0) :=
sum3(i
)(15 downto 0);
265 sum4
(i
) := sum3A
(i
) + sum3B
(i
);
269 for i
in 1 downto 0 loop 270 v
(i
).
sum5 := sum4
(i
)(31 downto 16) + sum4
(i
)(15 downto 0);
273 -- Perform 1's complement 276 ipCsum :=
not(r
(0).
sum5);
277 csum :=
not(r
(1).
sum5);
279 -- UDP checksum is calculated using one's complement arithmetic (RFC 793). 280 -- UDP has a special case where 0x0000 is reserved for "no checksum computed". 281 -- Thus 0x0000 is illegal and when calculated following the standard 282 -- algorithm, replaced with 0xFFFF. 283 if (udpDet = '
1'
) and (csum = x"0000"
) then 287 -- Check for valid inbound checksum 288 if (ipCsum = hdrCsum
) then 294 -- Check for UDP special case of 0x0000 checksum 295 if (udpDet = '
1'
) and (ibcsum = x"0000"
) then 297 -- check the standard checksum calculation 298 elsif (ibcsum = csum
) then 300 -- Else not a valid checksum 307 end package body EthMacPkg;
natural range 0 to 8 TDEST_BITS_C
array(natural range <> ) of slv( 31 downto 0) Slv32Array
Slv32Array( 1 downto 0) sum1
slv( 15 downto 0) := x"4300" DHCP_SPORT
Slv16Array EthPortArrayBigEndianportNum,portSize,
slv( 7 downto 0) := x"06" TCP_C
slv( 15 downto 0) := x"0008" IPV4_TYPE_C
integer := 3 EMAC_UDPERR_BIT_C
integer := 2 EMAC_TCPERR_BIT_C
natural range 1 to 16 TDATA_BYTES_C
EthMacStatusType :=(rxFifoDropCnt => '0',rxPauseCnt => '0',txPauseCnt => '0',rxCountEn => '0',rxOverFlow => '0',rxCrcErrorCnt => '0',txCountEn => '0',txUnderRunCnt => '0',txNotReadyCnt => '0') ETH_MAC_STATUS_INIT_C
slv( 15 downto 0) := x"4400" DHCP_CPORT
slv( EMAC_CSUM_PIPELINE_C downto 0) step
TkeepModeType TKEEP_MODE_C
slv( 15 downto 0) := x"0608" ARP_TYPE_C
natural range 0 to 8 TID_BITS_C
integer := 0 EMAC_FRAG_BIT_C
slv( 47 downto 0) macAddress
EthMacCsumAccumType :=(step =>( others => '0'),sum1 =>( others =>( others => '0')),sum3 =>( others => '0'),sum5 =>( others => '0')) ETH_MAC_CSUM_ACCUM_INIT_C
array(natural range <> ) of EthMacConfigType EthMacConfigArray
natural := 3 EMAC_CSUM_PIPELINE_C
array(natural range <> ) of positive PositiveArray
integer := 0 EMAC_EOFE_BIT_C
integer := 1 EMAC_SOF_BIT_C
TUserModeType TUSER_MODE_C
GetEthMacCsumudpDet,last,hdr,tKeep,tData,len,ibcsum,r,v,ipValid,ipCsum,valid,csum,
natural range 0 to 8 TUSER_BITS_C
array(natural range <> ) of slv( 15 downto 0) Slv16Array
slv( 15 downto 0) pauseTime
slv( 15 downto 0) := x"0081" VLAN_TYPE_C
slv( 7 downto 0) := x"11" UDP_C
slv( 47 downto 0) := x"020300564400" EMAC_ADDR_INIT_C
EthMacConfigType :=(macAddress => EMAC_ADDR_INIT_C,filtEnable => '1',pauseEnable => '1',pauseTime => x"00FF",ipCsumEn => '1',tcpCsumEn => '1',udpCsumEn => '1',dropOnPause => '0') ETH_MAC_CONFIG_INIT_C
integer := 1 EMAC_IPERR_BIT_C
array(natural range <> ) of slv( 7 downto 0) Slv8Array
array(natural range <> ) of EthMacStatusType EthMacStatusArray
AxiStreamConfigType :=(TSTRB_EN_C => false,TDATA_BYTES_C => 16,TDEST_BITS_C => 8,TID_BITS_C => 0,TKEEP_MODE_C => TKEEP_COMP_C,TUSER_BITS_C => 4,TUSER_MODE_C => TUSER_FIRST_LAST_C) EMAC_AXIS_CONFIG_C
array(natural range <> ) of EthMacCsumAccumType EthMacCsumAccumArray
slv( 7 downto 0) := x"01" ICMP_C