Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / verilog / mem / fbdimm / design / sb_crc_error_injector.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: sb_crc_error_injector.v
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35module sb_crc_error_injector( ps_in, ps_out, init, is_bar, link_clk);
36 parameter SB_LINK=10;
37 parameter DS=0;
38
39 input [SB_LINK-1:0] ps_in;
40 output [SB_LINK-1:0] ps_out;
41 input init;
42 input link_clk;
43 input is_bar;
44
45 reg [9:0] ps0_crc_mask;
46 reg [9:0] ps1_crc_mask;
47 reg [9:0] ps2_crc_mask;
48 reg [9:0] ps3_crc_mask;
49 reg [9:0] ps4_crc_mask;
50 reg [9:0] ps5_crc_mask;
51 reg [9:0] ps6_crc_mask;
52 reg [9:0] ps7_crc_mask;
53 reg [9:0] ps8_crc_mask;
54 reg [9:0] ps9_crc_mask;
55 reg [9:0] ps10_crc_mask;
56 reg [9:0] ps11_crc_mask;
57 reg [11:0] ps_frame_num;
58 reg [3:0] tr_counter;
59 reg [11:0] ps_crc_freq;
60 reg [11:0] ps_crc_period;
61 reg crc_en;
62 reg [15:0] frame_counter;
63 wire [15:0] crc_clock_period = (ps_crc_freq+ps_crc_period)*6;
64 reg header_detected,enable_fsm;
65 reg [3:0] fsr_counter,lock_counter,prev_counter;
66 reg [3:0] fsr_counter2,lock_counter2;
67
68reg [6:0] nop_cnt;
69reg dummy;
70wire frm_begin,frm_boundary;
71wire tr_complete;
72reg bypass_init;
73
74reg [3:0] UI_counter;
75reg start_UI_counter;
76
77assign ps_out = ( UI_counter == 4'h1 ) & crc_en ? ( ps_in ^ ps0_crc_mask ) :
78 ( UI_counter == 4'h2 ) & crc_en ? ( ps_in ^ ps1_crc_mask ) :
79 ( UI_counter == 4'h3 ) & crc_en ? ( ps_in ^ ps2_crc_mask ) :
80 ( UI_counter == 4'h4 ) & crc_en ? ( ps_in ^ ps3_crc_mask ) :
81 ( UI_counter == 4'h5 ) & crc_en ? ( ps_in ^ ps4_crc_mask ) :
82 ( UI_counter == 4'h6 ) & crc_en ? ( ps_in ^ ps5_crc_mask ) :
83 ( UI_counter == 4'h7 ) & crc_en ? ( ps_in ^ ps6_crc_mask ) :
84 ( UI_counter == 4'h8 ) & crc_en ? ( ps_in ^ ps7_crc_mask ) :
85 ( UI_counter == 4'h9 ) & crc_en ? ( ps_in ^ ps8_crc_mask ) :
86 ( UI_counter == 4'ha ) & crc_en ? ( ps_in ^ ps9_crc_mask ) :
87 ( UI_counter == 4'hb ) & crc_en ? ( ps_in ^ ps10_crc_mask ) :
88 ( UI_counter == 4'hc ) & crc_en ? ( ps_in ^ ps11_crc_mask ) : ps_in;
89
90
91always@(negedge link_clk)
92 if ( header_detected )
93 start_UI_counter <= 1;
94
95always@(posedge link_clk) if ( start_UI_counter )
96begin
97 if ( UI_counter == 4'hc )
98 UI_counter <= 4'h1;
99 else
100 UI_counter <= UI_counter + 4'h1;
101
102end
103
104initial begin
105tr_counter = 1;
106start_UI_counter=0;
107UI_counter=4'h1;
108ps0_crc_mask=0;
109ps1_crc_mask=0;
110ps2_crc_mask=0;
111ps3_crc_mask=0;
112ps4_crc_mask=0;
113ps5_crc_mask=0;
114ps6_crc_mask=0;
115ps7_crc_mask=0;
116ps8_crc_mask=0;
117ps9_crc_mask=0;
118ps10_crc_mask=0;
119ps11_crc_mask=0;
120crc_en= 0;
121ps_crc_freq=0;
122ps_frame_num=0;
123ps_crc_period=0;
124frame_counter=0;
125 if ( $test$plusargs("bypass_init") ) begin
126 lock_counter = 4'hc;
127 bypass_init = 1;
128 end
129 else
130 bypass_init = 0;
131
132lock_counter2=4'h1;
133
134`ifdef AXIS_FBDIMM_HW
135`else
136dummy=$value$plusargs("ps0_crc_mask=%h",ps0_crc_mask);
137dummy=$value$plusargs("ps1_crc_mask=%h",ps1_crc_mask);
138dummy=$value$plusargs("ps2_crc_mask=%h",ps2_crc_mask);
139dummy=$value$plusargs("ps3_crc_mask=%h",ps3_crc_mask);
140dummy=$value$plusargs("ps4_crc_mask=%h",ps4_crc_mask);
141dummy=$value$plusargs("ps5_crc_mask=%h",ps5_crc_mask);
142dummy=$value$plusargs("ps6_crc_mask=%h",ps6_crc_mask);
143dummy=$value$plusargs("ps7_crc_mask=%h",ps7_crc_mask);
144dummy=$value$plusargs("ps8_crc_mask=%h",ps8_crc_mask);
145dummy=$value$plusargs("ps9_crc_mask=%h",ps9_crc_mask);
146dummy=$value$plusargs("ps10_crc_mask=%h",ps10_crc_mask);
147dummy=$value$plusargs("ps11_crc_mask=%h",ps11_crc_mask);
148dummy=$value$plusargs("ps_frame_num=%h",ps_frame_num);
149dummy=$value$plusargs("ps_crc_freq=%h",ps_crc_freq);
150dummy=$value$plusargs("ps_crc_period=%h",ps_crc_period);
151`endif
152
153end
154
155reg [47:0] initialization_register_link0;
156
157initial fsr_counter=4'h7;
158initial fsr_counter2=4'hd;
159
160always@(posedge link_clk)
161begin
162 if ( fsr_counter == 4'h1 )
163 fsr_counter = 4'h6;
164 else
165 fsr_counter = fsr_counter - 1;
166
167 if ( fsr_counter2 == 4'h1 )
168 fsr_counter2 = 4'hc;
169 else
170 fsr_counter2 = fsr_counter2 - 1;
171
172end
173
174assign frm_begin = ( fsr_counter2 == lock_counter2 );
175assign frm_boundary = (fsr_counter2 == lock_counter);
176
177always@(negedge link_clk) if ( ~bypass_init )
178begin
179
180 if (header_detected )
181 lock_counter <= prev_counter;
182 else
183 prev_counter <= fsr_counter2;
184
185end
186
187
188
189reg [9:0] ps0_reg,ps1_reg,ps2_reg,ps3_reg,ps4_reg,ps5_reg,ps6_reg,ps7_reg,ps8_reg,ps9_reg,ps10_reg,ps11_reg;
190
191always@(negedge link_clk)
192begin
193 ps0_reg <= ps1_reg;
194 ps1_reg <= ps2_reg;
195 ps2_reg <= ps3_reg;
196 ps3_reg <= ps4_reg;
197 ps4_reg <= ps5_reg;
198 ps5_reg <= ps6_reg;
199 ps6_reg <= ps7_reg;
200 ps7_reg <= ps8_reg;
201 ps8_reg <= ps9_reg;
202 ps9_reg <= ps10_reg;
203 ps10_reg <= ps11_reg;
204 ps11_reg <= ps_in ;
205
206end
207
208
209always@(posedge link_clk) if ( ~bypass_init )
210begin
211 if( is_bar == 1'b0)
212 begin
213 if ( (ps0_reg == 10'h3ff ) &&
214 (ps1_reg == 10'h0 ) &&
215 (ps2_reg == 10'h3ff ) &&
216 (ps3_reg == 10'h3ff ) &&
217 (ps4_reg == 10'h3ff ) &&
218 (ps5_reg == 10'h3ff ) &&
219 (ps6_reg == 10'h3ff ) &&
220 (ps7_reg == 10'h3ff ) &&
221 (ps8_reg == 10'h3ff ) &&
222 (ps9_reg == 10'h3ff ) &&
223 (ps10_reg == 10'h3ff ) &&
224 (ps11_reg == 10'h0 ) )
225 begin
226 lock_counter2 <= fsr_counter2;
227 end
228 end
229 else if(is_bar == 1'b1)
230 begin
231 if( (ps0_reg == 10'h0 ) &&
232 (ps1_reg == 10'h3ff) &&
233 ( ps2_reg == 10'h0) &&
234 ( ps3_reg == 10'h0) &&
235 ( ps4_reg == 10'h0) &&
236 ( ps5_reg == 10'h0) &&
237 ( ps6_reg == 10'h0) &&
238 ( ps7_reg == 10'h0) &&
239 ( ps8_reg == 10'h0) &&
240 ( ps9_reg == 10'h0) &&
241 ( ps10_reg == 10'h0) &&
242 ( ps11_reg == 10'h3ff) )
243 begin
244 lock_counter2 <= fsr_counter2;
245 end
246 end
247
248end
249
250always@(posedge link_clk) if ( ~bypass_init )
251begin
252 if(is_bar == 1'b0) // Not the sb_bar_crc_error_injector
253 begin
254 if ( initialization_register_link0[47:36] == 12'hbfe )
255 header_detected<=1;
256 else
257 header_detected<=0;
258 end
259 else if(is_bar == 1'b1)
260 begin
261 if( initialization_register_link0[47:36] == 12'h401 )
262 header_detected <= 1;
263 else
264 header_detected <= 0;
265 end
266end
267
268always@(negedge link_clk)
269begin
270 initialization_register_link0[47:0] <= { ps_in[0], initialization_register_link0[47:1]};
271end
272
273
274always@(posedge link_clk) if ( ~init && (( ps_frame_num !== 0 ) && (crc_clock_period !== 0 )) )
275begin
276
277
278 if ( frame_counter !== crc_clock_period )
279 begin
280
281 if ( frame_counter < (ps_crc_freq*12) )
282 crc_en <= 1;
283 else
284 crc_en <= 0;
285
286 frame_counter=frame_counter+1;
287
288 end if ( frame_counter == crc_clock_period )
289 frame_counter = 0;
290
291
292
293 if ( tr_counter == 4'hc ) begin
294 tr_counter=1;
295
296 // If ps_frame_num is FFF, then all frames will have the same crc
297 if ( ps_frame_num == 12'hfff ) begin
298 crc_en <= 1;
299 end
300 // If ps_frame_num is non-zero, N number of frames will have crc errors
301 // then crc will be turned off
302 else if ( ps_frame_num !== 0 ) begin
303 crc_en <= 1;
304 ps_frame_num = ps_frame_num - 1;
305 end
306 else
307 crc_en <= 0;
308
309 end
310 else
311 tr_counter=tr_counter+1;
312
313end
314else
315 crc_en <= 0;
316
317endmodule