From 72b1a1f91e845665ba2ddd0a3048cb30f108ddf5 Mon Sep 17 00:00:00 2001 From: David Sawatzke Date: Fri, 3 Dec 2021 01:49:51 +0100 Subject: [PATCH] core/udp: Add dw>8 support to LiteEthUDPRX Pass through last_be or create a new one based on the length if needed Initialize count at dw//8 and don't subtract source_length since it could lead to underflow for very short packets. In case source.length is not dw aligned, count will not be equal, so adjust comparison for that. Crib last_be Case lookup from mac/sram.py --- liteeth/core/udp.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/liteeth/core/udp.py b/liteeth/core/udp.py index 253a144..8ab32d0 100644 --- a/liteeth/core/udp.py +++ b/liteeth/core/udp.py @@ -180,7 +180,7 @@ class LiteEthUDPRX(Module): count = Signal(16) self.submodules.fsm = fsm = FSM(reset_state="IDLE") fsm.act("IDLE", - NextValue(count, 0), + NextValue(count, dw//8), If(depacketizer.source.valid, NextState("DROP"), If(sink.protocol == udp_protocol, @@ -190,7 +190,22 @@ class LiteEthUDPRX(Module): ) fsm.act("RECEIVE", depacketizer.source.connect(source, keep={"valid", "ready"}), - source.last.eq(depacketizer.source.last | (count == (source.length - dw//8))), + source.last.eq(depacketizer.source.last | (count >= source.length)), + If(depacketizer.source.last_be, + source.last_be.eq(depacketizer.source.last_be), + ).Elif( + source.last, + Case(source.length & (dw//8 - 1), { + 1 : source.last_be.eq(0b00000001), + 2 : source.last_be.eq(0b00000010), + 3 : source.last_be.eq(0b00000100), + 4 : source.last_be.eq(0b00001000), + 5 : source.last_be.eq(0b00010000), + 6 : source.last_be.eq(0b00100000), + 7 : source.last_be.eq(0b01000000), + "default" : source.last_be.eq(2**(dw//8 - 1)), + }) + ), If(source.valid & source.ready, NextValue(count, count + dw//8), If(depacketizer.source.last,