// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: niu_txcntrl_wd.vr
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
#include "pcg_defines.vri"
#include "niu_tx_pktconfig.vrh"
class TxPacketControlWord {
// Ethernet Transmit Packet Header
// 128 bits control header for alignment
task new(integer i = 0) {
function bit[127:0] get_header() {
get_header = {rsvd_127_64,
task set_control_word ( bit [127:0] w) {
// {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;
//get frame type from pktconfig
function bit[4:0] get_frame_type(TxPacketGenConfig PktGenConfig) {
ftype = PktGenConfig.flow.frame.frame_type;
printf("VAL_OF_FRM_TYPE %0h\n",ftype);
// get frame class from pktconfig
function integer get_frame_class(TxPacketGenConfig PktGenConfig) {
fclass = PktGenConfig.flow.frame.frame_class;
printf("VAL_OF_FRM_CLASS %0d\n",fclass);
get_frame_class = fclass;
function integer get_ip_hdr_len(TxPacketGenConfig PktGenConfig) {
fip_hdr_len = PktGenConfig.flow.frame.header_length;
get_ip_hdr_len = fip_hdr_len;
// get pkt_length from the pktconfig
function bit [13:0] get_pkt_len(TxPacketGenConfig PktGenConfig) {
pkt_len = (PktGenConfig.data_length + PktGenConfig.pad*2) - 4;
// get vlan from pkt_config
function bit get_vlan(TxPacketGenConfig PktGenConfig) {
vlan = PktGenConfig.flow.frame.frame_type[2];
// get llc from pkt_config
function bit get_llc(TxPacketGenConfig PktGenConfig) {
llc = PktGenConfig.flow.frame.frame_type[0];
// get l3_start from pkt config
function bit [3:0] get_l3start(TxPacketGenConfig PktGenConfig) {
vlan = get_vlan(PktGenConfig);
llc = get_llc(PktGenConfig);
function bit [5:0] get_l4start_base(TxPacketGenConfig PktGenConfig) {
vlan = get_vlan(PktGenConfig);
llc = get_llc(PktGenConfig);
ipver = get_ip_ver(PktGenConfig);
2'b00 : l4start_base = 6'h11;
2'b01 : l4start_base = 6'h13;
2'b10 : l4start_base = 6'h15;
2'b11 : l4start_base = 6'h17;
2'b00 : l4start_base = 6'h1b;
2'b01 : l4start_base = 6'h1d;
2'b10 : l4start_base = 6'h1f;
2'b11 : l4start_base = 6'h21;
get_l4start_base = l4start_base;
function bit [5:0] get_l4stuff_base(TxPacketGenConfig PktGenConfig) {
vlan = get_vlan(PktGenConfig);
llc = get_llc(PktGenConfig);
fclass = get_frame_class(PktGenConfig);
ipver = get_ip_ver(PktGenConfig);
2'b00 : l4stuff_base = 6'h19;
2'b01 : l4stuff_base = 6'h1b;
2'b10 : l4stuff_base = 6'h1d;
2'b11 : l4stuff_base = 6'h1f;
} else if(fclass == CL_UDP) {
2'b00 : l4stuff_base = 6'h14;
2'b01 : l4stuff_base = 6'h16;
2'b10 : l4stuff_base = 6'h18;
2'b11 : l4stuff_base = 6'h1a;
if(fclass == CL_TCP_IP_V6) {
2'b00 : l4stuff_base = 6'h23;
2'b01 : l4stuff_base = 6'h25;
2'b10 : l4stuff_base = 6'h27;
2'b11 : l4stuff_base = 6'h29;
} else if(fclass == CL_UDP_IP_V6) {
2'b00 : l4stuff_base = 6'h1e;
2'b01 : l4stuff_base = 6'h20;
2'b10 : l4stuff_base = 6'h22;
2'b11 : l4stuff_base = 6'h24;
get_l4stuff_base = l4stuff_base;
function bit get_ip_ver(TxPacketGenConfig PktGenConfig) {
if(PktGenConfig.flow.frame.frame_type[3] == 1'b1)
// function bit [127:0] format_ctrl_word( bit [4:0] frame_type ,integer frame_class, bit [13:0] pkt_length, integer ip_hdr_len)
function bit [127:0] format_ctrl_word(TxPacketGenConfig PktGenConfig) {
// get the pkt params from the pkt_config;
frame_type = get_frame_type(PktGenConfig);
frame_class = get_frame_class(PktGenConfig);
pkt_length = get_pkt_len(PktGenConfig);
ip_hdr_len = get_ip_hdr_len(PktGenConfig);
l4stuff_base = get_l4stuff_base(PktGenConfig);
l4start_base = get_l4start_base(PktGenConfig);
ipver = get_ip_ver(PktGenConfig);
if((frame_type[2] == 1'b0) && ((frame_class == CL_ARP) || (frame_class == CL_RARP))) {
w = {64'h0,2'b00,ipver,1'b0,30'h0,pkt_length,13'h0,pad};
} else if((frame_type[1] == 1'b1) && (frame_class == CL_IP)) {
w = {64'h0,2'b00,ipver,1'b0,30'h0,pkt_length,13'h0,pad};
} else if((frame_type[3] == 1'b1) && (frame_class == CL_IP_V6)) {
w = {64'h0,2'b00,ipver,1'b0,30'h0,pkt_length,13'h0,pad};
} else if((frame_type[1] == 1'b1) && (frame_class == CL_TCP)) {
l4_start = l4start_base + (ip_hdr_len - 5)*2;
l4_stuff = l4stuff_base + (ip_hdr_len - 5)*2;
vlan = get_vlan(PktGenConfig);
llc = get_llc(PktGenConfig);
l3_start = get_l3start(PktGenConfig);
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};
} else if ((frame_type[3] == 1'b1) && (frame_class == CL_TCP_IP_V6)) {
// w = {64'h0,2'b01,1'b1,1'b0,8'h0,4'h7,10'h0,6'h23,2'h0,pkt_length,16'h0};
vlan = get_vlan(PktGenConfig);
llc = get_llc(PktGenConfig);
l3_start = get_l3start(PktGenConfig);
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};
} else if ((frame_type[1] == 1'b1) && (frame_class == CL_UDP)) {
l4_start = l4start_base + (ip_hdr_len - 5)*2;
l4_stuff = l4stuff_base + (ip_hdr_len - 5)*2;
vlan = get_vlan(PktGenConfig);
llc = get_llc(PktGenConfig);
l3_start = get_l3start(PktGenConfig);
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};
} else if ((frame_type[3] == 1'b1) && (frame_class == CL_UDP_IP_V6)) {
// w = {64'h0,2'b10,1'b1,1'b0,8'h0,4'h7,10'h0,6'h1E,2'h0,pkt_length,13'h0,pad};
vlan = get_vlan(PktGenConfig);
llc = get_llc(PktGenConfig);
l3_start = get_l3start(PktGenConfig);
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};