|
14 | 14 | import cocotb |
15 | 15 | from cocotb.regression import TestFactory |
16 | 16 | 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 |
18 | 18 |
|
19 | 19 | # ============================================================================= |
20 | 20 |
|
21 | 21 | TARGET_ADDRESS = 0x5A |
22 | 22 |
|
23 | 23 |
|
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): |
25 | 25 | """ |
26 | 26 | Sets up controller, target models and top-level core interface |
27 | 27 | """ |
@@ -52,7 +52,7 @@ async def test_setup(dut, timeout_us=25): |
52 | 52 | await tb.setup() |
53 | 53 |
|
54 | 54 | # Configure the top level |
55 | | - await boot_init(tb) |
| 55 | + await boot_init(tb, static_addr=static_addr, virtual_static_addr=virtual_static_addr) |
56 | 56 |
|
57 | 57 | return i3c_controller, i3c_target, tb |
58 | 58 |
|
@@ -187,6 +187,87 @@ async def bus_task(evt): |
187 | 187 |
|
188 | 188 | await tb.teardown() |
189 | 189 |
|
| 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 | + |
190 | 271 | @cocotb.test() |
191 | 272 | async def test_ibi_done(dut): |
192 | 273 |
|
|
0 commit comments