Skip to content

Commit a8bbca8

Browse files
committed
[flash_ctrl,dv] Make some structures unpacked
For example, consider flash_mp_region_cfg_t. Structs of this type are randomised in several places (see flash_ctrl_error_mp_vseq, for example). This isn't going to do what we need if the struct is packed. For example (without further constraints), each of those seven mubi4_t elements is going to be have an invalid encoding with probability 14/16. This might be worked around. Indeed, I see that flash_ctrl_error_mp_vseq has explicit constraints for the regions, that will force the fields to take named enum values. But it's probably more sensible to default to more guessable behaviour. As well as flash_ctrl_error_mp_vseq, this commit makes the same change to: - flash_bank_mp_info_page_cfg_t (another 7 mubi values, with the same analysis). - flash_op_t (contains several enums and gets confusingly randomised in several places, which is why I noticed this in the first place) - rd_cache_t (contains an enum variable) It turns out that removing "packed" isn't quite enough. The biggest reason is that there were quite a few "solve before" lines that aren't actually allowed if you have something more interesting than a bit vector. Changes needed: - Make the fields of flash_op_t themselves be rand. This is needed because calling my_class.randomise(some_class_variable) doesn't work if some_class_variable is an unpacked struct whose fields aren't explicitly marked rand. - This is also needed in flash_mp_region_cfg_t and flash_bank_mp_info_page_cfg_t. For some reason, *that* isn't visible at compile time, but you end up with a runtime error where something is randomised with X values (not allowed by the spec!) and the root cause is that we're not actually randomising e.g. a region config struct, so it gets its initial value (of X). - Rephrase lots of rules of the form "solve xyz before flash_op" to things like "solve xyz before flash_op.addr". This is because the SystemVerilog spec doesn't allow anything except an integer in as a thing to be solved before/after. I think the DV engineer just has to pretend to be a compiler. Sigh... - Remove some ordering constraints of the form "solve en_mp_regions before mp_regions". This is definitely not allowed (because mp_regions is an array of unpacked structs, so not a bit vector). I'm not completely convinced we care but, if we do, my proposal would be to randomise the items of the vector explicitly as we get to them ("late randomisation"). The code ends up simpler, I think. - Fix flat-out bogus syntax in flash_ctrl_invalid_op_vseq.sv. Antonio and I have fixed the same error in quite a few places in the past. In this case, it came from commit 9b01461 in 2022. Signed-off-by: Rupert Swarbrick <[email protected]>
1 parent e68ebfe commit a8bbca8

File tree

45 files changed

+122
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+122
-167
lines changed

hw/ip_templates/flash_ctrl/dv/env/flash_ctrl_env_pkg.sv

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -269,26 +269,26 @@ package flash_ctrl_env_pkg;
269269
NumReadTask = 2
270270
} read_task_e;
271271

272-
typedef struct packed {
273-
mubi4_t en; // enable this region
274-
mubi4_t read_en; // enable reads
275-
mubi4_t program_en; // enable write
276-
mubi4_t erase_en; // enable erase
277-
mubi4_t scramble_en; // enable scramble
278-
mubi4_t ecc_en; // enable ecc
279-
mubi4_t he_en; // enable high endurance
280-
uint num_pages; // 0:NumPages % start_page
281-
uint start_page; // 0:NumPages-1
272+
typedef struct {
273+
rand mubi4_t en; // enable this region
274+
rand mubi4_t read_en; // enable reads
275+
rand mubi4_t program_en; // enable write
276+
rand mubi4_t erase_en; // enable erase
277+
rand mubi4_t scramble_en; // enable scramble
278+
rand mubi4_t ecc_en; // enable ecc
279+
rand mubi4_t he_en; // enable high endurance
280+
rand uint num_pages; // 0:NumPages % start_page
281+
rand uint start_page; // 0:NumPages-1
282282
} flash_mp_region_cfg_t;
283283

284-
typedef struct packed {
285-
mubi4_t en; // enable this page
286-
mubi4_t read_en; // enable reads
287-
mubi4_t program_en; // enable write
288-
mubi4_t erase_en; // enable erase
289-
mubi4_t scramble_en; // enable scramble
290-
mubi4_t ecc_en; // enable ecc
291-
mubi4_t he_en; // enable high endurance
284+
typedef struct {
285+
rand mubi4_t en; // enable this page
286+
rand mubi4_t read_en; // enable reads
287+
rand mubi4_t program_en; // enable write
288+
rand mubi4_t erase_en; // enable erase
289+
rand mubi4_t scramble_en; // enable scramble
290+
rand mubi4_t ecc_en; // enable ecc
291+
rand mubi4_t he_en; // enable high endurance
292292
} flash_bank_mp_info_page_cfg_t;
293293

294294
// 2-states flash data type
@@ -307,20 +307,20 @@ package flash_ctrl_env_pkg;
307307
// Otf address in a bank.
308308
typedef bit [flash_ctrl_top_specific_pkg::BusAddrByteW-FlashBankWidth-1 : 0] otf_addr_t;
309309

310-
typedef struct packed {
311-
flash_dv_part_e partition; // data or one of the info partitions
312-
flash_erase_e erase_type; // erase page or the whole bank
313-
flash_op_e op; // read / program or erase
314-
flash_prog_sel_e prog_sel; // program select: normal or repair
315-
uint num_words; // number of words to read or program (TL_DW)
316-
addr_t addr; // starting addr for the op
310+
typedef struct {
311+
rand flash_dv_part_e partition; // data or one of the info partitions
312+
rand flash_erase_e erase_type; // erase page or the whole bank
313+
rand flash_op_e op; // read / program or erase
314+
rand flash_prog_sel_e prog_sel; // program select: normal or repair
315+
rand uint num_words; // number of words to read or program (TL_DW)
316+
rand addr_t addr; // starting addr for the op
317317
// address for the ctrl interface per bank, 18:0
318-
bit [flash_ctrl_top_specific_pkg::BusAddrByteW-2:0] otf_addr;
318+
rand bit [flash_ctrl_top_specific_pkg::BusAddrByteW-2:0] otf_addr;
319319
} flash_op_t;
320320

321321
// Address combined with region
322322
// Need for error injection.
323-
typedef struct packed {
323+
typedef struct {
324324
bit bank;
325325
addr_t addr;
326326
flash_dv_part_e part;

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_basic_rw_vseq.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class flash_ctrl_basic_rw_vseq extends flash_ctrl_base_vseq;
3232

3333
// Constraint for controller address to be in relevant range for the selected partition.
3434
constraint addr_c {
35-
solve bank before flash_op;
35+
solve bank before flash_op.addr;
3636
flash_op.addr inside {[BytesPerBank * bank : BytesPerBank * (bank + 1)]};
3737
flash_op.addr[2:0] == '0;
3838
}
@@ -52,7 +52,7 @@ class flash_ctrl_basic_rw_vseq extends flash_ctrl_base_vseq;
5252

5353
// Flash ctrl operation data queue - used for programming or reading the flash.
5454
constraint flash_op_data_c {
55-
solve flash_op before flash_op_data;
55+
solve flash_op.num_words before flash_op_data;
5656

5757
flash_op_data.size() == flash_op.num_words;
5858
}

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_erase_suspend_vseq.sv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ class flash_ctrl_erase_suspend_vseq extends flash_ctrl_base_vseq;
7171
rand flash_mp_region_cfg_t mp_regions[flash_ctrl_top_specific_pkg::MpRegions];
7272

7373
constraint mp_regions_c {
74-
solve en_mp_regions before mp_regions;
75-
7674
foreach (mp_regions[i]) {
7775
mp_regions[i].en == mubi4_bool_to_mubi(en_mp_regions[i]);
7876

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_error_mp_vseq.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class flash_ctrl_error_mp_vseq extends flash_ctrl_base_vseq;
4545
// Constraint for controller address to be in the relevant range for
4646
// the selected partition.
4747
constraint addr_c {
48-
solve bank before flash_op;
48+
solve bank before flash_op.partition, flash_op.addr;
4949
flash_op.addr inside {[BytesPerBank * bank : BytesPerBank * (bank + 1)]};
5050
if (flash_op.partition != FlashPartData) {
5151
flash_op.addr inside
@@ -93,7 +93,7 @@ class flash_ctrl_error_mp_vseq extends flash_ctrl_base_vseq;
9393

9494
// Flash ctrl operation data queue - used for programming or reading the flash.
9595
constraint flash_op_data_c {
96-
solve flash_op before flash_op_data;
96+
solve flash_op.num_words before flash_op_data;
9797
if (flash_op.op inside {flash_ctrl_top_specific_pkg::FlashOpRead,
9898
flash_ctrl_top_specific_pkg::FlashOpProgram}) {
9999
flash_op_data.size() == flash_op.num_words;

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_error_prog_type_vseq.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class flash_ctrl_error_prog_type_vseq extends flash_ctrl_base_vseq;
4141

4242
// Constraint for controller address to be in relevant range the for the selected partition.
4343
constraint addr_c {
44-
solve bank before flash_op;
44+
solve bank before flash_op.addr;
4545
flash_op.addr inside {[BytesPerBank * bank : BytesPerBank * (bank + 1)]};
4646
}
4747

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_fetch_code_vseq.sv

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class flash_ctrl_fetch_code_vseq extends flash_ctrl_base_vseq;
5252

5353
// Constraint for controller address to be in relevant range for the selected partition.
5454
constraint addr_c {
55-
solve bank before flash_op;
55+
solve bank before flash_op.partition;
5656
flash_op.addr inside {[BytesPerBank * bank : BytesPerBank * (bank + 1)]};
5757
if (flash_op.partition != FlashPartData) {
5858
flash_op.addr inside
@@ -97,7 +97,7 @@ class flash_ctrl_fetch_code_vseq extends flash_ctrl_base_vseq;
9797

9898
// Flash ctrl operation data queue - used for programming or reading the flash.
9999
constraint flash_op_data_c {
100-
solve flash_op before flash_op_data;
100+
solve flash_op.op, flash_op.num_words before flash_op_data;
101101
if (flash_op.op inside {
102102
flash_ctrl_top_specific_pkg::FlashOpRead, flash_ctrl_top_specific_pkg::FlashOpProgram}) {
103103
flash_op_data.size() == flash_op.num_words;
@@ -115,8 +115,6 @@ class flash_ctrl_fetch_code_vseq extends flash_ctrl_base_vseq;
115115
rand flash_mp_region_cfg_t mp_regions[flash_ctrl_top_specific_pkg::MpRegions];
116116

117117
constraint mp_regions_c {
118-
solve en_mp_regions before mp_regions;
119-
120118
foreach (mp_regions[i]) {
121119
mp_regions[i].en == mubi4_bool_to_mubi(en_mp_regions[i]);
122120
mp_regions[i].read_en == MuBi4True;

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_host_dir_rd_vseq.sv

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class flash_ctrl_host_dir_rd_vseq extends flash_ctrl_fetch_code_vseq;
2929

3030
// Constraint address to be in relevant range for the selected partition.
3131
constraint addr_c {
32-
solve bank before flash_op;
32+
solve bank before flash_op.addr;
3333
flash_op.addr inside {[BytesPerBank * bank : BytesPerBank * (bank + 1) - BytesPerBank / 2]};
3434
}
3535

@@ -45,8 +45,6 @@ class flash_ctrl_host_dir_rd_vseq extends flash_ctrl_fetch_code_vseq;
4545
data_t flash_rd_one_data;
4646

4747
constraint mp_regions_c {
48-
solve en_mp_regions before mp_regions;
49-
5048
foreach (mp_regions[i]) {
5149
mp_regions[i].en == mubi4_bool_to_mubi(en_mp_regions[i]);
5250

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_invalid_op_vseq.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class flash_ctrl_invalid_op_vseq extends flash_ctrl_base_vseq;
2929
bit expect_alert;
3030

3131
constraint flash_op_data_c {
32-
solve flash_op before flash_op_data;
32+
solve flash_op.num_words before flash_op_data;
3333
flash_op_data.size() == flash_op.num_words;
3434
}
3535

@@ -74,7 +74,7 @@ class flash_ctrl_invalid_op_vseq extends flash_ctrl_base_vseq;
7474
constraint mp_info_pages_c {
7575
foreach (mp_info_pages[i, j]) {
7676
mp_info_pages[i][j].size() == flash_ctrl_top_specific_pkg::InfoTypeSize[j];
77-
foreach (mp_info_pages[i][j][k]) {
77+
foreach (mp_info_pages[i, j, k]) {
7878
mp_info_pages[i][j][k].en == MuBi4True;
7979
mp_info_pages[i][j][k].read_en == MuBi4True;
8080
mp_info_pages[i][j][k].program_en == MuBi4True;

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_legacy_base_vseq.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class flash_ctrl_legacy_base_vseq extends flash_ctrl_otf_base_vseq;
1111

1212
constraint rand_op_c {
1313
solve fractions before rand_op.addr;
14-
solve flash_program_data before rand_op;
14+
solve flash_program_data before rand_op.partition, rand_op.addr;
1515
solve rand_op.partition before rand_op.prog_sel, rand_op.addr;
1616
solve rand_op.addr before rand_op.otf_addr;
1717
solve rand_op.addr before rand_op.num_words;

hw/ip_templates/flash_ctrl/dv/env/seq_lib/flash_ctrl_mid_op_rst_vseq.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class flash_ctrl_mid_op_rst_vseq extends flash_ctrl_base_vseq;
5050
}
5151

5252
constraint flash_op_data_c {
53-
solve flash_op before flash_op_data;
53+
solve flash_op.num_words before flash_op_data;
5454
flash_op_data.size() == flash_op.num_words;
5555
}
5656

0 commit comments

Comments
 (0)