Skip to content

Commit

Permalink
Remove dest_id from Tlp object; use completer_id instead
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Forencich <alex@alexforencich.com>
  • Loading branch information
alexforencich committed Nov 28, 2023
1 parent 8e01027 commit a164322
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 39 deletions.
6 changes: 3 additions & 3 deletions cocotbext/pcie/core/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ def match_tlp_secondary(self, tlp):
return False
elif tlp.fmt_type in {TlpType.CFG_READ_1, TlpType.CFG_WRITE_1}:
# Config type 1
return self.sec_bus_num <= tlp.dest_id.bus <= self.sub_bus_num and tlp.dest_id != PcieId(0, 0, 0)
return self.sec_bus_num <= tlp.completer_id.bus <= self.sub_bus_num and tlp.completer_id != PcieId(0, 0, 0)
elif tlp.fmt_type in {TlpType.CPL, TlpType.CPL_DATA, TlpType.CPL_LOCKED, TlpType.CPL_LOCKED_DATA}:
# Completion
return self.sec_bus_num <= tlp.requester_id.bus <= self.sub_bus_num and tlp.requester_id != PcieId(0, 0, 0)
elif tlp.fmt_type in {TlpType.MSG_ID, TlpType.MSG_DATA_ID}:
# ID routed message
return self.sec_bus_num <= tlp.dest_id.bus <= self.sub_bus_num and tlp.dest_id != PcieId(0, 0, 0)
return self.sec_bus_num <= tlp.completer_id.bus <= self.sub_bus_num and tlp.completer_id != PcieId(0, 0, 0)
elif tlp.fmt_type in {TlpType.IO_READ, TlpType.IO_WRITE}:
# IO read/write
return self.io_base <= tlp.address <= self.io_limit
Expand Down Expand Up @@ -342,7 +342,7 @@ async def upstream_recv(self, tlp):
# Route TLPs from primary side to secondary side
if self.match_tlp_secondary(tlp):

if tlp.fmt_type in {TlpType.CFG_READ_1, TlpType.CFG_WRITE_1} and tlp.dest_id.bus == self.sec_bus_num:
if tlp.fmt_type in {TlpType.CFG_READ_1, TlpType.CFG_WRITE_1} and tlp.completer_id.bus == self.sec_bus_num:
# config type 1 targeted to directly connected device; change to type 0
if tlp.fmt_type == TlpType.CFG_READ_1:
tlp.fmt_type = TlpType.CFG_READ_0
Expand Down
2 changes: 1 addition & 1 deletion cocotbext/pcie/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def upstream_recv(self, tlp):
# config type 0

# capture address information
self.bus_num = tlp.dest_id.bus
self.bus_num = tlp.completer_id.bus

# pass TLP to function
for f in self.functions:
Expand Down
18 changes: 9 additions & 9 deletions cocotbext/pcie/core/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def match_io_bar(self, addr):
def match_tlp(self, tlp):
if tlp.fmt_type in {TlpType.CFG_READ_0, TlpType.CFG_WRITE_0}:
# Config type 0
return self.device_num == tlp.dest_id.device and self.function_num == tlp.dest_id.function
return self.device_num == tlp.completer_id.device and self.function_num == tlp.completer_id.function
elif tlp.fmt_type in {TlpType.CFG_READ_1, TlpType.CFG_WRITE_1}:
# Config type 1
return False
Expand Down Expand Up @@ -545,13 +545,13 @@ async def perform_nonposted_operation(self, req, timeout=0, timeout_unit='ns'):
return completions

async def handle_config_0_read_tlp(self, tlp):
if tlp.dest_id.device == self.device_num and tlp.dest_id.function == self.function_num:
if tlp.completer_id.device == self.device_num and tlp.completer_id.function == self.function_num:
self.log.info("Config type 0 read, reg 0x%03x", tlp.address >> 2)

# capture address information
if self.bus_num != tlp.dest_id.bus:
self.log.info("Capture bus number %d", tlp.dest_id.bus)
self.pcie_id = self.pcie_id._replace(bus=tlp.dest_id.bus)
if self.bus_num != tlp.completer_id.bus:
self.log.info("Capture bus number %d", tlp.completer_id.bus)
self.pcie_id = self.pcie_id._replace(bus=tlp.completer_id.bus)

# perform operation
data = await self.read_config_register(tlp.address >> 2)
Expand All @@ -572,14 +572,14 @@ async def handle_config_0_read_tlp(self, tlp):
await self.upstream_send(cpl)

async def handle_config_0_write_tlp(self, tlp):
if tlp.dest_id.device == self.device_num and tlp.dest_id.function == self.function_num:
if tlp.completer_id.device == self.device_num and tlp.completer_id.function == self.function_num:
self.log.info("Config type 0 write, reg 0x%03x data 0x%08x",
tlp.address >> 2, struct.unpack('<L', tlp.get_data())[0])

# capture address information
if self.bus_num != tlp.dest_id.bus:
self.log.info("Capture bus number %d", tlp.dest_id.bus)
self.pcie_id = self.pcie_id._replace(bus=tlp.dest_id.bus)
if self.bus_num != tlp.completer_id.bus:
self.log.info("Capture bus number %d", tlp.completer_id.bus)
self.pcie_id = self.pcie_id._replace(bus=tlp.completer_id.bus)

data, = struct.unpack('<L', tlp.get_data())

Expand Down
4 changes: 2 additions & 2 deletions cocotbext/pcie/core/rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ async def config_read(self, dev, addr, length, timeout=0, timeout_unit='ns'):
req = Tlp()
req.fmt_type = TlpType.CFG_READ_1
req.requester_id = PcieId(0, 0, 0)
req.dest_id = dev
req.completer_id = dev

first_pad = addr % 4
byte_length = min(length-n, 4-first_pad)
Expand Down Expand Up @@ -634,7 +634,7 @@ async def config_write(self, dev, addr, data, timeout=0, timeout_unit='ns'):
req = Tlp()
req.fmt_type = TlpType.CFG_WRITE_1
req.requester_id = PcieId(0, 0, 0)
req.dest_id = dev
req.completer_id = dev

first_pad = addr % 4
byte_length = min(len(data)-n, 4-first_pad)
Expand Down
16 changes: 2 additions & 14 deletions cocotbext/pcie/core/tlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def __init__(self, tlp=None):
self.bcm = False
self.byte_count = 0
self.requester_id = PcieId(0, 0, 0)
self.dest_id = PcieId(0, 0, 0)
self.tag = 0
self.first_be = 0
self.last_be = 0
Expand Down Expand Up @@ -230,7 +229,6 @@ def __init__(self, tlp=None):
self.bcm = tlp.bcm
self.byte_count = tlp.byte_count
self.requester_id = tlp.requester_id
self.dest_id = tlp.dest_id
self.tag = tlp.tag
self.first_be = tlp.first_be
self.last_be = tlp.last_be
Expand Down Expand Up @@ -267,14 +265,6 @@ def requester_id(self):
def requester_id(self, val):
self._requester_id = PcieId(val)

@property
def dest_id(self):
return self._dest_id

@dest_id.setter
def dest_id(self, val):
self._dest_id = PcieId(val)

def check(self):
"""Validate TLP"""
ret = True
Expand Down Expand Up @@ -505,7 +495,7 @@ def pack_header(self):

if self.fmt_type in {TlpType.CFG_READ_0, TlpType.CFG_WRITE_0, TlpType.CFG_READ_1, TlpType.CFG_WRITE_1}:
dw = self.address & 0xffc
dw |= int(self.dest_id) << 16
dw |= int(self.completer_id) << 16
pkt.extend(struct.pack('>L', dw))
else:
if self.fmt in {TlpFmt.FOUR_DW, TlpFmt.FOUR_DW_DATA}:
Expand Down Expand Up @@ -577,7 +567,7 @@ def unpack_header(cls, pkt):
if tlp.fmt_type in {TlpType.CFG_READ_0, TlpType.CFG_WRITE_0, TlpType.CFG_READ_1, TlpType.CFG_WRITE_1}:
dw, = struct.unpack_from('>L', pkt, 8)
tlp.address = dw & 0xffc
tlp.dest_id = PcieId.from_int(dw >> 16)
tlp.completer_id = PcieId.from_int(dw >> 16)
elif tlp.fmt in {TlpFmt.FOUR_DW, TlpFmt.FOUR_DW_DATA}:
val, = struct.unpack_from('>Q', pkt, 8)
tlp.address = val & 0xfffffffffffffffc
Expand Down Expand Up @@ -631,7 +621,6 @@ def __eq__(self, other):
self.bcm == other.bcm and
self.byte_count == other.byte_count and
self.requester_id == other.requester_id and
self.dest_id == other.dest_id and
self.tag == other.tag and
self.first_be == other.first_be and
self.last_be == other.last_be and
Expand Down Expand Up @@ -659,7 +648,6 @@ def __repr__(self):
f"bcm={self.bcm}, "
f"byte_count={self.byte_count}, "
f"requester_id={self.requester_id!r}, "
f"dest_id={self.dest_id!r}, "
f"tag={self.tag}, "
f"first_be={self.first_be:#x}, "
f"last_be={self.last_be:#x}, "
Expand Down
4 changes: 2 additions & 2 deletions cocotbext/pcie/intel/ptile/ptile_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,11 @@ async def upstream_recv(self, tlp):
# config type 0

# capture address information
self.bus_num = tlp.dest_id.bus
self.bus_num = tlp.completer_id.bus

# pass TLP to function
for f in self.functions:
if f.pcie_id == tlp.dest_id:
if f.pcie_id == tlp.completer_id:
await f.upstream_recv(tlp)
return

Expand Down
4 changes: 2 additions & 2 deletions cocotbext/pcie/intel/s10/s10_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ async def upstream_recv(self, tlp):
# config type 0

# capture address information
self.bus_num = tlp.dest_id.bus
self.bus_num = tlp.completer_id.bus

# pass TLP to function
for f in self.functions:
if f.pcie_id == tlp.dest_id:
if f.pcie_id == tlp.completer_id:
await f.upstream_recv(tlp)
return

Expand Down
2 changes: 0 additions & 2 deletions cocotbext/pcie/xilinx/us/tlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ def __eq__(self, other):
self.bcm == other.bcm and
self.byte_count == other.byte_count and
self.requester_id == other.requester_id and
self.dest_id == other.dest_id and
self.tag == other.tag and
self.first_be == other.first_be and
self.last_be == other.last_be and
Expand All @@ -559,7 +558,6 @@ def __repr__(self):
f"bcm={self.bcm}, "
f"byte_count={self.byte_count}, "
f"requester_id={self.requester_id!r}, "
f"dest_id={self.dest_id!r}, "
f"tag={self.tag}, "
f"first_be={self.first_be:#x}, "
f"last_be={self.last_be:#x}, "
Expand Down
4 changes: 2 additions & 2 deletions cocotbext/pcie/xilinx/us/us_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,11 @@ async def upstream_recv(self, tlp):
return
else:
# capture address information
self.bus_num = tlp.dest_id.bus
self.bus_num = tlp.completer_id.bus

# pass TLP to function
for f in self.functions:
if f.pcie_id == tlp.dest_id:
if f.pcie_id == tlp.completer_id:
await f.upstream_recv(tlp)
return

Expand Down
4 changes: 2 additions & 2 deletions cocotbext/pcie/xilinx/us/usp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,11 +926,11 @@ async def upstream_recv(self, tlp):
return
else:
# capture address information
self.bus_num = tlp.dest_id.bus
self.bus_num = tlp.completer_id.bus

# pass TLP to function
for f in self.functions:
if f.pcie_id == tlp.dest_id:
if f.pcie_id == tlp.completer_id:
await f.upstream_recv(tlp)
return

Expand Down

0 comments on commit a164322

Please sign in to comment.