#ifdef INI_SUPPORT
/******************************************************************************/
/*                                                                            */
/*         Copyright(c) 2000-2002 by Ikanos Communications Inc.               */
/*                                                                            */
/*  All rights are reserved.  Reproduction in whole or in part is prohibited  */
/*  without the written consent of the copyright owner.                       */
/*                                                                            */
/*  The information and contents of this file are the proprietary information */
/*  of Ikanos Communication and may not be disclosed or used without the      */
/*  formal written approval of Ikanos Communication Inc.                      */
/*                                                                            */
/*  This Copyright notice may not be removed or modified without prior        */
/*  written consent of Ikanos Communications, Inc.                            */
/*                                                                            */
/******************************************************************************/
/*
**  Filename:    HostPtmfApi.c
**
**  Project:     Ikanos INI ASIC (AMUR) Software Integration
**
**  Target:      MOTOROLA XPC855T based host board
**
**  Platform specific:
**    None.
**
**  Description:
**
**  $Revision: 1.4 $
**  $Date: 2007/01/22 14:49:09 $
**
**
**  **************************************************************************** 
**  Public Functions:
**
**  **************************************************************************** 
**  Private Functions:
**
**  **************************************************************************** 
**  Modification History:
**
**    Date         By     Description
**    -----------  ---    ------------------------------------------------------
**	  Jun-16-2002  SFA    Created
**    Jul-17-2002  SFA    Integration into new host code
*/
/******************************************************************************/
/*------------------------------------------------------------------------------
  INCLUDE FILES
  ----------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>    

#include "dapi.h"
#include "apiosmacro.h"
#include "HostPtmfApi.h"
#include "HostPtmfHwRegs.h"
#include "HostEnetPhyUtils.h"

extern void oampPortStateStop( int bmeNum, int portNum);
#ifdef ALASKA
extern int webflag;
#endif
/*------------------------------------------------------------------------------
  PRIVATE PREPROCESSOR CONSTANTS
  ----------------------------------------------------------------------------*/
#define PTMF_ENET_PHY_PWR_DOWN  (0x0800)
/*------------------------------------------------------------------------------
  PRIVATE PREPROCESSOR MACROS
  ----------------------------------------------------------------------------*/
#if 0
#define PTMF_PAUSE_FRAME_SA   (01)
#define PTMF_RESUME_FRAME_CRC (3503309577)
#define PTMF_PAUSE_FRAME_CRC  (1310758184)

#else
#define PTMF_PAUSE_FRAME_SA   (02)
#define PTMF_RESUME_FRAME_CRC (2426870866UL)
#define PTMF_PAUSE_FRAME_CRC  (240634483)
#endif
/*------------------------------------------------------------------------------
  PRIVATE ENUMERATION DEFINITIONS
  ----------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
  PRIVATE TYPE DEFINITIONS
  ----------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
  PUBLIC VARIABLES DEFINITIONS
  ----------------------------------------------------------------------------*/
U8                      gbDebugLevel = 5;

static U8               s_bEnetPort = 0;
static U16              s_uiEnetPhyCtrlReg[MAX_ENET_PORTS];

int                      dropFrameEnable = 1;

tsIposPtmfCounters      tsIniCounters[MAX_ENET_PORTS];

tsIposPtmfPortConfig    tsIniPortParams[MAX_ENET_PORTS];

tsIposPtmfConfig        tsIniDefaultConfig = {

  PTMF_MDIO_ADDR,                         // Phy MDIO base address for port 0
  PTMF_MODE,                              // INI default mode = RMII
  PTMF_MAX_PORTS_PER_CHIP,                // Max. Ethernet Ports per PTMF 
  PTMF_ENET_PHY_BASE_ADDR,                // Ethernet PHY MDIO base address

  MAX_UTOPIA_PHYS,                        // Max. Utopia PHYS = 16
  IPOS_MAX_BME,                           // Max. RX ENABLE SIGNAL per BME

  UTOP_CELL_HEC_HDR,                      // ATM MODE
  UTOP_TRAFF_NO_IDLE_CELL,                // Idle cell generation OFF
  
  0x7e,                                   // HDLC Special Bytes 
  0xb7,                                   // HEC Byte (Cell byte 5)
  0xde,                                   // Non-Unity Byte (Cell byte 4)

  0,                                      // Not used for INI ASIC
  0,                                      // Not used for INI ASIC
  PTMF_MII_PORT_MAP,                      // xMII Port MAP

  FLOW_CONTROL_DUPLEX,                    // bFlowControl = ON
  DUPLEX_FULL,                            // bDuplex = FULL
  PORT_SPEED_100                          // bPortSpeed = 100Mbps
};

tsIposPtmfPortConfig      tsIniPortDefault = {

  0,                        // bPortIndex;  
  0,                        // bPtmfBaseAddr
  0,                        // bRxEnable
  0,                        // bPortAddr
  0,                        // bUtopiaPort

  FLOW_CONTROL_NONE,        // bFlowControl
  DUPLEX_FULL,              // bDuplex
  PORT_SPEED_100,           // bPortSpeed

  PTMF_PAUSE_FRAME_SA,      // bPauseFrameSrcAddr
  PTMF_PAUSE_FRAME_CRC,     // uiPauseFrameCrc
  PTMF_RESUME_FRAME_CRC,    // uiResumeFrameCrc

  FIFO_SIZE_16K,            // bTxFifoSize
  0,                        // bTxFifoAddr
  FIFO_WATERMARK_4K,        // bTxFifoLwm
  FIFO_WATERMARK_12K,       // bTxFifoHwm

  FIFO_SIZE_16K,            // bRxFifoSize
  0,                        // bRxFifoAddr
  FIFO_WATERMARK_12K,       // bRxFifoHwm

  0,                        // bTxHdlcHcf: HDLC TX Control field default
  0,                        // bTxHdlcHaf: HDLC TX Address field default

  FILTER_HDLC_CRC,          // bFilterHdlcCrc: Suppress HDLC CRC Errors = YES
  FILTER_ENET_CRC,          // bFilterEnetCrc: Suppress Ethernet CRC Errors = YES

  ENET_INVALID_LINK,        // bEnetLinkStatus: Ethernet Link = Down ; default
  0,                        // bEnetPhyAddr
  0,                        // bMiiMode
  0                         // bPtmfPortState: Port state; Not in showtime
};

/*------------------------------------------------------------------------------
  PRIVATE VARIABLES DEFINITIONS
  ----------------------------------------------------------------------------*/
#if defined(CPE_30)

static U8 s_bAtmPtmMode;

#endif //#if defined(CPE_30)
/*------------------------------------------------------------------------------
  PRIVATE FUNCTION PROTOTYPE
  ----------------------------------------------------------------------------*/
eIniRetCode
  PrIniUtopiaPollAdd (U8 bPortNumber);

eIniRetCode
  PrIniUtopiaPollRemove (U8 bPortNumber);

U32 
  PrIniMapDsl2Enet (U8 bPortNumber);

void 
  PrIniSetClock (U8 bPtmfBaseAddr);

U32
  PrIniReadDword (U8 bPortNumber, U16 uiRegAddr);

U32
  PrIniReadDword1(U8 bPortNumber, U32 uiRegAddr) ;

U32
  PrIniReadWord (U8 bPortNumber, U16 uiRegAddr);

void
  PrIniClrCounter (U8 bPortNumber);

void
  PrIniEnetPhyAutoNegotiate (U8 bEnetPortCount);

void 
  PrIniReConfigPort(U8 bEnetPortNumber);

/*------------------------------------------------------------------------------
  PUBLIC FUNCTION DEFINITIONS
  ----------------------------------------------------------------------------*/
/******************************************************************************
*                                                                             *
* Function.. : iposPtmfReset                                 	                *
*                                                   	                        *
* Purpose... : Reset PTMF setup lock.
*									                                                            *
* Parameters : None                                                           *
*                                                                             *
* Returns... : None                                                           *
*                                                                             *
******************************************************************************/

void iposPtmfReset(void)
{
  s_bEnetPort = 0;
  printf ("\nINI RESET");

}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfGetVersion                           	                *
*                                                   	                        *
* Purpose... : Reads the part number and version number from the definition   *
*              and copy it to the array as a string.                          *
*									                                                            *
* Parameters : Array Pointer                                                  *
*                                                                             *
* Returns... : None                                                           *
*                                                                             *
******************************************************************************/

void iposPtmfGetVersion(char *psVerString)
{
  char abPtmfVerRet[50];
  
	sprintf(abPtmfVerRet,"%s: Part Number: %i Version: %i", PTMF_STR,
                                                          PTMF_ASIC_PART, 
                                                          PTMF_ASIC_VERSION);
#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\n %s\n",abPtmfVerRet);
#endif //DEBUG_INI

  if (psVerString)
    strcpy(psVerString, abPtmfVerRet);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfGetVersionNumber                      	                *
*                                                   	                        *
* Purpose... : Reads the part number and version number from the definition   *
*              and returns the values in the relevent variables               *
*									                                                            *
* Parameters : Pointer to type / Part number /version number fields           *
*                                                                             *
* Returns... : eIniRetCode                                                    *
*                                                                             *
******************************************************************************/

eIniRetCode
  iposPtmfGetVersionNumber(U8 *pbType, U16 *puiPartNo, U8 *pbVerNo)
{
  
  *puiPartNo  = (U16)PTMF_ASIC_PART;
  *pbVerNo    = (U8)PTMF_ASIC_VERSION;
  *pbType     = (U8)PTMF_ASIC_TYPE;  

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfDbgLevelSet                           	                *
*                                                   	                        *
* Purpose... : Set the print debug level for the PTMF module         	        *
*									                                                            *
* Parameters : debug level (0 = Max; 5 = Min.)                                *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

void iposPtmfDbgLevelSet (U8 bDbgLevel)
{
  gbDebugLevel = bDbgLevel;
  printf ("\n SET INI MODULE DEBUG LEVEL TO %d \n", gbDebugLevel);
  return;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfSetup                                	                *
*                                                   	                        *
* Purpose... : Initialise the INI ASIC AMUR chip                    	        *
*									                                                            *
* Parameters : Pointer to global parameter structure                          *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
eIniRetCode 
  iposPtmfSetup (
    ptsIposPtmfConfig  ptsPtmfConfig)   /* Pointer to global parameter struct */
{
  U16                 uiMaxEnetPort;
  U16                 uiMiiPortMap;
  U8                  i, bPortIndex;
  U8                  bFifoSize, bLwm, bHwm;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC SETUP ");
#endif //DEBUG_INI

  /* if the config structure pointer passed is NULL, use default              */
  if (ptsPtmfConfig == NULL)
  {
    ptsPtmfConfig = &tsIniDefaultConfig;

#ifdef DEBUG_INI
    if (gbDebugLevel <= 2)
      printf("\nINI ASIC: USE DEFAULT..... ");
#endif //DEBUG_INI

  }
  
  if (s_bEnetPort)
  {
    if (ptsPtmfConfig->bIniMdioAddr == 
      tsIniPortParams[s_bEnetPort-1].bPtmfBaseAddr)
    {
      printf("\n PTMF already initialized!");
      return HOST_INI_UNDEFINED_ERROR;
    }
  }
  // Before any MDIO transaction, create a mutex to protect the MDIO bit 
  // access through multiple tasks.
  iposPtmfSemCreate ();

#ifndef BME_CPE_20
  PrIniSetClock(ptsPtmfConfig->bIniMdioAddr);
#endif

  /* Initialise the INI ASIC Chip for data traffic                            */
  iposPtmfInit(ptsPtmfConfig);

  uiMaxEnetPort = s_bEnetPort + ptsPtmfConfig->bIniMaxEnetPort;
  uiMiiPortMap = ptsPtmfConfig->uiMiiPortMap;
  bPortIndex = 0;

//  printf("\n MAX PTMF PORT = %04x ", MAX_ENET_PORTS);        

  for ( i = 0; 
        i < ptsPtmfConfig->bIniMaxEnetPort;
        i ++ )

  {
    // Check if passed Max Ethernet port number exceeds total system ports
    if (MAX_ENET_PORTS == (s_bEnetPort + i))
      return HOST_INI_MAX_ENET_PORT_ERROR;

    /* Initialise all the counters to ZERO                                    */
    PrIniClrCounter (s_bEnetPort + i);

    while(!(uiMiiPortMap & 0x01))
    {
      uiMiiPortMap = uiMiiPortMap >> 1;
      bPortIndex++;
    }

    /* Default values to the port parameters                                  */
//    tsIniPortParams[s_bEnetPort + i].bPortIndex = 
//      i * (16/ptsPtmfConfig->bIniMaxEnetPort);

    tsIniPortParams[s_bEnetPort + i].bPortIndex = bPortIndex;
      
    // MDIO base address of the PTMF chip of this port
    tsIniPortParams[s_bEnetPort + i].bPtmfBaseAddr = 
      ptsPtmfConfig->bIniMdioAddr;

    // Select RX Enable Mode = 0; i.e. use RX_EN_LINE[0] by default
    tsIniPortParams[s_bEnetPort + i].bRxEnable = 
      i /(ptsPtmfConfig->bIniMaxEnetPort / ptsPtmfConfig->bIniMaxRxEnable);

    // Port Addresses are incremental offset from MDIO base address of the PTMF
    tsIniPortParams[s_bEnetPort + i].bPortAddr = 
      ((ptsPtmfConfig->bIniMdioAddr) & PTMF_MDIO_ADDR_MASK) + i;

    // Default: Utopia PHY address = Global Ethernet Port Number
    //tsIniPortParams[s_bEnetPort + i].bUtopiaPort = s_bEnetPort + i;
    // Utopia PHY starts at zero for each new PTMF Chip.
    tsIniPortParams[s_bEnetPort + i].bUtopiaPort = i;

    tsIniPortParams[s_bEnetPort + i].bFlowControl = 
      ptsPtmfConfig->bFlowControl;
          
    tsIniPortParams[s_bEnetPort + i].bDuplex = 
      ptsPtmfConfig->bDuplex;
    
    tsIniPortParams[s_bEnetPort + i].bPortSpeed = 
      ptsPtmfConfig->bPortSpeed;
    
    tsIniPortParams[s_bEnetPort + i].bPauseFrameSrcAddr = 
      tsIniPortDefault.bPauseFrameSrcAddr;

    tsIniPortParams[s_bEnetPort + i].uiPauseFrameCrc = 
      tsIniPortDefault.uiPauseFrameCrc;

    tsIniPortParams[s_bEnetPort + i].uiResumeFrameCrc = 
      tsIniPortDefault.uiResumeFrameCrc;

    //------------------------------------------------------------------------
    switch (ptsPtmfConfig->bIniMaxEnetPort)
    {
      case 16:
        bFifoSize = FIFO_SIZE_16K;
        bLwm      = FIFO_WATERMARK_4K;
        bHwm      = FIFO_WATERMARK_12K;
        break;

      case 8:
        bFifoSize = FIFO_SIZE_32K;
        bLwm      = FIFO_WATERMARK_8K;
        bHwm      = FIFO_WATERMARK_24K;
        break;

      case 4:
        bFifoSize = FIFO_SIZE_64K;
        bLwm      = FIFO_WATERMARK_16K;
        bHwm      = FIFO_WATERMARK_48K;
        break;

      case 1:       // One port PTMF; BME_CPE_20

#if defined(CPE_30)

        bFifoSize = FIFO_SIZE_16K;
        bLwm      = FIFO_WATERMARK_4K;
        bHwm      = FIFO_WATERMARK_12K;
#else
        bFifoSize = FIFO_SIZE_32K;
        bLwm      = FIFO_WATERMARK_8K;
        bHwm      = FIFO_WATERMARK_24K;

#endif //#if defined(CPE_30)

        break;

      default:
        bFifoSize = FIFO_SIZE_16K;
        bLwm      = FIFO_WATERMARK_4K;
        bHwm      = FIFO_WATERMARK_12K;
        break;
    }
    //------------------------------------------------------------------------
    // FIFO SIZES = 16K * 16/max Enet per PTMF chip
    tsIniPortParams[s_bEnetPort + i].bTxFifoSize = bFifoSize;
    tsIniPortParams[s_bEnetPort + i].bRxFifoSize = bFifoSize;
      
    tsIniPortParams[s_bEnetPort + i].bTxFifoLwm = bLwm;
    tsIniPortParams[s_bEnetPort + i].bTxFifoHwm = bHwm;

    tsIniPortParams[s_bEnetPort + i].bRxFifoHwm = bHwm;
      
    //------------------------------------------------------------------------
    // FIFO size increments on 4K boundary - default
    tsIniPortParams[s_bEnetPort + i].bTxFifoAddr =
      ((i * (16/ptsPtmfConfig->bIniMaxEnetPort)) & 0x03) * 4;

#if !defined(BME_CPE_20)
    // FIFO size increments on 4K boundary - default
    tsIniPortParams[s_bEnetPort + i].bRxFifoAddr =
      (((i * (16/ptsPtmfConfig->bIniMaxEnetPort)) & 0x03) + 4) * 4;
#elif defined(CPE_30)
    // FIFO size increments on 4K boundary - default
    tsIniPortParams[s_bEnetPort + i].bRxFifoAddr =
      (((i * (16/ptsPtmfConfig->bIniMaxEnetPort)) & 0x03) + 4) * 1;
#elif defined(CPE_20)
    // FIFO size increments on 4K boundary - default
    tsIniPortParams[s_bEnetPort + i].bRxFifoAddr =
      (((i * (16/ptsPtmfConfig->bIniMaxEnetPort)) & 0x03) + 4) * 2;
#else
#error Please Define CPE_20 or CPE_30.
#endif
    //------------------------------------------------------------------------
    tsIniPortParams[s_bEnetPort + i].bTxHdlcHcf = 
      tsIniPortDefault.bTxHdlcHcf;

    tsIniPortParams[s_bEnetPort + i].bTxHdlcHaf = 
      tsIniPortDefault.bTxHdlcHaf;

    tsIniPortParams[s_bEnetPort + i].bFilterHdlcCrc = 
      tsIniPortDefault.bFilterHdlcCrc;

    tsIniPortParams[s_bEnetPort + i].bFilterEnetCrc = 
      tsIniPortDefault.bFilterEnetCrc;

    tsIniPortParams[s_bEnetPort + i].bEnetLinkStatus = 
      tsIniPortDefault.bEnetLinkStatus;

    tsIniPortParams[s_bEnetPort + i].bEnetPhyAddr = 
      ptsPtmfConfig->bEnetPhyAddr + i;

    tsIniPortParams[s_bEnetPort + i].bMiiMode = 
      ptsPtmfConfig->bIniMode;

    // Default to all ports not in show-time.
    tsIniPortParams[s_bEnetPort + i].bPtmfPortState = 
      PORT_NOT_SHOWTIME;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 4)
    printf("\n PTMF PORT = %04x ", s_bEnetPort + i);        

  if (gbDebugLevel <= 3)
    {
//      printf("\n PTMF PORT = %04x ", s_bEnetPort + i);        
      iposPtmfPrintPortStruct(s_bEnetPort + i);
    }
#endif //DEBUG_INI
    bPortIndex++;
    uiMiiPortMap = uiMiiPortMap >> 1;
  }
  // First port index of the next PTMF chip 
  s_bEnetPort = s_bEnetPort + i;

#if defined(CPE_HOSTLESS)
  // Reset the Ethernet PHY, if PTMF is in MAC mode and if external PHY present.
  if (ptsPtmfConfig->bIniMode & PTMF_PHY_MAC_MODE )
    iposEnetPhyHwReset();  
#endif //defined(CPE_HOSTLESS)

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfInit                               	                  *
*                                                   	                        *
* Purpose... : Initialise the PTM Framer chip, Configure the global modes     *
*									                                                            *
* Parameters : Pointer to global parameter structure                          *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode 
  iposPtmfInit (
    ptsIposPtmfConfig  ptsPtmfConfig)   /* Pointer to global parameter struct */
{
#if !defined(CPE_30)

  U16                uiRegValue;

  tsHostIniMdioAddrData tsIniReg;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC INIT ");
#endif //DEBUG_INI

  // Set INI ASIC MDIO base address 
  tsIniReg.bIniBaseAddr = ptsPtmfConfig->bIniMdioAddr;
//  iposPtmfMdioSetBaseAddr ((BYTE)tsIniConfig.uiIniMdioAddr);

  // Global Utopia Enable and Multiple RX Enable mode ON
  uiRegValue = UTOP_ENABLE | RX_ENABLE_MODE;               

  if (ptsPtmfConfig->bUtopiaCellMode == UTOP_CELL_ALL_DATA )
    uiRegValue &= 0xfff9;
  else
    uiRegValue |= 0x0002;

  if (ptsPtmfConfig->bUtopiaTrafficMode == UTOP_TRAFF_NO_IDLE_CELL )
    uiRegValue &= 0xffe7;
  else
    uiRegValue |= 0x0008;

  // Utopia Configuration Regiter0 - Global
  tsIniReg.uiIniRegAddr   = UCR0;
  tsIniReg.uiIniRdWrData  = uiRegValue;
  
  iposPtmfMdioWrite ( &tsIniReg );

  // Utopia HDLC Special Bytes Register 0 - Global
  tsIniReg.uiIniRegAddr   = HSBR0;
  tsIniReg.uiIniRdWrData  = ptsPtmfConfig->bHdlcSpecialBytes;
  
  iposPtmfMdioWrite ( &tsIniReg );

  // Utopia Configuration Regiter 1 - Global
  uiRegValue = ptsPtmfConfig->bAtmCellHecByte;
  uiRegValue <<= 8;
  uiRegValue |= ptsPtmfConfig->bAtmCellNonUnityHeaderByte;

  tsIniReg.uiIniRegAddr   = UCR1;
  tsIniReg.uiIniRdWrData  = uiRegValue;
  
  iposPtmfMdioWrite ( &tsIniReg );

  // Utopia Phys Active Register - Global
  tsIniReg.uiIniRegAddr   = UPAR;
  tsIniReg.uiIniRdWrData  = 0;    // ZERO UTOPIA PHYS ACTIVE ON STARTUP
  iposPtmfMdioWrite ( &tsIniReg);

#else

  s_bAtmPtmMode = ptsPtmfConfig->bUtopiaCellMode;

#endif //#if defined(CPE_30)

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStartTx                              	                *
*                                                   	                        *
* Purpose... : Activate an Ethernet ->  UTOPIA Path on the INI ASIC  	        *
*									                                                            *
* Parameters : bEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
eIniRetCode iposPtmfStartTx (U8 bEnetPortNumber, 
                             ptsIposPtmfPortConfig ptsPtmfPortConfig)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiMdioRegValue;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC START TX   #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // SFA 08/08
  // Cause a delay of approx 1 sec before activating the TX path.
 	iposTaskDelay(480);

  if (ptsPtmfPortConfig)
  {
    memcpy (&tsIniPortParams[bEnetPortNumber], 
            ptsPtmfPortConfig,
            sizeof(tsIposPtmfPortConfig));
  }

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // If Base Address is the same as port address than it's the first port of 
  // the chip. OR
  // If port Index = 0;
#ifndef CO_30
  if (tsIniPortParams[bEnetPortNumber].bPortIndex ) 
  {
    // Phy Address Set and Enable Phy register
    tsIniReg.uiIniRegAddr   = PHY1_ADD + 
                              tsIniPortParams[bEnetPortNumber].bPortIndex - 1;
    iposPtmfMdioRead ( &tsIniReg);

    if (tsIniReg.uiIniRdWrData & 0x0020)
    {
      //Port is already enabled.....
      tsIniPortParams[bEnetPortNumber].bPortAddr = 
        tsIniReg.uiIniRdWrData & 0x001f;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf ("\n Port Already Enabled!!!");
#endif //DEBUG_INI
    }
    else
    {
      // Enable addressing of the port and give it an address to access the 
      // MDIO registers.
      tsIniReg.uiIniRdWrData  = 
        tsIniPortParams[bEnetPortNumber].bPortAddr | 0x20;

      iposPtmfMdioWrite ( &tsIniReg);
    }
  }
#endif //CO_30
  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  // Tx_Fifo Config register 1
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bTxFifoLwm;
  uiMdioRegValue <<= 7;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bTxFifoHwm;
  uiMdioRegValue <<= 2;
  uiMdioRegValue &= 0xfffc;
  
  tsIniReg.uiIniRegAddr   = TFCR1;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Tx HDLC Address/Control Field Register
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bTxHdlcHcf;
  uiMdioRegValue <<= 8;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bTxHdlcHaf;

  tsIniReg.uiIniRegAddr   = THAFR;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Tx_Fifo Config register 0
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bTxFifoSize;
  uiMdioRegValue <<= 5;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bTxFifoAddr;
  uiMdioRegValue <<= 1;
  uiMdioRegValue |= 0x01;

  tsIniReg.uiIniRegAddr   = TFCR0;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  /* Port Start TX indicates port is in showtime.                             */
  tsIniPortParams[bEnetPortNumber].bPtmfPortState |= PORT_START_TX;

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStartRx                               	                *
*                                                   	                        *
* Purpose... : Activate the UTOPIA -> Ethernet Path on the INI ASIC  	        *
*									                                                            *
* Parameters : bEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode iposPtmfStartRx (U8 bEnetPortNumber,
                             ptsIposPtmfPortConfig ptsPtmfPortConfig)
{
  tsHostIniMdioAddrData   tsIniReg;
  tsHostIniMdioAddrData1   tsIniReg1;
  U16                     uiMdioRegValue;
  U32                     uiPauseCrc;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC START RX #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // SFA 08/08
  PrIniClrCounter (bEnetPortNumber);

  if (ptsPtmfPortConfig)
  {
    memcpy (&tsIniPortParams[bEnetPortNumber], 
            ptsPtmfPortConfig,
            sizeof(tsIposPtmfPortConfig));
  }

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // If Base Address is the same as port address than it's the first port of 
  // the chip. OR
  // If port Index = 0;
  if (tsIniPortParams[bEnetPortNumber].bPortIndex ) 
  {
    // Phy Address Set and Enable Phy register
    tsIniReg.uiIniRegAddr   = PHY1_ADD + 
                              tsIniPortParams[bEnetPortNumber].bPortIndex - 1;
    iposPtmfMdioRead ( &tsIniReg);

    if (tsIniReg.uiIniRdWrData & 0x0020)
    {
      //Port is already enabled.....
      tsIniPortParams[bEnetPortNumber].bPortAddr = 
        tsIniReg.uiIniRdWrData & 0x001f;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf ("\n Port Already Enabled!!!");
#endif //DEBUG_INI
    }
    else
    {
      // Enable addressing of the port and give it an address to access the 
      // MDIO registers.
      tsIniReg.uiIniRdWrData  = 
        tsIniPortParams[bEnetPortNumber].bPortAddr | 0x20;

      iposPtmfMdioWrite ( &tsIniReg);
    }
  }
  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  // Do a software reset to the port. This initialises the port state machine,
  // clears all the port counter and FIFO pointers and sets the port registers
  // to their default values.
  iposPtmfResetPort (tsIniReg.bIniBaseAddr, tsIniReg.uiIniPhyAddr);
  
  // Add the port to the utopia polling sequence
  PrIniUtopiaPollAdd (bEnetPortNumber);

  // Port Start RX 
  tsIniPortParams[bEnetPortNumber].bPtmfPortState |= PORT_START_RX;

  // PORT ENABLE = 1; Half Duplex retry limit = 16 times.
  uiMdioRegValue = 0x7801;
      
  // PORT SPEED 100/10
  if (tsIniPortParams[bEnetPortNumber].bPortSpeed == PORT_SPEED_100)
    uiMdioRegValue |= 0x0002;
  else if (tsIniPortParams[bEnetPortNumber].bPortSpeed == PORT_SPEED_10)
    uiMdioRegValue &= ~(0x0006);
  else
    uiMdioRegValue |= 0x0004 ;
      
  // DUPLEX = HALF or FULL
  if (tsIniPortParams[bEnetPortNumber].bDuplex == DUPLEX_HALF)
    uiMdioRegValue |= 0x0020;
  else
    uiMdioRegValue &= ~(0x0020);//full-dplx

  if (tsIniPortParams[bEnetPortNumber].bMiiMode & PTMF_XMII_LOOPBACK)
  {
    uiMdioRegValue |= 0x0080;   // xMII Loop-back mode : set bit[7] of XPCR reg
  }

  // FLOW CONTROL = NO FLOW  or FULL DUPLEX
  if (tsIniPortParams[bEnetPortNumber].bFlowControl & FULL_DUPLEX_FLOW) 
    uiMdioRegValue |= 0x0048; //set SUP_PAUSE_FRM
  else
    uiMdioRegValue &= ~(0x0048); //half-dplx flow ctrl

#if defined(CPE_30)

  if (s_bAtmPtmMode == UTOP_CELL_ALL_DATA)
    uiMdioRegValue &= 0x7fff;
  else
    uiMdioRegValue |= 0x8000;

#endif //#if defined(CPE_30)

  // xMII port configuration reg
  tsIniReg.uiIniRegAddr   = XPCR;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  printf ("\n XPCR :%04x", tsIniReg.uiIniRdWrData) ;  
  iposPtmfMdioWrite ( &tsIniReg);

   // Enable flow control on Pause Queue Register 
   if ((tsIniPortParams[bEnetPortNumber].bFlowControl & FULL_DUPLEX_FLOW) ||
      (tsIniPortParams[bEnetPortNumber].bFlowControl & HALF_DUPLEX_FLOW)) {

      tsIniReg1.uiIniRegAddr = EIU_PQER ;
      iposPtmfMdioRead1 (&tsIniReg1) ;
      tsIniReg1.uiIniRdWrData |= 0x00000010 ; //Flow control enabled for queue0
      printf ("\n PQER :%08x", tsIniReg1.uiIniRdWrData) ;
      iposPtmfMdioWrite1 (&tsIniReg1);
   }
  
  // Suppress HDLC CRC Errors ?
  tsIniReg1.uiIniRegAddr   = RX_SLB_CTRL_REG;
  if (tsIniPortParams[bEnetPortNumber].bFilterHdlcCrc == FILTER_HDLC_CRC ) 
      tsIniReg1.uiIniRdWrData |= 0x4; //set DRP_CRC_ERR (bit-2)
  else 
      tsIniReg1.uiIniRdWrData &= ~(0x4); //clear DRP_CRC_ERR (bit-2)

  iposPtmfMdioWrite1 (&tsIniReg1);

  // Suppress ENET CRC Errors ?
  if (tsIniPortParams[bEnetPortNumber].bFilterEnetCrc == FILTER_ENET_CRC)
    uiMdioRegValue |= 0x0002;
  else
    uiMdioRegValue &= 0xfffd;


#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf ("\n DBGR = %0x",uiMdioRegValue);
#endif //DEBUG_INI

  // Ikanos debug features reg 
  tsIniReg.uiIniRegAddr   = DBGR;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  //47-40 BITS OF SA REG
  tsIniReg1.uiIniRegAddr   = EIU_PFSARLO ;
  tsIniReg1.uiIniRdWrData  = tsIniPortParams[bEnetPortNumber].bPauseFrameSrcAddr ;
  iposPtmfMdioWrite1 ( &tsIniReg1);

  // PF CRC [31: 0]
  tsIniReg1.uiIniRegAddr   = EIU_PFCRCQ0 ;
  tsIniReg1.uiIniRdWrData  = tsIniPortParams[bEnetPortNumber].uiPauseFrameCrc ;
  iposPtmfMdioWrite1 ( &tsIniReg1);

  // RF CRC [31: 0]
  tsIniReg1.uiIniRegAddr   = EIU_RFCRCQ0;
  tsIniReg1.uiIniRdWrData  = tsIniPortParams[bEnetPortNumber].uiResumeFrameCrc ;
  iposPtmfMdioWrite1 ( &tsIniReg1);



  if (tsIniPortParams[bEnetPortNumber].bMiiMode & PTMF_PHY_MAC_MODE )
  {
    // Check for activity on the Enet LINK. Auto-negotiate only in MAC mode
    PrIniEnetPhyAutoNegotiate(bEnetPortNumber);  
  }
  else
  {
    // Link is NOW UP
    tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_VALID_LINK;
  
    //This is a special condition for Back to Back MAC.
    //so that pause frames can be generated in this mode
    //when Fixed Mode and Flow control is Full Duplex
    
    //Check if Autonegotiation disable
    if ((tsIniPortParams[bEnetPortNumber].bMiiMode & 0x0f) != 2)
    {
      // xMII port configuration reg
      tsIniReg.uiIniRegAddr   = XPCR;
      iposPtmfMdioRead ( &tsIniReg);
      printf("\nPHY Mode + AutoNegotiation Disable\n");

      if (tsIniPortParams[bEnetPortNumber].bFlowControl & FULL_DUPLEX_FLOW)
      {
          printf(" Full Duplex Flow Control(B-to-B)\n");
        // Set the Full Duplex Flow Control
          tsIniReg.uiIniRdWrData &= ~(0x0048);
          tsIniReg.uiIniRdWrData |= 0x0048;
      }
      else
      {
       // No Flow Control 
          printf("No Flow Control\n");
          tsIniReg.uiIniRdWrData &= ~(0x0048);
      }
      
      iposPtmfMdioWrite ( &tsIniReg);
      
    }
  }

  // Rx_Fifo Config register 1
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bRxFifoHwm;
  uiMdioRegValue <<= 2;
  uiMdioRegValue &= 0x1fc;

  tsIniReg.uiIniRegAddr   = RFCR1;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Rx_Fifo Config register 0
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bRxFifoSize;
  uiMdioRegValue <<= 5;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bRxFifoAddr;
  uiMdioRegValue <<= 1;
  uiMdioRegValue |= 0x01;

  tsIniReg.uiIniRegAddr   = RFCR0;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStopTx                               	                *
*                                                   	                        *
* Purpose... : De-activate the Ethernet -> UTOPIA Path on the INI ASIC        *
*									                                                            *
* Parameters : bEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode iposPtmfStopTx (U8 bEnetPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC STOP TX   #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  /* Port Stop TX indicates port is being stopped                            */
  tsIniPortParams[bEnetPortNumber].bPtmfPortState &= ~PORT_START_TX;

  // PORT DISABLE = 0
  // xMII port configuration reg
  tsIniReg.uiIniRegAddr   = XPCR;
  tsIniReg.uiIniRdWrData  = 0;
  iposPtmfMdioWrite ( &tsIniReg);

  // Link is DOWN
//  tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_INVALID_LINK;

  // Tx_Fifo Config register 0
  tsIniReg.uiIniRegAddr   = TFCR0;
  tsIniReg.uiIniRdWrData  = 0;
  iposPtmfMdioWrite ( &tsIniReg);


  /* Port Stop TX indicates port is being stopped                            */
//  tsIniPortParams[bEnetPortNumber].bPtmfPortState &= ~PORT_START_TX;

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStopRx                               	                *
*                                                   	                        *
* Purpose... : De-activate the Utopia -> Ethernet Path on the INI ASIC        *
*									                                                            *
* Parameters : uiEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode iposPtmfStopRx (U8 bEnetPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;

#ifdef TRUE_POLLING
  U8                      i=4;
#endif

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC STOP RX #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

#ifdef TRUE_POLLING

  // Remove the port from the utopia polling sequence
  PrIniUtopiaPollRemove (bEnetPortNumber);

  // Rx_Fifo Config register 0
  tsIniReg.uiIniRegAddr   = RFCR0;
  tsIniReg.uiIniRdWrData  = 0;
  iposPtmfMdioWrite ( &tsIniReg);

#endif //TRUE_POLLING

  // Initialise all the counters to ZERO                                      
  PrIniClrCounter (bEnetPortNumber);


  /* Port Stop RX indicates port is being stopped                            */
  tsIniPortParams[bEnetPortNumber].bPtmfPortState &= ~(PORT_START_RX |
                                                       PORT_AUTO_NEGO_OVER);

  // Link is DOWN
  tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_INVALID_LINK;

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfReadPortConfig                        	                *
*                                                   	                        *
* Purpose... : Read the configuration of the passed port.           	        *
*									                                                            *
* Parameters : PortNumber	& pointer to the port config structure              *
*                                                                             *
* Returns... : Success or failure                                             *
*                                                                             *
******************************************************************************/
eIniRetCode 
  iposPtmfReadPortConfig (U8 bEnetPortNumber, 
                          ptsIposPtmfPortConfig ptsPtmfPortConfig)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC READ PORT CONFIG #%d ",bEnetPortNumber );
#endif //DEBUG_INI


  if (ptsPtmfPortConfig)
  {

//    bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);
    memcpy (ptsPtmfPortConfig, 
            &tsIniPortParams[bEnetPortNumber], 
            sizeof(tsIposPtmfPortConfig));

    return HOST_INI_NO_ERROR;
  }
  else
    return HOST_INI_UNDEFINED_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfWritePortConfig                        	              *
*                                                   	                        *
* Purpose... : Write the configuration to the passed port.           	        *
*									                                                            *
* Parameters : PortNumber	& pointer to the port config structure              *
*                                                                             *
* Returns... : Success or failure                                             *
*                                                                             *
******************************************************************************/
eIniRetCode 
  iposPtmfWritePortConfig (U8 bEnetPortNumber, 
                          ptsIposPtmfPortConfig ptsPtmfPortConfig)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC WRITE PORT CONFIG #%d ",bEnetPortNumber );
#endif //DEBUG_INI


  if (ptsPtmfPortConfig)
  {

//    bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);
    memcpy (&tsIniPortParams[bEnetPortNumber], 
            ptsPtmfPortConfig,
            sizeof(tsIposPtmfPortConfig));

    return HOST_INI_NO_ERROR;
  }
  else
    return HOST_INI_UNDEFINED_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfReadCounters                          	                *
*                                                   	                        *
* Purpose... : Task                    	                                      *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

void iposPtmfReadCounters(U8 bEnetPortCount)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 1)
    printf("\nRead Counter for port #%d",bEnetPortCount);
#endif //DEBUG_INI

  // Ethernet TX frame counter
  tsIniCounters[bEnetPortCount].uiEnetTxFrameCount += 
    PrIniReadDword1 (bEnetPortCount, EIU_TXFCR0);

  // Ethernet RX Frame Counter
  tsIniCounters[bEnetPortCount].uiEnetRxFrameCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_RXFCR0);

  // Ethernet Dropped Frame Counter ; for CPE5 packets are dropped in SLB (10bits-27:18)
  tsIniCounters[bEnetPortCount].uiEnetDropFrameCount +=
    (PrIniReadDword1 (bEnetPortCount, TX_SLB_QUEUE_USE_REG) >> 18) & 0x3FF;

  // Octet Transmitted Counter
  tsIniCounters[bEnetPortCount].uiEnetOctXmitCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_OTCR0);
  
  // Allingment Error Counter
  tsIniCounters[bEnetPortCount].uiAllignErrorCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_AECR0);

  // Long Frame Counter
  tsIniCounters[bEnetPortCount].uiLongFrameCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_FTLCR0);

  // RX (undersize/too short frames) Error Counter
  tsIniCounters[bEnetPortCount].uiRxErrorCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_FTSCR0);
  
  // Ethernet CRC Error Counter
  tsIniCounters[bEnetPortCount].uiEnetCrcErrorCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_CECR0);
  
  // Carrier Sense Errror Counter
  tsIniCounters[bEnetPortCount].uiCarrierSenseErrorCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_CSER0);

  // Broadcast Frame Counter
  tsIniCounters[bEnetPortCount].uiBroadCastFrameCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_BFCR0);

  // TX pause Frame Counter
  tsIniCounters[bEnetPortCount].uiTxPauseFrameCount += 
    PrIniReadDword1 (bEnetPortCount, EIU_TPFCR);

  // RX Pause Frame Counter
  tsIniCounters[bEnetPortCount].uiRxPauseFrameCount += 
    PrIniReadDword1 (bEnetPortCount, EIU_PFCTR);

  // Octet Received Counter
  tsIniCounters[bEnetPortCount].uiEnetOctRcvCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_ORCR0);

  // RX HDLC Error Frame Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcErrorFrameCount +=
  PrIniReadDword1 (bEnetPortCount, RX_HDE_CRC_ERR_CNT_REG) ;
  // RX HDLC Invalid Frame Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcInvalidFrameCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_CECR0);

  // RX HDLC Dropped Frame Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcDropFrameCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_RHDCR0);

  // HD Late Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_HLCCR0);

  // HD Excess Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdecCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_HECCR0);

  // HD Single Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdscCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_HSCCR0);

  // HD Multi-Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdmcCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_HMCCR0);

  // HD Def Trans Counter
  tsIniCounters[bEnetPortCount].uiRxHdDefTransCount +=
    PrIniReadDword1 (bEnetPortCount, EIU_HDTCR0);

  if (tsIniPortParams[bEnetPortCount].bMiiMode & PTMF_PHY_MAC_MODE )
  {
    //---------------------------------------------------------------------
    // Check for activity on the Enet LINK. Auto-negotiate only in MAC mode
    PrIniEnetPhyAutoNegotiate (bEnetPortCount);
    //---------------------------------------------------------------------
  }
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfPrintCounters                        	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
void 
  iposPtmfPrintCounters(U8 bEnetPortNumber)
{
#ifdef ALASKA
 int i;
    FILE *vdslout;

    vdslout = fopen("/tmp/vdslcmd.out","a+");
    if(vdslout == NULL)
    {
	perror("iposPtmfPrintCounters(): cannot open /tmp/vdslcmd.out in a+ mode");
	return;
    }

    fprintf(vdslout,"\n=========== INI Performance Counters for Port #%2d =============",
            bEnetPortNumber + 1);
    
    fprintf(vdslout,"\n-------------------- ETHERNET RECEIVE -------------------------");

    fprintf(vdslout,"\n Frames...........: %10lu   Bytes............: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetTxFrameCount,
            tsIniCounters[bEnetPortNumber].uiEnetOctXmitCount );

    fprintf(vdslout,"\n Pause Frames.....: %10lu   Broadcast Frames.: %10lu", 
            tsIniCounters[bEnetPortNumber].uiTxPauseFrameCount,
            tsIniCounters[bEnetPortNumber].uiBroadCastFrameCount );

    fprintf(vdslout,"\n Dropped Frames...: %10lu   Alignment Errors.: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetDropFrameCount,
            tsIniCounters[bEnetPortNumber].uiAllignErrorCount );

    fprintf(vdslout,"\n Oversize.........: %10lu   Undersize........: %10lu", 
            tsIniCounters[bEnetPortNumber].uiLongFrameCount,
            tsIniCounters[bEnetPortNumber].uiRxErrorCount );

    fprintf(vdslout,"\n CRC Errors.......: %10lu   Carrier Sense Err: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetCrcErrorCount,
            tsIniCounters[bEnetPortNumber].uiCarrierSenseErrorCount );

    fprintf(vdslout,"\n-------------------- ETHERNET TRANSMIT-------------------------");

    fprintf(vdslout,"\n Frames...........: %10lu   Bytes............: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetRxFrameCount,
            tsIniCounters[bEnetPortNumber].uiEnetOctRcvCount );

    fprintf(vdslout,"\n Pause Frames.....: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxPauseFrameCount );

    
    fprintf(vdslout,"\n-------------------- ETHERNET HALF DUPLEX ---------------------");

    fprintf(vdslout,"\n Late Collisions..: %10lu   Excess Collisions: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcCount,
            tsIniCounters[bEnetPortNumber].uiRxHdecCount );

    fprintf(vdslout,"\n Single Collisions: %10lu   Multi Collisions.: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdscCount,
            tsIniCounters[bEnetPortNumber].uiRxHdmcCount );

    fprintf(vdslout,"\n Deferred Trans...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdDefTransCount );
    
    fprintf(vdslout,"\n------------------------- H.D.L.C.-----------------------------");
    
    fprintf(vdslout,"\n CRC Errors.......: %10lu   Invalid Frames...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcErrorFrameCount,
            tsIniCounters[bEnetPortNumber].uiRxHdlcInvalidFrameCount );

    fprintf(vdslout,"\n Dropped Frames...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcDropFrameCount );

    fprintf(vdslout,"\n===============================================================");
    if(!webflag)
    {
	fflush(vdslout);
	rewind(vdslout);
        while((i=fgetc(vdslout))!=EOF)
          printf("%c",i);
    }
    fclose(vdslout);
#else
    printf("\n=========== INI Performance Counters for Port #%2d =============",
            bEnetPortNumber + 1);
    
    printf("\n-------------------- ETHERNET RECEIVE -------------------------");

    printf("\n Frames...........: %10lu   Bytes............: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetTxFrameCount,
            tsIniCounters[bEnetPortNumber].uiEnetOctXmitCount );

    printf("\n Pause Frames.....: %10lu   Broadcast Frames.: %10lu", 
            tsIniCounters[bEnetPortNumber].uiTxPauseFrameCount,
            tsIniCounters[bEnetPortNumber].uiBroadCastFrameCount );

    printf("\n Dropped Frames...: %10lu   Alignment Errors.: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetDropFrameCount,
            tsIniCounters[bEnetPortNumber].uiAllignErrorCount );

    printf("\n Oversize.........: %10lu   Undersize........: %10lu", 
            tsIniCounters[bEnetPortNumber].uiLongFrameCount,
            tsIniCounters[bEnetPortNumber].uiRxErrorCount );

    printf("\n CRC Errors.......: %10lu   Carrier Sense Err: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetCrcErrorCount,
            tsIniCounters[bEnetPortNumber].uiCarrierSenseErrorCount );

    printf("\n-------------------- ETHERNET TRANSMIT-------------------------");

    printf("\n Frames...........: %10lu   Bytes............: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetRxFrameCount,
            tsIniCounters[bEnetPortNumber].uiEnetOctRcvCount );

    printf("\n Pause Frames.....: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxPauseFrameCount );

    
    printf("\n-------------------- ETHERNET HALF DUPLEX ---------------------");

    printf("\n Late Collisions..: %10lu   Excess Collisions: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcCount,
            tsIniCounters[bEnetPortNumber].uiRxHdecCount );

    printf("\n Single Collisions: %10lu   Multi Collisions.: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdscCount,
            tsIniCounters[bEnetPortNumber].uiRxHdmcCount );

    printf("\n Deferred Trans...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdDefTransCount );
    
    printf("\n------------------------- H.D.L.C.-----------------------------");
    
    printf("\n CRC Errors.......: %10lu   Invalid Frames...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcErrorFrameCount,
            tsIniCounters[bEnetPortNumber].uiRxHdlcInvalidFrameCount );

    printf("\n Dropped Frames...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcDropFrameCount );

    printf("\n===============================================================");
#endif
    printf("\n");
   
}

/******************************************************************************
*                                                                             *
* Function.. : dbgPtmfPortCounters                       	   	                *
*                                                   	                        *
* Purpose... : Read and display all the  counters of the passed port number   *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : NONE                                                           *
*                                                                             *
******************************************************************************/
eIniRetCode
  dbgPtmfPortCounters (U8 bEnetPortNumber)             
{
  tsHostIniMdioAddrData tsIniReg;

  bEnetPortNumber &= 0x0f;
/*
  if (bEnetPortNumber)
  {
    // Phy Address Set and Enable Phy register
    tsIniReg.uiIniRegAddr   = PHY1_ADD + bEnetPortNumber - 1;
    iposPtmfMdioRead ( &tsIniReg);

    if (tsIniReg.uiIniRdWrData & 0x0020)
    {
      //Port is already enabled.....
      tsIniPortParams[bEnetPortNumber].bPortAddr = 
        tsIniReg.uiIniRdWrData & 0x001f;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf ("\n Port Already Enabled!!!");
#endif //DEBUG_INI
    }
    else
    {
      // Enable addressing of the port and give it an address to access the 
      // MDIO registers.
      tsIniReg.uiIniRdWrData  = 
        tsIniPortParams[bEnetPortNumber].bPortAddr | 0x20;

      iposPtmfMdioWrite ( &tsIniReg);
    }
  }
*/
  // Set the base address in the structure to be passed to the driver 
  // function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;
  //***************************************************************************
  printf("\n=========== INI Performance Counters for Port #%2d =============",
          bEnetPortNumber + 1);
  
  printf("\n-------------------- ETHERNET RECEIVE -------------------------");

  printf("\n Frames...........: %10lu   Bytes............: %10lu", 
          PrIniReadDword (bEnetPortNumber, TXFCR0),
          PrIniReadDword (bEnetPortNumber, OTCR0));

  printf("\n Pause Frames.....: %10lu   Broadcast Frames.: %10lu", 
          PrIniReadWord (bEnetPortNumber, TPFCR),
          PrIniReadDword (bEnetPortNumber, BFCR0));

  printf("\n Dropped Frames...: %10lu   Alignment Errors.: %10lu", 
          PrIniReadDword (bEnetPortNumber, EDFR0),
          PrIniReadDword (bEnetPortNumber, AECR0));

  printf("\n Oversize.........: %10lu   Undersize........: %10lu", 
          PrIniReadDword (bEnetPortNumber, FTLCR0),
          PrIniReadDword (bEnetPortNumber, RECR0));

  printf("\n CRC Errors.......: %10lu   Carrier Sense Err: %10lu", 
          PrIniReadDword (bEnetPortNumber, CECR0),
          PrIniReadDword (bEnetPortNumber, CSER0));

  printf("\n-------------------- ETHERNET TRANSMIT-------------------------");

  printf("\n Frames...........: %10lu   Bytes............: %10lu", 
          PrIniReadDword (bEnetPortNumber, RXFCR0),
          PrIniReadDword (bEnetPortNumber, ORCR0));

  printf("\n Pause Frames.....: %10lu",
          PrIniReadWord (bEnetPortNumber, PFCTR));
  
  printf("\n-------------------- ETHERNET HALF DUPLEX ---------------------");

  printf("\n Late Collisions..: %10lu   Excess Collisions: %10lu",
          PrIniReadDword (bEnetPortNumber, HLCCR0),
          PrIniReadDword (bEnetPortNumber, HECCR0));

  printf("\n Single Collisions: %10lu   Multi Collisions.: %10lu",
          PrIniReadDword (bEnetPortNumber, HSCCR0),
          PrIniReadDword (bEnetPortNumber, HMCCR0));

  printf("\n Deferred Trans...: %10lu",
          PrIniReadDword (bEnetPortNumber, HDTCR0));
  
  printf("\n------------------------- H.D.L.C.-----------------------------");
  
  printf("\n CRC Errors.......: %10lu   Invalid Frames...: %10lu",
          PrIniReadDword (bEnetPortNumber, RHECR0),
          PrIniReadDword (bEnetPortNumber, CECR0));

  printf("\n Dropped Frames...: %10lu",
          PrIniReadDword (bEnetPortNumber, RHDCR0));

  printf("\n===============================================================\n");

  return HOST_INI_NO_ERROR;
}
/******************************************************************************
*                                                                             *
* Function.. : iposPtmfPrintPortStruct                         	              *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : Nothing                                                        *
*                                                                             *
******************************************************************************/
void 
  iposPtmfPrintPortStruct(U8 bEnetPortNumber)
{
  if (bEnetPortNumber >= MAX_ENET_PORTS)
  {
    printf("\nInvalid Port Number \n");  
    return;
  }
  printf("\n tsIniPortParams[%02d] ", bEnetPortNumber);
  printf("\n  |--bPortIndex................0x%02x ",tsIniPortParams[bEnetPortNumber].bPortIndex);
  printf("\n  |--bPtmfBaseAddr.............0x%02x ",tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr);
  printf("\n  |--bRxEnable.................0x%02x ",tsIniPortParams[bEnetPortNumber].bRxEnable);
  printf("\n  |--bPortAddr.................0x%02x ",tsIniPortParams[bEnetPortNumber].bPortAddr);
  printf("\n  |--bUtopiaPort...............0x%02x ",tsIniPortParams[bEnetPortNumber].bUtopiaPort);
  printf("\n  |--bFlowControl..............0x%02x ",tsIniPortParams[bEnetPortNumber].bFlowControl);
  printf("\n  |--bDuplex...................0x%02x ",tsIniPortParams[bEnetPortNumber].bDuplex);
  printf("\n  |--bPortSpeed................0x%02x ",tsIniPortParams[bEnetPortNumber].bPortSpeed);
  printf("\n  |--bPauseFrameSrcAddr........0x%02x ",tsIniPortParams[bEnetPortNumber].bPauseFrameSrcAddr);
  printf("\n  |--uiPauseFrameCrc.....0x%08x ",(unsigned int)tsIniPortParams[bEnetPortNumber].uiPauseFrameCrc);
  printf("\n  |--uiResumeFrameCrc....0x%08x ",(unsigned int)tsIniPortParams[bEnetPortNumber].uiResumeFrameCrc);
  printf("\n  |--bTxFifoSize...............0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoSize);
  printf("\n  |--bTxFifoAddr...............0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoAddr);
  printf("\n  |--bTxFifoLwm................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoLwm);
  printf("\n  |--bTxFifoHwm................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoHwm);
  printf("\n  |--bRxFifoSize...............0x%02x ",tsIniPortParams[bEnetPortNumber].bRxFifoSize);
  printf("\n  |--bRxFifoAddr...............0x%02x ",tsIniPortParams[bEnetPortNumber].bRxFifoAddr);
  printf("\n  |--bRxFifoHwm................0x%02x ",tsIniPortParams[bEnetPortNumber].bRxFifoHwm);
  printf("\n  |--bTxHdlcHcf................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxHdlcHcf);
  printf("\n  |--bTxHdlcHaf................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxHdlcHaf);
  printf("\n  |--bFilterHdlcCrc............0x%02x ",tsIniPortParams[bEnetPortNumber].bFilterHdlcCrc);
  printf("\n  |--bFilterEnetCrc............0x%02x ",tsIniPortParams[bEnetPortNumber].bFilterEnetCrc);
  printf("\n  |--bEnetLinkStatus...........0x%02x ",tsIniPortParams[bEnetPortNumber].bEnetLinkStatus);
  printf("\n  |--bEnetPhyAddr..............0x%02x ",tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);
  printf("\n  |--bMiiMode..................0x%02x ",tsIniPortParams[bEnetPortNumber].bMiiMode);
  printf("\n  `--bPtmfPortState............0x%02x \n",tsIniPortParams[bEnetPortNumber].bPtmfPortState);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxFrames                         	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/

U32 
  iposPtmfEnetRxFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetTxFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxBytes                          	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/

U32 
  iposPtmfEnetRxBytes (U8 bPortNumber) 
{
  return (tsIniCounters[bPortNumber].uiEnetOctXmitCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxPauseFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/

U32 
  iposPtmfEnetRxPauseFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiTxPauseFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxBrdcastFrames                   	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxBrdcastFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiBroadCastFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxDroppedFrames                   	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxDroppedFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetDropFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxAllignErrors                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxAllignErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiAllignErrorCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxOversize                        	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxOversize (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiLongFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxUndersize                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxUndersize (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxErrorCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxCrcErrors                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxCrcErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetCrcErrorCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxCarrierSenseErrors              	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxCarrierSenseErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiCarrierSenseErrorCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetTxFrames                         	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetTxFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetRxFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetTxBytes                          	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetTxBytes (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetOctRcvCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetTxPauseFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetTxPauseFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxPauseFrameCount);
}


#ifndef CO_30
/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDLateCollisions                      	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDLateCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdlcCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDExcessCollisions                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDExcessCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdecCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDSingleCollisions                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDSingleCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdscCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDMultiCollisions                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDMultiCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdmcCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDDeferredTrans                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDDeferredTrans (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdDefTransCount);
}

#endif

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHdlcCrcErrors                        	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHdlcCrcErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdlcErrorFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHdlcInvalidFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHdlcInvalidFrames (U8 bPortNumber) 
{
  return (tsIniCounters[bPortNumber].uiRxHdlcInvalidFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHdlcDroppedFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHdlcDroppedFrames (U8 bPortNumber) 
{
  return (tsIniCounters[bPortNumber].uiRxHdlcDropFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHdlcGeneralErrors                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHdlcGeneralErrors (U8 bPortNumber) 
{
  return (tsIniCounters[bPortNumber].uiRxHdlcInvalidFrameCount)+
		 (tsIniCounters[bPortNumber].uiRxHdlcErrorFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfGetConfigParam                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number, Parameter Type requested, pointer to return value *
*                                                                             *
* Returns... : Success or Failure code                                        *
*                                                                             *
******************************************************************************/
eIniRetCode
  iposPtmfGetConfigParam (U8 bPortNumber, 
                          eIposPtmfParamType eParamType, 
                          U32 *puiParam)
{
  tsHostIniMdioAddrData   tsIniReg;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC GET CONFIG PARAMS  #%d ", bPortNumber);
#endif //DEBUG_INI

  if (bPortNumber >= MAX_ENET_PORTS )
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 5)
    {
      printf("\n Invalid Port Number");
    }
#endif //DEBUG_INI
    return HOST_INI_UNDEFINED_ERROR;
  }

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

  // PORT DISABLE = 0
  // xMII port configuration reg
  tsIniReg.uiIniRegAddr   = XPCR;
  iposPtmfMdioRead ( &tsIniReg);

  switch (eParamType)
  {
    case ENET_LINK_EN:
      if (tsIniPortParams[bPortNumber].bEnetLinkStatus)
        *puiParam = ENET_LINK_ON;
      else
        *puiParam = ENET_LINK_OFF;
              
      break;

    case ENET_LINK_SPEED:
      if (tsIniPortParams[bPortNumber].bEnetLinkStatus)
      {
          if ((tsIniReg.uiIniRdWrData & BIT2_SET) == BIT2_SET)
            *puiParam = ENET_LINK_1000_MBPS; 
          else if ((tsIniReg.uiIniRdWrData & BIT1_SET) == BIT1_SET)
            *puiParam = ENET_LINK_100_MBPS;
          else
            *puiParam = ENET_LINK_10_MBPS;
      }
      else 
        return HOST_INI_UNDEFINED_ERROR;

      break;

    case ENET_LINK_DUPLEX:
      if (tsIniPortParams[bPortNumber].bEnetLinkStatus)
      {
          if ((tsIniReg.uiIniRdWrData & BIT5_SET) == BIT5_SET)
            *puiParam = ENET_LINK_HALF_DUPLEX;
          else
            *puiParam = ENET_LINK_FULL_DUPLEX;
      }
      else 
        return HOST_INI_UNDEFINED_ERROR;

      break;
    
    case ENET_LINK_FLOW_CONTROL:
      if (tsIniPortParams[bPortNumber].bEnetLinkStatus)
      {
          if ((tsIniReg.uiIniRdWrData & BIT3_SET) == BIT3_SET)
            *puiParam = ENET_FLOW_CONTROL_ON;
          else if ((tsIniReg.uiIniRdWrData & BIT4_SET) == BIT4_SET)
            *puiParam = ENET_FLOW_CONTROL_ON;
          else
            *puiParam = ENET_FLOW_CONTROL_OFF;
      }
      else 
        return HOST_INI_UNDEFINED_ERROR;

      break;
    case ENET_AUTO_NEG:
      if (tsIniPortParams[bPortNumber].bEnetLinkStatus)
      {
          *puiParam = (tsIniPortParams[bPortNumber].bMiiMode & 0x0f);
	  }
	  else
		return HOST_INI_UNDEFINED_ERROR;
    break;
    
    default:
      return HOST_INI_UNDEFINED_ERROR;
  }
  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfSetConfigParam                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number, Parameter Type to set, pointer to return value *
*                                                                             *
* Returns... : Success or Failure code                                        *
*                                                                             *
******************************************************************************/

eIniRetCode
  iposPtmfSetConfigParam (U8 bPortNumber, 
                          eIposPtmfParamType eParamType, 
                          U32 uiParam)
{
  tsHostIniMdioAddrData   tsIniReg;
  tsHostIniMdioAddrData1 tsIniReg1;
#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC SET CONFIG PARAMS  #%d ", bPortNumber);
#endif //DEBUG_INI

  if (bPortNumber >= MAX_ENET_PORTS )
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 5)
    {
      printf("\n Invalid Port Number");
    }
#endif //DEBUG_INI
    return HOST_INI_UNDEFINED_ERROR;
  }

  switch (eParamType)
  {
    case ENET_LOOPBACK:

      tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bEnetPhyAddr;
      tsIniReg.uiIniRegAddr = 0;  // PHY Control Register
      iposMdioRead (&tsIniReg);

      if (uiParam == 0)
      {
        printf("\n Turn OFF Phy Loopback: ");
        tsIniReg.uiIniRdWrData &= 0xbfff; // PHY Loopback = OFF

        if ((tsIniPortParams[bPortNumber].bMiiMode & 0x0f) == 2)
        {
          printf("Auto-negotiation");
          tsIniReg.uiIniRdWrData |= 0x3100; // Auto-negotiation = ON
        }
        else
        {
          printf("Fixed Mode");
          // Fixed mode;
          tsIniReg.uiIniRdWrData &= 0xefff;   // Auto-negotiation DISABLE

          if (tsIniPortParams[bPortNumber].bPortSpeed == PORT_SPEED_10)
          {
            tsIniReg.uiIniRdWrData &= 0xdfff;
          }
          else
          {
            tsIniReg.uiIniRdWrData |= 0x2000;
          }
          if (tsIniPortParams[bPortNumber].bDuplex == DUPLEX_HALF)
          {
            tsIniReg.uiIniRdWrData &= 0xfeff;
          }
          else
          {
            tsIniReg.uiIniRdWrData |= 0x0100;
          }
        }
        iposMdioWrite (&tsIniReg);
      }
      else if (uiParam == 1)
      {
        // PHY Loopback = ON
        tsIniReg.uiIniRdWrData &= 0xefff;   // Auto-negotiation DISABLE
        tsIniReg.uiIniRdWrData |= 0x6100;   // Loopback = ON, Speed = 100Mbps
                                            // Duplex = FULL
        iposMdioWrite (&tsIniReg);
      }

      // Set the base address in the structure to be passed to the driver function
      tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

      // Ethernet Port address set for access to the port specific MDIO registers.
      tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

      // PORT DISABLE = 0
      // xMII port configuration reg
      tsIniReg.uiIniRegAddr   = XPCR;
      iposPtmfMdioRead ( &tsIniReg);

      if (uiParam == 0)
      {
        tsIniReg.uiIniRdWrData &= ~0x0080; // xMII Loopback = OFF
        iposPtmfMdioWrite (&tsIniReg);
      }
      else if (uiParam == 2)
      {
        tsIniReg.uiIniRdWrData |= 0x0080; // xMII Loopback = ON
        iposPtmfMdioWrite (&tsIniReg);
      }

      break;

    case ENET_LINK_FLOW_CONTROL:

      tsIniPortParams[bPortNumber].bFlowControl = (U8)uiParam;

      // Set the base address in the structure to be passed to the driver function
      tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

      // Ethernet Port address set for access to the port specific MDIO registers.
      tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

      // xMII port configuration reg
      tsIniReg.uiIniRegAddr   = XPCR;
      iposPtmfMdioRead ( &tsIniReg);

      if (uiParam & FULL_DUPLEX_FLOW)
      {
        tsIniReg.uiIniRdWrData |= 0x0048;   // full-flow+Suppress pause frames
      }
      else 
      {
        tsIniReg.uiIniRdWrData &= ~(0x0048);   // Pass through pause frames.
      }
      printf ("\n Setup Cfg: XPCR:%04x", tsIniReg.uiIniRdWrData) ;
      iposPtmfMdioWrite (&tsIniReg);

   // Enable flow control on Pause Queue Register 
   if ((uiParam & FULL_DUPLEX_FLOW) ||
      (uiParam & HALF_DUPLEX_FLOW)) {

      tsIniReg1.uiIniRegAddr = EIU_PQER ;
      iposPtmfMdioRead1 (&tsIniReg1) ;
      tsIniReg1.uiIniRdWrData |= 0x00000010 ; //Flow control enabled for queue0
      printf ("\n PQER :%08x", tsIniReg1.uiIniRdWrData) ;
      iposPtmfMdioWrite1 ( &tsIniReg1);
   }
      
      tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bEnetPhyAddr;
      /* Ethernet PHY Auto-Negotiation Advertisement Register */
      tsIniReg.uiIniRegAddr = 04;
      iposMdioRead (&tsIniReg);

      if (uiParam & FULL_DUPLEX_FLOW )
      {
        tsIniReg.uiIniRdWrData |= 0x0400;
      }
      else
      {
        tsIniReg.uiIniRdWrData &= 0xfbff;
      }
      iposMdioWrite (&tsIniReg);

      printf("\n ADVTZ = %04x", tsIniReg.uiIniRdWrData);

      tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bEnetPhyAddr;
      tsIniReg.uiIniRegAddr = 0;  // PHY Control Register
      iposMdioRead (&tsIniReg);

      tsIniReg.uiIniRdWrData |= 0x0200; // Restart Auto-negotiation.
      iposMdioWrite (&tsIniReg);

      break;


    default:
      return HOST_INI_UNDEFINED_ERROR;
  }
  return HOST_INI_NO_ERROR;

}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfGetCounter                           	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number, COunter Type requested, pointer to return value   *
*                                                                             *
* Returns... : Success or Failure code                                        *
*                                                                             *
******************************************************************************/

eIniRetCode
  iposPtmfGetCounter (U8 bPortNumber, 
                      eIposPtmfCounterType eCounterType, 
                      U32 *puiCounter)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC GET COUNTER  #%d ", bPortNumber);
#endif //DEBUG_INI

  if (bPortNumber >= MAX_ENET_PORTS )
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 5)
    {
      printf("\n Invalid Port Number");
    }
#endif //DEBUG_INI
    return HOST_INI_UNDEFINED_ERROR;
  }
  
  switch (eCounterType)
  {
     
    case RX_ENET_UL2_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiEnetTxFrameCount;
      break;

    case RX_ENET_UL2_BYTES:
      *puiCounter = tsIniCounters[bPortNumber].uiEnetOctXmitCount;
      break;
    
    case RX_ENET_DROP_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiEnetDropFrameCount;
      break;

    case RX_ENET_ALIGN_ERR:
      *puiCounter = tsIniCounters[bPortNumber].uiAllignErrorCount;
      break;
    
    case RX_ENET_OVERSIZE_ERR:
      *puiCounter = tsIniCounters[bPortNumber].uiLongFrameCount;
      break;
    
    case RX_ENET_UNDERSIZE_ERR:
      *puiCounter = tsIniCounters[bPortNumber].uiRxErrorCount;
      break;
    
    case RX_ENET_CRC_ERR:
      *puiCounter = tsIniCounters[bPortNumber].uiEnetCrcErrorCount;
      break;
    
    case RX_ENET_CS_ERR:
      *puiCounter = tsIniCounters[bPortNumber].uiCarrierSenseErrorCount;
      break;

    case RX_ENET_BRDCAST_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiBroadCastFrameCount;
      break;

    case RX_ENET_PAUSE_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiTxPauseFrameCount;
      break;

    case TX_ENET_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiEnetRxFrameCount;
      break;
    
    case TX_ENET_BYTES:
      *puiCounter = tsIniCounters[bPortNumber].uiEnetOctRcvCount;
      break;

    case TX_PAUSE_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiRxPauseFrameCount;
      break;

    case HDLC_CRC_ERR:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdlcErrorFrameCount;
      break;
    
    case HDLC_INVALID_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdlcInvalidFrameCount;
      break;
    
    case HDLC_DROP_FRAMES:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdlcDropFrameCount;
      break;

    case HALF_DUPLEX_LC:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdlcCount;
      break;

    case HALF_DUPLEX_EC:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdecCount;
      break;

    case HALF_DUPLEX_SC:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdscCount;
      break;
    
    case HALF_DUPLEX_MC:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdmcCount;
      break;

    case HALF_DUPLEX_DEF_TRANS:
      *puiCounter = tsIniCounters[bPortNumber].uiRxHdDefTransCount;
      break;

    default:
      return HOST_INI_UNDEFINED_ERROR;
  }
  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfSetCounter                           	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number, COunter Type requested, pointer to return value   *
*                                                                             *
* Returns... : Success or Failure code                                        *
*                                                                             *
******************************************************************************/

eIniRetCode
  iposPtmfSetCounter (U8 bPortNumber, 
                      eIposPtmfCounterType eCounterType, 
                      U32 uiCounter)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC SET COUNTER  #%d ", bPortNumber);
#endif //DEBUG_INI

  if (bPortNumber >= MAX_ENET_PORTS )
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 5)
    {
      printf("\n Invalid Port Number");
    }
#endif //DEBUG_INI
    return HOST_INI_UNDEFINED_ERROR;
  }
  
  switch (eCounterType)
  {

    case ALL_COUNTERS:
      PrIniClrCounter (bPortNumber);
      break;
     
    case RX_ENET_UL2_FRAMES:
      tsIniCounters[bPortNumber].uiEnetTxFrameCount = uiCounter;
      break;

    case RX_ENET_UL2_BYTES:
      tsIniCounters[bPortNumber].uiEnetOctXmitCount = uiCounter;
      break;
    
    case RX_ENET_DROP_FRAMES:
      tsIniCounters[bPortNumber].uiEnetDropFrameCount = uiCounter;
      break;

    case RX_ENET_ALIGN_ERR:
      tsIniCounters[bPortNumber].uiAllignErrorCount = uiCounter;
      break;
    
    case RX_ENET_OVERSIZE_ERR:
      tsIniCounters[bPortNumber].uiLongFrameCount = uiCounter;
      break;
    
    case RX_ENET_UNDERSIZE_ERR:
      tsIniCounters[bPortNumber].uiRxErrorCount = uiCounter;
      break;
    
    case RX_ENET_CRC_ERR:
      tsIniCounters[bPortNumber].uiEnetCrcErrorCount = uiCounter;
      break;
    
    case RX_ENET_CS_ERR:
      tsIniCounters[bPortNumber].uiCarrierSenseErrorCount = uiCounter;
      break;

    case RX_ENET_BRDCAST_FRAMES:
      tsIniCounters[bPortNumber].uiBroadCastFrameCount = uiCounter;
      break;

    case RX_ENET_PAUSE_FRAMES:
      tsIniCounters[bPortNumber].uiTxPauseFrameCount = uiCounter;
      break;

    case TX_ENET_FRAMES:
      tsIniCounters[bPortNumber].uiEnetRxFrameCount = uiCounter;
      break;
    
    case TX_ENET_BYTES:
      tsIniCounters[bPortNumber].uiEnetOctRcvCount = uiCounter;
      break;

    case TX_PAUSE_FRAMES:
      tsIniCounters[bPortNumber].uiRxPauseFrameCount = uiCounter;
      break;

    case HDLC_CRC_ERR:
      tsIniCounters[bPortNumber].uiRxHdlcErrorFrameCount = uiCounter;
      break;
    
    case HDLC_INVALID_FRAMES:
      tsIniCounters[bPortNumber].uiRxHdlcInvalidFrameCount = uiCounter;
      break;
    
    case HDLC_DROP_FRAMES:
      tsIniCounters[bPortNumber].uiRxHdlcDropFrameCount = uiCounter;
      break;

    case HALF_DUPLEX_LC:
      tsIniCounters[bPortNumber].uiRxHdlcCount = uiCounter;
      break;

    case HALF_DUPLEX_EC:
      tsIniCounters[bPortNumber].uiRxHdecCount = uiCounter;
      break;

    case HALF_DUPLEX_SC:
      tsIniCounters[bPortNumber].uiRxHdscCount = uiCounter;
      break;
    
    case HALF_DUPLEX_MC:
      tsIniCounters[bPortNumber].uiRxHdmcCount = uiCounter;
      break;

    case HALF_DUPLEX_DEF_TRANS:
      tsIniCounters[bPortNumber].uiRxHdDefTransCount = uiCounter;
      break;

    default:
      return HOST_INI_UNDEFINED_ERROR;
  }
  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposMdioRegRead                              	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number, Register Address, pointer to return value         *
*                                                                             *
* Returns... : Success or Failure code                                        *
*                                                                             *
******************************************************************************/
eIniRetCode
  iposMdioRegRead(U8 bPortNumber, U16 uiRegAddr, U16 *puiRegData)
{
  tsHostIniMdioAddrData   tsIniReg;

  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bEnetPhyAddr;
  tsIniReg.uiIniRegAddr = uiRegAddr;

  iposMdioRead (&tsIniReg);

  *puiRegData = tsIniReg.uiIniRdWrData;

  return HOST_INI_NO_ERROR;

}

/******************************************************************************
*                                                                             *
* Function.. : iposMdioRegWrite                              	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number, Register Address, pointer to return value         *
*                                                                             *
* Returns... : Success or Failure code                                        *
*                                                                             *
******************************************************************************/
eIniRetCode
  iposMdioRegWrite(U8 bPortNumber, U16 uiRegAddr, U16 *puiRegData)
{
  tsHostIniMdioAddrData   tsIniReg;

  if (uiRegAddr == 1)
    return HOST_INI_ILLEGAL_MDIO_REG;
  else if (uiRegAddr == 0)
  {
    /* Special case if the write is to register #0, i.e. the control register */
    tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bEnetPhyAddr;
    tsIniReg.uiIniRegAddr = uiRegAddr;
    if (*puiRegData & PTMF_ENET_PHY_PWR_DOWN)
    {
      /* Power Down Ethernet PHY */
    iposMdioRead (&tsIniReg);
      /* Save the current control register content before going into 
         power down */
      s_uiEnetPhyCtrlReg[bPortNumber] = tsIniReg.uiIniRdWrData;
      tsIniReg.uiIniRdWrData = PTMF_ENET_PHY_PWR_DOWN;
    }
    else
    {
      int i=0;
      do 
      {
        /* Power Up Ethernet PHY */
        tsIniReg.uiIniRdWrData = s_uiEnetPhyCtrlReg[bPortNumber];
        iposMdioWrite (&tsIniReg);

        tsIniReg.uiIniRdWrData = 0xDEAD;
        iposMdioRead (&tsIniReg);
        i++;
      
        if (i > 10)
          return HOST_INI_ILLEGAL_MDIO_REG;
  
      }while (tsIniReg.uiIniRdWrData != s_uiEnetPhyCtrlReg[bPortNumber]);
    }
  }
  else
  {
    tsIniReg.uiIniRdWrData =  *puiRegData;
  }
  
  /* Write to the register */
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bEnetPhyAddr;
  tsIniReg.uiIniRegAddr = uiRegAddr;
  
  iposMdioWrite (&tsIniReg);

  return HOST_INI_NO_ERROR;

}
/*------------------------------------------------------------------------------
  PRIVATE FUNCTION DEFINITIONS
  ----------------------------------------------------------------------------*/
/******************************************************************************
*                                                                             *
* Function.. : PrIniEnetPhyAutoNegotiate                     	                *
*                                                   	                        *
* Purpose... : Determine the status of the Enet Link and program the INI ASIC *
*              register with the mode that the PHY auto negotiated            *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : None                                                           *
*                                                                             *
******************************************************************************/
void
  PrIniEnetPhyAutoNegotiate (U8 bEnetPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;
  tsHostIniMdioAddrData1   tsIniReg1;
  U16                     uiTemp;
  U16                     uiPhyStatus;
  U16                     uiPhyLinkPartnerAbiltity;
  U8                   bLinkSpeed, bLinkDuplex, bLinkFlowControl;
  U16                  uiMiiSlotCount;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 0)
    printf("\nINI ASIC ENET PHY AUTO-NEGOTIATION %02x", bEnetPortNumber);
#endif //DEBUG_INI

  // Read the Ethernet PHY Status register.
  uiPhyStatus = iposReadEnetPhyStatus(
                  tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);

#ifdef DEBUG_INI
  if (gbDebugLevel <= 2)
    printf(" PHY STATUS = %x ", uiPhyStatus);
#endif //DEBUG_INI

  // Is Link UP ?
  if ((uiTemp = (uiPhyStatus & ENET_VALID_LINK)))
  {
    // If Link is UP, then check if the link status has changed from the 
    // last time.
    if (uiTemp != tsIniPortParams[bEnetPortNumber].bEnetLinkStatus)
    {
      // Check if the PHY is capable of auto-negotiation
      if (uiPhyStatus & ENET_AUTONEGO_CAPABLE)
      {
        // Check if Auto-negotiation process is OVER
        if (uiPhyStatus & ENET_AUTO_NEGOTIATE_OVER)
        {

//#if defined(BME_CPE_20)
          // Read register 5 (ANLPAR): Auto-negotiation Link Partner Ability
          // Register
          uiPhyLinkPartnerAbiltity = iposReadEnetPartnerAbility(
              tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);

#ifdef DEBUG_INI
          if (gbDebugLevel <= 5)
            printf("\n LINK PARTNER ABILITY = %x \n", uiPhyLinkPartnerAbiltity);
#endif //DEBUG_INI

            // Check if Link partner has flow control support??
            if ((uiPhyLinkPartnerAbiltity & ENET_FCS) ==  ENET_FCS)
               bLinkFlowControl = 1;
            else
               bLinkFlowControl = 0;

            bLinkSpeed  = PORT_SPEED_100; //default
            bLinkDuplex = DUPLEX_HALF; //default

            //Please do not alter the "if" statments sequence below! Order Matters!!
            if ((uiPhyLinkPartnerAbiltity & ENET_10_HDX) == ENET_10_HDX) 
            {
                 printf (" :ENET_10HDX:");
                 bLinkSpeed  = PORT_SPEED_10;
                 bLinkDuplex = DUPLEX_HALF;
            }
            if ((uiPhyLinkPartnerAbiltity & ENET_10_FDX) == ENET_10_FDX)
            {
                 printf (" :ENET_10FDX:");
                 bLinkSpeed  = PORT_SPEED_10;
                 bLinkDuplex = DUPLEX_FULL;
            }
            if ((uiPhyLinkPartnerAbiltity & ENET_100_HDX) == ENET_100_HDX) 
            {
                 printf (" :ENET_100HDX:");
                 bLinkSpeed  = PORT_SPEED_100;
                 bLinkDuplex = DUPLEX_HALF;
            }
            if ((uiPhyLinkPartnerAbiltity & ENET_100_FDX) == ENET_100_FDX) 
            {
                 printf (" :ENET_100FDX:");
                 bLinkSpeed  = PORT_SPEED_100;
                 bLinkDuplex = DUPLEX_FULL;
            } 
                 printf ("\n");
        }
        else
        {
          /* Fixed Mode (Auto-negotiation = OFF)  */
          bLinkFlowControl = 1;
          bLinkSpeed = tsIniPortParams[bEnetPortNumber].bPortSpeed;
          bLinkDuplex = tsIniPortParams[bEnetPortNumber].bDuplex;
        }

        // Set the base address in the structure to be passed to the driver 
        // function
        tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

        // Ethernet Port address set for access to the port specific MDIO 
        // registers.
        tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

        // xMII port configuration reg
        tsIniReg.uiIniRegAddr   = XPCR;
        iposPtmfMdioRead ( &tsIniReg);

        if (bLinkSpeed == PORT_SPEED_100)
        {
          // Link Speed = 100 Mbps
          tsIniReg.uiIniRdWrData |= 0x0002;
          uiMiiSlotCount = 0x2cc;

        }
        else if (bLinkSpeed == PORT_SPEED_10)
        {
          // Link Speed = 10 Mbps
          tsIniReg.uiIniRdWrData &= ~(0x0006);
          uiMiiSlotCount = 0x1c00;
        }
        else
        {
          // Link Speed = 1000 Mbps
          tsIniReg.uiIniRdWrData &= 0x0004;
          uiMiiSlotCount = 0x2cc;//todo

        }
        if (bLinkDuplex)
        {
          // FULL DUPLEX
          tsIniReg.uiIniRdWrData &= ~0x0020;
          // PAUSE CAPABLE OR NOT
          if (bLinkFlowControl)
          {
            // Remote End Flow Capable; 
            // Check if Flow Control Enable at modem?
            if (tsIniPortParams[bEnetPortNumber].bFlowControl & FULL_DUPLEX_FLOW)
            {
              printf ("\n FULL DUPLEX- FLOW CONTROL ON \n");
              //Port start with Full duplex Pause/Resume frame generation ON
              tsIniReg.uiIniRdWrData &= ~(0x0048);
              tsIniReg.uiIniRdWrData |= 0x0048;
            }
            else
            {
              // No Flow Control
              tsIniReg.uiIniRdWrData &= ~(0x0048);
            }
          }
          else
          {
            // No Flow Control
            tsIniReg.uiIniRdWrData &= ~(0x0048);
          }
        }
        else
        {
          // HALF DUPLEX
          tsIniReg.uiIniRdWrData |= 0x0020;
          // Check if Half Duplex Flow Control Enable at modem?
          if (tsIniPortParams[bEnetPortNumber].bFlowControl & HALF_DUPLEX_FLOW)
          {
            if (bLinkFlowControl)
            {
              //Port start with HALF Duplex Flow Control ON
              tsIniReg.uiIniRdWrData &= ~(0x0050); 
              tsIniReg.uiIniRdWrData |= 0x0050; //set SUP_PAUSE_FRM also
              printf ("\n HALF DUPLEX FLOW CONTROL ON \n");
            }
            else
            {              
              // No Flow Control
              tsIniReg.uiIniRdWrData &= ~(0x0050);
            }
          }
          else
          {
            // No Flow Control
            tsIniReg.uiIniRdWrData &= ~(0x0050);
          }
        }
        // Enable xMII port
        tsIniReg.uiIniRdWrData |= 0x0001;
        printf ("\n Auto-neg XPCR:%04x", tsIniReg.uiIniRdWrData);
        // xMII port configuration reg
        tsIniReg.uiIniRegAddr   = XPCR;
        iposPtmfMdioWrite ( &tsIniReg);

      // Enable flow control on Pause Queue Register 
      tsIniReg1.uiIniRegAddr = EIU_PQER ;
      iposPtmfMdioRead1 (&tsIniReg1) ;
      if ((tsIniPortParams[bEnetPortNumber].bFlowControl & FULL_DUPLEX_FLOW) ||
         (tsIniPortParams[bEnetPortNumber].bFlowControl & HALF_DUPLEX_FLOW)) 
         tsIniReg1.uiIniRdWrData |= 0x00000010 ; //Flow control enabled for queue0
      else 
         tsIniReg1.uiIniRdWrData &= ~(0x00000010) ; //Flow control disabled for queue0

      printf ("\n PQER :%08x::FlowCtrlON?:%x", tsIniReg1.uiIniRdWrData, 
                     tsIniPortParams[bEnetPortNumber].bFlowControl);
      iposPtmfMdioWrite1 ( &tsIniReg1);


        // xMII Slot count register used for Half Duplex Flow control.
        tsIniReg.uiIniRegAddr   = XSCR;
        tsIniReg.uiIniRdWrData  = uiMiiSlotCount;
        iposPtmfMdioWrite ( &tsIniReg);

        // Port State = Auto-negotiation over.
        tsIniPortParams[bEnetPortNumber].bPtmfPortState |= 
          PORT_AUTO_NEGO_OVER;

        // Save the Auto-negotiated link parameters in the port structure
        tsIniPortParams[bEnetPortNumber].bDuplex = bLinkDuplex;
        tsIniPortParams[bEnetPortNumber].bPortSpeed = bLinkSpeed;
      }
      // Link is NOW UP
      tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_VALID_LINK;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 5)
      {
        printf("\n ENET PORT %02d LINK UP:\n", bEnetPortNumber + 1);
      }
#endif //DEBUG_INI
    }
  }
  else
  {
    // If Link is DOWN, then check if the link status has changed from the 
    // last time.
    if (uiTemp != tsIniPortParams[bEnetPortNumber].bEnetLinkStatus)
    {
      // Link is DOWN
      tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_INVALID_LINK;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 5)
        printf("\n ENET PORT %02d LINK DOWN:\n", bEnetPortNumber + 1);
#endif //DEBUG_INI

     // Set the base address in the structure to be passed to the driver 
      // function
      tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

      // Ethernet Port address set for access to the port specific MDIO 
      // registers.
      tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

      // xMII port configuration reg
      tsIniReg.uiIniRegAddr   = XPCR;
      iposPtmfMdioRead ( &tsIniReg);

      // No Flow Control
      tsIniReg.uiIniRdWrData &= 0xfff3;
      iposPtmfMdioWrite ( &tsIniReg);
    }
  }
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniClrCounter                              	                *
*                                                   	                        *
* Purpose... : Clears all the performance counter variables for a particular  *
*              port                                                           *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : None                                                           *
*                                                                             *
******************************************************************************/
void
  PrIniClrCounter ( U8 bPortNumber)
{
  /* Initialise all the counters to ZERO                                    */
  tsIniCounters[bPortNumber].uiEnetTxFrameCount       = 0;
  tsIniCounters[bPortNumber].uiEnetOctXmitCount       = 0;
  tsIniCounters[bPortNumber].uiEnetDropFrameCount     = 0;
  tsIniCounters[bPortNumber].uiAllignErrorCount       = 0;
  tsIniCounters[bPortNumber].uiLongFrameCount         = 0;
  tsIniCounters[bPortNumber].uiRxErrorCount           = 0;
  tsIniCounters[bPortNumber].uiEnetCrcErrorCount      = 0;
  tsIniCounters[bPortNumber].uiCarrierSenseErrorCount = 0;
  tsIniCounters[bPortNumber].uiBroadCastFrameCount    = 0;
  tsIniCounters[bPortNumber].uiTxPauseFrameCount      = 0;
  tsIniCounters[bPortNumber].uiEnetRxFrameCount       = 0;
  tsIniCounters[bPortNumber].uiEnetOctRcvCount        = 0;
  tsIniCounters[bPortNumber].uiRxHdlcErrorFrameCount  = 0;
  tsIniCounters[bPortNumber].uiRxHdlcInvalidFrameCount= 0;
  tsIniCounters[bPortNumber].uiRxPauseFrameCount      = 0;
  tsIniCounters[bPortNumber].uiRxHdlcDropFrameCount   = 0;
  tsIniCounters[bPortNumber].uiRxHdlcCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdecCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdscCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdmcCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdDefTransCount      = 0;
}
/******************************************************************************
*                                                                             *
* Function.. : PrIniReadWord                                	                *
*                                                   	                        *
* Purpose... : Performs MDIO reads of 1 16-bit registers and returns the      *
*              value                                                          * 
*									                                                            *
* Parameters : Port Number and register address                               *
*                                                                             *
* Returns... : 32-bit unsigned integer                                        *
*                                                                             *
******************************************************************************/
U32
  PrIniReadWord (U8 bPortNumber, U16 uiRegAddr)
{
  tsHostIniMdioAddrData   tsIniReg;

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

  // Read the addressed MDIO register from the specified port.
  tsIniReg.uiIniRegAddr = uiRegAddr ; 
  iposPtmfMdioRead (&tsIniReg);

  return (tsIniReg.uiIniRdWrData);
}
/******************************************************************************
*                                                                             *
* Function.. : PrIniReadDword                             	                  *
*                                                   	                        *
* Purpose... : Performs MDIO reads of 2 16-bit registers and returns a 32     *
*              bit value                                                      * 
*									                                                            *
* Parameters : Port Number and register address                               *
*                                                                             *
* Returns... : 32-bit unsigned integer                                        *
*                                                                             *
******************************************************************************/
U32
  PrIniReadDword ( U8 bPortNumber, U16 uiRegAddr)
{
  tsHostIniMdioAddrData   tsIniReg;
  U32                  uiCountX, uiCountTemp;

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

  // First read the LSW of the double word counter
  tsIniReg.uiIniRegAddr = uiRegAddr ; 
  iposPtmfMdioRead (&tsIniReg);
  uiCountX = tsIniReg.uiIniRdWrData;

  // Read the MSW of the double word counter
  tsIniReg.uiIniRegAddr = uiRegAddr + 1; 
  iposPtmfMdioRead (&tsIniReg);

  uiCountTemp = tsIniReg.uiIniRdWrData;
  uiCountTemp <<= 16;
  uiCountX |= uiCountTemp;

  return uiCountX;
}

U32
  PrIniReadDword1 ( U8 bPortNumber, U32 uiRegAddr)
{
  tsHostIniMdioAddrData1 tsIniReg;
  U32                  uiCountX;

  tsIniReg.uiIniRegAddr = uiRegAddr ;
  iposPtmfMdioRead1 (&tsIniReg);
  uiCountX = tsIniReg.uiIniRdWrData;

  return uiCountX;
}
/******************************************************************************
*                                                                             *
* Function.. : PrIniUtopiaPollAdd                           	                *
*                                                   	                        *
* Purpose... : Adds an Utopia Phy address to the polling sequence             *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode
  PrIniUtopiaPollAdd (U8 bPortNumber)
{

#if !defined(CPE_30)

  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiUtopiaPollReg;
  U8                      bPhyCount;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC ADD UTOPIA PHY TO POLLING %02x", bPortNumber);
#endif //DEBUG_INI

  // Set the base address 
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  uiUtopiaPollReg = tsIniPortParams[bPortNumber].bPortIndex & 0x0f;
  uiUtopiaPollReg <<= 6;
  uiUtopiaPollReg |= tsIniPortParams[bPortNumber].bUtopiaPort;
  uiUtopiaPollReg |= (tsIniPortParams[bPortNumber].bRxEnable << 10);

  tsIniReg.uiIniRegAddr = UPAR;
  iposPtmfMdioRead (&tsIniReg);
  bPhyCount = (U8)tsIniReg.uiIniRdWrData;
//  bPhyCount &= 0x0f;

  tsIniReg.uiIniRegAddr = UPR_0;

  while (bPhyCount)
  {
    iposPtmfMdioRead (&tsIniReg);

#ifdef DEBUG_INI
  if (gbDebugLevel <= 1)
    printf("\nADDR= %03x, DATA= %04x, CMP= %04x ",tsIniReg.uiIniRegAddr, 
                                                  tsIniReg.uiIniRdWrData,
                                                  uiUtopiaPollReg );
#endif //DEBUG_INI

    if (uiUtopiaPollReg == tsIniReg.uiIniRdWrData)
    {
#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf("\nFOUND AT %03x",tsIniReg.uiIniRegAddr );
#endif //DEBUG_INI
      return HOST_INI_NO_ERROR;
    }
    
    tsIniReg.uiIniRegAddr ++;
    bPhyCount--;
  }

  if (tsIniReg.uiIniRegAddr > UPR_F)
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 3)
      printf("\nPOLL FULL!!");
#endif //DEBUG_INI

    return HOST_INI_UNDEFINED_ERROR;
  }
//  tsIniReg.uiIniRdWrData = (tsIniPortParams[bPortNumber].bRxEnable << 10);
  tsIniReg.uiIniRdWrData = uiUtopiaPollReg;
  iposPtmfMdioWrite (&tsIniReg);

#ifdef DEBUG_INI
  if (gbDebugLevel <= 1)
    printf("\nADDR= %03x, DATA= %04x",tsIniReg.uiIniRegAddr, uiUtopiaPollReg );
#endif //DEBUG_INI

  tsIniReg.uiIniRegAddr = UPAR;
  iposPtmfMdioRead (&tsIniReg);

  tsIniReg.uiIniRdWrData ++;

  iposPtmfMdioWrite (&tsIniReg);

#endif //#if defined(CPE_30)
  
  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniUtopiaPollRemove                        	                *
*                                                   	                        *
* Purpose... : Removes an Utopia Phy address from the polling sequence        *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
eIniRetCode
  PrIniUtopiaPollRemove (U8 bPortNumber)
{

#if !defined(CPE_30)

  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiUtopiaPollReg, i;
  U16                     uiUtopiaPhy;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC REMOVE UTOPIA PHY FROM POLLING %02x", bPortNumber);
#endif //DEBUG_INI

  // Set the base address 
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  // Determine the number of PHYs being polled by the master i.e INI ASIC
  tsIniReg.uiIniRegAddr = UPAR;
  iposPtmfMdioRead (&tsIniReg);
  uiUtopiaPhy = tsIniReg.uiIniRdWrData;
  if (uiUtopiaPhy == 0)
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 4)
      printf("\nNO PHY TO REMOVE FROM POLLING ");
#endif //DEBUG_INI
    return HOST_INI_UNDEFINED_ERROR;
  }

  uiUtopiaPhy &= 0x0f;
  uiUtopiaPhy = uiUtopiaPhy - 1;

  for (i = UPR_0; i <= UPR_F; i++, uiUtopiaPhy-- )
  {
    // Read the Utopia poll register and find out the xMII port number
    tsIniReg.uiIniRegAddr = i;
    iposPtmfMdioRead (&tsIniReg);

    uiUtopiaPollReg = tsIniReg.uiIniRdWrData;
    uiUtopiaPollReg >>= 6;
    uiUtopiaPollReg  &= 0x0f;
    
    // Check if this is to be removed from Utopia polling sequence
    if (uiUtopiaPollReg == bPortNumber)
    {
      while (uiUtopiaPhy)
      {
        // Read from i+1 and write to i
        tsIniReg.uiIniRegAddr = i+1;
        iposPtmfMdioRead (&tsIniReg);

        tsIniReg.uiIniRegAddr = i;
        iposPtmfMdioWrite (&tsIniReg);

        // Step to next Utopia Poll register
        i++;
        
        // 
        uiUtopiaPhy --;
      }
      // Last but not the least decrement the No. of Phys to poll by one.
      tsIniReg.uiIniRegAddr = UPAR;
      iposPtmfMdioRead (&tsIniReg);

      tsIniReg.uiIniRdWrData --;
      iposPtmfMdioWrite (&tsIniReg);

      // Return success
      return HOST_INI_NO_ERROR;
    }
    else if (!uiUtopiaPhy)
      break;
  }

#endif //#if defined(CPE_30)
  // If you ever get out of the for loop, TROUBLE!!!!
  return HOST_INI_UNDEFINED_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniMapDsl2Enet                           	                  *
*                                                   	                        *
* Purpose... :                         	                                      *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
U32 
  PrIniMapDsl2Enet ( U8 bPortNumber)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 0)
    printf("\nINI ASIC MAP DSL LINE TO ENET PORT %02x", bPortNumber);
#endif //DEBUG_INI
  if (bPortNumber == 0 || bPortNumber > MAX_ENET_PORTS )
  {
    printf("\nERROR: WRONG INI PORT NUMBER %02x", bPortNumber);
    return 0;
  }
  return (bPortNumber-1);
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniSetClock                            	                    *
*                                                   	                        *
* Purpose... :                         	                                      *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
void 
  PrIniSetClock (U8 bPtmfBaseAddr)
{
  tsHostIniMdioAddrData   tsIniReg;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC SET CLOCK " );
#endif //DEBUG_INI

  tsIniReg.bIniBaseAddr = bPtmfBaseAddr;
  tsIniReg.uiIniRegAddr = CLK_PLLNM;
  tsIniReg.uiIniRdWrData = 0xcc;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = PLL_TEST;
  tsIniReg.uiIniRdWrData = 0x313;
  iposPtmfMdioWrite (&tsIniReg);

}

/******************************************************************************
*                                                                             *
* Function.. : PrIniReConfigPort                         	                    *
*                                                   	                        *
* Purpose... :                         	                                      *
*									                                                            *
* Parameters : Ethernet Port Number                                           *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
void 
  PrIniReConfigPort(U8 bEnetPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;
  tsHostIniMdioAddrData1   tsIniReg1;
  U16                     uiMdioRegValue;


#ifdef DEBUG_INI
  if (gbDebugLevel <= 5)
    printf("\nINI ASIC RE-CONFIG PORT #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  // SFA 08/08
  PrIniClrCounter (bEnetPortNumber);

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  // Do a software reset to the port. This initialises the port state machine,
  // clears all the port counter and FIFO pointers and sets the port registers
  // to their default values.
  iposPtmfResetPort (tsIniReg.bIniBaseAddr, tsIniReg.uiIniPhyAddr);

#if defined(BME_CPE_20)
  // FLOW CONTROL = NO FLOW  or FULL DUPLEX
  if (tsIniPortParams[bEnetPortNumber].bFlowControl & FULL_DUPLEX_FLOW)
    uiMdioRegValue = 1;
  else
    uiMdioRegValue = 0;

  // Receive pause frame control register
  tsIniReg.uiIniRegAddr   = RXPF;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

#endif //#if defined(BME_CPE_20)

  // xMII Port configuration register (XPCR)
  tsIniReg.uiIniRegAddr   = XPCR;
  iposPtmfMdioRead ( &tsIniReg);

  // FLOW CONTROL = NO FLOW  or FULL DUPLEX
  if (tsIniPortParams[bEnetPortNumber].bFlowControl & FULL_DUPLEX_FLOW)
    tsIniReg.uiIniRdWrData |= 0x0048;
  else
    tsIniReg.uiIniRdWrData &= ~(0x0048);
      printf ("\n ReCfg: XPCR:%04x", tsIniReg.uiIniRdWrData) ;
  iposPtmfMdioWrite ( &tsIniReg);


  // Suppress HDLC CRC Errors ?
  tsIniReg1.uiIniRegAddr   = RX_SLB_CTRL_REG;
  if (tsIniPortParams[bEnetPortNumber].bFilterHdlcCrc == FILTER_HDLC_CRC ) 
      tsIniReg1.uiIniRdWrData |= 0x4; //set DRP_CRC_ERR (bit-2)
  else 
      tsIniReg1.uiIniRdWrData &= ~(0x4); //clear DRP_CRC_ERR (bit-2)

  iposPtmfMdioWrite1 (&tsIniReg1);


  // Suppress ENET CRC Errors ?
  if (tsIniPortParams[bEnetPortNumber].bFilterEnetCrc == FILTER_ENET_CRC)
    uiMdioRegValue |= 0x0002;
  else
    uiMdioRegValue &= 0xfffd;


#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf ("\n DBGR = %0x",uiMdioRegValue);
#endif //DEBUG_INI

  // Ikanos debug features reg 
  tsIniReg.uiIniRegAddr   = DBGR;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  //47-40 BITS OF SA REG
  tsIniReg1.uiIniRegAddr   = EIU_PFSARLO;
  tsIniReg1.uiIniRdWrData  = tsIniPortParams[bEnetPortNumber].bPauseFrameSrcAddr;
  iposPtmfMdioWrite1 ( &tsIniReg1);

  // PF CRC [31: 0]
  tsIniReg1.uiIniRegAddr   = EIU_PFCRCQ0;
  tsIniReg1.uiIniRdWrData  = tsIniPortParams[bEnetPortNumber].uiPauseFrameCrc;
  iposPtmfMdioWrite1 ( &tsIniReg1);

  // RF CRC [31: 0]
  tsIniReg1.uiIniRegAddr   = EIU_RFCRCQ0;
  tsIniReg1.uiIniRdWrData  = tsIniPortParams[bEnetPortNumber].uiResumeFrameCrc;
  iposPtmfMdioWrite1 ( &tsIniReg1);

  // Rx_Fifo Config register 1
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bRxFifoHwm;
  uiMdioRegValue <<= 2;
  uiMdioRegValue &= 0x1fc;

  tsIniReg.uiIniRegAddr   = RFCR1;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Rx_Fifo Config register 0
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bRxFifoSize;
  uiMdioRegValue <<= 5;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bRxFifoAddr;
  uiMdioRegValue <<= 1;
  uiMdioRegValue |= 0x01;

  tsIniReg.uiIniRegAddr   = RFCR0;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Tx_Fifo Config register 1
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bTxFifoLwm;
  uiMdioRegValue <<= 7;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bTxFifoHwm;
  uiMdioRegValue <<= 2;
  uiMdioRegValue &= 0xfffc;

  //**************************************************************************
  // TX FIFO CONFIG
  tsIniReg.uiIniRegAddr   = TFCR1;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Tx_Fifo Config register 0
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bTxFifoSize;
  uiMdioRegValue <<= 5;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bTxFifoAddr;
  uiMdioRegValue <<= 1;
  uiMdioRegValue |= 0x01;

  tsIniReg.uiIniRegAddr   = TFCR0;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);


  return;
}

#endif //#ifdef INI_SUPPORT

/*------------------------------------------------------------------------------
                                 END OF FILE
------------------------------------------------------------------------------*/
