Rasmus Madsen | 583c80d | 2020-12-10 06:21:29 -0800 | [diff] [blame] | 1 | // Copyright lowRISC contributors. |
| 2 | // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Implements functional coverage for AES |
| 6 | |
| 7 | interface aes_cov_if |
| 8 | ( |
| 9 | input logic clk_i // not sure I will use this yet |
| 10 | ); |
| 11 | |
| 12 | import uvm_pkg::*; |
| 13 | import aes_pkg::*; |
| 14 | import dv_utils_pkg::*; |
| 15 | `include "dv_fcov_macros.svh" |
| 16 | |
| 17 | bit en_full_cov = 1'b1; |
| 18 | bit en_intg_cov = 1'b1; |
| 19 | |
| 20 | /////////////////////////////////// |
| 21 | // Control register cover points // |
| 22 | /////////////////////////////////// |
| 23 | |
| 24 | covergroup aes_ctrl_cg with function sample(bit aes_op, |
| 25 | bit [aes_pkg::AES_MODE_WIDTH-1:0] aes_mode, |
| 26 | bit [aes_pkg::AES_KEYLEN_WIDTH-1:0] aes_keylen, |
| 27 | bit aes_man_op, |
| 28 | bit aes_force_0mask |
| 29 | ); |
| 30 | option.per_instance = 1; |
| 31 | option.name = "aes_ctrl_cg"; |
| 32 | |
| 33 | cp_operation: coverpoint aes_op |
| 34 | { |
| 35 | bins enc = {AES_ENC}; |
| 36 | bins dec = {AES_DEC}; |
| 37 | } |
| 38 | |
| 39 | cp_mode: coverpoint aes_mode |
| 40 | { |
| 41 | bins ecb = { AES_ECB}; |
| 42 | bins cbc = { AES_CBC }; |
| 43 | bins cfb = { AES_CFB }; |
| 44 | bins ofb = { AES_OFB }; |
| 45 | bins ctr = { AES_CTR }; |
| 46 | bins none = { AES_NONE }; |
| 47 | bins illegal = { [0:$] } with ($countones(item) != 1); |
| 48 | } |
| 49 | |
| 50 | cp_key_len: coverpoint aes_keylen |
| 51 | { |
| 52 | bins aes_128 = {AES_128}; |
| 53 | bins aes_192 = {AES_192}; |
| 54 | bins aes_256 = {AES_256}; |
| 55 | bins illegal = { [0:$] } with ($countones(item) != 1); |
| 56 | } |
| 57 | |
| 58 | cp_manual_operation: coverpoint aes_man_op |
| 59 | { |
| 60 | bins auto_mode = { 1'b0 }; |
| 61 | bins manual_mode = { 1'b1 }; |
| 62 | } |
| 63 | |
| 64 | cp_force_0_masks: coverpoint aes_force_0mask; |
| 65 | |
| 66 | // Cross coverage points |
| 67 | // All key_lens are tested in all modes |
| 68 | cr_mode_key_len: cross cp_mode, cp_key_len; |
| 69 | // all modes are tested in both auto an manual operation |
| 70 | cr_mode_man_op: cross cp_mode, cp_manual_operation; |
| 71 | // All modes used in both incryption and decryption |
| 72 | cr_mode_op: cross cp_mode, cp_operation; |
| 73 | endgroup // aes_ctrl_cg |
| 74 | |
| 75 | |
| 76 | /////////////////////////////////// |
| 77 | // Status register cover points // |
| 78 | /////////////////////////////////// |
| 79 | |
| 80 | covergroup aes_status_cg with function sample(status_t aes_status); |
| 81 | option.per_instance = 1; |
| 82 | option.name = "aes_status_cg"; |
| 83 | endgroup // aes_status_cg |
| 84 | |
| 85 | |
| 86 | /////////////////////////////////// |
| 87 | // Trigger register cover points // |
| 88 | /////////////////////////////////// |
| 89 | |
| 90 | covergroup aes_trigger_cg with function sample(bit aes_start, |
| 91 | bit aes_key_iv_datain_clear, |
| 92 | bit aes_dataout_clear, |
| 93 | bit aes_prng_reseed |
| 94 | ); |
| 95 | option.per_instance = 1; |
| 96 | option.name = "aes_trigger_cg"; |
| 97 | |
| 98 | cp_start: coverpoint aes_start; |
| 99 | cp_key_iv_datain_clear: coverpoint aes_key_iv_datain_clear; |
| 100 | cp_dataout_clear: coverpoint aes_dataout_clear; |
| 101 | cp_prng_reseed: coverpoint aes_prng_reseed; |
| 102 | |
| 103 | cr_clear: cross cp_key_iv_datain_clear, cp_dataout_clear; |
| 104 | |
| 105 | endgroup // aes_trigger_cg |
| 106 | |
| 107 | /////////////////////////////////// |
| 108 | // Alert register cover points // |
| 109 | /////////////////////////////////// |
| 110 | |
| 111 | covergroup aes_alert_cg with function sample(alert_test_t alert_test); |
| 112 | option.per_instance = 1; |
| 113 | option.name = "aes_test_alert_cg"; |
| 114 | endgroup // aes_alert_cg |
| 115 | |
| 116 | |
| 117 | /////////////////////////////////// |
| 118 | // Instantiation Macros // |
| 119 | /////////////////////////////////// |
| 120 | |
| 121 | `DV_FCOV_INSTANTIATE_CG(aes_ctrl_cg, en_full_cov) |
| 122 | `DV_FCOV_INSTANTIATE_CG(aes_status_cg, en_full_cov) |
| 123 | `DV_FCOV_INSTANTIATE_CG(aes_trigger_cg, en_full_cov) |
| 124 | `DV_FCOV_INSTANTIATE_CG(aes_alert_cg, en_full_cov) |
| 125 | |
| 126 | |
| 127 | /////////////////////////////////// |
| 128 | // Sample functions // |
| 129 | // needed for xcelium // |
| 130 | /////////////////////////////////// |
| 131 | |
| 132 | function automatic void cg_ctrl_sample(bit aes_op, |
| 133 | bit [aes_pkg::AES_MODE_WIDTH-1:0] aes_mode, |
| 134 | bit [aes_pkg::AES_KEYLEN_WIDTH-1:0] aes_keylen, |
| 135 | bit aes_man_op, |
| 136 | bit aes_force_0mask |
| 137 | ); |
| 138 | aes_ctrl_cg_inst.sample(aes_op, aes_mode, aes_keylen, aes_man_op, aes_force_0mask); |
| 139 | endfunction |
| 140 | |
| 141 | function automatic void cg_status_sample(bit [31:0] val); |
| 142 | aes_status_cg_inst.sample(val); |
| 143 | endfunction |
| 144 | |
| 145 | function automatic void cg_trigger_sample(bit aes_start, |
| 146 | bit aes_key_iv_datain_clear, |
| 147 | bit aes_dataout_clear, |
| 148 | bit aes_prng_reseed |
| 149 | ); |
Rupert Swarbrick | 2bd0642 | 2021-04-22 12:31:41 +0100 | [diff] [blame^] | 150 | aes_trigger_cg_inst.sample(aes_start, |
| 151 | aes_key_iv_datain_clear, |
| 152 | aes_dataout_clear, |
| 153 | aes_prng_reseed); |
Rasmus Madsen | 583c80d | 2020-12-10 06:21:29 -0800 | [diff] [blame] | 154 | endfunction |
| 155 | |
| 156 | function automatic void cg_alert_test_sample(bit [31:0] val); |
| 157 | aes_alert_cg_inst.sample(val); |
| 158 | endfunction |
| 159 | |
| 160 | endinterface |