Repository navigation
Recovery Interface Restructure - #121
Conversation
clayton8
commented
Jan 30, 2026
- Add new RI test that does complext reads and writes - Add new capabilities to COCOCTB source repo for start/stop capabilities
1. Merge 3 FSMs into one 2. Fix many issues reguarding B2B transactions with Sr 3. Properly handle protocol errors 4. Add RI error interrupt controls
[884] W425 N.A error i3c-core/src/ctrl/bus_tx_flow.sv 68 5 Function uses a global variable: data [885] W425 N.A error i3c-core/src/ctrl/bus_tx_flow.sv 69 5 Function uses a global variable: tx_req_i.req_bit [882] W121 N.A error i3c-core/src/ctrl/bus_tx_flow.sv 65 5 Name 'req_value_d' is not unique - may shadow another variable(Previously used at line no. 46 in i3c-core/src/ctrl/bus_tx_flow.sv) [883] W121 N.A error i3c-core/src/ctrl/bus_tx_flow.sv 66 5 Name 'bit_counter_en' is not unique - may shadow another variable(Previously used at line no. 41 in i3c-core/src/ctrl/bus_tx_flow.sv)
- RI detects and reports INDIRECT_FIFO overflow error - RI detects and reports RX_FIFO overflow error - RI detects and reports invalid write length to CSR
mkj121
left a comment
There was a problem hiding this comment.
Some of these (Python) are stylistic and we can probably ignore those
| }; | ||
|
|
||
| assign indirect_fifo_status_0 = { | ||
| 16'd0, 5'd0, |
There was a problem hiding this comment.
Is there any reason that this is not also '0 ?
There was a problem hiding this comment.
I missed this one...
HDR was not exiting properly due to us not validating the address with an addr_valid signal. Also the addr_valid signal wasn't getting cleared properly from a stop or entering HDR mode. RI now properly handles HDR mode + invalid command sequences like Write + Sr + CCC or Write + Sr + Write (invalid)
RI write was broken due to error logic incorrectly detecting an error
- Add many different error scenario tests - Add override classes for the cocotbext_i3c classes to fix some functions and add additional functionality - Remove a ton of timers to reduce runtime
glaserf
left a comment
There was a problem hiding this comment.
Thanks for the excellent refactoring, especially of the FSMs and merging them! I am still not fully done looking through all the changes around the recovery handler/receiver and will continue tomorrow.
For now I have a couple of minor and cosmetic comments, and a general one regarding the recovery receiver. state_q is used around 30 times outside of the FSM to calculate all kinds of signals, which are essentially all FSM outputs (often solely depending on the state).
While I think this makes sense for some signals (like output data mux), it often distributes core FSM functionality around the file, which makes following and understanding the functionality sometimes really tricky. IMHO we should include more functionality into the main FSM process, but I'll let you be the judge if you want to go through this trouble at the current state of the project.
| //============================================================================ | ||
| // | ||
| // SECTION 4: RECOVERY MODE CONTROL | ||
| // | ||
| //============================================================================ |
There was a problem hiding this comment.
There are a lot of always_ff in this section which mostly only provide delayed versions of one signal each. I suggest to merge these into a single process to avoid the syntactical overhead for every signal.
| // Command validation - Raw detection (evaluated in CmdDispatch) | ||
| // Read-only commands: PROT_CAP, DEVICE_ID, DEVICE_STATUS, HW_STATUS, INDIRECT_STATUS, INDIRECT_FIFO_STATUS | ||
| assign readonly_err_raw = !cmd_is_rd && ( | ||
| (cmd_cmd == CMD_PROT_CAP) || |
There was a problem hiding this comment.
Could be replaced by a more readable inside {..}
There was a problem hiding this comment.
I think so let me try that.
| (cmd_len != csr_length_next); | ||
|
|
||
| // CSR write length validation - Enabled error | ||
| assign csr_length_err_en = csr_length_err_raw && length_err_det_en_i; |
There was a problem hiding this comment.
Suggest to change the suffix of the LHS to _masked or drop it, as _en suggest its the enable signal for said error.
There was a problem hiding this comment.
Ah yes I like this suggestion.
| end | ||
| else if (rx_flow) begin |
There was a problem hiding this comment.
end else if is handled inconsistently within the FSM (sometimes broken across two lines).
There was a problem hiding this comment.
let me clean this up.
| if (!rst_ni) cmd_is_rd <= 1'b0; | ||
| else if (state_q == Idle) cmd_is_rd <= 1'b0; | ||
| else if (set_cmd_is_rd) cmd_is_rd <= 1'b1; |
There was a problem hiding this comment.
set_cmd_is_rd is only set in one place inside the FSM, and only read here. Instead, cmd_is_rd_d could directly get set inside the FSM.
There was a problem hiding this comment.
You are suggesting having:
if (!rst_ni) cmd_is_rd <= 1'b0;
else cmd_is_rd <= cmd_is_rd_d;
?
There was a problem hiding this comment.
and in the FSM just set cmd_is_rd_d = 1 in a particular state?
| if (!rst_ni) len_lsb <= '0; | ||
| else if (latch_pec_from_len) len_lsb <= '0; | ||
| else if (capture_len_lsb) len_lsb <= rx_data_i; | ||
|
|
||
| always_ff @(posedge clk_i or negedge rst_ni) | ||
| if (!rst_ni) len_msb <= '0; | ||
| else if (latch_pec_from_len) len_msb <= '0; | ||
| else if (capture_len_msb) len_msb <= rx_data_i; |
There was a problem hiding this comment.
Suggest to merge these three very similar capture processes into one.
There was a problem hiding this comment.
Merging these into 1 always_ff would look like
always_ff @(posedge clk_i or negedge rst_ni) begin
if (!rst_ni) begin
len_lsb <= '0;
len_msb <= '0;
cmd_cmd <= command_e'('0);
end else if (latch_pec_from_len) begin
len_lsb <= '0;
len_msb <= '0;
end else begin
if (capture_cmd) begin
cmd_cmd <= command_e'(rx_data_i);
end
if (capture_len_lsb) begin
len_lsb <= rx_data_i;
end
if (capture_len_msb) begin
len_msb <= rx_data_i;
end
end
My concern is if the latch_pec_from_len is set in the same state as capture_cmd this could easily turn into a bug. hence why I kept the FF controls separate to be as safe as possible.
| assign length_underrun_err_raw = (payload_byte_cnt < cmd_len) || pec_rx_byte_cnt == 0; | ||
| assign length_overrun_err_raw = (pec_rx_byte_cnt > 1); |
There was a problem hiding this comment.
These conditions only apply to certain states at all, and for example pec_rx_byte_cnt == 0 is checked again in the RxPec state before setting the respective error flag. The whole under/overrun error calculation seems to be gated/split across 3-4 places within this file, and I find it very hard to follow, even though the actual logic is IIUC not that complicated.
I suggest to perform the 'raw' calculation fully within the respective states and then gate the error setting there with the length_err_det_en_i flag.
There was a problem hiding this comment.
Yeah I think at the time I was worried these check would be happening in multiple places within the file so I wanted a central check that could be used to avoid typos. But now that the design is complete this doesn't seem to be the case... I can update these and remove the raw/err_en signals.
|
Could you run a whitespace cleanup over this? There is quite a bit of trailing whitespace, in test_recovery.py in particular. Thanks! |
glaserf
left a comment
There was a problem hiding this comment.
A couple more small points in regards to the recovery receiver, more to follow.
| if (!rst_ni) rx_data_queue_select_reg <= 1'b1; | ||
| else if (state_q == Idle) rx_data_queue_select_reg <= 1'b1; | ||
| else if (state_q == RxLenH && rx_flow) rx_data_queue_select_reg <= 1'b0; | ||
| else if (state_q == RxPec) rx_data_queue_select_reg <= 1'b1; |
There was a problem hiding this comment.
These two are equivalent to
else if ((state_q == RxPec) || (state_d == RxPec)) rx_data_queue_select_reg <= 1'b1;
and directly assigning rx_data_queue_select_reg to rx_data_queue_select_o. Again, I think this would be better handled as a direct FSM output, but probably not the right time to change this.
There was a problem hiding this comment.
I double checked the waves and this can definitely come directly from the FSM without any additional flops. I think I inherited some legacy code and built upon it and didn't fully think this can easily be driven by the FSM.
| assign rx_fifo_overflow_err_raw = rx_fifo_overflow_raw_i; | ||
| assign rx_fifo_overflow_err_en = rx_fifo_overflow_err_raw && rx_fifo_overflow_err_det_en_i; |
There was a problem hiding this comment.
rx_fifo_overflow_err_raw is only used here (one line below its assignment).
There was a problem hiding this comment.
I have moved this code into the FSM. No dedicated err_raw and err_en signal. Just the raw_i and rx_fifo_overflow_err
| hwif_rec_o.RECOVERY_CTRL.CMS.next = tti_rx_rdata_i[7:0]; | ||
| hwif_rec_o.INDIRECT_FIFO_CTRL_0.RESET.next = bypass_i3c_core_i ? sw_indirect_fifo_ctrl_reset_value : tti_rx_rdata_i[15:8]; | ||
| hwif_rec_o.INDIRECT_FIFO_CTRL_0.CMS.next = tti_rx_rdata_i[7:0]; | ||
| hwif_rec_o.INDIRECT_FIFO_CTRL_1.IMAGE_SIZE.next = {tti_rx_rdata_i[15:0], prev_tti_rx_rdata[31:16]}; |
There was a problem hiding this comment.
Is this because we have to get the remaining size in two cycles due to the MSB/LSB split?
There was a problem hiding this comment.
This is their legacy code, it has to do with what bits the IMAGE_SIZE lives in within the INDIRECT_FIFO_CTRL command. I did some testing around this code and it works correct.
| always_ff @(posedge clk_i or negedge rst_ni) | ||
| if (!rst_ni) fifo_ptr_top <= '0; | ||
| else fifo_ptr_top <= fifo_size - 32'h1; |
There was a problem hiding this comment.
Is there a reason why we need to keep a flopped version of this instead of directly using size - 1?
There was a problem hiding this comment.
This is legacy code. This seems overkill. We can probably just do fifo_size - 1 in the code. I can fix this.
| always_ff @(posedge clk_i or negedge rst_ni) | ||
| if (!rst_ni) fifo_reg_reset_clear <= 1'b0; | ||
| else if (|hwif_rec_i.INDIRECT_FIFO_CTRL_0.RESET.value) fifo_reg_reset_clear <= 1'b1; | ||
| else fifo_reg_reset_clear <= 1'b0; |
There was a problem hiding this comment.
Similar question as before, do we really need a 1-cycle delayed/flopped version of |hwif_rec_i.INDIRECT_FIFO_CTRL_0.RESET.value ?
There was a problem hiding this comment.
This also was legacy code. Let me double check timing to ensure it clears the reset signal.
| sw_device_reset_ctrl_swmod <= 1'b0; | ||
| sw_recovery_ctrl_activate_rec_img_swmod <= 1'b0; | ||
| sw_indirect_fifo_ctrl_reset_swmod <= 1'b0; | ||
| end | ||
| else begin | ||
| sw_device_reset_ctrl_swmod <= hwif_socmgmt_i.REC_INTF_REG_W1C_ACCESS.DEVICE_RESET_CTRL.swmod; | ||
| sw_recovery_ctrl_activate_rec_img_swmod <= hwif_socmgmt_i.REC_INTF_REG_W1C_ACCESS.RECOVERY_CTRL_ACTIVATE_REC_IMG.swmod; | ||
| sw_indirect_fifo_ctrl_reset_swmod <= hwif_socmgmt_i.REC_INTF_REG_W1C_ACCESS.INDIRECT_FIFO_CTRL_RESET.swmod; | ||
| end | ||
| end | ||
|
|
||
| assign cmd_len_o = {len_msb, len_lsb}; | ||
| // Gate PEC error detection at source - when disabled, never report error | ||
| assign cmd_error_o = pec_err_det_en_i && !pec_match; | ||
| always_comb begin : clear_bypassed_regs | ||
| hwif_socmgmt_o.REC_INTF_REG_W1C_ACCESS.DEVICE_RESET_CTRL.we = sw_device_reset_ctrl_swmod; | ||
| hwif_socmgmt_o.REC_INTF_REG_W1C_ACCESS.DEVICE_RESET_CTRL.next = '0; | ||
| hwif_socmgmt_o.REC_INTF_REG_W1C_ACCESS.RECOVERY_CTRL_ACTIVATE_REC_IMG.we = sw_recovery_ctrl_activate_rec_img_swmod; | ||
| hwif_socmgmt_o.REC_INTF_REG_W1C_ACCESS.RECOVERY_CTRL_ACTIVATE_REC_IMG.next= '0; | ||
| hwif_socmgmt_o.REC_INTF_REG_W1C_ACCESS.INDIRECT_FIFO_CTRL_RESET.we = sw_indirect_fifo_ctrl_reset_swmod; | ||
| hwif_socmgmt_o.REC_INTF_REG_W1C_ACCESS.INDIRECT_FIFO_CTRL_RESET.next = '0; | ||
| end |
There was a problem hiding this comment.
So this takes the swmod fields of the hwif_socmgmt_i struct, delays them by one cycle and unconditionally feeds them back to the respective we field. I don't understand why this is done (but haven't looked deeper into it, maybe there is a good reason).
There was a problem hiding this comment.
This is a timing thing. If you don't delay the swmod and we will fight each other.
| // Read-only registers - no write enable | ||
| hwif_rec_o.PROT_CAP_2.REC_PROT_VERSION.we = '0; | ||
| hwif_rec_o.PROT_CAP_2.AGENT_CAPS.we = '0; | ||
| hwif_rec_o.PROT_CAP_3.NUM_OF_CMS_REGIONS.we = '0; | ||
| hwif_rec_o.PROT_CAP_3.MAX_RESP_TIME.we = '0; | ||
| hwif_rec_o.PROT_CAP_3.HEARTBEAT_PERIOD.we = '0; | ||
| hwif_rec_o.DEVICE_ID_0.DESC_TYPE.we = '0; | ||
| hwif_rec_o.DEVICE_ID_0.VENDOR_SPECIFIC_STR_LENGTH.we = '0; | ||
| hwif_rec_o.DEVICE_ID_0.DATA.we = '0; | ||
| hwif_rec_o.DEVICE_ID_1.DATA.we = '0; | ||
| hwif_rec_o.DEVICE_ID_2.DATA.we = '0; | ||
| hwif_rec_o.DEVICE_ID_3.DATA.we = '0; | ||
| hwif_rec_o.DEVICE_ID_4.DATA.we = '0; | ||
| hwif_rec_o.DEVICE_ID_5.DATA.we = '0; | ||
| hwif_rec_o.DEVICE_STATUS_1.HEARTBEAT.we = '0; | ||
| hwif_rec_o.DEVICE_STATUS_1.VENDOR_STATUS_LENGTH.we = '0; | ||
| hwif_rec_o.DEVICE_STATUS_1.VENDOR_STATUS.we = '0; | ||
| hwif_rec_o.RECOVERY_STATUS.DEV_REC_STATUS.we = '0; | ||
| hwif_rec_o.RECOVERY_STATUS.REC_IMG_INDEX.we = '0; | ||
| hwif_rec_o.RECOVERY_STATUS.VENDOR_SPECIFIC_STATUS.we = '0; | ||
| hwif_rec_o.HW_STATUS.TEMP_CRITICAL.we = '0; | ||
| hwif_rec_o.HW_STATUS.SOFT_ERR.we = '0; | ||
| hwif_rec_o.HW_STATUS.FATAL_ERR.we = '0; | ||
| hwif_rec_o.HW_STATUS.RESERVED_7_3.we = '0; | ||
| hwif_rec_o.HW_STATUS.VENDOR_HW_STATUS.we = '0; | ||
| hwif_rec_o.HW_STATUS.CTEMP.we = '0; | ||
| hwif_rec_o.HW_STATUS.VENDOR_HW_STATUS_LEN.we = '0; | ||
| hwif_rec_o.INDIRECT_FIFO_STATUS_0.REGION_TYPE.we = '0; | ||
| hwif_rec_o.INDIRECT_FIFO_RESERVED.DATA.we = '0; |
There was a problem hiding this comment.
Is there no way to declare these registers as hw-readonly in RDL and avoid all these manual 0-assigns?
There was a problem hiding this comment.
We should in the future but I didn't takt the time to go through each register and determine if it was used or now.
| hwif_socmgmt_o.REC_INTF_CFG.REC_PAYLOAD_DONE.we = fifo_xfer_done; | ||
| hwif_socmgmt_o.REC_INTF_CFG.REC_PAYLOAD_DONE.next = 1'b0; |
There was a problem hiding this comment.
Is it correct to write 0 as value into a register that should indicate "done", when a done-condition is high? Maybe I am missing something here.
There was a problem hiding this comment.
Third times the charm... Clearing is the correct action; SW writes this register to indicate the last bit of data has been transferred and HW clears the register. This will then trigger the payload_available_q to be set.
If you look at this section there seems to be a lot of redundancy here between the payload_done and the image_activated_o usage. This part of the code has been heavily tested by our FW team so I hesitate to change this logic since we know it works for their use case.
1. Changed rx_data_queue_select_o to be driven directly from FSM 2. All _err_raw/err_en now direct checks in FSM 3. Changes many checks to 'inside (..)' 4. added begin ends everywhere 5. Fixed bug with REC_PAYLOAD_DON not set when fifo_xfer_done asserted
mkj121
left a comment
There was a problem hiding this comment.
I think that the most recent changes have significantly improved the legibility.
Nice work
glaserf
left a comment
There was a problem hiding this comment.
Final round of minor comments, mostly in regards to the recovery handler.
| logic tti_tx_desc_queue_ack; | ||
| logic [ TtiTxDescDataWidth-1:0] tti_tx_desc_queue_data; | ||
| logic [ TtiTxDescThldWidth-1:0] tti_tx_desc_queue_ready_thld_i; | ||
| logic [ TtiTxDescThldWidth-1:0] tti_tx_desc_queue_ready_thld_o; |
There was a problem hiding this comment.
Could we maybe get rid of the local _i and _o signals as part of this big restructuring effort? The _i ones are fully superfluous and can just be replaced by the respective actual input signal. For _o and cases where they are more than a feed-through from some lower hierarchy, we should either create a local signal without the _o suffix or use the actual output everywhere.
There was a problem hiding this comment.
I agree with the idea but for right now I'm going to skip I need to start focusing on some other work in I3C that is more critical.
| //---------------------------------------------------------------------------- | ||
| // Virtual Device Selection Delay | ||
| // Shift register delays PEC init after virtual device selection | ||
| //---------------------------------------------------------------------------- | ||
| always @(posedge clk_i or negedge rst_ni) | ||
| if (~rst_ni) begin | ||
| virtual_device_cec_shreg <= 2'b10; | ||
| end else if (virtual_device_sel_i) begin | ||
| virtual_device_cec_shreg <= {1'b0, virtual_device_cec_shreg[1]}; | ||
| end else begin | ||
| virtual_device_cec_shreg <= 2'b10; | ||
| end |
There was a problem hiding this comment.
Is this a really convoluted way to get the PEC to start its calculation when receiving the bus address, to take it into account? I really have a hard time understanding what exactly is going on here.
In your nice comment at the beginning of the receiver, you say that the bus address is not taken into account for the PEC (only starting at the cmd), but I think it is? There is a data mux at the input of the PEC which selects the address during the init phase. But then again, if we have the init signal during address-valid, do we need this shift register at all?
There was a problem hiding this comment.
Yeah this is legacy... Let me see if I can clean this up by using the FSM....
| assign ctl_bus_any_start = ctl_bus_start_i | ctl_bus_rstart_i; | ||
|
|
||
| always @(posedge clk_i or negedge rst_ni) | ||
| always @(posedge clk_i or negedge rst_ni) begin |
There was a problem hiding this comment.
Should be always_ff, and I think there is one more occurrence of this.
There was a problem hiding this comment.
Oh good catch let me fix that.
| .virtual_target_start_i(virtual_target_start), | ||
| .other_target_start_i(other_target_start), | ||
|
|
||
| .pec_err_o(pec_err_o), | ||
| .length_err_o(length_err_o), | ||
| .readonly_err_o(readonly_err_o), | ||
| .unsupported_err_o(unsupported_err_o), | ||
| .rx_fifo_overflow_err_o(rx_fifo_overflow_err_o), | ||
| .indirect_fifo_overflow_err_o(indirect_fifo_overflow_err_o), | ||
| .exec_pending_o(recovery_exec_pending), | ||
| .recovery_mode_enter_o(recovery_mode_enter_o) | ||
| ); |
There was a problem hiding this comment.
Most of these (and some other) ports are pure feed-throughs. I think changing the port map style to .port, would make it clearer to spot that, given the signal complexity of this module.
| always_comb begin | ||
| // Only write to FIFO if not full - reject writes when full | ||
| indirect_rx_wvalid_o = (state_q == ExecFifoWrite) && tti_rx_rack_i && indirect_rx_wready_i; | ||
| indirect_rx_wdata_o = tti_rx_rdata_i; |
There was a problem hiding this comment.
This feed-through obfuscates that in the recovery handler there is some unnecessary muxing going on for the indirect FIFO wdata in bypass mode.
There is a direct path through the indirect_rx_wdata_muxed signal in Section 11, and one through the R3MUX and the exec_tti_rx_data_data signal, which ends up as tti_rx_rdata_i here. Both in the end mux tti_tx_data_queue_rdata to the wdata of the indirect FIFO (the former FIFO in Section 11 has the same signal on both of its inputs in bypass mode).
There was a problem hiding this comment.
Sorry, had a wrong signal there in the first version, now corrected.
| input logic desc_valid_i, | ||
| output logic desc_ready_o, | ||
| input logic [TtiRxDescDataWidth-1:0] desc_data_i, |
There was a problem hiding this comment.
These are unused (ready tied to 1, inputs not read).
There was a problem hiding this comment.
Thanks, these were used but cleaned up in this file and the handler file.