core/ip/tx: Add broadcast capability.

This commit is contained in:
Florent Kermarrec 2022-02-16 14:12:46 +01:00
parent aff1916a03
commit dc96269c8f
3 changed files with 15 additions and 3 deletions

View file

@ -60,6 +60,11 @@ arp_header_fields = {
} }
arp_header = Header(arp_header_fields, arp_header_length, swap_field_bytes=True) 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 ------------------------------------------------------------------------------ # Multicast Constants ------------------------------------------------------------------------------
mcast_oui = C(0x01005e, 24) mcast_oui = C(0x01005e, 24)

View file

@ -68,7 +68,7 @@ class LiteEthARPTX(Module):
packetizer.sink.target_mac.eq(sink.mac_address), packetizer.sink.target_mac.eq(sink.mac_address),
).Elif(sink.request, ).Elif(sink.request,
packetizer.sink.opcode.eq(arp_opcode_request), packetizer.sink.opcode.eq(arp_opcode_request),
packetizer.sink.target_mac.eq(0xffffffffffff), packetizer.sink.target_mac.eq(bcast_mac_address),
) )
] ]
self.comb += [ self.comb += [

View file

@ -110,7 +110,8 @@ class LiteEthIPTX(Module):
"last", "last",
"last_be", "last_be",
"protocol", "protocol",
"data"}), "data",
}),
packetizer.sink.valid.eq(sink.valid & checksum.done), packetizer.sink.valid.eq(sink.valid & checksum.done),
sink.ready.eq(packetizer.sink.ready & checksum.done), sink.ready.eq(packetizer.sink.ready & checksum.done),
packetizer.sink.target_ip.eq(sink.ip_address), packetizer.sink.target_ip.eq(sink.ip_address),
@ -130,9 +131,15 @@ class LiteEthIPTX(Module):
self.submodules.fsm = fsm = FSM(reset_state="IDLE") self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE", fsm.act("IDLE",
If(packetizer.source.valid, 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)), NextValue(target_mac, Cat(sink.ip_address[:23], 0, mcast_oui)),
NextState("SEND") NextState("SEND")
# Unicast.
).Else( ).Else(
NextState("SEND_MAC_ADDRESS_REQUEST") NextState("SEND_MAC_ADDRESS_REQUEST")
) )