From 57be29e68a737773a2271a5d708a93b2f5cde570 Mon Sep 17 00:00:00 2001 From: Vamsi K Vytla Date: Thu, 21 Nov 2019 10:25:29 +0100 Subject: [PATCH] global: pass data_width(dw) parameter to modules to prepare for 10Gbps/25Gbps links To support 10Gbps/25Gbps, the hardware stack will need to handle multiple bytes/clock cycle. Pass dw to all modules to allow making use of it in the future. For now dw=8. --- liteeth/core/__init__.py | 17 +++++++------ liteeth/core/arp.py | 32 ++++++++++++------------ liteeth/core/icmp.py | 46 +++++++++++++++++----------------- liteeth/core/ip.py | 46 +++++++++++++++++----------------- liteeth/core/udp.py | 53 ++++++++++++++++++++-------------------- liteeth/crossbar.py | 4 +-- liteeth/mac/__init__.py | 6 ++--- liteeth/mac/common.py | 20 +++++++-------- 8 files changed, 113 insertions(+), 111 deletions(-) diff --git a/liteeth/core/__init__.py b/liteeth/core/__init__.py index 722dc43..397656a 100644 --- a/liteeth/core/__init__.py +++ b/liteeth/core/__init__.py @@ -6,19 +6,20 @@ from liteeth.core.udp import LiteEthUDP from liteeth.core.icmp import LiteEthICMP class LiteEthIPCore(Module, AutoCSR): - def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True): + def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True, dw=8): if isinstance(ip_address, str): ip_address = convert_ip(ip_address) - self.submodules.mac = LiteEthMAC(phy, 8, interface="crossbar", with_preamble_crc=True) - self.submodules.arp = LiteEthARP(self.mac, mac_address, ip_address, clk_freq) - self.submodules.ip = LiteEthIP(self.mac, mac_address, ip_address, self.arp.table) + self.submodules.mac = LiteEthMAC(phy, dw, interface="crossbar", with_preamble_crc=True) + self.submodules.arp = LiteEthARP(self.mac, mac_address, ip_address, clk_freq, dw=dw) + self.submodules.ip = LiteEthIP(self.mac, mac_address, ip_address, self.arp.table, dw=dw) if with_icmp: - self.submodules.icmp = LiteEthICMP(self.ip, ip_address) + self.submodules.icmp = LiteEthICMP(self.ip, ip_address, dw=dw) class LiteEthUDPIPCore(LiteEthIPCore): - def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True): + def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True, dw=8): if isinstance(ip_address, str): ip_address = convert_ip(ip_address) - LiteEthIPCore.__init__(self, phy, mac_address, ip_address, clk_freq, with_icmp) - self.submodules.udp = LiteEthUDP(self.ip, ip_address) + LiteEthIPCore.__init__(self, phy, mac_address, ip_address, clk_freq, dw=dw, + with_icmp=with_icmp) + self.submodules.udp = LiteEthUDP(self.ip, ip_address, dw=dw) diff --git a/liteeth/core/arp.py b/liteeth/core/arp.py index b25bbdc..a9028c0 100644 --- a/liteeth/core/arp.py +++ b/liteeth/core/arp.py @@ -18,21 +18,21 @@ _arp_table_layout = [ # arp tx class LiteEthARPPacketizer(Packetizer): - def __init__(self): + def __init__(self, dw=8): Packetizer.__init__(self, - eth_arp_description(8), - eth_mac_description(8), + eth_arp_description(dw), + eth_mac_description(dw), arp_header) class LiteEthARPTX(Module): - def __init__(self, mac_address, ip_address): + def __init__(self, mac_address, ip_address, dw=8): self.sink = sink = stream.Endpoint(_arp_table_layout) - self.source = source = stream.Endpoint(eth_mac_description(8)) + self.source = source = stream.Endpoint(eth_mac_description(dw)) # # # - self.submodules.packetizer = packetizer = LiteEthARPPacketizer() + self.submodules.packetizer = packetizer = LiteEthARPPacketizer(dw) counter = Signal(max=max(arp_header.length, eth_min_len), reset_less=True) counter_reset = Signal() @@ -89,21 +89,21 @@ class LiteEthARPTX(Module): # arp rx class LiteEthARPDepacketizer(Depacketizer): - def __init__(self): + def __init__(self, dw=8): Depacketizer.__init__(self, - eth_mac_description(8), - eth_arp_description(8), + eth_mac_description(dw), + eth_arp_description(dw), arp_header) class LiteEthARPRX(Module): - def __init__(self, mac_address, ip_address): - self.sink = sink = stream.Endpoint(eth_mac_description(8)) + def __init__(self, mac_address, ip_address, dw=8): + self.sink = sink = stream.Endpoint(eth_mac_description(dw)) self.source = source = stream.Endpoint(_arp_table_layout) # # # - self.submodules.depacketizer = depacketizer = LiteEthARPDepacketizer() + self.submodules.depacketizer = depacketizer = LiteEthARPDepacketizer(dw) self.comb += sink.connect(depacketizer.sink) self.submodules.fsm = fsm = FSM(reset_state="IDLE") @@ -291,15 +291,15 @@ class LiteEthARPTable(Module): # arp class LiteEthARP(Module): - def __init__(self, mac, mac_address, ip_address, clk_freq): - self.submodules.tx = tx = LiteEthARPTX(mac_address, ip_address) - self.submodules.rx = rx = LiteEthARPRX(mac_address, ip_address) + def __init__(self, mac, mac_address, ip_address, clk_freq, dw=8): + self.submodules.tx = tx = LiteEthARPTX(mac_address, ip_address, dw) + self.submodules.rx = rx = LiteEthARPRX(mac_address, ip_address, dw) self.submodules.table = table = LiteEthARPTable(clk_freq) self.comb += [ rx.source.connect(table.sink), table.source.connect(tx.sink) ] - mac_port = mac.crossbar.get_port(ethernet_type_arp) + mac_port = mac.crossbar.get_port(ethernet_type_arp, dw=dw) self.comb += [ tx.source.connect(mac_port.sink), mac_port.source.connect(rx.sink) diff --git a/liteeth/core/icmp.py b/liteeth/core/icmp.py index 4445d89..34dc5c1 100644 --- a/liteeth/core/icmp.py +++ b/liteeth/core/icmp.py @@ -9,21 +9,21 @@ from litex.soc.interconnect.packet import Depacketizer, Packetizer # icmp tx class LiteEthICMPPacketizer(Packetizer): - def __init__(self): + def __init__(self, dw=8): Packetizer.__init__(self, - eth_icmp_description(8), - eth_ipv4_user_description(8), + eth_icmp_description(dw), + eth_ipv4_user_description(dw), icmp_header) class LiteEthICMPTX(Module): - def __init__(self, ip_address): - self.sink = sink = stream.Endpoint(eth_icmp_user_description(8)) - self.source = source = stream.Endpoint(eth_ipv4_user_description(8)) + def __init__(self, ip_address, dw=8): + self.sink = sink = stream.Endpoint(eth_icmp_user_description(dw)) + self.source = source = stream.Endpoint(eth_ipv4_user_description(dw)) # # # - self.submodules.packetizer = packetizer = LiteEthICMPPacketizer() + self.submodules.packetizer = packetizer = LiteEthICMPPacketizer(dw) self.comb += [ packetizer.sink.valid.eq(sink.valid), packetizer.sink.last.eq(sink.last), @@ -56,21 +56,21 @@ class LiteEthICMPTX(Module): # icmp rx class LiteEthICMPDepacketizer(Depacketizer): - def __init__(self): + def __init__(self, dw=8): Depacketizer.__init__(self, - eth_ipv4_user_description(8), - eth_icmp_description(8), + eth_ipv4_user_description(dw), + eth_icmp_description(dw), icmp_header) class LiteEthICMPRX(Module): - def __init__(self, ip_address): - self.sink = sink = stream.Endpoint(eth_ipv4_user_description(8)) - self.source = source = stream.Endpoint(eth_icmp_user_description(8)) + def __init__(self, ip_address, dw=8): + self.sink = sink = stream.Endpoint(eth_ipv4_user_description(dw)) + self.source = source = stream.Endpoint(eth_icmp_user_description(dw)) # # # - self.submodules.depacketizer = depacketizer = LiteEthICMPDepacketizer() + self.submodules.depacketizer = depacketizer = LiteEthICMPDepacketizer(dw) self.comb += sink.connect(depacketizer.sink) self.submodules.fsm = fsm = FSM(reset_state="IDLE") @@ -123,14 +123,14 @@ class LiteEthICMPRX(Module): # icmp echo class LiteEthICMPEcho(Module): - def __init__(self): - self.sink = sink = stream.Endpoint(eth_icmp_user_description(8)) - self.source = source = stream.Endpoint(eth_icmp_user_description(8)) + def __init__(self, dw=8): + self.sink = sink = stream.Endpoint(eth_icmp_user_description(dw)) + self.source = source = stream.Endpoint(eth_icmp_user_description(dw)) # # # # TODO: optimize ressources (no need to store parameters as datas) - self.submodules.buffer = stream.SyncFIFO(eth_icmp_user_description(8), 128, buffered=True) + self.submodules.buffer = stream.SyncFIFO(eth_icmp_user_description(dw), 128//(dw//8), buffered=True) self.comb += [ sink.connect(self.buffer.sink), self.buffer.source.connect(source), @@ -141,15 +141,15 @@ class LiteEthICMPEcho(Module): # icmp class LiteEthICMP(Module): - def __init__(self, ip, ip_address): - self.submodules.tx = tx = LiteEthICMPTX(ip_address) - self.submodules.rx = rx = LiteEthICMPRX(ip_address) - self.submodules.echo = echo = LiteEthICMPEcho() + def __init__(self, ip, ip_address, dw=8): + self.submodules.tx = tx = LiteEthICMPTX(ip_address, dw) + self.submodules.rx = rx = LiteEthICMPRX(ip_address, dw) + self.submodules.echo = echo = LiteEthICMPEcho(dw) self.comb += [ rx.source.connect(echo.sink), echo.source.connect(tx.sink) ] - ip_port = ip.crossbar.get_port(icmp_protocol) + ip_port = ip.crossbar.get_port(icmp_protocol, dw) self.comb += [ tx.source.connect(ip_port.sink), ip_port.source.connect(rx.sink) diff --git a/liteeth/core/ip.py b/liteeth/core/ip.py index cb6caf8..22f2b18 100644 --- a/liteeth/core/ip.py +++ b/liteeth/core/ip.py @@ -29,13 +29,13 @@ class LiteEthIPV4UserPort(LiteEthIPV4SlavePort): class LiteEthIPV4Crossbar(LiteEthCrossbar): - def __init__(self): - LiteEthCrossbar.__init__(self, LiteEthIPV4MasterPort, "protocol") + def __init__(self, dw=8): + LiteEthCrossbar.__init__(self, LiteEthIPV4MasterPort, "protocol", dw) - def get_port(self, protocol): + def get_port(self, protocol, dw=8): if protocol in self.users.keys(): raise ValueError("Protocol {0:#x} already assigned".format(protocol)) - port = LiteEthIPV4UserPort(8) + port = LiteEthIPV4UserPort(dw) self.users[protocol] = port return port @@ -84,17 +84,17 @@ class LiteEthIPV4Checksum(Module): # ip tx class LiteEthIPV4Packetizer(Packetizer): - def __init__(self): + def __init__(self, dw=8): Packetizer.__init__(self, - eth_ipv4_description(8), - eth_mac_description(8), + eth_ipv4_description(dw), + eth_mac_description(dw), ipv4_header) class LiteEthIPTX(Module): - def __init__(self, mac_address, ip_address, arp_table): - self.sink = sink = stream.Endpoint(eth_ipv4_user_description(8)) - self.source = source = stream.Endpoint(eth_mac_description(8)) + def __init__(self, mac_address, ip_address, arp_table, dw=8): + self.sink = sink = stream.Endpoint(eth_ipv4_user_description(dw)) + self.source = source = stream.Endpoint(eth_mac_description(dw)) self.target_unreachable = Signal() # # # @@ -105,7 +105,7 @@ class LiteEthIPTX(Module): checksum.reset.eq(source.valid & source.last & source.ready) ] - self.submodules.packetizer = packetizer = LiteEthIPV4Packetizer() + self.submodules.packetizer = packetizer = LiteEthIPV4Packetizer(dw) self.comb += [ packetizer.sink.valid.eq(sink.valid & checksum.done), packetizer.sink.last.eq(sink.last), @@ -176,21 +176,21 @@ class LiteEthIPTX(Module): # ip rx class LiteEthIPV4Depacketizer(Depacketizer): - def __init__(self): + def __init__(self, dw=8): Depacketizer.__init__(self, - eth_mac_description(8), - eth_ipv4_description(8), + eth_mac_description(dw), + eth_ipv4_description(dw), ipv4_header) class LiteEthIPRX(Module): - def __init__(self, mac_address, ip_address): - self.sink = sink = stream.Endpoint(eth_mac_description(8)) - self.source = source = stream.Endpoint(eth_ipv4_user_description(8)) + def __init__(self, mac_address, ip_address, dw=8): + self.sink = sink = stream.Endpoint(eth_mac_description(dw)) + self.source = source = stream.Endpoint(eth_ipv4_user_description(dw)) # # # - self.submodules.depacketizer = depacketizer = LiteEthIPV4Depacketizer() + self.submodules.depacketizer = depacketizer = LiteEthIPV4Depacketizer(dw) self.comb += sink.connect(depacketizer.sink) self.submodules.checksum = checksum = LiteEthIPV4Checksum(skip_checksum=False) @@ -253,15 +253,15 @@ class LiteEthIPRX(Module): # ip class LiteEthIP(Module): - def __init__(self, mac, mac_address, ip_address, arp_table): - self.submodules.tx = tx = LiteEthIPTX(mac_address, ip_address, arp_table) - self.submodules.rx = rx = LiteEthIPRX(mac_address, ip_address) - mac_port = mac.crossbar.get_port(ethernet_type_ip) + def __init__(self, mac, mac_address, ip_address, arp_table, dw=8): + self.submodules.tx = tx = LiteEthIPTX(mac_address, ip_address, arp_table, dw=dw) + self.submodules.rx = rx = LiteEthIPRX(mac_address, ip_address, dw=dw) + mac_port = mac.crossbar.get_port(ethernet_type_ip, dw) self.comb += [ tx.source.connect(mac_port.sink), mac_port.source.connect(rx.sink) ] - self.submodules.crossbar = crossbar = LiteEthIPV4Crossbar() + self.submodules.crossbar = crossbar = LiteEthIPV4Crossbar(dw) self.comb += [ crossbar.master.source.connect(tx.sink), rx.source.connect(crossbar.master.sink) diff --git a/liteeth/core/udp.py b/liteeth/core/udp.py index a79e034..a33eee8 100644 --- a/liteeth/core/udp.py +++ b/liteeth/core/udp.py @@ -30,15 +30,16 @@ class LiteEthUDPUserPort(LiteEthUDPSlavePort): class LiteEthUDPCrossbar(LiteEthCrossbar): - def __init__(self): - LiteEthCrossbar.__init__(self, LiteEthUDPMasterPort, "dst_port") + def __init__(self, dw=8): + self.dw = dw + LiteEthCrossbar.__init__(self, LiteEthUDPMasterPort, "dst_port", dw=dw) def get_port(self, udp_port, dw=8, cd="sys"): if udp_port in self.users.keys(): raise ValueError("Port {0:#x} already assigned".format(udp_port)) user_port = LiteEthUDPUserPort(dw) - internal_port = LiteEthUDPUserPort(8) + internal_port = LiteEthUDPUserPort(self.dw) # tx tx_stream = user_port.sink @@ -48,9 +49,9 @@ class LiteEthUDPCrossbar(LiteEthCrossbar): self.submodules += tx_cdc self.comb += tx_stream.connect(tx_cdc.sink) tx_stream = tx_cdc.source - if dw != 8: + if dw != self.dw: tx_converter = stream.StrideConverter(eth_udp_user_description(user_port.dw), - eth_udp_user_description(8)) + eth_udp_user_description(self.dw)) self.submodules += tx_converter self.comb += tx_stream.connect(tx_converter.sink) tx_stream = tx_converter.source @@ -58,8 +59,8 @@ class LiteEthUDPCrossbar(LiteEthCrossbar): # rx rx_stream = internal_port.source - if dw != 8: - rx_converter = stream.StrideConverter(eth_udp_user_description(8), + if dw != self.dw: + rx_converter = stream.StrideConverter(eth_udp_user_description(self.dw), eth_udp_user_description(user_port.dw)) self.submodules += rx_converter self.comb += rx_stream.connect(rx_converter.sink) @@ -79,21 +80,21 @@ class LiteEthUDPCrossbar(LiteEthCrossbar): # udp tx class LiteEthUDPPacketizer(Packetizer): - def __init__(self): + def __init__(self, dw=8): Packetizer.__init__(self, - eth_udp_description(8), - eth_ipv4_user_description(8), + eth_udp_description(dw), + eth_ipv4_user_description(dw), udp_header) class LiteEthUDPTX(Module): - def __init__(self, ip_address): - self.sink = sink = stream.Endpoint(eth_udp_user_description(8)) - self.source = source = stream.Endpoint(eth_ipv4_user_description(8)) + def __init__(self, ip_address, dw=8): + self.sink = sink = stream.Endpoint(eth_udp_user_description(dw)) + self.source = source = stream.Endpoint(eth_ipv4_user_description(dw)) # # # - self.submodules.packetizer = packetizer = LiteEthUDPPacketizer() + self.submodules.packetizer = packetizer = LiteEthUDPPacketizer(dw=dw) self.comb += [ packetizer.sink.valid.eq(sink.valid), packetizer.sink.last.eq(sink.last), @@ -126,21 +127,21 @@ class LiteEthUDPTX(Module): # udp rx class LiteEthUDPDepacketizer(Depacketizer): - def __init__(self): + def __init__(self, dw=8): Depacketizer.__init__(self, - eth_ipv4_user_description(8), - eth_udp_description(8), + eth_ipv4_user_description(dw), + eth_udp_description(dw), udp_header) class LiteEthUDPRX(Module): - def __init__(self, ip_address): - self.sink = sink = stream.Endpoint(eth_ipv4_user_description(8)) - self.source = source = stream.Endpoint(eth_udp_user_description(8)) + def __init__(self, ip_address, dw=8): + self.sink = sink = stream.Endpoint(eth_ipv4_user_description(dw)) + self.source = source = stream.Endpoint(eth_udp_user_description(dw)) # # # - self.submodules.depacketizer = depacketizer = LiteEthUDPDepacketizer() + self.submodules.depacketizer = depacketizer = LiteEthUDPDepacketizer(dw) self.comb += sink.connect(depacketizer.sink) self.submodules.fsm = fsm = FSM(reset_state="IDLE") @@ -192,15 +193,15 @@ class LiteEthUDPRX(Module): # udp class LiteEthUDP(Module): - def __init__(self, ip, ip_address): - self.submodules.tx = tx = LiteEthUDPTX(ip_address) - self.submodules.rx = rx = LiteEthUDPRX(ip_address) - ip_port = ip.crossbar.get_port(udp_protocol) + def __init__(self, ip, ip_address, dw=8): + self.submodules.tx = tx = LiteEthUDPTX(ip_address, dw) + self.submodules.rx = rx = LiteEthUDPRX(ip_address, dw) + ip_port = ip.crossbar.get_port(udp_protocol, dw) self.comb += [ tx.source.connect(ip_port.sink), ip_port.source.connect(rx.sink) ] - self.submodules.crossbar = crossbar = LiteEthUDPCrossbar() + self.submodules.crossbar = crossbar = LiteEthUDPCrossbar(dw) self.comb += [ crossbar.master.source.connect(tx.sink), rx.source.connect(crossbar.master.sink) diff --git a/liteeth/crossbar.py b/liteeth/crossbar.py index 24e1a20..fa39e4c 100644 --- a/liteeth/crossbar.py +++ b/liteeth/crossbar.py @@ -9,9 +9,9 @@ from litex.soc.interconnect.packet import Arbiter, Dispatcher class LiteEthCrossbar(Module): - def __init__(self, master_port, dispatch_param): + def __init__(self, master_port, dispatch_param, dw=8): self.users = OrderedDict() - self.master = master_port(8) + self.master = master_port(dw) self.dispatch_param = dispatch_param # overload this in derived classes diff --git a/liteeth/mac/__init__.py b/liteeth/mac/__init__.py index 8929406..4bb1d9a 100644 --- a/liteeth/mac/__init__.py +++ b/liteeth/mac/__init__.py @@ -14,9 +14,9 @@ class LiteEthMAC(Module, AutoCSR): self.submodules.core = LiteEthMACCore(phy, dw, endianness, with_preamble_crc) self.csrs = [] if interface == "crossbar": - self.submodules.crossbar = LiteEthMACCrossbar() - self.submodules.packetizer = LiteEthMACPacketizer() - self.submodules.depacketizer = LiteEthMACDepacketizer() + self.submodules.crossbar = LiteEthMACCrossbar(dw) + self.submodules.packetizer = LiteEthMACPacketizer(dw) + self.submodules.depacketizer = LiteEthMACDepacketizer(dw) self.comb += [ self.crossbar.master.source.connect(self.packetizer.sink), self.packetizer.source.connect(self.core.sink), diff --git a/liteeth/mac/common.py b/liteeth/mac/common.py index e853395..f7dbb4f 100644 --- a/liteeth/mac/common.py +++ b/liteeth/mac/common.py @@ -8,18 +8,18 @@ from litex.soc.interconnect.packet import Depacketizer, Packetizer class LiteEthMACDepacketizer(Depacketizer): - def __init__(self): + def __init__(self, dw): Depacketizer.__init__(self, - eth_phy_description(8), - eth_mac_description(8), + eth_phy_description(dw), + eth_mac_description(dw), mac_header) class LiteEthMACPacketizer(Packetizer): - def __init__(self): + def __init__(self, dw): Packetizer.__init__(self, - eth_mac_description(8), - eth_phy_description(8), + eth_mac_description(dw), + eth_phy_description(dw), mac_header) @@ -41,11 +41,11 @@ class LiteEthMACUserPort(LiteEthMACSlavePort): class LiteEthMACCrossbar(LiteEthCrossbar): - def __init__(self): - LiteEthCrossbar.__init__(self, LiteEthMACMasterPort, "ethernet_type") + def __init__(self, dw=8): + LiteEthCrossbar.__init__(self, LiteEthMACMasterPort, "ethernet_type", dw) - def get_port(self, ethernet_type): - port = LiteEthMACUserPort(8) + def get_port(self, ethernet_type, dw=8): + port = LiteEthMACUserPort(dw) if ethernet_type in self.users.keys(): raise ValueError("Ethernet type {0:#x} already assigned".format(ethernet_type)) self.users[ethernet_type] = port