Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: niu_rxdma_pkttab.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 <vera_defines.vrh> | |
36 | #include <ListMacros.vrh> | |
37 | #include "niu_rxtoken.vrh" | |
38 | #include "mbox_class.vrh" | |
39 | #include "get_mbox_id.vrh" | |
40 | extern mbox_class mbox_id; | |
41 | ||
42 | #define TIME {get_time(HI), get_time(LO)} | |
43 | ||
44 | class CRxPacketScoreBoard { | |
45 | ||
46 | ||
47 | integer port_id; | |
48 | integer no_of_packets_qued, no_of_bytes_qued; | |
49 | integer no_of_packets_dqued, no_of_bytes_dqued; | |
50 | integer no_of_packets_checked, no_of_bytes_checked; | |
51 | integer no_of_packets_dropped, no_of_bytes_dropped; | |
52 | ||
53 | integer no_of_packets_l2_errors, no_of_bytes_l2_errors; | |
54 | integer no_of_packets_ext_l2_errors, no_of_bytes_ext_l2_errors; | |
55 | integer no_of_packets_ext_cksum_errors, no_of_bytes_ext_cksum_errors; | |
56 | ||
57 | integer no_of_packets_ext_runts,no_of_bytes_ext_runts; | |
58 | ||
59 | integer hist1_count; | |
60 | integer hist2_count; | |
61 | integer hist3_count; | |
62 | integer hist4_count; | |
63 | integer hist5_count; | |
64 | integer hist6_count; | |
65 | integer hist7_count; | |
66 | integer max_pkt_err_count; | |
67 | integer min_pkt_err_count; | |
68 | integer mcast_pkt_count; | |
69 | integer bcast_pkt_count; | |
70 | integer code_viol_err_count; | |
71 | integer bmac_align_err_count; | |
72 | integer xmac_byte_cnt; | |
73 | ||
74 | bit last_pkt_rcvd; // Token with (last_packet == 1 )receivced | |
75 | // queu of packets | |
76 | CRxToken RxTokenQue[]; | |
77 | CRxToken DeletedRxTokenQue[]; | |
78 | ||
79 | task print_stats( ( integer interval = 10000), (bit one_time = 0) ); | |
80 | task new(integer p) { | |
81 | port_id = p; | |
82 | last_pkt_rcvd = 1'b0; | |
83 | ||
84 | if(mbox_id.niu_rxpath_sb[p] == -1) { | |
85 | mbox_id.niu_rxpath_sb[p] = alloc(MAILBOX,0,1); | |
86 | // Check if we were succesfull allocating the mailbox | |
87 | if(mbox_id.niu_rxpath_sb[p] == 0) { | |
88 | printf("ERROR Could not allocate the scoreboard mailbox port %d \n",p); | |
89 | mbox_id.niu_rxpath_sb[p] = -1; | |
90 | return; | |
91 | } | |
92 | } | |
93 | ||
94 | no_of_packets_qued = 0; | |
95 | no_of_packets_dqued = 0; | |
96 | no_of_packets_checked = 0; | |
97 | no_of_packets_dropped = 0; | |
98 | no_of_packets_l2_errors = 0; | |
99 | no_of_packets_ext_l2_errors =0; | |
100 | no_of_packets_ext_cksum_errors=0; | |
101 | no_of_bytes_ext_l2_errors=0; | |
102 | no_of_bytes_ext_cksum_errors =0; | |
103 | no_of_packets_ext_runts =0; | |
104 | no_of_bytes_ext_runts =0; | |
105 | ||
106 | hist1_count = 0; | |
107 | hist2_count = 0; | |
108 | hist3_count = 0; | |
109 | hist4_count = 0; | |
110 | hist5_count = 0; | |
111 | hist6_count = 0; | |
112 | hist7_count = 0; | |
113 | xmac_byte_cnt = 0; | |
114 | max_pkt_err_count = 0; | |
115 | min_pkt_err_count = 0; | |
116 | mcast_pkt_count = 0; | |
117 | bcast_pkt_count = 0; | |
118 | code_viol_err_count = 0; | |
119 | bmac_align_err_count = 0; | |
120 | ||
121 | no_of_bytes_qued = 0; | |
122 | no_of_bytes_dqued = 0; | |
123 | no_of_bytes_checked = 0; | |
124 | no_of_bytes_dropped = 0; | |
125 | no_of_bytes_l2_errors = 0; | |
126 | fork | |
127 | wait_for_packets(); | |
128 | join none | |
129 | fork | |
130 | print_stats(100000); | |
131 | join none | |
132 | } | |
133 | ||
134 | function integer addPackets(CRxToken RxToken); | |
135 | function integer getPacket(integer id, var CRxToken RxToken,integer dma_no,integer dma_no_from_pkt) ; | |
136 | local function integer CheckDeletedQueue(integer id, var CRxToken RxToken); | |
137 | function integer getNoOfEntries() ; | |
138 | task incPacketStats(CRxToken RxToken); | |
139 | task wait_for_packets(); | |
140 | ||
141 | } | |
142 | task CRxPacketScoreBoard::incPacketStats(CRxToken RxToken ) { | |
143 | integer pg_error_code; | |
144 | integer rxtoken_error_code; | |
145 | no_of_packets_qued ++; | |
146 | no_of_bytes_qued = no_of_bytes_qued + RxToken.pkt_length; | |
147 | ||
148 | // xmac byte counter ceils to the multiple of 8 bytes | |
149 | if (RxToken.pkt_length%8) | |
150 | xmac_byte_cnt = RxToken.pkt_length/8 + 1; | |
151 | else | |
152 | xmac_byte_cnt = RxToken.pkt_length/8; | |
153 | ||
154 | // ext errors | |
155 | pg_error_code = RxToken.pgToken.pack_db.frame.error_code; | |
156 | ||
157 | // if ext l2 errors | |
158 | if((pg_error_code&PG_CRC_ERR) /*What about PG_TYPE_LEN_ERR?*/) { | |
159 | no_of_packets_ext_l2_errors++; | |
160 | no_of_bytes_ext_l2_errors = no_of_bytes_ext_l2_errors + RxToken.pkt_length; | |
161 | } | |
162 | ||
163 | // if ext cksum errors | |
164 | if((pg_error_code&PG_CHKSUM_ERR) /**/) { | |
165 | no_of_packets_ext_cksum_errors++; | |
166 | no_of_bytes_ext_cksum_errors = no_of_bytes_ext_cksum_errors + RxToken.pkt_length; | |
167 | } | |
168 | ||
169 | if( RxToken.pkt_length<64) { | |
170 | no_of_packets_ext_runts++; | |
171 | no_of_bytes_ext_runts = no_of_bytes_ext_runts + RxToken.pkt_length; | |
172 | } | |
173 | ||
174 | ||
175 | if (RxToken.pkt_length==64) hist1_count ++ ; | |
176 | if (RxToken.pkt_length>=65 && RxToken.pkt_length<128) hist2_count ++ ; | |
177 | if (RxToken.pkt_length>=128 && RxToken.pkt_length<256) hist3_count ++ ; | |
178 | if (RxToken.pkt_length>=256 && RxToken.pkt_length<512) hist4_count ++ ; | |
179 | if (RxToken.pkt_length>=512 && RxToken.pkt_length<1024) hist5_count ++ ; | |
180 | if (RxToken.pkt_length>=1024 && RxToken.pkt_length<1523) hist6_count ++ ; | |
181 | ||
182 | hist7_count ++ ; // total packet counter | |
183 | ||
184 | ||
185 | ||
186 | ||
187 | if (RxToken.pgToken.pack_db.flow.dst_node.l2_addr == 48'hffff_ffff_ffff) bcast_pkt_count ++ ; | |
188 | ||
189 | ||
190 | ||
191 | ||
192 | } | |
193 | ||
194 | function integer CRxPacketScoreBoard::addPackets(CRxToken RxToken) { | |
195 | ||
196 | integer id; | |
197 | ||
198 | id = RxToken.id; | |
199 | if(RxToken.port_num!=port_id) { | |
200 | printf("ERROR Incorrect Packet port num received !! \n"); | |
201 | addPackets = -1; | |
202 | } else if(assoc_index(CHECK,RxTokenQue,id)) { | |
203 | // check if this entry already exists | |
204 | printf(" packet id - %d exists in the queue - TB ERROR \n"); | |
205 | addPackets = -1; | |
206 | } else { | |
207 | // Now add the packet | |
208 | RxTokenQue[id] = RxToken; | |
209 | ||
210 | incPacketStats(RxToken); | |
211 | ||
212 | printf("CRxPacketScoreBoard::addPackets packet id - %d added in the queue - Port id - %d No Sofar - %d\n",id,port_id,no_of_packets_qued); | |
213 | } | |
214 | ||
215 | if(RxToken.last_packet) { | |
216 | last_pkt_rcvd = 1'b1; | |
217 | printf("%d CRxPacketScoreBoard::addPackets packet id - %d Received Last packet for Port id - %d \n",TIME, id,port_id); | |
218 | } | |
219 | } | |
220 | ||
221 | function integer CRxPacketScoreBoard::CheckDeletedQueue(integer id, var CRxToken RxToken){ | |
222 | integer status; | |
223 | if(assoc_index(CHECK,DeletedRxTokenQue,id)) { | |
224 | CheckDeletedQueue = 0; | |
225 | RxToken = DeletedRxTokenQue[id].object_copy(); | |
226 | status = assoc_index(DELETE,DeletedRxTokenQue,id); | |
227 | printf("CRxPacketScoreBoard::CheckDeletedQueue: id - %d port_id - %d found in deleted entry !!\n",id,port_id); | |
228 | ||
229 | } else { | |
230 | CheckDeletedQueue = 1; | |
231 | } | |
232 | } | |
233 | function integer CRxPacketScoreBoard::getPacket(integer id, var CRxToken RxToken,integer dma_no,integer dma_no_from_pkt) { | |
234 | ||
235 | integer status; | |
236 | integer first_id; | |
237 | integer iid,j; | |
238 | integer dma_no_to_compare; | |
239 | ||
240 | // find out how many entries are there before this one. | |
241 | // Among these are any of the entries expected to be dropped due to intentional errors | |
242 | // such as CRC, FIFO Errors etc | |
243 | // If not - mark them as potentially dropped due to backpressure and check if the testcase | |
244 | // was intending to do back-pressure. | |
245 | ||
246 | // Check if this id is for a packet already deleted. If so the only time this can come would be | |
247 | // when default dma is different from what was intended | |
248 | ||
249 | status = CheckDeletedQueue(id, RxToken); | |
250 | if(status==0) { | |
251 | // entry found - decrement counter | |
252 | no_of_packets_dropped--; | |
253 | no_of_packets_dqued++; | |
254 | getPacket = 1; | |
255 | printf("CRxPacketScoreBoard::getPacket: CheckDeletedQueue PacketId - %d Port - %d dma_no - %d Dropped - So far - %d \n",id,port_id,dma_no_from_pkt,no_of_packets_dropped); | |
256 | ||
257 | // no_of_bytes_dropped = no_of_bytes_dropped +RxTokenQue[iid].pkt_length; | |
258 | // no_of_bytes_dqued = no_of_bytes_dqued + RxToken.pkt_length; | |
259 | } else { | |
260 | // check if the id exists | |
261 | status = assoc_index(FIRST,RxTokenQue,first_id); | |
262 | if(status==0) { | |
263 | printf("PacketQue Empty !!! Illegal packet received Port No -%d \n",port_id); | |
264 | getPacket = -1; | |
265 | } else if(assoc_index(CHECK,RxTokenQue,id)) { | |
266 | ||
267 | if(id== first_id) { | |
268 | printf(" Packet Received Matches with the first one- No Packets dropped until now PortNo- %d PacketId - %d \n",port_id,id); | |
269 | } else { | |
270 | // scan through the que until we find the packet | |
271 | ||
272 | dma_no_to_compare = dma_no; | |
273 | ||
274 | status = assoc_index(FIRST,RxTokenQue,first_id); | |
275 | iid = first_id; | |
276 | while(id!=iid) { | |
277 | // find out if next exists | |
278 | if(RxTokenQue[iid].dma_num== dma_no_to_compare) { | |
279 | no_of_packets_dropped++; | |
280 | no_of_bytes_dropped = no_of_bytes_dropped +RxTokenQue[iid].pkt_length; | |
281 | printf("CRxPacketScoreBoard::getPacket: PacketId - %d Port - %d dma_no - %d Dropped - So far - %d \n",iid,port_id,dma_no_to_compare,no_of_packets_dropped); | |
282 | j=iid; | |
283 | status = assoc_index(NEXT,RxTokenQue,j); | |
284 | if(status) { /*printf("delete found next\n");*/} | |
285 | else { if (id!=j) printf("ERROR IN FINDING NEXT\n"); } | |
286 | DeletedRxTokenQue[iid] = RxTokenQue[iid].object_copy(); | |
287 | status = assoc_index(DELETE,RxTokenQue,iid); | |
288 | iid = j; | |
289 | } else { | |
290 | j=iid; | |
291 | status = assoc_index(NEXT,RxTokenQue,j); | |
292 | if(status) { /*printf("found next\n");*/} | |
293 | else { if (id!=j) printf("ERROR IN FINDING NEXT\n"); } | |
294 | iid = j; | |
295 | } | |
296 | } | |
297 | printf(" RxTokenQue[%d] Expected DMa No - %d Matched with id - %d \n",port_id,dma_no,iid); | |
298 | }// end else | |
299 | ||
300 | ||
301 | RxToken = new(); | |
302 | RxToken = RxTokenQue[id].object_copy(); | |
303 | status = assoc_index(DELETE,RxTokenQue,id); | |
304 | no_of_packets_dqued++; | |
305 | no_of_bytes_dqued = no_of_bytes_dqued + RxToken.pkt_length; | |
306 | getPacket = 1; | |
307 | } else { | |
308 | printf(" Packet Id doesnt exist!!! Illegal packet received \n"); | |
309 | getPacket = -1; | |
310 | } | |
311 | } | |
312 | } | |
313 | function integer CRxPacketScoreBoard::getNoOfEntries() { | |
314 | getNoOfEntries = no_of_packets_qued - no_of_packets_dqued; | |
315 | } | |
316 | ||
317 | task CRxPacketScoreBoard::wait_for_packets() { | |
318 | CRxToken RxToken; | |
319 | integer no_of_tkns,status; | |
320 | ||
321 | while(1) { | |
322 | no_of_tkns = mailbox_get(WAIT,mbox_id.niu_rxpath_sb[port_id], RxToken); | |
323 | status = addPackets(RxToken); | |
324 | if(status==-1){ | |
325 | printf(" ERROR in adding packets to scoreboard \n"); | |
326 | return; | |
327 | } | |
328 | } | |
329 | ||
330 | } | |
331 | task CRxPacketScoreBoard::print_stats( ( integer interval = 10000), (bit one_time = 0) ) { | |
332 | integer count; | |
333 | integer packets_remaining,packets_checked,total_packets_sent,packets_dropped,packets_l2_errors; | |
334 | ||
335 | count = 0; | |
336 | while(1) { | |
337 | ||
338 | printf("###START CURRENT STATS####!! TIME - %d Port - %d \n",TIME,port_id); | |
339 | packets_remaining = getNoOfEntries(); | |
340 | packets_checked = no_of_packets_dqued; | |
341 | total_packets_sent = no_of_packets_qued; | |
342 | packets_dropped = no_of_packets_dropped; | |
343 | packets_l2_errors = no_of_packets_l2_errors; | |
344 | printf("###STATS SOFAR#### Port=%0d packets_remaining=%0d packets_checked=%0d total_packets_sent=%0d\n", port_id, packets_remaining, packets_checked, total_packets_sent); | |
345 | printf("###STATS SOFAR#### Port=%0d bytes_checked=%0d total_bytes_sent=%0d\n", port_id, no_of_bytes_dqued, no_of_bytes_qued); | |
346 | printf("###STATS SOFAR#### Port=%0d packets dropped due to L2Error=%0d bytes=%0d\n", port_id, no_of_packets_l2_errors, no_of_bytes_l2_errors); | |
347 | printf("###END CURRENT STATS####!! TIME - %d Port - %d \n",TIME,port_id); | |
348 | if(one_time) | |
349 | return; | |
350 | repeat(interval + 10*port_id ) @(posedge CLOCK); | |
351 | } | |
352 | } |