-
Notifications
You must be signed in to change notification settings - Fork 92
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
fix(PeriphDrivers): Fix MAA Operator Setter for TPU Drivers #1104
Conversation
@night1rider if you can re-test with this fix and confirm functionality we would very much appreciate it. |
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.
Shifting not require for _keySelect function.
Hello, The fix I have been using, which is not the proper way to fix this issue, is working and the tests for wolfssl pass. From my quick observations it does go down into the hardware and preform some sort of calculations, but the end result is wrong. I would wager that it is still not setting the correct operations to the register. |
Thanks @night1rider. What size are you initializing the MAA with? The reason I ask is that I see some of the TPU control fields are conditional based on the MAA word size (see MAA_MAWS register). Ex: The field values that you have found to work follow the same scheme for the MAWS > 1024 that some of these other fields do. I wonder if this is also the case for the clc field but our UG is not correct. |
For the tests that fail for wolfssl, we are passing the values of 1024 and 2048 to Here is a code snip of how we call it. We calculate len generically to determine what to pass for the needed operation. Also when we init we set a mutex so that the HW cannot be accessed until released (Just in case this is a concern).
|
4eedbba
to
23c3379
Compare
Thanks @night1rider. just updated the drivers under the assumption that the shift is necessary. Functionally this should be equivalent to the updates to the enum values you made except when the MAA is initialized with a size less than 1024. Just pinged design to validate this check. Checking the MAA example as well - you mentioned that wasn't working and it uses a size of 16. Let me know if the WolfSSL checks pass with the latest diff. They are very useful to validate our functionality. --- a/Libraries/PeriphDrivers/Source/TPU/tpu_reva.c
+++ b/Libraries/PeriphDrivers/Source/TPU/tpu_reva.c
@@ -262,6 +262,7 @@ int MXC_TPU_RevA_Cipher_Config(mxc_tpu_reva_regs_t *tpu, mxc_tpu_reva_modesel_t
int MXC_TPU_RevA_Cipher_KeySelect(mxc_tpu_reva_regs_t *tpu, mxc_tpu_reva_keysrc_t key_src)
{
MXC_SETFIELD(tpu->cipher_ctrl, MXC_F_TPU_REVA_CIPHER_CTRL_SRC, key_src);
+ // Note: "key_src" enum is set with "S" definitions instead of "V" definitions, so shifting is not necessary
return E_SUCCESS;
}
@@ -716,7 +717,13 @@ int MXC_TPU_RevA_MAA_Compute(mxc_tpu_reva_regs_t *tpu, mxc_tpu_maa_clcsel_t clc,
memcpy((void *)MAA_M, (uint32_t *)mod, len);
// Start MAA
- MXC_SETFIELD(tpu->maa_ctrl, MXC_F_TPU_REVA_MAA_CTRL_CLC, clc);
+ uint8_t clc_val = (uint8_t)clc;
+ if (((tpu->maa_maws & MXC_F_TPU_MAA_MAWS_MSGSZ) >> MXC_F_TPU_MAA_MAWS_MSGSZ_POS) >= 1024) {
+ // The actual value of the field must be left shifted by 1 if MAWS >= 1024
+ clc_val <<= 1;
+ }
+ MXC_SETFIELD(tpu->maa_ctrl, MXC_F_TPU_REVA_MAA_CTRL_CLC,
+ clc_val << MXC_F_TPU_REVA_MAA_CTRL_CLC_POS);
tpu->maa_ctrl |= MXC_F_TPU_REVA_MAA_CTRL_STC; |
@Jake-Carter Items to Reproduce:
As a base line I am only testing MULMOD with this for now. Current Upstream Results:So the results of using the current upstream:
You can see that when the MAA is given My temp fix Results:With my temp fix as described in the initial issue:
We can see here that with my temp fix when the MAA is given Initial Proposed Solution Results:Now testing the first proposed fixed (fixing the usage of
This produces these results:
We can see when the MAA is given Second Proposed Solution Results:Now testing the lastest suggestion -
This will produce this result:
Here we can see that when the MAA is given Solution to Bug:Now noticing this I found the actual issue: but in the second proposed solution you used this for MXC_SETFIELD: Turns out you just need to use: I then tested this: TLRD:Use: instead of: without the 1024 check (no extra bitshift) and this will pass the wolfSSL tests and the observation test I made as detailed. |
This reverts commit 23c3379.
(applies palm to face) yep, you're absolutely right... my mistake, sorry about that typo on that first pass... Confirmed on the original design spec the values in the UG are correct as well. Appreciate the testing and patience |
@ozersa ready for re-review |
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.
Looks good, thanks @Jake-Carter
Description
Fixes #1089
Checklist Before Requesting Review