Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / niu / rxc_sat / vera / pktconfig / pktConfig.vr
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: pktConfig.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
38// Check these
39#include "pcg_defines.vri"
40#include "pcg_types.vri"
41#include "pack_db.vrh"
42#include "flow_db.vrh"
43#include "flow_db_tasks.vrh"
44#include "pg_top_pp.vrh"
45#include "pc_top_pp.vrh"
46#include "pcg_token.vrh"
47
48#include "mbox_class.vrh"
49#include "get_mbox_id.vrh"
50#include "niu_rxtoken.vrh"
51#include "ip_ingress_classes.vrh"
52#include "ip_util.vrh"
53#include "pgIdgen.vrh"
54#include "niu_lptoken.vrh"
55
56
57extern mbox_class mbox_id;
58extern pg pack_gen[16];
59
60
61class CpktConfig {
62
63// Top level class which hold packet generator etc.
64 setup_cam_ram_fcram_class cam_ram_cl;
65 CpgIdgen pgIdgen;
66 bit [3:0] MAC_LOOP_BACK_MODE;
67 bit[15:0] packet_id[4];
68 integer modify_mac_src_addr = 0;
69// details to be worked out
70
71 task new() {
72 integer i,j;
73 string init_loopback,temp_port;
74 bit [31:0] loopback;
75
76
77 if (get_plus_arg(CHECK, "ENABLE_CTRL_FIFO_CHKR"))
78 cam_ram_cl = new;
79 pgIdgen = new();
80 for(i=0;i<4;i++) {
81 packet_id[i] = 0;
82 }
83
84 for(i=0;i<4;i++) {
85 if(mbox_id.niu_pktcfglp[i] == -1) {
86 mbox_id.niu_pktcfglp[i] = alloc(MAILBOX,0,1);
87 }
88 }
89
90 for(i=0;i<4;i++) {
91 if(mbox_id.niu_rxpath_mb[i] == -1) {
92 // Alocate Mailbox
93 mbox_id.niu_rxpath_mb[i] = alloc(MAILBOX,0,1);
94 // Check if we were succesfull allocating the mailbox
95 if(mbox_id.niu_rxpath_mb[i] == 0) {
96 printf("ERROR Could not allocate the outgoing mailbox port %d \n",i);
97 mbox_id.niu_rxpath_mb[i] = -1;
98 return;
99 }
100 }
101 }
102 for(i=0;i<4;i++) {
103 if(mbox_id.mac_opp[i] == -1) {
104 // Alocate Mailbox
105 mbox_id.mac_opp[i] = alloc(MAILBOX,0,1);
106 // Check if we were succesfull allocating the mailbox
107 if(mbox_id.mac_opp[i] == 0) {
108 printf("ERROR Could not allocate the outgoing mailbox port0\n");
109 mbox_id.mac_opp[i] = -1;
110 return;
111 }
112 }
113 }
114
115 if (get_plus_arg (CHECK, "RX_DROP_PKT_CHECK"))
116 modify_mac_src_addr = 1; // tmp added until we find a place to add the id
117 else modify_mac_src_addr =0;
118
119
120 if( get_plus_arg( CHECK, "MAC_LOOP_BACK=")) {
121 loopback = get_plus_arg( STR, "MAC_LOOP_BACK=");
122 init_loopback.bittostr(loopback);
123 for (j=0; j<init_loopback.len();j++)
124 { temp_port =init_loopback.substr(j,j);
125 MAC_LOOP_BACK_MODE = MAC_LOOP_BACK_MODE | ( 1<<temp_port.atoi()); }
126 } else MAC_LOOP_BACK_MODE = 0;
127
128
129 // Start the mem_checker_mbox also here
130 if(mbox_id.niu_rxpacket_memchk_mb == -1) {
131 // Alocate Mailbox
132 mbox_id.niu_rxpacket_memchk_mb = alloc(MAILBOX,0,1);
133 // Check if we were succesfull allocating the mailbox
134 if(mbox_id.niu_rxpacket_memchk_mb == 0) {
135 printf("ERROR Could not allocate the outgoing mailbox port %d \n",i);
136 mbox_id.niu_rxpacket_memchk_mb = -1;
137 return;
138 }
139 }
140 }
141
142 task gen_rxPacket(flow_desc flow, integer data_length, integer dma_num,integer mac_id ,(integer last_packet=0),(CRxTestClass rx_test_class = null) );
143 local task SendPktForLoopBack(flow_desc flow, integer data_length,integer dma_num,integer mac_id, integer last_packet = 0 ) ;
144 local task forward_RxToken(CRxToken RxToken);
145
146}
147
148task CpktConfig::gen_rxPacket(flow_desc flow, integer data_length,integer dma_num,integer mac_id, (integer last_packet = 0), (CRxTestClass rx_test_class = null) ) {
149
150 bit [13:0] pkt_length;
151 integer buf_sz;
152 bit[23:0] r;
153 bit[15:0] id;
154 bit[1:0] m;
155 bit[5:0] d;
156
157
158 CRxToken RxToken;
159 CpgToken pgToken;
160 byte_array nb;
161
162 Cpkt_info pkt_info;
163
164 if(modify_mac_src_addr) {
165 flow.src_node.l2_addr = pgIdgen.getMacSA(dma_num,mac_id);
166 printf("CpktConfig::gen_rxPacket Modified l2src address - %x \n",flow.src_node.l2_addr);
167 }
168
169
170
171 if ( !get_plus_arg (CHECK, "FFLP_TEST") && get_plus_arg(CHECK, "ENABLE_CTRL_FIFO_CHKR")) {
172 pkt_info = cam_ram_cl.construct_flow(0, TCP_SYN, flow);
173 mailbox_put(mbox_id.cntl_chkr_mbox[mac_id], pkt_info);
174 }
175
176 if( 0 /*MAC_LOOP_BACK_MODE[mac_id]*/ ) {
177 SendPktForLoopBack(flow, data_length,dma_num,mac_id,last_packet);
178 } else {
179 RxToken = new();
180 pack_gen[mac_id].pkt_gen(flow, data_length, 3, pgToken, O_WAIT_SEND);
181 pack_gen[mac_id].display_db(pgToken.pack_db);
182 RxToken.id=pgToken.gId;
183 // create a seperate entry indicating the padding
184 RxToken.pkt_length = data_length + flow.frame.l2_pad_length;
185 RxToken.pgToken = new pgToken;
186 RxToken.dma_num=dma_num;
187 RxToken.port_num=mac_id;
188 RxToken.error_info.error_code = flow.frame.error_code; // review Move this to a class
189 RxToken.last_packet=last_packet;
190 if(rx_test_class!=null) {
191 RxToken.rx_test_class = rx_test_class.object_copy();
192 }
193 forward_RxToken(RxToken);
194 }
195}
196
197task CpktConfig::forward_RxToken(CRxToken RxToken) {
198
199 integer mac_id,i;
200// if(blunt_loopback=1) {
201if ( get_plus_arg(CHECK, "BLUNT_END_LOOPBACK") ) {
202 mac_id = RxToken.port_num;
203 // Copy header to out_header in pack_db
204 RxToken.pgToken.pack_db.out_header[mac_id] = new;
205 RxToken.pgToken.pack_db.out_header[mac_id].use_header = 0;
206 RxToken.pgToken.pack_db.out_header[mac_id].header[0] = new;
207 RxToken.pgToken.pack_db.out_header[mac_id].header_len[0] = RxToken.pgToken.pack_db.header_len[ RxToken.pgToken.pack_db.use_hdr ];
208 for( i = 0; i < RxToken.pgToken.pack_db.out_header[mac_id].header_len[0]; i++ )
209 RxToken.pgToken.pack_db.out_header[mac_id].header[0].val[i] =
210 RxToken.pgToken.pack_db.header[ RxToken.pgToken.pack_db.use_hdr ].val[i];
211
212
213 mailbox_put(mbox_id.mac_opp[mac_id],RxToken.pgToken);
214 mailbox_put(mbox_id.niu_rxpath_mb[mac_id],RxToken);
215 //mailbox_put(mbox_id.mac_opp[mac_id],RxToken);
216 } else{
217 mac_id = RxToken.port_num;
218 mailbox_put(mbox_id.niu_rxpath_mb[mac_id],RxToken);
219 }
220
221}
222
223task CpktConfig::SendPktForLoopBack(flow_desc flow, integer data_length,integer dma_num,integer mac_id, integer last_packet = 0 ) {
224 CpktCfgLp pktCfgLp;
225
226
227 pktCfgLp = new();
228 pktCfgLp.flow = flow;
229 pktCfgLp.rx_dma = dma_num;
230 pktCfgLp.port_id = mac_id;
231 pktCfgLp.last_packet = last_packet;
232 pktCfgLp.data_length = data_length;
233
234 mailbox_put(mbox_id.niu_pktcfglp[mac_id],pktCfgLp);
235
236}