Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / fnx / vlib / FNXPCIEXactor / src / FNXPCIEXactorFCEngine.vr
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: FNXPCIEXactorFCEngine.vr
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#include "DenaliPCIE.vri"
36
37// FNXPCIEXactor library
38#include "FNXPCIEXactorDefines.vri"
39
40// report library
41#include "cReport.vrh"
42#include "FNXPCIEXactorReportMacros.vri"
43
44class FNXPCIEXactorFCEngine {
45
46 // Base Class and Method Names For QR Macros
47 local string ClassName = "FNXPCIEXactorFCEngine";
48 local string MethodName = null;
49
50 local ReportClass MyReport;
51 local string XactorName;
52 local FNXPCIEXactorSignalInterface SignalInterface;
53 local FNXPCIEXactorDenaliClkPort DenaliClkPort;
54 local FNXPCIEXactorUtilities Util;
55
56 protected bit FCTimerEnable[FNX_PCIE_XTR_NUM_FC_TYPES];
57 protected integer FCTimerMax[FNX_PCIE_XTR_NUM_FC_TYPES];
58 protected integer FCTimerVal[FNX_PCIE_XTR_NUM_FC_TYPES];
59 protected integer FCUpdateIncMin[FNX_PCIE_XTR_NUM_FC_TYPES];
60 protected integer FCUpdateIncMax[FNX_PCIE_XTR_NUM_FC_TYPES];
61
62 // constructor
63 task new( ReportClass _Report,
64 FNXPCIEXactorSignalInterface _SignalInterface,
65 FNXPCIEXactorDenaliClkPort _DenaliClkPort,
66 FNXPCIEXactorUtilities _Util,
67 string _XactorName );
68
69 // public methods
70 task Reset();
71 task GenFCUpdates();
72 task EnableFCTimer( denaliPcieFcTypeT denFcType );
73 task DisableFCTimer( denaliPcieFcTypeT denFcType );
74 task SetFCTimerMax( denaliPcieFcTypeT denFcType, integer fcTimerMax );
75 task SetFCUpdateRange( denaliPcieFcTypeT denFcType, integer fcUpdateMin, integer fcUpdateMax );
76 task SetFCData( denaliPcieFcTypeT denFcType, denaliPcieFcIdT denFcId,
77 bit [FNX_PCIE_XTR_REG_DEN_FC_CTRL_DATA_VAL_WIDTH-1:0] fcData );
78 function bit[FNX_PCIE_XTR_REG_DEN_FC_CTRL_DATA_VAL_WIDTH-1:0] GetFCData( denaliPcieFcTypeT denFcType,
79 denaliPcieFcIdT denFcId );
80}
81
82task FNXPCIEXactorFCEngine::new( ReportClass _Report,
83 FNXPCIEXactorSignalInterface _SignalInterface,
84 FNXPCIEXactorDenaliClkPort _DenaliClkPort,
85 FNXPCIEXactorUtilities _Util,
86 string _XactorName ) {
87 string MethodName = "new";
88
89 MyReport = _Report;
90 SignalInterface = _SignalInterface;
91 DenaliClkPort = _DenaliClkPort;
92 Util = _Util;
93 XactorName = _XactorName;
94 Reset();
95
96 // Start FC Update Engine
97 GenFCUpdates();
98}
99
100task FNXPCIEXactorFCEngine::Reset() {
101 string MethodName = "Reset";
102 integer i;
103
104 for (i=0; i < FNX_PCIE_XTR_NUM_FC_TYPES; i++) {
105 FCTimerEnable[i] = 0;
106 FCTimerMax[i] = 100;
107 FCTimerVal[i] = 100;
108 FCUpdateIncMin[i] = 1;
109 FCUpdateIncMax[i] = 1;
110 }
111}
112
113task FNXPCIEXactorFCEngine::GenFCUpdates() {
114 string MethodName = "GenFCUpdates";
115 bit [FNX_PCIE_XTR_REG_DEN_FC_CTRL_DATA_VAL_WIDTH-1:0] fcUpdateInc;
116 denaliPcieFcTypeT denFcType;
117 integer i;
118
119 fork {
120 while (1) {
121 for (i=0; i < FNX_PCIE_XTR_NUM_FC_TYPES; i++) {
122 if (FCTimerEnable[i]) {
123 FCTimerVal[i]--;
124 if (FCTimerVal[i] === 0) {
125 denFcType = Util.FCEncToDenaliType(i);
126 fcUpdateInc = Util.RandUtil.Rand32( FCUpdateIncMin[i], FCUpdateIncMax[i] );
127 SetFCData( denFcType, PCIE_FCID_RX_ALLOCATED,
128 GetFCData( denFcType, PCIE_FCID_RX_ALLOCATED ) + fcUpdateInc );
129 PCIEX_QR_I( "%s-> Set Inc=%h For Next %s Update",
130 XactorName, fcUpdateInc, denFcType );
131 }
132 if (FCTimerVal[i] < 0) {
133 FCTimerVal[i] = FCTimerMax[i];
134 }
135 }
136 }
137 @(posedge DenaliClkPort.$tx_clk); // Clock At Same Rate As Denali FC Timers (250 MHz PCIE, Not Raptor Clock)
138 }
139 } join none
140}
141
142task FNXPCIEXactorFCEngine::SetFCData( denaliPcieFcTypeT denFcType,
143 denaliPcieFcIdT denFcId,
144 bit [FNX_PCIE_XTR_REG_DEN_FC_CTRL_DATA_VAL_WIDTH-1:0] fcData ) {
145 string MethodName = "SetFCData";
146 bit [FNX_PCIE_XTR_REG_DEN_WIDTH-1:0] fcRegVal;
147 integer idenFcType, iFcOp, iVc, iFcId;
148
149 idenFcType = denFcType;
150 iFcOp = PCIE_FCCTRL_set;
151 iVc = PCIE_VCID_VC0; // FNX Only Implements VC 0
152 iFcId = denFcId;
153 fcRegVal = 0;
154 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_FC_TYPE_SLC] = idenFcType;
155 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_VC_SLC] = iVc;
156 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_FC_CMD_SLC] = iFcOp;
157 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_FC_ID_SLC] = iFcId;
158 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_DATA_VAL_SLC] = fcData;
159 SignalInterface.WriteDenaliReg( PCIE_REG_DEN_FC_CTRL, fcRegVal );
160}
161
162function bit[FNX_PCIE_XTR_REG_DEN_FC_CTRL_DATA_VAL_WIDTH-1:0] FNXPCIEXactorFCEngine::GetFCData( denaliPcieFcTypeT denFcType,
163 denaliPcieFcIdT denFcId ) {
164 string MethodName = "GetFCData";
165 bit [FNX_PCIE_XTR_REG_DEN_WIDTH-1:0] fcRegVal;
166 integer idenFcType, iFcOp, iVc, iFcId;
167
168 idenFcType = denFcType;
169 iFcOp = PCIE_FCCTRL_get;
170 iVc = PCIE_VCID_VC0; // FNX Only Implements VC 0
171 iFcId = denFcId;
172 fcRegVal = 0;
173 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_FC_TYPE_SLC] = idenFcType;
174 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_VC_SLC] = iVc;
175 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_FC_CMD_SLC] = iFcOp;
176 fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_FC_ID_SLC] = iFcId;
177 SignalInterface.WriteDenaliReg( PCIE_REG_DEN_FC_CTRL, fcRegVal );
178
179 fcRegVal = SignalInterface.ReadDenaliReg( PCIE_REG_DEN_FC_CTRL );
180 GetFCData = fcRegVal[FNX_PCIE_XTR_REG_DEN_FC_CTRL_DATA_VAL_SLC];
181}
182
183task FNXPCIEXactorFCEngine::EnableFCTimer( denaliPcieFcTypeT denFcType ) {
184 string MethodName = "EnableFCTimer";
185 integer i, idx;
186
187 idx = Util.denaliFCTypeToInt(denFcType);
188 if (idx < 0) {
189 for (i=0; i < FNX_PCIE_XTR_NUM_FC_TYPES; i++) {
190 FCTimerEnable[i] = 1;
191 }
192 } else {
193 FCTimerEnable[idx] = 1;
194 }
195}
196
197task FNXPCIEXactorFCEngine::DisableFCTimer( denaliPcieFcTypeT denFcType ) {
198 string MethodName = "DisableFCTimer";
199 integer i, idx;
200
201 idx = Util.denaliFCTypeToInt(denFcType);
202 if (idx < 0) {
203 for (i=0; i < FNX_PCIE_XTR_NUM_FC_TYPES; i++) {
204 FCTimerEnable[i] = 0;
205 }
206 } else {
207 FCTimerEnable[idx] = 0;
208 }
209}
210
211task FNXPCIEXactorFCEngine::SetFCTimerMax( denaliPcieFcTypeT denFcType, integer fcTimerMax ) {
212 string MethodName = "SetFCTimerMax";
213 integer i, idx;
214
215 idx = Util.denaliFCTypeToInt(denFcType);
216 if (idx < 0) {
217 for (i=0; i < FNX_PCIE_XTR_NUM_FC_TYPES; i++) {
218 FCTimerMax[i] = fcTimerMax;
219 }
220 } else {
221 FCTimerMax[idx] = fcTimerMax;
222 }
223}
224
225task FNXPCIEXactorFCEngine::SetFCUpdateRange( denaliPcieFcTypeT denFcType, integer fcUpdateMin, integer fcUpdateMax ) {
226 string MethodName = "SetFCUpdateRange";
227 integer i, idx;
228
229 idx = Util.denaliFCTypeToInt(denFcType);
230 if (idx < 0) {
231 for (i=0; i < FNX_PCIE_XTR_NUM_FC_TYPES; i++) {
232 FCUpdateIncMin[i] = fcUpdateMin;
233 FCUpdateIncMax[i] = fcUpdateMax;
234 }
235 } else {
236 FCUpdateIncMin[idx] = fcUpdateMin;
237 FCUpdateIncMax[idx] = fcUpdateMax;
238 }
239}