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

#ifndef _ECPRI_SWITCH_H_
#define _ECPRI_SWITCH_H_


/* -------------------------------------------------- <INC FILE> --------------------------------------------------- */
#include <stdbool.h>
#include "ucp_js_subcrg.h"
#include "ucp_ecpri.h"
#include "ucp_param.h"
#include "ucp_utility.h"
#include "phy_para.h"
#include "ecpri_comm.h"


/* -------------------------------------------------- <MACRO DEF> -------------------------------------------------- */
/* eCPRI MAC statistic consecutive register number 1 */
#define ECPRI_MAC_STATS_CONSEC_REG_NUM1         12
/* eCPRI MAC statistic consecutive register number 2 */
#define ECPRI_MAC_STATS_CONSEC_REG_NUM2         3
/* eCPRI MAC statistic consecutive register number 3 */
#define ECPRI_MAC_STATS_CONSEC_REG_NUM3         2

/* eCPRI SWITCH port number */
#define ECPRI_SWITCH_PORT_NUM                   3
/* eCPRI SWITCH port ID 0 */
#define ECPRI_SWITCH_PORT0                      0
/* eCPRI SWITCH port ID 1 */
#define ECPRI_SWITCH_PORT1                      1
/* eCPRI SWITCH port ID 2 */
#define ECPRI_SWITCH_PORT2                      2

/* eCPRI SWITCH statistic consecutive register number 1 */
#define ECPRI_SWITCH_STATS_CONSEC_REG_NUM1      3
/* eCPRI SWITCH statistic consecutive register number 2 */
#define ECPRI_SWITCH_STATS_CONSEC_REG_NUM2      12
/* eCPRI SWITCH statistic consecutive register number 3 */
#define ECPRI_SWITCH_STATS_CONSEC_REG_NUM3      4


/* -------------------------------------------------- <TYPE DEF> --------------------------------------------------- */
/* eCPRI MAC statistic structure */
typedef struct EcpriMacStats
{
    uint32_t rx_pkts_64b;                       /* receive 64Bytes packets */
    uint32_t rx_pkts_65b_127b;                  /* receive 65~127Bytes packets */
    uint32_t rx_pkts_128b_255b;                 /* receive 128~255Bytes packets */
    uint32_t rx_pkts_256b_511b;                 /* receive 256~511Bytes packets */
    uint32_t rx_pkts_512b_1023b;                /* receive 512~1023Bytes packets */
    uint32_t rx_pkts_1024b_1518b;               /* receive 1024~1518Bytes packets */
    uint32_t rx_pkts_1519b_max;                 /* receive 1519~maxBytes packets */
    uint32_t rx_pkts_under_64b;                 /* receive under 64Bytes packets */
    uint32_t rx_pkts_over_max;                  /* receive over maxBytes packets */
    uint32_t rx_pkts_total;                     /* receive total packets */
    uint32_t rx_bytes_total_lsb;                /* receive total bytes LSB */
    uint32_t rx_bytes_total_msb;                /* receive total bytes MSB */
    uint32_t rx_pkts_crc_err;                   /* receive CRC error packets */
    uint32_t rx_pkts_uc;                        /* receive unicast packets */
    uint32_t rx_pkts_mc;                        /* receive multicast packets */
    uint32_t rx_pkts_bc;                        /* receive broadcast packets */
    uint32_t rx_pkts_discard;                   /* receive discard packets */
    uint32_t rx_pkts_overflow;                  /* receive overflow packets */
    uint32_t tx_pkts_64b;                       /* send 64Bytes packets */
    uint32_t tx_pkts_65b_127b;                  /* send 65~127Bytes packets */
    uint32_t tx_pkts_128b_255b;                 /* send 128~255Bytes packets */
    uint32_t tx_pkts_256b_511b;                 /* send 256~511Bytes packets */
    uint32_t tx_pkts_512b_1023b;                /* send 512~1023Bytes packets */
    uint32_t tx_pkts_1024b_1518b;               /* send 1024~1518Bytes packets */
    uint32_t tx_pkts_1519b_max;                 /* send 1519~maxBytes packets */
    uint32_t tx_pkts_under_64b;                 /* send under 64Bytes packets */
    uint32_t tx_pkts_over_max;                  /* send over maxBytes packets */
    uint32_t tx_pkts_total;                     /* send total packets */
    uint32_t tx_bytes_total_lsb;                /* send total bytes LSB */
    uint32_t tx_bytes_total_msb;                /* send total bytes MSB */
} EcpriMacStats_t;

/* eCPRI SWITCH statistic structure */
typedef struct EcpriSwitchStats
{
    uint32_t rx_pkts_fltr;                      /* receive filtered packets */
    uint32_t rx_bytes_fltr;                     /* receive filtered bytes */
    uint32_t tx_pkts_drop;                      /* send filtered packets */
    uint32_t rx_pkts_voq_nq;                    /* receive enqueued packets */
    uint32_t tx_pkts_voq_dq;                    /* send dequeued packets */
    uint32_t rx_pkts_voq_drop;                  /* receive dropped packets */
    uint32_t rx_bytes_voq_nq;                   /* receive enqueued bytes */
    uint32_t tx_bytes_voq_dq;                   /* send dequeued bytes */
    uint32_t rx_bytes_voq_drop;                 /* receive dropped bytes */
    uint32_t rx_pkts_uc;                        /* receive unicast packets */
    uint32_t tx_pkts_uc;                        /* send unicast packets */
    uint32_t rx_bytes_uc;                       /* receive unicast bytes */
    uint32_t tx_bytes_uc;                       /* send unicast bytes */
    uint32_t rx_pkts_mc;                        /* receive multicast packets */
    uint32_t tx_pkts_mc;                        /* send multicast packets */
    uint32_t rx_bytes_mc;                       /* receive multicast bytes */
    uint32_t tx_bytes_mc;                       /* send multicast bytes */
    uint32_t rx_pkts_bc;                        /* receive broadcast packets */
    uint32_t tx_pkts_bc;                        /* send broadcast packets */
    uint32_t rx_bytes_bc;                       /* receive broadcast bytes */
    uint32_t tx_bytes_bc;                       /* send broadcast bytes */
    uint32_t rx_pkts_buf_ovfl;                  /* receive buffer-overflow dropped packets */
    uint32_t rx_bytes_buf_ovfl;                 /* receive buffer-overflow dropped bytes */
    uint32_t rx_pkts_err;                       /* receive error dropped packets */
    uint32_t rx_bytes_err;                      /* receive error dropped bytes */
} EcpriSwitchStats_t;


/* --------------------------------------------------- <DECLARE> --------------------------------------------------- */
/* eCPRI PCS reset */
void ecpri_pcs_rst(void);
/* eCPRI PCS init */
void ecpri_pcs_init(uint32_t ecpri_option);
/* eCPRI PCS config */
void ecpri_pcs_cfg(bool lb_en);
/* eCPRI MAC init */
void ecpri_mac_init(void);
/* eCPRI MAC config */
void ecpri_mac_cfg(bool discard_en);
/* eCPRI SWITCH init */
void ecpri_switch_init(void);
/* eCPRI PCS link status get */
bool ecpri_pcs_link_status_get(void);
/* eCPRI MAC statistic start */
void ecpri_mac_stats_start(void);
/* eCPRI MAC statistic stop */
void ecpri_mac_stats_stop(void);
/* eCPRI MAC statistic clear */
void ecpri_mac_stats_clear(void);
/* eCPRI MAC statistic get */
int32_t ecpri_mac_stats_get(EcpriMacStats_t *ecpri_mac_stats_ptr);
/* eCPRI SWITCH statistic get */
int32_t ecpri_switch_stats_get(uint8_t port, EcpriSwitchStats_t *ecpri_switch_stats_ptr);


#endif /* _ECPRI_SWITCH_H_ */

