/*
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 __NPA_EAGLE_H_INCLUDED__
#define __NPA_EAGLE_H_INCLUDED__

#define EAGLE_DATA_PORTS		10
#define EAGLE_CONTROL_PORTS		12

/* Eagle Statistic structures */
typedef struct rxMacStatistics {
    unsigned int vLANTagRcvd;
    unsigned int pauseTime;
    unsigned int octetsRcvdOKMSB;
    unsigned int octetsRcvdOKLSB;
    unsigned int numOfBadOctetsMSB;
    unsigned int numOfBadOctetsLSB;
    unsigned int numOfBadFrms;
    unsigned int numOfCRCErrors;
    unsigned int numOfCRCErrorsGT1518;
    unsigned int numOfCRCErrorsGTMax;
    unsigned int numOfBcastFrms;
    unsigned int numOfMcastFrms;
    unsigned int frmsOf64Octets;
    unsigned int frmsOf65to127Octets;
    unsigned int frmsOf128to255Octets;
    unsigned int frmsOf256to511Octets;
    unsigned int frmsOf512to1023Octets;
    unsigned int frmsOf1024to1518Octets;
    unsigned int oversizeFrms;
    unsigned int undersizeFrms;
    unsigned int numOfFragments;
    unsigned int numOfLongErrors;
    unsigned int numOfJabbers;
    unsigned int fRcvdOK;
    unsigned int fTooLongErrors;
    unsigned int ctrlFRcvd;
    unsigned int unsuppOpcodeRcvd;
    unsigned int goodVLANFRcvd;
    unsigned int badSAFRcvd;
    unsigned int dataError;
    unsigned int uCASTDrop;
    unsigned int filDrop;
} rxMacStatistics;

typedef struct rxDrpCtrlStats {
    unsigned int oVLANCtrlRdData;
    unsigned int oVLANCtrlRdDataPro;
    unsigned int oVLANIDRdData;
    unsigned int hashRdData;
    unsigned int dSCPAssignData;
    unsigned int tdmAbortedPkts[24];
    unsigned int tdmDroppedPkts[24];
    unsigned int rxDefaultDroppedFrms[24];
    unsigned int pedBCastFrms[24];
    unsigned int rxMPLSDroppedFrms[24];
    unsigned int rxVLANEtherDropFrms[24];
    unsigned int rxVLANControlDropFrms[24];
    unsigned int rxMACDropFrms[24];
    unsigned int rxDSCPIPDropFrms[24];
    unsigned int rxIllegalTypeLenFrms[24];
    unsigned int greenFrames[24];
    unsigned int redYellowFrames[24];
    unsigned int controlEOFs;
} rxDrpCtrlStats;

typedef struct rxWredStats {
    unsigned int eopCount[24];
    unsigned int wREDDropQ_0[24];
    unsigned int wREDDropQ_1[24];
    unsigned int wREDDropQ_2[24];
    unsigned int wREDDropQ_3[24];
    unsigned int bPDUDropQ_0[24];
    unsigned int bPDUDropQ_1[24];
    unsigned int bPDUDropQ_2[24];
    unsigned int bPDUDropQ_3[24];
    unsigned int tailDropQ_0[24];
    unsigned int tailDropQ_1[24];
    unsigned int tailDropQ_2[24];
    unsigned int tailDropQ_3[24];
} rxWredStats;

typedef struct rxLine2CpuStats {
    unsigned int nearlyFull;
    unsigned int nearlyEmpty;
    unsigned int tailDropCount;
    unsigned int pktCnt;
    unsigned int writePointer;
    unsigned int readPointer;
    unsigned int commitPointer;
    unsigned int lnDataReg_0;
    unsigned int lnDataReg_1;
    unsigned int lnDataReg_2;
    unsigned int lnDataReg_3;
    unsigned int lnDataReg_4;
    unsigned int lnDataReg_5;
    unsigned int lnDataReg_6;
    unsigned int lnDataReg_7;
    unsigned int lnDataReg_8;
    unsigned int lnDataRegVld;
} rxLine2CpuStats;

typedef struct rxEnqStats {
    unsigned int egrPktCnt;
    unsigned int perQueueDropPktCnt[96];
} rxEnqStats;

typedef struct rxQueueMgrPageStats {
    unsigned int maxPageCountRd[96];
    unsigned int rsvdPageCountRd[96];
    unsigned int usedPageCountRd[96];
    unsigned int queueFillLevel[96];
} rxQueueMgrPageStats;

typedef struct rxQueueMgrPktStats {
    unsigned int qmQueueNotEmpty0;
    unsigned int qmQueueNotEmpty1;
    unsigned int qmQueueNotEmpty2;
    unsigned int rsvdPoolPagePntr;
    unsigned int freePoolPagePntr;
    unsigned int memoryFullCount[24];
} rxQueueMgrPktStats;

typedef struct rxIntMemCtrlStats {
    unsigned int readData_0;
    unsigned int readData_1;
    unsigned int readData_2;
    unsigned int readData_3;
    unsigned int readData_4;
    unsigned int readData_5;
    unsigned int readData_6;
    unsigned int readData_7;
    unsigned int currReadAddress;
    unsigned int currWriteAddress;
} rxIntMemCtrlStats;

typedef struct rxDeqStats {
    unsigned int eOFCount;
    unsigned int pktCount[96];
} rxDeqStats;

typedef struct rxSpiStatistics {
    unsigned int minMdrrCreditCount[24];
    unsigned int maxMdrrCreditCount[24];
    /* unsigned int minMdrrCreditCount;
    unsigned int maxMdrrCreditCount; */
    unsigned int miscSPIHM;
    unsigned int ampleUsePipeEmpty;
    unsigned int sopCount;
    unsigned int eop1Count;
    unsigned int eop2Count;
    unsigned int eopACount;
    unsigned int trainingCount;
    unsigned int burstFifoUFlow;
    unsigned int outputFifoUFlow;
    unsigned int ampleUseSopCnt;
    unsigned int dip2ErrCount;
    unsigned int losStatus;
    unsigned int shdwCalendarAct;
} rxSpiStatistics;

typedef struct txMacStatistics {
    unsigned int goodByteCountMSB;
    unsigned int goodByteCountLSB;
    unsigned int errorByteCountMSB;
    unsigned int errorByteCountLSB;
    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 tooLongFrames;
    unsigned int droppedFrames;
    unsigned int fIFOUnderRun;
    unsigned int cRCErrorCountLT64;
    unsigned int cRCErrorCount;
    unsigned int cRCErrorCountGT1518;
    unsigned int cRCErrorCountGTMax;
} txMacStatistics;

typedef struct txMemMgrStats {
    /* UCAST Related Stats */
    unsigned int ucastTailDropCountReg[24];
    unsigned int ucastFifoPtrsReg[24];
    unsigned int ucastFifoNotEmptyReg;

    /* MCAST Related Stats */
    unsigned int mcastTailDropCountReg[24];
    unsigned int mcastFrmsOutCntReg[24];
    unsigned int mcastFifoPtrsReg[24];
    unsigned int mcastFifoNotEmptyReg;
    unsigned int mismatchFrameDropCntReg;
    unsigned int framesSentReg;
} txMemMgrStats;

typedef struct txCpu2LineStats {
    unsigned int fifoFull;
    unsigned int fifoEmpty;
    unsigned int tailDropPktCnt;
} txCpu2LineStats;

typedef struct txSpiStatistics {
    unsigned int addrMapMemRdData_0;
    unsigned int addrMapMemRdData_1;
    unsigned int addrMapMemRdData_2;
    unsigned int addrMapMemRdData_3;
    unsigned int oneLinePktDrop;
    unsigned int trainingCount;
    unsigned int sopCount;
    unsigned int eopCount;
    unsigned int extAbortEopCount;
    unsigned int intAbortEopCount;
    unsigned int dip4ErrCount;
    unsigned int protViolCount;
    unsigned int fifoOverFlow;
    unsigned int dPGStatus;
    unsigned int dPVByteErrCnt0;
    unsigned int dPVByteErrCnt1;
    unsigned int dPVByteErrCnt2;
    unsigned int dPVByteErrCnt3;
    unsigned int dPVByteErrCnt4;
    unsigned int dPVByteErrCnt5;
    unsigned int dPVByteErrCnt6;
    unsigned int dPVByteErrCnt7;
    unsigned int dPVGoodPktCnt;
    unsigned int dPVSyncOnCnt;
    unsigned int dPVEopCnt;
    unsigned int dPGEopCnt;
    unsigned int ampleUseDDS2;
} txSpiStatistics;

#define PORT_FLAG_NETDEV_REGISTERED		0x0001
struct npaEagleNetdev_t  {
#if defined( LINUX_OS ) && !defined( __U_BOOT__ )
	struct net_device *		netdev;		/**< linux net dev object */
	struct net_device_stats	stats;		/**< linux generic stats */
#endif
	struct npaEagleObj_t *	parent;		/**< parent eagle object - chip object */
	unsigned long			flags;		/**< internal flags */

	rxMacStatistics			rxMacStats;	/**< MAC interface statistics */
	txMacStatistics			txMacStats; /**< MAC interface statistics */
};

#define OBJ_FLAG_INTERRUPT_ALLOC		0x0001
#define OBJ_FLAG_TIMER_ALLOC			0x0002
#define OBJ_FLAG_SEM_ALLOC				0x0004
#define OBJ_FLAG_PROC_ALLOC				0x0008
struct npaEagleObj_t {
	struct npaEagleNetdev_t * eagleDev[EAGLE_DATA_PORTS];	/**< one per interface */
	unsigned long			flags;						/**< internal flags */
	unsigned long			baseAddress;				/**< base address of the eagle */
	unsigned char			sfpType[EAGLE_CONTROL_PORTS];

	txSpiStatistics			txSpiStats;
	rxSpiStatistics			rxSpiStats;

#if defined( LINUX_OS ) && !defined( __U_BOOT__ )
	struct timer_list		npa_eh_timer;				/**< eagle timer object */
	spinlock_t				devLock;					/**< chip lock */
#endif
};


int npaEgSfpVsRegWrite(struct npaEagleObj_t * eagle, int portNum, int reg, int mask, int newVal );
int npaEgSfpVsRegRead( struct npaEagleObj_t * eagle, int portNum, int reg, unsigned int *val );
int npaEgPhyRegWrite( struct npaEagleObj_t * eagle, int portNum, int reg, int mask, int newVal );
int npaEgPhyRegRead( struct npaEagleObj_t * eagle, int portNum, int reg, unsigned int *val );
int npaEgRegSet( struct npaEagleObj_t * eagleObj, int offset, uint32_t mask, uint32_t val );
int npaEgRegGet( struct npaEagleObj_t * eagleObj, int offset, int instance, uint32_t * pVal );

#if defined( LINUX_OS ) && !defined( __U_BOOT__ )
  int npaEgAddProcEntries( struct npaFunctionObj_t * pFunction );
  int npaEgRemoveProcEntries( struct npaFunctionObj_t * pFunction );
  int npaEgSetEthtoolOps( struct net_device *netdev );
#endif

#endif
