From 8e01027dee92e9f4f22ceb47525ba979ef586eb9 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Mon, 27 Nov 2023 00:37:26 -0800 Subject: [PATCH] Remove register_number from Tlp object; use address field instead Signed-off-by: Alex Forencich --- cocotbext/pcie/core/function.py | 8 ++++---- cocotbext/pcie/core/rc.py | 6 +----- cocotbext/pcie/core/tlp.py | 8 ++------ cocotbext/pcie/xilinx/us/tlp.py | 10 ++++------ 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/cocotbext/pcie/core/function.py b/cocotbext/pcie/core/function.py index 5571159..9e92d4d 100644 --- a/cocotbext/pcie/core/function.py +++ b/cocotbext/pcie/core/function.py @@ -546,7 +546,7 @@ async def perform_nonposted_operation(self, req, timeout=0, timeout_unit='ns'): 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: - self.log.info("Config type 0 read, reg 0x%03x", tlp.register_number) + self.log.info("Config type 0 read, reg 0x%03x", tlp.address >> 2) # capture address information if self.bus_num != tlp.dest_id.bus: @@ -554,7 +554,7 @@ async def handle_config_0_read_tlp(self, tlp): self.pcie_id = self.pcie_id._replace(bus=tlp.dest_id.bus) # perform operation - data = await self.read_config_register(tlp.register_number) + data = await self.read_config_register(tlp.address >> 2) # prepare completion TLP cpl = Tlp.create_completion_data_for_tlp(tlp, self.pcie_id) @@ -574,7 +574,7 @@ async def handle_config_0_read_tlp(self, tlp): 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: self.log.info("Config type 0 write, reg 0x%03x data 0x%08x", - tlp.register_number, struct.unpack('> 2, struct.unpack('> 2, data, tlp.first_be) # prepare completion TLP cpl = Tlp.create_completion_for_tlp(tlp, self.pcie_id) diff --git a/cocotbext/pcie/core/rc.py b/cocotbext/pcie/core/rc.py index e915562..e52033c 100644 --- a/cocotbext/pcie/core/rc.py +++ b/cocotbext/pcie/core/rc.py @@ -576,14 +576,12 @@ async def config_read(self, dev, addr, length, timeout=0, timeout_unit='ns'): byte_length = min(length-n, 4-first_pad) req.set_addr_be(addr, byte_length) - req.register_number = addr >> 2 - cpl_list = await self.perform_nonposted_operation(req, timeout, timeout_unit) if not cpl_list: # timed out d = b'\xff\xff\xff\xff' - elif cpl_list[0].status == CplStatus.CRS and req.register_number == 0 and cpl_list[0].ingress_port: + elif cpl_list[0].status == CplStatus.CRS and req.address == 0 and cpl_list[0].ingress_port: # completion retry status if cpl_list[0].ingress_port.pcie_cap.crs_software_visibility_enable: d = b'\x01\x00\xff\xff' @@ -642,8 +640,6 @@ async def config_write(self, dev, addr, data, timeout=0, timeout_unit='ns'): byte_length = min(len(data)-n, 4-first_pad) req.set_addr_be_data(addr, data[n:n+byte_length]) - req.register_number = addr >> 2 - cpl_list = await self.perform_nonposted_operation(req, timeout, timeout_unit) n += byte_length diff --git a/cocotbext/pcie/core/tlp.py b/cocotbext/pcie/core/tlp.py index 442d0c1..66f8c49 100644 --- a/cocotbext/pcie/core/tlp.py +++ b/cocotbext/pcie/core/tlp.py @@ -209,7 +209,6 @@ def __init__(self, tlp=None): self.lower_address = 0 self.address = 0 self.ph = 0 - self.register_number = 0 self.data = bytearray() self.seq = 0 @@ -238,7 +237,6 @@ def __init__(self, tlp=None): self.lower_address = tlp.lower_address self.address = tlp.address self.ph = tlp.ph - self.register_number = tlp.register_number self.data = bytearray(tlp.data) self.seq = tlp.seq @@ -506,7 +504,7 @@ def pack_header(self): pkt.extend(struct.pack('>L', dw)) if self.fmt_type in {TlpType.CFG_READ_0, TlpType.CFG_WRITE_0, TlpType.CFG_READ_1, TlpType.CFG_WRITE_1}: - dw = (self.register_number & 0x3ff) << 2 + dw = self.address & 0xffc dw |= int(self.dest_id) << 16 pkt.extend(struct.pack('>L', dw)) else: @@ -578,7 +576,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.register_number = (dw >> 2) & 0x3ff + tlp.address = dw & 0xffc tlp.dest_id = PcieId.from_int(dw >> 16) elif tlp.fmt in {TlpFmt.FOUR_DW, TlpFmt.FOUR_DW_DATA}: val, = struct.unpack_from('>Q', pkt, 8) @@ -640,7 +638,6 @@ def __eq__(self, other): self.lower_address == other.lower_address and self.address == other.address and self.ph == other.ph and - self.register_number == other.register_number and self.seq == other.seq ) return False @@ -669,7 +666,6 @@ def __repr__(self): f"lower_address={self.lower_address:#x}, " f"address={self.address:#x}, " f"ph={self.ph}, " - f"register_number={self.register_number:#x}, " f"seq={self.seq})" ) diff --git a/cocotbext/pcie/xilinx/us/tlp.py b/cocotbext/pcie/xilinx/us/tlp.py index 4710d85..6d0660b 100644 --- a/cocotbext/pcie/xilinx/us/tlp.py +++ b/cocotbext/pcie/xilinx/us/tlp.py @@ -309,7 +309,7 @@ def pack_us_rq(self): # Completer Request descriptor if self.fmt_type in {TlpType.CFG_READ_0, TlpType.CFG_WRITE_0, TlpType.CFG_READ_1, TlpType.CFG_WRITE_1}: # configuration - dw = (self.register_number & 0x3ff) << 2 + dw = self.address & 0xffc pkt.data.append(dw) pkt.data.append(0) else: @@ -377,7 +377,7 @@ def unpack_us_rq(cls, pkt, check_parity=False): tlp.fmt = TlpFmt.FOUR_DW_DATA else: # configuration - tlp.register_number = (pkt.data[0] >> 2) & 0x3ff + tlp.address = pkt.data[0] & 0xffc tlp.completer_id = PcieId.from_int(pkt.data[3] >> 8) tlp.requester_id_enable = bool(pkt.data[3] & (1 << 24)) @@ -538,8 +538,7 @@ def __eq__(self, other): self.last_be == other.last_be and self.lower_address == other.lower_address and self.address == other.address and - self.ph == other.ph and - self.register_number == other.register_number + self.ph == other.ph ) return False @@ -566,6 +565,5 @@ def __repr__(self): f"last_be={self.last_be:#x}, " f"lower_address={self.lower_address:#x}, " f"address={self.address:#x}, " - f"ph={self.ph}, " - f"register_number={self.register_number:#x})" + f"ph={self.ph})" )