-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[csrng/rtl] Propagate csrng errors to edn through cmd sts signal #21981
Conversation
b47e116
to
65fb31d
Compare
65fb31d
to
8cefcf7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this work, @h-filali. I think this is almost ready, just a few questions and suggestions from my side
// Return a status error when the state is not zeroized properly during a UNI command. | ||
assign ctr_drbg_cmd_sts_err = sfifo_keyvrc_pop && (ctr_drbg_cmd_ccmd_o == UNI) && | ||
((KeyLen == '0) && (BlkLen == '0) && (CtrLen == '0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand this condition. Which part checks the 'not zeroized properly'? And why are we comparing the length synthesis parameters to zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to change as little as possible but I agree with your point. I'll adapt the check such that it actually checks if we are zeroizing properly.
// Return a status error when the genbits FIFO is popped while ctr_drbg_gen_ccmd_o is not | ||
// equal to GEN. | ||
assign ctr_drbg_gen_sts_err = sfifo_genbits_pop && ( | ||
(ctr_drbg_gen_ccmd_o == INV) || | ||
(ctr_drbg_gen_ccmd_o == INS) || | ||
(ctr_drbg_gen_ccmd_o == RES) || | ||
(ctr_drbg_gen_ccmd_o == UPD) || | ||
(ctr_drbg_gen_ccmd_o == UNI)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have ctr_drbg_gen_ccmd_o != GEN
, in line with the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I'll change it.
hw/ip/csrng/rtl/csrng_pkg.sv
Outdated
@@ -22,17 +22,24 @@ package csrng_pkg; | |||
logic genbits_ready; | |||
} csrng_req_t; | |||
|
|||
typedef enum logic [1:0] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest introducing a localparam
that defines the width of this enum (reason: see next comment)
hw/ip/csrng/rtl/csrng_state_db.sv
Outdated
output logic [StateId-1:0] state_db_sts_id_o | ||
); | ||
|
||
localparam int InternalStateWidth = 2+KeyLen+BlkLen+CtrLen; | ||
localparam int RegInternalStateWidth = 30+InternalStateWidth; | ||
localparam int RegW = 32; | ||
localparam int StateWidth = 1+1+KeyLen+BlkLen+CtrLen+StateId+1; | ||
localparam int StateWidth = 1+1+KeyLen+BlkLen+CtrLen+StateId+2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest using the (newly introduced) localparam
that defines the width of csrng_cmd_sts_e
as last summand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent point, I totally missed that.
hw/ip/edn/data/edn.hjson
Outdated
0b00: Request completed successfully. | ||
0b01: Request completed with an invalid application command error. | ||
This error indicates that the issued application command doesn't represent a valid operation. | ||
If this error appears, the main state machine will hang and the entropy complex has to be restarted. | ||
0b10: Request completed with an invalid state parameter error. | ||
This error indicates that the state wasn't zeroized properly after an uninstantiate command. | ||
In this case the entropy complex should be restarted to properly zeroize the state. | ||
0b11: Request completed with an invalid counter drbg generation command error. | ||
This error indicates that CSRNG entropy was generated for a command that is not a generate command. | ||
In this case the entropy should not be considered as valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of duplicating this information from CSRNG, would it makes sense to refer to the CSRNG doc (like for HW_CMD_STS.CMD_TYPE
below)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it would.
hw/ip/edn/data/edn.hjson
Outdated
0b1: Request completed with an error. | ||
This field contains the application command type of the hardware controlled command issued last. | ||
The application command selects one of five operations to perform. | ||
A description of the application command types can be found [here](https://opentitan.org/book/hw/ip/csrng/doc/theory_of_operation.html#command-description). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to use relative paths (like ../../csrng/doc/theory_of_operation.md#command-description
) instead, because that will work with local files, and it will work if we change the web interface to the documentation
hw/ip/edn/data/edn.hjson
Outdated
0b00: Request completed successfully. | ||
0b01: Request completed with an invalid application command error. | ||
This error indicates that the issued application command doesn't represent a valid operation. | ||
If this error appears, the main state machine will hang and the entropy complex has to be restarted. | ||
0b10: Request completed with an invalid state parameter error. | ||
This error indicates that the state wasn't zeroized properly after an uninstantiate command. | ||
In this case the entropy complex should be restarted to properly zeroize the state. | ||
0b11: Request completed with an "invalid counter drbg generation command" error. | ||
This error indicates that CSRNG entropy was generated for a command that is not a generate command. | ||
In this case the entropy should not be considered as valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto referencing the CSRNG doc?
bit cmd_zero_delays; | ||
bit under_reset; | ||
bit rsp_sts_err; | ||
uint min_cmd_ack_dly, max_cmd_ack_dly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to combine this commit with the first one, so that tests continue to pass despite the RTL changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll squash.
@@ -157,30 +157,51 @@ Command request register | |||
## SW_CMD_STS | |||
Application interface command status register | |||
- Offset: `0x1c` | |||
- Reset default: `0x1` | |||
- Reset mask: `0x3` | |||
- Reset default: `0x0` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also combine this commit with the first one because otherwise documentation will be outdated
@@ -450,9 +450,9 @@ static status_t csrng_send_app_cmd(uint32_t base_address, | |||
reg = abs_mmio_read32(kBaseCsrng + CSRNG_INTR_STATE_REG_OFFSET); | |||
} while (!bitfield_bit32_read(reg, CSRNG_INTR_STATE_CS_CMD_REQ_DONE_BIT)); | |||
|
|||
// Check the "status" bit, which will be 1 only if there was an error. | |||
// Check the "status" bit, which will be 0 unless there was an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also combine this commit with the first one, because otherwise SW tests will fail
hw/ip/csrng/data/csrng.hjson
Outdated
0b1: Request completed with an error | ||
To check whether a command was succesful, wait for !!INTR_STATE.CS_CMD_REQ_DONE or | ||
!!SW_CMD_STS.CMD_ACK to be high and then check the value of this field. | ||
0b00: Request completed successfully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw in #22114 that you're changing the representation of the values from binary to hex, which I think makes a lot of sense and could already be done in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done!
d7b809d
to
0c9c6d6
Compare
@andreaskurth I addressed all your points and rebased to the current master. Thanks a lot for reviewing! |
f42f36e
to
6a423db
Compare
This commit changes the sw_cmd_sts and hw_cmd_sts signals to multiple bits. 0 represents a successful acknowledgement, whereas any value other than 0 represents an error status. The sts signal is now also able to anounce to the EDN that the CSRNG main SM is hanging due to an invalid acmd. This commit also aligns the EDN rtl with the new sts response. Furthermore a new csrng interface pkg is created to avoid circular dependencies. This commit also aligns the EDN and CSRNG DV, documentation and SW with the new STS signal. Signed-off-by: Hakim Filali <[email protected]>
6a423db
to
3d165f8
Compare
This commit removes the csrng_fsm_idle_wait() in csrng_send_app_cmd(). This was needed because the cmd_rdy signal was high whenever the CSRNG was turned off. Due to a fix in lowRISC#21981 this is no longer needed. Signed-off-by: Hakim Filali <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @h-filali ! It looks mostly good to me but I have some questions. Regarding the zeroizing check, I am more in favor of removing that entirely but let's discuss once you're back from vacation and exams.
bit = EDN_SW_CMD_STS_CMD_STS_BIT; | ||
field_val = bitfield_field32_read(reg, EDN_SW_CMD_STS_CMD_STS_FIELD); | ||
*set = field_val ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, here we fold all non-zero values to True, meaning the reported status becomes binary again. I believe this is okay for now as we should move forward but it probably makes sense to file an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we can do that in a separate issue. Let's talk about it and create an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed and agreed to create a separate software issue for this. This isn't critical for the TO.
status->kind = kDifCsrngCmdStatusError; | ||
uint32_t reg = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be quite a change. Do we need to re-align the corresponding function description in dif_csrng.h
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function description should be fine but let's check in person.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked and agreed that no further changes are needed here.
CMD_STS_INVALID_ACMD = 2'h1, | ||
CMD_STS_INVALID_STATE_PARAM = 2'h2, | ||
CMD_STS_INVALID_GEN_CMD = 2'h3, | ||
CMD_STS_UNDRIVEN = 'z |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean the undriven value here not the entire enum type.
I spent quite some time getting the CSRNG interface to work. Xcelium doesn't like it if we assign 'z to a struct that has a substruct. There's different ways you can do this and this is the only way I found that works both in the RTL and for the block level simulation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed and agreed in person that this is the way to handle this. Already previously, something very similar was done but only now we need to define an enum value for this case. This is okay.
assign ctr_drbg_cmd_sts_o = sfifo_keyvrc_pop && (ctr_drbg_cmd_ccmd_o == UNI) && | ||
((KeyLen == '0) && (BlkLen == '0) && (CtrLen == '0)); | ||
// Return a status error when the state is not zeroized properly during a UNI command. | ||
assign ctr_drbg_cmd_sts_err = sfifo_keyvrc_pop && (ctr_drbg_cmd_ccmd_o == UNI) && | ||
(sfifo_keyvrc_wdata >> (KeyVRCFifoWidth-UniZeroizeWidth)) == '0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% sure but I think this is another error condition in the design which doesn't really make sense as it's never going to happen (similarly to receiving an INS command on an instance which is not instantiated in the RTL ). Here we have in the same file:
assign sfifo_keyvrc_wdata = (rcstage_ccmd == UNI) ?
{{(KeyLen+BlkLen+CtrLen+1+SeedLen){1'b0}},rcstage_glast,upd_cmd_inst_id_i,upd_cmd_ccmd_i} :
meaning when the command seen is UNI, we set the relevant wdata
bits to 0 anyway. This might be a coverage hole and synthesis might optimize this away. Things like that should be tested with SVAs. Did I miss something @h-filali ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now I understood your comment in another discussion with @andreaskurth about "doing minimal changes". I think agree with you but I think in the case of CSRNG we should maybe sit together and discuss what we really want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's discuss this in person.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed in person to remove this in a separate PR to unblock this one.
This commit removes the csrng_fsm_idle_wait() in csrng_send_app_cmd(). This was needed because the cmd_rdy signal was high whenever the CSRNG was turned off. Due to a fix in lowRISC#21981 this is no longer needed. Signed-off-by: Hakim Filali <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after discussing in person.
This commit removes the csrng_fsm_idle_wait() in csrng_send_app_cmd(). This was needed because the cmd_rdy signal was high whenever the CSRNG was turned off. Due to a fix in lowRISC#21981 this is no longer needed. Signed-off-by: Hakim Filali <[email protected]>
This commit removes the csrng_fsm_idle_wait() in csrng_send_app_cmd(). This was needed because the cmd_rdy signal was high whenever the CSRNG was turned off. Due to a fix in lowRISC#21981 this is no longer needed. Signed-off-by: Hakim Filali <[email protected]>
This commit removes the csrng_fsm_idle_wait() in csrng_send_app_cmd(). This was needed because the cmd_rdy signal was high whenever the CSRNG was turned off. Due to a fix in #21981 this is no longer needed. Signed-off-by: Hakim Filali <[email protected]>
lowRISC#21981 reworked the status signaling of CSRNG and changed the definition of the ack_sts signal from 1-bit to a multi-bit enum which broke the csrng_intr vseq trying to force the ack and ack_sts signals. This commit gets the sequence working again until it's reworked to properly test the error signaling without forcing signals. This is related to lowRISC#22869. Signed-off-by: Pirmin Vogel <[email protected]>
#21981 reworked the status signaling of CSRNG and changed the definition of the ack_sts signal from 1-bit to a multi-bit enum which broke the csrng_intr vseq trying to force the ack and ack_sts signals. This commit gets the sequence working again until it's reworked to properly test the error signaling without forcing signals. This is related to #22869. Signed-off-by: Pirmin Vogel <[email protected]>
The underlying hardware issue got fixed with lowRISC#21981 and the software workaround got disabled with lowRISC#22263. This commit now removes the unused software function. This is related to lowRISC#19568. Signed-off-by: Pirmin Vogel <[email protected]>
The underlying hardware issue got fixed with #21981 and the software workaround got disabled with #22263. This commit now removes the unused software function. This is related to #19568. Signed-off-by: Pirmin Vogel <[email protected]>
The underlying hardware issue got fixed with lowRISC#21981 and the software workaround got disabled with lowRISC#22263. This commit now removes the unused software function. This is related to lowRISC#19568. Signed-off-by: Pirmin Vogel <[email protected]>
This PR adds functionality to signal status errors along a command acknowledgement.
For further details have a look at the individual commit messages.
Resolves #16516