From dc96269c8ffce46b6ed61ac85a3c6bdc74946692 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 16 Feb 2022 14:12:46 +0100 Subject: [PATCH] core/ip/tx: Add broadcast capability. --- liteeth/common.py | 5 +++++ liteeth/core/arp.py | 2 +- liteeth/core/ip.py | 11 +++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/liteeth/common.py b/liteeth/common.py index 6a5b47d..2c4f88f 100644 --- a/liteeth/common.py +++ b/liteeth/common.py @@ -60,6 +60,11 @@ arp_header_fields = { } arp_header = Header(arp_header_fields, arp_header_length, swap_field_bytes=True) +# Broadcast Constants ------------------------------------------------------------------------------ + +bcast_ip_mask = 0xff +bcast_mac_address = 0xffffffffffff + # Multicast Constants ------------------------------------------------------------------------------ mcast_oui = C(0x01005e, 24) diff --git a/liteeth/core/arp.py b/liteeth/core/arp.py index 99e47a9..18ccfbc 100644 --- a/liteeth/core/arp.py +++ b/liteeth/core/arp.py @@ -68,7 +68,7 @@ class LiteEthARPTX(Module): packetizer.sink.target_mac.eq(sink.mac_address), ).Elif(sink.request, packetizer.sink.opcode.eq(arp_opcode_request), - packetizer.sink.target_mac.eq(0xffffffffffff), + packetizer.sink.target_mac.eq(bcast_mac_address), ) ] self.comb += [ diff --git a/liteeth/core/ip.py b/liteeth/core/ip.py index ce89729..e29cde8 100644 --- a/liteeth/core/ip.py +++ b/liteeth/core/ip.py @@ -110,7 +110,8 @@ class LiteEthIPTX(Module): "last", "last_be", "protocol", - "data"}), + "data", + }), packetizer.sink.valid.eq(sink.valid & checksum.done), sink.ready.eq(packetizer.sink.ready & checksum.done), packetizer.sink.target_ip.eq(sink.ip_address), @@ -130,9 +131,15 @@ class LiteEthIPTX(Module): self.submodules.fsm = fsm = FSM(reset_state="IDLE") fsm.act("IDLE", If(packetizer.source.valid, - If(sink.ip_address[28:] == mcast_ip_mask, + # Broadcast. + If(sink.ip_address[0:8] == bcast_ip_mask, + NextValue(target_mac, bcast_mac_address), + NextState("SEND") + # Multicast. + ).Elif(sink.ip_address[28:] == mcast_ip_mask, NextValue(target_mac, Cat(sink.ip_address[:23], 0, mcast_oui)), NextState("SEND") + # Unicast. ).Else( NextState("SEND_MAC_ADDRESS_REQUEST") )