Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / niu / rtl / niu_rdmc_wr_dp_sm.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: niu_rdmc_wr_dp_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 ============================================
35module niu_rdmc_wr_dp_sm (
36 clk,
37 reset,
38 full_hdr_r1,
39 ipp_data_req_dly2,
40 rdmc_wr_req_accept_hdr,
41 rdmc_wr_req_accept_zcp,
42 muxed_ipp_data_ack,
43 rdmc_cal_eop_r,
44 ipp_next_eop,
45 ipp_fzcp_eop,
46 pkt_req_cnt_done,
47 pkt_req_cnt_done_r,
48 pkt_req_cnt_done_r1,
49 pkt_req_cnt_done_r2,
50 jmb_pkt_type,
51 zcopy_mode,
52 zcp_wr_type,
53
54 offset_reg_en,
55 offset_sel,
56 wr_idle_state,
57 rdmc_wr_data_sel,
58 rdmc_wr_data_valid_sm,
59 rdmc_wr_data_comp_sm,
60 rdmc_wr_last_comp_sm,
61 jmb_wr_cycle_sm,
62 wr_dp_sm_state
63 );
64
65input clk;
66input reset;
67input full_hdr_r1;
68input ipp_data_req_dly2;
69input rdmc_wr_req_accept_hdr;
70input rdmc_wr_req_accept_zcp;
71input muxed_ipp_data_ack;
72input rdmc_cal_eop_r;
73input ipp_next_eop;
74input ipp_fzcp_eop;
75input pkt_req_cnt_done;
76input pkt_req_cnt_done_r;
77input pkt_req_cnt_done_r1;
78input pkt_req_cnt_done_r2;
79input[1:0] jmb_pkt_type; //01:use one buf, 10:use two buf, 11:use three buf
80input zcopy_mode;
81input[1:0] zcp_wr_type; //00:one dmaw, ... 11:four dmaw
82
83output offset_reg_en;
84output[1:0] offset_sel;
85output wr_idle_state;
86output[1:0] rdmc_wr_data_sel;
87output rdmc_wr_data_valid_sm;
88output rdmc_wr_data_comp_sm;
89output rdmc_wr_last_comp_sm;
90output jmb_wr_cycle_sm;
91output[4:0] wr_dp_sm_state;
92
93reg offset_reg_en;
94reg[1:0] offset_sel;
95reg wr_idle_state;
96reg ready_cycle;
97reg[1:0] rdmc_wr_data_sel;
98reg rdmc_wr_data_valid_sm;
99reg rdmc_wr_data_comp_sm;
100reg rdmc_wr_last_comp_sm;
101reg inc_zcp_wr_cnt;
102reg jmb_pkt_done_sm;
103reg jmb_wr_cycle_sm;
104reg[4:0] state;
105reg[4:0] next_state;
106
107reg ready_cycle_reg;
108reg is_rdmc_wr_req_accept;
109reg[1:0] zcp_wr_cnt;
110reg jmb_pkt_done;
111
112wire[4:0] wr_dp_sm_state = state;
113wire zcp_wr_done;
114
115
116parameter
117
118IDLE = 5'd16,
119READY = 5'd0,
120FIRST_HDR = 5'd1,
121JMB_WR_DATA = 5'd2,
122WR_DATA = 5'd3,
123WAIT_DATA_LAST = 5'd4,
124WR_DATA_LAST = 5'd5,
125ZCP_WR_HDR = 5'd6,
126WAIT_ZCP_HDR_LAST = 5'd7,
127ZCP_WR_HDR_LAST = 5'd8,
128ZCP_READY = 5'd9,
129ZCP_WR_MID = 5'd10,
130WAIT_ZCP_MID_LAST = 5'd11,
131ZCP_WR_MID_LAST = 5'd12,
132ZCP_WR_DATA = 5'd13,
133WAIT_ZCP_DATA_LAST = 5'd14,
134ZCP_WR_DATA_LAST = 5'd15;
135
136always @ (state or full_hdr_r1 or ipp_data_req_dly2 or
137 jmb_pkt_type or jmb_pkt_done or
138 zcopy_mode or zcp_wr_done or
139 rdmc_wr_req_accept_hdr or rdmc_wr_req_accept_zcp or
140 is_rdmc_wr_req_accept or muxed_ipp_data_ack or
141 pkt_req_cnt_done or pkt_req_cnt_done_r or
142 pkt_req_cnt_done_r1 or pkt_req_cnt_done_r2 or
143 rdmc_cal_eop_r or ipp_next_eop or ipp_fzcp_eop)
144
145begin
146
147 offset_reg_en = 1'b0;
148 offset_sel = 2'b00;
149 wr_idle_state = 1'b0;
150 ready_cycle = 1'b0;
151 rdmc_wr_data_sel = 2'b00;
152 rdmc_wr_data_valid_sm = 1'b0;
153 rdmc_wr_data_comp_sm = 1'b0;
154 rdmc_wr_last_comp_sm = 1'b0;
155 inc_zcp_wr_cnt = 1'b0;
156 jmb_pkt_done_sm = 1'b0;
157 jmb_wr_cycle_sm = 1'b0;
158 next_state = 5'b0;
159
160case (state) //synopsys parallel_case full_case
161
162IDLE:
163begin
164 wr_idle_state = 1'b1;
165 if (rdmc_wr_req_accept_hdr)
166 begin
167 offset_reg_en = 1'b1;
168 offset_sel = 2'b00;
169 next_state = READY;
170 end
171 else
172 next_state = state;
173end
174
175READY:
176begin
177 ready_cycle = 1'b1;
178 if (ipp_data_req_dly2 & full_hdr_r1)
179 begin
180 rdmc_wr_data_sel = 2'b00;
181 rdmc_wr_data_valid_sm = 1'b1;
182 next_state = FIRST_HDR;
183 end
184 else if (muxed_ipp_data_ack & ipp_data_req_dly2)
185 begin
186 rdmc_wr_data_sel = 2'b01;
187 rdmc_wr_data_valid_sm = 1'b1;
188 if (zcopy_mode)
189 next_state = ZCP_WR_HDR;
190 else if (jmb_pkt_type[1])
191 next_state = JMB_WR_DATA;
192 else
193 next_state = WR_DATA;
194 end
195 else
196 next_state = state;
197end
198
199
200FIRST_HDR:
201begin
202 rdmc_wr_data_sel = 2'b01;
203 rdmc_wr_data_valid_sm = 1'b1;
204 if (jmb_pkt_type[1])
205 next_state = JMB_WR_DATA;
206 else
207 next_state = WR_DATA;
208end
209
210JMB_WR_DATA:
211begin
212 jmb_wr_cycle_sm = 1'b1;
213 if (muxed_ipp_data_ack & pkt_req_cnt_done_r2 & rdmc_cal_eop_r)//second buf has only one transfer,
214 begin //no need to read ipp
215 rdmc_wr_data_sel = 2'b10;
216 rdmc_wr_data_valid_sm = 1'b1;
217 rdmc_wr_data_comp_sm = 1'b1;
218 next_state = WAIT_DATA_LAST;
219 end
220
221 else if (muxed_ipp_data_ack & pkt_req_cnt_done_r2 & jmb_pkt_type[0] & !jmb_pkt_done)
222 begin
223 rdmc_wr_data_sel = 2'b10;
224 rdmc_wr_data_valid_sm = 1'b1;
225 rdmc_wr_data_comp_sm = 1'b1;
226 jmb_pkt_done_sm = 1'b1;
227 next_state = state;
228 end
229
230 else if (muxed_ipp_data_ack & pkt_req_cnt_done_r2)
231 begin
232 rdmc_wr_data_sel = 2'b10;
233 rdmc_wr_data_valid_sm = 1'b1;
234 rdmc_wr_data_comp_sm = 1'b1;
235 next_state = WR_DATA;
236 end
237 else if (muxed_ipp_data_ack)
238 begin
239 rdmc_wr_data_sel = 2'b10;
240 rdmc_wr_data_valid_sm = 1'b1;
241 next_state = state;
242 end
243 else
244 begin
245 rdmc_wr_data_sel = 2'b10;
246 rdmc_wr_data_valid_sm = 1'b0;
247 next_state = state;
248 end
249end
250
251WR_DATA:
252begin
253 if (muxed_ipp_data_ack & rdmc_cal_eop_r & pkt_req_cnt_done_r1)
254 begin
255 rdmc_wr_data_sel = 2'b10;
256 rdmc_wr_data_valid_sm = 1'b1;
257 next_state = WR_DATA_LAST;
258 end
259 else if (muxed_ipp_data_ack & rdmc_cal_eop_r & pkt_req_cnt_done_r2)
260 begin
261 rdmc_wr_data_sel = 2'b10;
262 rdmc_wr_data_valid_sm = 1'b1;
263 rdmc_wr_data_comp_sm = 1'b1;
264 rdmc_wr_last_comp_sm = 1'b1;
265 if (rdmc_wr_req_accept_hdr | is_rdmc_wr_req_accept)
266 next_state = READY;
267 else
268 next_state = IDLE;
269 end
270 else if (muxed_ipp_data_ack & rdmc_cal_eop_r)
271 begin
272 rdmc_wr_data_sel = 2'b10;
273 rdmc_wr_data_valid_sm = 1'b1;
274 next_state = WAIT_DATA_LAST;
275 end
276 else if (muxed_ipp_data_ack)
277 begin
278 rdmc_wr_data_sel = 2'b10;
279 rdmc_wr_data_valid_sm = 1'b1;
280 next_state = state;
281 end
282 else
283 begin
284 rdmc_wr_data_sel = 2'b10;
285 rdmc_wr_data_valid_sm = 1'b0;
286 next_state = state;
287 end
288end
289
290WAIT_DATA_LAST:
291begin
292 if (pkt_req_cnt_done_r | pkt_req_cnt_done_r1 | pkt_req_cnt_done)
293 next_state = WR_DATA_LAST;
294 else
295 next_state = state;
296end
297
298WR_DATA_LAST:
299begin
300 rdmc_wr_data_sel = 2'b10;
301 rdmc_wr_data_valid_sm = 1'b1;
302 rdmc_wr_data_comp_sm = 1'b1;
303 rdmc_wr_last_comp_sm = 1'b1;
304 if (rdmc_wr_req_accept_hdr | is_rdmc_wr_req_accept)
305 next_state = READY;
306 else
307 next_state = IDLE;
308end
309
310ZCP_WR_HDR:
311begin
312 if (muxed_ipp_data_ack & ipp_fzcp_eop & pkt_req_cnt_done_r1)
313 begin
314 rdmc_wr_data_sel = 2'b10;
315 rdmc_wr_data_valid_sm = 1'b1;
316 next_state = ZCP_WR_HDR_LAST;
317 end
318 else if (muxed_ipp_data_ack & ipp_fzcp_eop & pkt_req_cnt_done_r2)
319 begin
320 rdmc_wr_data_sel = 2'b10;
321 rdmc_wr_data_valid_sm = 1'b1;
322 rdmc_wr_data_comp_sm = 1'b1;
323 offset_reg_en = 1'b1;
324 offset_sel = 2'b01;
325 next_state = ZCP_READY;
326 end
327 else if (muxed_ipp_data_ack & ipp_fzcp_eop)
328 begin
329 rdmc_wr_data_sel = 2'b10;
330 rdmc_wr_data_valid_sm = 1'b1;
331 next_state = WAIT_ZCP_HDR_LAST;
332 end
333 else if (muxed_ipp_data_ack)
334 begin
335 rdmc_wr_data_sel = 2'b10;
336 rdmc_wr_data_valid_sm = 1'b1;
337 next_state = state;
338 end
339 else
340 begin
341 rdmc_wr_data_sel = 2'b10;
342 rdmc_wr_data_valid_sm = 1'b0;
343 next_state = state;
344 end
345end
346
347WAIT_ZCP_HDR_LAST:
348begin
349 if (pkt_req_cnt_done_r | pkt_req_cnt_done_r1 | pkt_req_cnt_done)
350 next_state = ZCP_WR_HDR_LAST;
351 else
352 next_state = state;
353end
354
355ZCP_WR_HDR_LAST:
356begin
357 rdmc_wr_data_sel = 2'b10;
358 rdmc_wr_data_valid_sm = 1'b1;
359 rdmc_wr_data_comp_sm = 1'b1;
360 offset_reg_en = 1'b1;
361 offset_sel = 2'b01;
362 next_state = ZCP_READY;
363end
364
365ZCP_READY:
366begin
367 if (rdmc_wr_req_accept_zcp & zcp_wr_done & ipp_next_eop)
368 next_state = WAIT_ZCP_DATA_LAST;
369 else if (rdmc_wr_req_accept_zcp & zcp_wr_done)
370 next_state = ZCP_WR_DATA;
371 else if (rdmc_wr_req_accept_zcp & ipp_next_eop)
372 begin
373 inc_zcp_wr_cnt = 1'b1;
374 next_state = WAIT_ZCP_MID_LAST;
375 end
376 else if (rdmc_wr_req_accept_zcp)
377 begin
378 inc_zcp_wr_cnt = 1'b1;
379 next_state = ZCP_WR_MID;
380 end
381 else
382 next_state = state;
383end
384
385ZCP_WR_MID:
386begin
387 if (muxed_ipp_data_ack & ipp_fzcp_eop & pkt_req_cnt_done_r1)
388 begin
389 rdmc_wr_data_sel = 2'b10;
390 rdmc_wr_data_valid_sm = 1'b1;
391 next_state = ZCP_WR_MID_LAST;
392 end
393 else if (muxed_ipp_data_ack & ipp_fzcp_eop & pkt_req_cnt_done_r2)
394 begin
395 rdmc_wr_data_sel = 2'b10;
396 rdmc_wr_data_valid_sm = 1'b1;
397 rdmc_wr_data_comp_sm = 1'b1;
398 offset_reg_en = 1'b1;
399 offset_sel = 2'b10;
400 next_state = ZCP_READY;
401 end
402 else if (muxed_ipp_data_ack & ipp_fzcp_eop)
403 begin
404 rdmc_wr_data_sel = 2'b10;
405 rdmc_wr_data_valid_sm = 1'b1;
406 next_state = WAIT_ZCP_MID_LAST;
407 end
408 else if (muxed_ipp_data_ack)
409 begin
410 rdmc_wr_data_sel = 2'b10;
411 rdmc_wr_data_valid_sm = 1'b1;
412 next_state = state;
413 end
414 else
415 begin
416 rdmc_wr_data_sel = 2'b10;
417 rdmc_wr_data_valid_sm = 1'b0;
418 next_state = state;
419 end
420end
421
422WAIT_ZCP_MID_LAST:
423begin
424 if (pkt_req_cnt_done_r | pkt_req_cnt_done_r1 | pkt_req_cnt_done)
425 next_state = ZCP_WR_MID_LAST;
426 else
427 next_state = state;
428end
429
430ZCP_WR_MID_LAST:
431begin
432 rdmc_wr_data_sel = 2'b10;
433 rdmc_wr_data_valid_sm = 1'b1;
434 rdmc_wr_data_comp_sm = 1'b1;
435 offset_reg_en = 1'b1;
436 offset_sel = 2'b10;
437 next_state = ZCP_READY;
438end
439
440ZCP_WR_DATA:
441begin
442 if (muxed_ipp_data_ack & ipp_fzcp_eop & pkt_req_cnt_done_r1)
443 begin
444 rdmc_wr_data_sel = 2'b10;
445 rdmc_wr_data_valid_sm = 1'b1;
446 next_state = ZCP_WR_DATA_LAST;
447 end
448 else if (muxed_ipp_data_ack & ipp_fzcp_eop & pkt_req_cnt_done_r2)
449 begin
450 rdmc_wr_data_sel = 2'b10;
451 rdmc_wr_data_valid_sm = 1'b1;
452 rdmc_wr_data_comp_sm = 1'b1;
453 rdmc_wr_last_comp_sm = 1'b1;
454 offset_reg_en = 1'b1;
455 offset_sel = 2'b00;
456
457 if (rdmc_wr_req_accept_hdr | is_rdmc_wr_req_accept)
458 next_state = READY;
459 else
460 next_state = IDLE;
461 end
462 else if (muxed_ipp_data_ack & ipp_fzcp_eop)
463 begin
464 rdmc_wr_data_sel = 2'b10;
465 rdmc_wr_data_valid_sm = 1'b1;
466 next_state = WAIT_ZCP_DATA_LAST;
467 end
468 else if (muxed_ipp_data_ack)
469 begin
470 rdmc_wr_data_sel = 2'b10;
471 rdmc_wr_data_valid_sm = 1'b1;
472 next_state = state;
473 end
474 else
475 begin
476 rdmc_wr_data_sel = 2'b10;
477 rdmc_wr_data_valid_sm = 1'b0;
478 next_state = state;
479 end
480end
481
482WAIT_ZCP_DATA_LAST:
483begin
484 if (pkt_req_cnt_done_r | pkt_req_cnt_done_r1 | pkt_req_cnt_done)
485 next_state = ZCP_WR_DATA_LAST;
486 else
487 next_state = state;
488end
489
490ZCP_WR_DATA_LAST:
491begin
492 rdmc_wr_data_sel = 2'b10;
493 rdmc_wr_data_valid_sm = 1'b1;
494 rdmc_wr_data_comp_sm = 1'b1;
495 rdmc_wr_last_comp_sm = 1'b1;
496 offset_reg_en = 1'b1;
497 offset_sel = 2'b00;
498
499 if (rdmc_wr_req_accept_hdr | is_rdmc_wr_req_accept)
500 next_state = READY;
501 else
502 next_state = IDLE;
503end
504
505
506default:
507 next_state = IDLE;
508
509endcase
510end
511
512
513always @ (posedge clk)
514if (reset)
515 state <= IDLE;
516else
517 state <= next_state;
518
519always @ (posedge clk)
520if (reset)
521 ready_cycle_reg <= 1'b0;
522else
523 ready_cycle_reg <= ready_cycle;
524
525wire ready_cycle_p = ready_cycle & !ready_cycle_reg;
526
527always @ (posedge clk)
528if (reset)
529 is_rdmc_wr_req_accept <= 1'b0;
530else if (rdmc_wr_req_accept_hdr)
531 is_rdmc_wr_req_accept <= 1'b1;
532else if (ready_cycle_p)
533 is_rdmc_wr_req_accept <= 1'b0;
534else
535 is_rdmc_wr_req_accept <= is_rdmc_wr_req_accept;
536
537always @ (posedge clk)
538if (reset)
539 zcp_wr_cnt <= 2'b0;
540else if (ready_cycle)
541 zcp_wr_cnt <= 2'b0;
542else if (inc_zcp_wr_cnt)
543 zcp_wr_cnt <= zcp_wr_cnt + 2'd1;
544else
545 zcp_wr_cnt <= zcp_wr_cnt;
546
547assign zcp_wr_done = (zcp_wr_cnt == zcp_wr_type);
548
549always @ (posedge clk)
550if (reset)
551 jmb_pkt_done <= 1'b0;
552else if (ready_cycle)
553 jmb_pkt_done <= 1'b0;
554else if (jmb_pkt_done_sm)
555 jmb_pkt_done <= 1'b1;
556else
557 jmb_pkt_done <= jmb_pkt_done;
558
559
560
561endmodule
562
563
564
565
566