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:
Florent Kermarrec 2021-10-05 14:10:41 +02:00
parent 944849c3cf
commit 6204994bad
4 changed files with 15 additions and 13 deletions

View File

@ -18,14 +18,15 @@ from litex.soc.interconnect.packet import Header, HeaderField
# Ethernet Constants ------------------------------------------------------------------------------- # Ethernet Constants -------------------------------------------------------------------------------
eth_mtu = 1530 eth_mtu = 1530
eth_min_len = 46 eth_min_frame_length = 64
eth_interpacket_gap = 12 eth_fcs_length = 4
eth_preamble = 0xd555555555555555 eth_interpacket_gap = 12
buffer_depth = 2**log2_int(eth_mtu, need_pow2=False) eth_preamble = 0xd555555555555555
buffer_depth = 2**log2_int(eth_mtu, need_pow2=False)
ethernet_type_ip = 0x800 ethernet_type_ip = 0x800
ethernet_type_arp = 0x806 ethernet_type_arp = 0x806
# MAC Constants/Header ----------------------------------------------------------------------------- # MAC Constants/Header -----------------------------------------------------------------------------
@ -43,6 +44,7 @@ arp_hwtype_ethernet = 0x0001
arp_proto_ip = 0x0800 arp_proto_ip = 0x0800
arp_opcode_request = 0x0001 arp_opcode_request = 0x0001
arp_opcode_reply = 0x0002 arp_opcode_reply = 0x0002
arp_min_length = eth_min_frame_length - eth_fcs_length - mac_header_length
arp_header_length = 28 arp_header_length = 28
arp_header_fields = { arp_header_fields = {

View File

@ -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) packet_words = packet_length//(dw//8)
counter = Signal(max=packet_words, reset_less=True) counter = Signal(max=packet_words, reset_less=True)

View File

@ -60,7 +60,7 @@ class LiteEthMACCore(Module, AutoCSR):
# Padding # Padding
if with_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) tx_padding = ClockDomainsRenamer(cd_tx)(tx_padding)
self.submodules += tx_padding self.submodules += tx_padding
tx_datapath.append(tx_padding) tx_datapath.append(tx_padding)
@ -141,7 +141,7 @@ class LiteEthMACCore(Module, AutoCSR):
# Padding. # Padding.
if with_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) rx_padding = ClockDomainsRenamer(cd_rx)(rx_padding)
self.submodules += rx_padding self.submodules += rx_padding
rx_datapath.append(rx_padding) rx_datapath.append(rx_padding)

View File

@ -88,7 +88,7 @@ class ARP(Module):
self.process(packet) self.process(packet)
def process(self, 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 raise ValueError
if packet.hwtype != arp_hwtype_ethernet: if packet.hwtype != arp_hwtype_ethernet:
raise ValueError raise ValueError
@ -105,7 +105,7 @@ class ARP(Module):
def process_request(self, request): def process_request(self, request):
if request.target_ip == self.ip_address: 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.hwtype = arp_hwtype_ethernet
reply.proto = arp_proto_ip reply.proto = arp_proto_ip
reply.opcode = arp_opcode_reply reply.opcode = arp_opcode_reply
@ -121,7 +121,7 @@ class ARP(Module):
self.table[reply.sender_ip] = reply.sender_mac self.table[reply.sender_ip] = reply.sender_mac
def request(self, ip_address): 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.hwtype = arp_hwtype_ethernet
request.proto = arp_proto_ip request.proto = arp_proto_ip
request.opcode = arp_opcode_request request.opcode = arp_opcode_request