Skip to content

Commit fe36342

Browse files
Cover x_QUEUE_DEPTH and x_QUEUE_FULL CSRs
1 parent 941f083 commit fe36342

3 files changed

Lines changed: 57 additions & 7 deletions

File tree

verification/cocotb/top/lib_i3c_top/test_bus_stall.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,68 @@ async def test_empty_indirect_fifo_read(dut):
6565
@cocotb.test()
6666
async def test_full_tx_desc_write(dut):
6767
tb = await initialize(dut)
68-
for _ in range(TRANSACTION_COUNT):
68+
QSIZE = tb.reg_map.I3C_EC.TTI.QUEUE_SIZE
69+
QDEPTH = tb.reg_map.I3C_EC.TTI.DESC_QUEUE_DEPTH
70+
QSTAT = tb.reg_map.I3C_EC.TTI.QUEUE_STATUS
71+
MAX_DEPTH = 2 ** (await tb.read_csr_field(QSIZE.base_addr, QSIZE.TX_DESC_BUFFER_SIZE) + 1)
72+
73+
for i in range(TRANSACTION_COUNT):
6974
await tb.write_csr(tb.reg_map.I3C_EC.TTI.TX_DESC_QUEUE_PORT.base_addr, int2dword(random.randint(0, 0xffffffff)), 4)
75+
if i < MAX_DEPTH:
76+
depth = await tb.read_csr_field(QDEPTH.base_addr, QDEPTH.TX_DESC_QUEUE_DEPTH)
77+
assert i + 1 == depth, "Transaction did not increase queue depth"
78+
7079
# Bus must not stall — verify it's still responsive
7180
data = dword2int(await tb.read_csr(tb.reg_map.I3CBASE.HCI_VERSION.base_addr, 4))
7281
assert data == 0x120, f"Bus stalled: HCI_VERSION read returned 0x{data:X} after {TRANSACTION_COUNT} TX_DESC writes"
7382

83+
assert await tb.read_csr_field(QSTAT.base_addr, QSTAT.TX_DESC_QUEUE_FULL) == 1, "Queue is not full"
84+
7485
await reset_n(tb.clk, tb.rst_n, cycles=5)
7586
await tb.teardown()
7687

7788
@cocotb.test()
7889
async def test_full_tx_data_write(dut):
7990
tb = await initialize(dut)
80-
for _ in range(TRANSACTION_COUNT):
91+
QSIZE = tb.reg_map.I3C_EC.TTI.QUEUE_SIZE
92+
QDEPTH = tb.reg_map.I3C_EC.TTI.DATA_QUEUE_DEPTH
93+
QSTAT = tb.reg_map.I3C_EC.TTI.QUEUE_STATUS
94+
MAX_DEPTH = 2 ** (await tb.read_csr_field(QSIZE.base_addr, QSIZE.TX_DATA_BUFFER_SIZE) + 1)
95+
96+
for i in range(TRANSACTION_COUNT):
8197
await tb.write_csr(tb.reg_map.I3C_EC.TTI.TX_DATA_PORT.base_addr, int2dword(random.randint(0, 0xffffffff)), 4)
98+
if i <= MAX_DEPTH+1 and i > 0:
99+
depth = await tb.read_csr_field(QDEPTH.base_addr, QDEPTH.TX_DATA_QUEUE_DEPTH)
100+
assert i == depth + 1, "Transaction did not increase queue depth"
101+
82102
# Bus must not stall — verify it's still responsive
83103
data = dword2int(await tb.read_csr(tb.reg_map.I3CBASE.HCI_VERSION.base_addr, 4))
84104
assert data == 0x120, f"Bus stalled: HCI_VERSION read returned 0x{data:X} after {TRANSACTION_COUNT} TX_DATA writes"
85105

106+
assert await tb.read_csr_field(QSTAT.base_addr, QSTAT.TX_DATA_QUEUE_FULL) == 1, "Queue is not full"
107+
86108
await reset_n(tb.clk, tb.rst_n, cycles=5)
87109
await tb.teardown()
88110

89111
@cocotb.test()
90112
async def test_full_ibi_write(dut):
91113
tb = await initialize(dut)
92-
for _ in range(TRANSACTION_COUNT):
114+
QSIZE = tb.reg_map.I3C_EC.TTI.IBI_QUEUE_SIZE
115+
QDEPTH = tb.reg_map.I3C_EC.TTI.IBI_QUEUE_DEPTH
116+
QSTAT = tb.reg_map.I3C_EC.TTI.QUEUE_STATUS
117+
MAX_DEPTH = 2 ** (await tb.read_csr_field(QSIZE.base_addr, QSIZE.IBI_QUEUE_SIZE) + 1)
118+
119+
for i in range(TRANSACTION_COUNT):
93120
await tb.write_csr(tb.reg_map.I3C_EC.TTI.IBI_PORT.base_addr, int2dword(random.randint(0, 0xffffffff)), 4)
121+
if i < MAX_DEPTH:
122+
depth = await tb.read_csr_field(QDEPTH.base_addr, QDEPTH.IBI_QUEUE_DEPTH)
123+
assert i + 1 == depth, "Transaction did not increase queue depth"
124+
94125
# Bus must not stall — verify it's still responsive
95126
data = dword2int(await tb.read_csr(tb.reg_map.I3CBASE.HCI_VERSION.base_addr, 4))
96127
assert data == 0x120, f"Bus stalled: HCI_VERSION read returned 0x{data:X} after {TRANSACTION_COUNT} IBI writes"
97128

129+
assert await tb.read_csr_field(QSTAT.base_addr, QSTAT.IBI_QUEUE_FULL) == 1, "Queue is not full"
130+
98131
await reset_n(tb.clk, tb.rst_n, cycles=5)
99132
await tb.teardown()

verification/cocotb/top/lib_i3c_top/test_i3c_target.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ async def test_setup(dut, fclk=333.0, fbus=12.5,
9090

9191
# Receiver agent (firmware side)
9292
async def rx_agent(tb, data_transfers):
93+
QSIZE = tb.reg_map.I3C_EC.TTI.QUEUE_SIZE
94+
QDEPTH = tb.reg_map.I3C_EC.TTI.DATA_QUEUE_DEPTH
95+
QSTAT = tb.reg_map.I3C_EC.TTI.QUEUE_STATUS
96+
MAX_DEPTH = 2 ** (await tb.read_csr_field(QSIZE.base_addr, QSIZE.RX_DATA_BUFFER_SIZE) + 1)
97+
9398
recv_data = []
9499

95100
# Enable RX descriptor interrupt
@@ -134,8 +139,14 @@ async def rx_agent(tb, data_transfers):
134139

135140
# Read RX data
136141
data_len = ceil(desc_len / 4)
142+
assert data_len <= MAX_DEPTH
143+
if data_len == MAX_DEPTH:
144+
assert await tb.read_csr_field(QSTAT.base_addr, QSTAT.RX_DATA_QUEUE_FULL) == 1, "Queue is not full, but it should be"
145+
137146
rx_data = []
138-
for _ in range(data_len):
147+
for i in range(data_len):
148+
depth = await tb.read_csr_field(QDEPTH.base_addr, QDEPTH.RX_DATA_QUEUE_DEPTH)
149+
assert depth == data_len - i, f"Unexpected queue depth: {depth}"
139150
data = dword2int(await tb.read_csr(tb.reg_map.I3C_EC.TTI.RX_DATA_PORT.base_addr, 4))
140151
for k in range(4):
141152
rx_data.append((data >> (k * 8)) & 0xFF)

verification/cocotb/top/lib_i3c_top/test_interrupts.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,23 @@ async def test_rx_desc_overflow(dut):
340340

341341
# Setup
342342
i3c_controller, _, tb = await test_setup(dut, timeout_us=500)
343+
QSIZE = tb.reg_map.I3C_EC.TTI.QUEUE_SIZE
344+
QDEPTH = tb.reg_map.I3C_EC.TTI.DESC_QUEUE_DEPTH
345+
QSTAT = tb.reg_map.I3C_EC.TTI.QUEUE_STATUS
346+
MAX_DEPTH = 2 ** (await tb.read_csr_field(QSIZE.base_addr, QSIZE.RX_DESC_BUFFER_SIZE) + 1)
343347

344-
for _ in range(65):
348+
for i in range(MAX_DEPTH):
345349
data = [random.randint(0, 255) for i in range(4)]
346350
await i3c_controller.i3c_write(TARGET_ADDRESS, data)
351+
depth = await tb.read_csr_field(QDEPTH.base_addr, QDEPTH.RX_DESC_QUEUE_DEPTH)
352+
assert i + 1 == depth, "Transaction did not increase queue depth"
347353

348-
assert tb.dut.xi3c_wrapper.i3c.tti_rx_desc_full.value == 1
354+
assert await tb.read_csr_field(QSTAT.base_addr, QSTAT.RX_DESC_QUEUE_FULL) == 1, "Queue is not full, but it should be"
349355

350356
await tb.read_csr(tb.reg_map.I3C_EC.TTI.RX_DESC_QUEUE_PORT.base_addr, 4)
351357

352358
await ClockCycles(tb.clk, 50)
353359

354-
assert tb.dut.xi3c_wrapper.i3c.tti_rx_desc_full.value == 0
360+
assert await tb.read_csr_field(QSTAT.base_addr, QSTAT.RX_DESC_QUEUE_FULL) == 0, "Queue is full, but it should not be"
355361

356362
await tb.teardown()

0 commit comments

Comments
 (0)