SPI Device DV document

Goals

  • DV
    • Verify all SPI Device IP features by running dynamic simulations with a SV/UVM based testbench
    • Develop and run all tests based on the testplan below towards closing code and functional coverage on the IP and all of its sub-modules
  • FPV
    • Verify TileLink device protocol compliance with an SVA based testbench

Current status

Design features

For detailed information on SPI Device design features, please see the SPI_device design specification.

Testbench architecture

SPI Device testbench has been constructed based on the CIP testbench architecture.

Block diagram

Block diagram

Top level testbench

Top level testbench is located at hw/ip/spi_device/dv/tb/tb.sv. It instantiates the SPI Device DUT module hw/ip/spi_device/rtl/spi_device.sv. In addition, it instantiates the following interfaces, connects them to the DUT and sets their handle into uvm_config_db:

Common DV utility components

The following utilities provide generic helper tasks and functions to perform activities that are common across the project:

Global types & methods

All common types and methods defined at the package level can be found in spi_device_env_pkg. Some of them in use are:

parameter uint SRAM_OFFSET = 'h800;
parameter uint SRAM_SIZE   = 2048;

TL_agent

SPI Device instantiates (already handled in CIP base env) tl_agent which provides the ability to drive and independently monitor random traffic via TL host interface into SPI Device.

SPI Device agent

spi agent is used to drive and monitor SPI items. Following special behavior is supported in spi_host_driver

  • Toggle clock when SPI is in idle state (csb=1)
  • During data transfer, there may be very long delay between each bit or byte of data

UVM RAL Model

The SPI Device RAL model is created with the ralgen FuseSoC generator script automatically when the simulation is at the build stage.

It can be created manually by invoking regtool:

Stimulus strategy

Test sequences

All test sequences reside in hw/ip/spi_device/dv/env/seq_lib. The spi_device_base_vseq virtual sequence is extended from cip_base_vseq and serves as a starting point. All test sequences are extended from spi_device_base_vseq. It provides commonly used handles, variables, functions and tasks that the test sequences can simple use / call. Some of the most commonly used tasks / functions are as follows:

  • spi_device_init: Fully randomize SPI Device control following CSRs and configure TX/RX SRAM FIFO size as following
    • clock polarity/phase(CPOL, CPHA), bit direction(tx/rx_order), mode, fifo interrupt level(txlvl, rxlvl)
    • TX/RX SRAM FIFO size: from 100 to 1900 and higher distribute for TX size / RX size = 1, 1/2 or 2/1
  • spi_host_xfer_bytes: Send bytes of data to DUT (SPI Device) through spi_host_driver
  • write_device_words_to_send: Write words of data to DUT CSR and update SRAM write pointer, which enables DUT to send data to SPI host.
  • read_tx/rx_avail_bytes: Read CSRs to get how many bytes of available space/data in SRAM memory

Functional coverage

To ensure high quality constrained random stimulus, it is necessary to develop a functional coverage model. The following covergroups have been developed to prove that the test intent has been adequately met:

  • common covergroup for interrupts hw/dv/sv/cip_lib/cip_base_env_cov.sv: Cover interrupt value, interrupt enable, intr_test, interrupt pin
  • TODO, add more

Self-checking strategy

Scoreboard

The spi_device_scoreboard is primarily used for end to end checking. It creates the following analysis fifos to retrieve the data monitored by corresponding interface agents:

  • tl_a_chan_fifo, tl_d_chan_fifo: These 2 fifos provide transaction items at the end of address channel and data channel respectively
  • host_spi_data_fifo, device_spi_data_fifo: These 2 fifos provides TX/RX words of data from spi_monitor

Assertions

  • TLUL assertions: The tb/spi_device_bind.sv binds the tlul_assert assertions to the IP to ensure TileLink interface protocol compliance.
  • Unknown checks on DUT outputs: The RTL has assertions to ensure all outputs are initialized to known values after coming out of reset.

Building and running tests

We are using our in-house developed regression tool for building and running our tests and regressions. Please take a look at the link for detailed information on the usage, capabilities, features and known issues. Here’s how to run a smoke test:

$ $REPO_TOP/util/dvsim/dvsim.py $REPO_TOP/hw/ip/spi_device/dv/spi_device_sim_cfg.hjson -i spi_device_smoke

Testplan

Testpoints

Milestone Name Tests Description
V1 smoke spi_device_smoke

Use default SRAM fifo setting. Seq:

  • Write a word data to TX memory and update wptr
  • Send a word SPI transfer
  • Read a word data from RX memory and update rptr
  • Compare the data and check no pending data in SRAM FIFO
  • Repeat above steps
V1 csr_hw_reset spi_device_csr_hw_reset

Verify the reset values as indicated in the RAL specification.

  • Write all CSRs with a random value.
  • Apply reset to the DUT as well as the RAL model.
  • Read each CSR and compare it against the reset value. it is mandatory to replicate this test for each reset that affects all or a subset of the CSRs.
  • It is mandatory to run this test for all available interfaces the CSRs are accessible from.
  • Shuffle the list of CSRs first to remove the effect of ordering.
V1 csr_rw spi_device_csr_rw

Verify accessibility of CSRs as indicated in the RAL specification.

  • Loop through each CSR to write it with a random value.
  • Read the CSR back and check for correctness while adhering to its access policies.
  • It is mandatory to run this test for all available interfaces the CSRs are accessible from.
  • Shuffle the list of CSRs first to remove the effect of ordering.
V1 csr_bit_bash spi_device_csr_bit_bash

Verify no aliasing within individual bits of a CSR.

  • Walk a 1 through each CSR by flipping 1 bit at a time.
  • Read the CSR back and check for correctness while adhering to its access policies.
  • This verify that writing a specific bit within the CSR did not affect any of the other bits.
  • It is mandatory to run this test for all available interfaces the CSRs are accessible from.
  • Shuffle the list of CSRs first to remove the effect of ordering.
V1 csr_aliasing spi_device_csr_aliasing

Verify no aliasing within the CSR address space.

  • Loop through each CSR to write it with a random value
  • Shuffle and read ALL CSRs back.
  • All CSRs except for the one that was written in this iteration should read back the previous value.
  • The CSR that was written in this iteration is checked for correctness while adhering to its access policies.
  • It is mandatory to run this test for all available interfaces the CSRs are accessible from.
  • Shuffle the list of CSRs first to remove the effect of ordering.
V1 csr_mem_rw_with_rand_reset spi_device_csr_mem_rw_with_rand_reset

Verify random reset during CSR/memory access.

  • Run csr_rw sequence to randomly access CSRs
  • If memory exists, run mem_partial_access in parallel with csr_rw
  • Randomly issue reset and then use hw_reset sequence to check all CSRs are reset to default value
  • It is mandatory to run this test for all available interfaces the CSRs are accessible from.
V1 regwen_csr_and_corresponding_lockable_csrspi_device_csr_rw
spi_device_csr_aliasing

Verify regwen CSR and its corresponding lockable CSRs.

  • Randomly access all CSRs
  • Test when regwen CSR is set, its corresponding lockable CSRs become read-only registers

Note:

  • If regwen CSR is HW read-only, this feature can be fully tested by common CSR tests - csr_rw and csr_aliasing.
  • If regwen CSR is HW updated, a separate test should be created to test it.

This is only applicable if the block contains regwen and locakable CSRs.

V1 mem_walk spi_device_mem_walk

Verify accessibility of all memories in the design.

  • Run the standard UVM mem walk sequence on all memories in the RAL model.
  • It is mandatory to run this test from all available interfaces the memories are accessible from.
V1 mem_partial_access spi_device_mem_partial_access

Verify partial-accessibility of all memories in the design.

  • Do partial reads and writes into the memories and verify the outcome for correctness.
  • Also test outstanding access on memories
V2 base_random_seq spi_device_txrx

Create 3 parallel threads

  • Write random data to TX memory unless fifo is full
  • Send SPI transfer unless TX is empty or RX is full
  • Read RX memory unless RX is empty
V2 fifo_full spi_device_fifo_full

Increase the chance to have fifo full by following

  • Reduce delay to write TX memory
  • Increase delay to read RX memory
V2 fifo_underflow_overflow spi_device_fifo_underflow_overflow

Override spi_device_txrx_vseq to send SPI transfer without checking TX/RX fifo, note:

  • When TX is underflow, SW shouldn't update wptr if spi isn't idle, otherwise, spi may send mis-aligned data
  • When RX is overflow, data will be lost and if SW update rptr, received data may be mis-aligned
  • Ensure underflow/overflow is triggered correctly
V2 dummy_sck_and_dummy_csb spi_device_dummy_item_extra_dly

Drive dummy sck without csb or drive dummy csb without sck, and test no impact on the design

V2 extra_delay_on_spi spi_device_dummy_item_extra_dly

Add extra delay between spi clock edge or extra delay between 2 words data This is to test host pause transfer for a while without turning off csb and then stream in data again

V2 tx_async_fifo_reset spi_device_tx_async_fifo_reset

Reset TX async fifo when SPI interface is idle

  • Fill TX SRAM FIFO with some data, which will be transfered to TX async FIFO
  • Write 0 into read and write point of TX SRAM FIFO
  • Program rst_txfifo to reset the async FIFO
  • Check async_fifo_level.txlvl is 0
  • Fill TX SRAM FIFO with some other data and enable SPI transfer
  • Check SPI device sends and receives the correct data
V2 rx_async_fifo_reset spi_device_rx_async_fifo_reset

Reset RX async fifo when SPI interface is idle

  • Configure RX SRAM FIFO with a small size, so that it's easy to fill up
  • Start SPI transfers to fill up the RX SRAM FIFO and at least part of the RX async FIFO
  • Program rst_rxfifo to reset the async FIFO
  • Check async_fifo_level.rxlvl is 0
  • Write 0 into read and write point of RX SRAM FIFO
  • Fill TX SRAM FIFO with some other data and start another SPI transfers
  • Check SPI device sends and receives the correct data
V2 interrupts spi_device_intr

Test all supported interrupts:

  • tx/rx lvl
  • rx full
  • rx error
  • overflow/underflow
V2 abort spi_device_abort
  • Fill TX FIFO without host traffic
  • Issue Abort to control register
  • Poll until abort_done in status register
  • TBD additional checking
V2 byte_transfer_on_spi spi_device_byte_transfer

send spi transfer on byte granularity, and make sure the timer never expires

V2 rx_timeout spi_device_rx_timeout
  • Send spi transfer on byte granularity, and timer may expires
  • Only check data in sequence level when timer expires. Monitor and scoreboard don't model the timer feature
  • Note: Timeout only for RX
V2 bit_transfer_on_spi spi_device_bit_transfer

Send spi transfer on bit granularity

  • If TX drives < 7 bits, this byte will be sent in next CSB.
  • If TX drives 7 bits and set CSB to high, this byte won't be sent in next CSB
V2 extreme_fifo_setting spi_device_extreme_fifo_size

Set fifo size to 4 bytes(minimum), 2k-4bytes(maximum) and others

V2 perf spi_device_perf

Run spi_device_fifi_full_vseq with very small delays

V2 tpm_read spi_device_tpm_read
  • Set TPM_CFG.TPM_MODE to 0 and set TPM_CFG.EN.
  • Randomise other fields in TPM_CFG.
  • Assert the tpm_csb.
  • Send TPM read command over the SPI bus with a randomised address.
  • Check TPM_CMD_ADDR.
  • Confirm FIFO behaviour dictated by TPM_CFG.tpm_mode.
  • Check TPM_STATUS.cmdaddr_notempty and INTR_STATE.tpm_header_notempty, they should be asserted if hw_reg_dis == 0.
  • If hw_reg_dis == 0, the data is returned to the host via return-by-HW register, else the data is returned via read FIFO.
  • Confirm that the TPM submodule sends WAIT until the read FIFO is available.
  • Check the read FIFO.
  • When available, confirm that the TPM submodule sends START followed by the register value.
  • Compare this value with the expected value.
V2 tpm_write spi_device_tpm_write
  • Set TPM_CFG.TPM_MODE to 0 and set TPM_CFG.EN.
  • Randomise other fields in TPM_CFG.
  • Assert the tpm_csb.
  • Send TPM write command with a randomised address.
  • Check TPM_CMD_ADDR and write FIFO.
  • Check TPM_STATUS.cmdaddr_notempty and INTR_STATE.tpm_header_notempty.
  • Based on FIFO status, check SPI bus to confirm WAIT or START sent.
  • Check that the TPM submodule accepts write data without the WAIT state if the write FIFO is empty.
  • Otherwise, check WAIT until the write FIFO becomes available (empty).
V2 tpm_locality spi_device_tpm_locality
  • Make transactions of varying locality to the tpm submodule.
  • Ensure that the data returned is correct for the given locality.
  • Randomise TPM_CFG.invalid_locality and confirm response.
V2 pass_cmd_filtering spi_device_pass_cmd_filtering
  • Randomize command opcode.
  • Configure unused CMD_INFO reg with new opcode and set it to valid.
  • Check opcode and address are passing through.
  • Configure filter bit corresponding to opcode to 1.
  • Check only opcode is passing through.
  • Set filter bit back to 0.
  • Check opcode and address are passing through again.
V2 pass_addr_translation spi_device_pass_addr_translation
  • Randomize command opcode.
  • Configure unused CMD_INFO reg with new opcode and set it to valid.
  • Enable address translation for given command.
  • Configure address translation bits.
  • Check proper address translation is applied.
  • Disable address translation for given command.
  • Check address is now passing unchanged.
V2 pass_payload_translation spi_device_pass_data_translation
  • Configure program or write_status command.
  • Enable payload translation for given command.
  • Configure payload translation bits.
  • Check proper payload translation is applied.
  • Disable payload translation for given command.
  • Check payload is now passing unchanged.
V2 cmd_info_slots
  • Configure first 5 slots according to required configuration.
  • Configure next 6 slots for read commands
  • Randomize configuration of the remaining 13 cmd info slots.
  • Issue commands with various opcodes enabled in info slots.
  • Check proper command propagation.
  • Disable some cmd info slots.
  • Check no propagation of disabled commands.
V2 cmd_read_status
  • Configure proper read status command info slot.
  • Issue read status command.
  • Check propagation of read status command.
  • Initiate response to the read status.
  • Check proper reception of response.
V2 cmd_read_jedec
  • Configure proper read jedec command info slot.
  • Issue read jedec command.
  • Check propagation of read jedec command.
  • Initiate response to the read jedec.
  • Check proper reception of response.
V2 cmd_read_sfdp
  • Configure proper read sfdp command info slot.
  • Issue read sfdp command.
  • Check propagation of read sfdp command.
  • Initiate response to the read sfdp.
  • Check proper reception of response.
V2 cmd_fast_read
  • Configure proper fast read command info slot.
  • Issue fast read command.
  • Check propagation of fast read command.
  • Initiate response to the fast read.
  • Check proper reception of response.
V2 flash_cmd_upload
  • Configure flash mode.
  • Configure cmd info slots.
  • Set upload to 1 for some of 13 non fixed cmd info slots.
  • Host should poll busy field status to check if command is done.
  • Issue next command upload and poll busy status again.
V2 mailbox_command
  • Configure cmd info slots.
  • Issue one of predefined read command targeting mailbox space.
  • Check response to read command.
  • Check if command is processed internally.
V2 mailbox_cross_outside_command
  • Configure cmd info slots.
  • Issue one of predefined read command targeting mailbox space.
  • Command should start inside mailbox space and cross into read space.
  • Command should be blocked.
V2 mailbox_cross_inside_command
  • Configure cmd info slots.
  • Issue one of predefined read command targeting read space outside mailbox space.
  • Command should start outside mailbox space and cross into mailbox space.
  • Command should be blocked.
V2 cmd_read_buffer
  • Configure device in flash or passthrough mode.
  • SW updates read buffer contents.
  • Issue read command.
  • Check proper read data.
  • Issue new read command that crosses read buffer boundary.
  • Behavior on crossing uncertain //TODO Clarify spec on this
  • Check internal buffer index bit.
V2 cmd_dummy_cycle
  • Configure cmd info slots.
  • Configure dummy cycle of read commands to non default value.
  • For single mode allowed dummy cycle is 7.
  • For dual mode allowed dummy cycle is 3 and 7.
  • For quad mode allowed dummy cycle is 1, 3, 5 and 7.
  • Check return data timing for configured commands.
  • Check proper read data.
  • Issue new read command that crosses read buffer boundary.
  • Check internal buffer index bit.
V2 quad_spi
  • Configure passthrough or flash mode.
  • Configure cmd info slots.
  • Configure quad mode.
  • Issue supported command.
  • Check data on all four lines.
V2 dual_spi
  • Configure passthrough or flash mode.
  • Configure cmd info slots.
  • Configure dual mode.
  • Issue supported command.
  • Check data on both lines.
V2 4b_3b_feature
  • Configure passthrough or flash mode.
  • Configure command info slots.
  • Configure different values for 4B/3B.
  • Randomize configuration of EN4B and EX4B register fields.
  • Issue supported command with required address.
  • Check proper address propagation.
V2 alert_test spi_device_alert_test

Verify common alert_test CSR that allows SW to mock-inject alert requests.

  • Enable a random set of alert requests by writing random value to alert_test CSR.
  • Check each alert_tx.alert_p pin to verify that only the requested alerts are triggered.
  • During alert_handshakes, write alert_test CSR again to verify that: If alert_test writes to current ongoing alert handshake, the alert_test request will be ignored. If alert_test writes to current idle alert handshake, a new alert_handshake should be triggered.
  • Wait for the alert handshakes to finish and verify alert_tx.alert_p pins all sets back to 0.
  • Repeat the above steps a bunch of times.
V2 intr_test spi_device_intr_test

Verify common intr_test CSRs that allows SW to mock-inject interrupts.

  • Enable a random set of interrupts by writing random value(s) to intr_enable CSR(s).
  • Randomly "turn on" interrupts by writing random value(s) to intr_test CSR(s).
  • Read all intr_state CSR(s) back to verify that it reflects the same value as what was written to the corresponding intr_test CSR.
  • Check the cfg.intr_vif pins to verify that only the interrupts that were enabled and turned on are set.
  • Clear a random set of interrupts by writing a randomly value to intr_state CSR(s).
  • Repeat the above steps a bunch of times.
V2 tl_d_oob_addr_access spi_device_tl_errors

Access out of bounds address and verify correctness of response / behavior

V2 tl_d_illegal_access spi_device_tl_errors

Drive unsupported requests via TL interface and verify correctness of response / behavior. Below error cases are tested bases on the [TLUL spec]({{< relref "hw/ip/tlul/doc/_index.md#explicit-error-cases" >}})

  • TL-UL protocol error cases
    • invalid opcode
    • some mask bits not set when opcode is PutFullData
    • mask does not match the transfer size, e.g. a_address = 0x00, a_size = 0, a_mask = 'b0010
    • mask and address misaligned, e.g. a_address = 0x01, a_mask = 'b0001
    • address and size aren't aligned, e.g. a_address = 0x01, a_size != 0
    • size is greater than 2
  • OpenTitan defined error cases
    • access unmapped address, expect d_error = 1 when devmode_i == 1
    • write a CSR with unaligned address, e.g. a_address[1:0] != 0
    • write a CSR less than its width, e.g. when CSR is 2 bytes wide, only write 1 byte
    • write a memory with a_mask != '1 when it doesn't support partial accesses
    • read a WO (write-only) memory
    • write a RO (read-only) memory
    • write with instr_type = True
V2 tl_d_outstanding_access spi_device_csr_hw_reset
spi_device_csr_rw
spi_device_csr_aliasing
spi_device_same_csr_outstanding

Drive back-to-back requests without waiting for response to ensure there is one transaction outstanding within the TL device. Also, verify one outstanding when back- to-back accesses are made to the same address.

V2 tl_d_partial_access spi_device_csr_hw_reset
spi_device_csr_rw
spi_device_csr_aliasing
spi_device_same_csr_outstanding

Access CSR with one or more bytes of data. For read, expect to return all word value of the CSR. For write, enabling bytes should cover all CSR valid fields.

V2S tl_intg_err spi_device_tl_intg_err
spi_device_sec_cm

Verify that the data integrity check violation generates an alert.

  • Randomly inject errors on the control, data, or the ECC bits during CSR accesses. Verify that triggers the correct fatal alert.
  • Inject a fault at the onehot check in u_reg.u_prim_reg_we_check and verify the corresponding fatal alert occurs
V2S sec_cm_bus_integrity

Verify the countermeasure(s) BUS.INTEGRITY.

Covergroups

Name Description
regwen_val_when_new_value_written_cg

Cover each lockable reg field with these 2 cases:

  • When regwen = 1, a different value is written to the lockable CSR field, and a read occurs after that.
  • When regwen = 0, a different value is written to the lockable CSR field, and a read occurs after that.

This is only applicable if the block contains regwen and locakable CSRs.

spi_device_4B_address_management_cg

Cover all possible combinations of EN4B and EX4B. Cross with various read commands.

spi_device_abort_all_cg

Cover the correct abort functionality for all modes.

TODO: Functionality of abort to be clarified.

spi_device_buffer_boundary_cg

Cover buffer boundary crossing (buffer flip).

spi_device_cmd_info_cg

Cover all opcode enabled in cmd info. Cover all payload direction. Cover all address modes. Cover addr swap enable. Cover payload swap enable. Cover upload enable. Cover busy enable. Cover all dummy sizes. Cover all payload enables. This is not configuration coverage, cover only if we have relevant transaction with opcode configured and enabled in cmd_info slot.

TODO: Consider relevant crosses between opcode and other items.

spi_device_fifo_fsm_cg

Cover all fsm states for RX/TX FIFO.

spi_device_lanes_cg

Cover out commands that use dual mode. Cover out commands that use quad mode. Cross dual and quad modes with flash/passthrough mode.

spi_device_mailbox_cg

Cover commands targeting mailbox space. Cover command starting in buffer overlapping with mailbox. Cover command starting in mailbox comming outside mailbox space.

spi_device_pass_addr_swap_cg

Cover all bits enable for address translation. Cover all bits values for address translation.

spi_device_pass_cmd_filter_cg

Cover all possible bits for command filter. Every opcode should be enabled and filtering checked.

spi_device_pass_payload_swap_cg

Cover all bits enable for payload translation. Cover all bits values for payload translation.

spi_device_payload_size_cg

Cover supported payload sizes for IN transactions. Cover supported payload sizes for OUT transactions. Cover upload transaction payload size. Cover payload size of upload transaction exceeds 256B limit (wrap around).

spi_device_read_commands_cg

Cover read status commands. Cover read JEDEC command. Cover read SFDP command. Cover all other read commands configurable in slots up to 10. Cover dummy cycle for all read commands. Cover INTERCEPT_EN with all applicable read commands.

spi_device_sck_config_cg

Cover all combinations of SPI_DEVICE.CFG.CPOL and SPI_DEVICE.CFG.CPHA.

Cover valid combinations for each mode.

spi_device_sram_size_cg

Cover the SramAw local parameter to confirm all sizes 1 - 32kB.

spi_device_tpm_all_modes_cg

Cover every combination of all possible modes:

  • All modes perform tx/rx interleaved tpm tx/rx.
spi_device_tpm_states_cg

Cover all tpm states on the SPI bus (WAIT, INVALID, ETC).

spi_device_txrx_order_cg

Verify that data being tx/rx is valid regardless of bit order and that the functionality behaves as expected:

Cover all configurations of rx/tx order in SPI_DEVICE.CFG for all valid modes.

tl_errors_cg

Cover the following error cases on TL-UL bus:

  • TL-UL protocol error cases.
  • OpenTitan defined error cases, refer to testpoint tl_d_illegal_access.
tl_intg_err_cg

Cover all kinds of integrity errors (command, data or both) and cover number of error bits on each integrity check.

Cover the kinds of integrity errors with byte enabled write on memory if applicable: Some memories store the integrity values. When there is a subword write, design re-calculate the integrity with full word data and update integrity in the memory. This coverage ensures that memory byte write has been issued and the related design logic has been verfied.