/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

#ifndef __TABLE_ACCESS_H__
#define __TABLE_ACCESS_H__

	/* ----------------------------------------------------------------------------------------------------------------------------------*/
	// Include dependent header files
	/* ----------------------------------------------------------------------------------------------------------------------------------*/
#include <api_oam_sdk/common/types/inc/mr_api_types.h>
#include <api_oam_sdk/performance_monitoring/src/dm.h>
#include <api_oam_sdk/table_access/inc/table_types.h>
#include "egl_types.h"
#include "egl_log.h"

#if EAGLE_INCLUDE_EFM
	#include "mrEfm.h"
#endif

// Function  definitions from mrTableAccess.c
#ifdef CPP
	extern "C" {
#endif

void tableAccessInit(void);

/*
 * @brief	Changes the logging level for this module
 *
 * @param[i]	logLevel - The lowest level severity to log
 *
 * This function is used to change the lowest level severity to log for
 * this module. Values of eLOG_LEVEL_DEBUG (lowest) to eLOG_LEVEL_ERROR
 * can be selected. Levels with greater severity than eLOG_LEVEL_ERROR
 * will default to eLOG_LEVEL_ERROR since severity of eLOG_LEVEL_ERROR
 * and higher are non maskable.
 */
void setTableAccessLogLevel(log_level_t logLevel);

int	readRawRMepDB(uint32_t addr,uint32_t *rdPtr);
int writeRawRMepDB(uint32_t addr,uint32_t wrData);
int readRawLMepTbl(uint32_t addr,uint32_t *rdPtr);
int writeRawLMepTbl(uint32_t addr,uint32_t wrData);
int readRawRMepTbl(uint32_t addr,uint32_t *rdPtr);
int writeRawRMepTbl(uint32_t addr,uint32_t wrData);
int readRawRxLMepNumRam(uint32_t addr,uint32_t *rdPtr);
int writeRawRxLMepNumRam(uint32_t addr,uint32_t wrData);
int readRawRxLMepNumRamLower(uint32_t addr,uint32_t *rdPtr,iFace_t iFace);
int writeRawRxLMepNumRamLower(uint32_t addr,uint32_t wrData,iFace_t iFace);
int readRawRxLMepNumRamUpper(uint32_t addr,uint32_t *rdPtr,iFace_t iFace);
int writeRawRxLMepNumRamUpper(uint32_t addr,uint32_t wrData,iFace_t iFace);

int readLMepTbl(uint32_t entryIdx,lMepTblEntry_t *lMepTblEntry);
int writeLMepTbl(uint32_t entryIdx,lMepTblEntry_t *lMepTblEntry);
int isFreeLMep(uint32_t entryIdx);
int clrLMepInUse(uint32_t entryIdx);
int setLMepInUse(uint32_t entryIdx);

int readRMepDB(uint32_t entryIdx, rMepDbTblEntry_t *rMepDbTblEntry);
int writeRMepDB(uint32_t entryIdx, rMepDbTblEntry_t *rMepDbTblEntry);
int isFreeRMepDB(uint32_t entryIdx);
int clrRMepDBInUse(uint32_t entryIdx);
int setRMepDBInUse(uint32_t entryIdx);

int readRMepTbl(uint32_t entryIdx, uint16_t *rMepID, rMepNum_t	*rMepNum);
int writeRMepTbl(uint32_t entryIdx, uint16_t rMepID, rMepNum_t	rMepNum);
int isFreeRMepTbl(uint32_t entryIdx);
int clrRMepTblInUse(uint32_t entryIdx);


int readRawVlanTbl(uint32_t entryIdx, uint32_t *rdData, iFace_t iFace);
int writeRawVlanTbl(uint32_t entryIdx, uint32_t wrData, iFace_t iFace);
int readVlanTbl(uint32_t entryIdx, vlanTblEntry_t *vlanTblEntry, iFace_t iFace);
int writeVlanTbl(uint32_t entryIdx, vlanTblEntry_t *vlanTblEntry, iFace_t iFace);
int readRawVlanPortTbl(uint32_t offset, uint32_t* rdData, iFace_t iFace);
int writeRawVlanPortTbl(uint32_t offset, uint32_t wrData, iFace_t iFace);
int writeValidInVlanPortTbl(uint32_t entryIdx, uint8_t valid, iFace_t iFace);
int writeClearVlanPortTbl(uint32_t entryIdx, iFace_t iFace);

int readDirLvl(uint32_t entryIdx, dirLvlTblEntry_t *dirLvlTblEntry);
int writeDirLvl(uint32_t entryIdx, dirLvlTblEntry_t *dirLvlTblEntry);
int readRawDirLvl(uint32_t entryOffset,uint32_t* rdData);
int writeRawDirLvl(uint32_t entryOffset, uint32_t wrData);
int clrDirLvlInUse(uint32_t entryIdx);
int isFreeDirLvl(uint32_t entryIdx);

int readTxTempl(uint32_t entryIdx, txTemplateEntry_t *txTemplateEntry, templateType_t templType,uint16_t *tlvLength,uint8_t tlv[]);
int writeTxTempl(uint32_t entryIdx, txTemplateEntry_t *txTemplateEntry, templateType_t templType,uint16_t tlvLength,uint8_t tlv[]);

int readSeqErr(uint32_t entryIdx,uint32_t *seqErr);
int writeSeqErr(uint32_t entryIdx,uint32_t seqErr);

int readRMepSMRam(uint32_t entryIdx,rMepSMEntry_t *rMepSMEntry);
int writeRMepSMRam(uint32_t entryIdx,rMepSMEntry_t *rMepSMEntry);

int readXConnSMRam(uint32_t entryIdx, xConnSMEntry_t *xConnSMEntry);
int writeXConnSMRam(uint32_t entryIdx, xConnSMEntry_t *xConnSMEntry);

int readRMepErrSMRam(uint32_t entryIdx, rMepErrSMEntry_t *rMepErrSMEntry);
int writeRMepErrSMRam(uint32_t entryIdx, rMepErrSMEntry_t *rMepErrSMEntry);

int	readPVidTable(mrPort_t port,pVidEntry_t *pVidEntry);
int	writePVidTable(mrPort_t port,pVidEntry_t *pVidEntry);

int readTxLMepNumRam(uint32_t txLMepNum,txLMepNumRamEntry_t *txLMepNumRamEntry);
int writeTxLMepNumRam(uint32_t txLMepNum,txLMepNumRamEntry_t *txLMepNumRamEntry);
int readPmNumRam(pmNum_t pmNum,pmNumRamEntry_t *pmNumRamEntry);
int writePmNumRam(pmNum_t pmNum,pmNumRamEntry_t *pmNumRamEntry);
int readRawPmTxLMepNumRam(uint32_t entryIdx,uint32_t *rdData);
int	writeRawPmTxLMepNumRam(uint32_t entryIdx,uint32_t wrData);
int isFreeTxPmNumTbl(uint32_t entryIdx);

int readRxLMepNumRam(uint32_t entryIdx,rxLMepNumRamEntry_t *rxLMepNumRamEntry,iFace_t iFace);
int writeRxLMepNumRam(uint32_t entryIdx,rxLMepNumRamEntry_t *rxLMepNumRamEntry,iFace_t iFace);
//int readRawRxLMepNumRam(uint32_t entryIdx,uint32_t* rdData);
//int writeRawRxLMepNumRam(uint32_t entryIdx,uint32_t wrData);
//int readRxLMepNumRamLower(uint32_t entryIdx, rxLMepRamLoEntry_t *rxLMepNumRamEntry);
//int writeRxLMepNumRamLower(uint32_t entryIdx, rxLMepRamLoEntry_t *rxLMepNumRamEntry);
int	isFreeRxLMepNumRam(uint32_t entryIdx,iFace_t iFace);
int clrRxLMepNumRamInUse(uint32_t entryIdx,iFace_t iFace);
int setRxLMepNumRamInUse(uint32_t entryIdx,iFace_t iFace);

int readMepIDInLMepTbl(uint32_t entryIdx,uint16_t *lMepID);
int readListIdxInLMepTbl(uint32_t entryIdx,uint16_t *listIndex);
int read1stDwdInLMepTbl(uint32_t entryIdx,uint16_t *lMepID, ccmInterval_t *interval, mdNum_t *mdNum,maNum_t *maNum);
int write1stDwdInLMepTbl(uint32_t entryIdx,uint16_t lMepID, ccmInterval_t interval,mdNum_t mdNum,maNum_t maNum);
int writeMaidInLMepTbl(uint32_t entryIdx,simpleMaid_t maid);

int readRMepIDInRMepDB(uint32_t entryIdx, uint16_t *remoteMepID);
int readRMepIdxInRMepDB(uint32_t entryIdx, uint16_t *rMepIdx);
int writeRMepIdxInRMepDB(uint32_t entryIdx, uint16_t rMepIdx);
int readSeqNumInRMepDB(uint32_t entryIdx, uint32_t *seqNum);
int readSAInRMepDB(uint32_t entryIdx, uint8_t SA[]);
int readTlvInRMepDB(uint32_t entryIdx, uint8_t tlv[]);

int	readProbeStore(uint8_t packetBuffer_t[220]);
int	readXConnStore(uint8_t packetBuffer_t[220]);
int	readRMepErrStore(uint8_t packetBuffer_t[220]);

int readDAInTxTempl(uint32_t entryIdx, uint8_t	DA[6], templateType_t templType);
int readSAInTxTempl(uint32_t entryIdx, uint8_t	SA[6], templateType_t templType);
int readTagsInTxTempl(uint32_t entryIdx,tag_t *outerTag,tag_t *innerTag,uint8_t eType[2], templateType_t templType);
int readProHdrInTxTempl(uint32_t entryIdx, uint8_t *proHdrLength, uint8_t	proHdr[16], templateType_t templType);
int readComCfmHdrInTxTempl(uint32_t entryIdx, uint8_t comCfmHdr[4], templateType_t templType);
int readSeqNumInTxTempl(uint32_t entryIdx, uint32_t	*seqNum, templateType_t templType);
int readMepIDInTxTempl(uint32_t entryIdx, uint16_t *mepID, templateType_t templType);
int readCfmTlvInTxTempl(uint32_t entryIdx, uint8_t	cfmTLV[], uint16_t *tlvLength, templateType_t templType);
int writeTlvInTxTempl(uint32_t entryIdx, uint16_t tlvLength, uint8_t tlv[], templateType_t templType);
int writeSeqNumInTxTempl(uint32_t entryIdx, uint32_t seqNum, templateType_t templType);
int writeRdiInTxTempl(uint32_t entryIdx, rdiVal_t rdi, templateType_t templType);
int writeCcmIntervalInTxTempl(uint32_t entryIdx, ccmInterval_t ccmInterval);
int writeDAInTxTempl(uint32_t entryIdx, macAddress_t macAddress, templateType_t templType);
int writeTagsInTxTempl(	uint32_t entryIdx,tagEntry_t *outerTag,tagEntry_t *innerTag,uint8_t eType[2],templateType_t templType);

int writePortMacRam(mrPort_t port,macAddress_t macEntry);
int readPortMacRam(mrPort_t port,macAddress_t macEntry);

int readMcLbrStore(uint32_t entryIdx,macAddress_t macAddr);
int writeMcLbrStore(uint32_t entryIdx,macAddress_t macAddr);

int readLBRPerSecFiFo(uint8_t chnl,uint8_t fifoPosn,uint32_t* txCnt, uint32_t* rxCnt);
int readLbmStore(uint32_t entryIdx,lbmStoreEntry_t *lbmStoreEntry, iFace_t iFace);
int writeLbmStore(uint32_t entryIdx,lbmStoreEntry_t *lbmStoreEntry, iFace_t iFace);

int readPmStatsRam(uint32_t entryIdx,pmStatsRamEntry_t *pmStatsRamEntry);
int writePmStatsRam(uint32_t entryIdx,pmStatsRamEntry_t *pmStatsRamEntry);
int readPmStatsRamRow(uint32_t entryIdx, uint8_t row, uint32_t *rowValue);
int writePmStatsRamRow(uint32_t entryIdx, uint8_t row, uint32_t rowValue);
int readLmmPmStatsRam(uint32_t entryIdx,pmStatsRamLmmEntry_t *pmStatsRamEntry);
int writeLmmPmStatsRam(uint32_t entryIdx,pmStatsRamLmmEntry_t *pmStatsRamEntry);
int readDmmDelayStats(uint32_t entryIdx, dmStatsEntry_t *dmStatsEntry);
int readDmmBinStats(uint32_t entryIdx,pmStatsRamDelayBinEntry_t *pmStatsRamDelayBinEntry);
int readDmmPmStatsRam(uint32_t entryIdx,pmStatsRamDmmEntry_t *pmStatsRamEntry);
int readDmmStatsLastValues(uint32_t entryIdx,uint32_t *lastJitter,uint32_t *lastDelay);
int writeDmmPmStatsRam(uint32_t entryIdx,pmStatsRamDmmEntry_t *pmStatsRamEntry);
/*
int readLastNeTx(uint8_t pmChnl, uint32_t *value);
int writeLastNeTx(uint8_t pmChnl, uint32_t value);
int readLastNeRx(uint8_t pmChnl, uint32_t *value);
int writeLastNeRx(uint8_t pmChnl, uint32_t value);
int readLastFeTx(uint8_t pmChnl, uint32_t *value);
int writeLastFeTx(uint8_t pmChnl, uint32_t value);
int readLastFeRx(uint8_t pmChnl, uint32_t *value);
int writeLastFeRx(uint8_t pmChnl, uint32_t value);
int readLastLmmNeRx(uint8_t pmChnl, uint32_t *value);
int writeLastLmmNeRx(uint8_t pmChnl, uint32_t value);
int readNeTxCntr(uint8_t pmChnl, uint32_t *value);
int writeNeTxCntr(uint8_t pmChnl, uint32_t value);
int readNeRxCntr(uint8_t pmChnl, uint32_t *value);
int writeNeRxCntr(uint8_t pmChnl, uint32_t value);
int readFeTxCntr(uint8_t pmChnl, uint32_t *value);
int writeFeTxCntr(uint8_t pmChnl, uint32_t value);
int readFeRxCntr(uint8_t pmChnl, uint32_t *value);
int writeFeRxCntr(uint8_t pmChnl, uint32_t value);
int readPmStatLMepNum(uint8_t pmChnl, uint16_t *value);
int writePmStatLMepNum(uint8_t pmChnl, uint16_t value);
int readPmStatRMepNum(uint8_t pmChnl, uint16_t *value);
int writePmStatRMepNum(uint8_t pmChnl, uint16_t value);

int writePmDbRam(uint32_t entryIdx,pmDbRamEntry_t *pmDbRamEntry);
int readPmDbRam(uint32_t entryIdx,pmDbRamEntry_t *pmDbRamEntry);
int readPmDbRamRow(uint32_t entryIdx,uint8_t row,uint32_t *rowValue);
int writePmDbRamRow(uint32_t entryIdx,uint8_t row,uint32_t rowValue);

int writeLmDbRam(uint32_t entryIdx,lmDbRamEntry_t *lmDbRamEntry);
int readLmDbRam(uint32_t entryIdx,lmDbRamEntry_t *lmDbRamEntry);

int writeDmDbRam(uint32_t entryIdx,dmDbRamEntry_t *dmDbRamEntry);
int readDmDbRam(uint32_t entryIdx,dmDbRamEntry_t *dmDbRamEntry);

int writeErrCntPmDbRam(uint32_t entryIdx,pmErrCntEntry_t *pmErrCntEntry);
int readErrCntPmDbRam(uint32_t entryIdx,pmErrCntEntry_t *pmErrCntEntry);
*/

int readLBRRam(uint32_t entryIdx,lbrRamEntry_t *lbrRamEntry);
int writeLBRRam(uint32_t entryIdx,lbrRamEntry_t *lbrRamEntry);
int readLBRLMepNum( uint8_t lbChnl,uint16_t *lMepNum,uint8_t *pcp);
int writeLBRLMepNum(uint8_t lbChnl,uint16_t lMepNum,uint8_t pcp);
int writeLBRSeqNum(uint8_t lbChnl,uint32_t seqNum);

int readTxLBRam(uint8_t lbChnl,uint32_t *txPktCount);

int writeLineStatsRam(uint32_t entryIdx,lineStatsEntry_t *lineStatEntry);
int readLineStatsRam(uint32_t entryIdx,lineStatsEntry_t *lineStatEntry);

int readPmDtFiFo(uint32_t entryIdx,uint32_t *rowValue);

#if EAGLE_INCLUDE_EFM
int	writeEfmTxTempl(uint16_t efmLMepNum,efmInfoTemplEntry_t *efmInfoTemplEntry);
int	writeEfmTxLBTempl(uint16_t efmLbChnl,efmLbTemplEntry_t *efmLbTemplEntry,uint8_t pktType, uint8_t lbData[]);
int	writeEfmTxTemplFlags(efmFlags_t *newFlags);
int	writeEfmTxTemplLclRev(uint32_t newRev);
int	writeEfmTxTemplIncLclRev(uint16_t *newRev);
int	writeEfmTxTemplLclState(uint8_t mux, uint8_t parser);
int	writeEfmTxTempleRemTlv(efmLRInfoTlv_t *newTlv);
int	writeEfmTxTempleLength(uint16_t pktLen);
int readEfmTxTemplLclRev(uint16_t *revision);
int writeEfmTxTemplLclCfg(efmCfg_t *efmCfg);
int writeEfmTxTemplOrgInfoTlv(uint32_t oui,uint8_t valueLen,uint8_t *value);

int readEfmTxTemplFlags(efmFlags_t *flags);
int	readEfmTxTemplLclTlv(efmLRInfoTlv_t *localTlv);
#endif

void clearLBErrors(uint8_t chnl);

int readRawEvcTbl(uint32_t addr, uint32_t *rdPtr, iFace_t iFace);
int writeRawEvcTbl(uint32_t addr, uint32_t wrData, iFace_t iFace);
int readEvcTbl(uint16_t evc, evcTblEntry_t *evcTblEntry, iFace_t iFace);
int writeEvcTbl(uint16_t evc, evcTblEntry_t *evcTblEntry, iFace_t iFace);

int readCfmTbl(uint16_t cfmNum, cfmTblEntry_t *cfmTblEntry, iFace_t iFace);
int writeCfmTbl(uint16_t cfmNum, cfmTblEntry_t *cfmTblEntry, iFace_t iFace);

int writeRxPcpTbl(uint8_t row, iFace_t iFace, pcpEntry_t *pcpEntry);
int readRxPcpTbl(uint8_t row, iFace_t iFace, pcpEntry_t *pcpEntry);
int writeTxPcpTbl(uint8_t row, iFace_t iFace, prio_t pcp);
int readTxPcpTbl(uint8_t row, iFace_t iFace, prio_t *pcp);
int writeDscpTbl(uint8_t row, iFace_t iFace, pcpEntry_t *pcpEntry, uint8_t discard);
int readDscpTbl(uint8_t row, iFace_t iFace, pcpEntry_t *pcpEntry, uint8_t *discard);

int writeFlowNumTbl(uint32_t row, iFace_t iFace, flowNumEntry_t *flowNumEntry);
int readFlowNumTbl(uint32_t row, iFace_t iFace, flowNumEntry_t *flowNumEntry);

int writeFrameDelayBinThresh(uint8_t binNum, uint32_t threshold);
int writeFrameDelayVarBinThresh(uint8_t binNum, uint32_t threshold);

void setHwLMepEnableState(lMepNum_t lMepNum, bool enable);

void setInvalidTlvFlag(rMepNum_t rMepNum);
void clrInvalidTlvFlag(rMepNum_t rMepNum);

#ifdef CPP
	}
#endif
#endif
