Skip to content

Commit

Permalink
mac/__init__.py: Improve/Cleanup LiteEthMAC.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Aug 19, 2024
1 parent bfc07e5 commit edc7188
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions liteeth/mac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, phy, dw,
assert interface in ["crossbar", "wishbone", "hybrid"]
assert endianness in ["big", "little"]

# Core.
# -----
self.core = LiteEthMACCore(
phy = phy,
dw = dw,
Expand All @@ -47,7 +49,10 @@ def __init__(self, phy, dw,
rx_cdc_buffered = rx_cdc_buffered,
)
self.csrs = []
if interface == "crossbar":

# Crossbar Mode.
# --------------
if interface in ["crossbar"]:
self.crossbar = LiteEthMACCrossbar(dw)
self.packetizer = LiteEthMACPacketizer(dw)
self.depacketizer = LiteEthMACDepacketizer(dw)
Expand All @@ -57,8 +62,11 @@ def __init__(self, phy, dw,
self.core.source.connect(self.depacketizer.sink),
self.depacketizer.source.connect(self.crossbar.master.sink)
]
else:
# Wishbone MAC
# Wishbone/Hybrid Mode.
# ---------------------
if interface in ["wishbone", "hybrid"]:
# Wishbone MAC (Common to Wishbone and Hybrid Modes).
# ---------------------------------------------------
self.rx_slots = CSRConstant(nrxslots)
self.tx_slots = CSRConstant(ntxslots)
self.slot_size = CSRConstant(2**bits_for(eth_mtu))
Expand All @@ -69,25 +77,29 @@ def __init__(self, phy, dw,
endianness = endianness,
timestamp = timestamp,
)
# On some targets (Intel/Altera), the complex ports aren't inferred
# as block ram, but are created with LUTs. FullMemoryWe splits such
# `Memory` instances up into 4 separate memory blocks, each
# containing 8 bits which gets inferred correctly on intel/altera.
# Yosys on ECP5 inferrs the original correctly, so FullMemoryWE
# leads to additional block ram instances being used, which
# increases memory usage by a lot.
if full_memory_we:
wishbone_interface = FullMemoryWE()(wishbone_interface)
wishbone_interface = self.apply_full_memory_we(wishbone_interface)
self.interface = wishbone_interface
self.ev, self.bus_rx, self.bus_tx = self.interface.sram.ev, self.interface.bus_rx, self.interface.bus_tx
self.csrs = self.interface.get_csrs() + self.core.get_csrs()
if interface == "hybrid":
# Hardware MAC
self.crossbar = LiteEthMACCrossbar(dw)
self.mac_crossbar = LiteEthMACCoreCrossbar(self.core, self.crossbar, self.interface, dw, hw_mac)
else:
self.ev = self.interface.sram.ev
self.bus_rx = self.interface.bus_rx
self.bus_tx = self.interface.bus_tx
self.csrs = self.interface.get_csrs() + self.core.get_csrs()

# Wishbone Mode.
# --------------
if interface in ["wishbone"]:
self.comb += self.interface.source.connect(self.core.sink)
self.comb += self.core.source.connect(self.interface.sink)
# Hybrid Mode.
# ------------
if interface in ["hybrid"]:
self.crossbar = LiteEthMACCrossbar(dw)
self.mac_crossbar = LiteEthMACCoreCrossbar(self.core, self.crossbar, self.interface, dw, hw_mac)

def apply_full_memory_we(self, interface):
# FullMemoryWE splits memory into 8-bit blocks to ensure proper block RAM inference on most FPGAs.
# On some (e.g., ECP5/Yosys), this isn't needed and can increase memory usage.
return FullMemoryWE()(wishbone_interface)

def get_csrs(self):
return self.csrs
Expand Down

0 comments on commit edc7188

Please sign in to comment.