Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / niu / rtl / xpcs_rxio_ebuffer_sm.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: xpcs_rxio_ebuffer_sm.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 ============================================
35// ****************************************************************
36//
37// Sun Proprietary/Confidential: Internal Use Only
38//
39// ****************************************************************
40// Design: Vega
41// Block: XPCS Lane-to-lane deskew Interface
42// Author: Carlos Castil
43//
44// Module: xpcs_rxio_ebuffer_sm
45// File: xpcs_rxio_ebuffer_sm.v
46//
47// Description: This block contains the deskew state machine
48// compliant to ieee 802.3ae clause 48 fig 48-8.
49//
50// Revision History
51// ------------------------------------------------------------
52// Ver Date Comments
53// ------------------------------------------------------------
54// 1.0 10/11/02 Created
55//
56// ****************************************************************
57
58
59module xpcs_rxio_ebuffer_sm (
60
61 reset,
62 rx_clk,
63
64 csr_pulse_deskew_error,
65 csr_link_status,
66 sync_status,
67
68 state,
69
70 deskew_init,
71 deskew_done,
72
73 r_byte_0,
74 r_byte_1,
75 r_byte_2,
76 r_byte_3,
77
78 r_special_0,
79 r_special_1,
80 r_special_2,
81 r_special_3,
82
83 r_error_0,
84 r_error_1,
85 r_error_2,
86 r_error_3 );
87
88input reset;
89input rx_clk;
90
91input [7:0] r_byte_0;
92input [7:0] r_byte_1;
93input [7:0] r_byte_2;
94input [7:0] r_byte_3;
95
96input r_special_0;
97input r_special_1;
98input r_special_2;
99input r_special_3;
100
101input r_error_0;
102input r_error_1;
103input r_error_2;
104input r_error_3;
105
106input deskew_done;
107
108input sync_status;
109
110output deskew_init;
111output [7:0] state;
112output csr_link_status;
113output csr_pulse_deskew_error;
114
115parameter DESKEW_LOSS = 8'h00;
116parameter ALIGN_DET1 = 8'h01;
117parameter ALIGN_DET2 = 8'h02;
118parameter ALIGN_DET3 = 8'h04;
119parameter DESKEW_OK = 8'h08;
120parameter ALIGN_ERR1 = 8'h10;
121parameter ALIGN_ERR2 = 8'h20;
122parameter ALIGN_ERR3 = 8'h40;
123
124wire [9:0] read_in_0;
125wire [9:0] read_in_1;
126wire [9:0] read_in_2;
127wire [9:0] read_in_3;
128
129wire alg_lane0;
130wire alg_lane1;
131wire alg_lane2;
132wire alg_lane3;
133
134wire alg_present;
135wire aligned;
136
137wire csr_deskew_error;
138wire got_deskew_ok;
139
140wire deskew_on_pulse;
141wire deskew_off_pulse;
142
143wire [7:0] nxt_state;
144
145reg [7:0] state;
146reg deskew_done_d;
147reg deskew_init_d;
148reg deskewing;
149
150// ************************************************************************
151// Snoop data out of deskew fifo to check if align characters are deskewed
152// ************************************************************************
153
154 assign read_in_0[9:0] = {r_error_0, r_special_0, r_byte_0[7:0]};
155 assign read_in_1[9:0] = {r_error_1, r_special_1, r_byte_1[7:0]};
156 assign read_in_2[9:0] = {r_error_2, r_special_2, r_byte_2[7:0]};
157 assign read_in_3[9:0] = {r_error_3, r_special_3, r_byte_3[7:0]};
158
159// check for comma symbol on all lanes
160
161 assign alg_lane0 = (read_in_0[9:0] == `XPCS_DEC_ALG);
162 assign alg_lane1 = (read_in_1[9:0] == `XPCS_DEC_ALG);
163 assign alg_lane2 = (read_in_2[9:0] == `XPCS_DEC_ALG);
164 assign alg_lane3 = (read_in_3[9:0] == `XPCS_DEC_ALG);
165
166 assign alg_present = alg_lane0 | alg_lane1 | alg_lane2 | alg_lane3 ;
167
168 assign aligned = alg_lane0 & alg_lane1 & alg_lane2 & alg_lane3;
169
170 assign csr_deskew_error = alg_present & !aligned;
171
172 assign got_deskew_ok = alg_present & aligned;
173
174// ********************************
175// Deskew init and done handshake
176// ********************************
177
178always @ (posedge rx_clk)
179 if (reset)
180 begin
181 deskew_done_d <= 1'b0;
182 deskew_init_d <= 1'b0;
183 deskewing <= 1'b0;
184 end
185 else
186 begin
187 deskew_done_d <= deskew_done;
188 deskew_init_d <= deskew_init;
189 deskewing <= deskew_on_pulse ? 1'b1 : deskew_off_pulse ? 1'b0 : deskewing;
190 end
191
192assign deskew_off_pulse = deskew_done & !deskew_done_d;
193assign deskew_on_pulse = deskew_init & !deskew_init_d;
194
195
196// *****************************************
197// Deskew state machine Clause 48 fig 48-8
198// *****************************************
199
200always @ (posedge rx_clk)
201 if (reset)
202 state <= 8'h00;
203 else
204 state <= nxt_state;
205
206
207 wire csr_link_status_temp;
208 reg csr_link_status;
209
210always @ (posedge rx_clk)
211 csr_link_status <= csr_link_status_temp;
212
213assign {csr_link_status_temp,
214 csr_pulse_deskew_error,
215 deskew_init,
216 nxt_state} = fn_deskew_sm (reset,
217 state,
218 sync_status,
219 csr_deskew_error,
220 deskewing,
221 got_deskew_ok);
222
223function [10:0] fn_deskew_sm;
224
225 input reset;
226 input [7:0] state;
227 input sync;
228 input error;
229 input deskewing;
230 input got_ok;
231
232 reg [7:0] n_state;
233 reg n_status;
234 reg n_init;
235 reg n_inc_deskew_error;
236
237begin
238
239 if (reset | !sync)
240 begin
241 n_status = 1'b0;
242 n_init = 1'b0;
243 n_inc_deskew_error = 1'b0;
244 n_state = DESKEW_LOSS;
245 end
246
247 else
248
249 begin
250 n_status = 1'b0;
251 n_init = 1'b0;
252 n_inc_deskew_error = 1'b0;
253 n_state = DESKEW_LOSS;
254
255 case (state) // synopsys parallel_case
256
257 DESKEW_LOSS:
258
259 if (!sync)
260 begin
261 n_init = 1'b0;
262 n_state = DESKEW_LOSS;
263 end
264
265 else if (got_ok)
266 begin
267 n_init = 1'b0;
268 n_state = ALIGN_DET1;
269 end
270
271 else if (!deskewing)
272 begin
273 n_init = 1'b1;
274 n_state = DESKEW_LOSS;
275 end
276
277 else
278 begin
279 n_init = 1'b0;
280 n_state = DESKEW_LOSS;
281 end
282
283 ALIGN_DET1:
284
285 if (error)
286 begin
287 n_state = DESKEW_LOSS;
288 end
289
290 else if (got_ok)
291 begin
292 n_state = ALIGN_DET2;
293 end
294
295 else
296 begin
297 n_state = ALIGN_DET1;
298 end
299
300 ALIGN_DET2:
301
302 if (error)
303 begin
304 n_state = DESKEW_LOSS;
305 end
306
307 else if (got_ok)
308 begin
309 n_state = ALIGN_DET3;
310 end
311
312 else
313 begin
314 n_state = ALIGN_DET2;
315 end
316
317 ALIGN_DET3:
318
319 if (error)
320 begin
321 n_state = DESKEW_LOSS;
322 end
323
324 else if (got_ok)
325 begin
326 n_state = DESKEW_OK;
327 end
328
329 else
330 begin
331 n_state = ALIGN_DET3;
332 end
333
334 DESKEW_OK:
335
336 if (error)
337 begin
338 n_status = 1'b1;
339 n_state = ALIGN_ERR1;
340 end
341
342 else
343 begin
344 n_status = 1'b1;
345 n_state = DESKEW_OK;
346 end
347
348
349 ALIGN_ERR1:
350
351 if (error)
352 begin
353 n_status = 1'b1;
354 n_state = ALIGN_ERR2;
355 end
356
357 else if (got_ok)
358 begin
359 n_status = 1'b1;
360 n_state = DESKEW_OK;
361 end
362
363 else
364 begin
365 n_status = 1'b1;
366 n_state = ALIGN_ERR1;
367 end
368
369 ALIGN_ERR2:
370
371 if (error)
372 begin
373 n_status = 1'b1;
374 n_state = ALIGN_ERR3;
375 end
376
377 else if (got_ok)
378 begin
379 n_status = 1'b1;
380 n_state = ALIGN_ERR1;
381 end
382
383 else
384 begin
385 n_status = 1'b1;
386 n_state = ALIGN_ERR2;
387 end
388
389 ALIGN_ERR3:
390
391 if (error)
392 begin
393 n_status = 1'b1;
394 n_inc_deskew_error = 1'b0;
395 n_state = DESKEW_LOSS;
396 end
397
398 else if (got_ok)
399 begin
400 n_status = 1'b1;
401 n_state = ALIGN_ERR2;
402 end
403
404 else
405 begin
406 n_status = 1'b1;
407 n_state = ALIGN_ERR3;
408 end
409
410 endcase
411
412 end
413
414 fn_deskew_sm = {n_status, n_inc_deskew_error, n_init, n_state};
415
416 end
417
418endfunction
419
420
421// 0in bits_on -var state -max 1 -clock rx_clk
422
423// 0in state -var state -val DESKEW_LOSS -next ALIGN_DET1 -clock rx_clk -reset (reset |!sync_status)
424// 0in state -var state -val ALIGN_DET1 -next DESKEW_LOSS ALIGN_DET2 -clock rx_clk -reset (reset |!sync_status)
425// 0in state -var state -val ALIGN_DET2 -next DESKEW_LOSS ALIGN_DET3 -clock rx_clk -reset (reset |!sync_status)
426// 0in state -var state -val ALIGN_DET3 -next DESKEW_LOSS DESKEW_OK -clock rx_clk -reset (reset |!sync_status)
427// 0in state -var state -val DESKEW_OK -next ALIGN_ERR1 -clock rx_clk -reset (reset |!sync_status)
428// 0in state -var state -val ALIGN_ERR1 -next DESKEW_OK ALIGN_ERR2 -clock rx_clk -reset (reset |!sync_status)
429// 0in state -var state -val ALIGN_ERR2 -next ALIGN_ERR3 ALIGN_ERR1 -clock rx_clk -reset (reset |!sync_status)
430// 0in state -var state -val ALIGN_ERR3 -next DESKEW_LOSS ALIGN_ERR2 -clock rx_clk -reset (reset |!sync_status)
431
432
433endmodule
434