Skip to content

Commit c56a8ec

Browse files
verification: Add regression test for TX_DESC_STAT spurious interrupt
Regression test for issue chipsalliance#184. Co-authored-by: Florian Glaser <glaserf@lowrisc.org> Signed-off-by: Kacper Słomiński <kslominski@antmicro.com>
1 parent f876e1c commit c56a8ec

2 files changed

Lines changed: 97 additions & 3 deletions

File tree

‎verification/cocotb/top/lib_i3c_top/test_interrupts.py‎

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
import cocotb
1515
from cocotb.regression import TestFactory
1616
from cocotb.triggers import ClockCycles, Event, RisingEdge, Timer
17-
from common import timeout_task, log_seed
17+
from common import timeout_task, log_seed, VALID_I3C_ADDRESSES
1818

1919
# =============================================================================
2020

2121
TARGET_ADDRESS = 0x5A
2222

2323

24-
async def test_setup(dut, timeout_us=25):
24+
async def test_setup(dut, timeout_us=25, static_addr=0x5A, virtual_static_addr=0x5B):
2525
"""
2626
Sets up controller, target models and top-level core interface
2727
"""
@@ -52,7 +52,7 @@ async def test_setup(dut, timeout_us=25):
5252
await tb.setup()
5353

5454
# Configure the top level
55-
await boot_init(tb)
55+
await boot_init(tb, static_addr=static_addr, virtual_static_addr=virtual_static_addr)
5656

5757
return i3c_controller, i3c_target, tb
5858

@@ -187,6 +187,87 @@ async def bus_task(evt):
187187

188188
await tb.teardown()
189189

190+
@cocotb.test()
191+
async def test_tx_desc_stat_virtual_device_masked(dut):
192+
"""
193+
Regression for spurious TX_DESC_STAT interrupt on a virtual-device read.
194+
Bug: https://github.com/chipsalliance/i3c-core/issues/184
195+
196+
A Private Read to the virtual (recovery) device must not raise TX_DESC_STAT
197+
(masked in tti.sv by `~virtual_device_sel_i & tx_pr_start_i`). On the buggy
198+
RTL, virtual_device_sel_i lags the combinational tx_pr_start_i by one cycle,
199+
so the mask fails and the interrupt fires for the virtual device too.
200+
201+
Checks (via the irq_o output line and the interrupt status register):
202+
- Private Read to MAIN target -> TX_DESC_STAT asserts (control)
203+
- Private Read to VIRTUAL device -> TX_DESC_STAT stays clear (fails on buggy RTL)
204+
"""
205+
206+
# Two distinct, randomly-picked valid I3C addresses for the main and virtual
207+
# devices, threaded into the DUT configuration so stimulus and config match.
208+
main_addr, virt_addr = random.sample(VALID_I3C_ADDRESSES, 2)
209+
dut._log.info(f"main_addr=0x{main_addr:02X}, virt_addr=0x{virt_addr:02X}")
210+
211+
# Setup
212+
i3c_controller, _, tb = await test_setup(
213+
dut, static_addr=main_addr, virtual_static_addr=virt_addr
214+
)
215+
irq = dut.xi3c_wrapper.irq_o
216+
217+
# Enable only the TX descriptor status interrupt so irq_o reflects it alone.
218+
csr = tb.reg_map.I3C_EC.TTI.INTERRUPT_ENABLE
219+
await tb.write_csr_field(csr.base_addr, csr.TX_DESC_STAT_EN, 1)
220+
221+
int_status = tb.reg_map.I3C_EC.TTI.INTERRUPT_STATUS
222+
223+
async def private_read(addr):
224+
# Precondition: clear TX_DESC_STAT (W1C) and confirm irq_o is low.
225+
await tb.write_csr_field(int_status.base_addr, int_status.TX_DESC_STAT, 1)
226+
await ClockCycles(tb.clk, 10)
227+
assert irq.value == 0, f"IRQ expected 0 before stimulus, got {int(irq.value)}"
228+
229+
# Private Read (no TX data queued -> NACKed, but tx_pr_start still pulses
230+
# on the address match, which is what exercises the mask).
231+
await i3c_controller.i3c_read(addr, 4)
232+
await ClockCycles(tb.clk, 20)
233+
234+
# Control: a Private Read to the MAIN target must set TX_DESC_STAT and drive irq_o.
235+
await private_read(main_addr)
236+
intrs = await get_interrupt_status(tb)
237+
dut._log.info(f"Private Read @ main (0x{main_addr:02X}) -> "
238+
f"TX_DESC_STAT={intrs['TX_DESC_STAT']}, irq_o={int(irq.value)}")
239+
assert intrs["TX_DESC_STAT"] == 1, (
240+
"Control failed: Private Read to the main target should set TX_DESC_STAT"
241+
)
242+
assert irq.value == 1, "Control failed: irq_o should assert for the main-target read"
243+
244+
# Verify W1C clear behavior explicitly: writing 1 clears the bit, irq_o drops
245+
# and stays low (no spurious re-assertion after the transaction).
246+
await tb.write_csr_field(int_status.base_addr, int_status.TX_DESC_STAT, 1)
247+
await ClockCycles(tb.clk, 10)
248+
assert (
249+
await tb.read_csr_field(int_status.base_addr, int_status.TX_DESC_STAT)
250+
) == 0, "TX_DESC_STAT should be W1C-cleared after the main-target read"
251+
assert irq.value == 0, "irq_o should deassert after clearing TX_DESC_STAT"
252+
253+
# Bug check: a Private Read to the VIRTUAL device must NOT set TX_DESC_STAT
254+
# nor drive irq_o. On the buggy RTL virtual_device_sel_i lags tx_pr_start_i by
255+
# one cycle, so the mask fails and these assertions fire.
256+
await private_read(virt_addr)
257+
intrs = await get_interrupt_status(tb)
258+
dut._log.info(f"Private Read @ virtual(0x{virt_addr:02X}) -> "
259+
f"TX_DESC_STAT={intrs['TX_DESC_STAT']}, irq_o={int(irq.value)}")
260+
assert intrs["TX_DESC_STAT"] == 0, (
261+
"BUG: TX_DESC_STAT was set by a Private Read to the virtual (recovery) "
262+
"device. The ~virtual_device_sel_i mask in tti.sv is applied one cycle "
263+
"too late relative to the combinational tx_pr_start_i pulse."
264+
)
265+
assert irq.value == 0, (
266+
"BUG: irq_o asserted for a Private Read to the virtual (recovery) device"
267+
)
268+
269+
await tb.teardown()
270+
190271
@cocotb.test()
191272
async def test_ibi_done(dut):
192273

‎verification/testplan/top/target_interrupts.hjson‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,18 @@
9393
"specific_interrupt_force"]
9494
tags: ["top"]
9595
}
96+
{
97+
name: tx_desc_stat_virtual_device_masked
98+
desc:
99+
'''
100+
Ensures that irq_o is deasserted. Enables the TX_DESC_STAT_EN TTI
101+
interrupt. Issues a private read to the main target and checks that
102+
the TX_DESC_STAT interrupt was asserted. Clears the interrupt via the
103+
INTERRUPT_STATUS CSR. Issues a private read to the virtual target and
104+
ensures that no interrupt was asserted.
105+
'''
106+
tests: ["tx_desc_stat_virtual_device_masked"]
107+
tags: ["top"]
108+
}
96109
]
97110
}

0 commit comments

Comments
 (0)