Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / niu / rtl / ipg_checker.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: ipg_checker.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/*%W% %G%*/
36
37/*******************************************************************
38 *
39 * File Name : ipg_checker.v
40 * Author Name : John Lo
41 * Description : For checking variable ipg.
42 * Parent Module: xmac
43 * Child Module:
44 * Interface Mod:
45 * Date Created : 3/24/04
46 *
47 * Copyright (c) 2020, Sun Microsystems, Inc.
48 * Sun Proprietary and Confidential
49 *
50 *
51 * Modification :
52 *
53 * Synthesis Notes:
54 *
55 ******************************************************************/
56
57`include "xmac.h"
58
59module ipg_checker (
60 tx_clk,
61 tx_reset,
62 xgmii_txc,
63 xgmii_txd,
64 var_min_ipg_en,
65 add_crc,
66 eop_txclk,
67 B_eop,
68 stretch_mode,
69 warning_msg_en
70 );
71 input tx_clk;
72 input tx_reset;
73 input [3:0] xgmii_txc;
74 input [31:0] xgmii_txd;
75 input var_min_ipg_en;
76 input add_crc;
77 input eop_txclk;
78 input B_eop;
79 input stretch_mode;
80 input warning_msg_en;
81
82 wire dly1_tx_clk;
83 wire dly2_tx_clk;
84 wire x2_tx_clk;
85 wire x2_tx_reset;
86 wire ipg_count_en_temp;
87 wire ipg_count_en;
88 wire T_det;
89 wire S_det;
90 wire store_ipg_time;
91 reg check_ipg_time;
92 reg [`BYTE] ipg_count;
93 reg [`BYTE] ipg_net_credit;
94 reg [`BYTE] stored_ipg_count;
95 reg [3:0] itxc;
96 reg [31:0] itxd;
97
98
99
100 SYNC_CELL SYNC_X2_TX_RESET(.D(tx_reset),.CP(x2_tx_clk),.Q(x2_tx_reset));
101 assign #1 dly1_tx_clk = tx_clk;
102 assign #1 dly2_tx_clk = dly1_tx_clk;
103 assign x2_tx_clk = dly1_tx_clk ^ dly2_tx_clk;
104
105 always @ (posedge x2_tx_clk)
106 if (x2_tx_reset)
107 begin
108 itxc <= 0;
109 itxd <= 0;
110 end // if (!tx_reset_n)
111 else
112 begin
113 itxc <= xgmii_txc;
114 itxd <= xgmii_txd;
115 end
116
117 assign T_det =
118 itxc[0] & (itxd[`BYTE0] == `T) | // lane0
119 itxc[1] & (itxd[`BYTE1] == `T) | // lane1
120 itxc[2] & (itxd[`BYTE2] == `T) | // lane2
121 itxc[3] & (itxd[`BYTE3] == `T) ; // lane3
122
123 assign S_det = itxc[0] & (itxd[`BYTE0] == `S); // lane0
124
125
126RSFF ipg_count_en_RSFF(.reset(x2_tx_reset),
127 .clk( x2_tx_clk),
128 .iSet(T_det),
129 .iRst(S_det),
130 .oQ(ipg_count_en_temp));
131
132assign ipg_count_en = (ipg_count_en_temp | T_det) & (~S_det);
133
134PlsGen2 store_ipg_time_PlsGen2(
135 .sig_in(ipg_count_en),
136 .clk(x2_tx_clk),
137 .lead(),.trail(store_ipg_time));
138
139 wire [`BYTE] itxc_bit0 = {7'b0,itxc[0]};
140 wire [`BYTE] itxc_bit1 = {7'b0,itxc[1]};
141 wire [`BYTE] itxc_bit2 = {7'b0,itxc[2]};
142 wire [`BYTE] itxc_bit3 = {7'b0,itxc[3]};
143
144 wire [`BYTE] itxc_count = itxc_bit0 + itxc_bit1 + itxc_bit2 + itxc_bit3;
145
146always @ (posedge x2_tx_clk)
147 check_ipg_time <= store_ipg_time;
148
149
150always @ (posedge x2_tx_clk)
151 if (x2_tx_reset | store_ipg_time)
152 ipg_count <= 0;
153 else if (ipg_count_en)
154 ipg_count <= itxc_count + ipg_count;
155 else
156 ipg_count <= ipg_count;
157
158always @ (posedge x2_tx_clk)
159 if (x2_tx_reset)
160 stored_ipg_count <= 0;
161 else if (store_ipg_time)
162 stored_ipg_count <= ipg_count;
163 else
164 stored_ipg_count <= stored_ipg_count;
165
166always @ (posedge x2_tx_clk)
167 if (x2_tx_reset)
168 ipg_net_credit <= `CREDIT_BIAS;
169 else if (store_ipg_time)
170 begin
171 if (ipg_count >= `CREDIT_BIAS)
172 ipg_net_credit <= ipg_net_credit + (ipg_count - `CREDIT_BIAS);
173 else
174 ipg_net_credit <= ipg_net_credit - (`CREDIT_BIAS - ipg_count);
175 end
176 else ipg_net_credit <= ipg_net_credit;
177
178 wire stored_add_crc;
179 wire stored_B_eop;
180
181xREG #(1) stored_add_crc_xREG(.din(add_crc),
182 .clk(x2_tx_clk),
183 .en(eop_txclk),
184 .reset(x2_tx_reset),
185 .qout(stored_add_crc));
186
187xREG #(1) stored_B_eop_xREG(.din(B_eop),
188 .clk(x2_tx_clk),
189 .en(eop_txclk),
190 .reset(x2_tx_reset),
191 .qout(stored_B_eop));
192
193always @ (negedge check_ipg_time) // LAN mode only
194 begin
195 if (warning_msg_en & (~x2_tx_reset) & var_min_ipg_en & (~stretch_mode) &
196 ((stored_ipg_count < 9) | (stored_ipg_count > 15)))
197 $display(" \n(* ERROR: at sim time = %d, from ipg_checker module, the ipg_checker has detected incorrect ipg value, stored_ipg_count = %d *)", $time, stored_ipg_count);
198 else ;
199 end
200
201
202always @ (negedge check_ipg_time)
203 begin
204 if (warning_msg_en & ~x2_tx_reset)
205 begin
206 if (stretch_mode) // WAN mode
207 $display("\n (* WARNING: from ipg_checker module, stored_ipg_count = %d, stored_add_crc = %h, stored_B_eop = %h, at sim time = %d, *)", stored_ipg_count,stored_add_crc, stored_B_eop, $time);
208 else // LAN mode
209 $display("\n (* WARNING: from ipg_checker module, stored_ipg_count = %d, ipg_net_credit = %d, stored_add_crc = %h, stored_B_eop = %h, at sim time = %d, *)", stored_ipg_count, ipg_net_credit, stored_add_crc, stored_B_eop, $time);
210 end
211 else ;
212 end
213
214endmodule // ipg_checker
215