Skip to content

Commit

Permalink
serwb/core: Add reset of core when link is down, to prevent accesses …
Browse files Browse the repository at this point in the history
…to be propagated to Etherbone and deadlock situations.
  • Loading branch information
enjoy-digital committed Jul 8, 2024
1 parent e0af9e5 commit 2677aa9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions liteiclink/serwb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# SERWB Core ---------------------------------------------------------------------------------------

class SERWBCore(LiteXModule):
def __init__(self, phy, clk_freq, mode, port=0,
def __init__(self, phy, clk_freq, mode, with_rst_on_link_down=True, port=0,
etherbone_buffer_depth = 4,
tx_buffer_depth = 8,
rx_buffer_depth = 8,
Expand All @@ -31,7 +31,7 @@ def __init__(self, phy, clk_freq, mode, port=0,

# Etherbone.
# ----------
self.etherbone = etherbone = Etherbone(mode, etherbone_buffer_depth)
self.etherbone = etherbone = ResetInserter()(Etherbone(mode, etherbone_buffer_depth))
self.add_downstream_endpoint(port=port, endpoint=etherbone.source)
self.add_upstream_endpoint( port=port, endpoint=etherbone.sink)

Expand All @@ -41,13 +41,13 @@ def __init__(self, phy, clk_freq, mode, port=0,

# Packetizer / Depacketizer.
# --------------------------
self.packetizer = packetizer = Packetizer()
self.depacketizer = depacketizer = Depacketizer(clk_freq)
self.packetizer = packetizer = ResetInserter()(Packetizer())
self.depacketizer = depacketizer = ResetInserter()(Depacketizer(clk_freq))

# Buffering.
# ----------
tx_fifo = stream.SyncFIFO([("data", 32)], tx_buffer_depth, buffered=True)
rx_fifo = stream.SyncFIFO([("data", 32)], rx_buffer_depth, buffered=True)
tx_fifo = ResetInserter()(stream.SyncFIFO([("data", 32)], tx_buffer_depth, buffered=True))
rx_fifo = ResetInserter()(stream.SyncFIFO([("data", 32)], rx_buffer_depth, buffered=True))
self.submodules += tx_fifo, rx_fifo

# Data-Path.
Expand All @@ -61,6 +61,17 @@ def __init__(self, phy, clk_freq, mode, port=0,
rx_fifo.source.connect(depacketizer.sink),
]

# Reset internal module when link down.
# -------------------------------------
if with_rst_on_link_down:
self.comb += [
etherbone.reset.eq( ~phy.init.ready),
packetizer.reset.eq( ~phy.init.ready),
depacketizer.reset.eq( ~phy.init.ready),
tx_fifo.reset.eq( ~phy.init.ready),
rx_fifo.reset.eq( ~phy.init.ready),
]

def add_downstream_endpoint(self, port, endpoint):
if port in self.downstream_endpoints.keys():
raise ValueError(f"Downstream endpoint for port {port} already exists.")
Expand Down

0 comments on commit 2677aa9

Please sign in to comment.