diff --git a/hw/ip/aes/dv/cov/aes_cov_if.sv b/hw/ip/aes/dv/cov/aes_cov_if.sv index 1d0968be8a10e..e7d5a8b7b2864 100644 --- a/hw/ip/aes/dv/cov/aes_cov_if.sv +++ b/hw/ip/aes/dv/cov/aes_cov_if.sv @@ -282,6 +282,79 @@ interface aes_cov_if } endgroup // aes_reg_interleave_cg + covergroup aes_gcm_text_len_cg with function sample( + int text_blocks, + int text_last_block_len, + bit [aes_pkg::AES_OP_WIDTH-1:0] aes_op + ); + option.per_instance = 1; + option.name = "aes_gcm_text_len_cg"; + + cp_operation: coverpoint aes_op + { + bins enc = {AES_ENC}; + bins dec = {AES_DEC}; + } + + cp_text_blocks: coverpoint text_blocks + { + bins text_blocks_0 = {0}; + bins text_blocks_l[2] = {[1:2]}; + bins text_blocks_h = {[3:$]}; + } + + cp_text_last_block_len: coverpoint text_last_block_len + { + bins text_last_block_len_l[2] = {[0:1]}; + bins text_last_block_len_m[2] = {[2:13]}; + bins text_last_block_len_h[2] = {[14:15]}; + } + + // Cross coverage points + // Ignore zero block in cross coverage. + cr_op_aad_block_len: cross cp_operation, cp_text_blocks, cp_text_last_block_len + { + ignore_bins zero_blocks = binsof(cp_text_blocks) intersect {0}; + } + + endgroup // aes_gcm_text_len_cg + + covergroup aes_gcm_aad_len_cg with function sample( + int aad_blocks, + int aad_last_block_len, + bit [aes_pkg::AES_OP_WIDTH-1:0] aes_op + ); + option.per_instance = 1; + option.name = "aes_gcm_aad_len_cg"; + + cp_operation: coverpoint aes_op + { + bins enc = {AES_ENC}; + bins dec = {AES_DEC}; + } + + cp_aad_blocks: coverpoint aad_blocks + { + bins aad_blocks_0 = {0}; + bins aad_blocks_l[2] = {[1:2]}; + bins aad_blocks_h = {[3:$]}; + } + + cp_aad_last_block_len: coverpoint aad_last_block_len + { + bins aad_last_block_len_l[2] = {[0:1]}; + bins aad_last_block_len_m[2] = {[2:13]}; + bins aad_last_block_len_h[2] = {[14:15]}; + } + + // Cross coverage points + // Ignore zero block in cross coverage. + cr_op_aad_block_len: cross cp_operation, cp_aad_blocks, cp_aad_last_block_len + { + ignore_bins zero_blocks = binsof(cp_aad_blocks) intersect {0}; + } + + endgroup // aes_gcm_aad_len_cg /////////////////////////////////// // Instantiation Macros // @@ -296,7 +369,8 @@ interface aes_cov_if `DV_FCOV_INSTANTIATE_CG(aes_iv_interleave_cg, en_full_cov) `DV_FCOV_INSTANTIATE_CG(aes_key_interleave_cg, en_full_cov) `DV_FCOV_INSTANTIATE_CG(aes_reg_interleave_cg, en_full_cov) - + `DV_FCOV_INSTANTIATE_CG(aes_gcm_text_len_cg, en_full_cov) + `DV_FCOV_INSTANTIATE_CG(aes_gcm_aad_len_cg, en_full_cov) /////////////////////////////////// // Sample functions // @@ -356,4 +430,18 @@ interface aes_cov_if aes_key_interleave_cg_inst.sample(key, idle_i); aes_reg_interleave_cg_inst.sample(1); endfunction + + function automatic void cg_gcm_text_len_sample( + int text_blocks, + int text_last_block_len, + bit [aes_pkg::AES_OP_WIDTH-1:0] aes_op); + aes_gcm_text_len_cg_inst.sample(text_blocks, text_last_block_len, aes_op); + endfunction + + function automatic void cg_gcm_aad_len_sample( + int aad_blocks, + int aad_last_block_len, + bit [aes_pkg::AES_OP_WIDTH-1:0] aes_op); + aes_gcm_aad_len_cg_inst.sample(aad_blocks, aad_last_block_len, aes_op); + endfunction endinterface diff --git a/hw/ip/aes/dv/env/aes_scoreboard.sv b/hw/ip/aes/dv/env/aes_scoreboard.sv index 82c010fd7e412..4e27ab45d3755 100644 --- a/hw/ip/aes/dv/env/aes_scoreboard.sv +++ b/hw/ip/aes/dv/env/aes_scoreboard.sv @@ -136,7 +136,25 @@ class aes_scoreboard extends cip_base_scoreboard #( if (keyname == csr_name && (|datain_rdy || input_item.manual_op)) begin input_item.data_in[i] = wdata; input_item.data_in_vld[i] = 1'b1; - cov_if.cg_wr_data_sample(i); + if (input_item.mode == AES_GCM && input_item.item_type == AES_GCM_TAG) begin + bit [31:0] endianess_swapped = {<<8{wdata}}; + int len_bytes = endianess_swapped / 8; + int blocks = len_bytes / 16; + int last_block_len_bytes = len_bytes % 16; + // In AES-GCM, len(aad) || len(data) is a 128-bit value where 64-bit + // each are reserved for len(aad) and len(data). Note that len(data) + // and len(aad) is the length in bits. To simplify the scoreboard, just + // take the lower 32-bits for the length. This is fine as, with 32-bit, + // we can represent long AADs and texts. Currently, in the DV tests, + // the longest AAD and text is 1023 bytes (8184 bits). + if (i == 3) begin + cov_if.cg_gcm_text_len_sample(blocks, last_block_len_bytes, input_item.operation); + end else if (i == 1) begin + cov_if.cg_gcm_aad_len_sample(blocks, last_block_len_bytes, input_item.operation); + end + end else begin + cov_if.cg_wr_data_sample(i); + end datain_rdy[i] = 0; end end