OpenCores
URL https://opencores.org/ocsvn/openhmc/openhmc/trunk

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [sim/] [tb/] [common/] [src/] [bfm_2_hmc_monitor.sv] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 juko
/*
2
 *                              .--------------. .----------------. .------------.
3
 *                             | .------------. | .--------------. | .----------. |
4
 *                             | | ____  ____ | | | ____    ____ | | |   ______ | |
5
 *                             | ||_   ||   _|| | ||_   \  /   _|| | | .' ___  || |
6
 *       ___  _ __   ___ _ __  | |  | |__| |  | | |  |   \/   |  | | |/ .'   \_|| |
7
 *      / _ \| '_ \ / _ \ '_ \ | |  |  __  |  | | |  | |\  /| |  | | || |       | |
8
 *       (_) | |_) |  __/ | | || | _| |  | |_ | | | _| |_\/_| |_ | | |\ `.___.'\| |
9
 *      \___/| .__/ \___|_| |_|| ||____||____|| | ||_____||_____|| | | `._____.'| |
10
 *           | |               | |            | | |              | | |          | |
11
 *           |_|               | '------------' | '--------------' | '----------' |
12
 *                              '--------------' '----------------' '------------'
13
 *
14
 *  openHMC - An Open Source Hybrid Memory Cube Controller
15
 *  (C) Copyright 2014 Computer Architecture Group - University of Heidelberg
16
 *  www.ziti.uni-heidelberg.de
17
 *  B6, 26
18
 *  68159 Mannheim
19
 *  Germany
20
 *
21
 *  Contact: openhmc@ziti.uni-heidelberg.de
22
 *  http://ra.ziti.uni-heidelberg.de/openhmc
23
 *
24
 *   This source file is free software: you can redistribute it and/or modify
25
 *   it under the terms of the GNU Lesser General Public License as published by
26
 *   the Free Software Foundation, either version 3 of the License, or
27
 *   (at your option) any later version.
28
 *
29
 *   This source file is distributed in the hope that it will be useful,
30
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 *   GNU Lesser General Public License for more details.
33
 *
34
 *   You should have received a copy of the GNU Lesser General Public License
35
 *   along with this source file.  If not, see .
36
 *
37
 *
38
 */
39
 
40
`ifndef BFM_2_HMC
41
`define BFM_2_HMC
42
class bfm_2_hmc_mon extends hmc_module_mon;
43
 
44
        typedef enum {
45
         LENGTH_ERROR,
46
         CRC_ERROR,
47
         SEQ_ERROR,
48
         POISON
49
        }error_class_e;
50
 
51
        mailbox#(cls_pkt) in_mb;
52
        cls_pkt pkt;
53
 
54
        bit [2:0] seq_number = 0;
55
 
56
        bit bitstream[];
57
 
58
        int phit_size = 64;
59
        bit [64:0] header;      //-- phit size
60
        bit [64:0] tail  ;      //-- phit size
61
        int data_phit_count;
62
 
63
        int flit_size = 128;
64
 
65
        bit error_abort_mode = 0;
66
        int irtry_cnt = 0;
67
 
68
        int irtry = 0;
69
 
70
 
71
        hmc_link_config link_cfg;
72
 
73
        error_class_e current_error;
74
        hmc_command_encoding current_command;
75
 
76
 
77
        int lng_error = 0;
78
        int crc_error = 0;
79
        int seq_error = 0;
80
        int poisoned_pkt =0;
81
 
82
        int rsp_rcvd = 0;
83
        int err_rsp_rcvd = 0;
84
        int req_rcvd = 0;
85
 
86
        hmc_link_config hmc_link_cfg;
87
 
88
        `uvm_component_utils_begin(bfm_2_hmc_mon)
89
                `uvm_field_object(link_cfg, UVM_DEFAULT)
90
        `uvm_component_utils_end
91
                covergroup hmc_pkt_error_cg;
92
                option.per_instance = 1;
93
                ERROR_TYPE: coverpoint current_error;
94
 
95
                HMC_COMMAND: coverpoint current_command {
96
                        //bins request_commands[] =
97
                        bins flow_types[] = {
98
                                HMC_TRET,
99
                                HMC_PRET,
100
                                HMC_NULL
101
                        };
102
                        bins requests[] = {
103
                                HMC_WRITE_16,
104
                                HMC_WRITE_32,
105
                                HMC_WRITE_48,
106
                                HMC_WRITE_64,
107
                                HMC_WRITE_80,
108
                                HMC_WRITE_96,
109
                                HMC_WRITE_112,
110
                                HMC_WRITE_128,
111
 
112
                                HMC_MODE_WRITE,
113
                                HMC_BIT_WRITE,
114
                                HMC_DUAL_8B_ADDI,
115
                                HMC_SINGLE_16B_ADDI,
116
 
117
                                HMC_POSTED_WRITE_16,
118
                                HMC_POSTED_WRITE_32,
119
                                HMC_POSTED_WRITE_48,
120
                                HMC_POSTED_WRITE_64,
121
                                HMC_POSTED_WRITE_80,
122
                                HMC_POSTED_WRITE_96,
123
                                HMC_POSTED_WRITE_112,
124
                                HMC_POSTED_WRITE_128,
125
                                HMC_POSTED_BIT_WRIT,
126
 
127
                                HMC_POSTED_BIT_WRIT,
128
                                HMC_POSTED_DUAL_8B_ADDI,
129
                                HMC_POSTED_SINGLE_16B_ADDI,
130
 
131
                                HMC_MODE_READ,
132
                                HMC_READ_16,
133
                                HMC_READ_32,
134
                                HMC_READ_48,
135
                                HMC_READ_64,
136
                                HMC_READ_80,
137
                                HMC_READ_96,
138
                                HMC_READ_112,
139
                                HMC_READ_128};
140
 
141
                        bins response[] = {
142
                                HMC_READ_RESPONSE,
143
                                HMC_WRITE_RESPONSE,
144
                                HMC_MODE_READ_RESPONSE,
145
                                HMC_MODE_WRITE_RESPONSE,
146
                                HMC_ERROR_RESPONSE
147
                        };
148
 
149
                        illegal_bins n_used = default;
150
                }
151
                CROSS_ERROR_TYPPE_COMMAND : cross ERROR_TYPE, HMC_COMMAND;
152
 
153
        endgroup
154
 
155
        function new ( string name="bfm_2_hmc_mon", uvm_component parent );
156
                super.new(name, parent);
157
                hmc_pkt_cg = new();
158
                hmc_pkt_error_cg = new();
159
        endfunction : new
160
 
161
        function void build_phase(uvm_phase phase);
162
                super.build_phase(phase);
163
 
164
                if (!uvm_config_db#(hmc_link_config)::get(this, "", "link_cfg", link_cfg)) begin
165
                        uvm_report_fatal(get_type_name(), $psprintf("hmc_link_config not set via config_db"));
166
                end
167
        endfunction : build_phase
168
 
169
        task run();
170
                cls_pkt old_pkt;
171
                `uvm_info(get_type_name(),$psprintf("starting BFM_2_HMC converter"), UVM_MEDIUM)
172
                forever begin
173
                        //mb_pkt.get(pkt);
174
                        old_pkt = pkt;
175
                        in_mb.peek(pkt);
176
                        if (pkt != old_pkt)
177
                                extract_hmc_pkt(pkt);
178
                        else
179
                                #5;
180
                end
181
 
182
        endtask
183
 
184
        task extract_hmc_pkt(cls_pkt pkt);
185
                header                          = pkt.get_header();
186
                tail                            = pkt.get_tail();
187
                data_phit_count         = pkt.data.size(); //-- 7 flits->14 phits --> 14-2 =12 data_phits
188
 
189
                bitstream                       = new [2*phit_size + data_phit_count*phit_size];
190
 
191
                //-- generate Bitstream
192
 
193
                if (header !=64'b0) begin
194
 
195
                        //-- check length
196
                        if( (header[10:7] != header[14:11]) || (header[10:7] != 1+data_phit_count /2)) begin
197
                                lng_error ++;
198
                                error_abort_mode = 1;
199
                                `uvm_info(get_type_name(),$psprintf("Set error abort mode: LNG/DLN ERROR, Command with header: %h", header), UVM_NONE)
200
                                irtry_cnt = 0;
201
 
202
 
203
                                current_error = LENGTH_ERROR;
204
                                current_command[5:0] = header[5:0];
205
                                hmc_pkt_error_cg.sample();
206
                        end else begin
207
 
208
                                //-- convert the cls_pkt pkt to hmc_packet packet
209
                                cls_pkt_to_hmc_packet(pkt);
210
 
211
                                //-- check crc error
212
                                check_crc_error(packet);
213
 
214
 
215
                                //-- wait for irtry
216
                                if (error_abort_mode)
217
                                        clear_error_abort_mode();
218
 
219
                                else begin
220
 
221
                                        //-- count Start Error Mode IRTRY
222
                                        if (packet.start_retry) begin
223
                                                irtry++;
224
                                                `uvm_info(get_type_name(),$psprintf("Start Retry: %0d", irtry), UVM_HIGH)
225
                                        end
226
 
227
                                        //-- packet sequence check
228
                                        if ((packet.command == HMC_TRET) || (packet.get_command_type() != HMC_FLOW_TYPE))  begin
229
                                                irtry = 0; //-- reset start retry mode counter
230
 
231
                                                if (packet.sequence_number != seq_number+1'b1) begin
232
                                                        seq_error ++;
233
                                                        error_abort_mode = 1;
234
                                                        `uvm_info(get_type_name(),$psprintf("Set error abort mode: SEQ ERROR, Command: %s", packet.command.name()), UVM_NONE)
235
                                                        irtry_cnt = 0;
236
 
237
 
238
                                                        //-- sample seq error
239
                                                        current_error = SEQ_ERROR;
240
                                                        current_command = packet.command;
241
                                                        hmc_pkt_error_cg.sample();
242
 
243
                                                end else begin
244
 
245
                                                        seq_number = packet.sequence_number;
246
 
247
                                                        //-- check if poisoned
248
                                                        if ( packet.poisoned) begin
249
                                                                poisoned_pkt++;
250
 
251
                                                                //-- sample poison
252
                                                                current_error = POISON;
253
                                                                current_command = packet.command;
254
                                                                hmc_pkt_error_cg.sample();
255
                                                        end else
256
                                                                if((packet.get_command_type() != HMC_FLOW_TYPE))
257
                                                                        write_packet(packet);
258
                                                end
259
                                        end
260
                                end
261
                        end
262
                end
263
 
264
        endtask : extract_hmc_pkt
265
 
266
 
267
 
268
        function void check_crc_error(hmc_packet packet);
269
                if (packet.crc_error) begin
270
                        crc_error++;
271
                        error_abort_mode = 1;
272
                        `uvm_info(get_type_name(),$psprintf("Set error abort mode: CRC ERROR, Command: %s", packet.command.name()), UVM_NONE)
273
                        irtry_cnt = 0;
274
 
275
                        current_error = CRC_ERROR;
276
                        current_command = packet.command;
277
                        hmc_pkt_error_cg.sample();
278
                end
279
        endfunction : check_crc_error
280
 
281
        function void clear_error_abort_mode();
282
                if ((packet.clear_error_abort)) begin
283
                        `uvm_info(get_type_name(), $psprintf("Clear Error Abort Mode: %0d",irtry_cnt ), UVM_HIGH)
284
                        irtry_cnt ++;
285
                end else begin
286
                        irtry_cnt = 0;                                                  //-- reset counter
287
                end
288
 
289
                if (irtry_cnt >= link_cfg.cfg_init_retry_rxcnt) begin                   //-- test threshold
290
                        error_abort_mode = 0;
291
                        `uvm_info(get_type_name(), $psprintf("Clear Error Abort Mode" ), UVM_NONE)
292
                end
293
        endfunction : clear_error_abort_mode
294
 
295
 
296
        function void cls_pkt_to_hmc_packet (cls_pkt pkt);
297
                //-- Convert the CLS_PKT to HMC_PKT
298
                                for (int b = 0; b < 64; b++) begin                                                              //-- read header to bitmap
299
                                        bitstream[b]=header[b];
300
                                end
301
 
302
                                if (data_phit_count > 0)
303
                                        for (int phit = 0; phit < data_phit_count; phit++)                      //-- read data to bitmap
304
                                                for (int b = 0; b < phit_size; b++)
305
                                                        bitstream[(phit + 1) * phit_size + b] = pkt.data[phit][b];
306
 
307
                                for (int b = 0; b < 64; b++) begin                                                              //-- read tail to bitmap
308
                                        bitstream[(data_phit_count+1)*phit_size+b]=tail[b];
309
                                end
310
 
311
                                //-- create hmc packet
312
                                `uvm_info(get_type_name(),$psprintf("Got a BFM Packet:  %s",pkt.convert2string()), UVM_HIGH)
313
                                packet = hmc_packet::type_id::create("packet", this);
314
                                void'(packet.unpack(bitstream));
315
 
316
        endfunction     :       cls_pkt_to_hmc_packet
317
 
318
        task write_packet(hmc_packet packet);
319
 
320
                if(packet.get_command_type() == HMC_RESPONSE_TYPE)begin
321
                        if(packet.command != HMC_ERROR_RESPONSE) begin
322
                                `uvm_info(get_type_name(),$psprintf("Rsp #%0d : %s",rsp_rcvd, packet.command.name()), UVM_HIGH)
323
                                `uvm_info(get_type_name(),$psprintf("Rsp #%0d : %s",rsp_rcvd, packet.sprint()), UVM_HIGH)
324
                                rsp_rcvd++;
325
                        end else begin
326
                                `uvm_info(get_type_name(),$psprintf("Err Rsp %0d : %s with error code %b",err_rsp_rcvd, packet.command.name(), packet.error_status), UVM_HIGH)
327
                                err_rsp_rcvd++;
328
                        end
329
                end else begin
330
                        `uvm_info(get_type_name(),$psprintf("Req %0d : %s",req_rcvd, packet.command.name()), UVM_HIGH)
331
                        req_rcvd++;
332
                end
333
 
334
 
335
                hmc_pkt_cg.sample();
336
 
337
                item_collected_port.write(packet);
338
 
339
        endtask : write_packet
340
 
341
 
342
        function void report_phase(uvm_phase phase);
343
                `uvm_info(get_type_name(),$psprintf("LNG error count  %0d", lng_error),         UVM_NONE)
344
                `uvm_info(get_type_name(),$psprintf("CRC error count  %0d", crc_error),         UVM_NONE)
345
                `uvm_info(get_type_name(),$psprintf("SEQ error count  %0d", seq_error),         UVM_NONE)
346
                `uvm_info(get_type_name(),$psprintf("poisoned packets %0d", poisoned_pkt),      UVM_NONE)
347
        endfunction : report_phase
348
 
349
endclass
350
 
351
 
352
`endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.