/******************************************************************************

  Copyright (C), 2012, Texas Instrument.

 ******************************************************************************
  File Name     : KeyStone_Packet_Descriptor.h
  Version       : Initial Draft
  Author        : Brighton Feng
  Created       : June 11, 2012
  Description   : Packet descriptor structure definition
******************************************************************************/

#ifndef _PACKET_DESCRIPTOR_H_
#define _PACKET_DESCRIPTOR_H_

typedef enum
{
    /** Host descriptor */
    Cppi_DescType_HOST = 0,
    /** Monolithic descriptor */
    Cppi_DescType_MONOLITHIC = 2
}Cppi_DescType;

/*******************************************************************/
/* Define the bit and word layouts for the Host Packet Descriptor. */
/* For a Host Packet, this is used for the first descriptor only.  */
/*******************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  volatile Uint32 type_id         : 2;  //always 0x0 (Host Packet ID)
  volatile Uint32 packet_type     : 5;
  volatile Uint32 reserved_w0     : 2;
  volatile Uint32 ps_reg_loc      : 1;  //0=PS words in desc, 1=PS words in SOP buff
  volatile Uint32 packet_length   : 22; //in bytes (4M - 1 max)

  /* word 1 */
  volatile Uint32 src_tag_hi      : 8;
  volatile Uint32 src_tag_lo      : 8;
  volatile Uint32 dest_tag_hi     : 8;
  volatile Uint32 dest_tag_lo     : 8;

  /* word 2 */
  volatile Uint32 epib            : 1;  //1=extended packet info block is present
  volatile Uint32 reserved_w2     : 1;
  volatile Uint32 psv_word_count  : 6;  //number of 32-bit PS data words
  volatile Uint32 err_flags       : 4;
  volatile Uint32 ps_flags        : 4;
  volatile Uint32 return_policy   : 1;  //0=linked packet goes to pkt_return_qnum,
                                  //1=each descriptor goes to pkt_return_qnum
  volatile Uint32 ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  volatile Uint32 pkt_return_qmgr : 2;
  volatile Uint32 pkt_return_qnum : 12;
   
  /* word 3 */
  volatile Uint32 reserved_w3     : 10;
  volatile Uint32 buffer_len      : 22;
   
  /* word 4 */
  volatile Uint32 buffer_ptr;
   
  /* word 5 */
  volatile Uint32 next_desc_ptr;
   
  /* word 6 */
  volatile Uint32 orig_buff0_pool : 4;
  volatile Uint32 orig_buff0_refc : 6;
  volatile Uint32 orig_buff0_len  : 22;
   
  /* word 7 */
  volatile Uint32 orig_buff0_ptr;

} HostPacketDescriptor;
#else
typedef struct
{
  /* word 0 */
  volatile Uint32 packet_length   : 22; //in bytes (4M - 1 max)
  volatile Uint32 ps_reg_loc      : 1;  //0=PS words in desc, 1=PS words in SOP buff
  volatile Uint32 reserved_w0     : 2;
  volatile Uint32 packet_type     : 5;
  volatile Uint32 type_id         : 2;  //always 0x0 (Host Packet ID)
   
  /* word 1 */
  volatile Uint32 dest_tag_lo     : 8;
  volatile Uint32 dest_tag_hi     : 8;
  volatile Uint32 src_tag_lo      : 8;
  volatile Uint32 src_tag_hi      : 8;
   
  /* word 2 */
  volatile Uint32 pkt_return_qnum : 12;
  volatile Uint32 pkt_return_qmgr : 2;
  volatile Uint32 ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  volatile Uint32 return_policy   : 1;  //0=linked packet goes to pkt_return_qnum,
                                  //1=each descriptor goes to pkt_return_qnum
  volatile Uint32 ps_flags        : 4;
  volatile Uint32 err_flags       : 4;
  volatile Uint32 psv_word_count  : 6;  //number of 32-bit PS data words
  volatile Uint32 reserved_w2     : 1;
  volatile Uint32 epib            : 1;  //1=extended packet info block is present
   
  /* word 3 */
  volatile Uint32 buffer_len      : 22;
  volatile Uint32 reserved_w3     : 10;
   
  /* word 4 */
  volatile Uint32 buffer_ptr;
   
  /* word 5 */
  volatile Uint32 next_desc_ptr;
   
  /* word 6 */
  volatile Uint32 orig_buff0_len  : 22;
  volatile Uint32 orig_buff0_refc : 6;
  volatile Uint32 orig_buff0_pool : 4;
   
  /* word 7 */
  volatile Uint32 orig_buff0_ptr;

} HostPacketDescriptor;
#endif

/*********************************************************************/
/* Define the bit and word layouts for the Monolithic Pkt Descriptor.*/
/*********************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  volatile Uint32  type_id         : 2;  //always 0x2 (Monolithic Packet ID)
  volatile Uint32  packet_type     : 5;
  volatile Uint32  data_offset     : 9;
  volatile Uint32  packet_length   : 16; //in bytes (65535 max)
   
  /* word 1 */
  volatile Uint32  src_tag_hi      : 8;
  volatile Uint32  src_tag_lo      : 8;
  volatile Uint32  dest_tag_hi     : 8;
  volatile Uint32  dest_tag_lo     : 8;
   
  /* word 2 */
  volatile Uint32  epib            : 1;  //1=extended packet info block is present
  volatile Uint32  reserved_w2     : 1;
  volatile Uint32  psv_word_count  : 6;  //number of 32-bit PS data words
  volatile Uint32  err_flags       : 4;
  volatile Uint32  ps_flags        : 4;
  volatile Uint32  reserved_w2b    : 1;
  volatile Uint32  ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  volatile Uint32  pkt_return_qmgr : 2;
  volatile Uint32  pkt_return_qnum : 12;

} MonolithicPacketDescriptor;
#else
typedef struct
{
  /* word 0 */
  volatile Uint32  packet_length   : 16; //in bytes (65535 max)
  volatile Uint32  data_offset     : 9;
  volatile Uint32  packet_type     : 5;
  volatile Uint32  type_id         : 2;  //always 0x2 (Monolithic Packet ID)
   
  /* word 1 */
  volatile Uint32  dest_tag_lo     : 8;
  volatile Uint32  dest_tag_hi     : 8;
  volatile Uint32  src_tag_lo      : 8;
  volatile Uint32  src_tag_hi      : 8;
   
  /* word 2 */
  volatile Uint32  pkt_return_qnum : 12;
  volatile Uint32  pkt_return_qmgr : 2;
  volatile Uint32  ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  volatile Uint32  reserved_w2b    : 1;
  volatile Uint32  ps_flags        : 4;
  volatile Uint32  err_flags       : 4;
  volatile Uint32  psv_word_count  : 6;  //number of 32-bit PS data words
  volatile Uint32  reserved_w2     : 1;
  volatile Uint32  epib            : 1;  //1=extended packet info block is present

} MonolithicPacketDescriptor;
#endif

/****************************************************************************/
/* Define the bit and word layouts for the SRIO Type 9 message TX descriptor*/
/****************************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  Uint32  SRC_ID    : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.
  Uint32  Dest_ID   : 16; //Destination Node ID the message was sent to.

  /* word 1 */
  Uint32  StreamID  : 16; 	//Stream ID for the transaction
  Uint32  reserved0 : 5;
  Uint32  TT        : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  Uint32  reserved1 : 1;
  Uint32  COS       : 8; 	//Class of Service

} SRIO_Type9_Message_TX_Descriptor;
#else
typedef struct
{
  /* word 0 */
  Uint32  Dest_ID   : 16; //Destination Node ID the message was sent to.
  Uint32  SRC_ID    : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.

  /* word 1 */
  Uint32  COS       : 8; 	//Class of Service
  Uint32  reserved1 : 1;
  Uint32  TT        : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  Uint32  reserved0 : 5;
  Uint32  StreamID  : 16; 	//Stream ID for the transaction

} SRIO_Type9_Message_TX_Descriptor;
#endif

/****************************************************************************/
/* Define the bit and word layouts for the SRIO Type 9 message RX descriptor*/
/****************************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  Uint32  SRC_ID    : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.
  Uint32  Dest_ID   : 16; //Destination Node ID the message was sent to.

  /* word 1 */
  Uint32  StreamID  : 16; 	//Stream ID for the transaction
  Uint32  reserved0 : 1;
  Uint32  PRI       : 4; 	//Message Priority (VC||PRIO||CRF)
  Uint32  T         : 1; 	//This is TT [0] bit only.
  Uint32  CC        : 2; 	//Completion Code
  Uint32  COS       : 8; 	//Class of Service

} SRIO_Type9_Message_RX_Descriptor;
#else
typedef struct
{
  /* word 0 */
  Uint32  Dest_ID   : 16; //Destination Node ID the message was sent to.
  Uint32  SRC_ID    : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.

  /* word 1 */
  Uint32  COS       : 8; 	//Class of Service
  Uint32  CC        : 2; 	//Completion Code
  Uint32  T         : 1; 	//This is TT [0] bit only.
  Uint32  PRI       : 4; 	//Message Priority (VC||PRIO||CRF)
  Uint32  reserved0 : 1;
  Uint32  StreamID  : 16; 	//Stream ID for the transaction

} SRIO_Type9_Message_RX_Descriptor;
#endif

/****************************************************************************/
/* Define the bit and word layouts for the SRIO Type 11 message RX descriptor*/
/****************************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  Uint32  SRC_ID    : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.
  Uint32  Dest_ID   : 16; //Destination Node ID the message was sent to.

  /* word 1 */
  Uint32  reserved0 : 15; 	
  Uint32  CC        : 2; 	//Completion Code
  Uint32  PRI       : 4; 	//Message Priority (VC||PRIO||CRF)
  Uint32  TT        : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  Uint32  LTR       : 3; 	//Destination Letter
  Uint32  MailBox   : 6; 	//Destination Mailbox

} SRIO_Type11_Message_RX_Descriptor;
#else
typedef struct
{
  /* word 0 */
  Uint32  Dest_ID   : 16; //Destination Node ID the message was sent to.
  Uint32  SRC_ID    : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.

  /* word 1 */
  Uint32  MailBox   : 6; 	//Destination Mailbox
  Uint32  LTR       : 3; 	//Destination Letter
  Uint32  TT        : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  Uint32  PRI       : 4; 	//Message Priority (VC||PRIO||CRF)
  Uint32  CC        : 2; 	//Completion Code
  Uint32  reserved0 : 15; 	

} SRIO_Type11_Message_RX_Descriptor;
#endif

/****************************************************************************/
/* Define the bit and word layouts for the SRIO Type 11 message TX descriptor*/
/****************************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  Uint32  SRC_ID      : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.
  Uint32  Dest_ID     : 16; //Destination Node ID the message was sent to.

  /* word 1 */
  Uint32  reserved0   : 5; 	
  Uint32  Retry_Count : 6; 	//Message Retry Count
  Uint32  SSIZE       : 4; 	//standard message payload size.
  Uint32  reserved1   : 6; 	
  Uint32  TT          : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  Uint32  LTR         : 3; 	//Destination Letter
  Uint32  MailBox     : 6; 	//Destination Mailbox

} SRIO_Type11_Message_TX_Descriptor;
#else
typedef struct
{
  /* word 0 */
  Uint32  Dest_ID   : 16; //Destination Node ID the message was sent to.
  Uint32  SRC_ID    : 16;  //Source Node Id ?a Unique Node identifier of the Source of the message.

  /* word 1 */
  Uint32  MailBox     : 6; 	//Destination Mailbox
  Uint32  LTR         : 3; 	//Destination Letter
  Uint32  TT          : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  Uint32  reserved1   : 6; 	
  Uint32  SSIZE       : 4; 	//standard message payload size.
  Uint32  Retry_Count : 6; 	//Message Retry Count
  Uint32  reserved0   : 5; 	

} SRIO_Type11_Message_TX_Descriptor;
#endif

/****************************************************************************/
/* Define the bit layouts for the AIF protocol specific descriptor*/
/****************************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  Uint32  reserved0   : 16; 	
  Uint32  egress      : 1; /*0: Ingress; 1: Egress*/
  Uint32  symNum      : 8; /*Symbol number*/
  Uint32  axcNum      : 7; /*AxC number (channel number)*/
} AIF_Protocol_Descriptor;
#else
typedef struct
{
  /* word 0 */
  Uint32  axcNum      : 7; /*AxC number (channel number)*/
  Uint32  symNum      : 8; /*Symbol number*/
  Uint32  egress      : 1; /*0: Ingress; 1: Egress*/
  Uint32  reserved0   : 16; 	
} AIF_Protocol_Descriptor;
#endif


#endif 
