#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 */
  unsigned int type_id         : 2;  //always 0x0 (Host Packet ID)
  unsigned int packet_type     : 5;
  unsigned int reserved_w0     : 2;
  unsigned int ps_reg_loc      : 1;  //0=PS words in desc, 1=PS words in SOP buff
  unsigned int packet_length   : 22; //in bytes (4M - 1 max)

  /* word 1 */
  unsigned int src_tag_hi      : 8;
  unsigned int src_tag_lo      : 8;
  unsigned int dest_tag_hi     : 8;
  unsigned int dest_tag_lo     : 8;

  /* word 2 */
  unsigned int epib            : 1;  //1=extended packet info block is present
  unsigned int reserved_w2     : 1;
  unsigned int psv_word_count  : 6;  //number of 32-bit PS data words
  unsigned int err_flags       : 4;
  unsigned int ps_flags        : 4;
  unsigned int return_policy   : 1;  //0=linked packet goes to pkt_return_qnum,
                                 //1=each descriptor goes to pkt_return_qnum
  unsigned int ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  unsigned int pkt_return_qmgr : 2;
  unsigned int pkt_return_qnum : 12;

  /* word 3 */
  unsigned int reserved_w3     : 10;
  unsigned int buffer_len      : 22;

  /* word 4 */
  unsigned int buffer_ptr;

  /* word 5 */
  unsigned int next_desc_ptr;

  /* word 6 */
  unsigned int orig_buff0_pool : 4;
  unsigned int orig_buff0_refc : 6;
  unsigned int orig_buff0_len  : 22;

  /* word 7 */
  unsigned int orig_buff0_ptr;

} HostPacketDescriptor;
#else
typedef struct
{
  /* word 0 */
  unsigned int packet_length   : 22; //in bytes (4M - 1 max)
  unsigned int ps_reg_loc      : 1;  //0=PS words in desc, 1=PS words in SOP buff
  unsigned int reserved_w0     : 2;
  unsigned int packet_type     : 5;
  unsigned int type_id         : 2;  //always 0x0 (Host Packet ID)

  /* word 1 */
  unsigned int dest_tag_lo     : 8;
  unsigned int dest_tag_hi     : 8;
  unsigned int src_tag_lo      : 8;
  unsigned int src_tag_hi      : 8;

  /* word 2 */
  unsigned int pkt_return_qnum : 12;
  unsigned int pkt_return_qmgr : 2;
  unsigned int ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  unsigned int return_policy   : 1;  //0=linked packet goes to pkt_return_qnum,
                                 //1=each descriptor goes to pkt_return_qnum
  unsigned int ps_flags        : 4;
  unsigned int err_flags       : 4;
  unsigned int psv_word_count  : 6;  //number of 32-bit PS data words
  unsigned int reserved_w2     : 1;
  unsigned int epib            : 1;  //1=extended packet info block is present


  /* word 3 */
  unsigned int buffer_len      : 22;
  unsigned int reserved_w3     : 10;

  /* word 4 */
  unsigned int buffer_ptr;

  /* word 5 */
  unsigned int next_desc_ptr;

  /* word 6 */
  unsigned int orig_buff0_len  : 22;
  unsigned int orig_buff0_refc : 6;
  unsigned int orig_buff0_pool : 4;

  /* word 7 */
  unsigned int orig_buff0_ptr;

} HostPacketDescriptor;
#endif

/*********************************************************************/
/* Define the bit and word layouts for the Monolithic Pkt Descriptor.*/
/*********************************************************************/
#ifdef _BIG_ENDIAN
typedef struct
{
  /* word 0 */
  unsigned int  type_id         : 2;  //always 0x2 (Monolithic Packet ID)
  unsigned int  packet_type     : 5;
  unsigned int  data_offset     : 9;
  unsigned int  packet_length   : 16; //in bytes (65535 max)

  /* word 1 */
  unsigned int  src_tag_hi      : 8;
  unsigned int  src_tag_lo      : 8;
  unsigned int  dest_tag_hi     : 8;
  unsigned int  dest_tag_lo     : 8;

  /* word 2 */
  unsigned int  epib            : 1;  //1=extended packet info block is present
  unsigned int  reserved_w2     : 1;
  unsigned int  psv_word_count  : 6;  //number of 32-bit PS data words
  unsigned int  err_flags       : 4;
  unsigned int  ps_flags        : 4;
  unsigned int  reserved_w2b    : 1;
  unsigned int  ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  unsigned int  pkt_return_qmgr : 2;
  unsigned int  pkt_return_qnum : 12;

} MonolithicPacketDescriptor;
#else
typedef struct
{
  /* word 0 */
  unsigned int  packet_length   : 16; //in bytes (65535 max)
  unsigned int  data_offset     : 9;
  unsigned int  packet_type     : 5;
  unsigned int  type_id         : 2;  //always 0x2 (Monolithic Packet ID)

  /* word 1 */
  unsigned int  dest_tag_lo     : 8;
  unsigned int  dest_tag_hi     : 8;
  unsigned int  src_tag_lo      : 8;
  unsigned int  src_tag_hi      : 8;

  /* word 2 */
  unsigned int  pkt_return_qnum : 12;
  unsigned int  pkt_return_qmgr : 2;
  unsigned int  ret_push_policy : 1;  //0=return to queue tail, 1=queue head
  unsigned int  reserved_w2b    : 1;
  unsigned int  ps_flags        : 4;
  unsigned int  err_flags       : 4;
  unsigned int  psv_word_count  : 6;  //number of 32-bit PS data words
  unsigned int  reserved_w2     : 1;
  unsigned int  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 */
  unsigned int  SRC_ID    : 16;  //Source Node Id ¡ª Unique Node identifier of the Source of the message.
  unsigned int  Dest_ID   : 16; //Destination Node ID the message was sent to.

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

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

  /* word 1 */
  unsigned int  COS       : 8; 	//Class of Service
  unsigned int  reserved1 : 1;
  unsigned int  TT        : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  unsigned int  reserved0 : 5;
  unsigned int  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 */
  unsigned int  SRC_ID    : 16;  //Source Node Id ¡ª Unique Node identifier of the Source of the message.
  unsigned int  Dest_ID   : 16; //Destination Node ID the message was sent to.

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

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

  /* word 1 */
  unsigned int  COS       : 8; 	//Class of Service
  unsigned int  CC        : 2; 	//Completion Code
  unsigned int  T         : 1; 	//This is TT [0] bit only.
  unsigned int  PRI       : 4; 	//Message Priority (VC||PRIO||CRF)
  unsigned int  reserved0 : 1;
  unsigned int  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 */
  unsigned int  SRC_ID    : 16;  //Source Node Id ¡ª Unique Node identifier of the Source of the message.
  unsigned int  Dest_ID   : 16; //Destination Node ID the message was sent to.

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

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

  /* word 1 */
  unsigned int  MailBox   : 6; 	//Destination Mailbox
  unsigned int  LTR       : 3; 	//Destination Letter
  unsigned int  TT        : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  unsigned int  PRI       : 4; 	//Message Priority (VC||PRIO||CRF)
  unsigned int  CC        : 2; 	//Completion Code
  unsigned int  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 */
  unsigned int  SRC_ID      : 16;  //Source Node Id ¡ª Unique Node identifier of the Source of the message.
  unsigned int  Dest_ID     : 16; //Destination Node ID the message was sent to.

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

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

  /* word 1 */
  unsigned int  MailBox     : 6; 	//Destination Mailbox
  unsigned int  LTR         : 3; 	//Destination Letter
  unsigned int  TT          : 2; 	//RapidIO tt field specifying 8 or 16bit DeviceIDs
  unsigned int  reserved1   : 6; 	
  unsigned int  SSIZE       : 4; 	//standard message payload size.
  unsigned int  Retry_Count : 6; 	//Message Retry Count
  unsigned int  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 */
  unsigned int  reserved0   : 16; 	
  unsigned int  egress      : 1; /*0: Ingress; 1: Egress*/
  unsigned int  symNum      : 8; /*Symbol number*/
  unsigned int  axcNum      : 7; /*AxC number (channel number)*/
} AIF_Protocol_Descriptor;
#else
typedef struct
{
  /* word 0 */
  unsigned int  axcNum      : 7; /*AxC number (channel number)*/
  unsigned int  symNum      : 8; /*Symbol number*/
  unsigned int  egress      : 1; /*0: Ingress; 1: Egress*/
  unsigned int  reserved0   : 16; 	
} AIF_Protocol_Descriptor;
#endif


#endif 
