Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: bw_calc.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 | module bw_calc (/*AUTOARG*/ | |
36 | // Inputs | |
37 | clk, data, enb, port_num, no_of_pkts, pkt_len, cal_enb, | |
38 | speed_10G); | |
39 | ||
40 | input clk; | |
41 | input [7:0] data; | |
42 | input enb; | |
43 | input cal_enb; | |
44 | input speed_10G; | |
45 | input [1:0] port_num; | |
46 | input [15:0] no_of_pkts; | |
47 | input [15:0] pkt_len; | |
48 | ||
49 | ||
50 | reg [1:0] bw_state; | |
51 | reg [1:0] nxt_state; | |
52 | integer data_byte_cnt; | |
53 | integer ipg_byte_cnt; | |
54 | real BW; | |
55 | real BW_d; | |
56 | real BW_in_pkts; | |
57 | real avg_ipg_byte_cnt; | |
58 | real bw_start_time; | |
59 | real bw_end_time; | |
60 | integer pkt_cnt; | |
61 | integer no_of_txpkts; | |
62 | integer packet_len; | |
63 | real delta_time; | |
64 | real delta_time1; | |
65 | integer count; | |
66 | reg [8*60:1] arg; | |
67 | integer host_dly; | |
68 | ||
69 | // initial for defaulting the values | |
70 | initial | |
71 | begin | |
72 | bw_state = 2'b00; | |
73 | end | |
74 | ||
75 | // initial block for getting the latency number | |
76 | ||
77 | initial | |
78 | begin | |
79 | arg = "SIU_REQ_DLY="; | |
80 | if($test$plusargs("SIU_REQ_DLY=")) begin | |
81 | `ifdef AXIS | |
82 | `else | |
83 | host_dly = $util_get_plus_args_num(arg); | |
84 | `endif | |
85 | $display("BW_CALC: Host_dly %0d\n",host_dly); | |
86 | end | |
87 | end | |
88 | ||
89 | ||
90 | ||
91 | always @(nxt_state) | |
92 | bw_state = nxt_state; | |
93 | ||
94 | always @(posedge clk) | |
95 | begin | |
96 | if(cal_enb && speed_10G) | |
97 | calc_BW(bw_state,data,enb,port_num,no_of_pkts,pkt_len,nxt_state); | |
98 | else if(cal_enb && ~speed_10G) | |
99 | calc_BW_1G(bw_state,data,enb,port_num,no_of_pkts,pkt_len,nxt_state); | |
100 | end | |
101 | ||
102 | ||
103 | ||
104 | task calc_BW; | |
105 | ||
106 | input [1:0] bw_state; | |
107 | input [7:0] data; | |
108 | input enb; | |
109 | input [1:0] port_num; | |
110 | input [15:0] no_of_pkts; | |
111 | input [15:0] pkt_len; | |
112 | ||
113 | output [1:0] nxt_state; | |
114 | ||
115 | case(bw_state) | |
116 | 2'b00 : begin | |
117 | if((data == 8'hfb) && (enb == 1)) begin | |
118 | nxt_state = 2'b01; | |
119 | bw_start_time = $time; | |
120 | $display("BW_CALC : START_TIME in BW %t for PORT %0d",bw_start_time,port_num); | |
121 | end // if ((data == 8'hfb) && (enb == 1)) | |
122 | else begin | |
123 | nxt_state = 2'b00; | |
124 | pkt_cnt = 0; | |
125 | data_byte_cnt = 0; | |
126 | ipg_byte_cnt = 0; | |
127 | avg_ipg_byte_cnt = 0; | |
128 | bw_start_time = 0; | |
129 | bw_end_time = 0; | |
130 | no_of_txpkts = no_of_pkts; | |
131 | packet_len = pkt_len; | |
132 | delta_time = 0; | |
133 | end // else: !if((data == 8'hfb) && (enb == 1)) | |
134 | end // case: 2'b00 | |
135 | 2'b01 : begin | |
136 | if((data == 8'hfd) && (enb == 1)) begin | |
137 | pkt_cnt = pkt_cnt + 1; | |
138 | if(pkt_cnt == no_of_txpkts) begin | |
139 | nxt_state = 2'b00; | |
140 | bw_end_time = $time; | |
141 | ||
142 | delta_time = (bw_end_time - bw_start_time)/1000000; | |
143 | delta_time1 = (bw_end_time - bw_start_time); | |
144 | $display("BW_CALC : DELTA_TIME in BW %t for PORT %0d",delta_time1,port_num); | |
145 | $display("BW_CALC : END_TIME in BW %t for PORT %0d",bw_end_time,port_num); | |
146 | ||
147 | avg_ipg_byte_cnt = ipg_byte_cnt/no_of_pkts; | |
148 | $display("BW_CALC : Avg_ipg_byte_cnt is %0f for PORT %0d",avg_ipg_byte_cnt,port_num); | |
149 | ||
150 | // print the BW calculated | |
151 | BW = 8*no_of_pkts*1000*(packet_len + 8 + avg_ipg_byte_cnt)/delta_time1; | |
152 | $display("BW_CALC: BW_ON_WIRE is %0f Gigabits/sec for Port %0d",BW,port_num); | |
153 | ||
154 | BW_d = 8*no_of_pkts*1000*packet_len/delta_time1; | |
155 | $display("BW_CALC: BW_DATA is %0f Gigabits/sec for Port %0d",BW_d,port_num); | |
156 | ||
157 | BW_in_pkts = no_of_pkts/delta_time; | |
158 | $display("BW_CALC : BW_IN_PKTS for port %0d is %f Million_pkts/sec",port_num,BW_in_pkts); | |
159 | ||
160 | if(packet_len == 64) begin | |
161 | if(BW_in_pkts < 14.88) begin | |
162 | if(host_dly < 140) | |
163 | $display("BW_CALC : ERROR BW less than expected for port %0d",port_num); | |
164 | else | |
165 | $display("BW_CALC : Warning BW less than expected for port %0d",port_num); | |
166 | end | |
167 | end | |
168 | else if(packet_len == 1518) begin | |
169 | if(BW_in_pkts < 0.8) | |
170 | $display("BW_CALC : ERROR BW less than expected for port %0d",port_num); | |
171 | end | |
172 | else if(packet_len == 9588) begin | |
173 | if(BW_in_pkts < 0.1301) | |
174 | $display("BW_CALC : ERROR BW less than expected for port %0d",port_num); | |
175 | end | |
176 | end | |
177 | else | |
178 | nxt_state = 2'b10; | |
179 | end | |
180 | else begin | |
181 | data_byte_cnt = data_byte_cnt + 1; | |
182 | nxt_state = 2'b01; | |
183 | end | |
184 | end | |
185 | 2'b10 : begin | |
186 | if((data == 8'hfb) && (enb == 1)) | |
187 | nxt_state = 2'b01; | |
188 | else begin | |
189 | ipg_byte_cnt = ipg_byte_cnt + 1; | |
190 | avg_ipg_byte_cnt = ipg_byte_cnt/no_of_pkts; | |
191 | nxt_state = 2'b10; | |
192 | end | |
193 | end | |
194 | endcase | |
195 | endtask | |
196 | ||
197 | task calc_BW_1G; | |
198 | ||
199 | input [1:0] bw_state; | |
200 | input [7:0] data; | |
201 | input enb; | |
202 | input [1:0] port_num; | |
203 | input [15:0] no_of_pkts; | |
204 | input [15:0] pkt_len; | |
205 | ||
206 | output [1:0] nxt_state; | |
207 | ||
208 | case(bw_state) | |
209 | 2'b00 : begin | |
210 | if(enb == 1'b1) begin | |
211 | nxt_state = 2'b01; | |
212 | bw_start_time = $time; | |
213 | $display("BW_CALC_1G : START_TIME in BW %t for PORT %0d",bw_start_time,port_num); | |
214 | end | |
215 | else begin | |
216 | nxt_state = 2'b00; | |
217 | pkt_cnt = 0; | |
218 | data_byte_cnt = 0; | |
219 | ipg_byte_cnt = 0; | |
220 | avg_ipg_byte_cnt = 0; | |
221 | bw_start_time = 0; | |
222 | bw_end_time = 0; | |
223 | no_of_txpkts = no_of_pkts; | |
224 | packet_len = pkt_len; | |
225 | delta_time = 0; | |
226 | count = 0; | |
227 | end | |
228 | end | |
229 | 2'b01 : begin // check for frame delimiter in this state | |
230 | if(enb) begin | |
231 | // $display("BW_CALC_1G : COUNT in BW %0d for PORT %0d",count,port_num); | |
232 | // $display("BW_CALC_1G : data in BW %0h for PORT %0d",data,port_num); | |
233 | if(count < 6) begin | |
234 | nxt_state = 2'b01; | |
235 | count = count + 1; | |
236 | end | |
237 | else if((data == 8'hd5) && (count == 6)) begin | |
238 | nxt_state = 2'b10; | |
239 | count = 0; | |
240 | end | |
241 | else begin | |
242 | nxt_state = 2'b00; | |
243 | bw_start_time = 0; | |
244 | end | |
245 | end | |
246 | else nxt_state = 2'b00; | |
247 | end | |
248 | 2'b10 : begin | |
249 | if(enb == 1'b0) begin | |
250 | pkt_cnt = pkt_cnt + 1; | |
251 | if(pkt_cnt == no_of_txpkts) begin | |
252 | nxt_state = 2'b00; | |
253 | bw_end_time = $time; | |
254 | ||
255 | delta_time = (bw_end_time - bw_start_time)/1000000; | |
256 | delta_time1 = (bw_end_time - bw_start_time); | |
257 | $display("BW_CALC_1G : END_TIME in BW %t for PORT %0d",bw_end_time,port_num); | |
258 | ||
259 | avg_ipg_byte_cnt = ipg_byte_cnt/no_of_pkts; | |
260 | $display("BW_CALC_1G : Avg_ipg_per_pkt is %0f for PORT %0d",avg_ipg_byte_cnt,port_num); | |
261 | ||
262 | // print the BW calculated | |
263 | BW = (8*no_of_pkts*1000)*(packet_len + 8 + avg_ipg_byte_cnt)/delta_time1; | |
264 | $display("BW_CALC_1G : BW_ON_WIRE is %0f Gigabits/sec for Port %0d",BW,port_num); | |
265 | ||
266 | BW_d = (8*no_of_pkts*1000*packet_len)/delta_time1; | |
267 | $display("BW_CALC_1G : BW_DATA is %0f Gigabits/sec for Port %0d",BW_d,port_num); | |
268 | ||
269 | BW_in_pkts = no_of_pkts/delta_time; | |
270 | $display("BW_CALC_1G : BW_IN_PKTS for port %0d is %f Million_pkts/sec",port_num,BW_in_pkts); | |
271 | ||
272 | if(packet_len == 64) begin | |
273 | if(BW_in_pkts < 15) | |
274 | $display("BW_CALC_1G : ERROR BW less than expected for port %0d",port_num); | |
275 | end | |
276 | else if(packet_len == 1518) begin | |
277 | if(BW_in_pkts < 0.8) | |
278 | $display("BW_CALC_1G : ERROR BW less than expected for port %0d",port_num); | |
279 | end | |
280 | end | |
281 | else begin | |
282 | nxt_state = 2'b11; | |
283 | ipg_byte_cnt = ipg_byte_cnt + 1; | |
284 | end | |
285 | end | |
286 | else begin | |
287 | data_byte_cnt = data_byte_cnt + 1; | |
288 | nxt_state = 2'b10; | |
289 | end | |
290 | end | |
291 | 2'b11 : begin | |
292 | if(~enb) begin | |
293 | nxt_state = 2'b11; | |
294 | ipg_byte_cnt = ipg_byte_cnt + 1; | |
295 | end | |
296 | else | |
297 | nxt_state = 2'b01; | |
298 | end | |
299 | endcase | |
300 | endtask | |
301 | ||
302 | ||
303 | endmodule // bw_calc | |
304 | ||
305 | ||
306 |