Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / niu / rtl / niu_ipp_load.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: niu_ipp_load.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
38 Project : Niu
39
40 File name : niu_ipp_load.v
41
42 Module(s) name : niu_ipp_load
43 Original: : ipp_load.v main.45, label: IPP_VERIF_1.84
44
45 Parent modules : niu_ipp.v
46
47 Child modules : niu_ipp_lib.v
48
49 Author's name : Jonathan Shen, George Chu
50
51 Date : May 2001
52
53 Description : This module loads the 64 bit double word data from
54 MAC/XMAC into ipp fifo. The data will be packed from
55 64-bit bus to 128-bit bus before loading in IPP Header fifo.
56 The protocol between IPP, XMAC and IPP, big MAC are
57 different.
58 FFLP reads the header part.
59
60 Synthesis Notes:
61
62 Modification History:
63
64 Date Description
65 ---- -----------
66
67************************************************************
68***********************************************************/
69
70module niu_ipp_load(
71// input
72 clk, reset,
73
74// input from mac
75 mac_ipp_req, xmac_ipp_ack,
76 mac_ipp_data, mac_ipp_tag,
77 mac_ipp_ctrl, mac_ipp_stat,
78
79// input from ffl
80 ffl_ipp_ready,
81 ffl_ipp_dvalid,
82 fflp_ipp_sum,
83
84// input from ffl_arbiter
85 ffl_arb_ack,
86
87 port_id,
88 ippfifo_rd_wr_ptr_bypass,
89 ippfifo_wr_ptr_pio_wr_en,
90 eop_from_hdr_fifo,
91 pio_wr_data,
92 fifo_wr_data_reg,
93 fifo_wr_data_reg_wr_en_pls,
94 ipp_enable, xmac_mode,
95 bypass_ffl,
96 vec_cycle1_wr_en,
97 inc_hfifo_dat_rptr,
98 ipp_hfifo_dat_rptr,
99 n_ipp_unload_idle,
100 clr_ipp_unload,
101
102// output
103// output to mac
104 ipp_mac_ack, ipp_xmac_req,
105
106// output to ffl
107 ipp_ffl_dvalid,
108 ipp_ffl_mac_default,
109
110// outout to ffl_arbiter
111 ipp_ffl_req,
112
113// output to ipp fifo
114 fifo_wr_en, fifo_wr_ptr,
115 ipp_hfifo_rden, ipp_hfifo_rptr,
116 ipp_hfifo_dat_empty,
117 fifo_data_in,
118 ipp_ffl_dvalid_n,
119// output to ipp_post
120 runt,
121// end of output to ipp post
122 ipp_hfifo_over_run_r, ipp_hfifo_under_run_r,
123 phase_state_xmac, phase_state,
124 phase_state_1st_data, mac_ack_fsm_curstate,
125 ipp_ffl_curstate,
126 cur_pkt_hdr_base_ptr, cur_pkt_ffl_sum_info
127 );
128
129input clk;
130input reset;
131input mac_ipp_req;
132input xmac_ipp_ack;
133input [63:0] mac_ipp_data;
134input mac_ipp_tag;
135input mac_ipp_ctrl;
136input [22:0] mac_ipp_stat;
137input ffl_ipp_ready; // from ffl_top module
138input ffl_ipp_dvalid; // from ffl_top module
139input [13:0] fflp_ipp_sum; // from ffl_top module
140input ffl_arb_ack; // from ffl_arb module
141input ippfifo_rd_wr_ptr_bypass; // from slave
142input ippfifo_wr_ptr_pio_wr_en; // from slave
143input eop_from_hdr_fifo; // from ipp
144input [13:0] pio_wr_data;
145input [129:0] fifo_wr_data_reg;
146input fifo_wr_data_reg_wr_en_pls;
147input [1:0] port_id;
148input ipp_enable;
149input xmac_mode;
150input bypass_ffl;
151input vec_cycle1_wr_en;
152input inc_hfifo_dat_rptr;
153input [6:0] ipp_hfifo_dat_rptr;
154
155input n_ipp_unload_idle;
156input clr_ipp_unload;
157
158output ipp_mac_ack;
159output ipp_xmac_req; // if fifo not full, always high (xmac)
160output ipp_ffl_req; // to ffl_arb module
161output ipp_ffl_dvalid; // valid data from ipp to ffl
162output ipp_ffl_dvalid_n; // valid data from ipp to ffl for par
163output [11:0] ipp_ffl_mac_default; // control inf. to ffl
164output ipp_hfifo_dat_empty;
165output fifo_wr_en; // to ipp_fifo
166output [6:0] fifo_wr_ptr; // to ipp_fifo
167output ipp_hfifo_rden; // to ipp_hdr_fifo
168output [5:0] ipp_hfifo_rptr; // to ipp_hdr_fifo
169output [129:0] fifo_data_in; // to ipp_fifo
170output ipp_hfifo_over_run_r;
171output ipp_hfifo_under_run_r;
172output [2:0] phase_state_xmac;
173output [2:0] phase_state;
174output phase_state_1st_data;
175output [3:0] mac_ack_fsm_curstate;
176output [1:0] ipp_ffl_curstate;
177output runt;
178output [6:0] cur_pkt_hdr_base_ptr;
179output [13:0] cur_pkt_ffl_sum_info;
180
181wire ipp_hfifo_dat_empty;
182reg ipp_hfifo_over_run_r;
183reg ipp_hfifo_under_run_r;
184reg [6:0] cur_pkt_hdr_base_ptr;
185reg [13:0] cur_pkt_ffl_sum_info;
186
187wire [6:0] ipp_hfifo_dat_empty_space;
188wire ipp_hfifo_dat_full;
189wire ipp_hfifo_over_run, n_ipp_hfifo_over_run;
190wire ipp_hfifo_under_run, n_ipp_hfifo_under_run;
191wire n_ipp_hfifo_bad_mac_load;
192reg ipp_hfifo_bad_mac_load;
193
194reg ffl_ipp_dvalid_d;
195
196reg ipp_mac_ack;
197reg ipp_mac_ack_d; // use ack delay as internal signal
198reg ipp_mac_ack_reg1;
199reg xmac_ack;
200reg bmac_ack;
201reg ipp_xmac_req;
202reg [6:0] fifo_wr_ptr;
203reg [6:0] wr_base_ptr; // use for rewind pointer like run packet only
204reg [6:0] hdr_rd_ptr;
205reg [6:0] hdr_rd_ptr_n;
206
207reg [3:0] hdr_count;
208reg [3:0] hdr_count_n;
209reg ipp_ffl_req;
210reg ipp_ffl_req_n;
211wire ipp_ffl_dvalid;
212reg ipp_ffl_dvalid_n;
213wire ipp_ffl_dvalid_n_nxt;
214wire filtered_tag;
215wire bmac_ipp_tag;
216
217// pipeline register stuff
218reg [63:0] mac_ipp_data_reg1;
219reg [131:0] mac_ipp_data_reg2;
220reg [130:0] xmac_ipp_data_reg2;
221reg [63:0] mac_ipp_stat_reg;
222reg [11:0] mac_ipp_ctl_reg; // store the mac ctl word
223reg mac_ipp_ctrl_reg; // registered the control signal
224reg mac_ipp_tag_reg1;
225reg xmac_ipp_ack_d;
226reg xmac_ipp_ack_reg1;
227reg [63:0] stage0_dout;
228reg [63:0] stage1_dout;
229reg [63:0] xstage0_dout;
230reg [63:0] xstage1_dout;
231reg stage0_tout;
232reg stage1_tout;
233reg sel;
234wire valid2;
235wire valid2_xmac;
236wire valid2_xmac_pio;
237wire stat_wr_reg2;
238wire fifo_wr_en;
239wire ctlfifo_wr_en;
240
241wire load_fifo;
242wire xload_fifo;
243
244wire [129:0] fifo_data_in = (ippfifo_rd_wr_ptr_bypass && valid2) ?
245 mac_ipp_data_reg2[129:0] :
246 (ippfifo_rd_wr_ptr_bypass && valid2_xmac_pio) ?
247 xmac_ipp_data_reg2[129:0] :
248 ((xmac_mode == 1'b0) && (load_fifo == 1'b0)) ?
249 130'h0 :
250 ((xmac_mode == 1'b1) && (xload_fifo == 1'b0)) ?
251 130'h0 :
252 xmac_mode ? xmac_ipp_data_reg2[129:0] :
253 mac_ipp_data_reg2[129:0];
254
255wire [5:0] ipp_hfifo_hdr_rptr = hdr_rd_ptr_n[5:0]; // to FFL read ptr
256wire [5:0] ipp_hfifo_rptr = (n_ipp_unload_idle && !ippfifo_rd_wr_ptr_bypass) ?
257 ipp_hfifo_hdr_rptr[5:0] : ipp_hfifo_dat_rptr[5:0];
258wire ipp_hfifo_rden = ipp_ffl_dvalid_n_nxt || inc_hfifo_dat_rptr ||
259 ippfifo_rd_wr_ptr_bypass || reset;
260
261// for mac_ack_fsm
262wire n_tag;
263wire nn_tag;
264wire [2:0] phase_state;
265wire [2:0] phase_state_xmac;
266wire phase_state_1st_data;
267wire [3:0] mac_ack_fsm_curstate;
268reg [1:0] ipp_ffl_curstate;
269reg [1:0] nex_state;
270wire ipp_ack;
271// geo: wire mac_tag;
272reg nn_tag_d;
273wire tag_err_mac = nn_tag_d & ~bmac_ipp_tag;
274wire set_tag_err_mac; //geo: from Vega: No load now, leave it for future use
275
276// geo: wire fifo_rdy_4rd;
277wire fifo_rdy_4wr;
278wire runt;
279wire hdr_ok_2xfer;
280wire ctlfifo_rd_dn;
281wire wr_1st_data;
282wire swap;
283wire [1:0] eop_4_fifo;
284
285reg [4:0] hdr_ok_2xfer_cnt, n_hdr_ok_2xfer_cnt;
286wire dec_hdr_ok_2xfer_cnt;
287wire hdr_ok_2xfer_cnt_gt_eq_1 = |(hdr_ok_2xfer_cnt[4:1]);
288wire start_hdr_xfer;
289
290assign bmac_ipp_tag = xmac_mode ? 1'b0 : mac_ipp_tag;
291assign filtered_tag = xmac_mode ? (mac_ipp_tag & xmac_ipp_ack):
292 (mac_ipp_tag & ipp_mac_ack_d);
293/* filtered_tag equals to the and function of tag and delayed ack
294*/
295assign valid2 = mac_ipp_data_reg2[130];
296assign valid2_xmac = xmac_ack;
297assign valid2_xmac_pio = xmac_ipp_data_reg2[130];
298assign stat_wr_reg2 = xmac_mode ? (xmac_ipp_data_reg2[128] & fifo_wr_en) :
299 (mac_ipp_data_reg2[128] & fifo_wr_en);
300assign eop_4_fifo = xmac_mode ? xmac_ipp_data_reg2[129:128] :
301 mac_ipp_data_reg2[129:128];
302
303assign fifo_wr_en = ippfifo_rd_wr_ptr_bypass ? (valid2 || valid2_xmac_pio) :
304 xmac_mode ? xload_fifo : load_fifo;
305
306//**********************************************************
307//***** mac_ipp_data pipe and associated control logic *****
308//**********************************************************
309
310// 1st stage mac_ipp_data pipe
311wire [63:0] mac_ipp_data_next = (sel == 1'b1) ? mac_ipp_stat_reg[63:0] :
312 mac_ipp_data[63:0];
313wire xmac_ipp_ack_next = (sel == 1'b1) ? sel :
314 xmac_ipp_ack;
315wire mac_ipp_tag_next = (sel == 1'b1) ? sel :
316 filtered_tag;
317
318always @ (posedge clk)
319 if (reset) begin
320 xmac_ipp_ack_d <= 1'h0;
321 ipp_mac_ack_d <= 1'h0;
322 xmac_ipp_ack_reg1 <= 1'h0;
323 ipp_mac_ack_reg1 <= 1'h0;
324 mac_ipp_ctrl_reg <= 1'h0;
325 mac_ipp_stat_reg <= 64'h0;
326//g mac_ipp_ctl_reg <= 12'h0;
327 sel <= 1'h0;
328 mac_ipp_data_reg1 <= 64'h0;
329 mac_ipp_tag_reg1 <= 1'h0;
330 end
331 else
332 begin
333 xmac_ipp_ack_d <= xmac_ipp_ack_next;
334 ipp_mac_ack_d <= ipp_mac_ack;
335 xmac_ipp_ack_reg1 <= xmac_ipp_ack_d;
336 ipp_mac_ack_reg1 <= ipp_mac_ack_d;
337 mac_ipp_ctrl_reg <= mac_ipp_ctrl;
338
339 if (filtered_tag & xmac_mode)
340 mac_ipp_stat_reg[63:0] <= {41'b0, mac_ipp_stat[22:0]};
341//g mac_ipp_ctl_reg[11:0] <= mac_ipp_stat[11:0];
342 sel <= (filtered_tag && xmac_mode)? 1'h1 : 1'h0;
343 mac_ipp_data_reg1[63:0] <= mac_ipp_data_next[63:0];
344 mac_ipp_tag_reg1 <= mac_ipp_tag_next;
345 end
346
347/******** geo ***********************************************************/
348 always @ (posedge clk) begin
349 if (reset || mac_ipp_ctrl) begin
350 mac_ipp_ctl_reg <= mac_ipp_stat[11:0] & {12{!reset}};
351 end
352 else begin
353 mac_ipp_ctl_reg <= mac_ipp_ctl_reg[11:0];
354 end
355 end
356/************************************************************************/
357
358// 2nd stage mac_data_in2 pipe, pack the data from 64-bit to 128-bit
359always @ (posedge clk)
360 begin
361 stage0_dout[63:0] <= mac_ipp_data_reg1[63:0];
362 stage1_dout[63:0] <= stage0_dout[63:0];
363 stage0_tout <= mac_ipp_tag_reg1;
364 stage1_tout <= stage0_tout;
365 xmac_ack <= xmac_ipp_ack_reg1;
366 bmac_ack <= ipp_mac_ack_reg1;
367
368// for xmac only
369 if (reset)
370 begin
371 xstage0_dout[63:0] <= 64'h0;
372 end
373 else if (xmac_ipp_ack_d)
374 begin
375 xstage0_dout[63:0] <= mac_ipp_data_reg1[63:0];
376 end
377 else
378 xstage0_dout[63:0] <= xstage0_dout[63:0];
379
380 if (reset)
381 begin
382 xstage1_dout[63:0] <= 64'h0;
383 end
384 else if (xmac_ipp_ack_reg1)
385 begin
386 xstage1_dout[63:0] <= xstage0_dout[63:0];
387 end
388 else
389 xstage1_dout[63:0] <= xstage1_dout[63:0];
390
391 if (reset)
392 xmac_ipp_data_reg2[130:0] <= 131'b0;
393 else if (fifo_wr_data_reg_wr_en_pls && xmac_mode)
394 xmac_ipp_data_reg2[130:0] <= {1'b1, fifo_wr_data_reg[129:0]};
395 else if (xmac_ipp_ack_reg1)
396 xmac_ipp_data_reg2[130:0] <= {1'b0, stage0_tout, stage1_tout, xstage0_dout[63:0], xstage1_dout[63:0]};
397 else if (xmac_ack & swap) // swap data
398 xmac_ipp_data_reg2[130:0] <= {1'b0, stage0_tout, stage1_tout, xstage1_dout[63:0], xstage0_dout[63:0]};
399 else
400 xmac_ipp_data_reg2[130:0] <= {1'b0, xmac_ipp_data_reg2[129:0]};
401// end of for xmac only
402
403 if (reset)
404 mac_ipp_data_reg2[131:0] <= 132'h0;
405 else if (fifo_wr_data_reg_wr_en_pls && (xmac_mode == 1'h0))
406 mac_ipp_data_reg2[131:0] <= {2'b01, fifo_wr_data_reg[129:0]};
407 else if ((stage0_tout == 1'b0) && (stage1_tout == 1'b1))
408 mac_ipp_data_reg2[131:0] <= {xmac_ack, bmac_ack, stage0_tout, stage1_tout, 64'h0, stage1_dout[63:0]};
409 else
410 mac_ipp_data_reg2[131:0] <= {xmac_ack, bmac_ack, stage0_tout, stage1_tout, stage0_dout[63:0], stage1_dout[63:0]};
411 end
412
413//***** end of mac_data_in pipe *****
414
415//***** phase_sm instantiation *****
416phase_sm0 xmac_phase_sm_after_packing (.clk(clk), .reset(reset),
417 .valid(valid2_xmac & (!ippfifo_rd_wr_ptr_bypass)),
418 .eop(eop_4_fifo), .swap(swap),
419 .load_fifo(xload_fifo), .phase_state(phase_state_xmac));
420
421phase_sm bmac_phase_sm_after_packing (.clk(clk), .reset(reset),
422 .valid(valid2 & (!ippfifo_rd_wr_ptr_bypass)), .eop(eop_4_fifo),
423 .load_fifo(load_fifo), .phase_state(phase_state));
424
425phase_sm3 phase_sm_1st_data (.clk(clk), .reset(reset),
426 .valid((valid2 | valid2_xmac) & (!ippfifo_rd_wr_ptr_bypass)),
427 .eop(stat_wr_reg2), .wr_1st_data(wr_1st_data),
428 .phase_state(phase_state_1st_data));
429
430//***** ipp_mac_ack shaper *****
431mac_ack_fsm mac_ack_fsm_ack (.clk(clk), .reset(reset | ~ipp_enable),
432 .ipp_enable(ipp_enable),
433 .mac_ipp_req(mac_ipp_req), .mac_tag(bmac_ipp_tag),
434 .fifo_rdy_4wr(fifo_rdy_4wr),
435 .tag_err_mac(tag_err_mac),
436 .n_tag(n_tag), .nn_tag(nn_tag), .set_tag_err_mac(set_tag_err_mac),
437 .ipp_ack(ipp_ack), .cur_state(mac_ack_fsm_curstate[3:0]));
438
439//***** ack to mac & control signals from mac_ack_fsm *****
440always @ (posedge clk)
441 if (reset | (~ipp_enable))
442 begin
443 ipp_mac_ack <= 0;
444 nn_tag_d <=0;
445 end
446 else
447 begin
448 ipp_mac_ack <= ipp_ack;
449 nn_tag_d <= nn_tag;
450 end
451
452//***** end of ack behavior *****
453
454
455//***** req to xmac *****
456always @ (posedge clk)
457 if (reset | (~fifo_rdy_4wr) | (~ipp_enable))
458 ipp_xmac_req <= 0;
459 else if (fifo_rdy_4wr)
460 ipp_xmac_req <= 1;
461 else
462 ipp_xmac_req <= ipp_xmac_req;
463//***** end of req behavior *****
464
465//************************************************
466//***** Ipp_hdr_fifo and associated control logic *****
467//************************************************
468
469//***** Ipp_hdr_fifo Write Pointer *****
470always @ (posedge clk)
471 if (reset)
472 fifo_wr_ptr <= 0;
473 else if (ippfifo_rd_wr_ptr_bypass)
474 casex (ippfifo_wr_ptr_pio_wr_en)
475 1'b0: fifo_wr_ptr <= fifo_wr_ptr; // hold the value
476 1'b1: fifo_wr_ptr <= pio_wr_data[6:0];
477 endcase
478 else if (runt)
479 fifo_wr_ptr <= wr_base_ptr; // abort packet; rewind pointer
480 else if (fifo_wr_en)
481 fifo_wr_ptr <= fifo_wr_ptr + 1; // increment
482 else
483 fifo_wr_ptr <= fifo_wr_ptr; // hold the value
484
485//***** Ipp_hdr_fifo Write Base Pointer *****
486always @ (posedge clk)
487 if (reset)
488 wr_base_ptr <= fifo_wr_ptr;
489 else if (wr_1st_data)
490 wr_base_ptr <= fifo_wr_ptr; // update count
491 else
492 wr_base_ptr <= wr_base_ptr;
493
494//***** Ipp_hdr_fifo Read Pointer *****
495/****** geo: ******
496input ippfifo_rd_ptr_pio_wr_en; // from slave
497always @ (posedge clk)
498 if (reset)
499 fifo_rd_ptr <= 7'b0;
500 else if (ippfifo_rd_wr_ptr_bypass)
501 casex (ippfifo_rd_ptr_pio_wr_en)
502 1'b0: fifo_rd_ptr <= fifo_rd_ptr; // hold the value
503 1'b1: fifo_rd_ptr <= pio_wr_data[6:0];
504 endcase
505 else if (fifo_rd_en)
506 fifo_rd_ptr <= fifo_rd_ptr_plus1[6:0]; // inc pointer
507 else
508 fifo_rd_ptr <= fifo_rd_ptr; // hold the value
509******* geo: *****/
510
511//*** 1K bytes Ipp_hdr_fifo Management (64-bit depth and 16 bytes(128-bit) wide) ***
512/****** geo: ******
513wire [6:0] fifo_empty_space = (fifo_wr_ptr[6] == fifo_rd_ptr[6]) ?
514 7'd64 - (fifo_wr_ptr[5:0] - fifo_rd_ptr[5:0]):
515 (fifo_rd_ptr[5:0] - fifo_wr_ptr[5:0]);
516
517wire fifo_full = (fifo_wr_ptr[6] == (!fifo_rd_ptr[6])) &&
518 (fifo_wr_ptr[5:0] == fifo_rd_ptr[5:0]);
519
520wire fifo_empty = (fifo_wr_ptr[6:0] == fifo_rd_ptr[6:0]);
521
522wire fifo_over_run = fifo_full & fifo_wr_en & (!ippfifo_rd_wr_ptr_bypass);
523
524wire fifo_under_run = fifo_empty & fifo_rd_en & (!ippfifo_rd_wr_ptr_bypass);
525******* geo: *****/
526
527// geo:
528 assign ipp_hfifo_dat_empty_space = (fifo_wr_ptr[6] == ipp_hfifo_dat_rptr[6]) ?
529 7'd64 - {1'b0,(fifo_wr_ptr[5:0] - ipp_hfifo_dat_rptr[5:0])}:
530 {1'b0,(ipp_hfifo_dat_rptr[5:0] - fifo_wr_ptr[5:0])};
531 assign ipp_hfifo_dat_full = (fifo_wr_ptr[6] == (!ipp_hfifo_dat_rptr[6]) ) &&
532 (fifo_wr_ptr[5:0] == ipp_hfifo_dat_rptr[5:0]);
533 assign ipp_hfifo_dat_empty = (fifo_wr_ptr[6:0] == ipp_hfifo_dat_rptr[6:0]);
534 assign ipp_hfifo_over_run = (ipp_hfifo_dat_full && fifo_wr_en || ipp_hfifo_bad_mac_load) && !ippfifo_rd_wr_ptr_bypass;
535 assign ipp_hfifo_under_run = (ipp_hfifo_dat_empty && inc_hfifo_dat_rptr || ipp_hfifo_bad_mac_load) && !ippfifo_rd_wr_ptr_bypass;
536
537 assign n_ipp_hfifo_over_run = (reset || clr_ipp_unload) ? 1'b0 :
538 ipp_hfifo_over_run ? 1'b1 :
539 ipp_hfifo_over_run_r;
540
541 assign n_ipp_hfifo_under_run = (reset || clr_ipp_unload) ? 1'b0 :
542 ipp_hfifo_under_run ? 1'b1 :
543 ipp_hfifo_under_run_r;
544
545 assign n_ipp_hfifo_bad_mac_load = xmac_mode && (phase_state_xmac[2:0]==3'h5) || // phase_sm0 ERROR state
546 !xmac_mode && (phase_state[2:0]==3'h5) || // phase_sm ERROR state
547 !xmac_mode && (mac_ack_fsm_curstate[3:0]==4'hB); // mac_ack_fsm error state
548
549 always @ (posedge clk)
550 begin
551 ipp_hfifo_over_run_r <= n_ipp_hfifo_over_run;
552 ipp_hfifo_under_run_r <= n_ipp_hfifo_under_run;
553 ipp_hfifo_bad_mac_load<= n_ipp_hfifo_bad_mac_load;
554 end
555
556// assign the sixteen byte data
557reg [11:0] sixteen_byte_count;
558always @ (posedge clk)
559 if (reset | runt | stat_wr_reg2)
560 sixteen_byte_count <= 0;
561 else if (fifo_wr_en)
562 sixteen_byte_count <= sixteen_byte_count + 1; // hold
563 else
564 sixteen_byte_count <= sixteen_byte_count; // inc.
565
566// assign the abort_wr
567reg abort_wr;
568always @ (posedge clk)
569 if (stat_wr_reg2)
570 if (xmac_mode) begin
571 if (xmac_ipp_data_reg2[129])
572 abort_wr <= xmac_ipp_data_reg2[79];
573 else
574 abort_wr <= xmac_ipp_data_reg2[15];
575 end
576 else begin
577 if (mac_ipp_data_reg2[129])
578 abort_wr <= mac_ipp_data_reg2[79];
579 else
580 abort_wr <= mac_ipp_data_reg2[15];
581 end
582 else
583 abort_wr <= 1'b0;
584
585// definition of runt packet
586assign runt = ((sixteen_byte_count < 12'd4) |
587 ((sixteen_byte_count == 12'd4) & abort_wr)) & stat_wr_reg2;
588
589// synopsys translate_off
590// For diagnostic purpose
591always @ (posedge clk)
592 if (!reset)
593 begin
594 if (ipp_hfifo_over_run)
595 $display("\n -> Warning at sim time = %d, ipp PortID=%d Ipp_hdr_fifo over run occurred.", $stime, port_id);
596 else if (ipp_hfifo_under_run)
597 $display("\n -> Warning at sim time = %d, ipp PortID=%d ipp Ipp_hdr_fifo under run occurred.", $stime, port_id);
598 else ;
599 end
600// synopsys translate_on
601
602// geo: wire [6:0] fifo_full_space = 7'd64 - ipp_hfifo_dat_empty_space[6:0];
603
604// there are 5 stages of registers for mac/ipp interface
605// As John's request change 5 to 6 (2-3-3)
606
607wire [6:0] hfifo_space = xmac_mode ? 7'd5 : 7'd9; // geo
608
609assign fifo_rdy_4wr = (ipp_hfifo_dat_empty_space[6:0] > hfifo_space);
610
611//***** used by ipp_bmc_ctrl *****
612//accumulate to 16-byte data (1)
613// geo: assign fifo_rdy_4rd = (fifo_full_space > 7'h0) & ~runt;
614
615
616//***** Ipp_hdr_fifo Header Read by FFL *****
617// oThe2ndTagTime is the status word. Can not count as part of the
618// 64 byte payload requirement.
619//
620// look inside PktLength field of status word approach.
621//wire time_2_xfer_hdr =((fifo_data_in[13:0] == `SIXTY_FOUR) & oThe2ndTagTime)|
622// ((sixteen_byte_count == `THIRTY_TWO) & fifo_wr_en & ~oThe2ndTagTime);
623
624// independent ipp approach
625wire time_2_xfer_hdr = ((sixteen_byte_count == 12'd4) & // 64-byte
626 (~abort_wr & stat_wr_reg2)) |
627 ((sixteen_byte_count == 12'd5) & // 80- byte
628 (~abort_wr & stat_wr_reg2)) |
629 ((sixteen_byte_count == 12'd6) & // 96-byte
630 (~abort_wr & stat_wr_reg2)) |
631 ((sixteen_byte_count == 12'd7) & //112-byte
632 (~abort_wr & stat_wr_reg2)) |
633 ((sixteen_byte_count == 12'd8) & //128-byte
634 ((~abort_wr & stat_wr_reg2) |
635 (fifo_wr_en & ~stat_wr_reg2)));
636
637ipp_puls_gen puls_gen_hdr_xfer (.reset(reset), .clk(clk),
638 .signal_in(time_2_xfer_hdr), .puls_out(hdr_ok_2xfer));
639
640//*********************************************
641//***** header base pointer fifo (7 x 16) *****
642//*********************************************
643
644reg [6:0] hdr_base_ptr_fifo [0:15]; // 7-bit by 16 deep
645reg [3:0] hdr_base_ptr_wr_ptr;
646reg [3:0] hdr_base_ptr_rd_ptr;
647
648//***** write to header base pointer fifo
649always @ (posedge clk)
650 if (reset)
651 begin
652 hdr_base_ptr_fifo[0] <= 7'b0;
653 hdr_base_ptr_fifo[1] <= 7'b0;
654 hdr_base_ptr_fifo[2] <= 7'b0;
655 hdr_base_ptr_fifo[3] <= 7'b0;
656 hdr_base_ptr_fifo[4] <= 7'b0;
657 hdr_base_ptr_fifo[5] <= 7'b0;
658 hdr_base_ptr_fifo[6] <= 7'b0;
659 hdr_base_ptr_fifo[7] <= 7'b0;
660 hdr_base_ptr_fifo[8] <= 7'b0;
661 hdr_base_ptr_fifo[9] <= 7'b0;
662 hdr_base_ptr_fifo[10] <= 7'b0;
663 hdr_base_ptr_fifo[11] <= 7'b0;
664 hdr_base_ptr_fifo[12] <= 7'b0;
665 hdr_base_ptr_fifo[13] <= 7'b0;
666 hdr_base_ptr_fifo[14] <= 7'b0;
667 hdr_base_ptr_fifo[15] <= 7'b0;
668 end
669 else if (wr_1st_data)
670 hdr_base_ptr_fifo[hdr_base_ptr_wr_ptr] <= fifo_wr_ptr[6:0];
671 else
672 hdr_base_ptr_fifo[hdr_base_ptr_wr_ptr] <= hdr_base_ptr_fifo[hdr_base_ptr_wr_ptr];
673
674//***** header base pointer write pointer *****
675always @ (posedge clk)
676 if (reset)
677 hdr_base_ptr_wr_ptr <= 4'h0;
678 else
679 casex ({wr_1st_data, runt})
680 2'b00: hdr_base_ptr_wr_ptr <= hdr_base_ptr_wr_ptr;
681 2'b01: hdr_base_ptr_wr_ptr <= hdr_base_ptr_wr_ptr - 4'h1; // rewind
682 2'b10: hdr_base_ptr_wr_ptr <= hdr_base_ptr_wr_ptr + 4'h1; // increment
683 2'b11: hdr_base_ptr_wr_ptr <= hdr_base_ptr_wr_ptr;
684 endcase
685
686//***** header base pointer read pointer *****
687always @ (posedge clk)
688 if (reset)
689 hdr_base_ptr_rd_ptr <= 4'h0;
690 else if (hdr_count == 4'd1)
691 hdr_base_ptr_rd_ptr <= hdr_base_ptr_rd_ptr + 1;
692 else
693 hdr_base_ptr_rd_ptr <= hdr_base_ptr_rd_ptr;
694
695//***** header base pointer
696wire [6:0] hdr_base_ptr = hdr_base_ptr_fifo[hdr_base_ptr_rd_ptr];
697
698// geo:
699always @ (posedge clk)
700 if (reset)
701 cur_pkt_hdr_base_ptr <= 7'h0;
702 else if (hdr_count == 4'd1)
703 cur_pkt_hdr_base_ptr <= hdr_base_ptr;
704 else
705 cur_pkt_hdr_base_ptr <= cur_pkt_hdr_base_ptr;
706//***** end of header base pointer fifo
707
708always @ (posedge clk)
709 if (reset)
710 cur_pkt_ffl_sum_info <= 14'h0;
711 else if (ffl_ipp_dvalid && !ffl_ipp_dvalid_d)
712 cur_pkt_ffl_sum_info <= fflp_ipp_sum[13:0];
713 else if (bypass_ffl && vec_cycle1_wr_en)
714 cur_pkt_ffl_sum_info <= pio_wr_data[13:0];
715 else
716 cur_pkt_ffl_sum_info <= cur_pkt_ffl_sum_info[13:0];
717
718parameter
719 Idle = 2'h0,
720 Wait4rdy = 2'h1,
721 Wait4ack = 2'h2,
722 Hdr_xfer = 2'h3;
723
724always @ (start_hdr_xfer or ffl_ipp_ready or ffl_arb_ack or
725 hdr_count or hdr_rd_ptr or hdr_base_ptr or ipp_ffl_dvalid_n or
726 n_ipp_unload_idle or
727 ipp_ffl_curstate)
728 begin
729 ipp_ffl_req_n = 0;
730// geo: ipp_ffl_dvalid_n = 0;
731 hdr_count_n = 0;
732 hdr_rd_ptr_n = 0;
733 nex_state = ipp_ffl_curstate;
734
735 case(ipp_ffl_curstate) // synopsys parallel_case full_case
736 Idle:
737 begin
738 if ((start_hdr_xfer) && (~ffl_ipp_ready) && n_ipp_unload_idle)
739 begin
740 ipp_ffl_req_n = 1;
741 nex_state = Wait4rdy;
742 end
743 else if ((start_hdr_xfer) && (ffl_ipp_ready) && n_ipp_unload_idle)
744 begin
745 ipp_ffl_req_n = 1;
746 nex_state = Wait4ack;
747 end
748 else nex_state = ipp_ffl_curstate;
749 end
750
751 Wait4rdy:
752 begin
753 ipp_ffl_req_n = 1;
754
755 if (ffl_ipp_ready)
756 begin
757 nex_state = Wait4ack;
758 end
759 else
760 nex_state = ipp_ffl_curstate;
761 end
762
763 Wait4ack:
764 begin
765 ipp_ffl_req_n = 1;
766 hdr_rd_ptr_n = hdr_base_ptr;
767
768 if (ffl_arb_ack & ffl_ipp_ready)
769 nex_state = Hdr_xfer;
770 else
771 nex_state = ipp_ffl_curstate;
772 end
773
774 Hdr_xfer:
775 begin
776 ipp_ffl_req_n = 1;
777// geo: ipp_ffl_dvalid_n = ((hdr_count == 3'd0) | (hdr_count == 3'd1) |
778// geo: (hdr_count == 3'd2) |
779// geo: ((3'd2 < hdr_count) && (hdr_count < 3'd6) &&
780// geo: (~eop_from_hdr_fifo))
781// geo: );
782
783 if (ipp_ffl_dvalid_n)
784 begin
785 hdr_count_n = hdr_count + 1;
786 hdr_rd_ptr_n = hdr_rd_ptr + 1;
787 nex_state = ipp_ffl_curstate;
788 end
789 else
790 begin
791 ipp_ffl_req_n = 0;
792 hdr_count_n = 0;
793 hdr_rd_ptr_n = hdr_rd_ptr;
794 nex_state = Idle;
795 end
796 end
797 endcase
798 end // end of comb part
799
800// geo:
801 assign ipp_ffl_dvalid_n_nxt = (nex_state==Hdr_xfer) &&
802 ((hdr_count_n == 4'd0) | (hdr_count_n == 4'd1) |
803 (hdr_count_n == 4'd2) |
804 ((4'd2 < hdr_count_n) && (hdr_count_n < 4'd8) &&
805 (~eop_from_hdr_fifo))
806 );
807
808 assign ipp_ffl_dvalid = ipp_ffl_dvalid_n;
809
810 always @ (dec_hdr_ok_2xfer_cnt or hdr_ok_2xfer or hdr_ok_2xfer_cnt)
811 case ({dec_hdr_ok_2xfer_cnt,hdr_ok_2xfer}) // synopsys parallel_case
812 2'b00: n_hdr_ok_2xfer_cnt = hdr_ok_2xfer_cnt;
813 2'b01: n_hdr_ok_2xfer_cnt = hdr_ok_2xfer_cnt + 5'h1; // get 1
814 2'b10: n_hdr_ok_2xfer_cnt = hdr_ok_2xfer_cnt - 5'h1; // consume 1
815 2'b11: n_hdr_ok_2xfer_cnt = hdr_ok_2xfer_cnt;
816 default: n_hdr_ok_2xfer_cnt = hdr_ok_2xfer_cnt;
817 endcase
818
819 assign dec_hdr_ok_2xfer_cnt = (nex_state == Hdr_xfer) && (ipp_ffl_curstate != Hdr_xfer) && hdr_ok_2xfer_cnt_gt_eq_1;
820 assign start_hdr_xfer = hdr_ok_2xfer || hdr_ok_2xfer_cnt_gt_eq_1;
821
822
823always @(posedge clk)
824 if (reset)
825 begin
826 ipp_ffl_req <= 1'h0;
827//geo ipp_ffl_dvalid <= 1'h0;
828 hdr_count <= 4'h0;
829 hdr_rd_ptr <= 7'h0;
830 ipp_ffl_curstate <= 2'h0;
831 ipp_ffl_dvalid_n <= 1'h0;
832 ffl_ipp_dvalid_d <= 1'h0;
833 hdr_ok_2xfer_cnt <= 5'h0;
834 end
835 else
836 begin
837 ipp_ffl_req <= ipp_ffl_req_n;
838//geo ipp_ffl_dvalid <= ipp_ffl_dvalid_n;
839 hdr_count <= hdr_count_n[3:0];
840 hdr_rd_ptr <= hdr_rd_ptr_n[6:0];
841 ipp_ffl_curstate <= nex_state[1:0];
842 ipp_ffl_dvalid_n <= ipp_ffl_dvalid_n_nxt;
843 ffl_ipp_dvalid_d <= ffl_ipp_dvalid;
844 hdr_ok_2xfer_cnt <= n_hdr_ok_2xfer_cnt;
845 end
846
847//***********************************************
848//***** Control Word FIFO and related logic *****
849//***********************************************
850// Control word fifo can maintain up to 16 minimum size packet(64 bytes) which
851// equals to 1k size fifo.
852
853reg [11:0] ctlfifo [0:15]; // 12-bit by 16 deep
854reg [3:0] ctlfifo_wr_ptr;
855reg [3:0] ctlfifo_rd_ptr;
856
857assign ctlfifo_wr_en = wr_1st_data;
858/******** geo ************************************************************
859assign ctlfifo_wr_en = xmac_mode ? (mac_ipp_ctrl_reg & xmac_ipp_ack_d) :
860 (mac_ipp_ctrl_reg & ipp_mac_ack_d);
861*************************************************************************/
862
863
864//***** write to control word fifo
865always @ (posedge clk)
866 if (reset)
867 begin
868 ctlfifo[0] <= 0;
869 ctlfifo[1] <= 0;
870 ctlfifo[2] <= 0;
871 ctlfifo[3] <= 0;
872 ctlfifo[4] <= 0;
873 ctlfifo[5] <= 0;
874 ctlfifo[6] <= 0;
875 ctlfifo[7] <= 0;
876 ctlfifo[8] <= 0;
877 ctlfifo[9] <= 0;
878 ctlfifo[10] <= 0;
879 ctlfifo[11] <= 0;
880 ctlfifo[12] <= 0;
881 ctlfifo[13] <= 0;
882 ctlfifo[14] <= 0;
883 ctlfifo[15] <= 0;
884 end
885 else if (ctlfifo_wr_en)
886 ctlfifo[ctlfifo_wr_ptr] <= mac_ipp_ctl_reg[11:0];
887 else
888 ctlfifo[ctlfifo_wr_ptr] <= ctlfifo[ctlfifo_wr_ptr];
889
890//***** control word write pointer *****
891always @ (posedge clk)
892 if (reset)
893 ctlfifo_wr_ptr <= 0;
894 else
895 casex ({ctlfifo_wr_en, runt})
896 2'b00: ctlfifo_wr_ptr <= ctlfifo_wr_ptr;
897 2'b01: ctlfifo_wr_ptr <= ctlfifo_wr_ptr - 1; // rewind
898 2'b10: ctlfifo_wr_ptr <= ctlfifo_wr_ptr + 1; // increment
899 2'b11: ctlfifo_wr_ptr <= ctlfifo_wr_ptr;
900 endcase
901
902//***** control word read pointer by FFL *****
903ipp_falling_edge_puls_gen falling_edge_puls_gen_ctlfifo_rd_dn (.reset(reset),
904 .clk(clk), .signal_in(ipp_ffl_dvalid),
905 .puls_out(ctlfifo_rd_dn));
906
907always @ (posedge clk)
908 if (reset | ~ipp_enable)
909 ctlfifo_rd_ptr <= 0;
910 else if (ctlfifo_rd_dn)
911 ctlfifo_rd_ptr <= ctlfifo_rd_ptr + 1;
912 else
913 ctlfifo_rd_ptr <= ctlfifo_rd_ptr;
914
915// read from control word
916// {2'b00, mac_addr_index(6), defaultQPN(8), mode_bit(1), local_CPU(1),
917// ph_bit(1), mu_bit(1)}
918wire [11:0] ffl_ctl_word = ctlfifo[ctlfifo_rd_ptr];
919wire [11:0] ipp_ffl_mac_default = ffl_ctl_word[11:0];
920
921//***** end of control word fifo and related logic *****
922
923`ifdef NEPTUNE
924wire [3:0] do_nad;
925wire [3:0] do_nor;
926wire [3:0] do_inv;
927wire [3:0] do_mux;
928wire [3:0] do_q;
929wire so;
930
931 nep_spare_ipp spare_ipp_0 (
932 .di_nd3 ({1'h1, 1'h1, do_q[3]}),
933 .di_nd2 ({1'h1, 1'h1, do_q[2]}),
934 .di_nd1 ({1'h1, 1'h1, do_q[1]}),
935 .di_nd0 ({1'h1, 1'h1, do_q[0]}),
936 .di_nr3 ({1'h0, 1'h0}),
937 .di_nr2 ({1'h0, 1'h0}),
938 .di_nr1 ({1'h0, 1'h0}),
939 .di_nr0 ({1'h0, 1'h0}),
940 .di_inv (do_nad[3:0]),
941 .di_mx3 ({1'h0, 1'h0}),
942 .di_mx2 ({1'h0, 1'h0}),
943 .di_mx1 ({1'h0, 1'h0}),
944 .di_mx0 ({1'h0, 1'h0}),
945 .mx_sel (do_nor[3:0]),
946 .di_reg (do_inv[3:0]),
947 .wt_ena (do_mux[3:0]),
948 .rst ({reset,reset,reset,reset}),
949 .si (1'h0),
950 .se (1'h0),
951 .clk (clk),
952 .do_nad (do_nad[3:0]),
953 .do_nor (do_nor[3:0]),
954 .do_inv (do_inv[3:0]),
955 .do_mux (do_mux[3:0]),
956 .do_q (do_q[3:0]),
957 .so (so)
958 );
959`endif
960
961`ifdef NEP_SIM_MAC_IPP_PKT_CNT
962
963// synopsys translate_off
964
965wire tag2_acked;
966wire [15:0] mac_ipp_pkt_cnt;
967
968 ipp_tag_acked tag_acked_0 (
969 .filtered_tag (filtered_tag),
970 .mac_ipp_ctrl (mac_ipp_ctrl),
971 .xmac_mode (xmac_mode),
972 .xmac_ipp_ack (xmac_ipp_ack),
973 .ipp_mac_ack (ipp_mac_ack),
974 .reset (reset),
975 .clk (clk),
976 .tag2_acked (tag2_acked),
977 .mac_ipp_pkt_cnt (mac_ipp_pkt_cnt)
978 );
979// synopsys translate_on
980`endif
981
982
983endmodule // end of ipp_load
984//***** end of main program ************************************************
985
986
987/**************************************************************************
988* mac_ack_fsm: Use this state machine to count phases before packing data.
989**************************************************************************/
990module mac_ack_fsm (clk, reset, ipp_enable,
991 mac_ipp_req, mac_tag, fifo_rdy_4wr, tag_err_mac,
992 n_tag, nn_tag, set_tag_err_mac,
993 ipp_ack, cur_state);
994input clk;
995input reset;
996input ipp_enable;
997input mac_ipp_req;
998input mac_tag;
999input fifo_rdy_4wr;
1000input tag_err_mac;
1001
1002output n_tag;
1003output nn_tag;
1004output set_tag_err_mac;
1005output ipp_ack;
1006output [3:0] cur_state;
1007
1008reg n_tag;
1009reg nn_tag;
1010reg set_tag_err_mac;
1011reg ipp_ack;
1012reg [3:0] cur_state, nex_state;
1013
1014parameter idle = 4'h0;
1015parameter load_bop = 4'h1;
1016parameter load_1 = 4'h2;
1017parameter load_2 = 4'h3;
1018parameter load_3 = 4'h4;
1019parameter load_4 = 4'h5;
1020parameter last_detect = 4'h6;
1021parameter wait_req = 4'h7;
1022parameter wait_req_stat_1 = 4'h8;
1023parameter load_stat = 4'h9;
1024parameter bubble_mac = 4'hA;
1025parameter error = 4'hB;
1026
1027// Comb part
1028always @ (cur_state or mac_tag or tag_err_mac or ipp_enable or fifo_rdy_4wr
1029 or mac_ipp_req)
1030 begin
1031 ipp_ack = 0;
1032 nex_state = idle;
1033 n_tag = 0;
1034 nn_tag = 0;
1035 set_tag_err_mac = 0;
1036
1037 casex (cur_state) // synopsys parallel_case full_case
1038 idle: // 0
1039 if (tag_err_mac)
1040 begin
1041 set_tag_err_mac = 1;
1042 nex_state = error;
1043 end
1044 else if (ipp_enable && fifo_rdy_4wr && mac_ipp_req)
1045 begin
1046 ipp_ack = 1;
1047 nex_state = load_bop;
1048 end
1049 else
1050 nex_state = idle;
1051
1052 load_bop: // 1
1053 begin
1054 ipp_ack = 1;
1055 nex_state = load_2;
1056 end
1057
1058 load_1: // 2
1059 begin
1060 ipp_ack = 1;
1061 nex_state = load_2; // parallel with load_bop
1062 end
1063
1064 load_2: // 3
1065 begin
1066 if (mac_tag)
1067 begin
1068 n_tag = 1;
1069 nn_tag = 1;
1070 nex_state = idle;
1071 end
1072 else
1073 begin
1074 ipp_ack = 1;
1075 nex_state = load_3;
1076 end
1077 end
1078
1079 load_3: // 4
1080 begin
1081 if (mac_tag)
1082 begin
1083 n_tag = 1;
1084 nn_tag = 1;
1085 nex_state = idle;
1086 end
1087 else
1088 begin
1089 ipp_ack = 1;
1090 nex_state = load_4;
1091 end
1092 end
1093
1094 load_4: // 5
1095 begin
1096 if (mac_tag)
1097 begin
1098 n_tag = 1;
1099 nn_tag = 1;
1100 nex_state = idle;
1101 end
1102 else
1103 begin
1104 nex_state = last_detect;
1105 end
1106 end
1107
1108 last_detect: // 6
1109 begin
1110 if (mac_tag)
1111 begin
1112 n_tag = 1;
1113 nex_state = wait_req_stat_1;
1114 end
1115 else
1116 nex_state = wait_req;
1117 end
1118
1119 wait_req: // 7
1120 begin
1121 if (~ipp_enable)
1122 nex_state = wait_req;
1123 else if (fifo_rdy_4wr && mac_ipp_req)
1124 begin
1125 ipp_ack = 1;
1126 nex_state = load_1;
1127 end
1128 else
1129 nex_state = wait_req;
1130 end
1131
1132 wait_req_stat_1: // 8
1133 begin
1134 if (~ipp_enable)
1135 nex_state = wait_req_stat_1;
1136 else if (fifo_rdy_4wr && mac_ipp_req)
1137 begin
1138 ipp_ack = 1;
1139 nex_state = load_stat;
1140 end
1141 else
1142 nex_state = wait_req_stat_1;
1143 end
1144
1145 load_stat: // 9
1146 begin
1147 nn_tag = 1;
1148 nex_state = bubble_mac;
1149 end
1150
1151/* This state only exists because there is a bug in the big mac which no one
1152 ** can fix. The MAC continues to assert request a cycle after the ack has been
1153 ** asserted and deasserted. However, it does not want to transfer more data.
1154 ** This bubble exists in order to ignore this extraneous request.
1155 */
1156 bubble_mac: // A
1157 if (tag_err_mac)
1158 begin
1159 set_tag_err_mac = 1;
1160 nex_state = error;
1161 end
1162 else
1163 nex_state = idle;
1164
1165 error: // B
1166 nex_state = error;
1167
1168/*geo*/ default: nex_state = idle;
1169
1170 endcase
1171 end // end of comb part
1172
1173// Seq part
1174always @ (posedge clk)
1175 if (reset)
1176 cur_state <= 4'b0;
1177 else
1178 cur_state <= nex_state;
1179
1180endmodule // end of mac_ack_fsm module
1181
1182
1183/**********************************************************************
1184* phase_sm0: Use this state machine to count phases after packing data.
1185 and generate the load_fifo for xmac
1186**********************************************************************/
1187module phase_sm0 (clk, reset, valid, eop, phase_state, load_fifo, swap);
1188
1189input clk;
1190input reset;
1191input valid;
1192input [1:0] eop;
1193output [2:0] phase_state;
1194output load_fifo;
1195output swap;
1196
1197reg [2:0] phase_state;
1198reg [2:0] nx_phase_state;
1199reg load_fifo;
1200reg swap;
1201
1202parameter NO_ACK = 3'h0;
1203parameter WAIT_2ND_TAG = 3'h1;
1204parameter WAIT_2ND_ACK = 3'h2;
1205parameter LAST_TAG = 3'h3;
1206parameter STATUS = 3'h4;
1207parameter ERROR = 3'h5;
1208
1209// Comb part
1210always @ (phase_state or valid or eop)
1211 begin
1212 load_fifo = 1'b0;
1213 swap = 1'b0;
1214 nx_phase_state = 3'b0;
1215
1216 case (phase_state) // synopsys parallel_case full_case
1217 NO_ACK: // 3'h0
1218 case (valid)
1219 1'b0: nx_phase_state = phase_state; // stay
1220 1'b1: begin
1221 if (eop == 2'b00)
1222 nx_phase_state = WAIT_2ND_ACK; // 3'h2
1223 else if (eop == 2'b10)
1224 nx_phase_state = WAIT_2ND_TAG; // 3'h1
1225 else
1226 nx_phase_state = ERROR;
1227// $display("Error: wrong state at NO_ACK of phase_sm at simtime = %d", $stime);
1228 end
1229 endcase
1230
1231 WAIT_2ND_TAG: // 3'h1
1232 if (eop == 2'b01)
1233 begin
1234 load_fifo = 1'b1;
1235 nx_phase_state = NO_ACK; // 3'h0
1236 end
1237 else if ((valid) && (eop == 2'b11))
1238 begin
1239 load_fifo = 1'b1;
1240 nx_phase_state = NO_ACK; // 3'h0
1241 end
1242 else
1243 nx_phase_state = ERROR;
1244// $display("Error: wrong state at WAIT_2ND_TAG of phase_sm at simtime= %d", $stime);
1245
1246 WAIT_2ND_ACK: // 3'h2
1247 case (valid)
1248 1'b0: nx_phase_state = phase_state; // stay
1249 1'b1: begin
1250 load_fifo = 1'b1;
1251
1252 if (eop == 2'b10)
1253 nx_phase_state = LAST_TAG; // 3'h3
1254 else if (eop == 2'b00)
1255 nx_phase_state = NO_ACK; // 3'h0
1256 else
1257 nx_phase_state = ERROR;
1258// $display("Error: wrong state at WAIT_2ND_ACK of phase_sm at simtime = %d", $stime);
1259 end
1260 endcase
1261
1262 LAST_TAG: // 3'h3
1263 case (valid)
1264 1'b0: begin
1265 if (eop == 2'b01)
1266 nx_phase_state = NO_ACK; // 3'h0
1267 else
1268 nx_phase_state = phase_state; // stay
1269 end
1270 1'b1: begin
1271 if (eop == 2'b11)
1272 begin
1273 swap = 1'b1;
1274 nx_phase_state = STATUS; // 3'h4
1275 end
1276 else
1277 nx_phase_state = ERROR;
1278// $display("Error: wrong state at LAST_TAG of phase_sm at simtime = %d", $stime);
1279 end
1280 endcase
1281
1282 STATUS: // 3'h4
1283 begin
1284 load_fifo = 1'b1;
1285 nx_phase_state = NO_ACK; // 3'h0
1286 end
1287
1288 ERROR: // 3'h5
1289 begin
1290// $display("E-rror: wrong state at phase_sm at simtime = %d", $stime);
1291 nx_phase_state = ERROR;
1292 end
1293
1294/*geo*/ default: nx_phase_state = NO_ACK;
1295
1296 endcase // case(phase_state)
1297 end // end of comb part
1298
1299// Seq part
1300
1301always @ (posedge clk)
1302 if (reset)
1303 phase_state <= 3'b0;
1304 else
1305 phase_state <= nx_phase_state;
1306
1307endmodule // end of phase_sm0 module
1308
1309
1310/**********************************************************************
1311* phase_sm: Use this state machine to count phases after packing data.
1312 and generate the load_fifo for bmac
1313**********************************************************************/
1314module phase_sm (clk, reset, valid, eop, phase_state, load_fifo);
1315
1316input clk;
1317input reset;
1318input valid;
1319input [1:0] eop;
1320output [2:0] phase_state;
1321output load_fifo;
1322
1323reg [2:0] phase_state;
1324reg [2:0] nx_phase_state;
1325reg load_fifo;
1326
1327parameter NO_ACK = 3'h0;
1328parameter WAIT_2ND_TAG = 3'h1;
1329parameter WAIT_2ND_ACK = 3'h2;
1330parameter LAST_TAG = 3'h3;
1331parameter STATUS = 3'h4;
1332parameter ERROR = 3'h5;
1333
1334// Comb part
1335always @ (phase_state or valid or eop)
1336 begin
1337 load_fifo = 1'b0;
1338 nx_phase_state = 0;
1339
1340 case (phase_state) // synopsys parallel_case full_case
1341 NO_ACK: // 3'h0
1342 case (valid)
1343 1'b0: nx_phase_state = phase_state; // stay
1344 1'b1: begin
1345 if (eop == 2'b00)
1346 nx_phase_state = WAIT_2ND_ACK; // 3'h2
1347 else if (eop == 2'b10)
1348 nx_phase_state = WAIT_2ND_TAG; // 3'h1
1349 else
1350 nx_phase_state = ERROR;
1351// $display("Error: wrong state at NO_ACK of phase_sm at simtime = %d", $stime);
1352 end
1353 endcase
1354
1355 WAIT_2ND_TAG: // 3'h1
1356 if (eop == 2'b01)
1357 begin
1358 load_fifo = 1'b1;
1359 nx_phase_state = NO_ACK; // 3'h0
1360 end
1361 else if ((valid) && (eop == 2'b11))
1362 begin
1363 load_fifo = 1'b1;
1364 nx_phase_state = NO_ACK; // 3'h0
1365 end
1366 else
1367 nx_phase_state = ERROR;
1368// $display("Error: wrong state at WAIT_2ND_TAG of phase_sm at simtime = %d", $stime);
1369
1370 WAIT_2ND_ACK: // 3'h2
1371 case (valid)
1372 1'b0: nx_phase_state = phase_state; // stay
1373 1'b1: begin
1374 load_fifo = 1'b1;
1375
1376 if (eop == 2'b10)
1377 nx_phase_state = LAST_TAG; // 3'h3
1378 else if (eop == 2'b00)
1379 nx_phase_state = NO_ACK; // 3'h0
1380 else
1381 nx_phase_state = ERROR;
1382// $display("Error: wrong state at WAIT_2ND_ACK of phase_sm at simtime = %d", $stime);
1383 end
1384 endcase
1385
1386 LAST_TAG: // 3'h3
1387 case (valid)
1388 1'b0: begin
1389 if (eop == 2'b01)
1390 nx_phase_state = NO_ACK; // 3'h0
1391 else
1392 nx_phase_state = phase_state; // stay
1393 end
1394 1'b1: begin
1395 if (eop == 2'b11)
1396 nx_phase_state = STATUS; // 3'h4
1397 else
1398 nx_phase_state = ERROR;
1399// $display("Error: wrong state at LAST_TAG of phase_sm at simtime = %d", $stime);
1400 end
1401 endcase
1402
1403 STATUS: // 3'h4
1404 if (eop == 2'b01)
1405 begin
1406 load_fifo = 1'b1;
1407 nx_phase_state = NO_ACK; // 3'h0
1408 end
1409 else
1410 nx_phase_state = ERROR;
1411// $display("Error: wrong state at STATUS of phase_sm at simtime = %d", $stime);
1412
1413 ERROR: // 3'h5
1414 begin
1415// $display("E-rror: wrong state at phase_sm at simtime = %d", $stime);
1416 nx_phase_state = ERROR;
1417 end
1418
1419/*geo*/ default: nx_phase_state = NO_ACK;
1420
1421 endcase // case(phase_state)
1422 end // end of comb part
1423
1424// Seq part
1425
1426always @ (posedge clk)
1427 if (reset)
1428 phase_state <= 3'b0;
1429 else
1430 phase_state <= nx_phase_state;
1431
1432endmodule // end of phase_sm module
1433
1434
1435/**********************************************************************
1436* phase_sm3: Use this state machine to generate the wr_1st_data
1437**********************************************************************/
1438module phase_sm3 (clk, reset, valid, eop, phase_state, wr_1st_data);
1439
1440input clk;
1441input reset;
1442input valid;
1443input eop;
1444output phase_state;
1445output wr_1st_data;
1446
1447reg phase_state;
1448reg nx_phase_state;
1449reg wr_1st_data;
1450
1451parameter IDLE = 1'b0;
1452parameter WAIT4TAG = 1'b1;
1453
1454// Comb part
1455always @ (phase_state or valid or eop )
1456 begin
1457 wr_1st_data = 0;
1458 nx_phase_state = 0;
1459
1460 case (phase_state) // synopsys parallel_case full_case
1461 IDLE:
1462 casex (valid)
1463 1'b0: nx_phase_state = phase_state; // stay
1464 1'b1: begin
1465 nx_phase_state = WAIT4TAG;
1466 wr_1st_data = 1;
1467 end
1468 endcase
1469
1470 WAIT4TAG:
1471 casex (eop)
1472 1'b0: nx_phase_state = phase_state; // stay
1473 1'b1: nx_phase_state = IDLE;
1474 endcase
1475
1476 endcase // case(phase_state)
1477 end // end of comb part
1478
1479// Seq part
1480
1481always @ (posedge clk)
1482 if (reset)
1483 phase_state <= 1'b0;
1484 else
1485 phase_state <= nx_phase_state;
1486
1487endmodule // end of phase_sm3 module
1488
1489
1490//////////////////////////////////////////////////////////////////
1491`ifdef NEP_SIM_MAC_IPP_PKT_CNT
1492module ipp_tag_acked (
1493 filtered_tag,
1494 mac_ipp_ctrl,
1495 xmac_mode,
1496 xmac_ipp_ack,
1497 ipp_mac_ack,
1498 reset,
1499 clk,
1500 tag2_acked,
1501 mac_ipp_pkt_cnt
1502 );
1503
1504input filtered_tag;
1505input mac_ipp_ctrl;
1506input xmac_mode;
1507input xmac_ipp_ack;
1508input ipp_mac_ack;
1509input reset;
1510input clk;
1511output tag2_acked;
1512output [15:0] mac_ipp_pkt_cnt;
1513
1514wire tag2_acked;
1515reg [15:0] mac_ipp_pkt_cnt;
1516
1517wire [15:0] mac_ipp_pkt_cnt_nxt;
1518
1519reg [1:0] tag_acked_cnt;
1520reg [1:0] tag_acked_cnt_nxt;
1521
1522reg inc_mac_ipp_pkt_cnt;
1523reg inc_mac_ipp_pkt_cnt_nxt;
1524
1525wire macipp_ack = xmac_mode ? xmac_ipp_ack : ipp_mac_ack;
1526
1527 always @ (filtered_tag or
1528 xmac_mode or
1529 tag_acked_cnt) begin
1530
1531 tag_acked_cnt_nxt = 2'h0;
1532 inc_mac_ipp_pkt_cnt_nxt = 1'h0;
1533
1534 case (tag_acked_cnt) // synopsys parallel_case full_case
1535
1536 2'h0: begin
1537 if (filtered_tag) begin
1538 inc_mac_ipp_pkt_cnt_nxt = 1'h1;
1539 tag_acked_cnt_nxt = xmac_mode ? 2'h2 : 2'h1;
1540 end
1541 else begin
1542 tag_acked_cnt_nxt = tag_acked_cnt;
1543 end
1544 end
1545
1546 2'h1: begin
1547 if (filtered_tag) begin
1548 tag_acked_cnt_nxt = 2'h2;
1549 end
1550 else begin
1551 tag_acked_cnt_nxt = tag_acked_cnt;
1552 end
1553 end
1554
1555 2'h2: begin
1556 tag_acked_cnt_nxt = 2'h0;
1557 end
1558
1559 default: tag_acked_cnt_nxt = 2'h0;
1560
1561 endcase
1562
1563 end
1564
1565 assign tag2_acked = tag_acked_cnt_nxt[1];
1566 assign mac_ipp_pkt_cnt_nxt = mac_ipp_pkt_cnt[15:0] + {15'h0,inc_mac_ipp_pkt_cnt};
1567
1568 always @(posedge clk) begin
1569 if (reset || mac_ipp_ctrl && macipp_ack) begin
1570 tag_acked_cnt <= #1 2'h0;
1571 end
1572 else begin
1573 tag_acked_cnt <= #1 tag_acked_cnt_nxt[1:0];
1574 end
1575 end
1576
1577 always @(posedge clk) begin
1578 if (reset) begin
1579 inc_mac_ipp_pkt_cnt <= #1 1'h0;
1580 mac_ipp_pkt_cnt <= #1 16'h0;
1581 end
1582 else begin
1583 inc_mac_ipp_pkt_cnt <= #1 inc_mac_ipp_pkt_cnt_nxt;
1584 mac_ipp_pkt_cnt <= #1 mac_ipp_pkt_cnt_nxt[15:0];
1585 end
1586 end
1587
1588// synopsys translate_on
1589
1590endmodule
1591`endif