// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: dmu_rmu_rrm_etsbfsm.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 dmu_rmu_rrm_etsbfsm (
// Outputs to TSB - Egress Pipeline
// Outputs to EFSM module
// Inputs from EFSM module
// Output (local) for debug visibility
// synopsys sync_set_reset "rst_l"
//############################################################################
//############################################################################
//------------------------------------------------------------------------
// Clock and Reset Signals
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
output [`FIRE_DLC_TSR_CMD_TYPE_WDTH-1:0] rm2ts_e_cmd_type; // 4 bit TSB Cmd
//------------------------------------------------------------------------
//------------------------------------------------------------------------
output tsb_fsm_idle; // TSB fsm IDLE
output ld_epe_rcd_tsb; // TSB Read Data Valid
input gen_tsb_access; // Kick off TSB FSM
input sr_err_last_pkt; // DMA Cpl LAST Packet bit set
//------------------------------------------------------------------------
// Outputs (local) for Debug Port Visibility
//------------------------------------------------------------------------
output [3:0] e_tsb_state; // 1-hot Egress FSM
//############################################################################
//############################################################################
ETSB_CMD_NULL = 4'b0000, // Initial Value - NULL - can be removed
ETSB_CMD_RDCLR = 4'b0011, // Read/Clr - ie: last_pkt=1
ETSB_CMD_RD = 4'b0001, // Read bcnt - ie: last_pkt=0
ETSB_CMD_WR = 4'b0100; // Write back remaining bcnt
// Egress TSB Control Finite State Machine Parameters
ETSB_IDLE = 0, // E_TSB FSM Idle
ETSB_RDCLR = 1, // Issue READ/CLEAR and retire TRN
ETSB_RD = 2, // Issue READ command to TSB
ETSB_WR = 3; // Issue WRITE command to TSB
//############################################################################
// DECLARE Module Wires and Registers
//############################################################################
wire ld_epe_rcd_tsb; // TSB Rd Data Valid -EFSM to LOAD RRM rcd
wire tsb_fsm_idle; // TSB IDLE - ready for action
//--------------------------------------------------
// Registers that Are Flops
//--------------------------------------------------
// Egress TSB FSM 1-hot state machine
reg [NUM_STATES-1:0] e_tsb_state, next_e_tsb_state; // 1-hot Egress FSM
// Egress State Machine Registered Outputs
reg rm2ts_e_req, next_rm2ts_e_req; // Registered E TSB REQ
reg [`FIRE_DLC_TSR_CMD_TYPE_WDTH-1:0] rm2ts_e_cmd_type, // Registerd E TSB Cmnd
//############################################################################
//############################################################################
//---------------------------------------------------------------------
// Egress TSB State Machine Checkers
//---------------------------------------------------------------------
0in state -var e_tsb_state
-val (4'b0001 << ETSB_IDLE)
-next (4'b0001 << ETSB_RDCLR)
0in state -var e_tsb_state
-val (4'b0001 << ETSB_RDCLR)
-next (4'b0001 << ETSB_IDLE)
0in state -var e_tsb_state
-val (4'b0001 << ETSB_RD)
-next (4'b0001 << ETSB_WR)
0in state -var e_tsb_state
-val (4'b0001 << ETSB_WR)
-next (4'b0001 << ETSB_IDLE)
// 0in one_hot -var e_tsb_state
/* 0in kndr -var sr_err_last_pkt
//############################################################################
//############################################################################
// Output signal that tells EFSM to
// 1) Load EPE record since TSB Rd data valid and
// 2) Tells EFSM to proceed processing ERR's from TCM
assign ld_epe_rcd_tsb = ((e_tsb_state[ETSB_RD] | e_tsb_state[ETSB_RDCLR]) &
// Output that keeps Egress FSM in sync with Egress TSB FSM
assign tsb_fsm_idle = e_tsb_state[ETSB_IDLE];
//############################################################################
//############################################################################
//----------------------------------------------
// Egress TSB State Machine Sequential Logic
//----------------------------------------------
e_tsb_state[NUM_STATES-1:0] <= {NUM_STATES{1'b0}};
e_tsb_state[ETSB_IDLE] <= 1'b1;
rm2ts_e_cmd_type <= {`FIRE_DLC_TSR_CMD_TYPE_WDTH{1'b0}};
e_tsb_state <= next_e_tsb_state;
rm2ts_e_req <= next_rm2ts_e_req; // State Machine Registered Outputs
rm2ts_e_cmd_type <= next_rm2ts_e_cmd_type;
//----------------------------------------------------------
// Egress TSB State Machine Combinatorial (Next State) Logic
//----------------------------------------------------------
always @ ( e_tsb_state or gen_tsb_access or sr_err_last_pkt or ts2rm_e_gnt )
next_e_tsb_state = {NUM_STATES{1'b0}}; // Default Outputs
next_rm2ts_e_cmd_type = `FIRE_DLC_TSR_CMD_TYPE_WDTH'b0;
case(1'b1) // synopsys parallel_case
// ETSB_IDLE -Initial State
casez({gen_tsb_access,sr_err_last_pkt})
(2'b0z) : // Ignore ERR including x's`
begin // until we NEED to access tsb
next_e_tsb_state[ETSB_IDLE] = 1'b1; // wait for gen_tsb_access
next_rm2ts_e_cmd_type = ETSB_CMD_NULL; // keep default value
next_rm2ts_e_req = 1'b0; // Req deasserted
next_e_tsb_state[ETSB_RD] = 1'b1; // DMA Cpl - Not Last Pkt - RDWR
next_rm2ts_e_cmd_type = ETSB_CMD_RD; // Access TSB to build RRM rcd
next_rm2ts_e_req = 1'b1; // assert REQ
next_e_tsb_state[ETSB_RDCLR]= 1'b1; // DMA Cpl - Last Pkt - RD/CLR
next_rm2ts_e_cmd_type = ETSB_CMD_RDCLR; // Issue Read Clear command
next_rm2ts_e_req = 1'b1; // assert REQ
endcase // ends ETSB_IDLE state case
// ETSB_RD - Go get data associated with DMA Response to build RRM Record
next_rm2ts_e_req = 1'b1; // keep REQ asserted
if (ts2rm_e_gnt) // RD completed - Start WR
next_e_tsb_state[ETSB_WR] = 1'b1; // Go to ETSB_WR state
next_rm2ts_e_cmd_type = ETSB_CMD_WR; // Issue Write command
next_e_tsb_state[ETSB_RD] = 1'b1; // ~gnt - keep RD asserted
next_rm2ts_e_cmd_type = ETSB_CMD_RD;
// ETSB_WR - RRM Rcd complete - write back new bcnt to TSB
if (ts2rm_e_gnt) // TSB WR completed
next_rm2ts_e_req = 1'b0; // Deassert REQ
next_e_tsb_state[ETSB_IDLE] = 1'b1; // Back to IDLE
next_rm2ts_e_cmd_type = ETSB_CMD_NULL; // Command no longer Vld
else // GNT not yet asserted
next_rm2ts_e_req = 1'b1; // Keep REQ asserted
next_e_tsb_state[ETSB_WR] = 1'b1; // Stay in WR state
next_rm2ts_e_cmd_type = ETSB_CMD_WR; // Hold WR Cmd
// ETSB_WR - RRM Rcd complete - write back new bcnt to TSB
e_tsb_state[ETSB_RDCLR] :
if (ts2rm_e_gnt) // RDCLR completed
next_rm2ts_e_req = 1'b0; // Deassert REQ
next_e_tsb_state[ETSB_IDLE] = 1'b1; // Back to IDLE
next_rm2ts_e_cmd_type = ETSB_CMD_NULL; // Command no longer Vld
else // GNT not yet asserted
next_rm2ts_e_req = 1'b1; // Keep REQ asserted
next_e_tsb_state[ETSB_RDCLR] = 1'b1; // Stay in WR state
next_rm2ts_e_cmd_type = ETSB_CMD_RDCLR; // Hold RD/CLR Cmd
endcase // Ends ETSB 1-hot FSM Case Statement
end // Ends combinatorial ETSB next state always block