/*
Copyright (C) 2008, 2009  GE Intelligent Platforms, Inc
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef __RHASICDRV_H__
#define __RHASICDRV_H__

/* Opcodes for the MDIO transactions defined in Clause 45 */
#define MDIO_OP_ADDR        0x0     /* 2 bits       - Address operation */
#define MDIO_OP_WRITE       0x1     /* 2 bits       - write operation */
#define MDIO_OP_INCRD       0x2     /* 2 bits       - write operation */
#define MDIO_OP_READ        0x3     /* 2 bits       - read operation */

/* Used for registers with instances */
#define STAT_INST(regname, to) regGet(regdb, regname, port, to)

/* Used for registers with no instance */
#define STAT(regname, to) regGet(regdb, regname, 0, to)

/* Declaring fields for interrupt source registers */
/* for Interrupt Source 0 register */
#define COMMON_INTR                 BIT_31
#define RXMAC_INTR_P0               BIT_30
#define RXMAC_INTR_P1               BIT_29
#define TXMAC_CFGINTR_P0            BIT_28
#define TXMAC_CFGINTR_P1            BIT_27
#define TXMAC_STSINTR_P0            BIT_26
#define TXMAC_STSINTR_P1            BIT_25
#define RXPSPI_INTR                 BIT_24
#define RXSSPI_INTR                 BIT_23
#define QUEUEMGR_INTR_P0            BIT_22
#define QUEUEMGR_INTR_P1            BIT_21
#define DUALMEMCTRL_INTR_P0         BIT_20
#define DUALMEMCTRL_INTR_P1         BIT_19
#define DEQUEUER_INTR_P0            BIT_18
#define DEQUEUER_INTR_P1            BIT_17
#define RXHIGIGXMAC_INTR_P0         BIT_16
#define RXHIGIGXMAC_INTR_P1         BIT_15
#define TXHIGIGXMAC_INTR_P0         BIT_14
#define TXHIGIGXMAC_INTR_P1         BIT_13
#define TXMEMMGR_INTR_P0            BIT_12
#define TXMEMMGR_INTR_P1            BIT_11
#define TXMEMMGRCOMM_INTR           BIT_10
#define TXPSPI_INTR                 BIT_9
#define TXSSPI_INTR                 BIT_8
#define RXWRED_INTR_P0              BIT_7
#define RXWRED_INTR_P1              BIT_6
#define ENQUEUER_INTR_P0            BIT_5
#define ENQUEUER_INTR_P1            BIT_4
#define TXVLANCTRL_INTR_P0          BIT_3
#define TXVLANCTRL_INTR_P1          BIT_2
#define TXCPUTOLINE_INTR_P0         BIT_1
#define TXCPUTOLINE_INTR_P1         BIT_0

/* for Interrupt Source 1 register */
#define MDIO_INTR                   BIT_14
#define RXDROPCTRL_INTR_P0          BIT_13
#define RXDROPCTRL_INTR_P1          BIT_12
#define RXDROPCTRLSTAT_INTR_P0      BIT_11
#define RXDROPCTRLSTAT_INTR_P1      BIT_10
#define SHADOWREG_INTR_P0           BIT_9
#define SHADOWREG_INTR_P1           BIT_8
#define RXLINETOCPUINTR_P0          BIT_7
#define RXLINETOCPUINTR_P1          BIT_6
#define LED_INTR_P0                 BIT_5
#define LED_INTR_P1                 BIT_4
#define RSVD_0                      BIT_3
#define RSVD_1                      BIT_2
#define TXPCS_INTR_P0               BIT_1
#define TXPCS_INTR_P1               BIT_0

/* Declarations for the fields of the interrupt registers */
#define COCLKMON_SPIRSCLK1          BIT_14
#define COCLKMON_SPIRSCLK0          BIT_13
#define COCLKMON_RXXFI66CLK1        BIT_12
#define COCLKMON_RXXFI66CLK0        BIT_11
#define COCLKMON_TXXFI66CLK1        BIT_10
#define COCLKMON_TXXFI66CLK0        BIT_9
#define COCLKMON_RXXFI64CLK1        BIT_8
#define COCLKMON_RXXFI64CLK0        BIT_7
#define COCLKMON_TXXFI64CLK1        BIT_6
#define COCLKMON_TXXFI64CLK0        BIT_5
#define COCLKMON_SPIRDCLK1          BIT_4
#define COCLKMON_SPIRDCLK0          BIT_3
#define COCLKMON_XAUICLK1           BIT_2
#define COCLKMON_XAUICLK0           BIT_1
#define COCLKMON_SYSCLK             BIT_0

#define WIREMASTER_INTR_P1          BIT_1
#define WIREMASTER_INTR_P0          BIT_0

#define COXAUI_BYTESYNC_P1          BIT_1
#define COXAUI_BYTESYNC_P0          BIT_0

#define COXFI_INTR_P1               BIT_1
#define COXFI_INTR_P0               BIT_0

#define RXMAC_VLDPAUSEFRM           BIT_6
#define RXMAC_PREAMBLEMISMATCH      BIT_5
#define RXMAC_FIFODRYTIMEOUT        BIT_4
#define RXMAC_FIFOFULL              BIT_3
#define RXMAC_CPUFRAME              BIT_2
#define RXMAC_REMOTELINKFAULTSTATUS BIT_1
#define RXMAC_LOCALLINKFAULTSTATUS  BIT_0

#define RXXAUI_REMOTEFAULTSTATUS    BIT_1
#define RXXAUI_LOCALFAULTSTATUS     BIT_0

#define EXTMEM_FCRAMINTR            BIT_2
#define EXTMEM_READINTR             BIT_1
#define EXTMEM_WRITEINTR            BIT_0

#define RXSPI_REMOTELINKFAULTSTATUS BIT_1
#define RXSPI_LOCALLINKFAULTSTATUS  BIT_0

#define TXMAC_PAUSEFRMSENT          BIT_3
#define TXMAC_FIFOFULLTIMEOUT       BIT_2
#define TXMAC_FIFODRY               BIT_1
#define TXMAC_CRCERROR              BIT_0

#define TXSPI_FIFOOVERFLOW          BIT_3
#define TXSPI_LOSSOFSYNC            BIT_2
#define TXSPI_PROTOCOLVIOLATION     BIT_1
#define TXSPI_HIGHDIP4ERROR         BIT_0

#define MDIO_AUTOSCANPHY1           BIT_2
#define MDIO_AUTOSCANPHY0           BIT_1
#define MDIO_COMMANDDONE            BIT_0

/* Number of ports */
#define NUM_PORTS 2

/* Structure holding the number of interrupts */
struct rhAsicInterrupts_ {
    struct commonInt_ {
        unsigned int total;
        unsigned int SpiRsClk1;
        unsigned int SpiRsClk0;
        unsigned int RxXfi66Clk1;
        unsigned int RxXfi66Clk0;
        unsigned int TxXfi66Clk1;
        unsigned int TxXfi66Clk0;
        unsigned int RxXfi64Clk1;
        unsigned int RxXfi64Clk0;
        unsigned int TxXfi64Clk1;
        unsigned int TxXfi64Clk0;
        unsigned int SpiRdClk1;
        unsigned int SpiRdClk0;
        unsigned int XauiClk1;
        unsigned int XauiClk0;
        unsigned int SysClk;
        unsigned int xaui;
        unsigned int xfi;
        unsigned int wiremaster1;
        unsigned int wiremaster0;
        unsigned int xauiByteSyncStatusChangeP0;
        unsigned int xauiByteSyncStatusChangeP1;
        unsigned int xfiintr0;
        unsigned int xfiintr1;
    } commonInt;

    struct mdio_ {
        unsigned int total;
        unsigned int autoScanPhy1;
        unsigned int autoScanPhy0;
        unsigned int cmdDone;
    } mdio;

    struct shadow_ {
        unsigned int total;
        unsigned int eventTrigger;
    } shadow[NUM_PORTS];

    struct rxMac_ {
        unsigned int total;
        unsigned int vldPauseFrmRcvd;
        unsigned int preambleMismatch;
        unsigned int fifoDryTimeOut;
        unsigned int fifoFull;
        unsigned int cpuFrame;
        unsigned int remoteLinkFaultStatus;
        unsigned int localLinkFaultStatus;
    } rxMac[NUM_PORTS];

    struct drpCtrl_ {
        unsigned int total;
        unsigned int miscEccErr;
        unsigned int miscEccSingleErr;
        unsigned int miscEccDoubleErr;
        unsigned int oVlanCpuEccErr;
        unsigned int oVlanCpuEccSingleErr;
        unsigned int oVlanCpuEccDoubleErr;
        unsigned int oVlanCtrlEccErr;
        unsigned int oVlanCtrlEccSingleErr;
        unsigned int oVlanCtrlEccDoubleErr;
        unsigned int iVlanCpuEccErr;
        unsigned int iVlanCpuEccSingleErr;
        unsigned int iVlanCpuEccDoubleErr;
        unsigned int iVlanCtrlEccErr;
        unsigned int iVlanCtrlEccSingleErr;
        unsigned int iVlanCtrlEccDoubleErr;
    } drpCtrl[NUM_PORTS];

    struct rxWred_ {
        unsigned int total;
        unsigned int err;
        unsigned int singleErr;
        unsigned int doubleErr;
    } rxWred[NUM_PORTS];

    struct lineToCpu_ {
        unsigned int total;
        unsigned int fifoFull;
        unsigned int fifoEmpty;
        unsigned int fifoData;
        unsigned int eccErr;
        unsigned int eccSingleErr;
        unsigned int eccDoubleErr;
        unsigned int fifoUnderrun;
    } lineToCpu[NUM_PORTS];

    struct memEnq_ {
        unsigned int total;
        unsigned int dmeccErr;
        unsigned int dmeccSingleErr;
        unsigned int dmeccDoubleErr;
        unsigned int enqSequenceErr;
        unsigned int enqDFifoOverflow;
        unsigned int enqSzLstFifoOverflow;
    } memEnq[NUM_PORTS];

    struct extMem_ {
        unsigned int total;
        unsigned int initFcram;
        unsigned int read;
        unsigned int write;
    } extMem[NUM_PORTS];

    struct databaseMgr_ {
        unsigned int total;
        unsigned int totalRsvdPageCount;
        unsigned int pageFifoOverflow;
        unsigned int qmFptEccErr;
        unsigned int qmFptEccSingleErr;
        unsigned int qmFptEccDoubleErr;
        unsigned int qmPltEccErr;
        unsigned int qmPltEccSingleErr;
        unsigned int qmPltEccDoubleErr;
    } databaseMgr[NUM_PORTS];

    struct rxDeq_ {
        unsigned int total;
        unsigned int qnumFifoOverflow;
        unsigned int dataFifoOverflow0;
        unsigned int dataFifoOverflow1;
        unsigned int dataFifoOverflow2;
        unsigned int dataFifoOverflow3;
        unsigned int dataFifoOverflow4;
        unsigned int dataFifoOverflow5;
        unsigned int dataFifoOverflow6;
        unsigned int dataFifoOverflow7;
        unsigned int eccErr;
        unsigned int eccSingleErr;
        unsigned int eccDoubleErr;
    } rxDeq[NUM_PORTS];

    struct rxSpi_ {
        unsigned int total;
        unsigned int rxpSpi;
        unsigned int rxsSpi;
    } rxSpi;

    struct rxXauiUplink_ {
        unsigned int total;
        unsigned int remoteLinkFaultStatus;
        unsigned int localLinkFaultStatus;
    } rxXauiUpLink[NUM_PORTS];

    struct txPrtInterface_ {
        unsigned int total;
        unsigned int pcsAlignFail;
        unsigned int syncStatusChanged;
    } txPrtInterface[NUM_PORTS];

    struct txMac_ {
        unsigned int total;
        unsigned int pauseFrmSent;
        unsigned int fifoFullTimeOut;
        unsigned int fifoDry;
        unsigned int crcErr;
    } txMac[NUM_PORTS];

    struct txVlanCtrl_ {
        unsigned int total;
        unsigned int underRunIntr;
        unsigned int err;
        unsigned int singleErr;
        unsigned int doubleErr;
    } txVlanCtrl[NUM_PORTS];

    struct txMemMgr_ {
        unsigned int total;
        unsigned int eccErr;
        unsigned int eccSingleErr;
        unsigned int eccDoubleErr;
        unsigned int mtuFifoOverflow;
        unsigned int mtuFifoUnderflow;
        unsigned int efhFifoOverflow;
        unsigned int efhFifoUnderflow;
    } txMemMgr[NUM_PORTS];

    struct cpuToLine_ {
        unsigned int total;
        unsigned int err;
        unsigned int singleErr;
        unsigned int doubleErr;
    } cpuToLine[NUM_PORTS];

    struct txpSpi_ {
        unsigned int total;
        unsigned int tSpiFifoOverFlow;
        unsigned int tSpiLossOfSync;
        unsigned int tSpiProtocolViolation;
        unsigned int tSpiHighDip4Error;
    } txpSpi;

    struct txsSpi_ {
        unsigned int total;
        unsigned int txSSpiFifoOverFlow;
        unsigned int txSSpiLossOfSync;
        unsigned int txSSpiProtocolViolation;
        unsigned int txSSpiHighDip4Error;
        unsigned int miscEccErr0;
        unsigned int miscEccSingleErr0;
        unsigned int miscEccDoubleErr0;
        unsigned int miscEccErr1;
        unsigned int miscEccSingleErr1;
        unsigned int miscEccDoubleErr1;
    } txsSpi;

    struct spiMtuCpu_ {
        unsigned int err0;
        unsigned int singleErr0;
        unsigned int doubleErr0;
        unsigned int err1;
        unsigned int singleErr1;
        unsigned int doubleErr1;
    } spiMtuCpu;
};

void rhAsicInterruptHandler (reginfo_t *regdb);

/*
 * RedHawk Statistic Structures
 */
typedef struct shadowRegsStats {
    unsigned int ToalFrmsReceived;
    unsigned int ToalFrmsTransmitted;
    unsigned int GoodFrmsReceived;
    unsigned int GoodFrmsTransmitted;
    unsigned int CrcErrsReceived;
    unsigned int CrcErrsTransmitted;
    unsigned int FrmsDropedByRed;
    unsigned int UCastFrmsDroped;
    unsigned int MCastFrmsDroped;
    unsigned int BCastFrmsDroped;
    unsigned int MPLSFrmsDroped;
    unsigned int EthTypeMatchFrmsDroped;
    unsigned int MacFilterFrmsDroped;
    unsigned int IngFilterFrmsDroped;
    unsigned int DeqExcessLatencyFrmsDroped;
    unsigned int EnqMemFullFrmsDroped;
} shadowRegsStats;

typedef struct rxMacStats {
    unsigned int RxVLANTagRcvd;
    unsigned int RxPauseTime;
    unsigned int LsbRxOctetsRcvdOK;
    unsigned int MsbRxOctetsRcvdOK;
    unsigned int LsbRxNumOfBadOctets;
    unsigned int MsbRxNumOfBadOctets;
    unsigned int RxNumOfBadFrms;
    unsigned int RxFRcvdOK;
    unsigned int RxNumOfCRCErrors;
    unsigned int RxNumOfBcastFrms;
    unsigned int RxNumOfMcastFrms;
    unsigned int RxFrmsOf64Octets;
    unsigned int RxFrmsOf65to127Octets;
    unsigned int RxFrmsOf128to255Octets;
    unsigned int RxFrmsOf256to511Octets;
    unsigned int RxFrmsOf512to1023Octets;
    unsigned int RxFrmsOf1024to1518Octets;
    unsigned int RxJumboFrms;
    unsigned int RxOversizeFrms;
    unsigned int RxUndersizeFrms;
    unsigned int RxNumOfFragments;
    unsigned int RxNumOfJabbers;
    unsigned int RxNumOfTooLongJabbers;
    unsigned int RxOutOfRangeLenField;
    unsigned int RxFTooLongErrors;
    unsigned int RxMACCtrlFRcvd;
    unsigned int RxUnsuppOpcodeRcvd;
    unsigned int RxGoodVLANFRcvd;
    unsigned int RxBadSAFRcvd;
    unsigned int RxDataError;
    unsigned int RxMcastDrop;
    unsigned int RxBcastDrop;
    unsigned int RxFilDrop;
    unsigned int RxMACInterrupt;
    unsigned int RxMACInterruptMask;
    unsigned int RxMACDiag;
    unsigned int RxIPG5;
    unsigned int RxIPG6;
    unsigned int RxIPG7;
    unsigned int RxIPG8;
    unsigned int RxIPG9;
    unsigned int RxIPG10;
    unsigned int RxIPG11;
} rxMacStats;

typedef struct rxDropControlStats {
    unsigned int TailDropCount;
    unsigned int RxDefaultDroppedFrms;
    unsigned int MSBRxDefaultDroppedOctets;
    unsigned int LSBRxDefaultDroppedOctets;
    unsigned int RxDroppedBCastFrms;
    unsigned int RxDroppedMCastFrms;
    unsigned int MSBRxDroppedBCastMCastOctets;
    unsigned int LSBRxDroppedBCastMCastOctets;
    unsigned int RxMPLSTypeMatchFrms;
    unsigned int RxMPLSDefaultMatchFrms;
    unsigned int RxMPLSLLSPMatchFrms;
    unsigned int RxMPLSDLLSPMatchFrms;
    unsigned int RxMPLSDroppedFrms;
    unsigned int MSBRxMPLSDroppedOctets;
    unsigned int LSBRxMPLSDroppedOctets;
    unsigned int RxVLANEthertypeFrms;
    unsigned int RxSVLANEthertypeFrms;
    unsigned int RxVLANSVLANEtherDropFrms;
    unsigned int RxStdPriMapFrms;
    unsigned int RxExtdPriMapFrms;
    unsigned int RxNoVLANTagFrms;
    unsigned int RxSingleVLANTagFrms;
    unsigned int RxDoubleVLANTagFrms;
    unsigned int RxMT2VLANTagFrms;
    unsigned int RxVLANControlDropFrms;
    unsigned int RxExtdVLANTagFrms;
    unsigned int RxVLANTagOpFrms;
    unsigned int RxVLANPrioOvrwrFrms;
    unsigned int RxDAMatchFrms;
    unsigned int RxMultiHashFrms;
    unsigned int RxTypeFrms;
    unsigned int RxOtherTypeFrms;
    unsigned int RxLLCSNAPFrms;
    unsigned int RxUnknownLLCSNAPFrms;
    unsigned int RxMACDropFrms;
    unsigned int MSBRxVLANMACDropOctets;
    unsigned int LSBRxVLANMACDropOctets;
    unsigned int RxDSCPIPVerMismatchFrms;
    unsigned int RxDSCPAssignFrms;
    unsigned int RxIPAssignFrms;
    unsigned int RxDIPAssignFrms;
    unsigned int RxDSCPIPDropFrms;
    unsigned int MSBRxDSCPIPDropOctets;
    unsigned int LSBRxDSCPIPDropOctets;
    unsigned int RxDropControlEOFs;
    unsigned int OVLANCtrlRdData;
    unsigned int IVLANCtrlRdData;
    unsigned int VLANIDRdData;
    unsigned int HashRdData;
    unsigned int DSCPAssignData;
    unsigned int RxIllegalTypeLenFrms;
    unsigned int RdDataRxVlanTagRam;
    unsigned int RxInRangeLengthErrs;
    unsigned int RxOutofRangeLengthErrs;
    unsigned int RxQueue0Frms;
    unsigned int RxQueue1Frms;
    unsigned int RxQueue2Frms;
    unsigned int RxQueue3Frms;
    unsigned int RxQueue4Frms;
    unsigned int RxQueue5Frms;
    unsigned int RxQueue6Frms;
    unsigned int RxQueue7Frms;
} rxDropControlStats;

typedef struct rxDropControlWredStats {
    unsigned int WREDDropProbability;
    unsigned int WREDDrop_0;
    unsigned int WREDDrop_1;
    unsigned int WREDDrop_2;
    unsigned int WREDDrop_3;
    unsigned int WREDDrop_4;
    unsigned int WREDDrop_5;
    unsigned int WREDDrop_6;
    unsigned int WREDDrop_7;
    unsigned int BPDUDrop_0;
    unsigned int BPDUDrop_1;
    unsigned int BPDUDrop_2;
    unsigned int BPDUDrop_3;
    unsigned int BPDUDrop_4;
    unsigned int BPDUDrop_5;
    unsigned int BPDUDrop_6;
    unsigned int BPDUDrop_7;
    unsigned int TailDrop_0;
    unsigned int TailDrop_1;
    unsigned int TailDrop_2;
    unsigned int TailDrop_3;
    unsigned int TailDrop_4;
    unsigned int TailDrop_5;
    unsigned int TailDrop_6;
    unsigned int TailDrop_7;
    unsigned int GreenColorMark_0;
    unsigned int GreenColorMark_1;
    unsigned int GreenColorMark_2;
    unsigned int GreenColorMark_3;
    unsigned int GreenColorMark_4;
    unsigned int GreenColorMark_5;
    unsigned int GreenColorMark_6;
    unsigned int GreenColorMark_7;
    unsigned int YelloColorMark_0;
    unsigned int YelloColorMark_1;
    unsigned int YelloColorMark_2;
    unsigned int YelloColorMark_3;
    unsigned int YelloColorMark_4;
    unsigned int YelloColorMark_5;
    unsigned int YelloColorMark_6;
    unsigned int YelloColorMark_7;
    unsigned int OrangeColorMark_0;
    unsigned int OrangeColorMark_1;
    unsigned int OrangeColorMark_2;
    unsigned int OrangeColorMark_3;
    unsigned int OrangeColorMark_4;
    unsigned int OrangeColorMark_5;
    unsigned int OrangeColorMark_6;
    unsigned int OrangeColorMark_7;
    unsigned int ColorRedMark_0;
    unsigned int ColorRedMark_1;
    unsigned int ColorRedMark_2;
    unsigned int ColorRedMark_3;
    unsigned int ColorRedMark_4;
    unsigned int ColorRedMark_5;
    unsigned int ColorRedMark_6;
    unsigned int ColorRedMark_7;
    unsigned int ExCongMark_0;
    unsigned int ExCongMark_1;
    unsigned int ExCongMark_2;
    unsigned int ExCongMark_3;
    unsigned int ExCongMark_4;
    unsigned int ExCongMark_5;
    unsigned int ExCongMark_6;
    unsigned int ExCongMark_7;
    unsigned int EopCount;
} rxDropControlWredStats;

typedef struct rxLineToCpuStats {
    unsigned int DataReg0;
    unsigned int DataReg1;
    unsigned int DataReg2;
    unsigned int DataReg3;
    unsigned int DataReg4;
    unsigned int DataReg5;
    unsigned int DataReg6;
    unsigned int DataReg7;
    unsigned int DataReg8;
    unsigned int DataReg9;
    unsigned int DataReg10;
    unsigned int DataReg11;
    unsigned int DataReg12;
    unsigned int WritePointer;
    unsigned int ReadPointer;
    unsigned int CommitPointer;
    unsigned int DropPktCnt;
} rxLineToCpuStats;

typedef struct enqueuerStats {
    unsigned int IntMemData_0;
    unsigned int IntMemData_1;
    unsigned int IntMemData_2;
    unsigned int IntMemData_3;
    unsigned int IntMemData_4;
    unsigned int IntMemData_5;
    unsigned int IntMemData_6;
    unsigned int IntMemData_7;
    unsigned int IntMemCurrentRdAddress;
    unsigned int IntMemCurrentWrAddress;
    unsigned int EnqIgrPktCnt;
    unsigned int EnqEgrPktCnt;
    unsigned int EnqDropPktCnt;
    unsigned int EnqDropPktCntQNum0;
    unsigned int EnqDropPktCntQNum1;
    unsigned int EnqDropPktCntQNum2;
    unsigned int EnqDropPktCntQNum3;
    unsigned int EnqDropPktCntQNum4;
    unsigned int EnqDropPktCntQNum5;
    unsigned int EnqDropPktCntQNum6;
    unsigned int EnqDropPktCntQNum7;
} enqueuerStats;

typedef struct dualMemCtlStats {
    unsigned int ExtMemData_0;
    unsigned int ExtMemData_1;
    unsigned int ExtMemData_2;
    unsigned int ExtMemData_3;
    unsigned int ExtMemData_4;
    unsigned int ExtMemData_5;
    unsigned int ExtMemData_6;
    unsigned int ExtMemData_7;
    unsigned int ExtMemCurrentRdAddress;
    unsigned int ExtMemCurrentWrAddress;
    unsigned int InitFCRAM;
    unsigned int MemAccessInterrupt;
    unsigned int MemAccessInterruptMask;
} dualMemCtlStats;

typedef struct queueManagerStats {
    unsigned int MaxPageCountRd;
    unsigned int RsvdPageCountRd;
    unsigned int RsvdPoolPagePntr;
    unsigned int FreePoolPagePntr;
    unsigned int MemoryFullCount;
    unsigned int qfillCount[8];
    unsigned int usedPageCount[8];
} queueManagerStats;

typedef struct DequeuerStats {
    unsigned int TailDropCount;
    unsigned int EOFCount;
    unsigned int LpbkEOFCount;
    unsigned int PktCountQ0;
    unsigned int PktCountQ1;
    unsigned int PktCountQ2;
    unsigned int PktCountQ3;
    unsigned int PktCountQ4;
    unsigned int PktCountQ5;
    unsigned int PktCountQ6;
    unsigned int PktCountQ7;
    unsigned int ExcessLatencyDropCountQ0;
    unsigned int ExcessLatencyDropCountQ1;
    unsigned int ExcessLatencyDropCountQ2;
    unsigned int ExcessLatencyDropCountQ3;
    unsigned int ExcessLatencyDropCountQ4;
    unsigned int ExcessLatencyDropCountQ5;
    unsigned int ExcessLatencyDropCountQ6;
    unsigned int ExcessLatencyDropCountQ7;
} DequeuerStats;

typedef struct rxpSpiStats {
    unsigned int RpSpiPLLLockDet;
    unsigned int RxpSpiInFifoEopCnt;
    unsigned int RxpSpiSopCount[5];
    unsigned int RxpSpiEop1Count[5];
    unsigned int RxpSpiEop2Count[5];
    unsigned int RxpSpiEopACount[5];
    unsigned int RxpSpiTrainingCount;
    unsigned int RxpSpiMdrrCreditCntr[5];
    unsigned int RxpSpiPortBurstCntr[5];
    unsigned int RxpSpiPerFetchFifoUFlow;
    unsigned int RxpSpiDiag;
} rxpSpiStats;

typedef struct rxSSpiStats {
    unsigned int RsSpiPLLLockDet;
    unsigned int RxsSpiInFifoEopCnt;
    unsigned int RxsSpiSopCount;
    unsigned int RxsSpiEop1Count;
    unsigned int RxsSpiEop2Count;
    unsigned int RxsSpiEopACount;
    unsigned int RxsSpiTrainingCount;
    unsigned int RxsSpiMdrrCreditCntr;
    unsigned int RxsSpiPortBurstCntr;
    unsigned int RxsSpiDiag;
    unsigned int RxsSpiPerFetchFifoUFlow;
    unsigned int RxsSpiDip2ErrCount;
} rxSSpiStats;

typedef struct rxXauiXMacStats {
    unsigned int RxXauiXmacSopInCnt;
    unsigned int RxXauiXmacEopInCnt;
    unsigned int RxXauiXmacSopOutCnt;
    unsigned int RxXauiXmacEopOutCnt;
    unsigned int LsbRxXauiXmacByteCount;
    unsigned int MsbRxXauiXmacByteCount;
    unsigned int RxXauiXmacFrames;
    unsigned int RxXauiXmacErroredFrames;
    unsigned int RxRSInterrupt;
    unsigned int RxRSInterruptMask;
} rxXauiXMacStats;

typedef struct txMacStats {
    unsigned int LsbGoodByteCount;
    unsigned int MsbGoodByteCount;
    unsigned int LsbErrorByteCount;
    unsigned int MsbErrorByteCount;
    unsigned int GoodFrames;
    unsigned int BCASTFrames;
    unsigned int MCASTFrames;
    unsigned int ControlFrames;
    unsigned int VLANFrames;
    unsigned int PauseFrames;
    unsigned int Frames64B;
    unsigned int Frames65to127B;
    unsigned int Frames128to255B;
    unsigned int Frames256to511B;
    unsigned int Frames512to1023B;
    unsigned int Frames1024to1518B;
    unsigned int Over1518BFrames;
    unsigned int ErroredFrames;
    unsigned int FilterDropFrames;
    unsigned int McastFilterDrop;
    unsigned int BcastFilterDrop;
    unsigned int TooLongFrames;
    unsigned int DroppedFrames;
    unsigned int JumboFrames;
    unsigned int FCSError;
    unsigned int MACInterrupt;
    unsigned int MACInterruptMask;
    unsigned int DiagPort;
} txMacStats;

typedef struct txVlanCtrlStats {
    unsigned int RdDataTxVlanCtrlTblRamReg;
    unsigned int RdDataVlanTagRamReg;
    unsigned int TxVlanCtrlSopInCnt;
    unsigned int TxVlanCtrlEopInCnt;
    unsigned int TxVlanCtrlSopOutCnt;
    unsigned int TxVlanCtrlEopOutCnt;
    unsigned int MPLSUnicastFrameCount;
    unsigned int MPLSMulticastFrameCount;
    unsigned int MPLSFrameOctetsEgressed;
    unsigned int NoVLANTagFrameCount;
    unsigned int SingleVLANTagFrameCount;
    unsigned int DoubleVLANTagFrameCount;
    unsigned int VLANControlTableFrameCount;
    unsigned int DefaultVLANControlTableFrameCount;
    unsigned int VLANControlTableTagOperationFrameCount;
    unsigned int EfhTagOperationFrameCount;
    unsigned int PreservedFrameCount;
} txVlanCtrlStats;

typedef struct txMemManagerStats {
    unsigned int MemMgrEgrPktCnt;
    unsigned int MemMgrDropPktCnt;
    unsigned int VlanCtrlPktCrcErrCnt;
    unsigned int EgressSpiErrDropCnt;
    unsigned int MemMgrOneLinePktsDropedCnt;
    unsigned int VlanCtrlEfhFcsErrCnt;
    unsigned int RedHawkIdMisMatchCnt;
} txMemManagerStats;

typedef struct txMemCommonStats {
    unsigned int WidConSopEopSameLineDropCntP0;
    unsigned int WidConSopEopSameLineDropCntP1;
    unsigned int TxMemMgrSPIMaxSzPktDrpCntPrt0;
    unsigned int TxMemMgrSPIMaxSzPktDrpCntPrt1;
    unsigned int TxMemMgrSPIMinSzPktDrpCntPrt0;
    unsigned int TxMemMgrSPIMinSzPktDrpCntPrt1;
} txMemCommonStats;

typedef struct txCpuToLineStats {
    unsigned int DropPktCnt;
    unsigned int WritePointer;
    unsigned int ReadPointer;
    unsigned int CommitPointer;
} txCpuToLineStats;

typedef struct txpSpiStats {
    unsigned int TSpiTrainingCount;
    unsigned int TSpiSopCount;
    unsigned int TSpiEopCount;
    unsigned int TSpiExtEopACount;
    unsigned int TSpiIntEopACount;
    unsigned int TSpiDip4ErrCount;
    unsigned int TSpiProtViolCount;
    unsigned int TSpiInterrupt;
    unsigned int TSpiInterruptMask;
    unsigned int TSpiFifoOverFlow;
    unsigned int TSpiDiag;
    unsigned int PSpiDPGStatus;
    unsigned int PSpiDPVBitCnt;
    unsigned int PSpiDPVErrorCnt;
    unsigned int PSpiDPVCRCErrorCnt;
    unsigned int PSpiDPVGoodPktCnt;
    unsigned int PSpiDPVSyncOnCnt;
    unsigned int PSpiDPVEopCnt;
    unsigned int PSpiCh0DropCount;
    unsigned int PSpiCh1DropCount;
    unsigned int PSpiLpbkPktDropCount;
    unsigned int PSpiXauiPktDropCount;
    unsigned int PSpiEopCountCh0;
    unsigned int PSpiEopCountCh1;
    unsigned int PSpiEopCountCh2;
    unsigned int PSpiEopCountCh3;
} txpSpiStats;

typedef struct txsSpiStats {
    unsigned int SSpiTrainingCount;
    unsigned int SSpiSopCount;
    unsigned int SSpiEopCount;
    unsigned int SSpiExtEopACount;
    unsigned int SSpiIntEopACount;
    unsigned int SSpiDip4ErrCount;
    unsigned int SSpiProtViolCount;
    unsigned int SSpiInterrupt;
    unsigned int SSpiInterruptMask;
    unsigned int SSpiFifoOverFlow;
    unsigned int SSpiDiag;
    unsigned int SSpiDPGStatus;
    unsigned int SSpiDPVBitCnt;
    unsigned int SSpiDPVErrorCnt;
    unsigned int SSpiDPVCRCErrorCnt;
    unsigned int SSpiDPVGoodPktCnt;
    unsigned int SSpiDPVSyncOnCnt;
    unsigned int SSpiDPVEopCnt;
    unsigned int SSpiCh0PktDropCount;
    unsigned int SSpiCh1PktDropCount;
    unsigned int SSpiLpbkPktDropCount;
    unsigned int SSpiEopCountCh0;
    unsigned int SSpiEopCountCh1;
    unsigned int SSpiEopCountCh2;
} txsSpiStats;

typedef struct txXauiXMacStats {
    unsigned int XauiXmacSopInCnt;
    unsigned int XauiXmacEopInCnt;
    unsigned int XauiXmacSopOutCnt;
    unsigned int XauiXmacEopOutCnt;
    unsigned int LsbTxXauiXmacByteCount;
    unsigned int MsbTxXauiXmacByteCount;
    unsigned int XauiXmacFrames;
    unsigned int XauiXmacErroredFrames;
} txXauiXMacStats;

typedef struct txsSpiMtuAccessStats {
    unsigned int TailDropCount1;
} txsSpiMtuAccessStats;

/*
 * rhAsicLib functions
 */
/* User Level Configuration functions */
void rhAsicXfiSpiConfig(int port);
void rhAsicXfiSpi2To1Config (void);
void rhAsicXauiSpiConfig(int port);
void rhAsic2To1Config (int port0, int port1, int lb_mode);

/* Initilization functions */
void rh_xfi_config (reginfo_t *regdb, int port, int ram_type);
void rh_xaui_config (reginfo_t *regdb, int port, int ram_type);
void rh_xfi_reconfig (reginfo_t *regdb, int port);

/* Module initilization routines */
void rhCommonInit (reginfo_t *regdb, int port);
int rhXfiInit (reginfo_t *regdb, int port);
int rhXauiInit (reginfo_t *regdb, int port);
void rhSpiInit (reginfo_t *regdb, int port);
void rhMiscInit (reginfo_t *regdb, int port, int ram_type);

/* Miscellaneous routines */
void comm_fcram_init(int port_num, int ram_type);
void fcram_init(int port_num, int ram_type);
void set_qm_maxpages (int port);
void rhAsicConfigOVLAN (int portNum, int opId);
void rhAsicConfigIVLAN (int portNum, int opId);
void rhAsic8021POVLANConfiguration ( int portNum);
void rhAsic8021PIVLANConfiguration ( int portNum);

/* Powerdown related Functions */
void rhAsicXAUIPowerdown (int portNum);
void rhAsicXFIPowerdown (int portNum);
void rhAsicSPIPowerdown (int portNum);
void rhAsicFCRAMPowerdown (int portNum);

/* Interrupt related routines */
void rhAsicUnmaskInterrupts(void);
void rhAsicMaskInterrupts(void);

/* Functions that update the RedHawk Statistics */
void rhAsicShadowRegsStats (reginfo_t *regdb, int port, shadowRegsStats *stat);
void rhAsicRxMacStats (reginfo_t *regdb, int port, rxMacStats *stat);
void rhAsicRxDropControlStats (reginfo_t *regdb, int port, rxDropControlStats *stat);
void rhAsicRxDropControlWredStats (reginfo_t *regdb, int port, rxDropControlWredStats *stat);
void rhAsicRxLineToCpuStats (reginfo_t *regdb, int port, rxLineToCpuStats *stat);
void rhAsicEnqueuerStats (reginfo_t *regdb, int port, enqueuerStats *stat);
void rhAsicDualMemCtlStats (reginfo_t *regdb, int port, dualMemCtlStats *stat);
void rhAsicQueueManagerStats (reginfo_t *regdb, int port, queueManagerStats *stat);
void rhAsicDequeuerStats (reginfo_t *regdb, int port, DequeuerStats *stat);
void rhAsicRxpSpiStats (reginfo_t *regdb, rxpSpiStats *stat);
void rhAsicRxSSpiStats (reginfo_t *regdb, int port, rxSSpiStats *stat);
void rhAsicRxXauiXMacStats (reginfo_t *regdb, int port, rxXauiXMacStats *stat);
void rhAsicTxMacStats (reginfo_t *regdb, int port, txMacStats *stat);
void rhAsicTxVlanCtrlStats (reginfo_t *regdb, int port, txVlanCtrlStats *stat);
void rhAsicTxMemManagerStats (reginfo_t *regdb, int port, txMemManagerStats *stat);
void rhAsicTxMemCommonStats (reginfo_t *regdb, txMemCommonStats *stat);
void rhAsicTxCpuToLineStats (reginfo_t *regdb, int port, txCpuToLineStats *stat);
void rhAsicTxpSpiStats (reginfo_t *regdb, txpSpiStats *stat);
void rhAsicTxsSpiStats (reginfo_t *regdb, txsSpiStats *stat);
void rhAsicTxXauiXMacStats (reginfo_t *regdb, int port, txXauiXMacStats *stat);
void rhAsicTxsSpiMtuAccessStats (reginfo_t *regdb, txsSpiMtuAccessStats *stat);

/* Statistic display functions */
void shadowregs_stats (int port);
void rxmac_stats (int port);
void rxdropcontrol_stats (int port);
void rxdropcontrolwred_stats (int port);
void rxlinetocpu_stats (int port);
void enqueuer_stats (int port);
void dualmemctl_stats (int port);
void queuemanager_stats (int port);
void dequeuer_stats (int port);
void rxpspi_stats (void);
void rxsspi_stats (int port);
void rxxauixmac_stats (int port);
void txmac_stats (int port);
void txvlanctrl_stats (int port);
void txmemmanager_stats (int port);
void txmemcommon_stats (void);
void txcputoline_stats (int port);
void txpspi_stats (void);
void txsspi_stats (void);
void txxauixmac_stats (int port);
void txsspimtuaccess_stats (void);

/* MDIO Driver related functions */
void rhAsicConfigMDIOMode (int slave_type, int slave_name, int port);
int rhAsicMdioRead (unsigned int portAddr, unsigned int regAddr, unsigned int devAddr, unsigned *regVal);
int rhAsicMdioWrite (unsigned int phyAddr, unsigned int regAddr, unsigned int devAddr, unsigned short regVal);

/* Two Wire Driver related functions */
int rhAsicTwoWireSerialRead(int portNum, int address, unsigned int *data);
int rhAsicTwoWireSerialWrite(int portNum, int address, unsigned int data);

/* Dequeue Memory related routines*/
int deqCommitPtr(int portNum, unsigned int addr);
int rhAsicReadDeqMem(int pNum, unsigned int addr, unsigned char *data);
int rhAsicWriteDeqMem(int pNum, unsigned int addr, unsigned char *data);

/* Drop Control Memory related routines*/
int drpCtrlCommitPtr(int portNum, unsigned int addr);
int rhAsicReadDrpCtrlMem(int pNum, unsigned int addr, unsigned char *data);
int rhAsicWriteDrpCtrlMem(int pNum, unsigned int addr, unsigned char *data);

/* Tx SPI Memory related routines*/
int txSpiCommitPtr(int portNum, unsigned int addr);
int rhAsicReadTxSpiMem(int pNum, unsigned int addr, unsigned char *data);
int rhAsicWriteTxSpiMem(int pNum, unsigned int addr, unsigned char *data);

/* Tx Memory related routines*/
int txMemCommitPtr(int portNum, unsigned int addr);
int rhAsicReadTxMem(int pNum, unsigned int addr, unsigned char *data);
int rhAsicWriteTxMem(int pNum, unsigned int addr, unsigned char *data);

/* FCRAM related routines */
int rhAsicReadExtMem(int pNum, int bank, unsigned int addr, unsigned char *data);
int rhAsicWriteExtMem(int portNum, int bank, unsigned int addr, unsigned char *data);

/* Functions used internally by the Init procedures */
void rh_program_calendar_mem (int memType);
void rh_init_freepage_table (void);
void mdioWrite(unsigned int regVal);

/* DPG DPV Functions */
void rhAsicDpgSetCrc(int mode, int spi_num, unsigned int crc_val);
void rhAsicDpgSetPktSize(int spi_num, int pkt_type, unsigned int pkt_size);
void rhAsicDpgSetNumPkts(int spi_num, int cont_send, unsigned int num_pkts);
void rhAsicDpgSetGapSize(int spi_num, int type, unsigned int gap_size);
void rhAsicDpgSetPattern(int spi_num, int patt_type, unsigned int patt_data);
void rhAsicDpgInsertDA(int spi_num, unsigned int da_msb, unsigned int da_lsb);
void rhAsicDpgInsertSA(int spi_num, unsigned int sa_msb, unsigned int sa_lsb);
void rhAsicDpgInsertPreamble(int spi_num, unsigned int pr_msb, unsigned int pr_lsb);
void rhAsicDpgInsertVlan(int spi_num, unsigned int vlan_val);
void rhAsicDpgPortSetup(int port0, int port1, int lp_mode);
void rhAsicDpgSetDefault(int spi_num);
void rhAsicStartDpg(int port0, int port1);

/* Functions checking registers for Default Values */
int common_defChk (void);
int dequeuer_defChk (void);
int dualmemctl_defChk (void);
int enqueuer_defChk (void);
int led_defChk (void);
int mdio_defChk (void);
int queuemanager_defChk (void);
int rxdropcontrol_defChk (void);
int rxdropcontrolstat_defChk (void);
int rxdropcontrolwred_defChk (void);
int rxlinetocpu_defChk (void);
int rxmac_defChk (void);
int rxpspiprical_defChk (void);
int rxpspishdwcal_defChk (void);
int rxpspi_defChk (void);
int rxpspistat_defChk (void);
int rxsspiprical_defChk (void);
int rxsspishdwcal_defChk (void);
int rxsspi_defChk (void);
int rxsspistat_defChk (void);
int rxxauixmac_defChk (void);
int shadowregs_defChk (void);
int txcputoline_defChk (void);
int txmaccfg_defChk (void);
int txmemcommon_defChk (void);
int txmemmanager_defChk (void);
int portinterface_defChk (void);
int txpspiprical_defChk (void);
int txpspishdwcal_defChk (void);
int txpspi_defChk (void);
int txpspistat_defChk (void);
int txsspimtuaccess_defChk (void);
int txsspiprical_defChk (void);
int txsspishdwcal_defChk (void);
int txsspi_defChk (void);
int txsspistat_defChk (void);
int txvlanctrl_defChk (void);
int txxauixmac_defChk (void);
int rhAsicTestDefault (void);
void checkDefVal (int regId, unsigned int defVal);

typedef struct regDB_Port_ {
    reginfo_t *regdb;
    int portNumber;
}REGDB_PORT;

int xfi_poll(void * param);

#endif /* Header endif */
