/**********************************************************************************************************************
*  Copyright (C), 2022-2026, SMARTLOGIC TECHNOLOGY LTD.
*  File Name: ecpri_que.h
*  Create Date: 23/05/15
*  Description: eCPRI Queue Module Header File
*  Change History:
*      <author>      <time>      <version>   <desc>
*    1. ShangH      23/05/15        1.0       Build this module
**********************************************************************************************************************/

#ifndef _ECPRI_QUE_H_
#define _ECPRI_QUE_H_


/* -------------------------------------------------- <INC FILE> --------------------------------------------------- */
#include <stdbool.h>
#include "ucp_ecpri.h"
#include "ucp_param.h"
#include "ucp_utility.h"
#include "ucp_printf.h"
#include "app_interface.h"
#include "hwque.h"
#include "ecpri_comm.h"

#ifdef TEST_ENABLE
#include "ecpri_test.h"
#endif


/* -------------------------------------------------- <MACRO DEF> -------------------------------------------------- */
/* eCPRI VLAN tag offset & length & value */
#define ECPRI_VLAN_TAG_OFFSET                   12
#define ECPRI_VLAN_TAG_LEN                      4
#define ECPRI_VLAN_TAG_VAL                      0x8100

/* eCPRI packet type offset */
#define ECPRI_PKT_TYPE_OFFSET                   12

/* eCPRI packet payload length offset */
#define ECPRI_PKT_LEN_OFFSET                    16

/* eCPRI packet head(eth_head+com_head) length */
#define ECPRI_PKT_HEAD_LEN                      18

/* eCPRI descriptor packet length offset */
#define ECPRI_DESC_PKT_LEN_OFFSET               (ECPRI_PKT_SIZE - 0x1C)

/* eCPRI strip ethernet head enable */
//#define ECPRI_STRIP_ETH_HEAD_ENABLE


/* -------------------------------------------------- <TYPE DEF> --------------------------------------------------- */
/* eCPRI ethernet type enumeration */
typedef enum EcpriEtherType
{
    E_Ether_Type_PTP = 0x88F7,                  /* PTP(1588) */
    E_Ether_Type_ECPRI = 0xAEFE                 /* eCPRI */
} EcpriEtherType_e;

/* eCPRI message type enumeration */
typedef enum EcpriMsgType
{
    E_MSG_TYPE_APE = 0x55,                      /* APE message */
    E_MSG_TYPE_ARM = 0xaa                       /* ARM message */
} EcpriMsgType_e;

/* eCPRI core ID enumeration */
typedef enum EcpriCoreId
{
    E_CORE_ID_APE0 = 0,                         /* APE0 */
    E_CORE_ID_APE1,                             /* APE1 */
    E_CORE_ID_APE2,                             /* APE2 */
    E_CORE_ID_APE3,                             /* APE3 */
    E_CORE_ID_APE4,                             /* APE4 */
    E_CORE_ID_APE5,                             /* APE5 */
    E_CORE_ID_APE6,                             /* APE6 */
    E_CORE_ID_APE7,                             /* APE7 */
    E_CORE_ID_PET0,                             /* PET RFM SPU0 */
    E_CORE_ID_PET1,                             /* PET RFM SPU1 */
    E_CORE_ID_ECS0,                             /* ECS RFM SPU0 */
    E_CORE_ID_ECS1,                             /* PET RFM SPU1 */
    E_CORE_ID_ARM0                              /* ARM0 */
} EcpriCoreId_t;

/* eCPRI packet statistic structure */
typedef struct EcpriPktStats
{
    uint64_t total_pkts;                        /* total packets */
    uint64_t ecpri_pkts;                        /* eCPRI packets */
    uint64_t other_pkts;                        /* other packets */
} EcpriPktStats_t;

/* eCPRI ring buffer structure */
typedef struct EcpriRingBuf
{
    uint32_t wr_idx;                            /* write index */
    uint32_t rd_idx;                            /* read index */
    EcpriPktStats_t ecpri_pkt_stats;            /* eCPRI packet statistic */
} EcpriRingBuf_t;

/* eCPRI inform message structure */
typedef struct EcpriInformMsg
{
    uint32_t pkt_addr;                          /* packet address */
    uint32_t pkt_len;                           /* packet length */
} EcpriInformMsg_t;

/* eCPRI callback function type */
typedef void (* EcpriCallback)(uint32_t, uint16_t);


/* --------------------------------------------------- <DECLARE> --------------------------------------------------- */
/* eCPRI queue init */
int32_t ecpri_que_init(void);
/* eCPRI queue polling */
int32_t ecpri_que_polling(void);
/* eCPRI packet process */
void ecpri_pkt_proc(uint32_t pkt_addr);
/* eCPRI inform PL */
int32_t ecpri_inform_pl(uint32_t pkt_addr, uint16_t pkt_len);
/* eCPRI inform ARM */
int32_t ecpri_inform_arm(uint32_t pkt_addr);
/* eCPRI callback function register */
void ecpri_callback_register(EcpriCallback ecpri_callback);
/* eCPRI packet statistic get */
int32_t ecpri_pkt_stats_get(EcpriPktStats_t *ecpri_pkt_stats);


#endif /* _ECPRI_QUE_H_ */

