-
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
[i2c] Clean up target mode transaction boundaries and NACK handling #22460
Conversation
f2d9566
to
9cd8512
Compare
After this PR, the DV regression is looking substantially better: I2C Simulation ResultsMonday April 08 2024 18:31:07 UTCGitHub Revision:
|
Stage | Name | Tests | Max Job Runtime | Simulated Time | Passing | Total | Pass Rate |
---|---|---|---|---|---|---|---|
V1 | target_smoke | i2c_target_smoke | 6.010s | 4.329ms | 5 | 5 | 100.00 % |
V1 | TOTAL | 5 | 5 | 100.00 % | |||
V2 | target_error_intr | i2c_target_unexp_stop | 1.050s | 941.057us | 0 | 5 | 0.00 % |
V2 | target_glitch | i2c_target_glitch | 2.910s | 2.461ms | 5 | 5 | 100.00 % |
V2 | target_maxperf | i2c_target_perf | 0.310s | 105.488us | 0 | 5 | 0.00 % |
V2 | target_fifo_empty | i2c_target_intr_smoke | 1.860s | 14.778ms | 5 | 5 | 100.00 % |
i2c_target_stress_rd | 19.130s | 2.344ms | 5 | 5 | 100.00 % | ||
V2 | target_fifo_reset | i2c_target_fifo_reset_acq | 11.770s | 10.033ms | 5 | 5 | 100.00 % |
i2c_target_fifo_reset_tx | 12.290s | 10.051ms | 5 | 5 | 100.00 % | ||
V2 | target_fifo_full | i2c_target_intr_stress_wr | 10.860s | 15.368ms | 5 | 5 | 100.00 % |
i2c_target_stress_wr | 35.710s | 53.386ms | 5 | 5 | 100.00 % | ||
i2c_target_stress_rd | 19.130s | 2.344ms | 5 | 5 | 100.00 % | ||
V2 | target_timeout | i2c_target_timeout | 2.190s | 1.321ms | 5 | 5 | 100.00 % |
V2 | target_clock_stretch | i2c_target_stretch | 5.565m | 30.367ms | 5 | 5 | 100.00 % |
V2 | bad_address | i2c_target_bad_addr | 1.440s | 1.742ms | 5 | 5 | 100.00 % |
V2 | target_mode_glitch | i2c_target_hrst | 0.920s | 494.797us | 5 | 5 | 100.00 % |
V2 | TOTAL | 55 | 65 | 84.62 % | |||
TOTAL | 60 | 70 | 85.71 % |
The results prior to this PR had many more failures. As for the remaining two... It appears i2c_target_unexp_stop doesn't apply its stimulus correctly, never appending the 0xFF byte to transmit on reads (forcing the target to release SDA and make a Stop possible), leading to FIFO states not matching. The ACK STOP sequence detection does appear to work, however.
For i2c_target_perf, the timing parameters seem to lead to the host agent generating stimulus with bogus timing. SDA and SCL are transitioning simultaneously, causing Start and Stop conditions to trigger after random CDC delay insertion.
hw/ip/i2c/doc/theory_of_operation.md
Outdated
|
||
If the Host-Mode Controller-Transmitter transmits a byte and the 9th bit is a NACK from the Target/Bus, the `nak` interrupt is usually asserted (modulo the effect of [`FDATA.NAKOK`](registers.md#fdata)). | ||
If the 'nak' interrupt is asserted, the Byte-Formatted Programming Mode FSM will halt until the interrupt has been acknowledged using the standard 'Event-Type' interrupt acknowledgement (W1C to INTR_STATE). | ||
If the Host-Mode Controller-Transmitter transmits a byte and the 9th bit is a NACK from the Target/Bus, the `controller_halt` interrupt is usually asserted (modulo the effect of [`FDATA.NAKOK`](registers.md#fdata)). |
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 that FDATA.NAKOK
should be renamed to FDATA.NACKOK
for consistency.
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.
While I agree, I am going to defer all such non-functional cleanups until after the RTL is feature complete. (stuff like this that will spread into a lot of files, I mean)
9cd8512
to
4062019
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.
These changes seem sensible to me. Thanks @a-will
hw/ip/i2c/data/i2c.hjson
Outdated
@@ -645,7 +645,14 @@ | |||
} | |||
{ bits: "10:8" | |||
name: "SIGNAL" | |||
desc: "Host issued a START before transmitting ABYTE, a STOP or a RESTART after the preceeding ABYTE" | |||
desc: ''' | |||
Host issued a START before transmitting ABYTE, a STOP or a RESTART after the preceeding ABYTE |
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.
nit: This first sentence doesn't make much sense.
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.
Fixed up all the descriptions.
hw/ip/i2c/rtl/i2c_target_fsm.sv
Outdated
@@ -170,13 +169,11 @@ module i2c_target_fsm import i2c_pkg::*; | |||
// Latch the nack next byte value when we receive an address to write to but |
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.
This comment is stale
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.
Right you are! Removed and replaced.
4062019
to
d07a88a
Compare
Change recording of Start symbols to always accompany the address data, instead of recording a separate R.Start, then Start+address. This helps maintain certain availability invariants needed for reliable stretching and NACK handling. Note that a controller that chooses to do a Repeated Start and address a *different* target is an unusual case, and it leads to a situation where the transfer closing symbol won't appear until the Stop or a later Repeated Start that *does* address this target. While this transaction style is not explicitly forbidden in the I2C specification, it is not typically supported in the wild. In any case, software should be able to resolve this case, and a closing symbol will eventually appear. Fix up the DV transaction generation to match the expected behavior. Signed-off-by: Alexander Williams <[email protected]>
Remove the extra NACK-specific states, generate ACQ FIFO entries at the point of the NACK timeout, and go to WaitForStop to release SDA and SCL. Return 0xFF on reads for NACK'd transactions. Add NackStop as an ACQ FIFO value to indicate the end of transactions that had errors (generally, NACK'd transfers). Fix up the glitch sequence to better handle the various states. Signed-off-by: Alexander Williams <[email protected]>
Add StretchAcqSetup state to follow the release of the hold from StretchAcqFull after the ACQ FIFO gains the necessary space. Continue to stretch SCL so the change to SDA doesn't violate setup time, then proceed to the normal ACK setup state. Remove the immediate write to the ACQ FIFO in the StretchAcqFull state when we're proceeding to a normal ACK. This created extra ACQ FIFO writes when it transitioned to the AcquireAckWait state, and the FSM gets simpler and less error-prone if only error cases operate on FIFOs outside of the non-stretch states. Signed-off-by: Alexander Williams <[email protected]>
d07a88a
to
cd024a7
Compare
End the transaction wait if the controller receives a NACK. Signed-off-by: Alexander Williams <[email protected]>
cd024a7
to
d78af0c
Compare
Failures are unrelated. Merging. |
Signed-off-by: Harry Callahan <[email protected]>
Signed-off-by: Harry Callahan <[email protected]>
[TESTPLAN,lowRISC#22459] controller_events CSR [TESTPLAN,lowRISC#22460] Overhaul NACK handling [TESTPLAN,lowRISC#22551,e7fe1f8ddb] Address-ACK/NACK ctrl [TESTPLAN,lowRISC#22551,0cbc6f7d99] ack_control_mode test [TESTPLAN,lowRISC#22864] Bus timeout testpoints [TESTPLAN,lowRISC#22865,2296ac62] Target timeout calculated against accumulated stretching time [TESTPLAN,lowRISC#22872] Multi-Controller tests Signed-off-by: Harry Callahan <[email protected]>
[TESTPLAN,#22459] controller_events CSR [TESTPLAN,#22460] Overhaul NACK handling [TESTPLAN,#22551,e7fe1f8ddb] Address-ACK/NACK ctrl [TESTPLAN,#22551,0cbc6f7d99] ack_control_mode test [TESTPLAN,#22864] Bus timeout testpoints [TESTPLAN,#22865,2296ac62] Target timeout calculated against accumulated stretching time [TESTPLAN,#22872] Multi-Controller tests Signed-off-by: Harry Callahan <[email protected]>
[TESTPLAN,lowRISC#22459] controller_events CSR [TESTPLAN,lowRISC#22460] Overhaul NACK handling [TESTPLAN,lowRISC#22551,e7fe1f8ddb] Address-ACK/NACK ctrl [TESTPLAN,lowRISC#22551,0cbc6f7d99] ack_control_mode test [TESTPLAN,lowRISC#22864] Bus timeout testpoints [TESTPLAN,lowRISC#22865,2296ac62] Target timeout calculated against accumulated stretching time [TESTPLAN,lowRISC#22872] Multi-Controller tests Signed-off-by: Harry Callahan <[email protected]>
Change recording of Start symbols to always accompany the address data,
instead of recording a separate R.Start, then Start+address. This helps
maintain certain availability invariants needed for reliable stretching
and NACK handling.
Note that a controller that chooses to do a Repeated Start and address a
different target is an unusual case, and it leads to a situation where
the transfer closing symbol won't appear until the Stop or a later
Repeated Start that does address this target. While this transaction
style is not explicitly forbidden in the I2C specification, it is not
typically supported in the wild. In any case, software should be able to
resolve this case, and a closing symbol will eventually appear.
Fix up the DV transaction generation to match the expected behavior.
Remove the extra NACK-specific states, generate ACQ FIFO entries at the
point of the NACK timeout, and go to WaitForStop to release SDA and SCL.
Return 0xFF on reads for NACK'd transactions.
Add NackStop as an ACQ FIFO value to indicate the end of transactions
that had errors (generally, NACK'd transfers).
Fix up the glitch sequence to better handle the various states.
Finally, add a StretchAcqSetup state to force the target FSM to maintain the required setup time for the ACK bit it started driving.