// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: l2err_checker.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 l2err_checker(L2_INT_RST,cpx_pkt_cnt,desr_log_cnt);
output [23:0] cpx_pkt_cnt,desr_log_cnt;
parameter S0=0,S1=1,S2=2,S3=3,SAMPLE=3;
wire [63:0] err_detected;
wire cpx_packet_valid,cpx_packet_l2miss;
wire [3:0] cpx_packet_rtntyp;
wire [1:0] cpx_packet_err;
wire [4:0] ras_desr_errtyp;
wire ras_desr_S,desr_F,desr_S,desr_ME;
reg [1:0] currentstate,currentstate1,currentstate2;
reg [1:0] nextstate,nextstate1,nextstate2;
reg st_inst,L2_err_flag,ld_pkt,err_pkt,pck_grnt_flag_ld,stmc_busy,pck_grnt_flag_err,desr_correct,errInj_enabled;
reg [23:0] cpx_pkt_cnt,desr_log_cnt;
assign err_detected = tb_top.cpu.l2t0.csreg.err_state_new_c8;
assign cpx_packet_valid = tb_top.cpu.l2t0.l2t_cpx_data_ca[145];
assign cpx_packet_l2miss = tb_top.cpu.l2t0.l2t_cpx_data_ca[140];
assign cpx_packet_rtntyp= tb_top.cpu.l2t0.l2t_cpx_data_ca[144:141];
assign cpx_packet_err= tb_top.cpu.l2t0.l2t_cpx_data_ca[139:138];
assign cpx_grnt = tb_top.cpu.l2t0.cpx_l2t_grant_cx;
assign desr_F = tb_top.cpu.spc0.tlu.dfd.desr_0[63];
assign desr_S = tb_top.cpu.spc0.tlu.dfd.desr_0[61];
assign desr_ME = tb_top.cpu.spc0.tlu.dfd.desr_0[62];
assign ras_desr_S = tb_top.cpu.spc0.tlu.dfd.ras_desr_et_0[61];
assign ras_desr_errtyp = tb_top.cpu.spc0.tlu.dfd.ras_desr_et_0[60:56];
//--------------------------------------------------------------------------------------
// Enable/Disable support : MAQ
//--------------------------------------------------------------------------------------
wire flush_reset_complete = `TOP.flush_reset_complete;
if (!($test$plusargs("l2err_checker_disable")) && (($test$plusargs("L2DA_ERR_ENABLE")) || ($test$plusargs("L2VD_CE_ERR_INJECT")) || ($test$plusargs("L2TA_RAND_ERR_ENABLE"))))
always @ (flush_reset_complete)
if (flush_reset_complete == 1'b0)
if ((flush_reset_complete == 1'b1) && !($test$plusargs("l2err_checker_disable")) && (($test$plusargs("L2DA_ERR_ENABLE")) || ($test$plusargs("L2VD_CE_ERR_INJECT")) || ($test$plusargs("L2TA_RAND_ERR_ENABLE")) ) )
//--------------------------------------------------------------------------------------
//L2_err_flag signal for SCOREBOARD
always @(posedge tb_top.cpu.l2clk)
if(enabled && cpx_packet_valid && cpx_packet_err == 2'b01 && (cpx_packet_rtntyp == 4'b1100 || cpx_packet_rtntyp == 4'b0000))
//To detect if the packet was with a load or an error indication packet
always @(posedge tb_top.cpu.l2clk)
if(cpx_packet_l2miss == 1 && cpx_packet_valid == 1 && cpx_packet_err == 2'b01 && cpx_packet_rtntyp == 4'b0000)
else if(cpx_packet_l2miss != 1 && cpx_packet_valid == 1 && cpx_packet_err == 2'b01 && cpx_packet_rtntyp == 4'b0000)
else if(cpx_packet_l2miss != 1 && cpx_packet_valid == 1 && cpx_packet_err == 2'b01 && cpx_packet_rtntyp == 4'b1100)
else if(cpx_packet_valid == 1 && cpx_packet_err == 2'b01 && (cpx_packet_rtntyp == 4'b1100 || cpx_packet_rtntyp == 4'b0001 || cpx_packet_rtntyp == 4'b0010 || cpx_packet_rtntyp == 4'b0100 || cpx_packet_rtntyp == 4'b1101))
//StateMachine for detecting the PCX Ack For ld_pkt - Sequential Logic
always @(posedge tb_top.cpu.l2clk)
currentstate <= nextstate;
//StateMachine for detecting the PCX Ack For ld_pkt - Combo Logic
always @(currentstate or nextstate or L2_INT_RST or ld_pkt)
if(ld_pkt == 1 && err_pkt == 0)
end //else of if(L2_err_flag == 1)
// `PR_ERROR("l2errChecker", `ERROR, "cpx_l2t_grant packet not generated by the CCX");
`PR_ALWAYS("l2errChecker", `ALWAYS, "cpx_l2t_grant packet not generated by the CCX");
//StateMachine for detecting the PCX Ack For err_pkt - Sequential Logic
always @(posedge tb_top.cpu.l2clk)
currentstate1 <= nextstate1;
//StateMachine for detecting the PCX Ack For err_pkt - Combo Logic
always @(currentstate1 or nextstate1 or L2_INT_RST or err_pkt)
if(err_pkt == 1 && ld_pkt == 0)
end //else of if(L2_err_flag == 1)
`PR_ALWAYS("l2errChecker", `ALWAYS, "cpx_l2t_grant packet not generated by the CCX");
//`PR_ERROR("l2errChecker", `ERROR, "cpx_l2t_grant packet not generated by the CCX");
//For Checking DESR for error packet
always @(pck_grnt_flag_err or desr_F or ras_desr_S or ras_desr_errtyp or enabled) // MAQ : Added Enabled
if((pck_grnt_flag_err == 1) && (enabled == 1)) // MAQ : Added Enabled
@(posedge tb_top.cpu.l2clk)
@(posedge tb_top.cpu.l2clk)
@(posedge tb_top.cpu.l2clk)
@(posedge tb_top.cpu.l2clk)
if(desr_F == 0 && ras_desr_S ==0 && (ras_desr_errtyp ==1 || ras_desr_errtyp ==2 || ras_desr_errtyp ==3 || ras_desr_errtyp ==8 || ras_desr_errtyp == 9 || ras_desr_errtyp ==11 ))
@(posedge tb_top.cpu.l2clk)
if(desr_S == 0 && desr_F == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
else if(desr_F == 0 && ras_desr_S ==1 && ras_desr_errtyp == 20)
@(posedge tb_top.cpu.l2clk)
if(desr_S == 1 && desr_F == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
else if(desr_F == 1 && ras_desr_S ==1)
@(posedge tb_top.cpu.l2clk)
if(desr_S == 1 && desr_ME == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
else if(desr_F == 1 && ras_desr_S ==0)
@(posedge tb_top.cpu.l2clk)
if(desr_ME == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
//`PR_ERROR("l2errChecker", `ERROR,"DESR is incorrectly Logged With Error Pcket");
//For Checking DESR for load instruction
always @(pck_grnt_flag_ld or desr_F or ras_desr_S or ras_desr_errtyp or enabled) // MAQ : Added Enabled
if((pck_grnt_flag_ld == 1) && (enabled == 1)) // MAQ : Added Enabled
@(posedge tb_top.cpu.l2clk)
@(posedge tb_top.cpu.l2clk)
@(posedge tb_top.cpu.l2clk)
@(posedge tb_top.cpu.l2clk)
if(desr_F == 0 && (ras_desr_S == 1) && (ras_desr_errtyp == 4))
@(posedge tb_top.cpu.l2clk)
if(desr_S == 1 && desr_F == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
else if(desr_F == 0 && (ras_desr_S == 0) && (ras_desr_errtyp == 9))
@(posedge tb_top.cpu.l2clk)
if(desr_S == 0 && desr_F == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
else if(desr_F == 1 && ras_desr_S ==1)
@(posedge tb_top.cpu.l2clk)
if(desr_S == 1 && desr_ME == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
else if(desr_F == 1 && ras_desr_S ==0)
@(posedge tb_top.cpu.l2clk)
if(desr_ME == 1 ) begin end
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged With Error Pcket");
`PR_ALWAYS("l2errChecker", `ALWAYS,"DESR is incorrectly Logged, Load Return Packet With Error");
//`PR_ERROR("l2errChecker", `ERROR,"DESR is incorrectly Logged, Load Return Packet With Error");
//To count the number of cpx packets sent
cpx_pkt_cnt <= cpx_pkt_cnt + 1;
else cpx_pkt_cnt <= cpx_pkt_cnt;
//To count the number of time DESR was logged
desr_log_cnt <= desr_log_cnt + 1;
else desr_log_cnt <= desr_log_cnt;