// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: xpcs_rxio_sync_sm.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 ============================================
// ****************************************************************
// Sun Proprietary/Confidential: Internal Use Only
// ****************************************************************
// Design: XPCS RX IO Interface
// Block: XPCS RX Sync state machine
// Module: xpcs_rxio_sync_sm
// File: xpcs_rxio_sync_sm.v
// Description: This block contains a comma detector compliant
// to ieee 802.3ae clause 48 fig 48-7.
// ------------------------------------------------------------
// ------------------------------------------------------------
// ****************************************************************
module xpcs_rxio_sync_sm (
output csr_lane_sync_status;
// Wires and Regs which are not flops
reg csr_lane_sync_status;
wire [2:0] nxt_comma_cnt; // counter for number of good commas received
wire [2:0] nxt_symbol_cnt; // counter for number of good symbol received
parameter LOSS_SYNC = 4'h0; // word synchronization state machine
parameter IN_SYNC = 4'h1;
parameter ONE_INVALID = 4'h2;
parameter TWO_INVALID = 4'h4;
parameter THREE_INVALID = 4'h8;
XPCS_DEC_COM 10'h1BC // K28.5
assign com_k281_det = ({error_deskew,special_deskew,byte_deskew[7:0]} == `XPCS_DEC_281);
assign com_k285_det = ({error_deskew,special_deskew,byte_deskew[7:0]} == `XPCS_DEC_285);
assign com_k287_det = ({error_deskew,special_deskew,byte_deskew[7:0]} == `XPCS_DEC_287);
assign com_det = com_k281_det | com_k285_det | com_k287_det;
assign invalid = error_deskew; // Disparity and decode errors
** Synchronization COMMA counter
always @ (posedge rx_lane_clk)
comma_cnt <= nxt_comma_cnt;
assign nxt_comma_cnt = (rx_lane_reset | clr_comma_cnt) ? 3'h0 :
(inc_comma_cnt) ? comma_cnt + 3'h1 :
assign comma_cnt_eq4 = (comma_cnt >= 3'h4);
** Synchronization SYMBOL counter
always @ (posedge rx_lane_clk)
symbol_cnt <= nxt_symbol_cnt;
assign nxt_symbol_cnt = (rx_lane_reset | clr_symbol_cnt) ? 3'h0 :
(inc_symbol_cnt) ? symbol_cnt + 3'h1 :
assign symbol_cnt_eq3 = (symbol_cnt >= 3'h3);
/* ************************************************************* */
always @ (posedge rx_lane_clk)
csr_lane_sync_status <= !rx_lane_sync_loss;
** Call of function word synchronization
assign {rx_lane_sync_loss,inc_symbol_cnt,clr_symbol_cnt,inc_comma_cnt,clr_comma_cnt,nxt_state}
= synchronization_fn(rx_lane_reset,
** Word Synchronization state machine
function [8:0] synchronization_fn;
input f_com_det; // to determine if there is a comma
input f_invalid; // invalid transmission word detected
input f_symbol_cnt_eq3; // found 3 commas with no errors
reg f_loss_sync; // indicates word sync status
reg f_inc_comma_cnt; // increment word sync counter
reg f_clr_comma_cnt; // clear word sync counter
reg f_inc_symbol_cnt; // increment word sync counter
reg f_clr_symbol_cnt; // clear word sync counter
reg [3:0] n_state; // next state
case (state) // synopsys parallel_case
LOSS_SYNC : // 0 // being in this state triggers link config
else if (f_comma_cnt_eq4) // got 3 good commas
else if (f_com_det) // accum good
else if (f_symbol_cnt_eq3) // got 3 good symbols
n_state = IN_SYNC; // go to sync state
else // inc good symbol count
else if (f_symbol_cnt_eq3) // got 3 good symbols
n_state = ONE_INVALID; // Need to get 3 more good symbols
else // inc good symbol count
else if (f_symbol_cnt_eq3) // got 3 good symbols
n_state = TWO_INVALID; // Need to get 6 more good symbols
else // inc good symbol count
// {rx_lane_sync_loss, inc_symbol_cnt, clr_symbol_cnt, inc_comma_cnt, clr_comma_cnt,nxt_state}
synchronization_fn = {f_loss_sync,f_inc_symbol_cnt,f_clr_symbol_cnt,f_inc_comma_cnt,f_clr_comma_cnt,n_state};
// ********************************
// Receive State Machine Registers
// ********************************
always @(posedge rx_lane_clk)
if (rx_lane_reset | !rx_signal_detect)
// 0in bits_on -var state -max 1 -clock rx_lane_clk
// 0in state -var state -val LOSS_SYNC -next IN_SYNC -clock rx_lane_clk -reset (rx_lane_reset | !rx_signal_detect)
// 0in state -var state -val IN_SYNC -next ONE_INVALID -clock rx_lane_clk -reset (rx_lane_reset | !rx_signal_detect)
// 0in state -var state -val ONE_INVALID -next TWO_INVALID IN_SYNC -clock rx_lane_clk -reset (rx_lane_reset | !rx_signal_detect)
// 0in state -var state -val TWO_INVALID -next THREE_INVALID ONE_INVALID -clock rx_lane_clk -reset (rx_lane_reset | !rx_signal_detect)
// 0in state -var state -val THREE_INVALID -next LOSS_SYNC TWO_INVALID -clock rx_lane_clk -reset (rx_lane_reset | !rx_signal_detect)