Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/ctrl/descriptor_rx.sv
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ module descriptor_rx #(

logic [31:0] rx_descriptor;
logic [15:0] byte_counter;
logic [15:0] byte_counter_q;
logic [3:0] rx_error;

logic transfer_ended;
logic transfer_ended_q;

assign transfer_ended = rx_byte_last_i;

Expand All @@ -75,17 +73,11 @@ module descriptor_rx #(

always_ff @(posedge clk_i or negedge rst_ni) begin : proc_error
if (!rst_ni) begin
byte_counter_q <= '0;
transfer_ended_q <= '0;
rx_error <= '0;
end else begin
transfer_ended_q <= transfer_ended;
if (transfer_ended) begin
byte_counter_q <= byte_counter;
end
if (rx_byte_err_i)
rx_error <= 4'b0001;
else if (transfer_ended_q)
else if (transfer_ended)
rx_error <= 4'b0000;
end
end
Expand All @@ -94,9 +86,11 @@ module descriptor_rx #(
assign rx_byte_ready_o = tti_rx_queue_wready_i;
assign tti_rx_queue_wdata_o = rx_byte_i;

assign rx_descriptor = {rx_error, {12{1'b0}}, byte_counter_q};
// Build descriptor combinationally: byte_counter is still valid during the
// transfer_ended cycle (before the clock edge resets it to 0)
assign rx_descriptor = {rx_error, {12{1'b0}}, byte_counter};
assign tti_rx_desc_queue_wdata_o = rx_descriptor;
assign tti_rx_desc_queue_wvalid_o = transfer_ended_q;
assign tti_rx_queue_flush_o = transfer_ended_q;
assign tti_rx_desc_queue_wvalid_o = transfer_ended;

@clayton8 clayton8 Feb 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkj121 This aligns the interrupt in tti.sv with the virtual_device_sel_i so interrupts aren't getting asserted when targeting RI.

assign tti_rx_queue_flush_o = transfer_ended;

endmodule
42 changes: 20 additions & 22 deletions src/recovery/recovery_handler.sv
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,7 @@ module recovery_handler
// - ctl_bus_addr_valid_q: For posedge detection of address valid
// - ctl_bus_addr_valid_posedge_q: Delayed posedge aligned with virtual_device_sel_i
//
// FUTUREFIX: The descriptor_rx module sends tti_rx_queue_flush 1 cycle after the
// transfer ends (transfer_ended_q). However, virtual_device_sel_i goes low on
// the same cycle that transfer_ended fires, causing recovery_pending to
// deassert before the flush arrives. This creates a race where the mux
// selects descriptor_rx's flush instead of recovery's, corrupting the FIFO.
// Extending virtual_device_sel_i by 1 cycle ensures recovery_pending stays
// high to block the spurious flush from descriptor_rx.
// The flush race is resolved in descriptor_rx (flush fires on transfer_ended cycle).
//----------------------------------------------------------------------------
always_ff @(posedge clk_i or negedge rst_ni) begin
if (!rst_ni) begin
Expand Down Expand Up @@ -724,23 +718,27 @@ module recovery_handler
always_comb begin : R1MUX
if (recovery_pending) begin
tti_rx_desc_queue_wvalid = '0;
ctl_tti_rx_desc_queue_full_o = '0;
ctl_tti_rx_desc_queue_depth_o = '0;
ctl_tti_rx_desc_queue_empty_o = '0;
ctl_tti_rx_desc_queue_wready_o = 1'b1;
ctl_tti_rx_desc_queue_empty_o = 1'b1; // Need to hide empty to reject AXI reads
csr_tti_rx_desc_queue_ready_thld_trig_o = '0;

ctl_tti_rx_data_queue_empty_o = 1'b1; // Need to hide empty to reject AXI reads
end else begin
tti_rx_desc_queue_wvalid = ctl_tti_rx_desc_queue_wvalid_i;
ctl_tti_rx_desc_queue_full_o = tti_rx_desc_queue_full;
ctl_tti_rx_desc_queue_depth_o = tti_rx_desc_queue_depth;
ctl_tti_rx_desc_queue_empty_o = tti_rx_desc_queue_empty;
ctl_tti_rx_desc_queue_wready_o = tti_rx_desc_queue_wready;
csr_tti_rx_desc_queue_ready_thld_trig_o = tti_rx_desc_queue_ready_thld_trig;

ctl_tti_rx_data_queue_empty_o = tti_rx_data_queue_empty;
end

tti_rx_desc_queue_wdata = ctl_tti_rx_desc_queue_wdata_i; // Don't mux data, disabling valid is enough
end
tti_rx_desc_queue_wdata = ctl_tti_rx_desc_queue_wdata_i; // Don't mux data, disabling valid is enough

ctl_tti_rx_desc_queue_wready_o = tti_rx_desc_queue_wready;

// Don't hide status of queue from status registers
ctl_tti_rx_desc_queue_full_o = tti_rx_desc_queue_full;
ctl_tti_rx_desc_queue_depth_o = tti_rx_desc_queue_depth;

end
// Threshold
assign ctl_tti_rx_desc_queue_ready_thld_o = tti_rx_desc_queue_ready_thld_o;
assign ctl_tti_rx_desc_queue_ready_thld_trig_o = tti_rx_desc_queue_ready_thld_trig;
Expand Down Expand Up @@ -786,9 +784,6 @@ module recovery_handler
recv_tti_rx_data_valid = ctl_tti_rx_data_queue_wvalid_i;
tti_rx_data_queue_wvalid = '0;
tti_rx_data_queue_flush = recv_tti_rx_data_queue_flush;
ctl_tti_rx_data_queue_full_o = tti_rx_data_queue_full;
ctl_tti_rx_data_queue_depth_o = tti_rx_data_queue_depth;
ctl_tti_rx_data_queue_empty_o = tti_rx_data_queue_empty;
ctl_tti_rx_data_queue_wready_o = recv_tti_rx_data_ready;
ctl_tti_rx_data_queue_start_thld_trig_o = '0;
csr_tti_rx_data_queue_ready_thld_trig_o = '0;
Expand All @@ -797,9 +792,6 @@ module recovery_handler
recv_tti_rx_data_valid = '0;
tti_rx_data_queue_wvalid = ctl_tti_rx_data_queue_wvalid_i;
tti_rx_data_queue_flush = ctl_tti_rx_data_queue_flush_i;
ctl_tti_rx_data_queue_full_o = tti_rx_data_queue_full;
ctl_tti_rx_data_queue_depth_o = tti_rx_data_queue_depth;
ctl_tti_rx_data_queue_empty_o = tti_rx_data_queue_empty;
ctl_tti_rx_data_queue_wready_o = tti_rx_data_queue_wready;
ctl_tti_rx_data_queue_start_thld_trig_o = tti_rx_data_queue_start_thld_trig;
csr_tti_rx_data_queue_ready_thld_trig_o = tti_rx_data_queue_ready_thld_trig;
Expand All @@ -808,6 +800,10 @@ module recovery_handler
tti_rx_data_queue_wdata = ctl_tti_rx_data_queue_wdata_i; // Don't mux data, disabling valid is enough
recv_tti_rx_data_data = ctl_tti_rx_data_queue_wdata_i;
recv_tti_rx_data_last = ctl_tti_rx_data_queue_wlast_i;

// Don't hide status of queue from status registers
ctl_tti_rx_data_queue_full_o = tti_rx_data_queue_full;
ctl_tti_rx_data_queue_depth_o = tti_rx_data_queue_depth;
end

// Thresholds
Expand Down Expand Up @@ -1098,6 +1094,8 @@ module recovery_handler
.unsupported_err_o,
.rx_fifo_overflow_err_o,
.indirect_fifo_overflow_err_o,
.rx_desc_wvalid_i(ctl_tti_rx_desc_queue_wvalid_i),
.rx_desc_wdata_i (ctl_tti_rx_desc_queue_wdata_i),
.exec_pending_o(recovery_exec_pending),
.recovery_mode_enter_o
);
Expand Down
41 changes: 27 additions & 14 deletions src/recovery/recovery_receiver.sv
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ module recovery_receiver
output logic rx_fifo_overflow_err_o, // RX FIFO overflow error (always reported)
output logic indirect_fifo_overflow_err_o, // INDIRECT_FIFO overflow error

// RX descriptor interface — monitored for bus-level parity errors
input logic rx_desc_wvalid_i,
input logic [TtiRxDescDataWidth-1:0] rx_desc_wdata_i,

//--------------------------------------------------------------------------
// Recovery CSR Interface
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -556,6 +560,7 @@ module recovery_receiver
inc_csr_sel = 1'b0;
load_csr_length = 1'b0;
rx_data_queue_select_o = 1'b0;
rx_data_queue_flush_o = 1'b0;
pec_enable_o = 1'b0;
pec_init_o = 1'b0;
tx_pec_enable_o = 1'b0;
Expand Down Expand Up @@ -652,11 +657,17 @@ module recovery_receiver
premature_stop = 1'b1;
length_underrun_err = length_err_det_en_i; // Report as length error (underrun)
state_d = Error;
end else if (rx_desc_wvalid_i && |rx_desc_wdata_i[31:28] && pec_err_det_en_i) begin
// RX descriptor reports bus-level error (T-bit parity) on write-phase PEC
// rx_desc_wvalid_i will be asserted same clock cycle as
// bus_rstart_i. If not assertion fires
pec_err = 1'b1;
state_d = Error;

@clayton8 clayton8 Feb 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkj121 - Finds parity error in PEC during the W part of the RI R. Remember we do RI PW + RI PR. This would only trigger if PEC is valid but T-bit of PEC is invalid.

end else if (bus_rstart_i) begin
// Repeated Start (Sr) indicates READ command - controller wants to read
set_cmd_is_rd = 1'b1;
latch_pec_from_len = 1'b1;
state_d = CmdDispatch;
state_d = CmdDispatch;
end else if (rx_flow) begin
capture_len_msb = 1'b1;
pec_enable_o = 1'b1;
Expand Down Expand Up @@ -699,8 +710,16 @@ module recovery_receiver
premature_stop = 1'b1;
length_underrun_err = ((payload_byte_cnt < cmd_len) || pec_rx_byte_cnt == '0) && length_err_det_en_i;
state_d = Error;
end else if (rx_data_last_i && |rx_desc_wdata_i[31:28] && pec_err_det_en_i) begin
// RX descriptor reports bus-level error (T-bit parity or overflow)
// rx_data_last_i should be asserted the same clock cycle
// as rx_desc_wvalid_i if not an assertion will fire.
pec_err = 1'b1;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkj121 - Finds parity error in PEC during RI write. This would only trigger if PEC is valid but T-bit of PEC is invalid.

state_d = Error;
end else if (rx_data_last_i) begin
state_d = CmdDispatch;
state_d = CmdDispatch;
// Flush partial word from width converter before ExecCsrWrite reads
rx_data_queue_flush_o = |(payload_byte_cnt[1:0]);
end
end

Expand Down Expand Up @@ -886,18 +905,6 @@ module recovery_receiver
// During Error, bytes are accepted but discarded via converter soft reset.
assign rx_data_ready_o = state_q inside {RxCmd, RxLenL, RxLenH, RxData, RxPec, Error};


//----------------------------------------------------------------------------
// RX Queue Flush/Clear Control
//----------------------------------------------------------------------------
always_ff @(posedge clk_i or negedge rst_ni) begin
if (!rst_ni) begin
rx_data_queue_flush_o <= 1'b0;
end else begin
rx_data_queue_flush_o <= (state_q == CmdDispatch) && |(payload_byte_cnt[1:0]);
end
end

// Assert soft reset to width converters during Error state (combinational for immediate effect)
assign conv_soft_reset_o = (state_q == Error);

Expand Down Expand Up @@ -1777,5 +1784,11 @@ module recovery_receiver
// INDIRECT_FIFO overflow: reported on each overflow event
assign indirect_fifo_overflow_err_o = indirect_fifo_overflow_err;

// rx_desc_wvalid_i must align with rx_data_last_i (both driven by transfer_ended)
`I3C_ASSERT(RxDescAlignedWithLast_A, rx_data_last_i |-> rx_desc_wvalid_i)

// rx_desc_wvalid_i must fire on Sr in RxLenH (read-flow write-phase ends here)
`I3C_ASSERT(RxDescAlignedWithRstart_A, (state_q == RxLenH) && bus_rstart_i |-> rx_desc_wvalid_i)

endmodule

Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ async def test_descriptor_rx(dut: SimHandleBase):

assert dut.rx_byte_ready_o.value == 1

# Send 5 bytes and wait for the RX descriptor
# Send 5 bytes and signal end of transfer
for i in range(5):
await send_byte(dut, i)
await cycle(dut.clk_i, dut.rx_byte_last_i)

# Assert rx_byte_last_i for one cycle; descriptor is valid on the same cycle
dut.rx_byte_last_i.value = 1
await ClockCycles(dut.clk_i, 1)
assert dut.tti_rx_desc_queue_wvalid_o.value == 1
assert dut.tti_rx_desc_queue_wdata_o.value == 5
dut.rx_byte_last_i.value = 0

await ClockCycles(dut.clk_i, 3)
1 change: 1 addition & 0 deletions verification/cocotb/top/i3c_ahb/test_ccc.py
1 change: 1 addition & 0 deletions verification/cocotb/top/i3c_ahb/test_empty_queue_read.py
1 change: 1 addition & 0 deletions verification/cocotb/top/i3c_axi/test_empty_queue_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,42 @@ async def command_write_tbit_error(self, address, command, data=None, error_byte
await self.controller.send_stop()
self.controller.give_bus_control()

async def command_read_tbit_error(self, address, command, error_byte_index=0):
"""
Issues a read command with T-bit error on a specific byte in the write phase.

Write phase xfer: [CMD(0), PEC(1)]. After error injection, attempts
the read phase (Sr + Addr+R). Returns None if target NACKs.

Args:
address: I3C target address
command: OCP Recovery command code
error_byte_index: Byte index in write phase to corrupt (0=CMD, 1=PEC)

Returns:
Tuple of (data, pec_ok) or (None, None) if target NACKed
"""
xfer = [command]
pec = int(self.pec_calc.checksum(bytes([address << 1] + xfer)))
xfer.append(pec)

await self.controller.take_bus_control()
await self.controller.send_start()
await self.controller.write_addr_header(I3C_RSVD_BYTE)
await self.controller.send_start()
ack = await self.controller.write_addr_header(address)

if ack:
for i, byte in enumerate(xfer):
inject_error = (i == error_byte_index)
await self.controller.send_byte_tbit(byte, inject_tbit_err=inject_error)

# Continue with read phase — target may NACK if error was detected
try:
return await self._i3c_recovery_read(address, send_stop=True)
except I3cRecoveryException:
return None, None

async def command_write_truncated(self, address, command, data=None, truncate_before_pec=True):
"""
Issues a write command but truncates it before sending PEC.
Expand Down
10 changes: 10 additions & 0 deletions verification/cocotb/top/lib_i3c_top/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from bus2csr import get_frontend_bus_if
from cocotb_helpers import reset_n
from reg_map import reg_map
from tti_monitor import TtiQueueMonitor

import cocotb
from cocotb.handle import SimHandleBase
Expand All @@ -23,6 +24,7 @@ def __init__(self, dut: SimHandleBase) -> None:
self.write_csr = self.busIf.write_csr
self.read_csr_field = self.busIf.read_csr_field
self.write_csr_field = self.busIf.write_csr_field
self.tti_monitor = None

async def setup(self, fclk=500.0):

Expand All @@ -41,3 +43,11 @@ async def setup(self, fclk=500.0):
await self.busIf.register_test_interfaces(fclk)
await ClockCycles(self.clk, 20)
await reset_n(self.clk, self.rst_n, cycles=5)

# Start TtiQueueMonitor for every test
try:
self.tti_monitor = TtiQueueMonitor(self.dut)
cocotb.start_soon(self.tti_monitor.run())
except AttributeError:
self.dut._log.warning("TtiQueueMonitor: required signals not found, skipping")
self.tti_monitor = None
Loading