Skip to content

Commit

Permalink
cores/liteeth_mini/mac/sram: fix reception of frames larger than MTU
Browse files Browse the repository at this point in the history
-use 32bits length CSR (allow software to detect frames larger than MTU)
-drop remaining bytes
enjoy-digital committed May 1, 2016
1 parent 6e86189 commit e136030
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions misoc/cores/liteeth_mini/mac/sram.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
from misoc.interconnect.csr import *
from misoc.interconnect.csr_eventmanager import *
from misoc.interconnect import stream
from misoc.cores.liteeth_mini.common import eth_phy_layout
from misoc.cores.liteeth_mini.common import eth_phy_layout, eth_mtu


class LiteEthMACSRAMWriter(Module, AutoCSR):
@@ -12,7 +12,7 @@ def __init__(self, dw, depth, nslots=2):
self.crc_error = Signal()

slotbits = max(log2_int(nslots), 1)
lengthbits = log2_int(depth*4) # length in bytes
lengthbits = 32

self._slot = CSRStatus(slotbits)
self._length = CSRStatus(lengthbits)
@@ -74,7 +74,7 @@ def __init__(self, dw, depth, nslots=2):
)
fsm.act("WRITE",
counter_ce.eq(sink.stb),
ongoing.eq(1),
ongoing.eq(counter < eth_mtu),

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq May 3, 2016

Member

This is not safe. If it receives a frame larger than 4GB (due to malfunction or malicious activities) the counter will wrap and it will resume writing. If this is connected to DMA this can do some damage.

I propose testing for counter == eth_mtu (which also has better timing than <) and putting the FSM into a "discard the remaining of the frame" state.

This comment has been minimized.

Copy link
@enjoy-digital

enjoy-digital May 3, 2016

Author Contributor

OK thanks, I'll do that.

If(sink.stb & sink.eop,
If((sink.error & sink.last_be) != 0,
NextState("DISCARD")

0 comments on commit e136030

Please sign in to comment.