Skip to content
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

[aes] Rework register interface #1053

Merged
merged 7 commits into from Dec 2, 2019
Merged

Conversation

vogelpi
Copy link
Contributor

@vogelpi vogelpi commented Nov 22, 2019

This PR contains a series of commits to implement the following two main changes:

  • Input data and initial key registers can now be cleared using a bit in the trigger register (like the output data register). At the moment, these registers are cleared to 0. At a later point, an LFSR will be inserted to clear those registers with pseudo-random data. Previously those registers had to be cleared by software.
  • Writes to the key and control registers are ignored if the AES unit is not idle. This similar to the behavior of the HMAC module changed in PR [hmac] Block the configuration change while processing #1014 .

Hand in hand with these changes goes a restructuring/cleanup of the AES core (not the cipher, but the aes_core.sv file connecting the data paths with the registers).

The changes have been successfully tested using my Verilator test framework.

hw/ip/aes/data/aes.hjson Outdated Show resolved Hide resolved
hw/ip/aes/data/aes.hjson Outdated Show resolved Hide resolved
@@ -374,10 +404,11 @@ module aes_control #(

// Detect new key, new input, output read
// Edge detectors are cleared by the FSM
assign key_init_new_d = dec_key_gen ? '0 : key_init_new_q | key_init_qe_i;
assign key_init_clear = (key_init_sel_o == KEY_INIT_CLEAR) & (&key_init_we_o);
assign key_init_new_d = dec_key_gen | key_init_clear ? '0 : key_init_new_q | key_init_qe_i;
Copy link

Choose a reason for hiding this comment

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

I personally prefer to parenthesize any compound conditions or assignments, even if the order of operations is correct, just to avoid silly editing/copy-paste errors that could occur later, but I believe this way is allowed by the style guide.

I am suggesting: ... = (dec_key_gen | key_init_clear) ? '0 : (key_init_new_q | key_init_qe_i);

But I am pretty liberal with parentheses, maybe too much so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that is a valid point. I added the parentheses.

Copy link

@cdgori cdgori left a comment

Choose a reason for hiding this comment

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

LGTM with a handful of nits/clarifications. I appreciate how much cleaner it looks with the for loops in some of the sections.

@vogelpi
Copy link
Contributor Author

vogelpi commented Nov 25, 2019

Thanks @cdgori for your feedback. I implemented your suggestions.

data_out_we_o = 1'b1;
data_out_clear_we_o = 1'b1;
end
end else if (key_clear_i || data_in_clear_i || data_out_clear_i) begin
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the signal pulse or level?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind I found the code below (they are level)

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this would work better as a wo where the qe was used to do the clearing, else
SW will need to write first to 1 then to 0, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this would work better as a wo where the qe was used to do the clearing, else
SW will need to write first to 1 then to 0, no?

Right. But the signals shouldn't be pulse as those signal used in other state too. But having it write-only and let hardware clear them if they are processed is good as I mentioned below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make it wo for software, this makes sense.

But to clarify:

  • Software only needs to write 1 (already now). The hardware will then clear it back to 0.
  • The hardware should not use the qe signal to trigger the clearing as pointed out by @eunchan. Writes to the TRIGGER register are not ignored when the unit is not idle. If the unit is busy while e.g. software triggers a clear of the input register, this clear would not be triggered after finishing operation when using the qe signal.

Comment on lines +56 to 58
output logic data_in_clear_o,
output logic data_in_clear_we_o,
output logic data_out_clear_o,
Copy link
Contributor

Choose a reason for hiding this comment

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

This could trigger the CSR test failure as TRIGGER register has RW for software access. @weicaiyang @sriyerg to give us clear answer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @eunchan for your reviewn and the comment. Do you suggest to make TRIGGER write-only for software?

Copy link
Contributor

Choose a reason for hiding this comment

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

If that works. Yes :)

Copy link
Contributor

Choose a reason for hiding this comment

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

You can merge as it is. It can be done in following PR after getting the answer from DV engineers,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I'll merge it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I would need the green light from someone with write permission. Would you mind @eunchan?

2. Clear the configured initial key by overwriting the Initial Key registers {{< regref "KEY0" >}} - {{< regref "KEY7" >}}.
3. Clear the previous input data by overwriting the Input Data registers {{< regref "DATA_IN0" >}} - {{< regref "DATA_IN3" >}}.
4. Clear the internal key registers and the Output Data register by setting the KEY_CLEAR and DATA_OUT_CLEAR bits in {{< regref "TRIGGER" >}} to `1`.
2. Clear all key registers as well as the Input Data and the Output Data registers by setting the KEY_CLEAR, DATA_IN_CLEAR and DATA_OUT_CLEAR bits in {{< regref "TRIGGER" >}} to `1`.
Copy link
Contributor

Choose a reason for hiding this comment

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

just a .md pro tip: you can number them all 1. and markdown will keep track of the emnumeration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's get pro then ;-) I changed it here and will keep it in mind for future changes to the doc.

data_out_we_o = 1'b1;
data_out_clear_we_o = 1'b1;
end
end else if (key_clear_i || data_in_clear_i || data_out_clear_i) begin
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this would work better as a wo where the qe was used to do the clearing, else
SW will need to write first to 1 then to 0, no?

@vogelpi
Copy link
Contributor Author

vogelpi commented Nov 28, 2019

I added another commit to change the software access permissions of the TRIGGER register from rw to wo as suggested.

The reason I made the trigger register rw for software in the first place was to allow software to check if a requested clear has been performed. Let me know if you think this is necessary or not. I can still remove the commit.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
This commit modifies the input data and initial key registers as well as
the control FSM to allow the hardware to clear those registers based on
the content of the trigger register.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
Software does not need to be able to read back the content of the
trigger register. This commit removes read access for software.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
@vogelpi
Copy link
Contributor Author

vogelpi commented Dec 2, 2019

Thanks @eunchan for approving. I am merging this now.

@vogelpi vogelpi merged commit 76463db into lowRISC:master Dec 2, 2019
@vogelpi vogelpi deleted the aes-rework-registers branch December 3, 2019 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants