from migen.fhdl.std import *
from migen.genlib.record import *
from migen.flow.actor import EndpointDescription, Sink, Source
+from migen.actorlib.packet import HeaderField, Header
from misoclib.com.litepcie.common import *
# headers
-class HField():
- def __init__(self, word, offset, width):
- self.word = word
- self.offset = offset
- self.width = width
-
-tlp_header_w = 128
-
-tlp_common_header = {
- "fmt": HField(0, 29, 2),
- "type": HField(0, 24, 5),
+tlp_common_header_length = 16
+tlp_common_header_fields = {
+ "fmt": HeaderField(0*4, 29, 2),
+ "type": HeaderField(0*4, 24, 5),
}
-
-tlp_request_header = {
- "fmt": HField(0, 29, 2),
- "type": HField(0, 24, 5),
- "tc": HField(0, 20, 3),
- "td": HField(0, 15, 1),
- "ep": HField(0, 14, 1),
- "attr": HField(0, 12, 2),
- "length": HField(0, 0, 10),
-
- "requester_id": HField(1, 16, 16),
- "tag": HField(1, 8, 8),
- "last_be": HField(1, 4, 4),
- "first_be": HField(1, 0, 4),
-
- "address": HField(2, 2, 30),
+tlp_common_header = Header(tlp_common_header_fields,
+ tlp_common_header_length,
+ swap_field_bytes=False)
+
+
+tlp_request_header_length = 16
+tlp_request_header_fields = {
+ "fmt": HeaderField(0*4, 29, 2),
+ "type": HeaderField(0*4, 24, 5),
+ "tc": HeaderField(0*4, 20, 3),
+ "td": HeaderField(0*4, 15, 1),
+ "ep": HeaderField(0*4, 14, 1),
+ "attr": HeaderField(0*4, 12, 2),
+ "length": HeaderField(0*4, 0, 10),
+
+ "requester_id": HeaderField(1*4, 16, 16),
+ "tag": HeaderField(1*4, 8, 8),
+ "last_be": HeaderField(1*4, 4, 4),
+ "first_be": HeaderField(1*4, 0, 4),
+
+ "address": HeaderField(2*4, 2, 30),
}
-
-tlp_completion_header = {
- "fmt": HField(0, 29, 2),
- "type": HField(0, 24, 5),
- "tc": HField(0, 20, 3),
- "td": HField(0, 15, 1),
- "ep": HField(0, 14, 1),
- "attr": HField(0, 12, 2),
- "length": HField(0, 0, 10),
-
- "completer_id": HField(1, 16, 16),
- "status": HField(1, 13, 3),
- "bcm": HField(1, 12, 1),
- "byte_count": HField(1, 0, 12),
-
- "requester_id": HField(2, 16, 16),
- "tag": HField(2, 8, 8),
- "lower_address": HField(2, 0, 7),
+tlp_request_header = Header(tlp_request_header_fields,
+ tlp_request_header_length,
+ swap_field_bytes=False)
+
+
+tlp_completion_header_length = 16
+tlp_completion_header_fields = {
+ "fmt": HeaderField(0*4, 29, 2),
+ "type": HeaderField(0*4, 24, 5),
+ "tc": HeaderField(0*4, 20, 3),
+ "td": HeaderField(0*4, 15, 1),
+ "ep": HeaderField(0*4, 14, 1),
+ "attr": HeaderField(0*4, 12, 2),
+ "length": HeaderField(0*4, 0, 10),
+
+ "completer_id": HeaderField(1*4, 16, 16),
+ "status": HeaderField(1*4, 13, 3),
+ "bcm": HeaderField(1*4, 12, 1),
+ "byte_count": HeaderField(1*4, 0, 12),
+
+ "requester_id": HeaderField(2*4, 16, 16),
+ "tag": HeaderField(2*4, 8, 8),
+ "lower_address": HeaderField(2*4, 0, 7),
}
+tlp_completion_header = Header(tlp_completion_header_fields,
+ tlp_completion_header_length,
+ swap_field_bytes=False)
# layouts
-def _layout_from_header(header):
- _layout = []
- for k, v in sorted(header.items()):
- _layout.append((k, v.width))
- return _layout
-
-
def tlp_raw_layout(dw):
layout = [
- ("header", tlp_header_w),
- ("dat", dw),
- ("be", dw//8)
+ ("header", 4*32),
+ ("dat", dw),
+ ("be", dw//8)
]
return EndpointDescription(layout, packetized=True)
def tlp_common_layout(dw):
- layout = _layout_from_header(tlp_common_header) + [
- ("dat", dw),
- ("be", dw//8)
+ layout = tlp_common_header.get_layout() + [
+ ("dat", dw),
+ ("be", dw//8)
]
return EndpointDescription(layout, packetized=True)
def tlp_request_layout(dw):
- layout = _layout_from_header(tlp_request_header) + [
- ("dat", dw),
- ("be", dw//8)
+ layout = tlp_request_header.get_layout() + [
+ ("dat", dw),
+ ("be", dw//8)
]
return EndpointDescription(layout, packetized=True)
def tlp_completion_layout(dw):
- layout = _layout_from_header(tlp_completion_header) + [
- ("dat", dw),
- ("be", dw//8)
+ layout = tlp_completion_header.get_layout() + [
+ ("dat", dw),
+ ("be", dw//8)
]
return EndpointDescription(layout, packetized=True)
from migen.genlib.fsm import FSM, NextState
from misoclib.com.litepcie.core.packet.common import *
-from misoclib.com.litepcie.core.switch.dispatcher import Dispatcher
-
-
-def _decode_header(h_dict, h_signal, obj):
- r = []
- for k, v in sorted(h_dict.items()):
- start = v.word*32+v.offset
- end = start+v.width
- r.append(getattr(obj, k).eq(h_signal[start:end]))
- return r
class HeaderExtracter(Module):
source.sop.eq(sop),
source.eop.eq(sink.eop),
source.dat.eq(Cat(reverse_bytes(sink_dat_r[32:]), reverse_bytes(sink.dat[:32]))),
- source.be.eq(Cat(reverse_bits(sink_be_r[4:]), reverse_bits(sink.be[:4]))),
+ source.be.eq(Cat(freversed(sink_be_r[4:]), freversed(sink.be[:4]))),
If(source.stb & source.ack & source.eop,
NextState("HEADER1")
)
source.sop.eq(1),
source.eop.eq(1),
source.dat.eq(reverse_bytes(sink.dat[32:])),
- source.be.eq(reverse_bits(sink.be[4:])),
+ source.be.eq(freversed(sink.be[4:])),
If(source.stb & source.ack & source.eop,
NextState("HEADER1")
)
dispatch_source.eop.eq(header_extracter.source.eop),
dispatch_source.dat.eq(header_extracter.source.dat),
dispatch_source.be.eq(header_extracter.source.be),
- _decode_header(tlp_common_header, header, dispatch_source)
+ tlp_common_header.decode(header, dispatch_source)
]
self.submodules.dispatcher = Dispatcher(dispatch_source, dispatch_sinks)
# decode TLP request and format local request
tlp_req = Source(tlp_request_layout(dw))
self.comb += Record.connect(dispatch_sinks[0], tlp_req)
- self.comb += _decode_header(tlp_request_header, header, tlp_req)
+ self.comb += tlp_request_header.decode(header, tlp_req)
req_source = self.req_source
self.comb += [
# decode TLP completion and format local completion
tlp_cmp = Source(tlp_completion_layout(dw))
self.comb += Record.connect(dispatch_sinks[1], tlp_cmp)
- self.comb += _decode_header(tlp_completion_header, header, tlp_cmp)
+ self.comb += tlp_completion_header.decode(header, tlp_cmp)
cmp_source = self.cmp_source
self.comb += [
from migen.genlib.misc import chooser
from misoclib.com.litepcie.core.packet.common import *
-from misoclib.com.litepcie.core.switch.arbiter import Arbiter
-
-
-def _encode_header(h_dict, h_signal, obj):
- r = []
- for k, v in sorted(h_dict.items()):
- start = v.word*32+v.offset
- end = start+v.width
- r.append(h_signal[start:end].eq(getattr(obj, k)))
- return r
class HeaderInserter(Module):
source.sop.eq(0),
source.eop.eq(sink.eop),
source.dat.eq(Cat(sink.header[64:96], reverse_bytes(sink.dat[:32]))),
- source.be.eq(Cat(Signal(4, reset=0xf), reverse_bits(sink.be[:4]))),
+ source.be.eq(Cat(Signal(4, reset=0xf), freversed(sink.be[:4]))),
If(source.stb & source.ack,
sink.ack.eq(1),
If(source.eop,
tlp_req.ack.eq(tlp_raw_req.ack),
tlp_raw_req.sop.eq(tlp_req.sop),
tlp_raw_req.eop.eq(tlp_req.eop),
- _encode_header(tlp_request_header, tlp_raw_req.header, tlp_req),
+ tlp_request_header.encode(tlp_req, tlp_raw_req.header),
tlp_raw_req.dat.eq(tlp_req.dat),
tlp_raw_req.be.eq(tlp_req.be),
]
tlp_cmp.ack.eq(tlp_raw_cmp.ack),
tlp_raw_cmp.sop.eq(tlp_cmp.sop),
tlp_raw_cmp.eop.eq(tlp_cmp.eop),
- _encode_header(tlp_completion_header, tlp_raw_cmp.header, tlp_cmp),
+ tlp_completion_header.encode(tlp_cmp, tlp_raw_cmp.header),
tlp_raw_cmp.dat.eq(tlp_cmp.dat),
tlp_raw_cmp.be.eq(tlp_cmp.be),
]