common: Define eth_min_frame_length, eth_fcs_length and arp_min_length and use them in core/mac/model.
This commit is contained in:
parent
944849c3cf
commit
6204994bad
|
@ -18,14 +18,15 @@ from litex.soc.interconnect.packet import Header, HeaderField
|
|||
|
||||
# Ethernet Constants -------------------------------------------------------------------------------
|
||||
|
||||
eth_mtu = 1530
|
||||
eth_min_len = 46
|
||||
eth_interpacket_gap = 12
|
||||
eth_preamble = 0xd555555555555555
|
||||
buffer_depth = 2**log2_int(eth_mtu, need_pow2=False)
|
||||
eth_mtu = 1530
|
||||
eth_min_frame_length = 64
|
||||
eth_fcs_length = 4
|
||||
eth_interpacket_gap = 12
|
||||
eth_preamble = 0xd555555555555555
|
||||
buffer_depth = 2**log2_int(eth_mtu, need_pow2=False)
|
||||
|
||||
ethernet_type_ip = 0x800
|
||||
ethernet_type_arp = 0x806
|
||||
ethernet_type_ip = 0x800
|
||||
ethernet_type_arp = 0x806
|
||||
|
||||
# MAC Constants/Header -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -43,6 +44,7 @@ arp_hwtype_ethernet = 0x0001
|
|||
arp_proto_ip = 0x0800
|
||||
arp_opcode_request = 0x0001
|
||||
arp_opcode_reply = 0x0002
|
||||
arp_min_length = eth_min_frame_length - eth_fcs_length - mac_header_length
|
||||
|
||||
arp_header_length = 28
|
||||
arp_header_fields = {
|
||||
|
|
|
@ -36,7 +36,7 @@ class LiteEthARPTX(Module):
|
|||
|
||||
# # #
|
||||
|
||||
packet_length = max(arp_header.length, eth_min_len)
|
||||
packet_length = max(arp_header.length, arp_min_length)
|
||||
packet_words = packet_length//(dw//8)
|
||||
counter = Signal(max=packet_words, reset_less=True)
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class LiteEthMACCore(Module, AutoCSR):
|
|||
|
||||
# Padding
|
||||
if with_padding:
|
||||
tx_padding = padding.LiteEthMACPaddingInserter(datapath_dw, 60)
|
||||
tx_padding = padding.LiteEthMACPaddingInserter(datapath_dw, (eth_min_frame_length - eth_fcs_length))
|
||||
tx_padding = ClockDomainsRenamer(cd_tx)(tx_padding)
|
||||
self.submodules += tx_padding
|
||||
tx_datapath.append(tx_padding)
|
||||
|
@ -141,7 +141,7 @@ class LiteEthMACCore(Module, AutoCSR):
|
|||
|
||||
# Padding.
|
||||
if with_padding:
|
||||
rx_padding = padding.LiteEthMACPaddingChecker(datapath_dw, 60)
|
||||
rx_padding = padding.LiteEthMACPaddingChecker(datapath_dw, (eth_min_frame_length - eth_fcs_length))
|
||||
rx_padding = ClockDomainsRenamer(cd_rx)(rx_padding)
|
||||
self.submodules += rx_padding
|
||||
rx_datapath.append(rx_padding)
|
||||
|
|
|
@ -88,7 +88,7 @@ class ARP(Module):
|
|||
self.process(packet)
|
||||
|
||||
def process(self, packet):
|
||||
if len(packet) != eth_min_len-arp_header.length:
|
||||
if len(packet) != arp_min_length-arp_header.length:
|
||||
raise ValueError
|
||||
if packet.hwtype != arp_hwtype_ethernet:
|
||||
raise ValueError
|
||||
|
@ -105,7 +105,7 @@ class ARP(Module):
|
|||
|
||||
def process_request(self, request):
|
||||
if request.target_ip == self.ip_address:
|
||||
reply = ARPPacket([0]*(eth_min_len-arp_header.length))
|
||||
reply = ARPPacket([0]*(arp_min_length-arp_header.length))
|
||||
reply.hwtype = arp_hwtype_ethernet
|
||||
reply.proto = arp_proto_ip
|
||||
reply.opcode = arp_opcode_reply
|
||||
|
@ -121,7 +121,7 @@ class ARP(Module):
|
|||
self.table[reply.sender_ip] = reply.sender_mac
|
||||
|
||||
def request(self, ip_address):
|
||||
request = ARPPacket([0]*(eth_min_len-arp_header.length))
|
||||
request = ARPPacket([0]*(arp_min_length-arp_header.length))
|
||||
request.hwtype = arp_hwtype_ethernet
|
||||
request.proto = arp_proto_ip
|
||||
request.opcode = arp_opcode_request
|
||||
|
|
Loading…
Reference in New Issue