From 6204994bad4fef91e7f316a0b5d26daf08663206 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 5 Oct 2021 14:10:41 +0200 Subject: [PATCH] common: Define eth_min_frame_length, eth_fcs_length and arp_min_length and use them in core/mac/model. --- liteeth/common.py | 16 +++++++++------- liteeth/core/arp.py | 2 +- liteeth/mac/core.py | 4 ++-- test/model/arp.py | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/liteeth/common.py b/liteeth/common.py index 3f80637..bb5f558 100644 --- a/liteeth/common.py +++ b/liteeth/common.py @@ -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 = { diff --git a/liteeth/core/arp.py b/liteeth/core/arp.py index 6ea7d6e..f35eefc 100644 --- a/liteeth/core/arp.py +++ b/liteeth/core/arp.py @@ -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) diff --git a/liteeth/mac/core.py b/liteeth/mac/core.py index 68070e2..3b2e9e7 100644 --- a/liteeth/mac/core.py +++ b/liteeth/mac/core.py @@ -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) diff --git a/test/model/arp.py b/test/model/arp.py index a4f79e8..fc0e367 100644 --- a/test/model/arp.py +++ b/test/model/arp.py @@ -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