Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: FNXPCIEXactorReplayMonitor.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 | ||
44 | class FNXPCIEXactorReplayMonitor { | |
45 | ||
46 | // Base Class and Method Names For QR Macros | |
47 | local string ClassName = "FNXPCIEXactorReplayMonitor"; | |
48 | local string MethodName = null; | |
49 | ||
50 | local ReportClass MyReport; | |
51 | local string XactorName; | |
52 | local FNXPCIEXactorUtilities Util; | |
53 | local integer PortNum; | |
54 | ||
55 | integer StartNextPurgeSeqNum; | |
56 | ||
57 | // Replay Buffer Contents | |
58 | local FNXPCIEXactorPacket ReplayBuffer[ FNX_PCIE_XTR_MAX_REPLAY_ENTRIES ]; | |
59 | ||
60 | // Replay Statistics Tracking | |
61 | local integer TotalNumReplays; | |
62 | local integer TotalBytesReplayed; | |
63 | local integer PktCntPerTimesReplayed[FNX_PCIE_XTR_MAX_NUM_RETRIES_PER_PKT]; | |
64 | local integer NumUnpurgedTLPs; | |
65 | ||
66 | local integer CurrReplayCnt; // Count of Ongoing Replay (0 == Not Replaying) | |
67 | ||
68 | // constructor | |
69 | task new( ReportClass _Report, | |
70 | string _XactorName, | |
71 | FNXPCIEXactorUtilities _Util, | |
72 | integer _PortNum ); | |
73 | ||
74 | // public methods | |
75 | task Reset(); | |
76 | task UpdateTlp( FNXPCIEXactorPacket tlpPkt ); | |
77 | function string GetStr(); | |
78 | task UpdateStats(); | |
79 | } | |
80 | ||
81 | task FNXPCIEXactorReplayMonitor::new( ReportClass _Report, | |
82 | string _XactorName, | |
83 | FNXPCIEXactorUtilities _Util, | |
84 | integer _PortNum ) | |
85 | { | |
86 | string MethodName = "new"; | |
87 | ||
88 | MyReport = _Report; | |
89 | XactorName = _XactorName; | |
90 | Util = _Util; | |
91 | PortNum = _PortNum; | |
92 | Reset(); | |
93 | } | |
94 | ||
95 | task FNXPCIEXactorReplayMonitor::Reset() | |
96 | { | |
97 | string MethodName = "Reset"; | |
98 | integer i; | |
99 | ||
100 | NumUnpurgedTLPs = 0; | |
101 | StartNextPurgeSeqNum = -1; | |
102 | ||
103 | for (i=0; i < FNX_PCIE_XTR_MAX_REPLAY_ENTRIES; i++) | |
104 | ReplayBuffer[i] = null; | |
105 | TotalNumReplays = 0; | |
106 | TotalBytesReplayed = 0; | |
107 | for (i=0; i < FNX_PCIE_XTR_MAX_NUM_RETRIES_PER_PKT; i++) | |
108 | PktCntPerTimesReplayed[i] = 0; | |
109 | CurrReplayCnt = 0; | |
110 | } | |
111 | ||
112 | task FNXPCIEXactorReplayMonitor::UpdateTlp( FNXPCIEXactorPacket tlpPkt ) | |
113 | { | |
114 | string MethodName = "UpdateTlp"; | |
115 | bit [FNX_PCIE_XTR_DLL_FRM_SEQ_NUM_WIDTH-1:0] seqNum; | |
116 | bit [FNX_PCIE_XTR_DLL_FRM_SEQ_NUM_WIDTH-1:0] endSeqNum, iSeqNum; | |
117 | ||
118 | seqNum = tlpPkt.DLLFrmSeqNum; | |
119 | ||
120 | // Packet Has Been Replayed | |
121 | if (ReplayBuffer[seqNum] !== null) { | |
122 | ||
123 | // Ensure Packet Contents Match Previously Transmitted Packet | |
124 | if (ReplayBuffer[seqNum].PktCompare( "===", tlpPkt )) { | |
125 | PCIEX_QR_I( "%s -> Received Replay TLP Match for SeqNum=%h", XactorName, seqNum ); | |
126 | ||
127 | // Update Replay Statistics on Replay Match | |
128 | ReplayBuffer[seqNum].ReplayCnt++; | |
129 | if (CurrReplayCnt !== ReplayBuffer[seqNum].ReplayCnt) { | |
130 | TotalNumReplays++; | |
131 | CurrReplayCnt = ReplayBuffer[seqNum].ReplayCnt; | |
132 | } | |
133 | TotalBytesReplayed += ReplayBuffer[seqNum].NumBytes(); | |
134 | } | |
135 | else { | |
136 | PCIEX_QR_ERR( "%s -> Received Replay TLP Mismatch.\n Original TLP Contents:\n%s\n Replayed TLP Contents:\n%s", | |
137 | XactorName, ReplayBuffer[seqNum].PktToStr(), tlpPkt.PktToStr() ); | |
138 | } | |
139 | } | |
140 | else { // Packet Is Newly Transmitted So Place in Replay Buffer | |
141 | ReplayBuffer[seqNum] = new( MyReport, XactorName, Util, PortNum ); | |
142 | ReplayBuffer[seqNum].PktCopy( tlpPkt ); | |
143 | ||
144 | // Increment Number of TLPs Not Purged From Replay Buffer | |
145 | NumUnpurgedTLPs++; | |
146 | ||
147 | // Initialize Sequence Number to Start First Purge At | |
148 | if (StartNextPurgeSeqNum < 0) | |
149 | StartNextPurgeSeqNum = seqNum; | |
150 | ||
151 | // Once 512 TLPs are in Replay Buffer, Purge 256 Oldest TLPs | |
152 | if (NumUnpurgedTLPs > 512) { | |
153 | iSeqNum = StartNextPurgeSeqNum; | |
154 | endSeqNum = iSeqNum + 256; | |
155 | ||
156 | // Cycle Through Replay Buffer, Purge TLPs and Update Statistics | |
157 | while (iSeqNum !== endSeqNum) { | |
158 | // Update Replay Count Statistics For TLP Being Purged | |
159 | if (ReplayBuffer[iSeqNum].ReplayCnt > 0) | |
160 | PktCntPerTimesReplayed[ReplayBuffer[iSeqNum].ReplayCnt-1]++; | |
161 | ||
162 | // Purge the TLP from the Replay Buffer | |
163 | ReplayBuffer[iSeqNum] = null; | |
164 | ||
165 | PCIEX_QR_D2( "%s -> Purged TLP w/ SeqNum=%h", XactorName, iSeqNum ); | |
166 | iSeqNum++; | |
167 | NumUnpurgedTLPs--; | |
168 | } | |
169 | StartNextPurgeSeqNum = endSeqNum; | |
170 | } | |
171 | CurrReplayCnt = 0; | |
172 | PCIEX_QR_D3( "%s -> Added TLP w/ SeqNum=%h to Replay Buffer. Contents:\n%s", XactorName, seqNum, ReplayBuffer[seqNum].PktToStr() ); | |
173 | } | |
174 | } | |
175 | ||
176 | function string FNXPCIEXactorReplayMonitor::GetStr() | |
177 | { | |
178 | string MethodName = "GetStr"; | |
179 | string tmp; | |
180 | integer i; | |
181 | ||
182 | sprintf( GetStr, "Replay Statisitcs\n" ); | |
183 | sprintf( tmp, " Total Num Replays: %0d", TotalNumReplays ); | |
184 | GetStr = { GetStr, tmp }; | |
185 | sprintf( tmp, "\n Total Bytes Replayed: %0d", TotalBytesReplayed ); | |
186 | GetStr = { GetStr, tmp }; | |
187 | for (i=0; i < FNX_PCIE_XTR_MAX_NUM_RETRIES_PER_PKT; i++) { | |
188 | sprintf( tmp, "\n Total Num Pkts Replayed %0d Time(s): %0d", | |
189 | i+1, PktCntPerTimesReplayed[i] ); | |
190 | GetStr = { GetStr, tmp }; | |
191 | } | |
192 | } | |
193 | ||
194 | task FNXPCIEXactorReplayMonitor::UpdateStats() | |
195 | { | |
196 | integer i; | |
197 | ||
198 | for (i=0; i < FNX_PCIE_XTR_MAX_REPLAY_ENTRIES; i++) { | |
199 | if (ReplayBuffer[i] !== null) { | |
200 | // Update Replay Count Statistics Per Unpurged TLP | |
201 | if (ReplayBuffer[i].ReplayCnt > 0) | |
202 | PktCntPerTimesReplayed[ReplayBuffer[i].ReplayCnt-1]++; | |
203 | } | |
204 | } | |
205 | } |