From: Florent Kermarrec Date: Mon, 9 Feb 2015 11:57:05 +0000 (+0100) Subject: mac: add interpacket gap inserter/checker X-Git-Tag: 24jan2021_ls180~2604^2~61 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e18e403f1098ae6d4a51ade5f9e906e5230fffa7;p=litex.git mac: add interpacket gap inserter/checker --- diff --git a/liteeth/common.py b/liteeth/common.py index ec90bf0a..b94ce217 100644 --- a/liteeth/common.py +++ b/liteeth/common.py @@ -15,6 +15,7 @@ from migen.bank.description import * eth_mtu = 1532 eth_min_len = 46 +eth_interpacket_gap = 12 eth_preamble = 0xD555555555555555 buffer_depth = 2**log2_int(eth_mtu, need_pow2=False) diff --git a/liteeth/mac/__init__.py b/liteeth/mac/__init__.py index 10a090f3..2b9cfb63 100644 --- a/liteeth/mac/__init__.py +++ b/liteeth/mac/__init__.py @@ -22,7 +22,7 @@ class LiteEthMACPacketizer(LiteEthPacketizer): mac_header_len) class LiteEthMAC(Module, AutoCSR): - def __init__(self, phy, dw, interface="crossbar", endianness="be", + def __init__(self, phy, dw, interface="crossbar", endianness="big", with_hw_preamble_crc=True): self.submodules.core = LiteEthMACCore(phy, dw, endianness, with_hw_preamble_crc) self.csrs = [] diff --git a/liteeth/mac/core/__init__.py b/liteeth/mac/core/__init__.py index f887c611..5db1feac 100644 --- a/liteeth/mac/core/__init__.py +++ b/liteeth/mac/core/__init__.py @@ -1,5 +1,5 @@ from liteeth.common import * -from liteeth.mac.core import preamble, crc, last_be +from liteeth.mac.core import gap, preamble, crc, last_be class LiteEthMACCore(Module, AutoCSR): def __init__(self, phy, dw, endianness="big", with_hw_preamble_crc=True): @@ -9,6 +9,14 @@ class LiteEthMACCore(Module, AutoCSR): rx_pipeline = [phy] tx_pipeline = [phy] + # Interpacket gap + tx_gap_inserter = gap.LiteEthMACGap(phy.dw) + rx_gap_checker = gap.LiteEthMACGap(phy.dw, ack_on_gap=True) + self.submodules += tx_gap_inserter, rx_gap_checker + + tx_pipeline += [tx_gap_inserter] + rx_pipeline += [rx_gap_checker] + # Preamble / CRC if with_hw_preamble_crc: self._hw_preamble_crc = CSRStatus(reset=1) diff --git a/liteeth/mac/core/gap.py b/liteeth/mac/core/gap.py new file mode 100644 index 00000000..0f1ddd79 --- /dev/null +++ b/liteeth/mac/core/gap.py @@ -0,0 +1,25 @@ +from liteeth.common import * + +class LiteEthMACGap(Module): + def __init__(self, dw, ack_on_gap=False): + self.sink = sink = Sink(eth_phy_description(dw)) + self.source = source = Source(eth_phy_description(dw)) + ### + gap = math.ceil(eth_interpacket_gap/(dw//8)) + self.submodules.counter = counter = Counter(max=gap) + + self.submodules.fsm = fsm = FSM(reset_state="COPY") + fsm.act("COPY", + counter.reset.eq(1), + Record.connect(sink, source), + If(sink.stb & sink.eop & sink.ack, + NextState("GAP") + ) + ) + fsm.act("GAP", + counter.ce.eq(1), + sink.ack.eq(int(ack_on_gap)), + If(counter.value == (gap-1), + NextState("COPY") + ) + )