Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: niu_txcntrl_wd.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 "pcg_defines.vri" | |
36 | #include "niu_tx_pktconfig.vrh" | |
37 | ||
38 | ||
39 | ||
40 | class TxPacketControlWord { | |
41 | ||
42 | integer id; | |
43 | // Ethernet Transmit Packet Header | |
44 | ||
45 | // 128 bits control header for alignment | |
46 | bit [1:0] pkt_type; | |
47 | bit ip_ver; | |
48 | bit v4_hdr_cs; | |
49 | bit [1:0] l4_proto_op; | |
50 | bit tcp_udp_crc_32c; | |
51 | bit [4:0] rsvd_56_52; | |
52 | bit [3:0] l3_start; | |
53 | bit [1:0] rsvd_47_46; | |
54 | bit [5:0] l4_start; | |
55 | bit [1:0] rsvd_39_38; | |
56 | bit [5:0] l4_stuff; | |
57 | bit [1:0] rsvd_31_30; | |
58 | bit [13:0] length; | |
59 | bit [63:0] rsvd_127_64; | |
60 | bit [12:0] rsvd_15_3; | |
61 | bit [2:0] pad; | |
62 | ||
63 | task new(integer i = 0) { | |
64 | id = i; | |
65 | ||
66 | rsvd_15_3 = 13'h0; | |
67 | rsvd_56_52 = 5'h0; | |
68 | rsvd_47_46 = 2'h0; | |
69 | rsvd_39_38 = 2'h0; | |
70 | rsvd_31_30 = 2'h0; | |
71 | rsvd_127_64 = 64'h0; | |
72 | } | |
73 | ||
74 | function bit[127:0] get_header() { | |
75 | get_header = {rsvd_127_64, | |
76 | pkt_type, | |
77 | ip_ver, | |
78 | v4_hdr_cs, | |
79 | l4_proto_op, | |
80 | tcp_udp_crc_32c, | |
81 | rsvd_56_52, | |
82 | l3_start, | |
83 | rsvd_47_46, | |
84 | l4_start, | |
85 | rsvd_39_38, | |
86 | l4_stuff, | |
87 | rsvd_31_30, | |
88 | length, | |
89 | rsvd_15_3, | |
90 | pad}; | |
91 | } | |
92 | ||
93 | task set_control_word ( bit [127:0] w) { | |
94 | rsvd_127_64 = w[127:64]; | |
95 | pkt_type = w[63:62]; | |
96 | ip_ver = w[61]; | |
97 | v4_hdr_cs = w[60]; | |
98 | l4_proto_op = w[59:58]; | |
99 | tcp_udp_crc_32c = w[57]; | |
100 | rsvd_56_52 = w[56:52]; | |
101 | l3_start = w[51:48]; | |
102 | rsvd_47_46 = w[47:46]; | |
103 | l4_start = w[45:40]; | |
104 | rsvd_39_38 = w[39:38]; | |
105 | l4_stuff = w[37:32]; | |
106 | rsvd_31_30 = w[31:30]; | |
107 | length = w[29:16]; | |
108 | rsvd_15_3 = w[15:3]; | |
109 | pad = w[2:0]; | |
110 | // {pkt_type,ip_ver,v4_hdr_cs,l4_proto_op,tcp_udp_crc_32c,rsvd_56_52,l3_start,rsvd_47_46,l4_start,rsvd_39_38,l4_stuff,rsvd_31_0} = w; | |
111 | } | |
112 | ||
113 | //get frame type from pktconfig | |
114 | ||
115 | function bit[4:0] get_frame_type(TxPacketGenConfig PktGenConfig) { | |
116 | ||
117 | bit [4:0] ftype; | |
118 | ||
119 | ftype = PktGenConfig.flow.frame.frame_type; | |
120 | printf("VAL_OF_FRM_TYPE %0h\n",ftype); | |
121 | ||
122 | get_frame_type = ftype; | |
123 | ||
124 | } | |
125 | ||
126 | // get frame class from pktconfig | |
127 | ||
128 | function integer get_frame_class(TxPacketGenConfig PktGenConfig) { | |
129 | ||
130 | integer fclass; | |
131 | ||
132 | fclass = PktGenConfig.flow.frame.frame_class; | |
133 | printf("VAL_OF_FRM_CLASS %0d\n",fclass); | |
134 | ||
135 | get_frame_class = fclass; | |
136 | ||
137 | } | |
138 | ||
139 | // get ip_hdr_len | |
140 | ||
141 | function integer get_ip_hdr_len(TxPacketGenConfig PktGenConfig) { | |
142 | ||
143 | integer fip_hdr_len; | |
144 | fip_hdr_len = PktGenConfig.flow.frame.header_length; | |
145 | ||
146 | get_ip_hdr_len = fip_hdr_len; | |
147 | ||
148 | } | |
149 | ||
150 | // get pkt_length from the pktconfig | |
151 | ||
152 | function bit [13:0] get_pkt_len(TxPacketGenConfig PktGenConfig) { | |
153 | ||
154 | bit [13:0] pkt_len; | |
155 | ||
156 | pkt_len = (PktGenConfig.data_length + PktGenConfig.pad*2) - 4; | |
157 | ||
158 | get_pkt_len = pkt_len; | |
159 | ||
160 | } | |
161 | ||
162 | // get vlan from pkt_config | |
163 | ||
164 | function bit get_vlan(TxPacketGenConfig PktGenConfig) { | |
165 | ||
166 | bit vlan; | |
167 | ||
168 | vlan = PktGenConfig.flow.frame.frame_type[2]; | |
169 | ||
170 | get_vlan = vlan; | |
171 | ||
172 | } | |
173 | ||
174 | // get llc from pkt_config | |
175 | ||
176 | function bit get_llc(TxPacketGenConfig PktGenConfig) { | |
177 | ||
178 | bit llc; | |
179 | ||
180 | llc = PktGenConfig.flow.frame.frame_type[0]; | |
181 | ||
182 | get_llc = llc; | |
183 | ||
184 | } | |
185 | ||
186 | // get l3_start from pkt config | |
187 | ||
188 | function bit [3:0] get_l3start(TxPacketGenConfig PktGenConfig) { | |
189 | ||
190 | bit [3:0] l3_start; | |
191 | bit llc; | |
192 | bit vlan; | |
193 | ||
194 | vlan = get_vlan(PktGenConfig); | |
195 | llc = get_llc(PktGenConfig); | |
196 | ||
197 | case({llc,vlan}) { | |
198 | 2'b00 : l3_start = 4'h7; | |
199 | 2'b01 : l3_start = 4'h9; | |
200 | 2'b10 : l3_start = 4'hb; | |
201 | 2'b11 : l3_start = 4'hd; | |
202 | } | |
203 | ||
204 | get_l3start = l3_start; | |
205 | ||
206 | } | |
207 | ||
208 | // get l4_start base | |
209 | ||
210 | function bit [5:0] get_l4start_base(TxPacketGenConfig PktGenConfig) { | |
211 | ||
212 | bit [5:0] l4start_base; | |
213 | bit llc; | |
214 | bit vlan; | |
215 | bit ipver; | |
216 | ||
217 | vlan = get_vlan(PktGenConfig); | |
218 | llc = get_llc(PktGenConfig); | |
219 | ipver = get_ip_ver(PktGenConfig); | |
220 | ||
221 | if(ipver == 1'b0) { | |
222 | case({llc,vlan}) { | |
223 | 2'b00 : l4start_base = 6'h11; | |
224 | 2'b01 : l4start_base = 6'h13; | |
225 | 2'b10 : l4start_base = 6'h15; | |
226 | 2'b11 : l4start_base = 6'h17; | |
227 | } | |
228 | } else { | |
229 | case({llc,vlan}) { | |
230 | 2'b00 : l4start_base = 6'h1b; | |
231 | 2'b01 : l4start_base = 6'h1d; | |
232 | 2'b10 : l4start_base = 6'h1f; | |
233 | 2'b11 : l4start_base = 6'h21; | |
234 | } | |
235 | } | |
236 | ||
237 | get_l4start_base = l4start_base; | |
238 | ||
239 | } | |
240 | ||
241 | // get l4_stuff base | |
242 | ||
243 | function bit [5:0] get_l4stuff_base(TxPacketGenConfig PktGenConfig) { | |
244 | ||
245 | bit [5:0] l4stuff_base; | |
246 | bit llc; | |
247 | bit vlan; | |
248 | integer fclass; | |
249 | bit ipver; | |
250 | ||
251 | vlan = get_vlan(PktGenConfig); | |
252 | llc = get_llc(PktGenConfig); | |
253 | fclass = get_frame_class(PktGenConfig); | |
254 | ipver = get_ip_ver(PktGenConfig); | |
255 | ||
256 | if(ipver == 1'b0) { | |
257 | if(fclass == CL_TCP) { | |
258 | case({llc,vlan}) { | |
259 | 2'b00 : l4stuff_base = 6'h19; | |
260 | 2'b01 : l4stuff_base = 6'h1b; | |
261 | 2'b10 : l4stuff_base = 6'h1d; | |
262 | 2'b11 : l4stuff_base = 6'h1f; | |
263 | } | |
264 | } else if(fclass == CL_UDP) { | |
265 | case({llc,vlan}) { | |
266 | 2'b00 : l4stuff_base = 6'h14; | |
267 | 2'b01 : l4stuff_base = 6'h16; | |
268 | 2'b10 : l4stuff_base = 6'h18; | |
269 | 2'b11 : l4stuff_base = 6'h1a; | |
270 | } | |
271 | } | |
272 | } else { | |
273 | if(fclass == CL_TCP_IP_V6) { | |
274 | case({llc,vlan}) { | |
275 | 2'b00 : l4stuff_base = 6'h23; | |
276 | 2'b01 : l4stuff_base = 6'h25; | |
277 | 2'b10 : l4stuff_base = 6'h27; | |
278 | 2'b11 : l4stuff_base = 6'h29; | |
279 | } | |
280 | } else if(fclass == CL_UDP_IP_V6) { | |
281 | case({llc,vlan}) { | |
282 | 2'b00 : l4stuff_base = 6'h1e; | |
283 | 2'b01 : l4stuff_base = 6'h20; | |
284 | 2'b10 : l4stuff_base = 6'h22; | |
285 | 2'b11 : l4stuff_base = 6'h24; | |
286 | } | |
287 | } | |
288 | } | |
289 | ||
290 | get_l4stuff_base = l4stuff_base; | |
291 | ||
292 | } | |
293 | ||
294 | function bit get_ip_ver(TxPacketGenConfig PktGenConfig) { | |
295 | ||
296 | bit ipver; | |
297 | ||
298 | if(PktGenConfig.flow.frame.frame_type[3] == 1'b1) | |
299 | ipver = 1'b1; | |
300 | else | |
301 | ipver = 1'b0; | |
302 | ||
303 | get_ip_ver = ipver; | |
304 | } | |
305 | ||
306 | ||
307 | ||
308 | ||
309 | // function bit [127:0] format_ctrl_word( bit [4:0] frame_type ,integer frame_class, bit [13:0] pkt_length, integer ip_hdr_len) | |
310 | function bit [127:0] format_ctrl_word(TxPacketGenConfig PktGenConfig) { | |
311 | ||
312 | bit [127:0] w; | |
313 | bit [5:0] l4_stuff; | |
314 | bit [5:0] l4stuff_base; | |
315 | bit [5:0] l4_start; | |
316 | bit [5:0] l4start_base; | |
317 | bit [3:0] l3_start; | |
318 | bit [3:0] ihl; | |
319 | bit vlan; | |
320 | bit llc; | |
321 | bit [4:0] frame_type; | |
322 | bit [13:0] pkt_length; | |
323 | integer ip_hdr_len; | |
324 | integer frame_class; | |
325 | bit ipver; | |
326 | ||
327 | // get the pkt params from the pkt_config; | |
328 | ||
329 | frame_type = get_frame_type(PktGenConfig); | |
330 | frame_class = get_frame_class(PktGenConfig); | |
331 | pkt_length = get_pkt_len(PktGenConfig); | |
332 | ip_hdr_len = get_ip_hdr_len(PktGenConfig); | |
333 | l4stuff_base = get_l4stuff_base(PktGenConfig); | |
334 | l4start_base = get_l4start_base(PktGenConfig); | |
335 | pad = PktGenConfig.pad; | |
336 | ipver = get_ip_ver(PktGenConfig); | |
337 | ||
338 | if((frame_type[2] == 1'b0) && ((frame_class == CL_ARP) || (frame_class == CL_RARP))) { | |
339 | w = {64'h0,2'b00,ipver,1'b0,30'h0,pkt_length,13'h0,pad}; | |
340 | } else if((frame_type[1] == 1'b1) && (frame_class == CL_IP)) { | |
341 | w = {64'h0,2'b00,ipver,1'b0,30'h0,pkt_length,13'h0,pad}; | |
342 | } else if((frame_type[3] == 1'b1) && (frame_class == CL_IP_V6)) { | |
343 | w = {64'h0,2'b00,ipver,1'b0,30'h0,pkt_length,13'h0,pad}; | |
344 | } else if((frame_type[1] == 1'b1) && (frame_class == CL_TCP)) { | |
345 | l4_start = l4start_base + (ip_hdr_len - 5)*2; | |
346 | l4_stuff = l4stuff_base + (ip_hdr_len - 5)*2; | |
347 | ihl = ip_hdr_len; | |
348 | vlan = get_vlan(PktGenConfig); | |
349 | llc = get_llc(PktGenConfig); | |
350 | l3_start = get_l3start(PktGenConfig); | |
351 | w = {64'h0,2'b01,ipver,1'b0,2'h0,llc,vlan,ihl,l3_start,2'h0,l4_start,2'h0,l4_stuff,2'h0,pkt_length,13'h0,pad}; | |
352 | } else if ((frame_type[3] == 1'b1) && (frame_class == CL_TCP_IP_V6)) { | |
353 | // w = {64'h0,2'b01,1'b1,1'b0,8'h0,4'h7,10'h0,6'h23,2'h0,pkt_length,16'h0}; | |
354 | l4_start = l4start_base; | |
355 | l4_stuff = l4stuff_base; | |
356 | ihl = ip_hdr_len; | |
357 | vlan = get_vlan(PktGenConfig); | |
358 | llc = get_llc(PktGenConfig); | |
359 | l3_start = get_l3start(PktGenConfig); | |
360 | w = {64'h0,2'b01,ipver,3'h0,llc,vlan,ihl,l3_start,2'h0,l4_start,2'h0,l4_stuff,2'h0,pkt_length,13'h0,pad}; | |
361 | } else if ((frame_type[1] == 1'b1) && (frame_class == CL_UDP)) { | |
362 | l4_start = l4start_base + (ip_hdr_len - 5)*2; | |
363 | l4_stuff = l4stuff_base + (ip_hdr_len - 5)*2; | |
364 | ihl = ip_hdr_len; | |
365 | vlan = get_vlan(PktGenConfig); | |
366 | llc = get_llc(PktGenConfig); | |
367 | l3_start = get_l3start(PktGenConfig); | |
368 | w = {64'h0,2'b10,1'b0,1'b0,2'h0,llc,vlan,ihl,l3_start,2'h0,l4_start,2'h0,l4_stuff,2'h0,pkt_length,13'h0,pad}; | |
369 | } else if ((frame_type[3] == 1'b1) && (frame_class == CL_UDP_IP_V6)) { | |
370 | // w = {64'h0,2'b10,1'b1,1'b0,8'h0,4'h7,10'h0,6'h1E,2'h0,pkt_length,13'h0,pad}; | |
371 | l4_start = l4start_base; | |
372 | l4_stuff = l4stuff_base; | |
373 | ihl = ip_hdr_len; | |
374 | vlan = get_vlan(PktGenConfig); | |
375 | llc = get_llc(PktGenConfig); | |
376 | l3_start = get_l3start(PktGenConfig); | |
377 | w = {64'h0,2'b10,ipver,3'h0,llc,vlan,ihl,l3_start,2'h0,l4_start,2'h0,l4_stuff,2'h0,pkt_length,13'h0,pad}; | |
378 | } | |
379 | ||
380 | format_ctrl_word = w; | |
381 | ||
382 | } | |
383 | ||
384 | } |