-
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
[kmac] Change fifo_empty interrupt type to status #21657
Conversation
@jadephilipoom I am wondering if the current implementation of this PR makes sense from a software perspective. To do a KMAC operation, software would:
What is your view, does this make sense? I am not sure if disabling/enabling interrupts at this granularity is practical for software. If yes, I could add information on this to the programmer's guide. If no, I could try to implement this in hardware. |
I can confirm the existing KMAC software doesn't use this interrupt (details below). My opinion is that using the interrupt to detect when to write to the FIFO is a little bit of an annoying interface for software, which is why it's not currently being used, so I'm in favor of a higher-level or non-interrupt-based software interface. The DIF calculates for itself how much it can write: opentitan/sw/device/lib/dif/dif_kmac.c Lines 645 to 650 in 89f6bec
The cryptolib driver simply writes the message straight out, but there's an open issue that says it should eventually follow the DIF: The opentitan/sw/device/silicon_creator/lib/drivers/kmac.c Lines 262 to 270 in 89f6bec
CC @ballifatih |
Thanks for your feedback @jadephilipoom ! What you wrote makes a lot of sense to me. And I think this means even how the interrupt works right now with this PR is not going to be very useful. I think I am going to try to change the hardware to only assert the interrupt in Phase 3 above and only if the FIFO has been filled up to a certain threshold once. In practice, KMAC will most likely empty the FIFO faster than software can fill it up, unless the core is currently processing or waiting for entropy. If software then observes that FIFO depth, it knows 1) that it will take some time until KMAC empties the FIFO again, 2) that KMAC will signal this with an interrupt. But we don't want so send pointless interrupts to software. In my view this is the only way this interrupt could ever become useful for software. |
I've now updated the interrupt implementation to only make the interrupt firing if the message FIFO has run full previously. This can happen e.g. if the SHA3 engine is busy and cannot accept more data currently, or if the KMAC block is waiting for entropy from EDN (can take hundreds of clock cycles). In all other cases, hardware will consume the data faster than software can provide it and there is no point in interrupting the software to tell it to work faster :-) Also, the interrupt is not firing if 1) a hardware application interface is using the block, 2) if the SHA3 engine is not in the Absorb state (i.e., not accepting input data anyway), or 3) if software triggered the Process command already (no more input data is accepted). |
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 change, @vogelpi 👍 LGTM with two suggestions
Thanks for your review @andreaskurth and the feedback. I've addressed your comments and pushed again. |
I've now rebased this PR on top of @msfschaffner 's flash_ctrl status type interrupt PR to include some relevant changes and avoid merge skew issues. |
The type of this interrupt is changed from event to status. To make the interrupt more usable for software, it only fires if the message FIFO has run full previously (e.g., if the SHA3 core is currently busy or if the KMAC block is waiting for entropy from EDN). Under normal circumstances, the hardware empties the FIFO much faster than software filling it, so there is no point in interrupting software to tell it to run faster. Also, the interrupt can now only fire if software can actually write the message FIFO. This resolves lowRISC#21049. Signed-off-by: Pirmin Vogel <[email protected]>
Thanks @vogelpi! Merging |
This resolves #21049.
Note that this PR currently contains a cherry-picked commit from @msfschaffner . In addition, some automated TLT sequence needs to be adjusted as well for this PR to pass CI. I am mainly creating now for the sake of visilbility.Together with @andreaskurth , I've come to the conclusion that it is better to not signal the empty status interrupt if software is not using the module. For example, software shouldn't get interrupted if an application interface is using KMAC (the app interface will handle the FIFO condition autonomously) or if the KMAC block is completely idle. But only if the FIFO runs empty while software is using the block and had to stop writing data at some point. I've now changed the design accordingly. This should work independently of potential TLT changes and CIP library modifications.
Since this change is software visible, one could argue to create a new version of the IP for this which would also require to go back to D1/V1. However, it seems that the current software only uses the untouched
Done
andErr
interrupts but not theFIFO_Empty
interrupt changed with this PR. For example:KMAC_INTR_ENABLE_FIFO_EMPTY
, i.e. the bit offset for enabling the interrupt in software yields nothing.KMAC_INTR_STATE_FIFO_EMPTY
gives one hit insidesw/device/silicon_creator/lib/drivers/kmac_unittest.cc
only.KMAC_INTR_TEST_FIFO_EMPTY
just gives the SV parameter definition for the reset value of this bit inkmac_reg_pkg.sv
(auto-generated).KMAC_INTR_COMMON_FIFO_EMPTY
gives one functionkmac_get_irq_bit_index()
insidesw/device/lib/dif/autogen/dif_kmac_autogen.c
. This function is called from withindif_kmac_irq_is_pending()
dif_kmac_irq_acknowledge()
dif_kmac_irq_force()
dif_kmac_irq_set_enabled()
dif_kmac_irq_set_enabled()
None of these functions are called with
kDifKmacIrqFifoEmpty
as argument.Most likely, FIFO empty interrupt is not used because it's not very usable as long as it's of type "event". I thus suggest avoid the hassle and not introduce a new version and remain at D2S/V2S if possible.