core/udp: Simplify LiteEthUDPRX and make sure to drop exceeding payload.
This commit is contained in:
parent
393158f2a5
commit
bee34ee955
|
@ -155,46 +155,46 @@ class LiteEthUDPRX(Module):
|
|||
|
||||
# # #
|
||||
|
||||
# Depacketizer.
|
||||
self.submodules.depacketizer = depacketizer = LiteEthUDPDepacketizer(dw)
|
||||
self.comb += sink.connect(depacketizer.sink)
|
||||
|
||||
# Data-Path.
|
||||
self.comb += [
|
||||
sink.connect(depacketizer.sink),
|
||||
depacketizer.source.connect(source, keep={
|
||||
"src_port",
|
||||
"dst_port",
|
||||
"data",
|
||||
"error"}),
|
||||
source.ip_address.eq(sink.ip_address),
|
||||
source.length.eq(depacketizer.source.length - udp_header.length),
|
||||
]
|
||||
|
||||
# Control-Path (FSM).
|
||||
count = Signal(16)
|
||||
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
|
||||
fsm.act("IDLE",
|
||||
depacketizer.source.ready.eq(1),
|
||||
NextValue(count, 0),
|
||||
If(depacketizer.source.valid,
|
||||
depacketizer.source.ready.eq(0),
|
||||
NextState("CHECK")
|
||||
NextState("DROP"),
|
||||
If(sink.protocol == udp_protocol,
|
||||
NextState("RECEIVE")
|
||||
)
|
||||
)
|
||||
valid = Signal(reset_less=True)
|
||||
self.sync += valid.eq(
|
||||
depacketizer.source.valid &
|
||||
(sink.protocol == udp_protocol)
|
||||
)
|
||||
|
||||
fsm.act("CHECK",
|
||||
If(valid,
|
||||
NextState("PRESENT")
|
||||
).Else(
|
||||
fsm.act("RECEIVE",
|
||||
depacketizer.source.connect(source, keep={"valid", "ready"}),
|
||||
source.last.eq(depacketizer.source.last | (count == (source.length - dw//8))),
|
||||
If(source.valid & source.ready,
|
||||
NextValue(count, count + dw//8),
|
||||
If(depacketizer.source.last,
|
||||
NextState("IDLE")
|
||||
).Elif(source.last,
|
||||
NextState("DROP")
|
||||
)
|
||||
)
|
||||
self.comb += [
|
||||
source.last.eq(depacketizer.source.last),
|
||||
source.src_port.eq(depacketizer.source.src_port),
|
||||
source.dst_port.eq(depacketizer.source.dst_port),
|
||||
source.ip_address.eq(sink.ip_address),
|
||||
source.length.eq(depacketizer.source.length - udp_header.length),
|
||||
source.data.eq(depacketizer.source.data),
|
||||
source.error.eq(depacketizer.source.error)
|
||||
]
|
||||
fsm.act("PRESENT",
|
||||
source.valid.eq(depacketizer.source.valid),
|
||||
depacketizer.source.ready.eq(source.ready),
|
||||
If(source.valid & source.last & source.ready,
|
||||
NextState("IDLE")
|
||||
)
|
||||
)
|
||||
|
||||
fsm.act("DROP",
|
||||
depacketizer.source.ready.eq(1),
|
||||
If(depacketizer.source.valid &
|
||||
|
|
Loading…
Reference in New Issue