Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: pc_top_pp.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 | ||
37 | #include "pcg_defines.vri" | |
38 | #include "pcg_types.vri" | |
39 | #include "pack_db.vrh" | |
40 | #include "flow_db.vrh" | |
41 | #include "flow_db_tasks.vrh" | |
42 | #include "mbox_class.vrh" | |
43 | #include "get_mbox_id.vrh" | |
44 | #include "pg_top_pp.vrh" | |
45 | #include "cMesg.vrh" | |
46 | #include "pcg_token.vrh" | |
47 | ||
48 | #include "bmac_util.vrh" | |
49 | #include "xmac_util.vrh" | |
50 | ||
51 | // extern pack_db_entry pack_db[]; | |
52 | extern flow_db_entry flow_db[]; | |
53 | ||
54 | extern mbox_class mbox_id; | |
55 | extern integer quiet_on; | |
56 | extern pg ptr_to_first_pg; | |
57 | extern pg pack_gen[16]; | |
58 | extern class pc; | |
59 | extern pc pack_check[4]; | |
60 | ||
61 | extern Mesg be_msg; | |
62 | ||
63 | extern bmac_util_class bmac_util; | |
64 | extern mac_util_class mac_util; | |
65 | ||
66 | class pc { | |
67 | local integer warning_count=0; | |
68 | local integer error_count=0; | |
69 | local bit [3:0] port_type; | |
70 | local integer my_port; | |
71 | local integer pack_cnt=0; | |
72 | static bit[19:0] pc_used_ports=0; | |
73 | local integer port_speed ; | |
74 | integer drrbypass_port_num; | |
75 | ||
76 | local integer mac_speed ; | |
77 | local integer om_token; | |
78 | local bit tx_err=0; | |
79 | integer col_start=0; | |
80 | integer used_col_start=0; | |
81 | integer col_len=0; | |
82 | integer col=0; | |
83 | integer reset_col_parameters=0; | |
84 | integer last_time = -1; | |
85 | integer debug_gmii = 0; | |
86 | integer debug_mii = 0; | |
87 | integer debug_fa = 0; | |
88 | integer debug_mii_rx = 0; | |
89 | integer debug_gmii_rx = 0; | |
90 | integer debug_xgmii_rx = 0; | |
91 | integer debug_rx = 0; | |
92 | integer debug_dg = 0; | |
93 | integer debug_db_in = 0; | |
94 | integer debug_db_out = 0; | |
95 | integer debug_checker = 1; | |
96 | integer debug_in_token = 1; | |
97 | integer ipg=-1; | |
98 | ||
99 | function integer check_option(bit [63:0] option, bit [63:0] flag) ; | |
100 | function integer drain_tokens(var CpgToken pgToken) ; | |
101 | task pkt_auto_rx() ; | |
102 | task rcv_packet(bit [3:0] ptype, byte_array buf, var integer len) ; | |
103 | task assert_col (mii_def port_bind) ; | |
104 | task ctrl_crs(bit crs_val) ; | |
105 | task assert_crs (mii_def port_bind, bit crs_val) ; | |
106 | task check_mii_ipg ( mii_def port_bind) ; | |
107 | task check_gmii_ipg (gmii_def port_bind) ; | |
108 | task check_xgmii_ipg (xgmii_def port_bind) ; | |
109 | task rcv_packet_mii (mii_def port_bind, bit [3:0] ptype, byte_array buf, var integer len ) ; | |
110 | task rcv_packet_gmii (gmii_def port_bind, bit [3:0] ptype, byte_array buf, var integer len) ; | |
111 | task rcv_packet_xgmii (xgmii_def port_bind, bit [3:0] ptype, byte_array buf, var integer len) ; | |
112 | task wait_clk(integer count) ; | |
113 | task display_buf( byte_array buf, integer hwlen, (integer ifedx=0)) ; | |
114 | task display_class(byte_array buf, var integer ptr) ; | |
115 | task display_class_ipv6(byte_array buf, var integer ptr) ; | |
116 | task display_data(byte_array buf, var integer ptr, integer len) ; | |
117 | task display_id(bit [79:0] id) ; | |
118 | task display_db(pack_db_entry pack_db) ; | |
119 | task display_flow(integer flow_id) ; | |
120 | task get_om_token() ; | |
121 | task pkt_check(byte_array buf, integer hwlen) ; | |
122 | task print_warn() ; | |
123 | task print_err() ; | |
124 | task new(integer my_porti, (bit [3:0] ptype=0)) ; | |
125 | task status() ; | |
126 | task config_rx (mii_def port_bind, integer mac_speed) ; | |
127 | ||
128 | } | |
129 | ||
130 | ||
131 | task pc::pkt_auto_rx() { | |
132 | integer len; | |
133 | byte_array buf; | |
134 | buf = new; | |
135 | ||
136 | while(1) { | |
137 | rcv_packet( port_type, buf, len); | |
138 | pack_cnt++; | |
139 | if(debug_rx & len > 0) display_buf( buf, len, port_type[1] ); | |
140 | ||
141 | ||
142 | ||
143 | if( (col & (used_col_start > 124)) | | |
144 | (!col & (len > 0 )) ) { | |
145 | ||
146 | ||
147 | ||
148 | pkt_check(buf, len); | |
149 | } | |
150 | ||
151 | col = 0; | |
152 | } | |
153 | } | |
154 | ||
155 | task pc::rcv_packet(bit [3:0] ptype, byte_array buf, var integer len) { | |
156 | integer n; | |
157 | ||
158 | case(my_port) { | |
159 | 0: { | |
160 | if (ptype[3]) { | |
161 | fork | |
162 | check_xgmii_ipg (xgm0); | |
163 | ||
164 | join none | |
165 | rcv_packet_xgmii (xgm0, ptype, buf, len); | |
166 | } else if (ptype[0]) { | |
167 | fork | |
168 | check_gmii_ipg (gm0); | |
169 | ||
170 | join none | |
171 | rcv_packet_gmii (gm0,ptype, buf, len); | |
172 | } else { | |
173 | fork | |
174 | check_mii_ipg (m0); | |
175 | ||
176 | join none | |
177 | rcv_packet_mii (m0,ptype, buf, len); | |
178 | } | |
179 | } | |
180 | ||
181 | 1: { | |
182 | if (ptype[3]) { | |
183 | fork | |
184 | check_xgmii_ipg (xgm1); | |
185 | ||
186 | join none | |
187 | rcv_packet_xgmii (xgm1, ptype, buf, len); | |
188 | } else if (ptype[0]) { | |
189 | fork | |
190 | check_gmii_ipg (gm1); | |
191 | ||
192 | //rcv_packet_gmii with gm1(ptype, buf, len); | |
193 | join none | |
194 | rcv_packet_gmii (gm1,ptype, buf, len); | |
195 | } else { | |
196 | fork | |
197 | check_mii_ipg ( m1); | |
198 | ||
199 | join none | |
200 | rcv_packet_mii (m1,ptype, buf, len); | |
201 | } | |
202 | } | |
203 | ||
204 | 2: { | |
205 | if (ptype[0]) { | |
206 | fork | |
207 | check_gmii_ipg (gm2); | |
208 | ||
209 | join none | |
210 | rcv_packet_gmii (gm2,ptype, buf, len); | |
211 | } else { | |
212 | fork | |
213 | check_mii_ipg (m2); | |
214 | ||
215 | join none | |
216 | rcv_packet_mii (m2,ptype, buf, len); | |
217 | } | |
218 | ||
219 | } | |
220 | 3: { | |
221 | if (ptype[0]) { | |
222 | fork | |
223 | check_gmii_ipg (gm3); | |
224 | ||
225 | join none | |
226 | rcv_packet_gmii (gm3,ptype, buf, len); | |
227 | } else { | |
228 | fork | |
229 | check_mii_ipg ( m3); | |
230 | ||
231 | join none | |
232 | rcv_packet_mii (m3,ptype, buf, len); | |
233 | } | |
234 | ||
235 | } | |
236 | ||
237 | ||
238 | } | |
239 | ||
240 | } | |
241 | ||
242 | task pc::assert_col (mii_def port_bind) { | |
243 | integer itmp; | |
244 | ||
245 | ||
246 | @(posedge port_bind.$txen async); | |
247 | used_col_start = 0; | |
248 | ||
249 | ||
250 | ||
251 | if( col_len>0 ) { | |
252 | itmp = col_start; | |
253 | used_col_start = col_start; | |
254 | while(itmp>0) { | |
255 | itmp--; | |
256 | @(posedge port_bind.$txclk); | |
257 | } | |
258 | if(port_bind.$txen) col = 1; | |
259 | port_bind.$rxcol = 1 async; | |
260 | itmp = col_len; | |
261 | while(itmp>0) { | |
262 | itmp--; | |
263 | @(posedge port_bind.$txclk); | |
264 | } | |
265 | port_bind.$rxcol = 0 async; | |
266 | col_len = 0; | |
267 | } | |
268 | ||
269 | } | |
270 | ||
271 | task pc::ctrl_crs(bit crs_val) { | |
272 | case(my_port) { | |
273 | 0: assert_crs (m0,crs_val); | |
274 | 1: assert_crs (m1,crs_val); | |
275 | 2: assert_crs (m2,crs_val); | |
276 | 3: assert_crs (m3,crs_val); | |
277 | ||
278 | } | |
279 | } | |
280 | ||
281 | task pc::assert_crs (mii_def port_bind, bit crs_val) { | |
282 | port_bind.$rxcrs = crs_val; | |
283 | } | |
284 | ||
285 | task pc::check_mii_ipg ( mii_def port_bind) { | |
286 | integer current_time; | |
287 | integer cycle_time; | |
288 | ||
289 | @(posedge port_bind.$txen); | |
290 | ||
291 | if(port_speed==1) cycle_time = 400; | |
292 | else cycle_time = 40; | |
293 | ||
294 | current_time = {get_time(HI),get_time(LO)}; | |
295 | if(last_time != -1) { | |
296 | ipg = (current_time-last_time)/cycle_time; | |
297 | if(debug_mii_rx) printf("PC[%0d]: IPG: %0d (Time: %0d)\n",my_port,ipg,current_time); | |
298 | ||
299 | } | |
300 | ||
301 | @(negedge port_bind.$txen); | |
302 | last_time = {get_time(HI),get_time(LO)}; | |
303 | } | |
304 | ||
305 | task pc::check_gmii_ipg (gmii_def port_bind) { | |
306 | integer current_time; | |
307 | ||
308 | @(posedge port_bind.$txen); | |
309 | ||
310 | current_time = {get_time(HI),get_time(LO)}; | |
311 | if(last_time != -1) { | |
312 | ipg = (current_time-last_time)/8; | |
313 | if(debug_gmii_rx) printf("PC[%0d]: IPG: %0d (Time: %0d)\n",my_port,ipg,current_time); | |
314 | } | |
315 | ||
316 | @(negedge port_bind.$txen); | |
317 | last_time = {get_time(HI),get_time(LO)}; | |
318 | } | |
319 | ||
320 | task pc::check_xgmii_ipg (xgmii_def port_bind) { | |
321 | integer current_time; | |
322 | ||
323 | @(posedge port_bind.$txen); | |
324 | ||
325 | current_time = {get_time(HI),get_time(LO)}; | |
326 | if(last_time != -1) { | |
327 | ipg = (current_time-last_time)/8; | |
328 | if(debug_xgmii_rx) printf("PC[%0d]: IPG: %0d (Time: %0d)\n",my_port,ipg,current_time); | |
329 | } | |
330 | ||
331 | @(negedge port_bind.$txen); | |
332 | last_time = {get_time(HI),get_time(LO)}; | |
333 | } | |
334 | ||
335 | task pc::rcv_packet_mii (mii_def port_bind, bit [3:0] ptype, byte_array buf, var integer len ) { | |
336 | integer n, cnt; | |
337 | bit [7:0] tmp; | |
338 | ||
339 | tx_err=0; | |
340 | if(debug_mii_rx) printf("RX: Using MII interface ...\n"); | |
341 | ||
342 | tmp[3:0] = port_bind.$txd; | |
343 | while(tmp[3:0] !== 4'h5) { | |
344 | @(posedge port_bind.$txclk); | |
345 | tmp[3:0] = port_bind.$txd; | |
346 | } | |
347 | ||
348 | for(n=0;n<7;n++) { | |
349 | while(!port_bind.$txen) @(posedge port_bind.$txclk); | |
350 | tmp[3:0] = port_bind.$txd; | |
351 | @(posedge port_bind.$txclk); | |
352 | while(!port_bind.$txen) @(posedge port_bind.$txclk); | |
353 | tmp[7:4] = port_bind.$txd; | |
354 | if(debug_mii_rx) printf("RX: Got preamble[%0d]: %h\n",n,tmp); | |
355 | @(posedge port_bind.$txclk); | |
356 | if(tmp != MII_PREAMBLE) { | |
357 | if(tmp != MII_SOF) { | |
358 | print_err(); | |
359 | printf("Receiver Confused, got %0d preambles, then got %h.\n",n,tmp); | |
360 | len = 0; | |
361 | return; | |
362 | } | |
363 | break; | |
364 | } | |
365 | } | |
366 | ||
367 | ||
368 | ||
369 | ||
370 | while(tmp != MII_SOF) { | |
371 | while(!port_bind.$txen) @(posedge port_bind.$txclk); | |
372 | tmp[3:0] = port_bind.$txd; | |
373 | @(posedge port_bind.$txclk); | |
374 | while(!port_bind.$txen) @(posedge port_bind.$txclk); | |
375 | tmp[7:4] = port_bind.$txd; | |
376 | if(debug_mii_rx) printf("RX: Got sof: %h\n",tmp); | |
377 | @(posedge port_bind.$txclk); | |
378 | if(tmp == MII_SOF) break; | |
379 | if(tmp != MII_PREAMBLE) { | |
380 | print_err(); | |
381 | printf("Receiver Confused, did not get SOF, got %h instead.\n",tmp); | |
382 | len = 0; | |
383 | return; | |
384 | } | |
385 | } | |
386 | ||
387 | ||
388 | ||
389 | ||
390 | n = 0; | |
391 | while(port_bind.$txen) { | |
392 | if(port_bind.$txerr==1) tx_err=1; | |
393 | tmp[3:0] = port_bind.$txd; | |
394 | if(!port_bind.$txen) { | |
395 | print_warn(); | |
396 | printf("Received an odd number (%0d) of nibbles ...\n",n); | |
397 | buf.val[n++] = tmp; | |
398 | len = n; | |
399 | break; | |
400 | } | |
401 | @(posedge port_bind.$txclk); | |
402 | if(port_bind.$txerr==1) tx_err=1; | |
403 | tmp[7:4] = port_bind.$txd; | |
404 | if(debug_mii_rx) printf("RX: Got data[%0d]: %h\n",n,tmp); | |
405 | @(posedge port_bind.$txclk); | |
406 | buf.val[n++] = tmp; | |
407 | len = n; | |
408 | } | |
409 | ||
410 | } | |
411 | ||
412 | ||
413 | task pc::rcv_packet_gmii (gmii_def port_bind, bit [3:0] ptype, byte_array buf, var integer len) { | |
414 | integer n, cnt; | |
415 | bit [7:0] tmp; | |
416 | ||
417 | ||
418 | ||
419 | ||
420 | ||
421 | if(debug_gmii_rx) printf("RX: Using GMII interface ...\n"); | |
422 | ||
423 | tx_err=0; | |
424 | ||
425 | tmp = port_bind.$txd; | |
426 | while(tmp !== GMII_PREAMBLE) { | |
427 | @(posedge port_bind.$txclk); | |
428 | tmp = port_bind.$txd; | |
429 | } | |
430 | ||
431 | for(n=0;n<7;n++) { | |
432 | while(!port_bind.$txen) @(posedge port_bind.$txclk); | |
433 | tmp = port_bind.$txd; | |
434 | @(posedge port_bind.$txclk); | |
435 | if(debug_gmii_rx) printf("RX: Got preamble[%0d]: %h\n",n,tmp); | |
436 | if(tmp != GMII_PREAMBLE) { | |
437 | if(tmp != GMII_SOF) { | |
438 | print_err(); | |
439 | printf("Receiver Confused, got %0d preambles, then got %h.\n",n,tmp); | |
440 | len = 0; | |
441 | return; | |
442 | } | |
443 | break; | |
444 | } | |
445 | } | |
446 | ||
447 | ||
448 | ||
449 | ||
450 | while(tmp != GMII_SOF) { | |
451 | while(!port_bind.$txen) @(posedge port_bind.$txclk); | |
452 | if(port_bind.$txerr==1) tx_err=1; | |
453 | tmp = port_bind.$txd; | |
454 | @(posedge port_bind.$txclk); | |
455 | if(debug_gmii_rx) printf("RX: Got sof: %h\n",tmp); | |
456 | if(tmp == GMII_SOF) break; | |
457 | if(tmp != GMII_PREAMBLE) { | |
458 | print_err(); | |
459 | printf("Receiver Confused, did not get SOF, got %h instead.\n",tmp); | |
460 | len = 0; | |
461 | return; | |
462 | } | |
463 | } | |
464 | ||
465 | ||
466 | ||
467 | ||
468 | n = 0; | |
469 | while(port_bind.$txen) { | |
470 | if(port_bind.$txerr==1) tx_err=1; | |
471 | tmp = port_bind.$txd; | |
472 | if(debug_gmii_rx) printf("RX: Got data[%0d]: %h\n",n,tmp); | |
473 | @(posedge port_bind.$txclk); | |
474 | buf.val[n++] = tmp; | |
475 | len = n; | |
476 | } | |
477 | ||
478 | ||
479 | } | |
480 | ||
481 | task pc::rcv_packet_xgmii (xgmii_def port_bind, bit [3:0] ptype, byte_array buf, var integer len) { | |
482 | integer n, cnt; | |
483 | bit [7:0] tmp; | |
484 | bit tmp1; | |
485 | ||
486 | ||
487 | ||
488 | ||
489 | ||
490 | if(debug_xgmii_rx) printf("RX: Using XGMII interface ...\n"); | |
491 | ||
492 | ||
493 | tmp = port_bind.$txd; | |
494 | while(tmp !== XGMII_SOP) { | |
495 | @(posedge port_bind.$txclk_int); | |
496 | tmp = port_bind.$txd; | |
497 | ||
498 | tmp1 = port_bind.$txen; | |
499 | if((tmp == XGMII_SOP) &&(tmp1 != 1)) { | |
500 | print_err(); | |
501 | printf("Receiver Confused, got %0d as tx_control,\n",tmp1); | |
502 | } | |
503 | ||
504 | } | |
505 | ||
506 | ||
507 | for(n=0;n<6;n++) { | |
508 | while(port_bind.$txen) @(posedge port_bind.$txclk_int); | |
509 | ||
510 | tmp = port_bind.$txd; | |
511 | tmp1 = port_bind.$txen; | |
512 | @(posedge port_bind.$txclk_int); | |
513 | if(debug_xgmii_rx) printf("RX: Got preamble[%0d]: %h\n",n,tmp); | |
514 | if((tmp != XGMII_PREAMBLE) && (tmp1 !=0)) { | |
515 | print_err(); | |
516 | printf("Receiver Confused, got %0d preambles, then got %h.\n",n,tmp); | |
517 | len = 0; | |
518 | return; | |
519 | break; | |
520 | } | |
521 | } | |
522 | ||
523 | ||
524 | ||
525 | ||
526 | while(tmp != XGMII_SOF) { | |
527 | while(port_bind.$txen) @(posedge port_bind.$txclk_int); | |
528 | tmp = port_bind.$txd; | |
529 | @(posedge port_bind.$txclk_int); | |
530 | if(debug_xgmii_rx) printf("RX: Got sof: %h\n",tmp); | |
531 | if(tmp == XGMII_SOF) break; | |
532 | if(tmp != XGMII_PREAMBLE) { | |
533 | print_err(); | |
534 | printf("Receiver Confused, did not get SOF, got %h instead.\n",tmp); | |
535 | len = 0; | |
536 | return; | |
537 | } | |
538 | } | |
539 | ||
540 | ||
541 | ||
542 | ||
543 | n = 0; | |
544 | while(!port_bind.$txen) { | |
545 | tmp = port_bind.$txd; | |
546 | if(debug_xgmii_rx) printf("RX: Got data[%0d]: %h\n",n,tmp); | |
547 | @(posedge port_bind.$txclk_int); | |
548 | buf.val[n++] = tmp; | |
549 | len = n; | |
550 | } | |
551 | ||
552 | ||
553 | ||
554 | ||
555 | tmp = port_bind.$txd; | |
556 | tmp1 = port_bind.$txen; | |
557 | @(posedge port_bind.$txclk_int); | |
558 | if(debug_xgmii_rx) printf("RX: Got EOP: %h\n",tmp); | |
559 | if(tmp != XGMII_EOP) { | |
560 | // print_err(); | |
561 | printf("Receiver Confused, did not get EOP, got %h instead.\n",tmp); | |
562 | } | |
563 | ||
564 | ||
565 | } | |
566 | ||
567 | ||
568 | ||
569 | task pc::wait_clk(integer count) { | |
570 | repeat(count) @(posedge CLOCK); | |
571 | } | |
572 | ||
573 | ||
574 | task pc::display_buf( byte_array buf, integer hwlen, (integer ifedx=0)) { | |
575 | integer ptr=0; | |
576 | integer tunneling_ipv4 = 0; | |
577 | integer tunneling_ipv6 = 0; | |
578 | integer ah_transp_ipv4 = 0; | |
579 | integer ah_transp_ipv6 = 0; | |
580 | integer esp_transp_ipv4 = 0; | |
581 | integer esp_transp_ipv6 = 0; | |
582 | ||
583 | integer buf_shift; | |
584 | integer n; | |
585 | bit [15:0] len; | |
586 | bit [7:0] flag_bit; | |
587 | bit [79:0] id; | |
588 | integer token; | |
589 | ||
590 | bit [95:0] debug_mac_hdr_bits; | |
591 | printf("\n\n______________________________________________________________\n"); | |
592 | printf("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\n"); | |
593 | ||
594 | if(ifedx==1) printf("This is an INTER FEDX packet\n\n"); | |
595 | ||
596 | printf("____________ Hex Dump ____________\n"); | |
597 | for(n=0;n<hwlen;n++) { | |
598 | if( !(n % 16) ) printf("\n%d: ",n); | |
599 | printf("%h ", buf.val[ptr++]); | |
600 | } | |
601 | printf("\n__________________________________\n\n"); | |
602 | ||
603 | ptr=0; | |
604 | ||
605 | if(ifedx==1) { | |
606 | printf("Interfedx Control Word: %h\n\n", {buf.val[ptr+1], buf.val[ptr]} ); | |
607 | ptr=ptr+2; | |
608 | } | |
609 | ||
610 | debug_mac_hdr_bits = 0; | |
611 | for(n=0;n<12;n++) { | |
612 | debug_mac_hdr_bits = debug_mac_hdr_bits | (buf.val[11 - n] << 8*n ); | |
613 | } | |
614 | ||
615 | ||
616 | printf(" L2 Header\n"); | |
617 | printf("+---------------\n"); | |
618 | ||
619 | printf("| Destination Address: %h.%h.%h.%h.%h.%h\n", buf.val[ptr++], buf.val[ptr++], | |
620 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
621 | printf("| Source Address: %h.%h.%h.%h.%h.%h\n", buf.val[ptr++], buf.val[ptr++], | |
622 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
623 | ||
624 | len = {buf.val[ptr++], buf.val[ptr++]}; | |
625 | ||
626 | //printf("TEST:The val of ptr is %0d\n",ptr); | |
627 | ||
628 | ||
629 | if( get_plus_arg (CHECK,"ENABLE_MAC_HDR_DEBUG") ) { | |
630 | printf(" DEBUG FROM PKTCHECKER - Received Packet With DMA# - %d, Port# - %d, PacketStartAddress[31:0] -0x%x , Length - %d , DescriptorAddress[31:0]-0x%x \n", debug_mac_hdr_bits[95:91],debug_mac_hdr_bits[90:89],debug_mac_hdr_bits[88:57],debug_mac_hdr_bits [56:43],debug_mac_hdr_bits[42:11]); | |
631 | // printf(" DEBUG From PktChecker: \n"); | |
632 | ||
633 | } | |
634 | if( len == TPID_8021Q ) { | |
635 | ||
636 | ||
637 | if( {buf.val[ptr+4], buf.val[ptr+5], buf.val[ptr+6]} == LLC_SNAP ) { | |
638 | printf("| L2 Header Type: 802.1Q Tagged LLC-SNAP Ethernet Header\n"); | |
639 | printf("| TPID: %0h\n", len ); | |
640 | printf("| TCI: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
641 | ||
642 | len = {buf.val[ptr++], buf.val[ptr++]}; | |
643 | ||
644 | printf("| LEN/TYPE: 0x%h(%0d)\n", len, len ); | |
645 | printf("| LLC: %h\n", {buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] }); | |
646 | printf("| SNAP: %h\n", {buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
647 | buf.val[ptr++], buf.val[ptr++] } ); | |
648 | ||
649 | len = {buf.val[ptr - 2], buf.val[ptr - 1]}; | |
650 | } | |
651 | else { | |
652 | ||
653 | ||
654 | printf("| L2 Header Type: 802.1Q Tagged Ethernet Header\n"); | |
655 | printf("| TPID: %0h\n", len ); | |
656 | printf("| TCI: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
657 | ||
658 | len = {buf.val[ptr++], buf.val[ptr++]}; | |
659 | ||
660 | printf("| TYPE/LEN: 0x%h(%d)\n", len, len); | |
661 | } | |
662 | } | |
663 | else if ( len == CNTL_FRAME ) { | |
664 | ||
665 | ||
666 | printf("| L2 Header Type: MAC Control Frame Header\n"); | |
667 | printf("| Type: %h\n", len ); | |
668 | } | |
669 | else { | |
670 | ||
671 | if( {buf.val[ptr], buf.val[ptr+1], buf.val[ptr+2]} == LLC_SNAP ) { | |
672 | printf("| L2 Header Type: LLC-SNAP Ethernet Header\n"); | |
673 | printf("| Data Length: 0x%h(%0d)\n", len, len); | |
674 | printf("| LLC: %h\n", {buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] }); | |
675 | printf("| SNAP: %h\n", {buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
676 | buf.val[ptr++], buf.val[ptr++] } ); | |
677 | ||
678 | ||
679 | ||
680 | if( buf.val[ptr-2] == 8'h08 ) { | |
681 | ||
682 | ptr +=20; | |
683 | if( buf.val[ptr - 11 ] == TCP_PROTO){ | |
684 | ptr +=20; | |
685 | } | |
686 | } | |
687 | ||
688 | if( buf.val[ptr-2] == 8'h86 ) { | |
689 | ptr +=40; | |
690 | ||
691 | if( buf.val[ptr - 34 ] == TCP_PROTO){ | |
692 | ptr +=20; | |
693 | } | |
694 | } | |
695 | ||
696 | ||
697 | } else { | |
698 | ||
699 | printf("| L2 Header Type: 802.3 Ethernet Header\n"); | |
700 | printf("| Data Length/Type: 0x%h(%0d)\n", len, len); | |
701 | } | |
702 | } | |
703 | ||
704 | token = { buf.val[ptr], buf.val[ptr+1] }; | |
705 | ||
706 | ||
707 | if((len>16'h0600 & len != CNTL_FRAME) || ((len == RARP_FRAME) &(len != CNTL_FRAME))){ | |
708 | ||
709 | len = -1; | |
710 | ||
711 | if((buf.val[ptr - 2 ] == 8'h08 ) || (( buf.val[ptr-2] == 8'h80) &&\ | |
712 | (buf.val[ptr-1] == 8'h35))) { | |
713 | ||
714 | ||
715 | ||
716 | if( buf.val[ptr + 9] == AH_PROTO) { | |
717 | ||
718 | printf("+-------------------------------------\n"); | |
719 | printf(" L3 Header-- Type: IPv4, IPSec: AH\n"); | |
720 | printf("+--------------------------------------\n"); | |
721 | ah_transp_ipv4 = 1; | |
722 | } | |
723 | else if( buf.val[ptr + 9] == ESP_PROTO) { | |
724 | ||
725 | printf("+-------------------------------------\n"); | |
726 | printf(" L3 Header-- Type: IPv4, IPSec: ESP\n"); | |
727 | printf("+--------------------------------------\n"); | |
728 | esp_transp_ipv4 = 1; | |
729 | ||
730 | } | |
731 | else if( buf.val[ptr + 9] == IP_V4_PROTO) { | |
732 | ||
733 | printf("+-------------------------------------\n"); | |
734 | printf(" L3 Header-- Type: Tunnel (IPv4/IPv4)\n"); | |
735 | printf("+--------------------------------------\n"); | |
736 | printf("| IP Header Tunnel Layer 1: IPv4\n| \n"); | |
737 | ||
738 | tunneling_ipv4 = 1; | |
739 | } | |
740 | else if( buf.val[ptr + 9] == IP_V6_PROTO) { | |
741 | ||
742 | printf("+-------------------------------------\n"); | |
743 | printf(" L3 Header-- Type: Tunnel (IPv4/IPv6)\n"); | |
744 | printf("+--------------------------------------\n"); | |
745 | printf("| IP Header Tunnel Layer 1: IPv4\n| \n"); | |
746 | ||
747 | tunneling_ipv6 = 1; | |
748 | } | |
749 | else { | |
750 | ||
751 | printf("+-------------------------------------\n"); | |
752 | printf(" L3 Header-- Type: IPv4\n"); | |
753 | printf("+--------------------------------------\n"); | |
754 | } | |
755 | ptr--; | |
756 | ptr--; | |
757 | ||
758 | display_class(buf, ptr); | |
759 | ||
760 | ||
761 | ||
762 | printf("| IPV4 Payload Len: %h%h\n", buf.val[ptr-10], buf.val[ptr-9] ); | |
763 | ||
764 | printf("| IPV4 Checksum: %h%h\n", buf.val[ptr-2], buf.val[ptr-1] ); | |
765 | ||
766 | printf("| IP SRC Address: %h.%h.%h.%h\n", | |
767 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
768 | printf("| IP DST Address: %h.%h.%h.%h\n", | |
769 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
770 | ||
771 | if (esp_transp_ipv4) { | |
772 | printf("| ESP SPI : %h.%h.%h.%h\n", | |
773 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
774 | ||
775 | } | |
776 | ||
777 | if (ah_transp_ipv4) { | |
778 | ptr += 4; | |
779 | printf("| AH SPI : %h.%h.%h.%h\n", | |
780 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
781 | ||
782 | } | |
783 | ||
784 | if( tunneling_ipv4 ) { | |
785 | ||
786 | ||
787 | printf("| ----------- \n|\n"); | |
788 | printf("| IP Header Tunnel Layer 2: IPv4:\n"); | |
789 | printf("| \n"); | |
790 | ||
791 | ptr--; | |
792 | ptr--; | |
793 | ||
794 | display_class(buf, ptr); | |
795 | ||
796 | printf("| IP SRC Address: %h.%h.%h.%h\n", | |
797 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
798 | printf("| IP DST Address: %h.%h.%h.%h\n", | |
799 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
800 | ||
801 | } | |
802 | else if( tunneling_ipv6) { | |
803 | ||
804 | ||
805 | printf("| ----------- \n|\n"); | |
806 | printf("| IP Header Tunnel Layer 2: IPv6:\n"); | |
807 | printf("| \n"); | |
808 | ||
809 | ptr--; | |
810 | ptr--; | |
811 | ||
812 | display_class_ipv6(buf, ptr); | |
813 | ||
814 | printf("| Payload Len: 0x%h(%d)\n", buf.val[ptr++], buf.val[ptr++]); | |
815 | printf("| Next Header: 0x%h\n", buf.val[ptr++]); | |
816 | printf("| Hop Limit : 0x%h\n", buf.val[ptr++]); | |
817 | printf("| IP SRC Address: %h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h\n", | |
818 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
819 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
820 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
821 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
822 | printf("| IP DST Address: %h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h\n", | |
823 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
824 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
825 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
826 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
827 | } | |
828 | ||
829 | ||
830 | ||
831 | ||
832 | ||
833 | ||
834 | ||
835 | if( tunneling_ipv6 ) | |
836 | ||
837 | buf_shift = 34; | |
838 | else | |
839 | buf_shift = 11; | |
840 | ||
841 | ||
842 | if( buf.val[ptr - buf_shift ] == UDP_PROTO) { | |
843 | ||
844 | printf("+-------------------------------------\n"); | |
845 | printf(" L4 Header-- Type: UDP \n"); | |
846 | printf("+--------------------------------------\n"); | |
847 | printf("| UDP SRC Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
848 | printf("| UDP DST Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
849 | ||
850 | token = { buf.val[ptr + 4], buf.val[ptr + 5] }; | |
851 | } | |
852 | else if( buf.val[ptr - buf_shift ] == TCP_PROTO) { | |
853 | ||
854 | printf("+-------------------------------------\n"); | |
855 | printf(" L4 Header-- Type: TCP\n"); | |
856 | printf("+--------------------------------------\n"); | |
857 | ||
858 | printf("| TCP SRC Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
859 | printf("| TCP DST Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
860 | printf("| TCP Sequence #: %h\n", {buf.val[ptr++], buf.val[ptr++], | |
861 | buf.val[ptr++], buf.val[ptr++]} ); | |
862 | printf("| TCP ACK #: %h\n", {buf.val[ptr++], buf.val[ptr++], | |
863 | buf.val[ptr++], buf.val[ptr++]} ); | |
864 | ||
865 | ||
866 | ptr += 1; | |
867 | ||
868 | flag_bit = buf.val[ptr++]; | |
869 | ||
870 | printf("| TCP Flag bits: URG:%b ACK:%b PSH:%b RST:%b SYN:%b FIN:%b\n", | |
871 | flag_bit[5], flag_bit[4], flag_bit[3], flag_bit[2], flag_bit[1], flag_bit[0]); | |
872 | printf("| Window Size: %h\n", {buf.val[ptr++], buf.val[ptr++]}); | |
873 | printf("| TCP Checksum: %h\n", {buf.val[ptr++], buf.val[ptr++]}); | |
874 | printf("+---------------\n"); | |
875 | ||
876 | token = { buf.val[ptr + 2], buf.val[ptr+3] }; | |
877 | ||
878 | } | |
879 | ||
880 | ||
881 | else if (esp_transp_ipv4) { | |
882 | ||
883 | ptr += 8; | |
884 | ||
885 | token = { buf.val[ptr], buf.val[ptr+1] }; | |
886 | ||
887 | } | |
888 | ||
889 | else if (ah_transp_ipv4) { | |
890 | ||
891 | ptr += 4; | |
892 | ||
893 | token = { buf.val[ptr], buf.val[ptr+1] }; | |
894 | } | |
895 | ||
896 | ||
897 | else { | |
898 | ||
899 | ||
900 | token = { buf.val[ptr], buf.val[ptr+1] }; | |
901 | } | |
902 | } | |
903 | else { | |
904 | ||
905 | ||
906 | ||
907 | ||
908 | if( buf.val[ptr + 6] == AH_PROTO) { | |
909 | ||
910 | printf("+-------------------------------------\n"); | |
911 | printf(" L3 Header-- Type: IPv6, IPSec: AH\n"); | |
912 | printf("+--------------------------------------\n"); | |
913 | ah_transp_ipv6 = 1; | |
914 | } | |
915 | else if( buf.val[ptr + 6] == ESP_PROTO) { | |
916 | ||
917 | printf("+-------------------------------------\n"); | |
918 | printf(" L3 Header-- Type: IPv6, IPSec: ESP\n"); | |
919 | printf("+--------------------------------------\n"); | |
920 | esp_transp_ipv6 = 1; | |
921 | } | |
922 | else if( buf.val[ptr + 6] == IP_V4_PROTO) { | |
923 | ||
924 | printf("+-------------------------------------\n"); | |
925 | printf(" L3 Header-- Type: Tunnel (IPv6/IPv4)\n"); | |
926 | printf("+--------------------------------------\n"); | |
927 | printf("| IP Header Tunnel Layer 1: IPv6\n"); | |
928 | printf("| \n"); | |
929 | ||
930 | tunneling_ipv4 = 1; | |
931 | } | |
932 | else if( buf.val[ptr + 6] == IP_V6_PROTO) { | |
933 | ||
934 | printf("+-------------------------------------\n"); | |
935 | printf(" L3 Header-- Type: Tunnel (IPv6/IPv6)\n"); | |
936 | printf("+--------------------------------------\n"); | |
937 | printf("| IP Header Tunnel Layer 1: IPv6\n"); | |
938 | printf("| \n"); | |
939 | ||
940 | tunneling_ipv6 = 1; | |
941 | } | |
942 | else { | |
943 | ||
944 | printf("+-------------------------------------\n"); | |
945 | printf(" L3 Header-- Type: IPv6\n"); | |
946 | printf("+--------------------------------------\n"); | |
947 | } | |
948 | ptr--; | |
949 | ptr--; | |
950 | ||
951 | display_class_ipv6(buf, ptr); | |
952 | ||
953 | printf("| Payload Len: 0x%h(%d)\n", buf.val[ptr++], buf.val[ptr++]); | |
954 | printf("| Next Header: 0x%h\n", buf.val[ptr++]); | |
955 | printf("| Hop Limit : 0x%h\n", buf.val[ptr++]); | |
956 | printf("| IP SRC Address: %h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h\n", | |
957 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
958 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
959 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
960 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
961 | printf("| IP DST Address: %h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h\n", | |
962 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
963 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
964 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
965 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
966 | ||
967 | if (esp_transp_ipv6) { | |
968 | printf("| ESP SPI : %h.%h.%h.%h\n", | |
969 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
970 | ||
971 | } | |
972 | ||
973 | if (ah_transp_ipv6) { | |
974 | ptr += 4; | |
975 | printf("| AH SPI : %h.%h.%h.%h\n", | |
976 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
977 | ||
978 | } | |
979 | ||
980 | if( tunneling_ipv4 ) { | |
981 | ||
982 | ||
983 | printf("| ----------- \n|\n"); | |
984 | printf("| IP Header Tunnel Layer 2: IPv4:\n"); | |
985 | printf("| \n"); | |
986 | ||
987 | ptr--; | |
988 | ptr--; | |
989 | ||
990 | display_class(buf, ptr); | |
991 | ||
992 | printf("| IP SRC Address: %h.%h.%h.%h\n", | |
993 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
994 | printf("| IP DST Address: %h.%h.%h.%h\n", | |
995 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
996 | ||
997 | } | |
998 | else if( tunneling_ipv6) { | |
999 | ||
1000 | ||
1001 | printf("| ----------- \n|\n"); | |
1002 | printf("| IP Header Tunnel Layer 2: IPv6:\n"); | |
1003 | printf("| \n"); | |
1004 | ||
1005 | ptr--; | |
1006 | ptr--; | |
1007 | ||
1008 | display_class_ipv6(buf, ptr); | |
1009 | ||
1010 | printf("| Payload Len: 0x%h(%d)\n", buf.val[ptr++], buf.val[ptr++]); | |
1011 | printf("| Next Header: 0x%h\n", buf.val[ptr++]); | |
1012 | printf("| Hop Limit : 0x%h\n", buf.val[ptr++]); | |
1013 | printf("| IP SRC Address: %h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h\n", | |
1014 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
1015 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
1016 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
1017 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
1018 | printf("| IP DST Address: %h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h:%h%h\n", | |
1019 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
1020 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
1021 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], | |
1022 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] ); | |
1023 | } | |
1024 | ||
1025 | ||
1026 | ||
1027 | ||
1028 | ||
1029 | ||
1030 | if( tunneling_ipv4 ) | |
1031 | ||
1032 | buf_shift = 11; | |
1033 | else | |
1034 | buf_shift = 34; | |
1035 | ||
1036 | if( buf.val[ptr - buf_shift ] == UDP_PROTO) { | |
1037 | ||
1038 | ||
1039 | printf("+-------------------------------------\n"); | |
1040 | printf(" L4 Header-- Type: UDP \n"); | |
1041 | printf("+--------------------------------------\n"); | |
1042 | printf("| UDP SRC Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1043 | printf("| UDP DST Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1044 | ||
1045 | token = { buf.val[ptr + 4], buf.val[ptr+5] }; | |
1046 | } | |
1047 | else if( buf.val[ptr - buf_shift ] == TCP_PROTO) { | |
1048 | ||
1049 | printf("+-------------------------------------\n"); | |
1050 | printf(" L4 Header-- Type: TCP\n"); | |
1051 | printf("+--------------------------------------\n"); | |
1052 | ||
1053 | printf("| TCP SRC Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1054 | printf("| TCP DST Port: %h\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1055 | printf("| TCP Sequence #: %h\n", {buf.val[ptr++], buf.val[ptr++], | |
1056 | buf.val[ptr++], buf.val[ptr++]} ); | |
1057 | printf("| TCP ACK #: %h\n", {buf.val[ptr++], buf.val[ptr++], | |
1058 | buf.val[ptr++], buf.val[ptr++]} ); | |
1059 | ||
1060 | ||
1061 | ptr += 1; | |
1062 | ||
1063 | flag_bit = buf.val[ptr++]; | |
1064 | ||
1065 | printf("| TCP Flag bits: URG:%b ACK:%b PSH:%b RST:%b SYN:%b FIN:%b\n", | |
1066 | flag_bit[5], flag_bit[4], flag_bit[3], flag_bit[2], flag_bit[1], flag_bit[0]); | |
1067 | printf("| Window Size: %h\n", {buf.val[ptr++], buf.val[ptr++]}); | |
1068 | printf("| TCP Checksum: %h\n", {buf.val[ptr++], buf.val[ptr++]}); | |
1069 | printf("+---------------\n"); | |
1070 | ||
1071 | token = { buf.val[ptr + 2], buf.val[ptr+3] }; | |
1072 | ||
1073 | } | |
1074 | ||
1075 | else if (esp_transp_ipv6) { | |
1076 | ||
1077 | ptr += 8; | |
1078 | ||
1079 | token = { buf.val[ptr], buf.val[ptr+1] }; | |
1080 | ||
1081 | } | |
1082 | ||
1083 | else if (ah_transp_ipv6) { | |
1084 | ||
1085 | ptr += 4; | |
1086 | ||
1087 | token = { buf.val[ptr], buf.val[ptr+1] }; | |
1088 | } | |
1089 | else { | |
1090 | ||
1091 | token = { buf.val[ptr], buf.val[ptr+1] }; | |
1092 | } | |
1093 | } | |
1094 | } | |
1095 | ||
1096 | ||
1097 | if(len<0) len = hwlen; | |
1098 | ||
1099 | printf("\npc::display_buf Time: %0d\n",{get_time(HI),get_time(LO)}); | |
1100 | printf("Token: %0d\n", token); | |
1101 | ||
1102 | ||
1103 | printf("\n"); | |
1104 | if(ifedx==1) display_data(buf, ptr, hwlen-ptr-4-4 ); | |
1105 | else display_data(buf, ptr, hwlen-ptr-4 ); | |
1106 | ||
1107 | printf("\n"); | |
1108 | printf("CRC: %h\n", { buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } ); | |
1109 | ||
1110 | if(ifedx==1) | |
1111 | printf("\n INTER FEDX CRC: %h\n", | |
1112 | { buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } ); | |
1113 | ||
1114 | printf("\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); | |
1115 | printf("--------------------------------------------------------------\n\n"); | |
1116 | ||
1117 | } | |
1118 | ||
1119 | ||
1120 | task pc::display_class(byte_array buf, var integer ptr) { | |
1121 | integer n,last; | |
1122 | ||
1123 | last = ptr+14; | |
1124 | ||
1125 | printf("| Class: "); | |
1126 | ||
1127 | ||
1128 | for(n=0;n<14;n++) printf("%h ", buf.val[ptr+n] ); | |
1129 | printf("\n"); | |
1130 | ||
1131 | if( {buf.val[ptr], buf.val[ptr+1]} < 16'h0600) | |
1132 | printf("| Length: %0d\n|\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1133 | else | |
1134 | printf("| Type: %0h\n|\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1135 | ||
1136 | ptr=last; | |
1137 | } | |
1138 | ||
1139 | ||
1140 | task pc::display_class_ipv6(byte_array buf, var integer ptr) { | |
1141 | integer n,last; | |
1142 | ||
1143 | last = ptr+6; | |
1144 | ||
1145 | printf("| Class: "); | |
1146 | ||
1147 | ||
1148 | for(n=0;n<10;n++) printf("%h ", buf.val[ptr+n] ); | |
1149 | printf("\n"); | |
1150 | ||
1151 | if( {buf.val[ptr], buf.val[ptr+1]} < 16'h0600) | |
1152 | printf("| Length: %0d\n|\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1153 | else | |
1154 | printf("| Type: %0h\n|\n", {buf.val[ptr++], buf.val[ptr++]} ); | |
1155 | ||
1156 | ptr=last; | |
1157 | } | |
1158 | ||
1159 | ||
1160 | ||
1161 | task pc::display_data(byte_array buf, var integer ptr, integer len) { | |
1162 | integer n; | |
1163 | ||
1164 | printf(" Data:\n"); | |
1165 | printf("+---------------"); | |
1166 | ||
1167 | if(len<1) | |
1168 | printf("\n| No Payload ..."); | |
1169 | else | |
1170 | ||
1171 | for(n=0;n< len ;n++) { | |
1172 | if( !(n % 16) ) printf("\n| %d: ",n); | |
1173 | printf("%h ", buf.val[ptr++]); | |
1174 | } | |
1175 | printf("\n+---------------\n"); | |
1176 | } | |
1177 | ||
1178 | ||
1179 | task pc::display_id(bit [79:0] id) { | |
1180 | ||
1181 | printf(" ID Tags:\n"); | |
1182 | printf("+---------------\n"); | |
1183 | printf("| Src port: %0d\n", id[79:75] ); | |
1184 | printf("| Dst port: %0h\n", id[74:35] ); | |
1185 | printf("| Order Type: %0h\n", id[34:33] ); | |
1186 | printf("| Order Sequnce: %0d\n", id[32:27] ); | |
1187 | printf("| Packet number: %0d\n", id[26:11] ); | |
1188 | printf("| Data Type: %0d\n", id[10:8] ); | |
1189 | printf("| Data Seed: %0d\n", id[7:0] ); | |
1190 | printf("+---------------\n"); | |
1191 | } | |
1192 | ||
1193 | ||
1194 | task pc::display_db(pack_db_entry pack_db ) { | |
1195 | ||
1196 | if(pack_db == null) { | |
1197 | printf("This entry is not allocated ...\n"); | |
1198 | } else { | |
1199 | printf("\n========== Display DB Entry %0d ========== \n",pack_db.gId); | |
1200 | printf("\tframe.frame_type: %h\n",pack_db.frame.frame_type); | |
1201 | printf("\tframe.frame_class: %h\n",pack_db.frame.frame_class); | |
1202 | printf("\tframe.class_mask: %h\n",pack_db.frame.class_mask); | |
1203 | printf("\tframe.class_funct: %h\n",pack_db.frame.class_funct); | |
1204 | printf("\tframe.data_type: %h\n",pack_db.frame.data_type); | |
1205 | printf("\tframe.data_seed: %h\n",pack_db.frame.data_seed); | |
1206 | printf("\tframe.data_length: %h\n",pack_db.data_length); | |
1207 | printf("\n"); | |
1208 | printf("\tsrc_node.l2_addr: %h\n",pack_db.src_node.l2_addr); | |
1209 | printf("\tsrc_node.tci: %h\n",pack_db.src_node.tci); | |
1210 | printf("\tsrc_node.ip_addr: %h\n",pack_db.src_node.ip_addr); | |
1211 | printf("\tsrc_node.ipv6_addr: %h\n",pack_db.src_node.ipv6_addr); | |
1212 | printf("\n"); | |
1213 | printf("\tdst_node.l2_addr: %h\n",pack_db.dst_node.l2_addr); | |
1214 | printf("\tdst_node.tci: %h\n",pack_db.dst_node.tci); | |
1215 | printf("\tdst_node.ip_addr: %h\n",pack_db.dst_node.ip_addr); | |
1216 | printf("\tdst_node.ipv6_addr: %h\n",pack_db.dst_node.ipv6_addr); | |
1217 | printf("\n"); | |
1218 | printf("\ttup.src_tcp_udp_port: %h\n",pack_db.tup.src_tcp_udp_port); | |
1219 | printf("\ttup.dst_tcp_udp_port: %h\n",pack_db.tup.dst_tcp_udp_port); | |
1220 | printf("\n"); | |
1221 | printf("\trcv_isn: %0h\n",pack_db.rx_param.rcv_isn); | |
1222 | printf("\tlast_ackno: %0h\n",pack_db.rx_param.last_ackno); | |
1223 | printf("\tadv_isn: %0h\n",pack_db.tx_param.adv_isn); | |
1224 | printf("\tlast_seqno: %0h\n",pack_db.tx_param.last_seqno); | |
1225 | printf("\n"); | |
1226 | printf("\torg_port: %0d\n",pack_db.org_port); | |
1227 | printf("\torder_seq: %0d\n",pack_db.order_seq); | |
1228 | printf("\tpckt_num: %0d\n",pack_db.pckt_num); | |
1229 | printf("\toptions: %h\n",pack_db.options); | |
1230 | } | |
1231 | printf("========================================== \n\n"); | |
1232 | } | |
1233 | ||
1234 | task pc::display_flow(integer flow_id) { | |
1235 | ||
1236 | printf("\n========== Display FLOW DB Entry %0d ========== \n",flow_id); | |
1237 | if(flow_db[flow_id] == null) { | |
1238 | printf("This entry is not allocated ...\n"); | |
1239 | } else { | |
1240 | printf("\tframe.data_length: %h\n",flow_db[flow_id].data_length); | |
1241 | printf("\n"); | |
1242 | printf("\ttup.src_tcp_udp_port: %h\n",flow_db[flow_id].tup.src_tcp_udp_port); | |
1243 | printf("\ttup.dst_tcp_udp_port: %h\n",flow_db[flow_id].tup.dst_tcp_udp_port); | |
1244 | printf("\n"); | |
1245 | printf("\torg_port: %0d\n",flow_db[flow_id].org_port); | |
1246 | printf("\trcv_isn: %0h\n",flow_db[flow_id].rx_param.rcv_isn); | |
1247 | printf("\tlast_ackno: %0h\n",flow_db[flow_id].rx_param.last_ackno); | |
1248 | printf("\tadv_isn: %0h\n",flow_db[flow_id].tx_param.adv_isn); | |
1249 | printf("\tlast_seqno: %0h\n",flow_db[flow_id].tx_param.last_seqno); | |
1250 | ||
1251 | ||
1252 | } | |
1253 | printf("========================================== \n\n"); | |
1254 | } | |
1255 | ||
1256 | task pc::get_om_token() { | |
1257 | // TOADS--- | |
1258 | if(mbox_id != null & mbox_id.mac_opp[my_port] != -1) { | |
1259 | mailbox_get(NO_WAIT,mbox_id.mac_opp[my_port], om_token); | |
1260 | if( flag() ) { | |
1261 | om_token = -1; | |
1262 | flag(OFF); | |
1263 | print_err(); | |
1264 | printf("Could not get token from OPP-MAC checker mailbox.\n"); | |
1265 | } | |
1266 | } else { | |
1267 | om_token = -1; | |
1268 | print_err(); | |
1269 | printf("OPP-MAC checker %0d outgoing mailbox not allocated.\n", | |
1270 | my_port); | |
1271 | } | |
1272 | ||
1273 | } | |
1274 | ||
1275 | function integer pc::drain_tokens( var CpgToken pgToken) { | |
1276 | integer no_of_tkns; | |
1277 | integer sync_up; | |
1278 | integer count =0; | |
1279 | sync_up = 0; | |
1280 | ||
1281 | count = 0; | |
1282 | while(sync_up==0) { | |
1283 | no_of_tkns = mailbox_get(COPY_NO_WAIT,mbox_id.mac_opp[my_port], pgToken); | |
1284 | if(no_of_tkns == 0) { | |
1285 | drain_tokens = 1; sync_up = 1; | |
1286 | } else if(pgToken.do_not_check==1) { | |
1287 | while((no_of_tkns != 0) && (pgToken.tx_request_seen==0) && (pgToken.do_not_check==1) && ( count <10000)) { | |
1288 | no_of_tkns = mailbox_get(NO_WAIT,mbox_id.mac_opp[my_port], pgToken); | |
1289 | printf("pc_top_pp, drain_tokens, num_of_tokens %d\n",no_of_tkns); | |
1290 | count++; | |
1291 | printf("pc::drain_tokens REMOVING OLD TOKEN - %d \n",pgToken.gId); | |
1292 | printf("drain_tokens:: TX REQUEST SEEN - %d FOR - ID - %d\n", pgToken.tx_request_seen , pgToken.gId); | |
1293 | } | |
1294 | ||
1295 | if(count>=10000) { | |
1296 | printf("TEST ERROR -- pc::drain_tokens: Some +args seems to be missing!!! \n"); | |
1297 | exit(0); | |
1298 | } | |
1299 | ||
1300 | if(pgToken.do_not_check==0) { | |
1301 | drain_tokens = 0; sync_up = 1; | |
1302 | } else { | |
1303 | drain_tokens = 1; sync_up = 1; | |
1304 | } | |
1305 | } else if(pgToken.do_not_check==0) { | |
1306 | no_of_tkns = mailbox_get(NO_WAIT,mbox_id.mac_opp[my_port], pgToken); | |
1307 | drain_tokens = 0; sync_up = 1; | |
1308 | printf("pc::drain_tokens POPPING NEW TOKEN - %d \n",pgToken.gId); | |
1309 | printf("CheckReqCbs:: TX REQUEST SEEN - %d FOR - ID - %d\n", pgToken.tx_request_seen , pgToken.gId); | |
1310 | ||
1311 | } | |
1312 | @(posedge CLOCK); | |
1313 | // @(posedge port_bind.$txclk_int); | |
1314 | } | |
1315 | ||
1316 | } | |
1317 | ||
1318 | ||
1319 | ||
1320 | task pc::pkt_check(byte_array buf, integer hwlen) { | |
1321 | integer token; | |
1322 | integer ptr=0; | |
1323 | integer i,n,m; | |
1324 | integer len; | |
1325 | integer type_len; | |
1326 | integer error=0; | |
1327 | bit padded=0; | |
1328 | integer llc_snap=0; | |
1329 | bit [79:0] id; | |
1330 | byte_array nb; | |
1331 | bit [39:0] base_addr; | |
1332 | bit [31:0] min_frame_size, max_frame_size,tmp32; | |
1333 | bit [31:0] min_size, max_size; | |
1334 | bit tmp1,bad_packet; | |
1335 | integer no_of_tkns ; | |
1336 | integer debug_checker = 1; | |
1337 | CpgToken pgToken; | |
1338 | pack_db_entry pack_db; | |
1339 | integer LLC_HACK = 1; | |
1340 | bit[15:0] llc_length; | |
1341 | integer dma_id; | |
1342 | bit [7:0] id_of_dma; | |
1343 | integer skip_checking; | |
1344 | integer dma_id_from_pkt; | |
1345 | bit[3:0] drr_bypass; | |
1346 | ||
1347 | #ifdef N2_FC | |
1348 | min_size = 10'h40; | |
1349 | max_size = 14'h5EE; | |
1350 | #else | |
1351 | ||
1352 | base_addr = bmac_util.get_mac_reg_base(my_port); | |
1353 | ||
1354 | max_frame_size[31:14] = 0; | |
1355 | ||
1356 | if ((my_port ==0) || (my_port==1)) { | |
1357 | mac_util.ipp_shadow_rd(base_addr + XMAC_MAX,max_size,tmp32,tmp1); | |
1358 | } | |
1359 | else { | |
1360 | bmac_util.ipp_shadow_rd(base_addr + BMAC_MAX,max_size,tmp32,tmp1); | |
1361 | } | |
1362 | //printf("The prog MAX_FRAME_SIZE is %0h\n",max_size); | |
1363 | //max_frame_size[13:0] = 14'h5EE; | |
1364 | max_frame_size[13:0] = max_size; | |
1365 | min_frame_size[31:10] = 0; | |
1366 | //min_frame_size[9:0] = 10'h040; | |
1367 | if ((my_port ==0) || (my_port==1)) { | |
1368 | mac_util.ipp_shadow_rd(base_addr + XMAC_MIN,min_size,tmp32,tmp1); | |
1369 | } | |
1370 | else { | |
1371 | bmac_util.ipp_shadow_rd(base_addr + BMAC_MIN,min_size,tmp32,tmp1); | |
1372 | } | |
1373 | min_frame_size[9:0] = min_size; | |
1374 | ||
1375 | #endif | |
1376 | ||
1377 | nb = new; | |
1378 | ||
1379 | id_of_dma = buf.val[ptr]; | |
1380 | dma_id = id_of_dma[7:3]; | |
1381 | dma_id_from_pkt = dma_id; | |
1382 | ||
1383 | if (get_plus_arg(CHECK,"BYPASS_TXDRR")) { | |
1384 | // this code used only to weed out other | |
1385 | // tx related issues and till the DRR checker | |
1386 | ||
1387 | be_msg.print(e_mesg_info, "IP_Packet_Chkr", "check_packet", | |
1388 | "Pulling token from DMA_MBX %0d bound to PORT %0d\n",dma_id,my_port); | |
1389 | no_of_tkns = mailbox_get(NO_WAIT,mbox_id.tx_dma_mb[dma_id], pgToken); | |
1390 | } else { | |
1391 | ||
1392 | if(drrbypass_port_num == my_port) { | |
1393 | be_msg.print(e_mesg_info, "IP_Packet_Chkr", "check_packet", | |
1394 | "Pulling token from DMA_MBX %0d bound to PORT %0d\n",dma_id,my_port); | |
1395 | no_of_tkns = mailbox_get(NO_WAIT,mbox_id.tx_dma_mb[dma_id], pgToken); | |
1396 | } else | |
1397 | no_of_tkns = mailbox_get(NO_WAIT,mbox_id.mac_opp[my_port], pgToken); | |
1398 | } | |
1399 | ||
1400 | if(pgToken == null) { | |
1401 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1402 | "IP Packet Checker[%0d]: Did not get token \n", my_port); | |
1403 | return; | |
1404 | } | |
1405 | ||
1406 | skip_checking = 0; | |
1407 | ||
1408 | if( pgToken.do_not_check) { | |
1409 | skip_checking = drain_tokens(pgToken); | |
1410 | } | |
1411 | if(pgToken!=null) { | |
1412 | printf("CheckReqCbs:: TX REQUEST SEEN - %d FOR - ID - %d\n", pgToken.tx_request_seen , pgToken.gId); | |
1413 | } | |
1414 | ||
1415 | if(skip_checking) { | |
1416 | printf("PACKET ID - %d DMA ID - %d PortID - %d SKIPPED CHECKING\n",pgToken.gId,pgToken.tx_dma_id,my_port); | |
1417 | return; | |
1418 | } | |
1419 | ||
1420 | if(pgToken == null) { | |
1421 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1422 | "IP Packet Checker[%0d]: Did not get token \n", my_port); | |
1423 | return; | |
1424 | } | |
1425 | ||
1426 | om_token = pgToken.gId; | |
1427 | pack_db = new pgToken.pack_db; | |
1428 | ||
1429 | be_msg.print(e_mesg_info, "IP_Packet_Chkr", "check_packet", | |
1430 | "IP Packet Checker[%0d] : Received token from NTX-MAC Checker\n", \ | |
1431 | my_port,token); | |
1432 | ||
1433 | if(om_token == -1) { | |
1434 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1435 | "IP Packet Checker[%0d]: Did not get token from NTX-MAC Checker\n", | |
1436 | my_port); | |
1437 | return; | |
1438 | } | |
1439 | ||
1440 | if ( my_port > 1) { | |
1441 | if(pgToken.exp_err == 1) { | |
1442 | error = 1; | |
1443 | } else { | |
1444 | if(tx_err & !check_option( pack_db.options, O_PC_EXP_TXERR) ) { | |
1445 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1446 | "IP Packet Checker[%0d]: Got an unexpected tx_err: Token[%0d]\n", | |
1447 | my_port,om_token); | |
1448 | } | |
1449 | } | |
1450 | } | |
1451 | ||
1452 | if(!tx_err & check_option( pack_db.options, O_PC_EXP_TXERR) ) { | |
1453 | print_err(); | |
1454 | ||
1455 | ||
1456 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1457 | "IP Packet Checker[%0d]: Expected tx_err, did not see it. (Token: %0d)\n" | |
1458 | , my_port, om_token); | |
1459 | } | |
1460 | ||
1461 | if(tx_err & check_option( pack_db.options, O_PC_EXP_TXERR) ) { | |
1462 | error =1 ; | |
1463 | } | |
1464 | ||
1465 | if( check_option( pack_db.options, O_PC_DO_NOT_CHECK) ) { | |
1466 | return; | |
1467 | } | |
1468 | ||
1469 | // Parse Header | |
1470 | // Get length and Payload beginning | |
1471 | // | |
1472 | be_msg.print(e_mesg_debug2, "IP_Packet_Chkr", "check_packet", | |
1473 | "IP Packet Checker[%0d]: Received frame: (Token: %0d)\n",my_port,om_token); | |
1474 | display_buf(buf, hwlen, INTER_FEDX); | |
1475 | ||
1476 | ptr += 12; | |
1477 | ||
1478 | len = {buf.val[ptr++], buf.val[ptr++]}; | |
1479 | type_len = len; | |
1480 | // printf(" type_len %x \n",type_len); | |
1481 | ||
1482 | if( len === TPID_8021Q ) { // Tagged packet | |
1483 | //printf("NVN it is a VLAN packet\n"); | |
1484 | ptr += 2; | |
1485 | type_len = {buf.val[ptr], buf.val[ptr+1]}; | |
1486 | len = 2 + 12+4+2+{buf.val[ptr++], buf.val[ptr++]}; | |
1487 | } | |
1488 | else len=len+12+4+2; | |
1489 | ||
1490 | ||
1491 | if(LLC_HACK && ((pack_db.frame.frame_type== 5'h3 )|| (pack_db.frame.frame_type== 5'h7) | |
1492 | || (pack_db.frame.frame_type== 5'hb) || (pack_db.frame.frame_type== 5'hf))) { | |
1493 | ||
1494 | if((pack_db.frame.frame_type== 5'h3 ) || (pack_db.frame.frame_type== 5'hb)) { | |
1495 | type_len = {buf.val[ 6 + ptr], buf.val[ 6 + ptr+1]}; | |
1496 | } else if((pack_db.frame.frame_type== 5'h7) || (pack_db.frame.frame_type== 5'hf)) { | |
1497 | type_len = {buf.val[ 6 + ptr], buf.val[ 6 + ptr+1]}; | |
1498 | } | |
1499 | printf("LLC_HACK code executed\n"); | |
1500 | } | |
1501 | printf(" type_len %d len - %d ptr - %d \n",type_len,len,ptr); | |
1502 | if( | |
1503 | ( (type_len<16'h0600) & ({buf.val[ptr+0], buf.val[ptr+1], buf.val[ptr+2]} === LLC_SNAP) ) | | |
1504 | ( (type_len==16'h8870) & ({buf.val[ptr+0], buf.val[ptr+1], buf.val[ptr+2]} === LLC_SNAP) ) | |
1505 | ) { // A LLC-SNAP packet | |
1506 | ptr += 6; // bypass llc_snap value | |
1507 | ptr += 2; // bypass the length field in following length feild | |
1508 | llc_snap = 1; | |
1509 | } | |
1510 | printf(" PTR - bypass llc %d \n",ptr); | |
1511 | ||
1512 | //pkt_gen allows the user to modify the type feild with user-defined feilds. | |
1513 | //Whenever user defines the frame.type!=(-1), then pkt_gen modifies the type | |
1514 | //feild with the frame.type value. | |
1515 | //if the user uses this option on a L3 packet, the checker will treat it as a | |
1516 | //standard ip pkt. if the user uses this option on a L2 pkt, the checker will | |
1517 | //treat this pkt like a L2 packet. | |
1518 | if(pack_db.frame.type != -1) { | |
1519 | if( (pack_db.frame.frame_type[1] == 1) ) | |
1520 | ptr += 24; //this will force the packet to be treated as a L3 pkt | |
1521 | else ptr += 0; //this will force the packet to be treated as a L2 pkt | |
1522 | } | |
1523 | else { | |
1524 | //pkt_gen did not use the frame.type switch | |
1525 | //check if the packet has a IP Header | |
1526 | if(type_len>16'h05ff) { | |
1527 | if ( type_len == 16'h0800 ){ //IP Header | |
1528 | //printf("NVN packet is IPv4 \n"); | |
1529 | //ptr += 24; | |
1530 | ptr += 20; | |
1531 | } | |
1532 | else if ( type_len == 16'h86dd ) //IPV6 | |
1533 | ptr += 40; // | |
1534 | else { | |
1535 | be_msg.print(e_mesg_debug2, "IP_Packet_Chkr", "check_packet", | |
1536 | "IP Packet Checker[%0d]:Unidentified packet Type : (Token: %0d)\n",my_port,token); | |
1537 | //Treat such packets also as they have IP Headers. | |
1538 | ptr += 24; | |
1539 | } | |
1540 | } | |
1541 | } | |
1542 | printf(" BEFORE TCP ptr -0 %d\n",ptr); | |
1543 | ||
1544 | //check if the packet is a TCP packet | |
1545 | if ( ( (pack_db.frame.frame_type[1] == 1) && | |
1546 | ( (pack_db.frame.frame_class == CL_TCP) || (pack_db.frame.frame_class == CL_TCP_IP_V6) || | |
1547 | (pack_db.frame.frame_class == CL_TCP_OPT) || | |
1548 | (pack_db.frame.frame_class == CL_TCP_FRAG) ) ) | |
1549 | ) { | |
1550 | ptr += 20; //8words for TCP header | |
1551 | be_msg.print(e_mesg_info, "IP_Packet_Chkr", "check_packet", | |
1552 | "IP Packet Checker[%0d]: Received Token [%0d] detected to be a\ | |
1553 | TCP Packet\n",my_port,token); | |
1554 | } | |
1555 | //check if the packet is a UDP packet | |
1556 | if ( (pack_db.frame.frame_type[1] == 1) && | |
1557 | ( (pack_db.frame.frame_class == CL_UDP) || (pack_db.frame.frame_class == CL_UDP_IP_V6) || | |
1558 | (pack_db.frame.frame_class == CL_UDP_OPT) || | |
1559 | (pack_db.frame.frame_class == CL_UDP_FRAG) ) | |
1560 | ) { | |
1561 | ptr += 8; //2words for UDP header | |
1562 | ||
1563 | be_msg.print(e_mesg_info, "IP_Packet_Chkr", "check_packet", | |
1564 | "IP Packet Checker[%0d]: Received Token [%0d] detected to be a\ | |
1565 | UDP Packet\n",my_port,token); | |
1566 | } | |
1567 | ||
1568 | ||
1569 | ||
1570 | ||
1571 | be_msg.print(e_mesg_debug2, "IP_Packet_Chkr", "check_packet", | |
1572 | "IP Packet Checker[%0d]: Extracted Length: [%0d], hw len: %0d\n", | |
1573 | my_port,len,hwlen); | |
1574 | ||
1575 | // | |
1576 | if(len<0) len = hwlen; | |
1577 | ||
1578 | ||
1579 | ||
1580 | ptr += (pack_db.frame.header_length - 5)*4; | |
1581 | printf(" PC: TOKEN PTR - %d frame_type - %x \n",ptr,pack_db.frame.frame_type); | |
1582 | ||
1583 | if(LLC_HACK && ((pack_db.frame.frame_type== 5'h3 )|| (pack_db.frame.frame_type== 5'h7) | |
1584 | || (pack_db.frame.frame_type== 5'hb) || (pack_db.frame.frame_type== 5'hf))) { | |
1585 | if((pack_db.frame.frame_type== 5'h3) || (pack_db.frame.frame_type== 5'hb)) | |
1586 | token = {buf.val[8+ ptr++], buf.val[8+ ptr++]}; | |
1587 | else if((pack_db.frame.frame_type== 5'h7) || (pack_db.frame.frame_type== 5'hf)) { | |
1588 | token = {buf.val[8+ ptr++], buf.val[8+ ptr++]}; | |
1589 | } | |
1590 | } else token = {buf.val[ptr++], buf.val[ptr++]}; | |
1591 | ||
1592 | be_msg.print(e_mesg_debug2, "IP_Packet_Chkr", "check_packet", | |
1593 | "IP Packet Checker[%0d]: Extracted Token from Packet : %0d\n", | |
1594 | my_port,token); | |
1595 | ||
1596 | // | |
1597 | // Check if packet token matches recieved token | |
1598 | // | |
1599 | #ifdef 0 | |
1600 | // if LLC_HACK | |
1601 | if(token !== om_token) { | |
1602 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1603 | "IP Packet Checker[%0d]: Packet Token (%0d) does not match recived \ | |
1604 | token (%0d).\n", my_port,token,om_token); | |
1605 | token = om_token; | |
1606 | display_buf(buf, hwlen, INTER_FEDX); | |
1607 | return; | |
1608 | } | |
1609 | #endif | |
1610 | ||
1611 | // | |
1612 | // Check if entry exists | |
1613 | // | |
1614 | tmp32 = token; | |
1615 | if( tmp32 === 32'hxxxxxxxx ) { | |
1616 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1617 | "IP Packet Checker[%0d]: Damaged Packet received (Packet token is \ | |
1618 | unknown \n",my_port); | |
1619 | token = om_token; | |
1620 | display_buf(buf, hwlen, INTER_FEDX); | |
1621 | return; | |
1622 | } | |
1623 | if( pack_db== null ) { | |
1624 | ||
1625 | // TOADS---- | |
1626 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1627 | "IP Packet Checker[%0d]: Spurious Packet received (token: %0d\n", | |
1628 | my_port,token); | |
1629 | token = om_token; | |
1630 | display_buf(buf, hwlen, INTER_FEDX); | |
1631 | return; | |
1632 | } | |
1633 | ||
1634 | // Now assemble the whole packet | |
1635 | // | |
1636 | #ifdef MAC_SAT | |
1637 | if(debug_checker) | |
1638 | pack_gen[pgToken.port_id].build_frame(token | 32'h80000000, pack_db, nb, m, my_port, 1); | |
1639 | else | |
1640 | pack_gen[pgToken.port_id].build_frame(token, pack_db, nb, m, my_port, 1); | |
1641 | #else | |
1642 | nb = new pgToken.buf; | |
1643 | m = assoc_index(CHECK,nb.val); | |
1644 | #endif | |
1645 | ||
1646 | if (m<min_frame_size) { | |
1647 | padded = 1'b0; | |
1648 | } else{ | |
1649 | padded = 1'b0; | |
1650 | } | |
1651 | ||
1652 | printf("The val of padded is %0d\n",padded); | |
1653 | ||
1654 | if (( (hwlen != m) & (m <= max_frame_size[13:0]) & (m >= min_frame_size[9:0]) & (!col) ) & ( !( check_option(pack_db.options, O_PC_DO_NOT_CHECK)))) { | |
1655 | if(pgToken.exp_err == 1) { | |
1656 | // don't print the error message for length mismatch | |
1657 | } else { | |
1658 | // this is real error print the length mismatch | |
1659 | print_err(); | |
1660 | printf("Rebuild frame length mismatch (Token: %0d): expected %0d, got: %0d.\n", | |
1661 | token,m,hwlen); | |
1662 | } | |
1663 | error=1; | |
1664 | } | |
1665 | ||
1666 | //-- Commenting out this piece of code | |
1667 | //-- 08/22/05 | |
1668 | //-- MAC tx doesn't perform padding, hence check against min frame doesn't make sense | |
1669 | ||
1670 | /* | |
1671 | if(m < min_frame_size[9:0] & hwlen < min_frame_size[9:0] ) { | |
1672 | print_err(); | |
1673 | printf("Packet was not padded. Min length: %0d, Sent packet Length: %0d, Rcvd Packet length: %0d\n", | |
1674 | min_frame_size[9:0], m, hwlen); | |
1675 | } | |
1676 | */ | |
1677 | ||
1678 | ||
1679 | bad_packet = m > max_frame_size; | |
1680 | ||
1681 | if(hwlen<m) m=hwlen; // Take the shortest length | |
1682 | ||
1683 | // If the packet had a late collision check only the first 55 bytes of the packet | |
1684 | // Anyway the packet is dropped!! | |
1685 | if(col) m = 55; | |
1686 | ||
1687 | ||
1688 | if(padded) { | |
1689 | m=m-4; // Do not compare crc | |
1690 | printf("Info:Packet Checker[%0d]: Token:%0d is a padded packet\n", my_port,token); | |
1691 | } | |
1692 | ||
1693 | if(m>max_frame_size) m = max_frame_size; // Packet will be trunkated | |
1694 | ||
1695 | // | |
1696 | // Now compare the new packet against the recived one | |
1697 | // | |
1698 | for(n=0;n<m;n++) { | |
1699 | //printf("buf[%0d]: %h\n",n,buf.val[n]); | |
1700 | ||
1701 | be_msg.print(e_mesg_debug4, "IP_Packet_Chkr", "check_packet", | |
1702 | "DEBUG4:IP_Packet_Chkr[%0d]: byte: %0d Expected Data :%h Received Data:%0h\n" \ | |
1703 | ,my_port,n,nb.val[n],buf.val[n]); | |
1704 | ||
1705 | if(nb.val[n] !== buf.val[n]) { | |
1706 | ||
1707 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1708 | " DATA_MISMAT:IP_Packet_ChkrPC[%0d]: Token: %0d byte: %0d Received Data :%h Expected Data:%0h\n" , my_port,pgToken.gId, n, buf.val[n], nb.val[n]); | |
1709 | error = 1; | |
1710 | } | |
1711 | } | |
1712 | ||
1713 | if(padded) { // Verify CRC | |
1714 | tmp32 = pack_gen[pgToken.port_id].crc_gen(buf, 0, hwlen-4); | |
1715 | ||
1716 | if( {buf.val[hwlen-4],buf.val[hwlen-3],buf.val[hwlen-2],buf.val[hwlen-1]} !== tmp32 ) { | |
1717 | print_err(); | |
1718 | printf("ERROR: PC[%0d]: NEW CRC Error. Expeced: %h, Got: %h (Token: %0d).\n", | |
1719 | my_port,tmp32, {buf.val[hwlen-4],buf.val[hwlen-3],buf.val[hwlen-2],buf.val[hwlen-1]}, | |
1720 | token); | |
1721 | } | |
1722 | } | |
1723 | ||
1724 | ||
1725 | ||
1726 | if(error == 0) { | |
1727 | if(pgToken.exp_err == 1) { | |
1728 | pack_db.pc_check[my_port] = -1; | |
1729 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1730 | "INFO:IP_Packet_Chkr[%0d]: TokenFromRTL= %0d TokenFromVerif= %0d Packet Length= %0d \ | |
1731 | Got a good pkt, when a error pkt expected : %0d\n" \ | |
1732 | ,my_port,token,pgToken.gId,hwlen,pack_db.pc_check[my_port]); | |
1733 | } else { | |
1734 | pack_db.pc_check[my_port] = 1; | |
1735 | be_msg.print(e_mesg_info, "IP_Packet_Chkr", "check_packet", | |
1736 | "INFO:IP_Packet_Chkr[%0d]: TokenFromRTL= %0d TokenFromVerif= %0d Packet Length= %0d \ | |
1737 | Packet Checker DONE checker status : %0d\n" \ | |
1738 | ,my_port,token,pgToken.gId,hwlen,pack_db.pc_check[my_port]); | |
1739 | } | |
1740 | } | |
1741 | ||
1742 | else { pack_db.pc_check[my_port] = -1; | |
1743 | ||
1744 | if( check_option( pack_db.options, O_PC_EXP_TXERR) ) { | |
1745 | } else if(pgToken.exp_err == 1) { | |
1746 | be_msg.print(e_mesg_info,"IP_Packet_Chkr","check_packet", | |
1747 | "INFO: IP_Packet_Chkr[%0d]: TokenFromRTL= %0d TokenFromVerif= %0d Packet Length= %0d \ | |
1748 | Packet checker Expected_Err_pkt got Err_pkt\n" \ | |
1749 | ,my_port,token,pgToken.gId,hwlen); | |
1750 | } else{ | |
1751 | be_msg.print(e_mesg_error, "IP_Packet_Chkr", "check_packet", | |
1752 | "INFO:IP_Packet_Chkr[%0d]: Token= %0d Packet NOT Received \ | |
1753 | checker status : %0d\n", my_port,token, \ | |
1754 | pack_db.pc_check[my_port]); | |
1755 | } | |
1756 | ||
1757 | } | |
1758 | ||
1759 | } | |
1760 | ||
1761 | ||
1762 | function integer pc::check_option(bit [63:0] option, bit [63:0] flag) { | |
1763 | if((option[63:0] & flag[63:0]) > 64'h0) check_option = 1; | |
1764 | else check_option = 0; | |
1765 | } | |
1766 | ||
1767 | ||
1768 | ||
1769 | ||
1770 | task pc::print_warn() { | |
1771 | printf("WARNING: Packet Checker[%0d]: ", my_port); | |
1772 | } | |
1773 | ||
1774 | ||
1775 | task pc::print_err() { | |
1776 | printf("ERROR: Packet Checker[%0d] time:%0d : ", my_port, {get_time(HI), get_time(LO)}); | |
1777 | } | |
1778 | ||
1779 | ||
1780 | // # 56 "pc_top.vr" 2 | |
1781 | ||
1782 | ||
1783 | task pc::new(integer my_porti, (bit [3:0] ptype=0)) { | |
1784 | integer n,i; | |
1785 | string init_bypass_mac_ports,temp_port; | |
1786 | bit[31:0] bypass_mac_port; | |
1787 | bit[3:0] drr_bypass; | |
1788 | ||
1789 | my_port = my_porti; | |
1790 | port_type = ptype; | |
1791 | ||
1792 | ||
1793 | ||
1794 | ||
1795 | if (my_port>8 ) { | |
1796 | printf("PC: INIT: Port %0d is invalid or out of range.\n", my_port); | |
1797 | ||
1798 | terminate; | |
1799 | } | |
1800 | ||
1801 | if(!quiet_on) | |
1802 | printf("INFO: Packet Checker attaching to port %0d\n",my_port); | |
1803 | ||
1804 | ||
1805 | ||
1806 | ||
1807 | if(pc_used_ports[my_port] == 1) { | |
1808 | printf("PC: INIT: Port %0d already in use.\n", my_port); | |
1809 | ||
1810 | terminate; | |
1811 | } | |
1812 | pc_used_ports[my_port] = 1; | |
1813 | ||
1814 | ||
1815 | ||
1816 | fork | |
1817 | pkt_auto_rx(); | |
1818 | join none | |
1819 | ||
1820 | printf("PKT_CHKR : MY_PORT_VAL %0d\n",my_port); | |
1821 | ||
1822 | fork | |
1823 | case(my_port) { | |
1824 | ||
1825 | 0: if (get_plus_arg(CHECK, "MAC_SPEED0=")) { | |
1826 | mac_speed = get_plus_arg(NUM,"MAC_SPEED0="); | |
1827 | config_rx (m0,mac_speed); | |
1828 | } | |
1829 | ||
1830 | 1: if (get_plus_arg(CHECK, "MAC_SPEED1=")) { | |
1831 | mac_speed = get_plus_arg(NUM,"MAC_SPEED1="); | |
1832 | config_rx (m1,mac_speed); | |
1833 | } | |
1834 | ||
1835 | 2: if (get_plus_arg(CHECK, "MAC_SPEED2=")) { | |
1836 | mac_speed = get_plus_arg(NUM,"MAC_SPEED2="); | |
1837 | printf("PKT_CHKR : MY_PORT_VAL %0d\n",my_port); | |
1838 | printf("PKT_CHKR : MAC_SPEED %0d\n",mac_speed); | |
1839 | config_rx (m2,mac_speed); | |
1840 | } | |
1841 | ||
1842 | 3: if (get_plus_arg(CHECK, "MAC_SPEED3=")) { | |
1843 | mac_speed = get_plus_arg(NUM,"MAC_SPEED3="); | |
1844 | printf("PKT_CHKR : MY_PORT_VAL %0d\n",my_port); | |
1845 | printf("PKT_CHKR : MAC_SPEED %0d\n",mac_speed); | |
1846 | config_rx (m3,mac_speed); | |
1847 | } | |
1848 | ||
1849 | ||
1850 | } | |
1851 | join none | |
1852 | /* drr bypass flag per port*/ | |
1853 | if(get_plus_arg( CHECK, "TXDRR_BYPASS_PORT_NUM=")) | |
1854 | bypass_mac_port = get_plus_arg( STR, "TXDRR_BYPASS_PORT_NUM="); | |
1855 | init_bypass_mac_ports.bittostr(bypass_mac_port); | |
1856 | for(i=0; i<init_bypass_mac_ports.len();i++) { | |
1857 | temp_port =init_bypass_mac_ports.substr(i,i); | |
1858 | drr_bypass = drr_bypass | ( 1<<temp_port.atoi()); | |
1859 | } | |
1860 | if(drr_bypass[my_port]) { | |
1861 | drrbypass_port_num = my_port; | |
1862 | } else drrbypass_port_num = -1; | |
1863 | } | |
1864 | ||
1865 | task pc::status() { | |
1866 | printf("\n"); | |
1867 | printf("------------------------------\n"); | |
1868 | printf("PC[%0d]: Status Report:\n",my_port); | |
1869 | printf(" Encountered %0d ERRORS\n",error_count); | |
1870 | printf(" Encountered %0d WARNINGS\n",warning_count); | |
1871 | printf(" Received %0d packets\n",pack_cnt); | |
1872 | printf("------------------------------\n\n"); | |
1873 | } | |
1874 | ||
1875 | ||
1876 | ||
1877 | task pc::config_rx (mii_def port_bind, integer mac_speed) { | |
1878 | ||
1879 | printf("PKT_CHKR : cfg_rx MAC_SPEED %d\n",mac_speed); | |
1880 | ||
1881 | /* if(mac_speed == 10000) { | |
1882 | port_bind.$tx_config = 4; | |
1883 | port_speed = 4; | |
1884 | printf("PKT_CHKR : CONFIG 10G\n"); | |
1885 | } | |
1886 | ||
1887 | if(mac_speed == 1000) { | |
1888 | port_bind.$tx_config = 3; | |
1889 | port_speed = 3; | |
1890 | printf("PKT_CHKR : CONFIG 1G\n"); | |
1891 | } | |
1892 | ||
1893 | if(mac_speed == 100 ) { | |
1894 | port_bind.$tx_config = 2; | |
1895 | port_speed = 2; | |
1896 | } | |
1897 | ||
1898 | if((mac_speed != 10000) || (mac_speed != 1000) || (mac_speed != 100)) { | |
1899 | port_bind.$tx_config = 1; | |
1900 | port_speed = 1; | |
1901 | } */ | |
1902 | ||
1903 | case(mac_speed) { | |
1904 | 10000 : { | |
1905 | port_bind.$tx_config = 4; | |
1906 | port_speed = 4; | |
1907 | printf("PKT_CHKR : CONFIG 10G\n"); | |
1908 | } | |
1909 | ||
1910 | 1000 : { | |
1911 | port_bind.$tx_config = 3; | |
1912 | port_speed = 3; | |
1913 | printf("PKT_CHKR : CONFIG 1G\n"); | |
1914 | } | |
1915 | ||
1916 | 100 : { | |
1917 | port_bind.$tx_config = 2; | |
1918 | port_speed = 2; | |
1919 | } | |
1920 | default : { | |
1921 | port_bind.$tx_config = 1; | |
1922 | port_speed = 1; | |
1923 | } | |
1924 | } | |
1925 | ||
1926 | } | |
1927 | ||
1928 | ||
1929 |