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 |
|
|
`ifndef HMC_RETRY_BUFFER_SV
|
40 |
|
|
`define HMC_RETRY_BUFFER_SV
|
41 |
|
|
|
42 |
|
|
class hmc_retry_buffer extends uvm_component;
|
43 |
|
|
|
44 |
|
|
hmc_packet retry_buffer[$];
|
45 |
|
|
hmc_packet retry_packets[$];
|
46 |
|
|
|
47 |
|
|
int retry_pos = 0;
|
48 |
|
|
|
49 |
|
|
bit [7:0] last_rrp = 8'h0;
|
50 |
|
|
bit [7:0] retry_pointer_head = 8'h0;
|
51 |
|
|
bit [7:0] retry_pointer_next = 8'h0;
|
52 |
|
|
bit retry_in_progress = 0;
|
53 |
|
|
int buffer_usage = 0;
|
54 |
|
|
|
55 |
|
|
`uvm_analysis_imp_decl(_return_pointer)
|
56 |
|
|
uvm_analysis_imp_return_pointer#(int, hmc_retry_buffer) return_pointer_imp;
|
57 |
|
|
|
58 |
|
|
`uvm_component_utils(hmc_retry_buffer)
|
59 |
|
|
|
60 |
|
|
function new(string name="hmc_retry_buffer", uvm_component parent);
|
61 |
|
|
super.new(name,parent);
|
62 |
|
|
|
63 |
|
|
return_pointer_imp = new ("return_pointer_imp",this);
|
64 |
|
|
retry_pointer_head = 8'h0;
|
65 |
|
|
retry_pointer_next = 8'h0;
|
66 |
|
|
retry_in_progress = 0;
|
67 |
|
|
endfunction : new
|
68 |
|
|
|
69 |
|
|
function void build_phase(uvm_phase phase);
|
70 |
|
|
super.build_phase(phase);
|
71 |
|
|
|
72 |
|
|
endfunction : build_phase
|
73 |
|
|
|
74 |
|
|
function void reset();
|
75 |
|
|
retry_buffer = {};
|
76 |
|
|
retry_packets = {};
|
77 |
|
|
retry_pointer_head = 8'h0;
|
78 |
|
|
retry_pointer_next = 8'h0;
|
79 |
|
|
retry_in_progress = 0;
|
80 |
|
|
endfunction : reset
|
81 |
|
|
|
82 |
|
|
function void write_return_pointer(input int rrp);
|
83 |
|
|
|
84 |
|
|
int index = -1;
|
85 |
|
|
`uvm_info(get_type_name(),$psprintf("write_return_pointer: rrp %0d", rrp), UVM_HIGH)
|
86 |
|
|
|
87 |
|
|
if(last_rrp == rrp)
|
88 |
|
|
return;
|
89 |
|
|
|
90 |
|
|
last_rrp = rrp;
|
91 |
|
|
|
92 |
|
|
for (int i=0; i
|
93 |
|
|
buffer_usage = buffer_usage - retry_buffer[i].packet_length;
|
94 |
|
|
if (retry_buffer[i].forward_retry_pointer == rrp) begin
|
95 |
|
|
index = i;
|
96 |
|
|
break;
|
97 |
|
|
end
|
98 |
|
|
end
|
99 |
|
|
|
100 |
|
|
valid_rrp_found_in_retry_buffer : assert (index!=-1 && index
|
101 |
|
|
|
102 |
|
|
// Delete everything up to the index
|
103 |
|
|
if (retry_buffer.size()-1 == index) begin
|
104 |
|
|
retry_buffer = {};
|
105 |
|
|
end else begin
|
106 |
|
|
retry_buffer = retry_buffer[index+1:$];
|
107 |
|
|
end
|
108 |
|
|
endfunction : write_return_pointer
|
109 |
|
|
|
110 |
|
|
function int add_packet(input hmc_packet pkt);
|
111 |
|
|
hmc_packet copy;
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
bit [8:0] retry_pointer_next_sum = retry_pointer_next + pkt.packet_length;
|
115 |
|
|
|
116 |
|
|
no_add_packet_when_retry_in_progress : assert (retry_in_progress == 0);
|
117 |
|
|
|
118 |
|
|
if(retry_pointer_next_sum[7:0] >= last_rrp && retry_pointer_next_sum[8]) begin
|
119 |
|
|
`uvm_info(get_type_name(),$psprintf("add_packet: Retry Buffer full 1 with last frp %0d", last_rrp), UVM_HIGH)
|
120 |
|
|
return -1;
|
121 |
|
|
end
|
122 |
|
|
|
123 |
|
|
if(retry_pointer_next_sum >= last_rrp && retry_pointer_next < last_rrp) begin
|
124 |
|
|
`uvm_info(get_type_name(),$psprintf("add_packet: Retry Buffer full 2 with last frp %0d", last_rrp), UVM_HIGH)
|
125 |
|
|
return -1;
|
126 |
|
|
end
|
127 |
|
|
retry_pointer_next = retry_pointer_next_sum[7:0];
|
128 |
|
|
pkt.forward_retry_pointer = retry_pointer_next;
|
129 |
|
|
buffer_usage += pkt.packet_length;
|
130 |
|
|
|
131 |
|
|
`uvm_info(get_type_name(),$psprintf("add_packet: %s frp %0d", pkt.command.name(), pkt.forward_retry_pointer), UVM_HIGH)
|
132 |
|
|
|
133 |
|
|
copy = new pkt;
|
134 |
|
|
retry_buffer.push_back(copy);
|
135 |
|
|
return retry_pointer_next;
|
136 |
|
|
endfunction : add_packet
|
137 |
|
|
|
138 |
|
|
function hmc_packet get_retry_packet();
|
139 |
|
|
if (retry_in_progress == 0 && retry_buffer.size() > 0) begin
|
140 |
|
|
retry_in_progress = 1;
|
141 |
|
|
retry_packets = retry_buffer;
|
142 |
|
|
`uvm_info(get_type_name(),$psprintf("get_retry_packet: start retry with %0d packets", retry_buffer.size()), UVM_HIGH)
|
143 |
|
|
retry_pos = 0;
|
144 |
|
|
end
|
145 |
|
|
|
146 |
|
|
if (retry_pos
|
147 |
|
|
retry_pos ++;
|
148 |
|
|
return retry_packets[retry_pos-1];
|
149 |
|
|
end else begin
|
150 |
|
|
retry_in_progress = 0;
|
151 |
|
|
return null;
|
152 |
|
|
end
|
153 |
|
|
endfunction : get_retry_packet
|
154 |
|
|
|
155 |
|
|
function void check_phase(uvm_phase phase);
|
156 |
|
|
no_retry_at_check : assert (retry_in_progress == 0);
|
157 |
|
|
if (retry_buffer.size() > 0) begin
|
158 |
|
|
for (int i=0;i
|
159 |
|
|
`uvm_info(get_type_name(),$psprintf("retry_buffer %0d: %s frp %0d", i, retry_buffer[i].command.name(), retry_buffer[i].forward_retry_pointer), UVM_LOW)
|
160 |
|
|
end
|
161 |
|
|
end
|
162 |
|
|
retry_buffer_empty : assert (retry_buffer.size() == 0);
|
163 |
|
|
endfunction : check_phase
|
164 |
|
|
|
165 |
|
|
function int get_buffer_used();
|
166 |
|
|
return buffer_usage;
|
167 |
|
|
endfunction : get_buffer_used
|
168 |
|
|
|
169 |
|
|
endclass : hmc_retry_buffer
|
170 |
|
|
|
171 |
|
|
`endif // HMC_RETRY_BUFFER_SV
|