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

[SPI_DEVICE|SPI_FLASH] Added a write-protection on en4b/ex4b to avoid… #15326

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

jeoongp
Copy link
Contributor

@jeoongp jeoongp commented Oct 6, 2022

… SW overwrite

  • Issue : as reported in [spi_device] EN4B/EX4B may fail if the next item comes very shortly #14940, when CSB has a short deassertion time, the next sck_csb_asserted_pulse can show up at the next SPI transaction while the previous propagation is still ongoing. Since spi_reg_cfg_addr_4b_en_sync still shows the old value different from spi_cfg_addr_4b_en_o, spi_cfg_addr_4b_en_o is written again by the old value.
  • In this fix, the HW source-of-truth value is protected till its mirrorred SW reg is updated

Signed-off-by: Joshua Park [email protected]

@jeoongp jeoongp requested a review from eunchan as a code owner October 6, 2022 23:50
hw/ip/spi_device/rtl/spid_addr_4b.sv Outdated Show resolved Hide resolved
hw/ip/spi_device/rtl/spid_addr_4b.sv Outdated Show resolved Hide resolved
hw/ip/spi_device/rtl/spid_addr_4b.sv Outdated Show resolved Hide resolved
hw/ip/spi_device/rtl/spid_addr_4b.sv Outdated Show resolved Hide resolved
… SW overwrite

- Issue : as reported in lowRISC#14940, hhen CSB has a short deassertion time, the next sck_csb_asserted_pulse can show up at the next SPI transaction while the previous propagation is still ongoing. Since spi_reg_cfg_addr_4b_en_sync still shows the old value different from spi_cfg_addr_4b_en_o, spi_cfg_addr_4b_en_o is written again by the old value.
- In this fix, the HW source-of-truth value is protected till its mirrorred SW regs is updated

Signed-off-by: Joshua Park <[email protected]>
logic addr_4b_en_unlock_condition;
logic addr_4b_en_sw_update_condition;

assign addr_4b_en_lock_condition = spi_reg_cfg_addr_4b_en_sync ? spi_addr_4b_clr_i :
Copy link
Contributor

Choose a reason for hiding this comment

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

In the doc, the diagram shows lock condition is XOR of spi_reg_cfg_addr_4b_en_sync and spi_cfg_addr_4b_en_o. Here, it uses EN4B/EX4B condition. Is this to retract update (of locked FF) by one SPI clock ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Line 111 : assign addr_4b_en_sw_update_condition = (spi_reg_cfg_addr_4b_en_sync != spi_cfg_addr_4b_en_o);
corresponds to XOR. XOR output is also marked with addr_4b_en_sw_update_condition in the doc.

addr_4b_en_lock_condition needs en4b/ex4b condition to protect spi_cfg_addr_4b_en_o at the right next cycle after en4b/ex4b.

end else if (spi_csb_asserted_pulse_i
&& (spi_cfg_addr_4b_en_o != spi_reg_cfg_addr_4b_en_sync)) begin
end else if (spi_csb_asserted_pulse_i & !addr_4b_en_locked &
addr_4b_en_sw_update_condition) begin
// Update
Copy link

Choose a reason for hiding this comment

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

ah this is kind of neat, it's like the reverse of what we're doing in prim_reg_cdc i think.
So to make sure i understand..

when there is a spi host update, that takes priority. If the value is different from the mirrored software value, the software update becomes "locked" until they are the same.

I'm sure you guys have tested, but can we make sure that if the software side needs to change the value before host transaction ever starts that this works correctly? It looks like it should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tjaychen your understanding is correct. As I've run regression test with mp 100, they are all passing. But, I am not sure if this corner case was covered by the regression. I will clarify with @weicaiyang once @eunchan confirms this HW fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure you guys have tested, but can we make sure that if the software side needs to change the value before host transaction ever starts that this works correctly? It looks like it should.

CSR addr_4b_en could be updated before or after host sends transactions. But it can be only updated when spi interface is idle. I suppose we don't have race condition that both HW and SW update it at the same time.
https://cs.opensource.google/opentitan/opentitan/+/master:hw/ip/spi_device/dv/env/seq_lib/spi_device_pass_base_vseq.sv;l=323?q=addr_4b_en&ss=opentitan%2Fopentitan:hw%2F&start=11

@eunchan
Copy link
Contributor

eunchan commented Oct 7, 2022

I think I am OK with this change as this PR removes the issue (short CSb inactive rolls back the addr_4b value). But I think we may use general CDC logic (primitives) for readers to understand more easily.

+1 for merging this. I will delegate to @tjaychen to final stamp. :)

@tjaychen
Copy link

tjaychen commented Oct 7, 2022

I think I am OK with this change as this PR removes the issue (short CSb inactive rolls back the addr_4b value). But I think we may use general CDC logic (primitives) for readers to understand more easily.

+1 for merging this. I will delegate to @tjaychen to final stamp. :)

ah yeah agreed with @eunchan if we can re-use cdc primitives it would be better. Which ones did you have in mind?

@eunchan
Copy link
Contributor

eunchan commented Oct 7, 2022

I think I am OK with this change as this PR removes the issue (short CSb inactive rolls back the addr_4b value). But I think we may use general CDC logic (primitives) for readers to understand more easily.
+1 for merging this. I will delegate to @tjaychen to final stamp. :)

ah yeah agreed with @eunchan if we can re-use cdc primitives it would be better. Which ones did you have in mind?

prim_sync_reqack_data would be enough I think.

@tjaychen
Copy link

tjaychen commented Oct 7, 2022

ahhh, are you thinking about using the ack kind of as the "lock" condition?

@eunchan
Copy link
Contributor

eunchan commented Oct 7, 2022 via email

@eunchan
Copy link
Contributor

eunchan commented Oct 7, 2022

Honestly, I feel guilty by designing this logic poorly at the beginning. :( I didn't think deeply at that time (incl. CSb timing.. ) Thanks for fixing the logic, Joshua!

@tjaychen
Copy link

tjaychen commented Oct 7, 2022

Kind of. I assume SW updates addr_4b only when it restores the config after power cycles. So it is one-time program only. In that case, asynchronous FIFO is too much in my opinion. By using reqack_data, the src_ack comes from dst_ack, the acceptance indicator @ SPI_CLK. We could create a logic showing pending bit (connecting to src_req and cleared by src_ack) and make it visible to SW. Then SW knows when the value has been accepted (committed).

On Oct 7, 2022, at 3:30 PM, tjaychen @.***> wrote: ahhh, are you thinking about using the ack kind of as the "lock" condition? — Reply to this email directly, view it on GitHub <#15326 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJDG3S5BJAWJDJN2EYCF43WCCP7TANCNFSM6AAAAAAQ7DK6PQ. You are receiving this because you were mentioned.

i would "probably" be careful about assuming that it's one-time only. I know that's the direction Alex gave also, but you never know with these things...something could show up that we completely did not anticipate.

@tjaychen
Copy link

tjaychen commented Oct 7, 2022

Honestly, I feel guilty by designing this logic poorly at the beginning. :( I didn't think deeply at that time (incl. CSb timing.. ) Thanks for fixing the logic, Joshua!

ah no worries. We did not exactly have a lot of time, and there were many complicated things in this block :)

@eunchan
Copy link
Contributor

eunchan commented Oct 7, 2022 via email

@weicaiyang
Copy link
Contributor

@tjaychen @eunchan can we merge this? If we want to make a reusable prim for this, we could do it in another PR. WDYT?

@eunchan
Copy link
Contributor

eunchan commented Oct 12, 2022 via email

@tjaychen
Copy link

sounds good.

@tjaychen
Copy link

@eunchan can you approve if it looks good to you? It looks okay to me, but I think you guys had discussed the implementation and probably know the details better than I do.

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.

4 participants