// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: bw_calc.v
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
module bw_calc (/*AUTOARG*/
clk, data, enb, port_num, no_of_pkts, pkt_len, cal_enb,
// initial for defaulting the values
// initial block for getting the latency number
if($test$plusargs("SIU_REQ_DLY=")) begin
host_dly = $util_get_plus_args_num(arg);
$display("BW_CALC: Host_dly %0d\n",host_dly);
calc_BW(bw_state,data,enb,port_num,no_of_pkts,pkt_len,nxt_state);
else if(cal_enb && ~speed_10G)
calc_BW_1G(bw_state,data,enb,port_num,no_of_pkts,pkt_len,nxt_state);
if((data == 8'hfb) && (enb == 1)) begin
$display("BW_CALC : START_TIME in BW %t for PORT %0d",bw_start_time,port_num);
end // if ((data == 8'hfb) && (enb == 1))
no_of_txpkts = no_of_pkts;
end // else: !if((data == 8'hfb) && (enb == 1))
if((data == 8'hfd) && (enb == 1)) begin
if(pkt_cnt == no_of_txpkts) begin
delta_time = (bw_end_time - bw_start_time)/1000000;
delta_time1 = (bw_end_time - bw_start_time);
$display("BW_CALC : DELTA_TIME in BW %t for PORT %0d",delta_time1,port_num);
$display("BW_CALC : END_TIME in BW %t for PORT %0d",bw_end_time,port_num);
avg_ipg_byte_cnt = ipg_byte_cnt/no_of_pkts;
$display("BW_CALC : Avg_ipg_byte_cnt is %0f for PORT %0d",avg_ipg_byte_cnt,port_num);
// print the BW calculated
BW = 8*no_of_pkts*1000*(packet_len + 8 + avg_ipg_byte_cnt)/delta_time1;
$display("BW_CALC: BW_ON_WIRE is %0f Gigabits/sec for Port %0d",BW,port_num);
BW_d = 8*no_of_pkts*1000*packet_len/delta_time1;
$display("BW_CALC: BW_DATA is %0f Gigabits/sec for Port %0d",BW_d,port_num);
BW_in_pkts = no_of_pkts/delta_time;
$display("BW_CALC : BW_IN_PKTS for port %0d is %f Million_pkts/sec",port_num,BW_in_pkts);
if(packet_len == 64) begin
if(BW_in_pkts < 14.88) begin
$display("BW_CALC : ERROR BW less than expected for port %0d",port_num);
$display("BW_CALC : Warning BW less than expected for port %0d",port_num);
else if(packet_len == 1518) begin
$display("BW_CALC : ERROR BW less than expected for port %0d",port_num);
else if(packet_len == 9588) begin
$display("BW_CALC : ERROR BW less than expected for port %0d",port_num);
data_byte_cnt = data_byte_cnt + 1;
if((data == 8'hfb) && (enb == 1))
ipg_byte_cnt = ipg_byte_cnt + 1;
avg_ipg_byte_cnt = ipg_byte_cnt/no_of_pkts;
$display("BW_CALC_1G : START_TIME in BW %t for PORT %0d",bw_start_time,port_num);
no_of_txpkts = no_of_pkts;
2'b01 : begin // check for frame delimiter in this state
// $display("BW_CALC_1G : COUNT in BW %0d for PORT %0d",count,port_num);
// $display("BW_CALC_1G : data in BW %0h for PORT %0d",data,port_num);
else if((data == 8'hd5) && (count == 6)) begin
if(pkt_cnt == no_of_txpkts) begin
delta_time = (bw_end_time - bw_start_time)/1000000;
delta_time1 = (bw_end_time - bw_start_time);
$display("BW_CALC_1G : END_TIME in BW %t for PORT %0d",bw_end_time,port_num);
avg_ipg_byte_cnt = ipg_byte_cnt/no_of_pkts;
$display("BW_CALC_1G : Avg_ipg_per_pkt is %0f for PORT %0d",avg_ipg_byte_cnt,port_num);
// print the BW calculated
BW = (8*no_of_pkts*1000)*(packet_len + 8 + avg_ipg_byte_cnt)/delta_time1;
$display("BW_CALC_1G : BW_ON_WIRE is %0f Gigabits/sec for Port %0d",BW,port_num);
BW_d = (8*no_of_pkts*1000*packet_len)/delta_time1;
$display("BW_CALC_1G : BW_DATA is %0f Gigabits/sec for Port %0d",BW_d,port_num);
BW_in_pkts = no_of_pkts/delta_time;
$display("BW_CALC_1G : BW_IN_PKTS for port %0d is %f Million_pkts/sec",port_num,BW_in_pkts);
if(packet_len == 64) begin
$display("BW_CALC_1G : ERROR BW less than expected for port %0d",port_num);
else if(packet_len == 1518) begin
$display("BW_CALC_1G : ERROR BW less than expected for port %0d",port_num);
ipg_byte_cnt = ipg_byte_cnt + 1;
data_byte_cnt = data_byte_cnt + 1;
ipg_byte_cnt = ipg_byte_cnt + 1;