Skip to content

Commit

Permalink
[kmac/dv] KMAC smoke test
Browse files Browse the repository at this point in the history
This commit adds the initial version of KMAC smoke test.

There are some TODO items remaining that will be handled in the future,
such as adding random sideload key injections, and moving most of the
checking logic into the scoreboard once it is fleshed out.

Signed-off-by: Udi Jonnalagadda <udij@google.com>
  • Loading branch information
Udi Jonnalagadda committed Jan 15, 2021
1 parent 33d9a8a commit c9347e6
Show file tree
Hide file tree
Showing 11 changed files with 923 additions and 21 deletions.
11 changes: 10 additions & 1 deletion hw/dv/sv/dv_utils/dv_utils_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,20 @@ package dv_utils_pkg;
return val >= 0 ? val : -val;
endfunction

// endian swap
// endian swaps a 32-bit data word
function automatic logic [31:0] endian_swap(logic [31:0] data);
return {<<8{data}};
endfunction

// endian swaps bytes at a word granularity, while preserving overall word ordering.
//
// e.g. if `arr[] = '{'h0, 'h1, 'h2, 'h3, 'h4, 'h5, 'h6, 'h7}`, this function will produce:
// `'{'h3, 'h2, 'h1, 'h0, 'h7, 'h6, 'h5, 'h4}`
function automatic void endian_swap_byte_arr(ref bit [7:0] arr[]);
arr = {<< byte {arr}};
arr = {<< 32 {arr}};
endfunction

`ifdef UVM
// Simple function to set max errors before quitting sim
function automatic void set_max_quit_count(int n);
Expand Down
2 changes: 2 additions & 0 deletions hw/ip/kmac/dv/env/kmac_env.core
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ filesets:
- lowrisc:dv:ralgen
- lowrisc:dv:cip_lib
- lowrisc:dv:push_pull_agent
- lowrisc:dv:str_utils
- lowrisc:dv:test_vectors
- lowrisc:dv:digestpp_dpi:0.1
- lowrisc:ip:kmac
files:
- kmac_env_pkg.sv
- kmac_sideload_if.sv
Expand Down
3 changes: 3 additions & 0 deletions hw/ip/kmac/dv/env/kmac_env_cfg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class kmac_env_cfg extends cip_base_env_cfg #(.RAL_T(kmac_reg_block));
idle_vif idle_vif;
sideload_vif sideload_vif;

// Masked KMAC is the default configuration
bit enable_masking = 1;

`uvm_object_utils_begin(kmac_env_cfg)
`uvm_object_utils_end

Expand Down
30 changes: 28 additions & 2 deletions hw/ip/kmac/dv/env/kmac_env_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ package kmac_env_pkg;
import dv_utils_pkg::*;
import dv_lib_pkg::*;
import tl_agent_pkg::*;
import str_utils_pkg::*;
import test_vectors_pkg::*;
import digestpp_dpi_pkg::*;
import cip_base_pkg::*;
import csr_utils_pkg::*;
import push_pull_agent_pkg::*;
import kmac_ral_pkg::*;
import kmac_pkg::*;
import keymgr_pkg::*;

// macro includes
Expand All @@ -23,6 +25,27 @@ package kmac_env_pkg;

// parameters

// max number of shares in design
parameter int KMAC_NUM_SHARES = 2;

parameter int KMAC_NUM_KEYS_PER_SHARE = 16;

// share1 of the 1600-bit KMAC state memory
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE0_BASE = 32'h400;
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE0_END = 32'h4C7;

// share2 of the 1600-bit KMAC state memory
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE1_BASE = 32'h500;
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE1_END = 32'h5C7;

// base and end addresses of the KAMC message FIFO.
parameter bit [TL_AW-1:0] KMAC_FIFO_BASE = 32'h800;
parameter bit [TL_AW-1:0] KMAC_FIFO_END = 32'hFFC;

// Represents the max bit-width of some value to be encoded with either
// `right_encode()` or `left_encode()`.
parameter int MAX_ENCODE_WIDTH = 2040;

// Sideload data has 2*KeyWidth bits of key shares and 1 bit valid.
parameter int SIDELOAD_KEY_SIZE = $bits(hw_key_req_t);
// KDF request data has 1 bit for last, and the rest are for data/strb.
Expand All @@ -33,10 +56,13 @@ package kmac_env_pkg;
parameter int KDF_DIGEST_SIZE = $bits(kmac_data_rsp_t) - 1;

// types
typedef enum {

// interrupt types
typedef enum logic [1:0] {
KmacDone,
KmacFifoEmpty,
KmacErr
KmacErr,
KmacNumIntrs
} kmac_intr_e;

typedef virtual pins_if#(1) idle_vif;
Expand Down
25 changes: 19 additions & 6 deletions hw/ip/kmac/dv/env/kmac_scoreboard.sv
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class kmac_scoreboard extends cip_base_scoreboard #(

virtual task process_tl_access(tl_seq_item item, tl_channels_e channel = DataChannel);
uvm_reg csr;
bit do_read_check = 1'b1;
bit write = item.is_write();
uvm_reg_addr_t csr_addr = ral.get_word_aligned_addr(item.a_addr);
bit do_read_check = 1'b1;
bit write = item.is_write();
uvm_reg_addr_t csr_addr = ral.get_word_aligned_addr(item.a_addr);
bit [TL_AW-1:0] csr_addr_mask = ral.get_addr_mask();

bit addr_phase_read = (!write && channel == AddrChannel);
bit addr_phase_write = (write && channel == AddrChannel);
Expand All @@ -44,8 +45,15 @@ class kmac_scoreboard extends cip_base_scoreboard #(
if (csr_addr inside {cfg.csr_addrs}) begin
csr = ral.default_map.get_reg_by_offset(csr_addr);
`DV_CHECK_NE_FATAL(csr, null)
end
else begin
end else if ((csr_addr & csr_addr_mask) inside {[KMAC_FIFO_BASE:KMAC_FIFO_END]}) begin
// msgfifo window
return;
end else if ((csr_addr & csr_addr_mask) inside
{[KMAC_STATE_SHARE0_BASE:KMAC_STATE_SHARE0_END],
[KMAC_STATE_SHARE1_BASE:KMAC_STATE_SHARE1_END]}) begin
// state digest window
return;
end else begin
`uvm_fatal(`gfn, $sformatf("Access unexpected addr 0x%0h", csr_addr))
end

Expand All @@ -69,8 +77,13 @@ class kmac_scoreboard extends cip_base_scoreboard #(
"intr_test": begin
// FIXME
end
"status": begin
// STATUS is read only
do_read_check = 1'b0;
end
default: begin
`uvm_fatal(`gfn, $sformatf("invalid csr: %0s", csr.get_full_name()))
// TODO: uncomment after implementing scoreboard
//`uvm_fatal(`gfn, $sformatf("invalid csr: %0s", csr.get_full_name()))
end
endcase

Expand Down
Loading

0 comments on commit c9347e6

Please sign in to comment.